Add edgeObjects() method to Settings to create Edge objects

This commit is contained in:
Florian Festi 2016-11-23 21:11:15 +01:00
parent 981c99a7d8
commit aa5fa73c8a
2 changed files with 84 additions and 33 deletions

View File

@ -335,58 +335,43 @@ class Boxes:
else: else:
setattr(self, name, part) setattr(self, name, part)
def addParts(self, parts):
for part in parts:
self.addPart(part)
def _buildObjects(self): def _buildObjects(self):
"""Add default edges and parts """ """Add default edges and parts """
self.edges = {} self.edges = {}
self.addPart(edges.Edge(self, None)) self.addPart(edges.Edge(self, None))
self.addPart(edges.OutSetEdge(self, None)) self.addPart(edges.OutSetEdge(self, None))
s = edges.GripSettings(self.thickness) edges.GripSettings(self.thickness).edgeObjects(self)
self.addPart(edges.GrippingEdge(self, s))
# Finger joints # Finger joints
# Share settings object # Share settings object
s = edges.FingerJointSettings(self.thickness, True, s = edges.FingerJointSettings(self.thickness, True,
**self.edgesettings.get("FingerJoint", {})) **self.edgesettings.get("FingerJoint", {}))
self.addPart(edges.FingerJointEdge(self, s)) s.edgeObjects(self)
self.addPart(edges.FingerJointEdgeCounterPart(self, s))
self.addPart(edges.FingerHoles(self, s), name="fingerHolesAt") self.addPart(edges.FingerHoles(self, s), name="fingerHolesAt")
self.addPart(edges.FingerHoleEdge(self, None))
# Stackable # Stackable
ss = edges.StackableSettings(self.thickness, True, edges.StackableSettings(self.thickness, True,
**self.edgesettings.get("Stackable", {})) **self.edgesettings.get("Stackable", {})).edgeObjects(self)
self.addPart(edges.StackableEdge(self, ss, s))
self.addPart(edges.StackableEdgeTop(self, ss, s))
# Dove tail joints # Dove tail joints
s = edges.DoveTailSettings(self.thickness, True, edges.DoveTailSettings(self.thickness, True,
**self.edgesettings.get("DoveTail", {})) **self.edgesettings.get("DoveTail", {})).edgeObjects(self)
self.addPart(edges.DoveTailJoint(self, s))
self.addPart(edges.DoveTailJointCounterPart(self, s))
# Flex # Flex
s = edges.FlexSettings(self.thickness, True, s = edges.FlexSettings(self.thickness, True,
**self.edgesettings.get("Flex", {})) **self.edgesettings.get("Flex", {}))
self.addPart(edges.FlexEdge(self, s)) self.addPart(edges.FlexEdge(self, s))
# Clickable # Clickable
s = edges.ClickSettings(self.thickness, True, edges.ClickSettings(self.thickness, True,
**self.edgesettings.get("Click", {})) **self.edgesettings.get("Click", {})).edgeObjects(self)
self.addPart(edges.ClickConnector(self, s))
self.addPart(edges.ClickEdge(self, s))
# Hinges # Hinges
s = edges.HingeSettings(self.thickness, True, edges.HingeSettings(self.thickness, True,
**self.edgesettings.get("Hinge", {})) **self.edgesettings.get("Hinge", {})).edgeObjects(self)
for i in range(1, 4):
self.addPart(edges.Hinge(self, s, i))
self.addPart(edges.HingePin(self, s, i))
# Sliding Lid # Sliding Lid
s = edges.LidSettings(self.thickness, True, edges.LidSettings(self.thickness, True,
**self.edgesettings.get("Lid", {})) **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 # Nuts
self.addPart(NutHole(self, None)) self.addPart(NutHole(self, None))
# Gears # Gears

View File

@ -187,6 +187,31 @@ class Settings(object):
self.values[name] = value * factor self.values[name] = value * factor
self.setValues(thickness, relative, **kw) 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): def setValues(self, thickness, relative=True, **kw):
""" """
Set values Set values
@ -304,6 +329,9 @@ Values:
"depth": 0.3, "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): class GrippingEdge(BaseEdge):
description = """Corrugated edge useful as an gipping area""" description = """Corrugated edge useful as an gipping area"""
@ -493,6 +521,13 @@ Values:
"play" : 0.0, "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: class FingerJointBase:
def calcFingers(self, length, bedBolts): def calcFingers(self, length, bedBolts):
@ -598,11 +633,9 @@ class FingerHoles(FingerJointBase):
""" """
self.boxes.ctx.save() self.boxes.ctx.save()
self.boxes.moveTo(x, y, angle) self.boxes.moveTo(x, y, angle)
s, f = self.settings.space, self.settings.finger s, f = self.settings.space, self.settings.finger
p = self.settings.play p = self.settings.play
b = self.boxes.burn b = self.boxes.burn
fingers, leftover = self.calcFingers(length, bedBolts) fingers, leftover = self.calcFingers(length, bedBolts)
if self.boxes.debug: if self.boxes.debug:
@ -698,6 +731,11 @@ Values:
"holedistance": 1.0, "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): class StackableEdge(BaseEdge):
"""Edge for having stackable Boxes. The Edge creates feet on the bottom """Edge for having stackable Boxes. The Edge creates feet on the bottom
@ -781,6 +819,16 @@ Values:
"grip_length": 0, "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): class Hinge(BaseEdge):
char = 'i' char = 'i'
@ -1024,6 +1072,16 @@ Inherited:
"spring": ("both", "none", "left", "right", "both"), "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): class LidEdge(FingerJointEdge):
char = "l" char = "l"
description = "Edge for slide on lid" description = "Edge for slide on lid"
@ -1156,6 +1214,10 @@ class ClickSettings(Settings):
"bottom_radius": 0.1, "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): class ClickConnector(BaseEdge):
char = "c" char = "c"
@ -1299,6 +1361,10 @@ Values:
"radius": 0.2, "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): class DoveTailJoint(BaseEdge):
"""Edge with dove tail joints """ """Edge with dove tail joints """