Add MountingEdge

and add it to top_edge.
This commit is contained in:
suks.ae 2022-05-25 23:31:55 +02:00 committed by Florian Festi
parent e6ef17c070
commit 20f45224fb
4 changed files with 147 additions and 3 deletions

View File

@ -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", {}))

View File

@ -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

View File

@ -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]):

View File

@ -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)