From 20f45224fb3039ffabf2d594796481bab7751885 Mon Sep 17 00:00:00 2001 From: "suks.ae" Date: Wed, 25 May 2022 23:31:55 +0200 Subject: [PATCH] Add MountingEdge and add it to top_edge. --- boxes/__init__.py | 6 +- boxes/edges.py | 130 ++++++++++++++++++++++++++++++++ boxes/lids.py | 13 +++- documentation/src/api_edges.rst | 1 + 4 files changed, 147 insertions(+), 3 deletions(-) diff --git a/boxes/__init__.py b/boxes/__init__.py index 775fc49..c7e670a 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -449,7 +449,7 @@ class Boxes: if default is None: default = "e" self.argparser.add_argument( "--top_edge", action="store", - type=ArgparseEdgeType("efFhcESŠikvLt"), choices=list("efFhcESŠikvfLt"), + type=ArgparseEdgeType("efFhcESŠikvLtG"), choices=list("efFhcESŠikvfLtG"), default=default, help="edge type for top edge") elif arg == "outside": if default is None: default = True @@ -567,7 +567,9 @@ class Boxes: # Grooved Edge edges.GroovedSettings(self.thickness, True, **self.edgesettings.get("Grooved", {})).edgeObjects(self) - + # Mounting Edge + edges.MountingSettings(self.thickness, True, + **self.edgesettings.get("Mounting", {})).edgeObjects(self) # HexHoles self.hexHolesSettings = HexHolesSettings(self.thickness, True, **self.edgesettings.get("HexHoles", {})) diff --git a/boxes/edges.py b/boxes/edges.py index 7efad96..88e88c8 100644 --- a/boxes/edges.py +++ b/boxes/edges.py @@ -341,6 +341,136 @@ class OutSetEdge(Edge): def startwidth(self): return self.boxes.thickness +############################################################################# +#### MountingEdge +############################################################################# + +class MountingSettings(Settings): + """Settings for Mouning Edge +Values: +* absolute_params + + * style : "straight edge, within" : edge style + * side : "left" : side of box (not all valid configurations make sense...) + * num : 2 : number of mounting holes (integer) + * margin : 0.125 : minimum space left and right without holes (fraction of the edge length) + * d_shaft : 3.0 : shaft diameter of mounting screw (in mm) + * d_head : 6.5 : head diameter of mounting screw (in mm) +""" + + PARAM_IN = "straight edge, within" + PARAM_EXT = "straight edge, extended" + PARAM_TAB = "mounting tab" + + PARAM_LEFT = "left" + PARAM_BACK = "back" + PARAM_RIGHT = "right" + PARAM_FRONT = "front" + + absolute_params = { + "style": (PARAM_IN, PARAM_EXT, PARAM_TAB), + "side": (PARAM_LEFT, PARAM_BACK, PARAM_RIGHT, PARAM_FRONT), + "num": 2, + "margin": 0.125, + "d_shaft" : 3.0, + "d_head" : 6.5 + } + + def edgeObjects(self, boxes, chars="G", add=True): + edges = [MountingEdge(boxes, self)] + return self._edgeObjects(edges, boxes, chars, add) + + +class MountingEdge(BaseEdge): + description = """Edge with pear shaped mounting holes""" # for slide-on mounting using flat-head screws""" + char = 'G' + + def margin(self): + if self.settings.style == MountingSettings.PARAM_TAB: + return 2.75 * self.boxes.thickness + self.settings.d_head + else: + return 0 + + def startwidth(self): + if self.settings.style == MountingSettings.PARAM_EXT: + return 2.5 * self.boxes.thickness + self.settings.d_head + else: + return 0 + + def __call__(self, length, **kw): + if length == 0.0: + return + + def check_bounds(val, mn, mx, name): + if not mn <= val <= mx: + raise ValueError(f"MountingEdge: {name} needs to be in [{mn}, {mx}] but is {val}") + + style = self.settings.style + margin = self.settings.margin + num = self.settings.num + ds = self.settings.d_shaft + dh = self.settings.d_head + if dh > 0: + width = 3 * self.thickness + dh + else: + width = ds + + if num != int(num): + raise ValueError(f"MountingEdge: num needs to be an integer number") + + check_bounds(margin, 0, 0.5, "margin") + if not dh == 0: + if not dh > ds: + raise ValueError(f"MountingEdge: d_shaft needs to be in 0 or > {ds}, but is {dh}") + + # Check how many holes fit + count = max(1, int(num)) + if count > 1: + margin_ = length * margin + gap = (length - 2 * margin_ - width*count) / (count - 1) + if gap < width: + count = int(((length - 2 * margin + width) / (2 * width)) - 0.5) + if count < 1: + self.edge(length) + return + if count < 2: + margin_ = (length - width) / 2 + gap = 0 + else: + gap = (length - 2 * margin_ - width*count) / (count - 1) + else: + margin_ = (length - width) / 2 + gap = 0 + + if style == MountingSettings.PARAM_TAB: + + # The edge until the first groove + self.edge(margin_, tabs=1) + + for i in range(count): + if i > 0: + self.edge(gap) + self.corner(-90,self.thickness/2) + self.edge(dh+1.5*ds-self.thickness/4-dh/2) + self.corner(90,self.thickness+dh/2) + self.corner(-90) + self.corner(90) + self.mountingHole(0,self.thickness*1.25+ds/2,ds,dh,-90) + self.corner(90,self.thickness+dh/2) + self.edge(dh+1.5*ds-self.thickness/4-dh/2) + self.corner(-90,self.thickness/2) + + # The edge until the end + self.edge(margin_, tabs=1) + else: + x = margin_ + for i in range(count): + x += width/2 + self.mountingHole(x,ds/2+self.thickness*1.5,ds,dh,-90) + x += width/2 + x += gap + self.edge(length) + ############################################################################# #### GroovedEdge diff --git a/boxes/lids.py b/boxes/lids.py index 5bd7ec5..783fb7d 100644 --- a/boxes/lids.py +++ b/boxes/lids.py @@ -92,7 +92,7 @@ class _TopEdge(Boxes): def addTopEdgeSettings(self, fingerjoint={}, stackable={}, hinge={}, cabinethinge={}, lid={}, click={}, - roundedtriangle={}): + roundedtriangle={}, mounting={}): self.addSettingsArgs(edges.FingerJointSettings, **fingerjoint) self.addSettingsArgs(edges.StackableSettings, **stackable) self.addSettingsArgs(edges.HingeSettings, **hinge) @@ -100,6 +100,7 @@ class _TopEdge(Boxes): self.addSettingsArgs(edges.LidSettings, **lid) self.addSettingsArgs(edges.ClickSettings, **click) self.addSettingsArgs(edges.RoundedTriangleEdgeSettings, **roundedtriangle) + self.addSettingsArgs(edges.MountingSettings, **mounting) def topEdges(self, top_edge): t1 = t2 = t3 = t4 = self.edges.get(top_edge, self.edges["e"]) @@ -117,6 +118,16 @@ class _TopEdge(Boxes): t2 = t3 = t4 = "e" elif t1.char == "t": t1 = t3 = "e" + elif t1.char == "G": + t1 = t2 = t3 = t4 = "e" + if self.edges["G"].settings.side == edges.MountingSettings.PARAM_LEFT: + t1 = "G" + elif self.edges["G"].settings.side == edges.MountingSettings.PARAM_RIGHT: + t3 = "G" + elif self.edges["G"].settings.side == edges.MountingSettings.PARAM_FRONT: + t4 = "G" + else: #PARAM_BACK + t2 = "G" return [t1, t2, t3, t4] def drawLid(self, x, y, top_edge, bedBolts=[None, None]): diff --git a/documentation/src/api_edges.rst b/documentation/src/api_edges.rst index a4c8b8b..66784ae 100644 --- a/documentation/src/api_edges.rst +++ b/documentation/src/api_edges.rst @@ -38,6 +38,7 @@ A set of instances are kept the ``.edges`` attribute of the * f : FingerJointEdge * F : FingerJointEdgeCounterPart * g : GrippingEdge +* G : MountingEdge * h : FingerHoleEdge * ijk : Hinge (start, end, both sides) * IJK : HingePin (start, end, both sides)