Skip to content

Commit

Permalink
Updated GridfinityDrawerSpacer to guard against rendering when not re…
Browse files Browse the repository at this point in the history
…quired. Added adjustable magnet hole radius to GridfinityBox
  • Loading branch information
michaelgale committed Feb 17, 2024
1 parent 371e0c1 commit cc432ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- v.0.5.3 - Removed a potential namespace collision for computing the height of boxes
- v.0.5.4 - Optimized the geometry of the baseplate top height
- v.0.5.5 - Added underside bin clearance and variable wall thickness interior radiusing
- v.0.5.6 - Added adjustable magnet hole diameter to box. Prevent drawer spacers being rendered which fall below minimum size
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ b1.save_step_file()
- v.0.5.3 - Removed a potential namespace collision for computing the height of boxes
- v.0.5.4 - Optimized the geometry of the baseplate top height
- v.0.5.5 - Added underside bin clearance and variable wall thickness interior radiusing
- v.0.5.6 - Added adjustable magnet hole diameter to box. Prevent drawer spacers being rendered which fall below minimum size


# References

Expand Down
2 changes: 1 addition & 1 deletion cqgridfinity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# fmt: off
__project__ = 'cqgridfinity'
__version__ = '0.5.5'
__version__ = '0.5.6'
# fmt: on

VERSION = __project__ + "-" + __version__
Expand Down
6 changes: 5 additions & 1 deletion cqgridfinity/gf_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ def render_holes(self, obj):
)

def render_hole_fillers(self, obj):
rc = cq.Workplane("XY").rect(self.hole_diam / 2, self.hole_diam).extrude(GR_HOLE_SLICE)
rc = (
cq.Workplane("XY")
.rect(self.hole_diam / 2, self.hole_diam)
.extrude(GR_HOLE_SLICE)
)
xo = self.hole_diam / 2
rs = composite_from_pts(rc, [(-xo, 0, GR_HOLE_H), (xo, 0, GR_HOLE_H)])
rs = composite_from_pts(rs, self.hole_centres)
Expand Down
27 changes: 25 additions & 2 deletions cqgridfinity/gf_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,28 @@ def wide_enough(self):
def deep_enough(self):
return self.length_th > self.min_margin

def check_dimensions(self):
"""Check required size does not fall below specified minimum margin."""
if not self.wide_enough and not self.deep_enough:
print("Drawer spacers NOT required since resulting margins are:")
print(
" %.2f mm +/-%.2f mm (tolerance) widthwise which is not above the %.2f margin threshold"
% (self.length_th, self.tolerance, self.min_margin)
)
print(
" %.2f mm +/-%.2f mm (tolerance) depthwise which is not above the %.2f margin threshold"
% (self.width_th, self.tolerance, self.min_margin)
)
return False
return True

def render(self, arrows_top=True, arrows_bottom=True):
"""Renders a corner spacer component. This component can be used for any of
the four corners due to symmetry. Optional arrows can be cut into the
component on the top or bottom to show the drawer sliding/depth-wise direction
"""
if not self.check_dimensions():
return None
sp_length = self.length + self.width_th + self.tolerance
sp_width = self.width + self.length_th + self.tolerance
r, rd = None, None
Expand All @@ -158,15 +175,17 @@ def render(self, arrows_top=True, arrows_bottom=True):
.rect(sp_length, self.length_th)
.extrude(self.thickness)
)
er = min(GR_RAD, self.length_th / 4)
r = r.translate((sp_length / 2, self.length_th / 2, 0))
r = r.edges("|Z").edges("<X").edges("<Y").fillet(GR_RAD)
r = r.edges("|Z").edges("<X").edges("<Y").fillet(er)
r = r.edges("|Z").fillet(self.fillet_rad)
if self.wide_enough:
rd = (
cq.Workplane("XY").rect(self.width_th, sp_width).extrude(self.thickness)
)
er = min(GR_RAD, self.width_th / 4)
rd = rd.translate((self.width_th / 2, sp_width / 2, 0))
rd = rd.edges("|Z").edges("<X").edges("<Y").fillet(GR_RAD)
rd = rd.edges("|Z").edges("<X").edges("<Y").fillet(er)
rd = rd.edges("|Z").fillet(self.fillet_rad)

if r is not None and rd is not None:
Expand Down Expand Up @@ -299,6 +318,8 @@ def render_full_set(self, include_baseplate=False):
respective installed position in the drawer so that the resulting object can
be used to preview final composition of components."""
# Four corners top/bottom left + top/bottom right
if not self.check_dimensions():
return None
bl = self.render()
tl = rotate_x(bl, 180).translate((0, self.size[1], self.thickness))
br = rotate_y(bl, 180).translate((self.size[0], 0, self.thickness))
Expand Down Expand Up @@ -332,6 +353,8 @@ def render_half_set(self):
for 3D printing. This resulting compound object can then be printed twice to
yield a complete set of spacer components for a drawer."""
# one of each corner
if not self.check_dimensions():
return None
bl = self.render(arrows_bottom=False)
br = self.render(arrows_top=False)
if self.deep_enough:
Expand Down

0 comments on commit cc432ff

Please sign in to comment.