cadbuildr-gridfinity 0.2.0__py3-none-any.whl
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.
- cadbuildr/__init__.py +3 -0
- cadbuildr/gridfinity/__init__.py +87 -0
- cadbuildr/gridfinity/_base.py +177 -0
- cadbuildr/gridfinity/_geom.py +117 -0
- cadbuildr/gridfinity/assemblies.py +108 -0
- cadbuildr/gridfinity/baseplates.py +255 -0
- cadbuildr/gridfinity/bins.py +333 -0
- cadbuildr/gridfinity/errors.py +38 -0
- cadbuildr/gridfinity/inserts.py +397 -0
- cadbuildr/gridfinity/interfaces.py +47 -0
- cadbuildr/gridfinity/layout.py +104 -0
- cadbuildr/gridfinity/spec.py +383 -0
- cadbuildr_gridfinity-0.2.0.dist-info/METADATA +159 -0
- cadbuildr_gridfinity-0.2.0.dist-info/RECORD +17 -0
- cadbuildr_gridfinity-0.2.0.dist-info/WHEEL +4 -0
- cadbuildr_gridfinity-0.2.0.dist-info/entry_points.txt +2 -0
- cadbuildr_gridfinity-0.2.0.dist-info/licenses/LICENSE +21 -0
cadbuildr/__init__.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""cadbuildr-gridfinity: the Gridfinity modular storage system on CADbuildr.
|
|
2
|
+
|
|
3
|
+
Gridfinity is Zack Freedman's open 42 mm grid storage system
|
|
4
|
+
(https://gridfinity.xyz/specification/); dimensions follow the community
|
|
5
|
+
reference *Gridfinity Rebuilt* (https://github.com/kennetek/gridfinity-rebuilt-openscad),
|
|
6
|
+
modelled from its published numbers (see :mod:`.spec`).
|
|
7
|
+
|
|
8
|
+
Items (all ``@part`` / ``@assembly`` library items):
|
|
9
|
+
|
|
10
|
+
* bins: :class:`GridfinityBin`, :class:`GridfinityBlock`;
|
|
11
|
+
* baseplates: :class:`GridfinityBaseplate` (plain / magnet / weighted /
|
|
12
|
+
screw), :class:`GridfinityDrawerBaseplate` (fit to a drawer);
|
|
13
|
+
* accessories: :class:`GridfinityHexBitInsert`, :class:`GridfinityHoleInsert`,
|
|
14
|
+
:class:`GridfinityCutoutInsert`, :class:`GridfinityLid`;
|
|
15
|
+
* assemblies: :class:`GridfinityDrawer` (layout string),
|
|
16
|
+
:class:`GridfinityDemoDrawer`.
|
|
17
|
+
|
|
18
|
+
Bins stand on baseplates by ``connect``: ``GridfinityFoot`` (``foot``) on
|
|
19
|
+
``GridfinitySocket`` (``cell_<i>_<j>``, ``stack_<i>_<j>``); use
|
|
20
|
+
:func:`place_bin` / :func:`stack_on` for checked placement.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from . import spec
|
|
24
|
+
from .assemblies import GridfinityDemoDrawer, GridfinityDrawer
|
|
25
|
+
from .baseplates import GridfinityBaseplate, GridfinityDrawerBaseplate
|
|
26
|
+
from .bins import LABEL_STYLES, GridfinityBin, GridfinityBlock
|
|
27
|
+
from .errors import (
|
|
28
|
+
FitError,
|
|
29
|
+
GridfinityError,
|
|
30
|
+
GridSizeError,
|
|
31
|
+
LayoutError,
|
|
32
|
+
OptionConflictError,
|
|
33
|
+
OutlineError,
|
|
34
|
+
)
|
|
35
|
+
from .inserts import (
|
|
36
|
+
GridfinityCutoutInsert,
|
|
37
|
+
GridfinityHexBitInsert,
|
|
38
|
+
GridfinityHoleInsert,
|
|
39
|
+
GridfinityLid,
|
|
40
|
+
parse_diameters,
|
|
41
|
+
parse_outline,
|
|
42
|
+
)
|
|
43
|
+
from .interfaces import GridfinityFoot, GridfinitySocket
|
|
44
|
+
from .layout import LAYOUT_KINDS, parse_layout, place_bin, stack_on
|
|
45
|
+
from .spec import HALF_PITCH, HEIGHT_UNIT, PITCH, bin_height, bin_outer, drawer_fit, tile_layout
|
|
46
|
+
|
|
47
|
+
__version__ = "0.2.0"
|
|
48
|
+
|
|
49
|
+
#: cq-gridfinity's name for a bin (kept from the starter vocabulary)
|
|
50
|
+
GridfinityBox = GridfinityBin
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"FitError",
|
|
54
|
+
"GridSizeError",
|
|
55
|
+
"GridfinityBaseplate",
|
|
56
|
+
"GridfinityBin",
|
|
57
|
+
"GridfinityBlock",
|
|
58
|
+
"GridfinityBox",
|
|
59
|
+
"GridfinityCutoutInsert",
|
|
60
|
+
"GridfinityDemoDrawer",
|
|
61
|
+
"GridfinityDrawer",
|
|
62
|
+
"GridfinityDrawerBaseplate",
|
|
63
|
+
"GridfinityError",
|
|
64
|
+
"GridfinityFoot",
|
|
65
|
+
"GridfinityHexBitInsert",
|
|
66
|
+
"GridfinityHoleInsert",
|
|
67
|
+
"GridfinityLid",
|
|
68
|
+
"GridfinitySocket",
|
|
69
|
+
"HALF_PITCH",
|
|
70
|
+
"HEIGHT_UNIT",
|
|
71
|
+
"LABEL_STYLES",
|
|
72
|
+
"LAYOUT_KINDS",
|
|
73
|
+
"LayoutError",
|
|
74
|
+
"OptionConflictError",
|
|
75
|
+
"OutlineError",
|
|
76
|
+
"PITCH",
|
|
77
|
+
"bin_height",
|
|
78
|
+
"bin_outer",
|
|
79
|
+
"drawer_fit",
|
|
80
|
+
"parse_diameters",
|
|
81
|
+
"parse_layout",
|
|
82
|
+
"parse_outline",
|
|
83
|
+
"place_bin",
|
|
84
|
+
"spec",
|
|
85
|
+
"stack_on",
|
|
86
|
+
"tile_layout",
|
|
87
|
+
]
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""Shared bin geometry: feet, body, cavity + stacking lip, holes, anchors.
|
|
2
|
+
|
|
3
|
+
Every Gridfinity item that stands on a baseplate (bins, blocks, inserts,
|
|
4
|
+
lids) is built from the same pieces, in the bin's own frame: footprint
|
|
5
|
+
centred on the origin, bottom of the feet at ``z = 0``.
|
|
6
|
+
|
|
7
|
+
* **Feet** (one per cell, ``z = 0 .. 4.75``): the GR base profile — 0.8 mm
|
|
8
|
+
45-degree chamfer, 1.8 mm vertical, 2.15 mm 45-degree chamfer — from a
|
|
9
|
+
35.6 mm (r 0.8) bottom to a 41.5 mm (r 3.75) top on the 42 mm grid. Each
|
|
10
|
+
flank is its own operation (a two-section ruled loft or a straight
|
|
11
|
+
extrusion), which keeps every flank exactly planar; one multi-section
|
|
12
|
+
loft over the whole stack bulges between sections.
|
|
13
|
+
* **Body** (``z = 4.75 ..`` top): the bin outline ``42 n - 0.5`` (r 3.75);
|
|
14
|
+
its bottom 2.25 mm is the bridge that ties the feet together and is the
|
|
15
|
+
cavity floor (``z = 7``).
|
|
16
|
+
* **Stacking lip**: the outline carried 4.0 mm above the body top
|
|
17
|
+
(``7 * units_z``) with the GR lip line cut out of it, under it the 1.2 mm
|
|
18
|
+
vertical + 45-degree support back to the wall.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import math
|
|
24
|
+
from typing import List, Optional, Tuple
|
|
25
|
+
|
|
26
|
+
from cadbuildr.foundation import Part, make_anchor
|
|
27
|
+
from cadbuildr.foundation.checks import issue
|
|
28
|
+
|
|
29
|
+
from . import _geom as G
|
|
30
|
+
from . import spec as S
|
|
31
|
+
from .errors import GridSizeError, OptionConflictError
|
|
32
|
+
from .interfaces import GridfinityFoot, GridfinitySocket
|
|
33
|
+
|
|
34
|
+
GRID_GREY = "dark_grey"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def check_units(name: str, value, lo: float, hi: float, integer: bool = True) -> float:
|
|
38
|
+
try:
|
|
39
|
+
v = float(value)
|
|
40
|
+
except (TypeError, ValueError):
|
|
41
|
+
raise GridSizeError(f"{name} must be a number, got {value!r}") from None
|
|
42
|
+
if integer and abs(v - round(v)) > 1e-9:
|
|
43
|
+
raise GridSizeError(f"{name} must be a whole number of cells, got {value!r}")
|
|
44
|
+
if not lo <= v <= hi:
|
|
45
|
+
raise GridSizeError(f"{name} must be between {lo:g} and {hi:g}, got {value!r}")
|
|
46
|
+
return int(round(v)) if integer else v
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def check_bool(name: str, value) -> bool:
|
|
50
|
+
if not isinstance(value, bool):
|
|
51
|
+
raise OptionConflictError(f"{name} must be True or False, got {value!r}")
|
|
52
|
+
return value
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class GridBody(Part):
|
|
56
|
+
"""Internal base class of the Gridfinity parts (not a library item).
|
|
57
|
+
|
|
58
|
+
Sub-classes call :meth:`_grid` first, then the builders they need.
|
|
59
|
+
Attributes set by :meth:`_grid`: ``units_x``, ``units_y``, ``pitch``,
|
|
60
|
+
``outer_w``, ``outer_d`` and ``cell_centres``.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
# -- setup -------------------------------------------------------- #
|
|
64
|
+
def _grid(self, units_x, units_y, half_pitch: bool = False, max_units: int = 16):
|
|
65
|
+
half = check_bool("half_pitch", half_pitch)
|
|
66
|
+
self.pitch = S.HALF_PITCH if half else S.PITCH
|
|
67
|
+
lim = max_units * (2 if half else 1)
|
|
68
|
+
self.units_x = check_units("units_x", units_x, 1, lim)
|
|
69
|
+
self.units_y = check_units("units_y", units_y, 1, lim)
|
|
70
|
+
self.half_pitch = half
|
|
71
|
+
self.outer_w = S.bin_outer(self.units_x, self.pitch)
|
|
72
|
+
self.outer_d = S.bin_outer(self.units_y, self.pitch)
|
|
73
|
+
self.cell_centres = S.cells(self.units_x, self.units_y, self.pitch)
|
|
74
|
+
self._issues: List[dict] = []
|
|
75
|
+
|
|
76
|
+
def _height(self, units_z, lo: float = 1, hi: float = 30) -> float:
|
|
77
|
+
self.units_z = check_units("units_z", units_z, lo, hi)
|
|
78
|
+
self.body_top = S.bin_height(self.units_z)
|
|
79
|
+
return self.body_top
|
|
80
|
+
|
|
81
|
+
# -- geometry ----------------------------------------------------- #
|
|
82
|
+
def _feet(self) -> None:
|
|
83
|
+
secs = []
|
|
84
|
+
for z in (z for _, z in S.BASE_PROFILE):
|
|
85
|
+
w, r = S.foot_section(z, self.pitch)
|
|
86
|
+
secs.append((z, (w, w, r)))
|
|
87
|
+
G.ruled_many(self, secs, [(cx, cy) for _, _, cx, cy in self.cell_centres])
|
|
88
|
+
|
|
89
|
+
def _outline(self, inset: float = 0.0) -> Tuple[float, float, float]:
|
|
90
|
+
return (
|
|
91
|
+
self.outer_w - 2 * inset,
|
|
92
|
+
self.outer_d - 2 * inset,
|
|
93
|
+
max(S.BASE_TOP_RADIUS - inset, 0.3),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def _body(self, z_top: float, z_bottom: float = S.BASE_PROFILE_HEIGHT - G.EPS) -> None:
|
|
97
|
+
w, d, r = self._outline()
|
|
98
|
+
G.prism_z(self, z_bottom, z_top, lambda sk: [G.rrect(sk, 0, 0, w, d, r)])
|
|
99
|
+
|
|
100
|
+
def _lip_sections(self, wall: Optional[float]) -> List[Tuple[float, Tuple[float, float, float]]]:
|
|
101
|
+
"""Cut sections of the stacking-lip opening, from the bottom of its
|
|
102
|
+
support (``wall`` = inner wall inset; ``None`` for a solid body:
|
|
103
|
+
start at the vertical support) to just above the lip top."""
|
|
104
|
+
z0 = self.body_top
|
|
105
|
+
secs = []
|
|
106
|
+
if wall is not None:
|
|
107
|
+
secs.append((z0 - S.lip_support_height(wall), self._outline(wall)))
|
|
108
|
+
secs.append((z0 - S.STACKING_LIP_SUPPORT_HEIGHT, self._outline(S.STACKING_LIP_DEPTH)))
|
|
109
|
+
for x, h in S.STACKING_LIP_PROFILE:
|
|
110
|
+
if h > S.LIP_TOP_HEIGHT:
|
|
111
|
+
break
|
|
112
|
+
secs.append((z0 + h, self._outline(S.STACKING_LIP_DEPTH - x)))
|
|
113
|
+
top = S.LIP_TOP_HEIGHT
|
|
114
|
+
x = S.profile_x(S.STACKING_LIP_PROFILE, top)
|
|
115
|
+
# the last 45-degree flank runs EPS past the lip top
|
|
116
|
+
secs.append((z0 + top + G.EPS, self._outline(S.STACKING_LIP_DEPTH - x - G.EPS)))
|
|
117
|
+
return secs
|
|
118
|
+
|
|
119
|
+
def _lip_top(self) -> float:
|
|
120
|
+
return self.body_top + S.LIP_TOP_HEIGHT
|
|
121
|
+
|
|
122
|
+
def _cut_lip(self, wall: Optional[float]) -> None:
|
|
123
|
+
G.ruled(self, self._lip_sections(wall), cut=True)
|
|
124
|
+
|
|
125
|
+
def _holes(self, magnets: bool, screws: bool, only_corners: bool) -> None:
|
|
126
|
+
if not (magnets or screws):
|
|
127
|
+
return
|
|
128
|
+
if self.half_pitch:
|
|
129
|
+
raise OptionConflictError(
|
|
130
|
+
"magnet / screw holes sit 13 mm from a 42 mm cell centre and do not "
|
|
131
|
+
"fit a half-pitch (21 mm) foot: set magnets=False and screws=False"
|
|
132
|
+
)
|
|
133
|
+
pts = []
|
|
134
|
+
for i, j, cx, cy in self.cell_centres:
|
|
135
|
+
for (hx, hy) in S.corner_holes(cx, cy):
|
|
136
|
+
if only_corners:
|
|
137
|
+
sx, sy = hx > cx, hy > cy
|
|
138
|
+
ok_x = (i == self.units_x - 1) if sx else (i == 0)
|
|
139
|
+
ok_y = (j == self.units_y - 1) if sy else (j == 0)
|
|
140
|
+
if not (ok_x and ok_y):
|
|
141
|
+
continue
|
|
142
|
+
pts.append((hx, hy))
|
|
143
|
+
if magnets:
|
|
144
|
+
G.prism_z(self, -G.EPS, S.MAGNET_DEPTH, lambda sk: G.circles(sk, pts, S.MAGNET_D / 2), cut=True)
|
|
145
|
+
if screws:
|
|
146
|
+
G.prism_z(self, -G.EPS, S.SCREW_HOLE_DEPTH, lambda sk: G.circles(sk, pts, S.SCREW_D / 2), cut=True)
|
|
147
|
+
self.hole_count = len(pts)
|
|
148
|
+
|
|
149
|
+
def _foot_anchor(self) -> None:
|
|
150
|
+
_, _, x0, y0 = self.cell_centres[0]
|
|
151
|
+
a = self.add_anchor(make_anchor("foot", (x0, y0, 0.0), z_down=True))
|
|
152
|
+
self.add_interface(GridfinityFoot(pitch=self.pitch), a)
|
|
153
|
+
|
|
154
|
+
def _sockets(self, prefix: str, z: float, units_x=None, units_y=None, centres=None) -> None:
|
|
155
|
+
for i, j, cx, cy in centres or self.cell_centres:
|
|
156
|
+
a = self.add_anchor(make_anchor(f"{prefix}_{i}_{j}", (cx, cy, z)))
|
|
157
|
+
self.add_interface(GridfinitySocket(pitch=self.pitch), a)
|
|
158
|
+
|
|
159
|
+
def _top_anchor(self, z: float) -> None:
|
|
160
|
+
self.add_anchor(make_anchor("top", (0.0, 0.0, z)))
|
|
161
|
+
|
|
162
|
+
# -- checks ------------------------------------------------------- #
|
|
163
|
+
def _note(self, severity: str, code: str, message: str, fix: Optional[str] = None) -> None:
|
|
164
|
+
self._issues.append(issue(severity, code, message, fix=fix))
|
|
165
|
+
|
|
166
|
+
def _bed_check(self, w: float, d: float, h: float, what: str) -> None:
|
|
167
|
+
bed = 256.0 # Estimated: a common 256 x 256 mm consumer printer bed
|
|
168
|
+
if max(w, d) > bed:
|
|
169
|
+
self._note(
|
|
170
|
+
"warning",
|
|
171
|
+
"gridfinity.bed",
|
|
172
|
+
f"{what} is {w:.1f} x {d:.1f} mm, larger than a {bed:g} mm bed",
|
|
173
|
+
fix="split it with tile_layout()",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
def __checks__(self):
|
|
177
|
+
return list(getattr(self, "_issues", []))
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Sketch helpers shared by the gridfinity parts (internal)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Callable, Iterable, List, Sequence, Tuple
|
|
6
|
+
|
|
7
|
+
from cadbuildr.foundation import (
|
|
8
|
+
Circle,
|
|
9
|
+
Extrusion,
|
|
10
|
+
Loft,
|
|
11
|
+
Polygon,
|
|
12
|
+
Point,
|
|
13
|
+
Rectangle,
|
|
14
|
+
RectangleRounded,
|
|
15
|
+
Sketch,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
Section = Tuple[float, float, float] # (width, depth, corner radius)
|
|
19
|
+
EPS = 0.01
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def plane_z(part, z: float):
|
|
23
|
+
"""The part's XY plane moved to height ``z``."""
|
|
24
|
+
return part.xy().get_parallel_plane(float(z))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def rrect(sketch: Sketch, cx: float, cy: float, w: float, d: float, r: float):
|
|
28
|
+
"""A ``w`` x ``d`` rectangle centred at ``(cx, cy)``, corners rounded
|
|
29
|
+
with ``r`` (square below 0.05 mm)."""
|
|
30
|
+
r = min(float(r), 0.5 * min(w, d) - 1e-3)
|
|
31
|
+
centre = Point(sketch, float(cx), float(cy))
|
|
32
|
+
if r > 0.05:
|
|
33
|
+
return RectangleRounded(centre, float(w), float(d), r)
|
|
34
|
+
return Rectangle.from_center_and_sides(centre, float(w), float(d))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def rect(sketch: Sketch, x0: float, y0: float, x1: float, y1: float):
|
|
38
|
+
"""Axis-aligned rectangle from two corners."""
|
|
39
|
+
return Rectangle.from_center_and_sides(
|
|
40
|
+
Point(sketch, (x0 + x1) / 2.0, (y0 + y1) / 2.0), abs(x1 - x0), abs(y1 - y0)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def prism_z(part, z0: float, z1: float, shapes: Callable[[Sketch], Iterable], cut: bool = False):
|
|
45
|
+
"""Extrude the shapes ``shapes(sketch)`` draws on the plane at ``z0`` up
|
|
46
|
+
to ``z1`` (one operation for all of them; they must not overlap)."""
|
|
47
|
+
sk = Sketch(plane_z(part, z0))
|
|
48
|
+
items = list(shapes(sk))
|
|
49
|
+
if not items:
|
|
50
|
+
return None
|
|
51
|
+
op = Extrusion(items, float(z1 - z0), cut=cut)
|
|
52
|
+
part.add_operation(op)
|
|
53
|
+
return op
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def ruled(part, sections: Sequence[Tuple[float, Section]], cx: float = 0.0, cy: float = 0.0, cut: bool = False):
|
|
57
|
+
"""Rounded-rectangle sections ``[(z, (w, d, r)), ...]`` centred at
|
|
58
|
+
``(cx, cy)``, joined segment by segment: equal sections by an
|
|
59
|
+
extrusion, different ones by a two-section ruled loft (one loft per
|
|
60
|
+
segment keeps every flank planar, see the module docstring of
|
|
61
|
+
:mod:`cadbuildr.gridfinity.bins`)."""
|
|
62
|
+
for (z0, s0), (z1, s1) in zip(sections, sections[1:]):
|
|
63
|
+
if z1 - z0 <= 1e-9:
|
|
64
|
+
continue
|
|
65
|
+
if all(abs(a - b) < 1e-9 for a, b in zip(s0, s1)):
|
|
66
|
+
prism_z(part, z0, z1, lambda sk: [rrect(sk, cx, cy, *s0)], cut=cut)
|
|
67
|
+
continue
|
|
68
|
+
a = rrect(Sketch(plane_z(part, z0)), cx, cy, *s0)
|
|
69
|
+
b = rrect(Sketch(plane_z(part, z1)), cx, cy, *s1)
|
|
70
|
+
part.add_operation(Loft([a, b], ruled=True, cut=cut))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def ruled_many(part, sections: Sequence[Tuple[float, Section]], centres: Sequence[Tuple[float, float]], cut: bool = False):
|
|
74
|
+
""":func:`ruled` at every centre, with each straight segment drawn as ONE
|
|
75
|
+
extrusion for all centres (the sections must not overlap between
|
|
76
|
+
neighbouring centres) and each sloped segment as one loft per centre."""
|
|
77
|
+
for (z0, s0), (z1, s1) in zip(sections, sections[1:]):
|
|
78
|
+
if z1 - z0 <= 1e-9:
|
|
79
|
+
continue
|
|
80
|
+
if all(abs(a - b) < 1e-9 for a, b in zip(s0, s1)):
|
|
81
|
+
prism_z(part, z0, z1, lambda sk: [rrect(sk, cx, cy, *s0) for cx, cy in centres], cut=cut)
|
|
82
|
+
continue
|
|
83
|
+
for cx, cy in centres:
|
|
84
|
+
a = rrect(Sketch(plane_z(part, z0)), cx, cy, *s0)
|
|
85
|
+
b = rrect(Sketch(plane_z(part, z1)), cx, cy, *s1)
|
|
86
|
+
part.add_operation(Loft([a, b], ruled=True, cut=cut))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def polygon(sketch: Sketch, pts: Sequence[Tuple[float, float]]):
|
|
90
|
+
"""Closed polygon through ``pts`` (sketch coordinates); several may share
|
|
91
|
+
one sketch."""
|
|
92
|
+
return Polygon.from_points(sketch, [(float(x), float(y)) for x, y in pts])
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def prism_x(part, ring: Sequence[Tuple[float, float]], x0: float, x1: float, cut: bool = False):
|
|
96
|
+
"""A prism of the ``(y, z)`` polygon ``ring`` between ``x = x0`` and
|
|
97
|
+
``x = x1`` (sketched on the part's YZ plane, extruded along +X)."""
|
|
98
|
+
sk = Sketch(part.yz())
|
|
99
|
+
op = Extrusion(polygon(sk, ring), float(x1), float(x0), cut=cut)
|
|
100
|
+
part.add_operation(op)
|
|
101
|
+
return op
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def circles(sketch: Sketch, centres: Iterable[Tuple[float, float]], r: float) -> List:
|
|
105
|
+
return [Circle(Point(sketch, float(x), float(y)), float(r)) for x, y in centres]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def hexagon(sketch: Sketch, cx: float, cy: float, af: float):
|
|
109
|
+
"""Regular hexagon ``af`` across flats, flats parallel to X."""
|
|
110
|
+
import math
|
|
111
|
+
|
|
112
|
+
rc = af / math.sqrt(3.0) # circumradius
|
|
113
|
+
pts = [
|
|
114
|
+
(cx + rc * math.cos(math.radians(60 * k)), cy + rc * math.sin(math.radians(60 * k)))
|
|
115
|
+
for k in range(6)
|
|
116
|
+
]
|
|
117
|
+
return polygon(sketch, pts)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Gridfinity assemblies: a drawer from a layout string, and the demo.
|
|
2
|
+
|
|
3
|
+
Every bin is placed by ``connect`` (``GridfinityFoot`` on a baseplate's
|
|
4
|
+
``GridfinitySocket``), never by coordinates, so ``assembly.check()`` sees
|
|
5
|
+
each joint and a moved cell moves its bin.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from cadbuildr.foundation import Assembly
|
|
11
|
+
from cadbuildr.foundation.library import Num, OneOf, assembly
|
|
12
|
+
|
|
13
|
+
from . import spec as S
|
|
14
|
+
from .baseplates import GridfinityBaseplate, GridfinityDrawerBaseplate
|
|
15
|
+
from .bins import GridfinityBin, GridfinityBlock
|
|
16
|
+
from .inserts import GridfinityCutoutInsert, GridfinityHexBitInsert, GridfinityHoleInsert, GridfinityLid
|
|
17
|
+
from .layout import parse_layout, place_bin, stack_on
|
|
18
|
+
|
|
19
|
+
__all__ = ["GridfinityDemoDrawer", "GridfinityDrawer"]
|
|
20
|
+
|
|
21
|
+
_KINDS = {
|
|
22
|
+
"bin": GridfinityBin,
|
|
23
|
+
"block": GridfinityBlock,
|
|
24
|
+
"hexbit": GridfinityHexBitInsert,
|
|
25
|
+
"holes": GridfinityHoleInsert,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
DEFAULT_LAYOUT = (
|
|
29
|
+
"bin 2x2x6@0,0; bin 1x1x3@2,0; hexbit 1x1x3@3,0; "
|
|
30
|
+
"bin 2x1x3@2,1; holes 1x1x3@0,2; bin 3x1x3@1,2"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@assembly(
|
|
35
|
+
category="Storage/Gridfinity",
|
|
36
|
+
name="Gridfinity drawer",
|
|
37
|
+
configurations={
|
|
38
|
+
"4 x 3 mixed": dict(drawer_width=180, drawer_depth=130, layout=DEFAULT_LAYOUT),
|
|
39
|
+
"3 x 2 small bins": dict(
|
|
40
|
+
drawer_width=126, drawer_depth=84,
|
|
41
|
+
layout="1x1x3@0,0; 1x1x3@1,0; 1x1x3@2,0; 3x1x2@0,1",
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
)
|
|
45
|
+
class GridfinityDrawer(Assembly):
|
|
46
|
+
"""A drawer baseplate (cells and padding from the drawer size) with bins
|
|
47
|
+
placed from a layout string: ``'[kind] <w>x<d>[x<h>]@<i>,<j>; ...'``
|
|
48
|
+
(kinds: bin, block, hexbit, holes; height in 7 mm units, default 3).
|
|
49
|
+
Items off the plate or over each other raise ``LayoutError``.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
drawer_width: inside width of the drawer, mm.
|
|
53
|
+
drawer_depth: inside depth of the drawer, mm.
|
|
54
|
+
style: baseplate style.
|
|
55
|
+
layout: bins as '[kind] <w>x<d>[x<h>]@<i>,<j>' items separated by ';'.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
drawer_width: Num(min=42, max=2000, unit="mm") = 180.0,
|
|
61
|
+
drawer_depth: Num(min=42, max=2000, unit="mm") = 130.0,
|
|
62
|
+
style: OneOf[S.BASEPLATE_STYLES] = "magnet",
|
|
63
|
+
layout: str = DEFAULT_LAYOUT,
|
|
64
|
+
):
|
|
65
|
+
plate = GridfinityDrawerBaseplate(drawer_width=drawer_width, drawer_depth=drawer_depth, style=style)
|
|
66
|
+
items = parse_layout(layout, plate.units_x, plate.units_y)
|
|
67
|
+
self.ground(plate)
|
|
68
|
+
self.plate = plate
|
|
69
|
+
self.items = []
|
|
70
|
+
for kind, w, d, h, i, j in items:
|
|
71
|
+
if kind == "bin":
|
|
72
|
+
obj = GridfinityBin(units_x=w, units_y=d, units_z=h, label="full" if h >= 3 else "none")
|
|
73
|
+
else:
|
|
74
|
+
obj = _KINDS[kind](units_x=w, units_y=d, units_z=h)
|
|
75
|
+
place_bin(self, obj, plate, i, j)
|
|
76
|
+
self.items.append(obj)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@assembly(category="Storage/Gridfinity", name="Gridfinity demo drawer")
|
|
80
|
+
class GridfinityDemoDrawer(Assembly):
|
|
81
|
+
"""Demo: a 4 x 3 magnet baseplate for a 180 x 130 mm drawer, filled with
|
|
82
|
+
a divided 2 x 2 x 6 bin, a 1 x 1 scoop bin with a lid stacked on it, a
|
|
83
|
+
1/4 in hex-bit holder, a drill-size hole holder, a 2 x 1 hex-key
|
|
84
|
+
cut-out insert and a 2 x 1 two-compartment bin, all placed by connect.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
style: baseplate style.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(self, style: OneOf[S.BASEPLATE_STYLES] = "magnet"):
|
|
91
|
+
plate = GridfinityDrawerBaseplate(drawer_width=180, drawer_depth=130, style=style)
|
|
92
|
+
self.ground(plate)
|
|
93
|
+
self.plate = plate
|
|
94
|
+
big = GridfinityBin(units_x=2, units_y=2, units_z=6, dividers_x=1, dividers_y=1, magnets=True)
|
|
95
|
+
small = GridfinityBin(units_x=1, units_y=1, units_z=3, label="center", magnets=True)
|
|
96
|
+
lid = GridfinityLid(units_x=1, units_y=1, stackable=True)
|
|
97
|
+
bits = GridfinityHexBitInsert(units_x=1, units_y=1, units_z=3, magnets=True)
|
|
98
|
+
drills = GridfinityHoleInsert(units_x=1, units_y=1, units_z=3, diameters="2, 3, 4, 5, 6, 8")
|
|
99
|
+
keys = GridfinityCutoutInsert(units_x=2, units_y=1, units_z=3)
|
|
100
|
+
pair = GridfinityBin(units_x=2, units_y=1, units_z=3, dividers_x=1, label="left")
|
|
101
|
+
place_bin(self, big, plate, 0, 0)
|
|
102
|
+
place_bin(self, small, plate, 2, 0)
|
|
103
|
+
place_bin(self, bits, plate, 3, 0)
|
|
104
|
+
place_bin(self, pair, plate, 2, 1)
|
|
105
|
+
place_bin(self, drills, plate, 0, 2)
|
|
106
|
+
place_bin(self, keys, plate, 1, 2)
|
|
107
|
+
stack_on(self, lid, small)
|
|
108
|
+
self.items = [big, small, bits, pair, drills, keys, lid]
|