cadbuildr-electronics 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. cadbuildr_electronics-0.1.0/.gitignore +31 -0
  2. cadbuildr_electronics-0.1.0/CHANGELOG.md +16 -0
  3. cadbuildr_electronics-0.1.0/LICENSE +21 -0
  4. cadbuildr_electronics-0.1.0/PKG-INFO +185 -0
  5. cadbuildr_electronics-0.1.0/README.md +174 -0
  6. cadbuildr_electronics-0.1.0/cadbuildr/__init__.py +3 -0
  7. cadbuildr_electronics-0.1.0/cadbuildr/electronics/__init__.py +120 -0
  8. cadbuildr_electronics-0.1.0/cadbuildr/electronics/_solids.py +89 -0
  9. cadbuildr_electronics-0.1.0/cadbuildr/electronics/board.py +117 -0
  10. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/__init__.py +16 -0
  11. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/arduino_nano.py +59 -0
  12. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/arduino_uno.py +98 -0
  13. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/esp32_devkit.py +62 -0
  14. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/raspberry_pi.py +82 -0
  15. cadbuildr_electronics-0.1.0/cadbuildr/electronics/boards/raspberry_pi_pico.py +70 -0
  16. cadbuildr_electronics-0.1.0/cadbuildr/electronics/catalog/__init__.py +10 -0
  17. cadbuildr_electronics-0.1.0/cadbuildr/electronics/catalog/catalog.py +126 -0
  18. cadbuildr_electronics-0.1.0/cadbuildr/electronics/catalog/digikey.py +200 -0
  19. cadbuildr_electronics-0.1.0/cadbuildr/electronics/catalog/package.py +37 -0
  20. cadbuildr_electronics-0.1.0/cadbuildr/electronics/catalog/part.py +37 -0
  21. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/__init__.py +44 -0
  22. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/connectors.py +178 -0
  23. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/diodes.py +68 -0
  24. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/ics.py +139 -0
  25. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/misc.py +59 -0
  26. cadbuildr_electronics-0.1.0/cadbuildr/electronics/components/passives.py +147 -0
  27. cadbuildr_electronics-0.1.0/cadbuildr/electronics/constants.py +65 -0
  28. cadbuildr_electronics-0.1.0/cadbuildr/electronics/data/packages.json +33 -0
  29. cadbuildr_electronics-0.1.0/cadbuildr/electronics/data/parts.csv +11 -0
  30. cadbuildr_electronics-0.1.0/cadbuildr/electronics/families/__init__.py +14 -0
  31. cadbuildr_electronics-0.1.0/cadbuildr/electronics/families/_ipc.py +82 -0
  32. cadbuildr_electronics-0.1.0/cadbuildr/electronics/families/base.py +91 -0
  33. cadbuildr_electronics-0.1.0/cadbuildr/electronics/families/generators.py +173 -0
  34. cadbuildr_electronics-0.1.0/cadbuildr/electronics/footprint.py +207 -0
  35. cadbuildr_electronics-0.1.0/cadbuildr/electronics/pcb.py +209 -0
  36. cadbuildr_electronics-0.1.0/cadbuildr/electronics/projects.py +76 -0
  37. cadbuildr_electronics-0.1.0/docs/COMPONENT_REFERENCE.md +130 -0
  38. cadbuildr_electronics-0.1.0/docs/SCALING.md +124 -0
  39. cadbuildr_electronics-0.1.0/docs/VISUAL_VERIFICATION.md +79 -0
  40. cadbuildr_electronics-0.1.0/docs/gallery/arduino_uno.png +0 -0
  41. cadbuildr_electronics-0.1.0/docs/gallery/blinky.png +0 -0
  42. cadbuildr_electronics-0.1.0/docs/gallery/catalog_generated.png +0 -0
  43. cadbuildr_electronics-0.1.0/docs/gallery/components.png +0 -0
  44. cadbuildr_electronics-0.1.0/docs/gallery/raspberry_pi.png +0 -0
  45. cadbuildr_electronics-0.1.0/examples/blinky.py +23 -0
  46. cadbuildr_electronics-0.1.0/examples/reference_boards.py +18 -0
  47. cadbuildr_electronics-0.1.0/github-io/.env.example +17 -0
  48. cadbuildr_electronics-0.1.0/github-io/.env.local +3 -0
  49. cadbuildr_electronics-0.1.0/github-io/.gitignore +1 -0
  50. cadbuildr_electronics-0.1.0/github-io/README.md +64 -0
  51. cadbuildr_electronics-0.1.0/github-io/index.html +20 -0
  52. cadbuildr_electronics-0.1.0/github-io/package.json +33 -0
  53. cadbuildr_electronics-0.1.0/github-io/src/kernelApiEnv.ts +10 -0
  54. cadbuildr_electronics-0.1.0/github-io/src/main.tsx +505 -0
  55. cadbuildr_electronics-0.1.0/github-io/src/pcbLocal.ts +5 -0
  56. cadbuildr_electronics-0.1.0/github-io/src/styles.css +422 -0
  57. cadbuildr_electronics-0.1.0/github-io/src/vite-env.d.ts +10 -0
  58. cadbuildr_electronics-0.1.0/github-io/tsconfig.json +32 -0
  59. cadbuildr_electronics-0.1.0/github-io/vite.config.ts +50 -0
  60. cadbuildr_electronics-0.1.0/pyproject.toml +33 -0
  61. cadbuildr_electronics-0.1.0/scripts/check_collisions.py +118 -0
  62. cadbuildr_electronics-0.1.0/scripts/render.py +303 -0
  63. cadbuildr_electronics-0.1.0/tests/test_catalog.py +93 -0
  64. cadbuildr_electronics-0.1.0/tests/test_pcb.py +184 -0
