cadbuildr-flatpack 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.
@@ -0,0 +1,36 @@
1
+ name: python
2
+
3
+ # Tests for cadbuildr-flatpack as a standalone repository. CADbuildr dependencies
4
+ # install from their public repositories until their releases are on PyPI
5
+ # (temporary: switch to plain PyPI pins once they are published).
6
+
7
+ on:
8
+ push:
9
+ branches: [master, main]
10
+ pull_request:
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ python-version: ["3.11", "3.12"]
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - name: Install uv
26
+ uses: astral-sh/setup-uv@v6
27
+ - name: Set up Python
28
+ run: uv python install ${{ matrix.python-version }}
29
+ - name: Create the environment
30
+ run: |
31
+ uv venv --python ${{ matrix.python-version }}
32
+ uv pip install --no-deps "cadbuildr-foundation @ git+https://github.com/cadbuildr/foundation@master"
33
+ uv pip install --no-deps "cadbuildr-stdlib @ git+https://github.com/cadbuildr/stdlib@master"
34
+ uv pip install -e . "pytest>=8"
35
+ - name: Test
36
+ run: uv run --no-sync pytest -q
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - First release as a standalone repository (moved out of the CADbuildr monorepo).
@@ -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,93 @@
1
+ Metadata-Version: 2.5
2
+ Name: cadbuildr-flatpack
3
+ Version: 0.1.0
4
+ Summary: Laser-cut and CNC-routed sheet construction: panels, kerf-compensated joints, box generators, flat DXF/SVG export with nesting
5
+ Author: CADbuildr Team
6
+ License-File: LICENSE
7
+ Requires-Python: <4.0.0,>=3.10.0
8
+ Requires-Dist: cadbuildr-foundation<0.4.0,>=0.3.0
9
+ Requires-Dist: cadbuildr-stdlib>=0.4.0
10
+ Requires-Dist: numpy<3.0.0,>=2.2.6
11
+ Description-Content-Type: text/markdown
12
+
13
+ # cadbuildr-flatpack
14
+
15
+ ## Summary
16
+
17
+ Laser-cut and CNC-routed sheet construction: panels cut from a sheet + machine profile, joints
18
+ that cut both panels (finger, slot-and-tab, cross halving, T-slot bolts with stdlib hardware,
19
+ living hinge), box / enclosure / grid generators, nested DXF / SVG export and cut validation.
20
+
21
+ ## Tags
22
+
23
+ cad, python, library, laser-cutting, cnc, flat-pack, plywood, dxf, svg, nesting
24
+
25
+ ## Status
26
+
27
+ yellow — P0 content shipped (panels, 6 joints, 4 generators, export, validation)
28
+
29
+ ## Guidelines
30
+
31
+ - Every feature reads the panel's `Sheet` (measured thickness) and `Machine` (kerf, bit, clearance).
32
+ - Joints place panels with anchors + `RigidJoint` and cut both panels; never `translate`.
33
+ - 3D cuts and the 2D cut model come from the same edge features (3D == exported DXF).
34
+ - Fail loudly with named errors (`FitError`, `CornerConflict`, `TSlotError`...).
35
+ - Standard hardware comes from stdlib and connects by interface (`ScrewHole`, `NutSeat`).
36
+
37
+ ## Dependencies
38
+
39
+ ### Upstream
40
+
41
+ - `cadbuildr-foundation` (library configurables, anchors / joints, interfaces)
42
+ - `cadbuildr-stdlib` (DIN 912 screws, DIN 934 nuts for T-slot joints)
43
+ - `numpy`
44
+
45
+ ### Downstream
46
+
47
+ - Prototype app demo videos (finger box, T-slot enclosure, egg crate)
48
+
49
+ ## Usage
50
+
51
+ ```python
52
+ from cadbuildr.foundation import show
53
+ from cadbuildr.flatpack import FingerBox, nest, to_dxf, to_svg, sheet_report, check_flatpack
54
+
55
+ box = FingerBox(length=240, width=160, height=110, sheet="Plywood 6 mm", thickness=5.8)
56
+ assert check_flatpack(box) == [] # webs, relief, fit, interface check
57
+ sheets = nest(box) # shelf-packed onto 600 x 400 sheets
58
+ open("box.dxf", "w").write(to_dxf(sheets)) # CUT / ENGRAVE / SHEET layers, kerf compensated
59
+ print(sheet_report(sheets))
60
+ show(box)
61
+ ```
62
+
63
+ | Item | Kind | What it does |
64
+ |---|---|---|
65
+ | `Panel` | part | One flat part: `width`, `height`, `sheet`, measured `thickness`, `machine`, `label`; anchors `origin`, `face_out`, `face_in`, `edge_s/e/n/w` |
66
+ | `finger_joint` | operation | Finger corner between two equal edges, odd count, kerf / clearance / relief aware |
67
+ | `slot_and_tab` | operation | Tabs on one panel's edge through slots in another (T joint) |
68
+ | `cross_halving` | operation | Egg-crate crossing, slotted halfway from opposite edges |
69
+ | `tslot_joint` | operation | Butt joint + DIN 912 screws into T-slots with captive DIN 934 nuts (connected by interface) |
70
+ | `butt_joint` | operation | Plain butt (glue / brads), no cuts |
71
+ | `living_hinge` | operation | Kerf-bending lines across a band: straight, lattice (thirds) or zigzag |
72
+ | `FingerBox` | assembly | Open / closed / lift-off-lid finger-jointed box |
73
+ | `TSlotEnclosure` | assembly | Six-panel bolted case, walls inset so holes keep a web |
74
+ | `EggCrate` | assembly | Grid of cross-halving ribs |
75
+ | `HingeSample` | assembly | Living-hinge test coupon / sleeve |
76
+ | `ShapedPanel` | part | Any straight-sided outline (`"x,y x,y ..."`), edges `e0`, `e1`... take every joint |
77
+ | `KerfCoupon` | part | Comb of test slots (thickness + clearance) and a square kerf gauge, cut as drawn |
78
+ | `stack_joint` | operation | Lay one panel flat on another's face (laminates, lid plates, drawer fronts) |
79
+ | `dovetail_splice` | operation | Coplanar dovetail (puzzle) joint: parts longer than the bed |
80
+ | `DrawerUnit` | assembly | Open-front carcass + finger-jointed drawer + overlay front with pull hole |
81
+ | `PhoneStand` | assembly | Two shaped (mirrored) sides + two tabbed cross bars |
82
+
83
+ Outputs: `flatten`, `nest`, `to_svg`, `to_dxf`, `sheet_report` (incl. cut time + cost), `bom_rows`, `cut_time`.
84
+ Validation: `check_flatpack` (web, relief, fit, nut, plus `Assembly.check()`), `overlap_samples`.
85
+
86
+ ```bash
87
+ python -m cadbuildr.foundation.library manifest cadbuildr.flatpack
88
+ uv run --frozen --no-sync python -m pytest packages/cadbuildr/flatpack -q
89
+ ```
90
+
91
+ Conventions: a panel lies on `x = 0..width`, `y = 0..height`, `z = 0..t`; `z = 0` is the
92
+ outer face. Edges run counter-clockwise (`s`, `e`, `n`, `w`). Positions along an edge are
93
+ panel coordinates (x for `s`/`n`, y for `e`/`w`).
@@ -0,0 +1,81 @@
1
+ # cadbuildr-flatpack
2
+
3
+ ## Summary
4
+
5
+ Laser-cut and CNC-routed sheet construction: panels cut from a sheet + machine profile, joints
6
+ that cut both panels (finger, slot-and-tab, cross halving, T-slot bolts with stdlib hardware,
7
+ living hinge), box / enclosure / grid generators, nested DXF / SVG export and cut validation.
8
+
9
+ ## Tags
10
+
11
+ cad, python, library, laser-cutting, cnc, flat-pack, plywood, dxf, svg, nesting
12
+
13
+ ## Status
14
+
15
+ yellow — P0 content shipped (panels, 6 joints, 4 generators, export, validation)
16
+
17
+ ## Guidelines
18
+
19
+ - Every feature reads the panel's `Sheet` (measured thickness) and `Machine` (kerf, bit, clearance).
20
+ - Joints place panels with anchors + `RigidJoint` and cut both panels; never `translate`.
21
+ - 3D cuts and the 2D cut model come from the same edge features (3D == exported DXF).
22
+ - Fail loudly with named errors (`FitError`, `CornerConflict`, `TSlotError`...).
23
+ - Standard hardware comes from stdlib and connects by interface (`ScrewHole`, `NutSeat`).
24
+
25
+ ## Dependencies
26
+
27
+ ### Upstream
28
+
29
+ - `cadbuildr-foundation` (library configurables, anchors / joints, interfaces)
30
+ - `cadbuildr-stdlib` (DIN 912 screws, DIN 934 nuts for T-slot joints)
31
+ - `numpy`
32
+
33
+ ### Downstream
34
+
35
+ - Prototype app demo videos (finger box, T-slot enclosure, egg crate)
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ from cadbuildr.foundation import show
41
+ from cadbuildr.flatpack import FingerBox, nest, to_dxf, to_svg, sheet_report, check_flatpack
42
+
43
+ box = FingerBox(length=240, width=160, height=110, sheet="Plywood 6 mm", thickness=5.8)
44
+ assert check_flatpack(box) == [] # webs, relief, fit, interface check
45
+ sheets = nest(box) # shelf-packed onto 600 x 400 sheets
46
+ open("box.dxf", "w").write(to_dxf(sheets)) # CUT / ENGRAVE / SHEET layers, kerf compensated
47
+ print(sheet_report(sheets))
48
+ show(box)
49
+ ```
50
+
51
+ | Item | Kind | What it does |
52
+ |---|---|---|
53
+ | `Panel` | part | One flat part: `width`, `height`, `sheet`, measured `thickness`, `machine`, `label`; anchors `origin`, `face_out`, `face_in`, `edge_s/e/n/w` |
54
+ | `finger_joint` | operation | Finger corner between two equal edges, odd count, kerf / clearance / relief aware |
55
+ | `slot_and_tab` | operation | Tabs on one panel's edge through slots in another (T joint) |
56
+ | `cross_halving` | operation | Egg-crate crossing, slotted halfway from opposite edges |
57
+ | `tslot_joint` | operation | Butt joint + DIN 912 screws into T-slots with captive DIN 934 nuts (connected by interface) |
58
+ | `butt_joint` | operation | Plain butt (glue / brads), no cuts |
59
+ | `living_hinge` | operation | Kerf-bending lines across a band: straight, lattice (thirds) or zigzag |
60
+ | `FingerBox` | assembly | Open / closed / lift-off-lid finger-jointed box |
61
+ | `TSlotEnclosure` | assembly | Six-panel bolted case, walls inset so holes keep a web |
62
+ | `EggCrate` | assembly | Grid of cross-halving ribs |
63
+ | `HingeSample` | assembly | Living-hinge test coupon / sleeve |
64
+ | `ShapedPanel` | part | Any straight-sided outline (`"x,y x,y ..."`), edges `e0`, `e1`... take every joint |
65
+ | `KerfCoupon` | part | Comb of test slots (thickness + clearance) and a square kerf gauge, cut as drawn |
66
+ | `stack_joint` | operation | Lay one panel flat on another's face (laminates, lid plates, drawer fronts) |
67
+ | `dovetail_splice` | operation | Coplanar dovetail (puzzle) joint: parts longer than the bed |
68
+ | `DrawerUnit` | assembly | Open-front carcass + finger-jointed drawer + overlay front with pull hole |
69
+ | `PhoneStand` | assembly | Two shaped (mirrored) sides + two tabbed cross bars |
70
+
71
+ Outputs: `flatten`, `nest`, `to_svg`, `to_dxf`, `sheet_report` (incl. cut time + cost), `bom_rows`, `cut_time`.
72
+ Validation: `check_flatpack` (web, relief, fit, nut, plus `Assembly.check()`), `overlap_samples`.
73
+
74
+ ```bash
75
+ python -m cadbuildr.foundation.library manifest cadbuildr.flatpack
76
+ uv run --frozen --no-sync python -m pytest packages/cadbuildr/flatpack -q
77
+ ```
78
+
79
+ Conventions: a panel lies on `x = 0..width`, `y = 0..height`, `z = 0..t`; `z = 0` is the
80
+ outer face. Edges run counter-clockwise (`s`, `e`, `n`, `w`). Positions along an edge are
81
+ panel coordinates (x for `s`/`n`, y for `e`/`w`).
@@ -0,0 +1,139 @@
1
+ ---
2
+ name: cadbuildr-flatpack
3
+ description: Laser-cut / CNC-routed sheet parts (plywood, MDF, acrylic) — Panel from a Sheet (measured thickness) + Machine (kerf, bit, dogbone/T-bone, clearance); joints that place AND cut both panels (finger_joint, slot_and_tab, cross_halving, tslot_joint with stdlib screws/nuts, living_hinge); FingerBox / TSlotEnclosure / EggCrate generators; flatten + nest + DXF/SVG export; check_flatpack validation.
4
+ ---
5
+
6
+ # cadbuildr-flatpack
7
+
8
+ Build anything cut flat from sheet stock and slotted / bolted together.
9
+ **Never hand-model finger notches, slots or T-slots, and never `translate`
10
+ panels into place** — a joint call does both: it places one panel against the
11
+ other (anchor + `RigidJoint`) and cuts both, cut for the sheet's *measured*
12
+ thickness and the machine's clearance. The same cuts feed the flat export, so
13
+ the DXF is exactly the 3D model.
14
+
15
+ ```python
16
+ from cadbuildr.foundation import Assembly, show
17
+ from cadbuildr.flatpack import (
18
+ Panel, finger_joint, slot_and_tab, cross_halving, tslot_joint, living_hinge,
19
+ FingerBox, TSlotEnclosure, EggCrate, check_flatpack, nest, to_dxf, to_svg, sheet_report,
20
+ )
21
+ ```
22
+
23
+ ## 1. Stock and machine (read by every feature)
24
+
25
+ ```python
26
+ Panel(width=200, height=120, sheet="Plywood 6 mm", thickness=5.8, # measured override
27
+ machine="Laser CO2", label="front")
28
+ ```
29
+
30
+ * `sheet`: `"Plywood 3/4/6/9/12/18 mm"`, `"MDF 3/6/12 mm"`, `"Acrylic 3/5 mm"`
31
+ (`SHEETS`; each has nominal + **measured** thickness, sheet size, `min_web`,
32
+ `max_interference`). Custom: `Sheet("Bamboo", 5, 5.2, size_x=600, size_y=400)`.
33
+ * `thickness`: measured thickness override (0 keeps the table value). Change
34
+ it and every joint re-cuts.
35
+ * `machine`: `"Laser CO2"`, `"Laser CO2 press fit"`, `"Laser diode"`,
36
+ `"CNC 6 mm bit dogbone"`, `"CNC 1/4in bit T-bone"`, `"CNC 3 mm bit dogbone"`
37
+ (`MACHINES`; kerf, bit diameter, relief, default clearance). Laser kerf is
38
+ compensated on export; router inside corners get dogbones / T-bones.
39
+
40
+ Panel frame: `x = 0..width`, `y = 0..height`, `z = 0..t`; `z = 0` is the
41
+ OUTER face. Edges run counter-clockwise: `s` (y=0), `e` (x=width), `n`
42
+ (y=height), `w` (x=0). Anchors: `origin`, `face_out`, `face_in`, `edge_<k>`.
43
+
44
+ ## 2. Joints (each places a panel AND cuts both)
45
+
46
+ Ground the first panel (`asm.ground(panel)`; on an empty assembly the first
47
+ joint grounds one of its two panels). A joint between two panels that
48
+ are both placed closes a loop and is checked (`LoopClosureError` if not).
49
+
50
+ ```python
51
+ asm = Assembly()
52
+ bottom, front = Panel(200, 120, label="bottom"), Panel(200, 80, label="front")
53
+ asm.ground(bottom)
54
+ finger_joint(asm, front, "s", bottom, "s") # front stands on bottom's s edge
55
+ ```
56
+
57
+ | Call | Geometry |
58
+ |---|---|
59
+ | `finger_joint(asm, a, a_edge, b, b_edge, fingers=0, fit=None)` | corner, outer faces flush, equal edges; `a` keeps the end fingers (odd count, auto ≈ 3t) |
60
+ | `slot_and_tab(asm, tab_panel, tab_edge, slot_panel, at=, along="x"/"y", start=0, tabs=2)` | tab panel stands on slot panel's inner face on the line `y=at` (along x) / `x=at` (along y) |
61
+ | `cross_halving(asm, a, b, at_a=, at_b=, a_edge="n", b_edge="s")` | egg-crate crossing; positions are panel coordinates along the edges |
62
+ | `tslot_joint(asm, face_panel, face_edge, edge_panel, edge_edge, bolts=2, size="M3", length=0, at=0, inset=0)` | butt + stdlib `DIN912Screw` through clearance holes into T-slots with captive `HexNut`, **connected by interface** (Check: OK) |
63
+ | `butt_joint(asm, face_panel, face_edge, edge_panel, edge_edge, at=0, inset=0)` | plain butt (glue) |
64
+ | `living_hinge(panel, x0, x1, spacing=0, cut_length=0, bridge=3)` | staggered kerf-bending lines across a band |
65
+
66
+ `fit=` overrides the machine clearance per joint (negative = press fit,
67
+ limited by the sheet's `max_interference`). For a box: front/back keep end
68
+ fingers on all their joints, sides keep them against bottom/top — that is what
69
+ `FingerBox` does so every corner cube belongs to one panel.
70
+
71
+ ## 3. Generators
72
+
73
+ ```python
74
+ FingerBox(length=240, width=160, height=110, sheet="Plywood 6 mm", top="closed")
75
+ TSlotEnclosure(length=180, width=120, height=70, size="M3", bolts=2) # 24 screws + 24 nuts
76
+ EggCrate(length=300, width=220, height=60, nx=3, ny=2)
77
+ HingeSample(length=160, width=80, band=40)
78
+ ```
79
+
80
+ `.panels` lists the panels; `TSlotEnclosure.hardware` the (screw, nut) pairs.
81
+
82
+ ## 4. Export
83
+
84
+ ```python
85
+ sheets = nest(box) # per stock; spacing = 4 mm laser / 1.5 bit router
86
+ open("box.svg", "w").write(to_svg(sheets)) # red CUT, blue ENGRAVE labels, grey SHEET
87
+ open("box.dxf", "w").write(to_dxf(sheets)) # R12, layers CUT / ENGRAVE / SHEET, mm
88
+ sheet_report(sheets) # sheets, utilization, cut length (m), weight (kg)
89
+ bom_rows(sheets) # one "Plywood 6 mm sheet" row per stock, qty = sheets
90
+ ```
91
+
92
+ `flatten(obj)` gives one `FlatPart` per panel (outline CCW + holes CW, with
93
+ corner relief); `FlatPart.cut_paths()` adds the half-kerf offset for lasers.
94
+
95
+ ## 5. Validate
96
+
97
+ ```python
98
+ check_flatpack(box) # [] when clean
99
+ ```
100
+
101
+ Codes: `web` (material under the sheet's `min_web` — fingers too thin, hole
102
+ too near an edge: use `inset`), `relief` (corner too small for the bit),
103
+ `fit` (press fit beyond the material), `nut` (info: nut wider than the
104
+ sheet), plus `Assembly.check()` issues for the interface-connected hardware.
105
+ `overlap_samples(asm)` counts points inside two panels (0 = no interference).
106
+
107
+ Errors are named: `FitError` (too many / too narrow fingers, press fit),
108
+ `EdgeMismatch` (unequal finger edges, slot line off the panel), `CornerConflict`,
109
+ `FeatureOverlap` (two joints on one stretch of edge), `WebTooThin`, `TSlotError`
110
+ (screw too short — the message names the length to use), `NestingError`,
111
+ `UnknownStock`.
112
+
113
+ ## 6. More parts and joints
114
+
115
+ ```python
116
+ ShapedPanel("0,0 160,0 120,80 40,80") # any straight-sided outline, edges e0, e1, ...
117
+ ShapedPanel(rounded_rect(120, 80, 10)) # or chamfered_rect(w, h, c); points must be >= 0
118
+ stack_joint(asm, base, top, x=10, y=10, face="in") # laminate / lid plate / drawer front
119
+ dovetail_splice(asm, a, "e", b, "w", tails=3) # coplanar puzzle joint, longer than the bed
120
+ living_hinge(panel, 60, 100, pattern="lattice") # straight | lattice | zigzag
121
+ FingerBox(..., top="lift-off") # loose lid + locating plate inside the walls
122
+ DrawerUnit(width=300, depth=250, height=100) # carcass + drawer + overlay front
123
+ PhoneStand(width=80, angle=65, device=12) # mirrored shaped sides + tabbed bars
124
+ KerfCoupon(sheet="Plywood 3 mm") # cut as drawn; then:
125
+ machine = MACHINES["Laser CO2"].with_kerf(kerf_from_measurement(20, 19.84)).with_clearance(0.0)
126
+ sheet_report(nest(box))["cut_time_min"], sheet_report(nest(box))["cost"]
127
+ ```
128
+
129
+ `finger_box(asm, L, W, H, kw, faces, ...)` builds any subset of the six box
130
+ faces with the corner-ownership rule (used by `DrawerUnit`).
131
+
132
+ ## Gotchas
133
+
134
+ * Positions along an edge are **panel coordinates** (x for `s`/`n`, y for `e`/`w`).
135
+ * One stretch of edge takes one joint; two joints on the same edge must use
136
+ disjoint ranges (`at=` on butt / T-slot joints).
137
+ * Finger counts are odd; `fingers=0` picks one from the thickness.
138
+ * Sheet-metal bending is `sheet_metal.py` (foundation), not this library;
139
+ solid-wood joinery (mortise, dovetail on boards) is `cadbuildr-woodworking`.
@@ -0,0 +1,3 @@
1
+ from pkgutil import extend_path
2
+
3
+ __path__ = extend_path(__path__, __name__)
@@ -0,0 +1,167 @@
1
+ """cadbuildr-flatpack: laser-cut and CNC-routed sheet construction.
2
+
3
+ Everything starts from a sheet and a machine:
4
+
5
+ * :class:`Sheet` / :data:`SHEETS` — material, nominal and **measured**
6
+ thickness, sheet size, minimum web; :class:`Machine` / :data:`MACHINES` —
7
+ laser kerf, router bit + dogbone / T-bone relief, default joint clearance.
8
+ * :class:`Panel` — one flat part; joints cut its edges and faces.
9
+ * Joints (library operations; each places a panel AND cuts both):
10
+ :func:`finger_joint`, :func:`slot_and_tab`, :func:`cross_halving`,
11
+ :func:`tslot_joint` (stdlib DIN 912 screws + DIN 934 nuts connected by
12
+ interface), :func:`butt_joint`, :func:`living_hinge`.
13
+ * Generators: :class:`FingerBox`, :class:`TSlotEnclosure`, :class:`EggCrate`,
14
+ :class:`HingeSample`.
15
+ * Output: :func:`flatten`, :func:`nest`, :func:`to_svg`, :func:`to_dxf`,
16
+ :func:`sheet_report`, :func:`bom_rows`.
17
+ * Validation: :func:`check_flatpack`, :func:`overlap_samples`.
18
+ """
19
+
20
+ from .errors import (
21
+ CornerConflict,
22
+ EdgeMismatch,
23
+ FeatureOverlap,
24
+ FitError,
25
+ FlatpackError,
26
+ NestingError,
27
+ NotPlaced,
28
+ TSlotError,
29
+ UnknownStock,
30
+ WebTooThin,
31
+ )
32
+ from .export import (
33
+ FlatPart,
34
+ SheetLayout,
35
+ bom_rows,
36
+ cut_time,
37
+ flatten,
38
+ nest,
39
+ panels_of,
40
+ sheet_report,
41
+ to_dxf,
42
+ to_svg,
43
+ )
44
+ from .calibration import KerfCoupon, coupon_clearances, kerf_from_measurement
45
+ from .generators import (
46
+ DrawerUnit,
47
+ EggCrate,
48
+ FingerBox,
49
+ HingeSample,
50
+ PhoneStand,
51
+ TSlotEnclosure,
52
+ finger_box,
53
+ )
54
+ from .joints import (
55
+ SCREW_LENGTHS,
56
+ butt_joint,
57
+ cross_halving,
58
+ dovetail_splice,
59
+ finger_count,
60
+ finger_joint,
61
+ living_hinge,
62
+ slot_and_tab,
63
+ stack_joint,
64
+ tslot_joint,
65
+ )
66
+ from .panel import EDGES, Panel, ShapedPanel, chamfered_rect, parse_points, rounded_rect
67
+ from .stock import MACHINES, SHEETS, Machine, Sheet, resolve_machine, resolve_sheet
68
+ from .validate import check_flatpack, check_panel, overlap_samples
69
+
70
+ LIBRARY_ID = "flatpack"
71
+ LIBRARY_NAME = "Flatpack (laser & CNC sheet parts)"
72
+ LIBRARY_TAB = "Flatpack"
73
+
74
+ TOOLBAR = {
75
+ "tab": "Flatpack",
76
+ "sections": [
77
+ {
78
+ "id": "panels",
79
+ "label": "Panels",
80
+ "items": ["Panel", "ShapedPanel", "KerfCoupon"],
81
+ },
82
+ {
83
+ "id": "joints",
84
+ "label": "Joints",
85
+ "items": [
86
+ "finger_joint",
87
+ "slot_and_tab",
88
+ "cross_halving",
89
+ "tslot_joint",
90
+ "butt_joint",
91
+ "dovetail_splice",
92
+ "stack_joint",
93
+ "living_hinge",
94
+ ],
95
+ },
96
+ {
97
+ "id": "generators",
98
+ "label": "Generators",
99
+ "items": [
100
+ "FingerBox",
101
+ "DrawerUnit",
102
+ "TSlotEnclosure",
103
+ "EggCrate",
104
+ "PhoneStand",
105
+ "HingeSample",
106
+ ],
107
+ },
108
+ ],
109
+ }
110
+
111
+ __all__ = [
112
+ "DrawerUnit",
113
+ "KerfCoupon",
114
+ "PhoneStand",
115
+ "ShapedPanel",
116
+ "chamfered_rect",
117
+ "coupon_clearances",
118
+ "cut_time",
119
+ "dovetail_splice",
120
+ "finger_box",
121
+ "kerf_from_measurement",
122
+ "parse_points",
123
+ "rounded_rect",
124
+ "stack_joint",
125
+ "CornerConflict",
126
+ "EDGES",
127
+ "EdgeMismatch",
128
+ "EggCrate",
129
+ "FeatureOverlap",
130
+ "FingerBox",
131
+ "FitError",
132
+ "FlatPart",
133
+ "FlatpackError",
134
+ "HingeSample",
135
+ "MACHINES",
136
+ "Machine",
137
+ "NestingError",
138
+ "NotPlaced",
139
+ "Panel",
140
+ "SCREW_LENGTHS",
141
+ "SHEETS",
142
+ "Sheet",
143
+ "SheetLayout",
144
+ "TSlotEnclosure",
145
+ "TSlotError",
146
+ "UnknownStock",
147
+ "WebTooThin",
148
+ "bom_rows",
149
+ "butt_joint",
150
+ "check_flatpack",
151
+ "check_panel",
152
+ "cross_halving",
153
+ "finger_count",
154
+ "finger_joint",
155
+ "flatten",
156
+ "living_hinge",
157
+ "nest",
158
+ "overlap_samples",
159
+ "panels_of",
160
+ "resolve_machine",
161
+ "resolve_sheet",
162
+ "sheet_report",
163
+ "slot_and_tab",
164
+ "to_dxf",
165
+ "to_svg",
166
+ "tslot_joint",
167
+ ]
@@ -0,0 +1,110 @@
1
+ """Calibrate a machine on a sheet: one coupon tells you the kerf and the fit.
2
+
3
+ Cut a :class:`KerfCoupon` (exported **without** kerf compensation):
4
+
5
+ * a comb of slots, each the sheet's measured thickness plus a clearance
6
+ (``-0.15 … +0.15`` mm by default, engraved under the slot). Push an
7
+ offcut of the same sheet into each; the slot that fits the way you want
8
+ (snug / press / slip) gives the clearance:
9
+ ``machine.with_clearance(c)``;
10
+ * a square hole ``hole`` mm wide. Measure the square that drops out:
11
+ ``kerf_from_measurement(hole, measured)`` is the kerf
12
+ (``machine.with_kerf(k)``).
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from typing import List
18
+
19
+ from cadbuildr.foundation.library import Num, OneOf, part
20
+
21
+ from . import geometry2d as g2
22
+ from .errors import FitError
23
+ from .panel import Panel
24
+ from .stock import DEFAULT_MACHINE, DEFAULT_SHEET, MACHINES, SHEETS
25
+
26
+
27
+ def coupon_clearances(slots: int, start: float, step: float) -> List[float]:
28
+ return [round(start + i * step, 4) for i in range(int(slots))]
29
+
30
+
31
+ def kerf_from_measurement(nominal: float, measured: float) -> float:
32
+ """Kerf from an uncompensated square: the drop is ``nominal - kerf`` wide."""
33
+ k = float(nominal) - float(measured)
34
+ if not 0.0 <= k < 1.0:
35
+ raise FitError(
36
+ f"kerf_from_measurement: a {nominal:g} mm square measured {measured:g} mm gives "
37
+ f"kerf {k:.3f} mm; measure the square that dropped out, not the hole"
38
+ )
39
+ return round(k, 4)
40
+
41
+
42
+ @part(
43
+ category="Calibration",
44
+ name="Kerf / fit coupon",
45
+ configurations={
46
+ "Laser, 3 mm ply": dict(sheet="Plywood 3 mm"),
47
+ "CNC, coarse steps": dict(machine="CNC 6 mm bit dogbone", step=0.1, start=-0.1),
48
+ },
49
+ )
50
+ class KerfCoupon(Panel):
51
+ """A comb of test slots (thickness + clearance) and a square kerf gauge.
52
+
53
+ Args:
54
+ sheet: the stock to calibrate.
55
+ thickness: measured thickness override (0 keeps the sheet's measured value).
56
+ machine: the machine profile to calibrate.
57
+ slots: number of test slots.
58
+ start: clearance of the first slot (mm, negative = press fit).
59
+ step: clearance step between slots (mm).
60
+ hole: size of the square kerf gauge (mm).
61
+ """
62
+
63
+ def __init__(
64
+ self,
65
+ sheet: OneOf[SHEETS] = DEFAULT_SHEET,
66
+ thickness: Num(min=0, max=40, step=0.05) = 0.0,
67
+ machine: OneOf[MACHINES] = DEFAULT_MACHINE,
68
+ slots: int = 7,
69
+ start: Num(min=-0.5, max=0.5, step=0.01) = -0.15,
70
+ step: Num(min=0.01, max=0.2, step=0.01) = 0.05,
71
+ hole: Num(min=5, max=50, step=1) = 20.0,
72
+ ):
73
+ from .stock import resolve_sheet
74
+
75
+ if slots < 2:
76
+ raise FitError("KerfCoupon: at least two slots")
77
+ t = resolve_sheet(sheet, thickness).thickness
78
+ depth = max(10.0, 2.0 * t)
79
+ pitch = t + 0.5 + max(8.0, 2.0 * t)
80
+ margin = 8.0
81
+ width = 2 * margin + slots * pitch + hole + margin
82
+ height = depth + hole + 3 * margin
83
+ self._setup(
84
+ g2.rect(0.0, 0.0, width, height),
85
+ sheet,
86
+ thickness,
87
+ machine,
88
+ "coupon",
89
+ names=("s", "e", "n", "w"),
90
+ )
91
+ self.compensate = False # calibration is cut as drawn
92
+ self.clearances = coupon_clearances(slots, start, step)
93
+ ops_rings = []
94
+ edge = self.edge("n")
95
+ for i, c in enumerate(self.clearances):
96
+ x = margin + (i + 0.5) * pitch
97
+ w = t + c
98
+ if w <= 0:
99
+ raise FitError(f"KerfCoupon: clearance {c:g} closes a {t:g} mm slot")
100
+ handle = edge.notch(
101
+ self.u_of("n", x + w / 2), self.u_of("n", x - w / 2), depth, "coupon"
102
+ )
103
+ ops_rings.extend(self.void_rings("n", handle))
104
+ self.engrave_text(f"{c:+.2f}", x, height - depth - 5.0, 3.0)
105
+ hx = width - margin - hole
106
+ ops_rings.append(self.hole_ring(g2.rect(hx, margin, hx + hole, margin + hole)))
107
+ self.engrave_text(f"{hole:g}", hx + hole / 2, margin + hole + 4.0, 3.0)
108
+ for op in self.cut_ops(ops_rings):
109
+ self.add_operation(op)
110
+ self.hole_size = float(hole)