Slot and SlottedEdge: Move code from typetray.py to boxes.py

This commit is contained in:
Florian Festi 2014-04-06 16:21:29 +02:00
parent 5d3edc1b6c
commit ade81f9e64
2 changed files with 42 additions and 40 deletions

View File

@ -75,7 +75,6 @@ class Bolts(BoltPolicy):
#print pos, result, ((float(pos)*(self.bolts+1)/self.fingers)-0.01), ((float(pos+1)*(self.bolts+1)/self.fingers)-0.01)
return result
#############################################################################
### Settings
#############################################################################
@ -153,6 +152,45 @@ class OutSetEdge(Edge):
def width(self):
return self.boxes.thickness
class Slot(Edge):
def __init__(self, boxes, depth):
Edge.__init__(self, boxes, None)
self.depth = depth
def __call__(self, length, **kw):
if self.depth:
self.boxes.corner(90)
self.boxes.edge(self.depth)
self.boxes.corner(-90)
self.boxes.edge(length)
self.boxes.corner(-90)
self.boxes.edge(self.depth)
self.boxes.corner(90)
else:
self.boxes.edge(self.length)
class SlottedEdge(Edge):
def __init__(self, boxes, sections, edge="e", slots=0):
Edge.__init__(self, boxes, None)
self.edge = self.edges.get(edge, edge)
self.sections = sections
self.slots = slots
def width(self):
return self.edge.width()
def margin(self):
return self.edge.margin()
def __call__(self, length, **kw):
for l in self.sections[:-1]:
self.edge(l)
if self.slots:
Slot(self.boxes, self.slots)(self.thickness)
else:
self.edge(self.thickness)
self.edge(self.sections[-1])
class FingerJointSettings(Settings):
absolute_params = {

View File

@ -16,42 +16,6 @@
from boxes import *
class BottomEdge(FingerJointEdge):
def __init__(self, boxes, sections, slot=0):
FingerJointEdge.__init__(self, boxes, None)
self.sections = sections
self.slot = slot
def _slot(self):
if self.slot:
self.boxes.corner(90)
self.boxes.edge(self.slot)
self.boxes.corner(-90)
self.boxes.edge(self.thickness)
self.boxes.corner(-90)
self.boxes.edge(self.slot)
self.boxes.corner(90)
else:
self.boxes.edge(self.thickness)
def __call__(self, l, **kw):
for x in self.sections[:-1]:
self.boxes.fingerJointEdge(x)
self._slot()
self.boxes.fingerJointEdge(self.sections[-1])
class TopEdge(BottomEdge):
margin = Edge.margin
width = Edge.width
def __call__(self, l, **kw):
for x in self.sections[:-1]:
self.boxes.edge(x)
self._slot()
self.boxes.edge(self.sections[-1])
class TypeTray(Boxes):
def __init__(self, x, y, h, hi=None, **kw):
self.x, self.y, self.h = x, y, h
@ -124,12 +88,12 @@ class TypeTray(Boxes):
move="right")
# Inner walls
for i in range(len(self.x)-1):
e = [BottomEdge(self, self.y, 0.5*hi), "f", "e", "f"]
e = [SlottedEdge(self, self.y, "f", slots=0.5*hi), "f", "e", "f"]
self.rectangularWall(y, hi, e,
move="up")
for i in range(len(self.y)-1):
e = [BottomEdge(self, self.x), "f",
TopEdge(self, self.x, 0.5*hi), "f"]
e = [SlottedEdge(self, self.x, "f"), "f",
SlottedEdge(self, self.x[::-1], "e", slots=0.5*hi), "f"]
self.rectangularWall(x, hi, e,
move="up")
self.close()