Add edgeObjects() method to Settings to create Edge objects
This commit is contained in:
parent
981c99a7d8
commit
aa5fa73c8a
|
@ -335,58 +335,43 @@ class Boxes:
|
|||
else:
|
||||
setattr(self, name, part)
|
||||
|
||||
def addParts(self, parts):
|
||||
for part in parts:
|
||||
self.addPart(part)
|
||||
|
||||
def _buildObjects(self):
|
||||
"""Add default edges and parts """
|
||||
self.edges = {}
|
||||
self.addPart(edges.Edge(self, None))
|
||||
self.addPart(edges.OutSetEdge(self, None))
|
||||
s = edges.GripSettings(self.thickness)
|
||||
self.addPart(edges.GrippingEdge(self, s))
|
||||
edges.GripSettings(self.thickness).edgeObjects(self)
|
||||
|
||||
# Finger joints
|
||||
# Share settings object
|
||||
s = edges.FingerJointSettings(self.thickness, True,
|
||||
**self.edgesettings.get("FingerJoint", {}))
|
||||
self.addPart(edges.FingerJointEdge(self, s))
|
||||
self.addPart(edges.FingerJointEdgeCounterPart(self, s))
|
||||
s.edgeObjects(self)
|
||||
self.addPart(edges.FingerHoles(self, s), name="fingerHolesAt")
|
||||
self.addPart(edges.FingerHoleEdge(self, None))
|
||||
# Stackable
|
||||
ss = edges.StackableSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Stackable", {}))
|
||||
self.addPart(edges.StackableEdge(self, ss, s))
|
||||
self.addPart(edges.StackableEdgeTop(self, ss, s))
|
||||
edges.StackableSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Stackable", {})).edgeObjects(self)
|
||||
# Dove tail joints
|
||||
s = edges.DoveTailSettings(self.thickness, True,
|
||||
**self.edgesettings.get("DoveTail", {}))
|
||||
self.addPart(edges.DoveTailJoint(self, s))
|
||||
self.addPart(edges.DoveTailJointCounterPart(self, s))
|
||||
edges.DoveTailSettings(self.thickness, True,
|
||||
**self.edgesettings.get("DoveTail", {})).edgeObjects(self)
|
||||
# Flex
|
||||
s = edges.FlexSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Flex", {}))
|
||||
self.addPart(edges.FlexEdge(self, s))
|
||||
# Clickable
|
||||
s = edges.ClickSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Click", {}))
|
||||
self.addPart(edges.ClickConnector(self, s))
|
||||
self.addPart(edges.ClickEdge(self, s))
|
||||
edges.ClickSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Click", {})).edgeObjects(self)
|
||||
# Hinges
|
||||
s = edges.HingeSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Hinge", {}))
|
||||
|
||||
for i in range(1, 4):
|
||||
self.addPart(edges.Hinge(self, s, i))
|
||||
self.addPart(edges.HingePin(self, s, i))
|
||||
edges.HingeSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Hinge", {})).edgeObjects(self)
|
||||
# Sliding Lid
|
||||
s = edges.LidSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Lid", {}))
|
||||
edges.LidSettings(self.thickness, True,
|
||||
**self.edgesettings.get("Lid", {})).edgeObjects(self)
|
||||
|
||||
self.addPart(edges.LidEdge(self, s))
|
||||
self.addPart(edges.LidHoleEdge(self, s))
|
||||
self.addPart(edges.LidSideRight(self, s))
|
||||
self.addPart(edges.LidSideLeft(self, s))
|
||||
self.addPart(edges.LidRight(self, s))
|
||||
self.addPart(edges.LidLeft(self, s))
|
||||
# Nuts
|
||||
self.addPart(NutHole(self, None))
|
||||
# Gears
|
||||
|
|
|
@ -187,6 +187,31 @@ class Settings(object):
|
|||
self.values[name] = value * factor
|
||||
self.setValues(thickness, relative, **kw)
|
||||
|
||||
def edgeObjects(self, boxes, chars="", add=True):
|
||||
"""
|
||||
Generate Edge objects using this kind of settings
|
||||
|
||||
:param boxes: Boxes object
|
||||
:param chars: sequence of chars to be used by Edge objects
|
||||
:param add: add the resulting Edge objects to the Boxes object's edges
|
||||
|
||||
"""
|
||||
edges = []
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
def _edgeObjects(self, edges, boxes, chars, add):
|
||||
for i, edge in enumerate(edges):
|
||||
try:
|
||||
char = chars[i]
|
||||
edge.char = char
|
||||
except IndexError:
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
if add:
|
||||
boxes.addParts(edges)
|
||||
return edges
|
||||
|
||||
def setValues(self, thickness, relative=True, **kw):
|
||||
"""
|
||||
Set values
|
||||
|
@ -304,6 +329,9 @@ Values:
|
|||
"depth": 0.3,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="g", add=True):
|
||||
edges = [GrippingEdge(boxes, self)]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class GrippingEdge(BaseEdge):
|
||||
description = """Corrugated edge useful as an gipping area"""
|
||||
|
@ -493,6 +521,13 @@ Values:
|
|||
"play" : 0.0,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="fFh", add=True):
|
||||
edges = [FingerJointEdge(boxes, self),
|
||||
FingerJointEdgeCounterPart(boxes, self),
|
||||
FingerHoleEdge(boxes, self),
|
||||
]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class FingerJointBase:
|
||||
|
||||
def calcFingers(self, length, bedBolts):
|
||||
|
@ -598,11 +633,9 @@ class FingerHoles(FingerJointBase):
|
|||
"""
|
||||
self.boxes.ctx.save()
|
||||
self.boxes.moveTo(x, y, angle)
|
||||
|
||||
s, f = self.settings.space, self.settings.finger
|
||||
p = self.settings.play
|
||||
b = self.boxes.burn
|
||||
|
||||
fingers, leftover = self.calcFingers(length, bedBolts)
|
||||
|
||||
if self.boxes.debug:
|
||||
|
@ -698,6 +731,11 @@ Values:
|
|||
"holedistance": 1.0,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="sS", add=True, fingersettings=None):
|
||||
fingersettings = fingersettings or boxes.edges["f"].settings
|
||||
edges = [StackableEdge(boxes, self, fingersettings),
|
||||
StackableEdgeTop(boxes, self, fingersettings)]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class StackableEdge(BaseEdge):
|
||||
"""Edge for having stackable Boxes. The Edge creates feet on the bottom
|
||||
|
@ -781,6 +819,16 @@ Values:
|
|||
"grip_length": 0,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="iIjJkK", add=True):
|
||||
edges = [
|
||||
Hinge(boxes, self, 1),
|
||||
HingePin(boxes, self, 1),
|
||||
Hinge(boxes, self, 2),
|
||||
HingePin(boxes, self, 2),
|
||||
Hinge(boxes, self, 3),
|
||||
HingePin(boxes, self, 3),
|
||||
]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class Hinge(BaseEdge):
|
||||
char = 'i'
|
||||
|
@ -1024,6 +1072,16 @@ Inherited:
|
|||
"spring": ("both", "none", "left", "right", "both"),
|
||||
} )
|
||||
|
||||
def edgeObjects(self, boxes, chars=None, add=True):
|
||||
edges = [LidEdge(boxes, self),
|
||||
LidHoleEdge(boxes, self),
|
||||
LidRight(boxes, self),
|
||||
LidLeft(boxes, self),
|
||||
LidSideRight(boxes, self),
|
||||
LidSideLeft(boxes, self),
|
||||
]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class LidEdge(FingerJointEdge):
|
||||
char = "l"
|
||||
description = "Edge for slide on lid"
|
||||
|
@ -1156,6 +1214,10 @@ class ClickSettings(Settings):
|
|||
"bottom_radius": 0.1,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="cC", add=True):
|
||||
edges = [ClickConnector(boxes, self),
|
||||
ClickEdge(boxes, self)]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class ClickConnector(BaseEdge):
|
||||
char = "c"
|
||||
|
@ -1299,6 +1361,10 @@ Values:
|
|||
"radius": 0.2,
|
||||
}
|
||||
|
||||
def edgeObjects(self, boxes, chars="dD", add=True):
|
||||
edges = [DoveTailJoint(boxes, self),
|
||||
DoveTailJointCounterPart(boxes, self)]
|
||||
return self._edgeObjects(edges, boxes, chars, add)
|
||||
|
||||
class DoveTailJoint(BaseEdge):
|
||||
"""Edge with dove tail joints """
|
||||
|
|
Loading…
Reference in New Issue