Box2: Refactor lid generation out of the Box2 class

This commit is contained in:
Florian Festi 2017-02-12 13:11:36 +01:00
parent dd6c5560f9
commit b59de950c0
1 changed files with 101 additions and 72 deletions

View File

@ -18,37 +18,23 @@ from boxes import *
from boxes.edges import Bolts
import inspect
class Box2(Boxes):
"""Box various options for different stypes and lids"""
class ChestLid(Boxes):
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.StackableSettings)
self.addSettingsArgs(edges.HingeSettings)
self.addSettingsArgs(edges.CabinetHingeSettings)
self.addSettingsArgs(edges.LidSettings)
self.addSettingsArgs(edges.ClickSettings)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("top_edge", "bottom_edge", "x", "y", "h")
self.argparser.add_argument(
"--lid", action="store", type=str, default="default (none)",
choices=("default (none)", "chest", "flat"),
help="additional lid")
self.angle = 0
def getR(self):
x, y, h, angle = self.x, self.y, self.h, self.angle
def getR(self, x, angle=0):
t = self.thickness
d = x - 2*math.sin(math.radians(angle)) * (3*t)
r = d / 2.0 / math.cos(math.radians(angle))
return r
def side(self, move=""):
x, y, h, angle = self.x, self.y, self.h, self.angle
def side(self, x, angle=0, move=""):
if "a" not in self.edges:
s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0)
s.edgeObjects(self, "aA.")
t = self.thickness
r = self.getR()
r = self.getR(x, angle)
if self.move(x+2*t, 0.5*x+3*t, move, True):
return
@ -62,13 +48,20 @@ class Box2(Boxes):
self.move(x+2*t, 0.5*x+3*t, move, False)
def top(self):
# XXX move param
x, y, h = self.x, self.y, self.h
t = self.thickness
angle = 30
def top(self, x, y, angle=0, move=None):
if "a" not in self.edges:
s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0)
s.edgeObjects(self, "aA.")
l = math.radians(180-2*angle) * self.getR()
t = self.thickness
l = math.radians(180-2*angle) * self.getR(x, angle)
tw = l + 6*t
th = y+2*t
if self.move(tw, th, move, True):
return
self.edges["A"](3*t)
self.edges["X"](l, y+2*t)
@ -83,21 +76,33 @@ class Box2(Boxes):
self.edge(y+2*t)
self.corner(90)
def render(self):
x, y, h = self.x, self.y, self.h
self.move(tw, th, move)
self.open()
# generate g,G finger joints with default settings
s = edges.FingerJointSettings(self.thickness)
g = edges.FingerJointEdge(self, s)
g.char = 'a'
self.addPart(g)
G = edges.FingerJointEdgeCounterPart(self, s)
G.char = 'A'
self.addPart(G)
def drawAddOnLid(self, x, y, style):
if style == "flat":
self.rectangularWall(x, y, "eeee", move="right")
self.rectangularWall(x, y, "EEEE", move="up")
elif style == "chest":
self.side(x, move="right")
self.side(x, move="up")
self.side(x, move="left only")
self.top(x, y, move="up")
else:
return False
return True
b = self.edges.get(self.bottom_edge, self.edges["F"])
t1 = t2 = t3 = t4 = self.edges.get(self.top_edge, self.edges["e"])
class TopEdge(Boxes):
def addTopEdgeSettings(self):
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.StackableSettings)
self.addSettingsArgs(edges.HingeSettings)
self.addSettingsArgs(edges.CabinetHingeSettings)
self.addSettingsArgs(edges.LidSettings)
self.addSettingsArgs(edges.ClickSettings)
def topEdges(self, top_edge):
t1 = t2 = t3 = t4 = self.edges.get(top_edge, self.edges["e"])
if t1.char == "i":
t2 = t4 = "e"
@ -111,7 +116,56 @@ class Box2(Boxes):
elif t1.char == "v":
t2 = t3 = t4 = "e"
self.edges["k"].settings.setValues(self.thickness, outset=True)
return [t1, t2, t3, t4]
def drawLid(self, x, y, top_edge, bedBolts=[None, None]):
d2, d3 = bedBolts
if top_edge == "c":
self.rectangularWall(x, y, "CCCC", bedBolts=[d2, d3, d2, d3], move="up")
elif top_edge == "f":
self.rectangularWall(x, y, "FFFF", move="up")
elif top_edge == "L":
self.rectangularWall(x, y, "nlmE", move="up")
elif top_edge == "i":
self.rectangularWall(x, y, "IEJe", move="up")
elif top_edge == "k":
outset = self.edges["k"].settings.outset
self.edges["k"].settings.setValues(self.thickness, outset=True)
lx = x/2.0-0.1*self.thickness
self.edges['k'].settings.setValues(self.thickness, grip_length=5)
self.rectangularWall(lx, y, "IeJe", move="right")
self.rectangularWall(lx, y, "IeJe", move="up")
self.rectangularWall(lx, y, "IeJe", move="left only")
self.edges["k"].settings.setValues(self.thickness, outset=outset)
elif top_edge == "v":
self.rectangularWall(x, y, "VEEE", move="up")
self.edges["v"].parts(move="up")
else:
return False
return True
class Box2(TopEdge, ChestLid):
"""Box various options for different stypes and lids"""
def __init__(self):
Boxes.__init__(self)
self.addTopEdgeSettings()
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("top_edge", "bottom_edge", "x", "y", "h")
self.argparser.add_argument(
"--lid", action="store", type=str, default="default (none)",
choices=("default (none)", "chest", "flat"),
help="additional lid")
self.angle = 0
def render(self):
x, y, h = self.x, self.y, self.h
self.open()
t1, t2, t3, t4 = self.topEdges(self.top_edge)
b = self.edges.get(self.bottom_edge, self.edges["F"])
d2 = Bolts(2)
d3 = Bolts(3)
@ -128,36 +182,11 @@ class Box2(Boxes):
bedBolts=[d3], move="left")
self.rectangularWall(x, h, [b, "F", t3, "F"],
bedBolts=[d2], move="up only")
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right")
if self.top_edge == "c":
self.rectangularWall(x, y, "CCCC", bedBolts=[d2, d3, d2, d3], move="up")
elif self.top_edge == "f":
self.rectangularWall(x, y, "FFFF", move="up")
elif self.top_edge == "L":
self.rectangularWall(x, y, "nlmE", move="up")
elif self.top_edge == "i":
self.rectangularWall(x, y, "IEJe", move="up")
elif self.top_edge == "k":
lx = x/2.0-0.1*self.thickness
self.edges['k'].settings.setValues(self.thickness, grip_length=5)
self.rectangularWall(lx, y, "IeJe", move="right")
self.rectangularWall(lx, y, "IeJe", move="up")
elif self.top_edge == "v":
self.rectangularWall(x, y, "VEEE", move="up")
self.rectangularWall(x, y, "VEEE", move="left only")
self.edges["v"].parts()
else:
self.rectangularWall(x, y, "CCCC", bedBolts=[d2, d3, d2, d3], move="up only")
if self.lid == "flat":
self.rectangularWall(x, y, "eeee")
self.rectangularWall(x, y, "EEEE", move="left")
elif self.lid == "chest":
self.side()
self.side(move="left up")
self.top()
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right")
if self.drawLid(x, y, self.top_edge, [d2, d3]):
self.rectangularWall(x, y, "ffff", move="left only")
self.drawAddOnLid(x, y, self.lid)
self.close()