From fbb7142a9a15f3c0ecaf3f330fa8445b443c2a89 Mon Sep 17 00:00:00 2001 From: Michael Gale Date: Tue, 9 Jan 2024 19:25:30 -0500 Subject: [PATCH] Added smarter automatic object naming. Updated console scripts. --- Makefile | 1 + cqgridfinity/constants.py | 2 + cqgridfinity/gf_baseplate.py | 52 +++++++++------ cqgridfinity/gf_box.py | 16 ++++- cqgridfinity/gf_drawer.py | 5 ++ cqgridfinity/gf_obj.py | 20 +++++- cqgridfinity/gf_ruggedbox.py | 91 ++++++++++++++++---------- cqgridfinity/scripts/gridfinitybase.py | 43 ++++++++++++ cqgridfinity/scripts/gridfinitybox.py | 12 +++- cqgridfinity/scripts/ruggedbox.py | 29 +++++++- tests/test_baseplate.py | 1 - tests/test_rbox.py | 33 ++++++++-- tests/test_spacer.py | 40 +++++------ 13 files changed, 257 insertions(+), 88 deletions(-) diff --git a/Makefile b/Makefile index 8213b7d..8c5d97f 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ clean-pyc: ## remove Python file artifacts clean-test: ## remove test and coverage artifacts @find . -name '*.step' -exec rm -f {} + @find . -name '*.stl' -exec rm -f {} + + @find . -name '*.svg' -exec rm -f {} + @rm -f .coverage @rm -fr htmlcov/ diff --git a/cqgridfinity/constants.py b/cqgridfinity/constants.py index 13c0612..0f9f76a 100644 --- a/cqgridfinity/constants.py +++ b/cqgridfinity/constants.py @@ -93,6 +93,7 @@ (GR_BOX_CHAMF_H * SQRT2, 45), ) +# Rugged Box constant parameters GR_RBOX_WALL = 2.5 GR_RBOX_FLOOR = 1.2 GR_RBOX_CWALL = 10.0 @@ -137,6 +138,7 @@ GR_LID_HANDLE_W = 70 GR_SIDE_HANDLE_W = 60 +GR_HINGE_SZ = 32 GR_HINGE_D = 3 GR_HINGE_W1 = 5.5 GR_HINGE_H1 = 2.7 diff --git a/cqgridfinity/gf_baseplate.py b/cqgridfinity/gf_baseplate.py index 5e7e80e..c760f7b 100644 --- a/cqgridfinity/gf_baseplate.py +++ b/cqgridfinity/gf_baseplate.py @@ -46,18 +46,37 @@ class GridfinityBaseplate(GridfinityObject): width_y - width in U (42 mm / U) ext_depth - extrude bottom face by an extra amount in mm straight_bottom - remove bottom chamfer and replace with straight side + corner_screws - add countersink mounting screws to the inside corners + corner_tab_size - size of mounting screw corner tabs + csk_hole - mounting screw hole diameter + csk_diam - mounting screw countersink diameter + csk_angle - mounting screw countersink angle """ def __init__(self, length_u, width_u, **kwargs): super().__init__() self.length_u = length_u self.width_u = width_u - self.ext_depth = 0 # extra extrusion depth below bottom face - self.straight_bottom = False # remove chamfered bottom lip + self.ext_depth = 0 + self.straight_bottom = False self.corner_screws = False + self.corner_tab_size = 21 + self.csk_hole = 5.0 + self.csk_diam = 10.0 + self.csk_angle = 82 for k, v in kwargs.items(): - if k in self.__dict__: + if k in self.__dict__ and v is not None: self.__dict__[k] = v + if self.corner_screws: + self.ext_depth = max(self.ext_depth, 5.0) + + def _corner_pts(self, offset=0): + oxy = (self.corner_tab_size - offset) / 2 + return [ + (i * (self.length / 2 - oxy), j * (self.width / 2 - oxy), 0) + for i in (-1, 1) + for j in (-1, 1) + ] def render(self): profile = GR_BASE_PROFILE if not self.straight_bottom else GR_STR_BASE_PROFILE @@ -78,24 +97,17 @@ def render(self): .cut(rc) ) if self.corner_screws: - rs = cq.Sketch().rect(21, 21) - rs = cq.Workplane("XY").placeSketch(rs).extrude(self.ext_depth) - rs = rs.faces(">Z").cskHole(5, cskDiameter=10, cskAngle=82) - pts = [ - (i * (self.length / 2 - 10.5), j * (self.width / 2 - 10.5), 0) - for i in (-1, 1) - for j in (-1, 1) - ] - rp = composite_from_pts(rs, pts) + depth = self.ext_depth + rs = cq.Sketch().rect(self.corner_tab_size, self.corner_tab_size) + rs = cq.Workplane("XY").placeSketch(rs).extrude(depth) + rs = rs.faces(">Z").cskHole( + self.csk_hole, cskDiameter=self.csk_diam, cskAngle=self.csk_angle + ) + rp = composite_from_pts(rs, self._corner_pts()) rp = recentre(rp, "XY") r = r.union(rp) - r = r.edges( - VerticalEdgeSelector(self.ext_depth) & HasZCoordinateSelector(0) - ).fillet(GR_RAD) - pts = [ - (i * (self.length / 2 - 10), j * (self.width / 2 - 10), 0) - for i in (-1, 1) - for j in (-1, 1) - ] + r = r.edges(VerticalEdgeSelector(depth) & HasZCoordinateSelector(0)).fillet( + GR_RAD + ) return r diff --git a/cqgridfinity/gf_box.py b/cqgridfinity/gf_box.py index f234e6c..84f7ad5 100644 --- a/cqgridfinity/gf_box.py +++ b/cqgridfinity/gf_box.py @@ -27,7 +27,7 @@ import cadquery as cq from cqkit import HasZCoordinateSelector, VerticalEdgeSelector, FlatEdgeSelector -from cqkit.cq_helpers import multi_extrude, rounded_rect_sketch, composite_from_pts +from cqkit.cq_helpers import rounded_rect_sketch, composite_from_pts from cqgridfinity import * @@ -54,6 +54,12 @@ class GridfinityBox(GridfinityObject): - no_lip : removes the contoured lip on the top module used for stacking - length_div, width_div : subdivides the box into sub-compartments in length and/or width. + - lite_style : render box as an economical shell without elevated floor + - unsupported_holes : render bottom holes as 3D printer friendly versions + which can be printed without supports + - label_width : width of top label ledge face overhang + - label_height : height of label ledge overhang + - scoop_rad : radius of the bottom scoop feature """ @@ -103,7 +109,13 @@ def render(self): "Cannot select both holes and lite box styles together" ) if self.wall_th > 1.5: - raise ValueError("Wall thickness cannot exceed 1.5 for lite box style") + raise ValueError( + "Wall thickness cannot exceed 1.5 mm for lite box style" + ) + if self.wall_th > 2.5: + raise ValueError("Wall thickness cannot exceed 2.5 mm") + if self.wall_th < 0.5: + raise ValueError("Wall thickness must be at least 0.5 mm") r = self.render_shell() rd = self.render_dividers() rs = self.render_scoops() diff --git a/cqgridfinity/gf_drawer.py b/cqgridfinity/gf_drawer.py index 96ae5ec..3d8ca4e 100644 --- a/cqgridfinity/gf_drawer.py +++ b/cqgridfinity/gf_drawer.py @@ -184,6 +184,7 @@ def render(self, arrows_top=True, arrows_bottom=True): rc = self.alignment_feature(as_cutter=False, horz=False) r = r.union(rc.translate((self.width_th / 2, sp_width, 0))) self._cq_obj = r + self._obj_label = "corner_spacer" return r def alignment_feature(self, as_cutter=False, horz=True): @@ -268,6 +269,7 @@ def render_length_filler(self, alignment_type="peg"): r = r.union(ra.translate((self.length_fill / 2, 0, 0))) r = r.union(ra.translate((-self.length_fill / 2, 0, 0))) self._cq_obj = r + self._obj_label = "length_spacer" return r def render_width_filler(self, arrows_top=True, arrows_bottom=True): @@ -288,6 +290,7 @@ def render_width_filler(self, arrows_top=True, arrows_bottom=True): r = r.cut(ra.translate((0, self.width_fill / 2, 0))) r = r.cut(ra.translate((0, -self.width_fill / 2, 0))) self._cq_obj = r + self._obj_label = "width_spacer" return r def render_full_set(self, include_baseplate=False): @@ -321,6 +324,7 @@ def render_full_set(self, include_baseplate=False): rb = bp.render().translate((self.size[0] / 2, self.size[1] / 2, 0)) r = r.union(rb) self._cq_obj = r + self._obj_label = "full_set" return r def render_half_set(self): @@ -362,4 +366,5 @@ def render_half_set(self): ) ) self._cq_obj = r + self._obj_label = "half_set" return r diff --git a/cqgridfinity/gf_obj.py b/cqgridfinity/gf_obj.py index cc6ca3f..26c3776 100644 --- a/cqgridfinity/gf_obj.py +++ b/cqgridfinity/gf_obj.py @@ -46,6 +46,7 @@ def __init__(self, **kwargs): self.width_u = 1 self.height_u = 1 self._cq_obj = None + self._obj_label = None for k, v in kwargs.items(): if k in self.__dict__: self.__dict__[k] = v @@ -192,7 +193,7 @@ def filename(self, prefix=None, path=None): if self.lite_style: prefix = prefix + "lite_" elif isinstance(self, GridfinityDrawerSpacer): - prefix = "gf_spacer_" + prefix = "gf_drawer_" elif isinstance(self, GridfinityRuggedBox): prefix = "gf_ruggedbox_" else: @@ -212,6 +213,8 @@ def filename(self, prefix=None, path=None): fn = fn + "x%d" % (self.width_div) else: fn = fn + "_div_x%d" % (self.width_div) + if abs(self.wall_th - GR_WALL) > 1e-3: + fn = fn + "_%.2f" % (self.wall_th) if self.no_lip: fn = fn + "_basic" if self.holes: @@ -225,6 +228,8 @@ def filename(self, prefix=None, path=None): fn = fn + "_labels" elif isinstance(self, GridfinityRuggedBox): fn = fn + "x%d" % (self.height_u) + if self._obj_label is not None: + fn = fn + "_%s" % (self._obj_label) if self.front_handle or self.front_label: fn = fn + "_fr-" if self.front_handle: @@ -241,6 +246,14 @@ def filename(self, prefix=None, path=None): fn = fn + "_stack" if self.lid_baseplate: fn = fn + "_lidbp" + elif isinstance(self, GridfinityDrawerSpacer): + if self._obj_label is not None: + fn = fn + "_%s" % (self._obj_label) + elif isinstance(self, GridfinityBaseplate): + if self.ext_depth > 0: + fn = fn + "x%.1f" % (self.ext_depth) + if self.corner_screws: + fn = fn + "_screwtabs" return fn def save_step_file(self, filename=None, path=None, prefix=None): @@ -251,7 +264,10 @@ def save_step_file(self, filename=None, path=None, prefix=None): ) if not fn.lower().endswith(".step"): fn = fn + ".step" - export_step_file(self.cq_obj, fn) + if isinstance(self.cq_obj, cq.Assembly): + self.cq_obj.save(fn) + else: + export_step_file(self.cq_obj, fn) def save_stl_file( self, filename=None, path=None, prefix=None, tol=1e-2, ang_tol=0.1 diff --git a/cqgridfinity/gf_ruggedbox.py b/cqgridfinity/gf_ruggedbox.py index a014afe..937428a 100644 --- a/cqgridfinity/gf_ruggedbox.py +++ b/cqgridfinity/gf_ruggedbox.py @@ -23,9 +23,6 @@ # # Gridfinity Rugged Boxes - -import math - import cadquery as cq from cadquery.selectors import StringSyntaxSelector from cqkit import ( @@ -47,7 +44,7 @@ size_3d, bounds_3d, ) -from cqkit import pprint_obj, Ribbon +from cqkit import Ribbon from cqgridfinity import * from .gf_helpers import * @@ -70,9 +67,16 @@ def __init__(self, length_u, width_u, height_u, **kwargs): self.front_label = True self.label_length = None self.label_height = None + self.label_th = GR_LABEL_TH self.back_feet = True - self.hinge_width = 32 + self.hinge_width = GR_HINGE_SZ self.hinge_bolted = False + self.box_color = cq.Color(0.25, 0.25, 0.25) + self.lid_color = cq.Color(0.25, 0.5, 0.75) + self.handle_color = cq.Color(0.75, 0.5, 0.25) + self.latch_color = cq.Color(0.75, 0.5, 0.25) + self.hinge_color = cq.Color(0.75, 0.5, 0.25) + self.label_color = cq.Color(0.7, 0.7, 0.7) for k, v in kwargs.items(): if k in self.__dict__: self.__dict__[k] = v @@ -446,7 +450,10 @@ def label_slot(self): def render_label(self): """Renders a label panel insert""" rs = rounded_rect_sketch(*self.label_size(tol=3), GR_RAD) - return cq.Workplane("XZ").placeSketch(rs).extrude(GR_LABEL_TH) + r = cq.Workplane("XZ").placeSketch(rs).extrude(self.label_th) + self._obj_label = "label" + self._cq_obj = r + return self._cq_obj def clasp_cut(self, as_lid=False): """Renders the vertical channel where the clasps / latch are installed.""" @@ -571,7 +578,9 @@ def render_handle(self): .extrude(8 * lt) .translate((-4 * lt, 0, h - M3_CLR_DIAM)) ) - return r + self._obj_label = "handle" + self._cq_obj = r + return self._cq_obj def render_back_foot(self): """Renders a corresponding rear foot the same depth as the hinge for standing @@ -706,9 +715,10 @@ def render_latch(self): r = r.union(rc.translate((-17.45, -w2, h2))) r = r.union(rotate_z(rc, 180).translate((-17.45, w2, h2))) self._cq_obj = rotate_z(recentre(r, "xy"), -90) + self._obj_label = "latch" return self._cq_obj - def render_hinge(self, as_closed=False): + def render_hinge(self, as_closed=False, section=None): """Renders the rear hinge.""" tol = 0.25 / 2 cl = 2 * (GR_HINGE_OFFS + GR_HINGE_D + GR_HINGE_W2 / 2) @@ -782,8 +792,15 @@ def _bracket(side="left"): if as_closed: rl = rotate_z(rl.translate((-ctr[0], -ctr[1], 0)), 90) rr = rotate_z(rr.translate((-ctr[0], -ctr[1], 0)), -90) - r = rl.union(rr) + if section is not None: + if section == "outer": + r = rr + else: + r = rl + else: + r = rl.union(rr) self._cq_obj = r + self._obj_label = "hinge" return self._cq_obj def render(self): @@ -863,6 +880,7 @@ def render(self): ) r = r.union(rb) self._cq_obj = r + self._obj_label = None return self._cq_obj def render_lid(self): @@ -907,7 +925,9 @@ def render_lid(self): for k, v in self.qtr_centres(tol=0.125, at_height=self.lid_height).items(): rq = quarter_circle(GR_REG_R0, GR_REG_R1, GR_REG_H, k) r = r.union(rq.translate(v)) + self._cq_obj = r + self._obj_label = "lid" return self._cq_obj def render_accessories(self): @@ -940,61 +960,60 @@ def render_accessories(self): r = r.union(rl.translate((40, -20, 0.5))) self._cq_obj = r + self._obj_label = "acc" return self._cq_obj def render_assembly(self): """Renders a CadQuery Assembly object representing the entire box with accessories""" r = self.render() - a = cq.Assembly( - obj=r, name="Gridfinity Rugged Box", color=cq.Color(0.25, 0.25, 0.25) - ) + a = cq.Assembly(obj=r, name="Gridfinity Rugged Box", color=self.box_color) r = self.render_lid() r = r.translate((0, 0, self.box_height)) - a.add(r, color=cq.Color(0.25, 0.5, 0.75), name="Lid") + a.add(r, color=self.lid_color, name="Lid") if self.front_handle: r = self.render_handle() zo = self.right_handle_centre[2] - (GR_HANDLE_SZ - M3_CB_DEPTH) r = r.translate((0, -self.box_width / 2 - GR_HANDLE_H / 2, zo)) - a.add(r, color=cq.Color(0.75, 0.5, 0.25), name="Handle") + a.add(r, color=self.handle_color, name="Handle") rf = rotate_x(self.render_latch(), -90) idx = 1 - latch_color = cq.Color(0.75, 0.5, 0.25) yo = GR_LATCH_H / 2 zo = self.box_height - GR_RIB_CTR + yo / 2 for pt in self.front_clasp_centres: - a.add( - rf.translate((pt[0], pt[1] - yo, zo)), - color=latch_color, - name="Latch %d" % (idx), - ) + name = "Latch %d" % (idx) + pt = (pt[0], pt[1] - yo, zo) + a.add(rf.translate(pt), color=self.latch_color, name=name) idx += 1 if self.side_clasps: rl = rotate_z(rotate_x(self.render_latch(), -90), -90) rr = rotate_z(rl, 180) for pt in self.side_clasp_centres: + name = "Latch %d" % (idx) + y = -yo if pt[0] < 0 else yo + pt = (pt[0] + y, pt[1], zo) if pt[0] < 0: - a.add( - rl.translate((pt[0] - yo, pt[1], zo)), - color=latch_color, - name="Latch %d" % (idx), - ) + a.add(rl.translate(pt), color=self.latch_color, name=name) else: - a.add( - rr.translate((pt[0] + yo, pt[1], zo)), - color=latch_color, - name="Latch %d" % (idx), - ) + a.add(rr.translate(pt), color=self.latch_color, name=name) idx += 1 - r = rotate_y(recentre(self.render_hinge(as_closed=True)), 90) - a.add(r.translate(self.hinge_centres[0]), color=latch_color, name="Left Hinge") - a.add(r.translate(self.hinge_centres[1]), color=latch_color, name="Right Hinge") + for i, section in [(a, b) for a in (0, 1) for b in ("inner", "outer")]: + r = recentre(self.render_hinge(as_closed=True, section=section), "yz") + r = rotate_y(r, 90) + name = "Right " if i else "Left " + name = name + "Hinge %s" % (section) + a.add( + r.translate(self.hinge_centres[i]), + color=self.hinge_color, + name=name, + ) if self.front_label: r = self.render_label() - a.add(r.translate(self.label_centre), color=latch_color, name="Label") - - return a + a.add(r.translate(self.label_centre), color=self.label_color, name="Label") + self._obj_label = "assembly" + self._cq_obj = a + return self._cq_obj diff --git a/cqgridfinity/scripts/gridfinitybase.py b/cqgridfinity/scripts/gridfinitybase.py index 4be873f..8fa003a 100644 --- a/cqgridfinity/scripts/gridfinitybase.py +++ b/cqgridfinity/scripts/gridfinitybase.py @@ -49,6 +49,41 @@ def main(): default="step", help="Output file format (STEP, STL, SVG) default=STEP", ) + parser.add_argument( + "-s", + "--screws", + default=False, + action="store_true", + help="Add screw mounting tabs to the corners (adds +5 mm to depth)", + ) + parser.add_argument( + "-d", + "--depth", + default=None, + action="store", + help="Extrude extended depth under baseplate by this amount", + ) + parser.add_argument( + "-hd", + "--holediam", + default=None, + action="store", + help="Corner mounting screw hole diameter (default=5)", + ) + parser.add_argument( + "-hc", + "--cskdiam", + default=None, + action="store", + help="Corner mounting screw countersink diameter (default=10)", + ) + parser.add_argument( + "-ca", + "--cskangle", + default=None, + action="store", + help="Corner mounting screw countersink angle (deg) (default=82)", + ) parser.add_argument( "-o", "--output", @@ -57,9 +92,17 @@ def main(): ) args = parser.parse_args() argsd = vars(args) + for k in ["depth", "holediam", "cskdiam", "cskangle"]: + if argsd[k] is not None: + argsd[k] = float(argsd[k]) base = GridfinityBaseplate( length_u=int(argsd["length"]), width_u=int(argsd["width"]), + ext_depth=argsd["depth"], + corner_screws=argsd["screws"], + csk_hole=argsd["holediam"], + csk_diam=argsd["cskdiam"], + csk_angle=argsd["cskangle"], ) print(title) print( diff --git a/cqgridfinity/scripts/gridfinitybox.py b/cqgridfinity/scripts/gridfinitybox.py index 175c200..5d5ab67 100644 --- a/cqgridfinity/scripts/gridfinitybox.py +++ b/cqgridfinity/scripts/gridfinitybox.py @@ -125,6 +125,13 @@ def main(): default=0, help="Split box width-wise with specified number of divider walls", ) + parser.add_argument( + "-wt", + "--wall", + action="store", + default=1.0, + help="Wall thickness (default=1 mm)", + ) parser.add_argument( "-f", "--format", @@ -142,6 +149,7 @@ def main(): solid_ratio = float(argsd["ratio"]) length_div = int(argsd["lengthdiv"]) width_div = int(argsd["widthdiv"]) + wall = float(argsd["wall"]) box = GridfinityBox( length_u=int(argsd["length"]), width_u=int(argsd["width"]), @@ -156,6 +164,7 @@ def main(): solid_ratio=solid_ratio, length_div=length_div, width_div=width_div, + wall_th=wall, ) if argsd["ecolite"]: bs = "lite " @@ -165,7 +174,7 @@ def main(): bs = "" print(title) print( - "Gridfinity %sbox: %dU x %dU x %dU (%.1f mm x %.1f mm x %.1f mm)" + "Gridfinity %sbox: %dU x %dU x %dU (%.1f mm x %.1f mm x %.1f mm), %.2f mm walls" % ( bs, box.length_u, @@ -174,6 +183,7 @@ def main(): box.length, box.width, box.height, + box.wall_th, ) ) if argsd["solid"]: diff --git a/cqgridfinity/scripts/ruggedbox.py b/cqgridfinity/scripts/ruggedbox.py index 816e1bb..4cc5c52 100644 --- a/cqgridfinity/scripts/ruggedbox.py +++ b/cqgridfinity/scripts/ruggedbox.py @@ -213,6 +213,21 @@ def main(): default=False, help="Generate accessory components only", ) + parser.add_argument( + "-gh", + "--hinge", + action="store_true", + default=False, + help="Generate hinge element only", + ) + parser.add_argument( + "-ge", + "--genlabel", + action="store_true", + default=False, + help="Generate label panel insert only", + ) + args = parser.parse_args() argsd = vars(args) box = GridfinityRuggedBox( @@ -295,12 +310,22 @@ def main(): if argsd["lid"]: print("Rendering lid...") r = box.render_lid() - save_asset(box, argsd, prefix="lid_") + save_asset(box, argsd) g = True if argsd["acc"]: print("Rendering accessory components...") r = box.render_accessories() - save_asset(box, argsd, prefix="acc_") + save_asset(box, argsd) + g = True + if argsd["hinge"]: + print("Rendering hinge components...") + r = box.render_hinge() + save_asset(box, argsd) + g = True + if argsd["genlabel"]: + print("Rendering label panel...") + r = box.render_label() + save_asset(box, argsd) g = True if not g: print("Rendering full assembly...") diff --git a/tests/test_baseplate.py b/tests/test_baseplate.py index e9cb4f0..bcc32f2 100644 --- a/tests/test_baseplate.py +++ b/tests/test_baseplate.py @@ -8,7 +8,6 @@ from common_test import ( EXPORT_STEP_FILE_PATH, _almost_same, - _edges_match, _faces_match, _export_files, ) diff --git a/tests/test_rbox.py b/tests/test_rbox.py index bcd35f0..21f03bf 100644 --- a/tests/test_rbox.py +++ b/tests/test_rbox.py @@ -3,15 +3,12 @@ # my modules from cqgridfinity import * -# from cqkit.cq_helpers import size_3d from cqkit.cq_helpers import * from cqkit import * from common_test import ( EXPORT_STEP_FILE_PATH, _almost_same, - _edges_match, - _faces_match, _export_files, ) @@ -33,7 +30,35 @@ def test_rugged_box(): assert r is not None assert _almost_same(size_3d(r), (230.0, 194.15, 47.5)) if _export_files("rbox"): - export_step_file(r, EXPORT_STEP_FILE_PATH + os.sep + "rbox6.step") + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) r = b1.render_accessories() assert len(r.solids().vals()) == 16 + assert b1.filename() == "gf_ruggedbox_5x4x6_acc_fr-hl_sd-hc_stack_lidbp" + if _export_files("rbox"): + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) + + r = b1.render_handle() + assert b1.filename() == "gf_ruggedbox_5x4x6_handle_fr-hl_sd-hc_stack_lidbp" + if _export_files("rbox"): + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) + + r = b1.render_hinge() + assert b1.filename() == "gf_ruggedbox_5x4x6_hinge_fr-hl_sd-hc_stack_lidbp" + if _export_files("rbox"): + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) + + r = b1.render_label() + assert b1.filename() == "gf_ruggedbox_5x4x6_label_fr-hl_sd-hc_stack_lidbp" + if _export_files("rbox"): + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) + + r = b1.render_latch() + assert b1.filename() == "gf_ruggedbox_5x4x6_latch_fr-hl_sd-hc_stack_lidbp" + if _export_files("rbox"): + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) + + if _export_files("rbox"): + r = b1.render_assembly() + assert b1.filename() == "gf_ruggedbox_5x4x6_assembly_fr-hl_sd-hc_stack_lidbp" + b1.save_step_file(path=EXPORT_STEP_FILE_PATH) diff --git a/tests/test_spacer.py b/tests/test_spacer.py index e7e4ea8..c89e004 100644 --- a/tests/test_spacer.py +++ b/tests/test_spacer.py @@ -52,6 +52,9 @@ def test_spacer(): assert _almost_same(s1.length_th, 8.10, tol=0.01) assert _almost_same(s1.width_th, 19.80, tol=0.01) + +def test_spacer_render(): + s1 = GridfinityDrawerSpacer(tolerance=0.25) dx, dy = INCHES(22 + 15 / 16), INCHES(16.25) s1.best_fit_to_dim(dx, dy) assert s1.size_u[0] == 13 @@ -66,29 +69,26 @@ def test_spacer(): assert _almost_same(s1.width_th, 18.06, tol=0.01) r = s1.render_full_set() assert _almost_same(size_3d(r), (582.6125, 412.75, 5)) + assert s1.filename() == "gf_drawer_4x3_full_set" + if _export_files("spacer"): + s1.save_step_file(path=EXPORT_STEP_FILE_PATH) rh = s1.render_half_set() assert _almost_same(size_3d(rh), (253.084, 177.0625, 5)) + assert s1.filename() == "gf_drawer_4x3_half_set" + if _export_files("spacer"): + s1.save_step_file(path=EXPORT_STEP_FILE_PATH) + r = s1.render_length_filler() + assert s1.filename() == "gf_drawer_4x3_length_spacer" if _export_files("spacer"): - export_step_file(r, EXPORT_STEP_FILE_PATH + os.sep + "full_set.step") - export_step_file(rh, EXPORT_STEP_FILE_PATH + os.sep + "half_set.step") - rc = s1.render() - export_step_file(rc, EXPORT_STEP_FILE_PATH + os.sep + "corner_spacer.step") - rl = s1.render_length_filler() - rw = s1.render_width_filler() - if rl is not None: - export_step_file(rl, EXPORT_STEP_FILE_PATH + os.sep + "length_filler.step") - if rw is not None: - export_step_file(rw, EXPORT_STEP_FILE_PATH + os.sep + "width_filler.step") + s1.save_step_file(path=EXPORT_STEP_FILE_PATH) + r = s1.render_width_filler() + assert s1.filename() == "gf_drawer_4x3_width_spacer" + if _export_files("spacer"): + s1.save_step_file(path=EXPORT_STEP_FILE_PATH) -# if _EXPORT_STEP_FILES: -# dx, dy = 580, 410 -# s1.best_fit_to_dim(dx, dy) -# r = s1.render_full_set() -# rh = s1.render_half_set() -# export_step_file(r, "./testfiles/full_set.step") -# export_step_file(rh, "./testfiles/half_set.step") -# exporters.export( -# rh, "./testfiles/half_set.stl", tolerance=1e-2, angularTolerance=0.15 -# ) + r = s1.render() + assert s1.filename() == "gf_drawer_4x3_corner_spacer" + if _export_files("spacer"): + s1.save_step_file(path=EXPORT_STEP_FILE_PATH)