Compose board tool (compose_board.py)
tools/compose_board.py builds a base board from routed module boards. It copies each module's footprints, tracks, vias, pours and drawings onto the base board as one tile (a KiCad group named after the sheet). It turns the tile 0 or 180° and moves it, and renames references and nets to the base board's schematic. The modules stay the source: rebuild to pick up a changed module.
Use
. tools/kicad_env.sh
cp libraries/templates/DIN_6TE/DIN_6TE.kicad_pcb myboard/myboard.kicad_pcb # start from an empty template
$KPY tools/compose_board.py myboard/compose.json
$KPY tools/sync_board.py myboard/out/myboard.net myboard/myboard.kicad_pcb # paths, values, fields
$KPY tools/silk_refs.py myboard/myboard.kicad_pcb
Close the board in KiCad first. The .kicad_pro is restored after SaveBoard.
Requirements on the schematic
- References offset per sheet: the base schematic uses the modules' block sheets with references offset per sheet (
U1→U601with offset 600). A block used twice is one sheet file with two instance paths. - Nets through the pads: nets come from the base netlist through the pads. A module net takes the base net of its pads (
/Iso/GND_ISO→/Iso 1/GND_ISO,/Iso/TXD→/MB1_TXD). All pads of a module net must agree, or the script stops and lists them. repin: a pad whose net the root sheet changed, such as an address strap that is GND in the module and +3V3 on the base board. Its module copper is left out from the pad up to the first via or junction. A pad that loses its only link shows in DRC as unconnected.
Spec (JSON)
board,netlist;modules: per moduleboard,sheet,offset;block: the module's block rectangle in its own coordinates (pours, not the test outline);rot(0 or 180);at: top-left corner of the turned block on the base board;skip: e.g. the module's housing post, which the base template already has;repin;
parts: base-sheet parts (pull-ups) placed from the netlist's footprint;tabs:bottom/topconnector lists for connector_tab.add_tabs.tab_merge(mm, default 3): bodies closer than this share one tab.- The template outline is a
gr_rect. Compose turns it into segments first, soadd_tabscan split them.
What it handles and what not
- Each tile's pours get priority
module priority + index. Butting tiles' GND pours touch, which DRC reports aszones_intersectat equal priority. - Copies keep the module's routing exactly. Base-board nets between tiles stay unrouted; route them afterwards, e.g. with the Router and the whole board as
[[fixed]]copper. - Rotations other than 0/180° are not tested.
- KiCad API notes:
FOOTPRINT.Duplicate(addToParentGroup)takes an argument; the other items'Duplicate()takes none.- Cast copies with
Cast_to_FOOTPRINT,Cast_to_ZONEand.Cast(). - Pads keep the source board's net objects until
SetNetis called with the base board's.
Related: KiCad notes (sync_board), Placer, DIN-rail board format.