@@ -0,0 +1,31 @@
1
+ # Python cache and bytecode
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual environments and local tooling
7
+ .venv/
8
+ venv/
9
+ .python-version
10
+
11
+ # Test and type-check caches
12
+ .pytest_cache/
13
+ .mypy_cache/
14
+ .ruff_cache/
15
+ .coverage
16
+ .coverage.*
17
+ htmlcov/
18
+
19
+ # Build artifacts
20
+ build/
21
+ dist/
22
+ *.egg-info/
23
+ *.egg
24
+
25
+ # OS/editor noise
26
+ .DS_Store
27
+ .idea/
28
+ .vscode/
29
+
30
+ # github-io (Vite / npm)
31
+ github-io/node_modules/
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## 0.1.0 - 2026-06-26
6
+
7
+ - Initial public release of `cadbuildr.electronics`.
8
+ - 3D PCB component library (resistors, capacitors, LEDs, pin headers, USB /
9
+ Ethernet connectors, DIP / SOIC / QFP ICs, crystals, buttons) with a
10
+ footprint-driven `PCB` assembly that drills the board and seats parts in one
11
+ call.
12
+ - Reference boards built from the library: Arduino Uno (genuine R3 edge-cut
13
+ outline), Arduino Nano, Raspberry Pi, Raspberry Pi Pico, ESP32 DevKitC.
14
+ - Components live in a `components` sub-assembly so the viewer can show a bare,
15
+ drilled board and reveal the population via the assembly tree.
16
+ - `github-io/` interactive demo (Pyodide + `@cadbuildr/sdk-react` viewer).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CADbuildr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.4
2
+ Name: cadbuildr-electronics
3
+ Version: 0.1.0
4
+ Summary: 3D models of common PCB components plus a footprint-driven framework for assembling them into boards
5
+ Author: CADbuildr Team
6
+ License-File: LICENSE
7
+ Requires-Python: <4.0.0,>=3.10.0
8
+ Requires-Dist: cadbuildr-foundation<0.3.0,>=0.2.12
9
+ Requires-Dist: cadbuildr-stdlib<0.0.1,>=0.0.0.2
10
+ Description-Content-Type: text/markdown
11
+
12
+ # cadbuildr.electronics
13
+
14
+ ## Summary
15
+
16
+ 3D models of common printed-circuit-board components (resistors, capacitors,
17
+ LEDs, pin headers, USB / Ethernet connectors, ICs, crystals, …) plus a small,
18
+ reusable framework for placing them onto boards. The framework's headline
19
+ feature is a **footprint dual-action**: a single `place(...)` call both drills
20
+ the component's land pattern into the board *and* seats its 3D body in the
21
+ assembly, so the two can never drift apart.
22
+
23
+ ## Tags
24
+
25
+ cad, python, pcb, electronics, footprint, assembly
26
+
27
+ ## Status
28
+
29
+ yellow
30
+
31
+ ## Guidelines
32
+
33
+ - A component owns its footprint. Define the pads **once** (in `footprint()`),
34
+ never separately on the board.
35
+ - All dimensions are millimetres; through-hole pads use `drill > 0`, SMD lands
36
+ use `drill == 0`. The board is the only thing that drills holes.
37
+ - Keep component bodies built from the proven `Sketch` + `Extrusion` primitives
38
+ (see `_solids.py`) so DAG generation stays kernel-agnostic and testable.
39
+ - Reference boards (`boards/`) are stylised approximations for visual
40
+ validation — recognisable, not pin-accurate clones.
41
+
42
+ ## Install / develop
43
+
44
+ ```bash
45
+ # from the monorepo py/ workspace
46
+ uv run --package cadbuildr-electronics pytest packages/cadbuildr/electronics/tests
47
+ ```
48
+
49
+ ## Quick start
50
+
51
+ ```python
52
+ from cadbuildr.foundation import show
53
+ from cadbuildr.electronics import PCB, PinHeader, Resistor, LED
54
+
55
+ pcb = PCB(50, 24, color="blue")
56
+ pcb.place(PinHeader(positions=2), ref="J1", x=-20, y=0) # drills board + seats body
57
+ pcb.place(Resistor("220"), ref="R1", x=-2, y=0)
58
+ pcb.place(LED("red"), ref="D1", x=18, y=0)
59
+ show(pcb)
60
+ ```
61
+
62
+ Declarative form (the "standard format" of components + placements):
63
+
64
+ ```python
65
+ from cadbuildr.electronics import PCB, Placement, Resistor, LED, PinHeader
66
+
67
+ PCB.from_placements(50, 24, [
68
+ Placement(PinHeader(positions=2), "J1", -20, 0),
69
+ Placement(Resistor("220"), "R1", -2, 0),
70
+ Placement(LED("red"), "D1", 18, 0, rotation=0),
71
+ ])
72
+ ```
73
+
74
+ ## Scaling to catalog size
75
+
76
+ Writing a class per part doesn't scale; Digi-Key's ~18 M part numbers collapse
77
+ onto ~15 k footprints and a few dozen **package families**, because geometry is
78
+ a pure function of `Package/Case + Mounting + pins + pitch`, never the
79
+ electrical value. So there's a **data-driven catalog layer** (`catalog/`,
80
+ `families/`, `data/`):
81
+
82
+ ```
83
+ K family generators ◀── M packages (data) ◀── N parts (data)
84
+ families/ data/packages.json data/parts.csv
85
+ ```
86
+
87
+ ```python
88
+ from cadbuildr.electronics import Catalog, PCB
89
+ cat = Catalog.load()
90
+ pcb = PCB(40, 30)
91
+ pcb.place(cat.build_part("ATMEGA328P-AU"), "U1", 0, 0) # MPN → TQFP-32, generated
92
+ pcb.place(cat.build_part("NE555P"), "U2", 12, -8) # MPN → DIP-8, generated
93
+
94
+ # ingest a Digi-Key Package/Case string straight to geometry:
95
+ cat.resolve_package_case("0805 (2012 Metric)", mounting="Surface Mount") # → R_0805
96
+ ```
97
+
98
+ Adding a part is one CSV row; a new package is one JSON row; a new family is one
99
+ generator class. Land patterns are generated to **IPC-7351B**. Full design in
100
+ [`docs/SCALING.md`](docs/SCALING.md). Generated parts on a board:
101
+
102
+ ![generated parts](docs/gallery/catalog_generated.png)
103
+
104
+ ## How the dual-action works
105
+
106
+ ```
107
+ component.footprint() ─┬─▶ board.apply_footprint(...) # cut holes / paint pads
108
+ └─▶ assembly.add_component(...) # seat the 3D body
109
+ (same x, y, rotation maths → holes always line up)
110
+ ```
111
+
112
+ - **`Footprint` / `Pad`** (`footprint.py`) — the single source of truth for a
113
+ part's pads. `transformed_pads(x, y, rot)` is shared by the board and the
114
+ assembly, which is what makes placement non error-prone.
115
+ - **`ElectronicComponent`** — base class for parts; subclasses build geometry
116
+ and implement `footprint()`. Any `Part` can instead be decorated with
117
+ `@footprint(...)`.
118
+ - **`PCBBoard`** (`board.py`) — the FR-4 slab; `apply_footprint` / `drill`.
119
+ - **`PCB`** (`pcb.py`) — the `Assembly` template that wires the two together
120
+ and exposes `place`, `from_placements`, `mounting_holes_rect` and `bom`.
121
+
122
+ ## What's in the box
123
+
124
+ | Family | Parts |
125
+ |--------|-------|
126
+ | Passives | `Resistor`, `ResistorSMD`, `CeramicCapacitor`, `ElectrolyticCapacitor` |
127
+ | Diodes | `LED`, `Diode` |
128
+ | Connectors | `PinHeader`, `ScrewTerminal`, `USBTypeA`, `USBMicroB`, `RJ45`, `BarrelJack` |
129
+ | ICs | `DIP`, `SOIC`, `QFP` |
130
+ | Misc | `Crystal`, `TactileButton` |
131
+ | Boards | `ArduinoUno`, `RaspberryPi` (reference assemblies) |
132
+
133
+ For the standard names (KiCad / JEDEC / IPC), canonical dimensions, and
134
+ authoritative + license-clean 3D-model sources behind each part, see
135
+ [`docs/COMPONENT_REFERENCE.md`](docs/COMPONENT_REFERENCE.md).
136
+
137
+ ## Visual verification
138
+
139
+ The library is checked by actually *rendering* it. `scripts/render.py` sends a
140
+ part's DAG to a local **kernel-api** (the same replicad/OpenCascade kernel the
141
+ web viewer uses — no GPU, no display, no cloud auth) and rasterizes the colored
142
+ mesh to a PNG. Full setup in
143
+ [`docs/VISUAL_VERIFICATION.md`](docs/VISUAL_VERIFICATION.md):
144
+
145
+ ```bash
146
+ # kernel-api running locally on :8087 (see the doc), then:
147
+ python scripts/render.py --target arduino -o /tmp/arduino.png
148
+ python scripts/render.py --gallery -o /tmp/pcb_gallery
149
+ ```
150
+
151
+ Checked-in reference renders (regenerate any time):
152
+
153
+ ![component gallery](docs/gallery/components.png)
154
+
155
+ | Arduino Uno | Raspberry Pi |
156
+ |---|---|
157
+ | ![Arduino](docs/gallery/arduino_uno.png) | ![Raspberry Pi](docs/gallery/raspberry_pi.png) |
158
+
159
+ ## Dependencies
160
+
161
+ ### Upstream
162
+
163
+ - cadbuildr-foundation
164
+ - cadbuildr-stdlib
165
+
166
+ ### Downstream
167
+
168
+ - (none)
169
+
170
+ ## GitHub Pages demo (Vite + R3F)
171
+
172
+ A static browser demo (`kernel-api` + Pyodide) lives in `github-io/`, mirroring
173
+ the `lego` project. It depends on `@buildr/cad-kernel-r3f` and
174
+ `@buildr/cad-pyodide-runtime` via `workspace:*`, so install/run it from the
175
+ monorepo `tsjs/` root:
176
+
177
+ ```bash
178
+ cd py/packages/cadbuildr/electronics && uv build # produce the wheel
179
+ cd ../../../../tsjs && pnpm install && pnpm run pcb:demo
180
+ ```
181
+
182
+ See `github-io/README.md` for wheel sync, static build, and GitHub Pages notes.
183
+ This package is also wired as a git submodule mirror (like the other open
184
+ `cadbuildr.*` packages), so the `github-io/` folder travels with the package
185
+ when it is published to its standalone repo.
@@ -0,0 +1,174 @@
1
+ # cadbuildr.electronics
2
+
3
+ ## Summary
4
+
5
+ 3D models of common printed-circuit-board components (resistors, capacitors,
6
+ LEDs, pin headers, USB / Ethernet connectors, ICs, crystals, …) plus a small,
7
+ reusable framework for placing them onto boards. The framework's headline
8
+ feature is a **footprint dual-action**: a single `place(...)` call both drills
9
+ the component's land pattern into the board *and* seats its 3D body in the
10
+ assembly, so the two can never drift apart.
11
+
12
+ ## Tags
13
+
14
+ cad, python, pcb, electronics, footprint, assembly
15
+
16
+ ## Status
17
+
18
+ yellow
19
+
20
+ ## Guidelines
21
+
22
+ - A component owns its footprint. Define the pads **once** (in `footprint()`),
23
+ never separately on the board.
24
+ - All dimensions are millimetres; through-hole pads use `drill > 0`, SMD lands
25
+ use `drill == 0`. The board is the only thing that drills holes.
26
+ - Keep component bodies built from the proven `Sketch` + `Extrusion` primitives
27
+ (see `_solids.py`) so DAG generation stays kernel-agnostic and testable.
28
+ - Reference boards (`boards/`) are stylised approximations for visual
29
+ validation — recognisable, not pin-accurate clones.
30
+
31
+ ## Install / develop
32
+
33
+ ```bash
34
+ # from the monorepo py/ workspace
35
+ uv run --package cadbuildr-electronics pytest packages/cadbuildr/electronics/tests
36
+ ```
37
+
38
+ ## Quick start
39
+
40
+ ```python
41
+ from cadbuildr.foundation import show
42
+ from cadbuildr.electronics import PCB, PinHeader, Resistor, LED
43
+
44
+ pcb = PCB(50, 24, color="blue")
45
+ pcb.place(PinHeader(positions=2), ref="J1", x=-20, y=0) # drills board + seats body
46
+ pcb.place(Resistor("220"), ref="R1", x=-2, y=0)
47
+ pcb.place(LED("red"), ref="D1", x=18, y=0)
48
+ show(pcb)
49
+ ```
50
+
51
+ Declarative form (the "standard format" of components + placements):
52
+
53
+ ```python
54
+ from cadbuildr.electronics import PCB, Placement, Resistor, LED, PinHeader
55
+
56
+ PCB.from_placements(50, 24, [
57
+ Placement(PinHeader(positions=2), "J1", -20, 0),
58
+ Placement(Resistor("220"), "R1", -2, 0),
59
+ Placement(LED("red"), "D1", 18, 0, rotation=0),
60
+ ])
61
+ ```
62
+
63
+ ## Scaling to catalog size
64
+
65
+ Writing a class per part doesn't scale; Digi-Key's ~18 M part numbers collapse
66
+ onto ~15 k footprints and a few dozen **package families**, because geometry is
67
+ a pure function of `Package/Case + Mounting + pins + pitch`, never the
68
+ electrical value. So there's a **data-driven catalog layer** (`catalog/`,
69
+ `families/`, `data/`):
70
+
71
+ ```
72
+ K family generators ◀── M packages (data) ◀── N parts (data)
73
+ families/ data/packages.json data/parts.csv
74
+ ```
75
+
76
+ ```python
77
+ from cadbuildr.electronics import Catalog, PCB
78
+ cat = Catalog.load()
79
+ pcb = PCB(40, 30)
80
+ pcb.place(cat.build_part("ATMEGA328P-AU"), "U1", 0, 0) # MPN → TQFP-32, generated
81
+ pcb.place(cat.build_part("NE555P"), "U2", 12, -8) # MPN → DIP-8, generated
82
+
83
+ # ingest a Digi-Key Package/Case string straight to geometry:
84
+ cat.resolve_package_case("0805 (2012 Metric)", mounting="Surface Mount") # → R_0805
85
+ ```
86
+
87
+ Adding a part is one CSV row; a new package is one JSON row; a new family is one
88
+ generator class. Land patterns are generated to **IPC-7351B**. Full design in
89
+ [`docs/SCALING.md`](docs/SCALING.md). Generated parts on a board:
90
+
91
+ ![generated parts](docs/gallery/catalog_generated.png)
92
+
93
+ ## How the dual-action works
94
+
95
+ ```
96
+ component.footprint() ─┬─▶ board.apply_footprint(...) # cut holes / paint pads
97
+ └─▶ assembly.add_component(...) # seat the 3D body
98
+ (same x, y, rotation maths → holes always line up)
99
+ ```
100
+
101
+ - **`Footprint` / `Pad`** (`footprint.py`) — the single source of truth for a
102
+ part's pads. `transformed_pads(x, y, rot)` is shared by the board and the
103
+ assembly, which is what makes placement non error-prone.
104
+ - **`ElectronicComponent`** — base class for parts; subclasses build geometry
105
+ and implement `footprint()`. Any `Part` can instead be decorated with
106
+ `@footprint(...)`.
107
+ - **`PCBBoard`** (`board.py`) — the FR-4 slab; `apply_footprint` / `drill`.
108
+ - **`PCB`** (`pcb.py`) — the `Assembly` template that wires the two together
109
+ and exposes `place`, `from_placements`, `mounting_holes_rect` and `bom`.
110
+
111
+ ## What's in the box
112
+
113
+ | Family | Parts |
114
+ |--------|-------|
115
+ | Passives | `Resistor`, `ResistorSMD`, `CeramicCapacitor`, `ElectrolyticCapacitor` |
116
+ | Diodes | `LED`, `Diode` |
117
+ | Connectors | `PinHeader`, `ScrewTerminal`, `USBTypeA`, `USBMicroB`, `RJ45`, `BarrelJack` |
118
+ | ICs | `DIP`, `SOIC`, `QFP` |
119
+ | Misc | `Crystal`, `TactileButton` |
120
+ | Boards | `ArduinoUno`, `RaspberryPi` (reference assemblies) |
121
+
122
+ For the standard names (KiCad / JEDEC / IPC), canonical dimensions, and
123
+ authoritative + license-clean 3D-model sources behind each part, see
124
+ [`docs/COMPONENT_REFERENCE.md`](docs/COMPONENT_REFERENCE.md).
125
+
126
+ ## Visual verification
127
+
128
+ The library is checked by actually *rendering* it. `scripts/render.py` sends a
129
+ part's DAG to a local **kernel-api** (the same replicad/OpenCascade kernel the
130
+ web viewer uses — no GPU, no display, no cloud auth) and rasterizes the colored
131
+ mesh to a PNG. Full setup in
132
+ [`docs/VISUAL_VERIFICATION.md`](docs/VISUAL_VERIFICATION.md):
133
+
134
+ ```bash
135
+ # kernel-api running locally on :8087 (see the doc), then:
136
+ python scripts/render.py --target arduino -o /tmp/arduino.png
137
+ python scripts/render.py --gallery -o /tmp/pcb_gallery
138
+ ```
139
+
140
+ Checked-in reference renders (regenerate any time):
141
+
142
+ ![component gallery](docs/gallery/components.png)
143
+
144
+ | Arduino Uno | Raspberry Pi |
145
+ |---|---|
146
+ | ![Arduino](docs/gallery/arduino_uno.png) | ![Raspberry Pi](docs/gallery/raspberry_pi.png) |
147
+
148
+ ## Dependencies
149
+
150
+ ### Upstream
151
+
152
+ - cadbuildr-foundation
153
+ - cadbuildr-stdlib
154
+
155
+ ### Downstream
156
+
157
+ - (none)
158
+
159
+ ## GitHub Pages demo (Vite + R3F)
160
+
161
+ A static browser demo (`kernel-api` + Pyodide) lives in `github-io/`, mirroring
162
+ the `lego` project. It depends on `@buildr/cad-kernel-r3f` and
163
+ `@buildr/cad-pyodide-runtime` via `workspace:*`, so install/run it from the
164
+ monorepo `tsjs/` root:
165
+
166
+ ```bash
167
+ cd py/packages/cadbuildr/electronics && uv build # produce the wheel
168
+ cd ../../../../tsjs && pnpm install && pnpm run pcb:demo
169
+ ```
170
+
171
+ See `github-io/README.md` for wheel sync, static build, and GitHub Pages notes.
172
+ This package is also wired as a git submodule mirror (like the other open
173
+ `cadbuildr.*` packages), so the `github-io/` folder travels with the package
174
+ when it is published to its standalone repo.
@@ -0,0 +1,3 @@
1
+ from pkgutil import extend_path
2
+
3
+ __path__ = extend_path(__path__, __name__)
@@ -0,0 +1,120 @@
1
+ """CADbuildr PCB — 3D models of common printed-circuit-board components plus a
2
+ reusable framework for assembling them into boards.
3
+
4
+ Two halves:
5
+
6
+ * **Components** — parametric 3D parts (resistors, capacitors, LEDs, headers,
7
+ USB / Ethernet connectors, ICs, crystals, ...), each of which carries its own
8
+ :class:`~cadbuildr.electronics.footprint.Footprint`.
9
+
10
+ * **Assembly** — :class:`~cadbuildr.electronics.pcb.PCB`, a template that owns a
11
+ :class:`~cadbuildr.electronics.board.PCBBoard` and places components with a
12
+ single dual-action call that keeps the board holes and the 3D bodies in sync.
13
+
14
+ Quick start::
15
+
16
+ from cadbuildr.foundation import show
17
+ from cadbuildr.electronics import PCB, PinHeader, Resistor, LED
18
+
19
+ pcb = PCB(50, 30, color="blue")
20
+ pcb.place(PinHeader(positions=6), ref="J1", x=-18, y=10)
21
+ pcb.place(Resistor("220"), ref="R1", x=0, y=0)
22
+ pcb.place(LED("red"), ref="D1", x=12, y=0)
23
+ show(pcb)
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ from .constants import COLORS, BOARD_COLOR_CHOICES, LED_COLOR_CHOICES
29
+ from .footprint import (
30
+ ElectronicComponent,
31
+ Footprint,
32
+ Pad,
33
+ footprint,
34
+ grid_pads,
35
+ two_pad,
36
+ )
37
+ from .board import PCBBoard, RoundedPCBBoard
38
+ from .pcb import PCB, Components, Placement, BomLine
39
+ from .components import (
40
+ Resistor,
41
+ ResistorSMD,
42
+ CeramicCapacitor,
43
+ ElectrolyticCapacitor,
44
+ LED,
45
+ Diode,
46
+ PinHeader,
47
+ ScrewTerminal,
48
+ USBTypeA,
49
+ USBMicroB,
50
+ RJ45,
51
+ BarrelJack,
52
+ DIP,
53
+ SOIC,
54
+ QFP,
55
+ Crystal,
56
+ TactileButton,
57
+ )
58
+
59
+ # Scale layer: data-driven catalog (parts → packages → family generators) and
60
+ # the parametric generators behind it. Lets the library grow to catalogue size
61
+ # by adding data rows, not classes. See docs/SCALING.md.
62
+ from .families import GeneratedComponent, PackageFamily, families
63
+ from .catalog import Catalog, Package, Part, PackageKey, parse_package_case
64
+
65
+ # Parametric @cadbuildr_project entry points (best-effort: needs a foundation
66
+ # new enough to expose the SDK parameter decorators).
67
+ try:
68
+ from .projects import demo_board, header_strip, blinky
69
+ except Exception: # pragma: no cover - older pinned foundations
70
+ demo_board = header_strip = blinky = None # type: ignore[assignment]
71
+
72
+ __all__ = [
73
+ "COLORS",
74
+ "BOARD_COLOR_CHOICES",
75
+ "LED_COLOR_CHOICES",
76
+ # framework
77
+ "ElectronicComponent",
78
+ "Footprint",
79
+ "Pad",
80
+ "footprint",
81
+ "grid_pads",
82
+ "two_pad",
83
+ "PCBBoard",
84
+ "RoundedPCBBoard",
85
+ "PCB",
86
+ "Components",
87
+ "Placement",
88
+ "BomLine",
89
+ # components
90
+ "Resistor",
91
+ "ResistorSMD",
92
+ "CeramicCapacitor",
93
+ "ElectrolyticCapacitor",
94
+ "LED",
95
+ "Diode",
96
+ "PinHeader",
97
+ "ScrewTerminal",
98
+ "USBTypeA",
99
+ "USBMicroB",
100
+ "RJ45",
101
+ "BarrelJack",
102
+ "DIP",
103
+ "SOIC",
104
+ "QFP",
105
+ "Crystal",
106
+ "TactileButton",
107
+ # scale layer
108
+ "GeneratedComponent",
109
+ "PackageFamily",
110
+ "families",
111
+ "Catalog",
112
+ "Package",
113
+ "Part",
114
+ "PackageKey",
115
+ "parse_package_case",
116
+ # projects
117
+ "demo_board",
118
+ "header_strip",
119
+ "blinky",
120
+ ]
@@ -0,0 +1,89 @@
1
+ """Tiny geometry helpers shared by the component bodies.
2
+
3
+ Everything is expressed in the component's *local* frame: the board top sits at
4
+ ``z = 0`` and the body grows in ``+Z``. Leads grow in ``-Z`` (down through the
5
+ board). All helpers add operations to a foundation ``Part`` and return it.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from cadbuildr.foundation import (
11
+ Circle,
12
+ Extrusion,
13
+ Part,
14
+ Point,
15
+ Rectangle,
16
+ Sketch,
17
+ )
18
+
19
+
20
+ def add_box(
21
+ part: Part,
22
+ width: float,
23
+ depth: float,
24
+ height: float,
25
+ cx: float = 0.0,
26
+ cy: float = 0.0,
27
+ z0: float = 0.0,
28
+ ) -> Part:
29
+ """Axis-aligned box centred at ``(cx, cy)`` spanning ``z0 .. z0+height``."""
30
+ sketch = Sketch(part.xy())
31
+ rect = Rectangle.from_center_and_sides(Point(sketch, cx, cy), width, depth)
32
+ part.add_operation(Extrusion(rect, z0, z0 + height))
33
+ return part
34
+
35
+
36
+ def add_cylinder_z(
37
+ part: Part,
38
+ radius: float,
39
+ height: float,
40
+ cx: float = 0.0,
41
+ cy: float = 0.0,
42
+ z0: float = 0.0,
43
+ ) -> Part:
44
+ """Vertical cylinder (axis along +Z) from ``z0`` to ``z0+height``."""
45
+ sketch = Sketch(part.xy())
46
+ circle = Circle(Point(sketch, cx, cy), radius)
47
+ part.add_operation(Extrusion(circle, z0, z0 + height))
48
+ return part
49
+
50
+
51
+ def add_cylinder_x(
52
+ part: Part,
53
+ radius: float,
54
+ length: float,
55
+ cy: float = 0.0,
56
+ cz: float = 0.0,
57
+ x0: float | None = None,
58
+ ) -> Part:
59
+ """Horizontal cylinder whose axis runs along +X.
60
+
61
+ Sketched on the YZ plane (normal = X) and extruded along X. ``cy`` / ``cz``
62
+ locate the axis; the cylinder is centred on X unless ``x0`` is given.
63
+ """
64
+ sketch = Sketch(part.yz())
65
+ circle = Circle(Point(sketch, cy, cz), radius)
66
+ if x0 is None:
67
+ part.add_operation(Extrusion(circle, -length / 2.0, length / 2.0))
68
+ else:
69
+ part.add_operation(Extrusion(circle, x0, x0 + length))
70
+ return part
71
+
72
+
73
+ def add_lead_z(part: Part, x: float, y: float, radius: float = 0.25, depth: float = 3.5) -> Part:
74
+ """A round through-hole lead at ``(x, y)`` dropping from the board top
75
+ (``z = 0``) down to ``z = -depth``."""
76
+ sketch = Sketch(part.xy())
77
+ circle = Circle(Point(sketch, x, y), radius)
78
+ part.add_operation(Extrusion(circle, -depth, 0.0))
79
+ return part
80
+
81
+
82
+ def add_pin_z(
83
+ part: Part, x: float, y: float, side: float, top: float, bottom: float
84
+ ) -> Part:
85
+ """A square pin (e.g. a header post) at ``(x, y)`` spanning ``bottom..top``."""
86
+ sketch = Sketch(part.xy())
87
+ rect = Rectangle.from_center_and_sides(Point(sketch, x, y), side, side)
88
+ part.add_operation(Extrusion(rect, bottom, top))
89
+ return part