# sch-rnd modularization

## Why bother...

I believe good software should be modular. This is especially important in the context of large software, such as CAD applications. There should be a thin core that can model the world and provide the basic operations defined on it but anything else should go in separate modules.

Sch-rnd is built up from scratch with modularity in mind.

I believe such modularization has benefits on multiple levels:

- it is possible to compile smaller, potentially faster executables by omitting features the specific user would never use anyway
- in a distribution dynamic-link plugins can be distributed as separate packages providing the user with the option to decide what features to install
- such plugins have to have some sort of APIs if they want to reference each other or if the code needs to reference them; such an API may not (and often did not) exist when the code is part of the core

## Code size in charts

### Overall distribution

All numbers are in SLOC and are acquired running sloccount on the given directory. While lines of code alone is not a true measure of complexity, it's a good estimation. The slices of pie charts are the major components of the sch-rnd executable.

Main components

The main components are:

- libcschem: library that is operating the data model and the modular compiler
- sch-rnd app: application code: main() and the central infrastructure
- 3rd minilibs: 3rd-party minilibs shipped with sch-rnd; these minilibs are specialized in narrow tasks
- plugins: optional modules implementing the actual functionality (each can be disabled)

### Zooming on to the plugins

total size per class

IO plugins

feature plugins

export plugins

GUI plugins

engine plugins

(Red means the plugin doesn't really work).

## Progress in numbers

Below is a table with the summary of core plugins.

module | size [sloc] | status | configure default | class | description
--- | --- | --- | --- | --- | ---
act_draw | 278 | works | buildin | feature | Actions for drawing objects on a graphical sheet or symbol
act_read | 333 | works | buildin | feature | Data access related API as actions
backann | 1128 | works | buildin | feature | interactive back annotation
construct | 465 | works | buildin | feature | construct complex objects from atoms, break up groups
diag | 71 | works | buildin | feature | Actions for sch-rnd core diagnostics, intended for developers. These are not in core because end users normally don't need these. As a plugin, due to dynamic loading, it can be dropped on an existing sch-rnd installation with minimal risk of scaring away a reproducible bug.
export_abst | 194 | works | buildin | export | export project's abstract model to text
export_bom | 254 | works | buildin | export | export a BoM based on the components of the abstract model, using configurable templates
export_lpr | 14 | works | buildin | export | Export to lpr (using export_ps to generate postscript)
export_png | 267 | works | buildin | export | png, jpeg and gif render
export_ps | 576 | works | buildin | export | PostScript, Encapsulated PostScript exporter
export_spice | 474 | works | buildin | export | SPICE netlist exporter for circuit simulation
export_svg | 219 | works | buildin | export | Scalable Vector Graphics exporter
export_tedax | 259 | works | buildin | export | export netlist as a tEDAx netlist block
gui | 1415 | works | buildin | gui | sch-rnd-specific GUI elements
io_altium | 2444 | works | buildin | io | Load schematics from altium schdoc
io_geda | 1236 | works | buildin | io | Load schematics and symbols from gEDA format.
io_lihata | 1576 | works | buildin | io | Load and save the schematics and symbols in the native lihata format.
io_ngrp_fawk | 259 | works | buildin | io | non-graphical schematic sheets in form of fawk scripts.
io_ngrp_tedax | 393 | works | buildin | io | Load non-graphical schematic sheets in tEDAx format.
io_tinycad | 1511 | works | buildin | io | Load schematics from TinyCAD .dsn xml format.
lib_alien | 623 | works | buildin | io | Format-independent helper functions for reading alien files
lib_netlist_exp | 62 | works | buildin | export | Helper functions for exporting netlists
lib_ngrp | 241 | works | buildin | io | Helper functions for handling non-graphical sheets
lib_plot | 639 | works | disable-all | gui | subdialog for plotting and navigating graphs
lib_target | 133 | works | buildin | export | Helper functions for implementing target plugins
place | 137 | works | buildin | feature | place complex objects such as terminals from template
propedit | 2203 | works | buildin | feature | List and edit properties of a group of objects.
query | 4245 | works | buildin | feature | sch-rnd query language: execute expressions on objects and rules for the programmed drc.
renumber | 333 | works | buildin | feature | Systematically change the name of selected symbols
sch_dialogs | 6545 | works | buildin | gui | Standard schematics editor dialog boxes
sim | 1695 | works | buildin | feature | abstract differences of circuit simiulation implementations, provide an unified interface (infrastructure, CLI and actions)
sim_gui | 2138 | works | buildin | feature | GUI for the the a unified high level simulation interface
sim_ngspice | 438 | works | buildin | feature | ngspice specific execution glue (for the GUI)
std_cschem | 342 | works | buildin | engine | Handles: component connect
std_devmap | 1007 | works | buildin | engine | Handles slotting, device mapping and port mapping
std_forge | 2088 | works | buildin | engine | Handles: attribute forging
std_tools | 1461 | works | buildin | feature | Tools for drawing standard cschem concrete primitives
symlib_fs | 119 | works | buildin | symlib | access symbol libraries stored on the local file system
symlib_local | 696 | works | buildin | symlib | access symbol library stored within the sheet
target_none | 46 | works | buildin | engine | Display original names
target_pcb | 176 | works | buildin | engine | Attribute transformations for the PCB workflow
target_spice | 1096 | works | buildin | engine | Attribute transformations for the SPICE workflow

### Classes

Each plugin implements a class (rarely a set of classes). Classes are:

name | description
--- | ---
feature | random features directly accessible for the user, usually actions
lib | support code library for other plugins (core doesn't depend on these); functionality not directly accessible for the user but other plugins may depend on it
import | load alien formats into the design space
export | save (parts of) the design space in alien formats
io | native file format (save & load) implementation

### Status

Common status column values mean:

name | description
--- | ---
works | production quality code - configures, compiles, tested
WIP | work in progress: the plugin may be avaialble for testing but is not yet production quality
abandoned | unmaintained plugin; may be in working condition but there is no developer supporting it
deprecated | legacy plugin scheduled for removal; may still work but will soon be removed; if your workflow depends on it, please report ASAP

### Plugin dependency map