Add command line parameter using argparse
Remove params from __init__() Added new function .open() that needs to be called from .render()
This commit is contained in:
parent
333c786a11
commit
40d011db6a
2
TODO.txt
2
TODO.txt
|
@ -6,3 +6,5 @@
|
|||
* finish lamp
|
||||
* Make settings nicer
|
||||
* offer a collection of different settings
|
||||
* Make bolts configurable (e.g. box2.py)
|
||||
* Make flextest.py pattern configurable
|
||||
|
|
16
box.py
16
box.py
|
@ -17,13 +17,17 @@
|
|||
from boxes import *
|
||||
|
||||
class Box(Boxes):
|
||||
def __init__(self, x, y, h, **kw):
|
||||
self.x, self.y, self.h = x, y, h
|
||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
|
||||
def render(self):
|
||||
x, y, h = self.x, self.y, self.h
|
||||
t = self.thickness
|
||||
self.open(width=x+y+40, height=y+2*h+50)
|
||||
|
||||
b.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
|
||||
d2 = [Bolts(2)]
|
||||
d3 = [Bolts(3)]
|
||||
|
@ -41,7 +45,7 @@ class Box(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
b = Box(140, 202, 50, thickness=4.0)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
if __name__ == '__main__':
|
||||
b = Box()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
15
box2.py
15
box2.py
|
@ -18,13 +18,16 @@ from boxes import *
|
|||
import inspect
|
||||
|
||||
class Box(Boxes):
|
||||
def __init__(self, x, y, h, **kw):
|
||||
self.x, self.y, self.h = x, y, h
|
||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
|
||||
def render(self):
|
||||
x, y, h = self.x, self.y, self.h
|
||||
t = self.thickness
|
||||
self.open(width=x+y+40, height=y+2*h+50)
|
||||
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
|
||||
d2 = [Bolts(2)]
|
||||
d3 = [Bolts(3)]
|
||||
|
@ -41,7 +44,7 @@ class Box(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
b = Box(200, 200, 200, thickness=4.0)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
if __name__ == '__main__':
|
||||
b = Box()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
18
box3.py
18
box3.py
|
@ -17,14 +17,19 @@
|
|||
from boxes import *
|
||||
|
||||
class Box(Boxes):
|
||||
def __init__(self, x, y, h, **kw):
|
||||
self.x, self.y, self.h = x, y, h
|
||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
|
||||
def render(self):
|
||||
x, y, h = self.x, self.y, self.h
|
||||
t = self.thickness
|
||||
|
||||
self.open(width=x+y+10*t, height=y+h+10*t)
|
||||
|
||||
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
|
||||
d2 = [Bolts(2)]
|
||||
d3 = [Bolts(3)]
|
||||
|
||||
|
@ -41,8 +46,7 @@ class Box(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
t = 6.0
|
||||
b = Box(380-2*t, 370-2*t, 120-t, thickness=t)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
if __name__ == '__main__':
|
||||
b = Box()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
102
boxes.py
102
boxes.py
|
@ -16,6 +16,8 @@
|
|||
|
||||
import cairo
|
||||
import math
|
||||
import argparse
|
||||
import re
|
||||
from functools import wraps
|
||||
|
||||
def dist(dx, dy):
|
||||
|
@ -494,21 +496,88 @@ class NutHole:
|
|||
self.boxes.edge(side)
|
||||
self.boxes.corner(-60)
|
||||
|
||||
def argparseSections(s):
|
||||
m = re.match(r"(\d+(\.\d+)?)/(\d+)", s)
|
||||
if m:
|
||||
n = int(m.group(3))
|
||||
print([ float(m.group(1)) ] * n)
|
||||
return [ float(m.group(1))/n ] * n
|
||||
m = re.match(r"(\d+(\.\d+)?)\*(\d+)", s)
|
||||
if m:
|
||||
n = int(m.group(3))
|
||||
return [ float(m.group(1)) ] * n
|
||||
try:
|
||||
return [float(part) for part in s.split(":")]
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("Don't understand sections string")
|
||||
|
||||
class Boxes:
|
||||
|
||||
def __init__(self, width=300, height=200, thickness=3.0, burn=0.05):
|
||||
self.thickness = thickness
|
||||
self.burn = burn
|
||||
def __init__(self):
|
||||
self.argparser = argparse.ArgumentParser()
|
||||
self.argparser.add_argument(
|
||||
"--thickness", action="store", type=float, default=4.0,
|
||||
help="thickness of the material")
|
||||
self.argparser.add_argument(
|
||||
"--output", action="store", type=str, default="box.svg",
|
||||
help="name of resulting file")
|
||||
self.argparser.add_argument(
|
||||
"--debug", action="store_true", default=False,
|
||||
help="print surrounding boxes for some structures")
|
||||
self.argparser.add_argument(
|
||||
"--burn", action="store", type=float, default=0.05,
|
||||
help="burn correction in mm")
|
||||
|
||||
def open(self, width, height):
|
||||
self.spacing = 2*self.burn + 0.5 * self.thickness
|
||||
|
||||
self.fingerHoleEdgeWidth = 1.0 # multitudes of self.thickness
|
||||
self.bedBoltSettings = (3, 5.5, 2, 20, 15) #d, d_nut, h_nut, l, l1
|
||||
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
|
||||
self.output = "box.svg"
|
||||
self.debug = 0
|
||||
self._init_surface(width, height)
|
||||
self._buildObjects()
|
||||
|
||||
def buildArgParser(self, *l):
|
||||
for arg in l:
|
||||
if arg == "x":
|
||||
self.argparser.add_argument(
|
||||
"--x", action="store", type=float, default=100.0,
|
||||
help="inner width in mm")
|
||||
elif arg == "y":
|
||||
self.argparser.add_argument(
|
||||
"--y", action="store", type=float, default=100.0,
|
||||
help="inner depth in mm")
|
||||
elif arg == "sx":
|
||||
self.argparser.add_argument(
|
||||
"--sx", action="store", type=argparseSections,
|
||||
default="50*3",
|
||||
help="""Sections left to right in mm
|
||||
Possible formats:
|
||||
* overallwidth/numberof sections e.g. "250/5"
|
||||
* sectionwith*numberofsections e.g. "50*5"
|
||||
* section widths separated by : e.g. "30:25.5:70"
|
||||
""")
|
||||
elif arg == "sy":
|
||||
self.argparser.add_argument(
|
||||
"--sy", action="store", type=argparseSections,
|
||||
default="50*3",
|
||||
help="""Sections back to front in mm
|
||||
|
||||
See --sy for format""")
|
||||
elif arg == "h":
|
||||
self.argparser.add_argument(
|
||||
"--h", action="store", type=float, default=100.0,
|
||||
help="inner height in mm")
|
||||
elif arg == "hi":
|
||||
self.argparser.add_argument(
|
||||
"--hi", action="store", type=float, default=None,
|
||||
help="inner height of inner walls in mm")
|
||||
else:
|
||||
raise ValueError("No default for argument", arg)
|
||||
|
||||
def parseArgs(self):
|
||||
self.argparser.parse_args(namespace=self)
|
||||
|
||||
def addPart(self, part, name=None):
|
||||
if name is None:
|
||||
name = part.__class__.__name__
|
||||
|
@ -1111,17 +1180,25 @@ class Boxes:
|
|||
### main
|
||||
##################################################
|
||||
|
||||
def render(self, x, y, h):
|
||||
class DemoBox(Boxes):
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
|
||||
def render(self):
|
||||
x, y, h, t = self.x, self.y, self.h, self.thickness
|
||||
self.open(2*x+10*self.thickness, y+2*h+20*self.thickness)
|
||||
self.ctx.save()
|
||||
|
||||
self.moveTo(10, 10)
|
||||
self.roundedPlate(x, y, 0)
|
||||
self.moveTo(x+40, 0)
|
||||
self.moveTo(t, t)
|
||||
self.rectangularWall(x, y, "ffff")
|
||||
self.moveTo(x+4*t, 0)
|
||||
self.rectangularWall(x, y, "FFFF")
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
self.moveTo(10, y+20)
|
||||
self.moveTo(t, y+4*t)
|
||||
for i in range(2):
|
||||
for l in (x, y):
|
||||
self.rectangularWall(l, h, "hffF")
|
||||
|
@ -1132,5 +1209,6 @@ class Boxes:
|
|||
self.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
b = Boxes(900, 700)
|
||||
b.render(100, 161.8, 120)
|
||||
b = DemoBox()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
|
@ -19,7 +19,10 @@ from boxes import *
|
|||
class Castle(Boxes):
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self, 800, 600)
|
||||
Boxes.__init__(self)
|
||||
|
||||
def render(self, t_x=70, t_h=250, w1_x=300, w1_h=120, w2_x=100, w2_h=120):
|
||||
self.open(800, 600)
|
||||
s = FingerJointSettings(self.thickness, relative=False,
|
||||
space = 10, finger=10, height=10,
|
||||
width=self.thickness)
|
||||
|
@ -30,7 +33,6 @@ class Castle(Boxes):
|
|||
P.char = "P"
|
||||
self.addPart(P)
|
||||
|
||||
def render(self, t_x=70, t_h=250, w1_x=300, w1_h=120, w2_x=100, w2_h=120):
|
||||
self.moveTo(0,0)
|
||||
self.rectangularWall(t_x, t_h, edges="efPf", move="right", callback=
|
||||
[lambda: self.fingerHolesAt(t_x*0.5, 0, w1_h, 90),])
|
||||
|
@ -44,5 +46,7 @@ class Castle(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
c = Castle()
|
||||
c.parseArgs()
|
||||
c.render()
|
||||
|
|
15
drillbox.py
15
drillbox.py
|
@ -17,10 +17,9 @@
|
|||
from boxes import *
|
||||
|
||||
class Box(Boxes):
|
||||
def __init__(self, x, y, h, **kw):
|
||||
def __init__(self, x, y, h):
|
||||
Boxes.__init__(self)
|
||||
self.x, self.y, self.h = x, y, h
|
||||
Boxes.__init__(self, width=x+y+40, height=3*y+2*h+50, **kw)
|
||||
|
||||
|
||||
def holesx(self):
|
||||
self.fingerHolesAt(0, 5, self.x, angle=0)
|
||||
|
@ -52,6 +51,10 @@ class Box(Boxes):
|
|||
x, y, h = self.x, self.y, self.h
|
||||
t = self.thickness
|
||||
|
||||
self.open(width=x+y+40, height=3*y+2*h+16*t)
|
||||
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
|
||||
self.moveTo(t, t)
|
||||
self.rectangularWall(x, h, "FfeF", callback=[self.holesx],move="right")
|
||||
self.rectangularWall(y, h, "FfeF", callback=[self.holesy], move="up")
|
||||
|
@ -68,7 +71,7 @@ class Box(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
b = Box(120, 240, 60, thickness=4.0)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
||||
surroundingspaces=1)
|
||||
if __name__ == '__main__':
|
||||
b = Box(120, 240, 60)
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
50
flexbox.py
50
flexbox.py
|
@ -18,17 +18,12 @@ import boxes
|
|||
import math
|
||||
|
||||
class FlexBox(boxes.Boxes):
|
||||
def __init__(self, x, y, z, r=None, thickness=3.0):
|
||||
c4 = math.pi * r * 0.5
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.r = r or min(x, y)/2.0
|
||||
self.latchsize = 8*thickness
|
||||
|
||||
width = 2*x + 2*y - 8*r + 4*c4 + 4*thickness
|
||||
height = y + z + 4*thickness
|
||||
boxes.Boxes.__init__(self, width, height, thickness=thickness)
|
||||
def __init__(self):
|
||||
boxes.Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
self.argparser.add_argument(
|
||||
"--radius", action="store", type=float, default=15,
|
||||
help="Radius of the latch in mm")
|
||||
|
||||
@boxes.restore
|
||||
def flexBoxSide(self, x, y, r, callback=None):
|
||||
|
@ -47,20 +42,20 @@ class FlexBox(boxes.Boxes):
|
|||
self.corner(90, r)
|
||||
|
||||
def surroundingWall(self):
|
||||
x, y, z, r = self.x, self.y, self.z, self.r
|
||||
x, y, h, r = self.x, self.y, self.h, self.radius
|
||||
|
||||
c4 = math.pi * r * 0.5
|
||||
|
||||
self.edges["F"](y-2*r-self.latchsize, False)
|
||||
self.flexEdge(c4, z+2*self.thickness)
|
||||
self.flexEdge(c4, h+2*self.thickness)
|
||||
self.edges["F"](x-2*r, False)
|
||||
self.flexEdge(c4, z+2*self.thickness)
|
||||
self.flexEdge(c4, h+2*self.thickness)
|
||||
self.edges["F"](y-2*r, False)
|
||||
self.flexEdge(c4, z+2*self.thickness)
|
||||
self.flexEdge(c4, h+2*self.thickness)
|
||||
self.edge(x-2*r)
|
||||
self.flexEdge(c4, z+2*self.thickness)
|
||||
self.flexEdge(c4, h+2*self.thickness)
|
||||
self.latch(self.latchsize, False)
|
||||
self.edge(z+2*self.thickness)
|
||||
self.edge(h+2*self.thickness)
|
||||
self.latch(self.latchsize, False, True)
|
||||
self.edge(c4)
|
||||
self.edge(x-2*r)
|
||||
|
@ -71,20 +66,31 @@ class FlexBox(boxes.Boxes):
|
|||
self.edge(c4)
|
||||
self.edges["F"](y-2*r-self.latchsize, False)
|
||||
self.corner(90)
|
||||
self.edge(z+2*self.thickness)
|
||||
self.edge(h+2*self.thickness)
|
||||
self.corner(90)
|
||||
|
||||
def render(self):
|
||||
x, y, h = self.x, self.y, self.h
|
||||
r = self.radius or min(x, y)/2.0
|
||||
self.latchsize = 8 * self.thickness
|
||||
c4 = math.pi * r * 0.5
|
||||
|
||||
width = 2*x + 2*y - 8*r + 4*c4 + 4*self.thickness
|
||||
height = y + h + 8*self.thickness
|
||||
|
||||
self.open(width, height)
|
||||
|
||||
self.moveTo(self.thickness, self.thickness)
|
||||
self.surroundingWall()
|
||||
self.moveTo(self.thickness, self.z+4*self.thickness)
|
||||
self.flexBoxSide(self.x, self.y, self.r)
|
||||
self.moveTo(self.thickness, self.h+5*self.thickness)
|
||||
self.flexBoxSide(self.x, self.y, self.radius)
|
||||
self.moveTo(2*self.x+3*self.thickness, 0)
|
||||
self.ctx.scale(-1, 1)
|
||||
self.flexBoxSide(self.x, self.y, self.r)
|
||||
self.flexBoxSide(self.x, self.y, self.radius)
|
||||
|
||||
self.close()
|
||||
|
||||
if __name__=="__main__":
|
||||
b = FlexBox(50, 70, 50, r=15)
|
||||
b = FlexBox()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
57
flexbox2.py
57
flexbox2.py
|
@ -18,19 +18,12 @@ from boxes import *
|
|||
import math
|
||||
|
||||
class FlexBox(Boxes):
|
||||
def __init__(self, x, y, z, r=None, thickness=3.0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.r = r or min(x, y)/2.0
|
||||
self.c4 = c4 = math.pi * r * 0.5
|
||||
self.latchsize = 8*thickness
|
||||
|
||||
width = 2*x + y - 3*r + 2*c4 + 7*thickness + self.latchsize # lock
|
||||
height = y + z + 8*thickness
|
||||
|
||||
Boxes.__init__(self, width, height, thickness=thickness)
|
||||
self.fingerJointSettings = (4, 4)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
self.argparser.add_argument(
|
||||
"--radius", action="store", type=float, default=15,
|
||||
help="Radius of the corners in mm")
|
||||
|
||||
@restore
|
||||
def flexBoxSide(self, x, y, r, callback=None):
|
||||
|
@ -50,17 +43,17 @@ class FlexBox(Boxes):
|
|||
self.corner(90)
|
||||
|
||||
def surroundingWall(self):
|
||||
x, y, z, r = self.x, self.y, self.z, self.r
|
||||
x, y, h, r = self.x, self.y, self.h, self.radius
|
||||
|
||||
self.edges["F"](y-r, False)
|
||||
if (x-2*r < 0.1):
|
||||
self.flexEdge(2*self.c4, z+2*self.thickness)
|
||||
self.flexEdge(2*self.c4, h+2*self.thickness)
|
||||
else:
|
||||
self.flexEdge(self.c4, z+2*self.thickness)
|
||||
self.flexEdge(self.c4, h+2*self.thickness)
|
||||
self.edge(x-2*r)
|
||||
self.flexEdge(self.c4, z+2*self.thickness)
|
||||
self.flexEdge(self.c4, h+2*self.thickness)
|
||||
self.latch(self.latchsize, False)
|
||||
self.edge(z+2*self.thickness)
|
||||
self.edge(h+2*self.thickness)
|
||||
self.latch(self.latchsize, False, True)
|
||||
self.edge(self.c4)
|
||||
self.edge(x-2*r)
|
||||
|
@ -68,28 +61,40 @@ class FlexBox(Boxes):
|
|||
self.edges["F"](y-r)
|
||||
self.corner(90)
|
||||
self.edge(self.thickness)
|
||||
self.edges["f"](z)
|
||||
self.edges["f"](h)
|
||||
self.edge(self.thickness)
|
||||
self.corner(90)
|
||||
|
||||
def render(self):
|
||||
self.radius = self.radius or min(x, y)/2.0
|
||||
self.c4 = c4 = math.pi * self.radius * 0.5
|
||||
self.latchsize = 8*self.thickness
|
||||
|
||||
width = 2*self.x + self.y - 3*self.radius + 2*c4 + 7*self.thickness + self.latchsize # lock
|
||||
height = self.y + self.h + 8*self.thickness
|
||||
|
||||
self.open(width, height)
|
||||
|
||||
self.fingerJointSettings = (4, 4)
|
||||
|
||||
self.moveTo(2*self.thickness, self.thickness)
|
||||
self.ctx.save()
|
||||
self.surroundingWall()
|
||||
self.moveTo(self.x+self.y-3*self.r+2*self.c4+self.latchsize+1*self.thickness, 0)
|
||||
self.rectangularWall(self.x, self.z, edges="FFFF")
|
||||
self.moveTo(self.x+self.y-3*self.radius+2*self.c4+self.latchsize+1*self.thickness, 0)
|
||||
self.rectangularWall(self.x, self.h, edges="FFFF")
|
||||
self.ctx.restore()
|
||||
self.moveTo(0, self.z+4*self.thickness)
|
||||
self.flexBoxSide(self.x, self.y, self.r)
|
||||
self.moveTo(0, self.h+4*self.thickness)
|
||||
self.flexBoxSide(self.x, self.y, self.radius)
|
||||
self.moveTo(2*self.x+3*self.thickness, 0)
|
||||
self.ctx.scale(-1, 1)
|
||||
self.flexBoxSide(self.x, self.y, self.r)
|
||||
self.flexBoxSide(self.x, self.y, self.radius)
|
||||
self.ctx.scale(-1, 1)
|
||||
self.moveTo(2*self.thickness, 0)
|
||||
self.rectangularWall(self.z, self.y-self.r-self.latchsize, edges="fFeF")
|
||||
self.rectangularWall(self.h, self.y-self.radius-self.latchsize, edges="fFeF")
|
||||
self.close()
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
b = FlexBox(70, 100, 70, r=30, thickness=3.0)
|
||||
b = FlexBox()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
69
flexbox3.py
69
flexbox3.py
|
@ -18,30 +18,21 @@ from boxes import *
|
|||
import math
|
||||
|
||||
class FlexBox(Boxes):
|
||||
def __init__(self, x, y, z, r=None, d=1.0, h=5.0, thickness=3.0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.r = r or min(x, y)/2.0
|
||||
self.d = d
|
||||
self.h = h
|
||||
self.c4 = c4 = math.pi * r * 0.5 * 0.95
|
||||
self.latchsize = 8*thickness
|
||||
|
||||
width = 2*x + y - 3*r + 2*c4 + 15*thickness + 3*10 # lock
|
||||
height = y + z + 8*thickness
|
||||
|
||||
Boxes.__init__(self, width, height, thickness=thickness)
|
||||
self.edges["f"].settings.setValues(
|
||||
self.thickness, finger=2, space=2, surroundingspaces=1)
|
||||
|
||||
s = FingerJointSettings(self.thickness, surroundingspaces=1)
|
||||
g = FingerJointEdge(self, s)
|
||||
g.char = "g"
|
||||
self.addPart(g)
|
||||
G = FingerJointEdgeCounterPart(self, s)
|
||||
G.char = "G"
|
||||
self.addPart(G)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y")
|
||||
self.argparser.add_argument(
|
||||
"--z", action="store", type=float, default=100.0,
|
||||
help="height of the box")
|
||||
self.argparser.add_argument(
|
||||
"--h", action="store", type=float, default=10.0,
|
||||
help="height of the lid")
|
||||
self.argparser.add_argument(
|
||||
"--radius", action="store", type=float, default=10.0,
|
||||
help="radius of the lids living hinge")
|
||||
self.argparser.add_argument(
|
||||
"--c", action="store", type=float, default=1.0,
|
||||
dest="d", help="clearance of the lid")
|
||||
|
||||
def rectangleCorner(self, edge1=None, edge2=None):
|
||||
edge1 = self.edges.get(edge1, edge1)
|
||||
|
@ -68,7 +59,7 @@ class FlexBox(Boxes):
|
|||
self.corner(90)
|
||||
|
||||
def surroundingWall(self):
|
||||
x, y, z, r, d = self.x, self.y, self.z, self.r, self.d
|
||||
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
|
||||
|
||||
self.edges["F"](y-r, False)
|
||||
self.flexEdge(self.c4, z+2*self.thickness)
|
||||
|
@ -93,7 +84,7 @@ class FlexBox(Boxes):
|
|||
|
||||
@restore
|
||||
def lidSide(self):
|
||||
x, y, z, r, d, h = self.x, self.y, self.z, self.r, self.d, self.h
|
||||
x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h
|
||||
t = self.thickness
|
||||
r2 = r+t if r+t <=h+t else h+t
|
||||
self.moveTo(self.thickness, self.thickness)
|
||||
|
@ -107,7 +98,28 @@ class FlexBox(Boxes):
|
|||
self.edge(x+2*t)
|
||||
|
||||
def render(self):
|
||||
x, y, z, r, d, h = self.x, self.y, self.z, self.r, self.d, self.h
|
||||
x, y, z, d, h = self.x, self.y, self.z, self.d, self.h
|
||||
r = self.radius = self.radius or min(x, y)/2.0
|
||||
thickness = self.thickness
|
||||
|
||||
self.c4 = c4 = math.pi * r * 0.5 * 0.95
|
||||
self.latchsize = 8*thickness
|
||||
|
||||
width = 2*x + y - 2*r + c4 + 14*thickness + 3*h # lock
|
||||
height = y + z + 8*thickness
|
||||
|
||||
self.open(width, height)
|
||||
|
||||
self.edges["f"].settings.setValues(
|
||||
self.thickness, finger=2, space=2, surroundingspaces=1)
|
||||
|
||||
s = FingerJointSettings(self.thickness, surroundingspaces=1)
|
||||
g = FingerJointEdge(self, s)
|
||||
g.char = "g"
|
||||
self.addPart(g)
|
||||
G = FingerJointEdgeCounterPart(self, s)
|
||||
G.char = "G"
|
||||
self.addPart(G)
|
||||
|
||||
self.moveTo(2*self.thickness, self.thickness+2*d)
|
||||
self.ctx.save()
|
||||
|
@ -134,5 +146,6 @@ class FlexBox(Boxes):
|
|||
self.close()
|
||||
|
||||
if __name__=="__main__":
|
||||
b = FlexBox(100, 40, 100, r=20, h=10, thickness=4.0)
|
||||
b = FlexBox() #100, 40, 100, r=20, h=10, thickness=4.0)
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
20
flextest.py
20
flextest.py
|
@ -17,9 +17,17 @@
|
|||
from boxes import *
|
||||
|
||||
class FlexTest(Boxes):
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y")
|
||||
|
||||
def render(self):
|
||||
x, y = self.x, self.y
|
||||
self.open(x+60, y+20)
|
||||
|
||||
# (1.5, 3.0, 15.0) # line distance, connects, width
|
||||
self.flexSettings = (2, 4.0, 16.0)
|
||||
|
||||
def render(self, x, y):
|
||||
self.moveTo(5, 5)
|
||||
self.edge(10)
|
||||
self.flexEdge(x, y)
|
||||
|
@ -34,10 +42,8 @@ class FlexTest(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
x = 40
|
||||
y = 100
|
||||
f = FlexTest(x+30, y+10, thickness=5.0, burn=0.05)
|
||||
# (1.5, 3.0, 15.0) # line distance, connects, width
|
||||
f.flexSettings = (2, 4.0, 16.0)
|
||||
f.render(x, y)
|
||||
if __name__ == '__main__':
|
||||
f = FlexTest()
|
||||
f.parseArgs()
|
||||
f.render()
|
||||
|
||||
|
|
18
folder.py
18
folder.py
|
@ -19,16 +19,18 @@ import math
|
|||
|
||||
class Folder(Boxes):
|
||||
|
||||
def __init__(self, x, y, h, r=0):
|
||||
Boxes.__init__(self, width=2*x+3*h+20, height=y+20)
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.h = h
|
||||
self.r = r
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h")
|
||||
self.argparser.add_argument(
|
||||
"-r", action="store", type=float, default=10.0,
|
||||
help="radius of the corners")
|
||||
self.argparser.set_defaults(h=20)
|
||||
|
||||
def render(self):
|
||||
x, y, r, h = self.x, self.y, self.r, self.h
|
||||
c2 = math.pi * h
|
||||
self.open(width=2*x+3*h+20, height=y+20)
|
||||
self.moveTo(r+self.thickness, self.thickness)
|
||||
self.edge(x-r)
|
||||
self.flexEdge(c2, y)
|
||||
|
@ -43,5 +45,7 @@ class Folder(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
f = Folder(240, 350, 20, 15)
|
||||
if __name__ == '__main__':
|
||||
f = Folder()
|
||||
f.parseArgs()
|
||||
f.render()
|
||||
|
|
21
lamp.py
21
lamp.py
|
@ -57,13 +57,7 @@ class RoundedTriangle(Edge):
|
|||
|
||||
class Lamp(Boxes):
|
||||
def __init__(self):
|
||||
Boxes.__init__(self, width=1000, height=1000,
|
||||
thickness=5.0, burn=0.05)
|
||||
self.fingerJointSettings = (5, 5) # XXX
|
||||
|
||||
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
|
||||
self.addPart(RoundedTriangle(self, s))
|
||||
|
||||
Boxes.__init__(self)
|
||||
|
||||
def side(self, y, h):
|
||||
return
|
||||
|
@ -82,6 +76,16 @@ class Lamp(Boxes):
|
|||
y : width box
|
||||
h : height box
|
||||
"""
|
||||
|
||||
self.open(width=1000, height=1000)
|
||||
|
||||
self.fingerJointSettings = (5, 5) # XXX
|
||||
|
||||
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
|
||||
self.addPart(RoundedTriangle(self, s))
|
||||
|
||||
self.flexSettings = (3, 5.0, 20.0)
|
||||
|
||||
self.fingerJointEdge.settings.setValues(self.thickness, finger=5, space=5, relative=False)
|
||||
d = 2*(r+w)
|
||||
|
||||
|
@ -112,6 +116,7 @@ class Lamp(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
l = Lamp()
|
||||
l.flexSettings = (3, 5.0, 20.0)
|
||||
l.parseArgs()
|
||||
l.render(r=4*25.4, w=20, x=270, y=150, h=100)
|
||||
|
|
|
@ -17,19 +17,18 @@
|
|||
from boxes import *
|
||||
|
||||
class Box(Boxes):
|
||||
def __init__(self, x, y, h, h2, thickness=4.0):
|
||||
self.x, self.y, self.h, self.h2 = x, y, h, h2
|
||||
Boxes.__init__(self, width=x+y+8*thickness, height=x+h+h2+4*thickness,
|
||||
thickness=thickness)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h", "hi")
|
||||
|
||||
def side(self, w, h, h2):
|
||||
r = min(h-h2, w) / 2.0
|
||||
if (h-h2) > w:
|
||||
def side(self, w, h, hi):
|
||||
r = min(h-hi, w) / 2.0
|
||||
if (h-hi) > w:
|
||||
r = w / 2.0
|
||||
lx = 0
|
||||
ly = (h-h2) - w
|
||||
ly = (h-hi) - w
|
||||
else:
|
||||
r = (h - h2) / 2.0
|
||||
r = (h - hi) / 2.0
|
||||
lx = (w - 2*r) / 2.0
|
||||
ly = 0
|
||||
|
||||
|
@ -40,7 +39,7 @@ class Box(Boxes):
|
|||
self.edge(e_w)
|
||||
self.corner(90)
|
||||
self.edge(e_w)
|
||||
self.edges["F"](h2)
|
||||
self.edges["F"](hi)
|
||||
self.corner(90)
|
||||
self.edge(e_w)
|
||||
self.edge(lx)
|
||||
|
@ -56,23 +55,29 @@ class Box(Boxes):
|
|||
|
||||
|
||||
def render(self):
|
||||
x, y, h, h2 = self.x, self.y, self.h, self.h2
|
||||
x, y, h, = self.x, self.y, self.h
|
||||
self.hi = hi = self.hi or (h / 2.0)
|
||||
t = self.thickness
|
||||
|
||||
self.open(width=x+y+8*t, height=x+h+hi+4*t)
|
||||
|
||||
self.edges["f"].settings.setValues(self.thickness, space=2, finger=2)
|
||||
|
||||
self.ctx.save()
|
||||
self.rectangularWall(x, h, "Ffef", move="up")
|
||||
self.rectangularWall(x, h2, "Ffef", move="up")
|
||||
self.rectangularWall(x, hi, "Ffef", move="up")
|
||||
|
||||
self.rectangularWall(y, x, "ffff")
|
||||
self.ctx.restore()
|
||||
|
||||
self.rectangularWall(x, h, "Ffef", move="right only")
|
||||
self.side(y, h, h2)
|
||||
self.moveTo(y+15, h+h2+15, 180)
|
||||
self.side(y, h, h2)
|
||||
self.side(y, h, hi)
|
||||
self.moveTo(y+15, h+hi+15, 180)
|
||||
self.side(y, h, hi)
|
||||
|
||||
self.close()
|
||||
|
||||
b = Box(80, 235, 300, 150)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=2, finger=2)
|
||||
if __name__ == '__main__':
|
||||
b = Box()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
|
@ -20,8 +20,7 @@ class Printer(Boxes):
|
|||
|
||||
"""Work in progress"""
|
||||
def __init__(self, r=250, h=400, d_c=100):
|
||||
Boxes.__init__(self, 650, 600, thickness=5.0, burn=0.05)
|
||||
self.edges["f"].settings.setValues(self.thickness, surroundingspaces=0)
|
||||
Boxes.__init__(self)
|
||||
self.r = r
|
||||
self.h = h
|
||||
self.d_c = d_c
|
||||
|
@ -122,6 +121,8 @@ class Printer(Boxes):
|
|||
self.move(overallwidth, overallheight, move)
|
||||
|
||||
def render(self):
|
||||
self.open(650, 600)
|
||||
self.edges["f"].settings.setValues(self.thickness, surroundingspaces=0)
|
||||
self.ctx.save()
|
||||
for i in range(3):
|
||||
# motor mounts
|
||||
|
@ -175,4 +176,5 @@ class Printer(Boxes):
|
|||
self.close()
|
||||
|
||||
p = Printer()
|
||||
p.parseArgs()
|
||||
p.render()
|
||||
|
|
|
@ -66,6 +66,7 @@ class Silverware(Boxes):
|
|||
##################################################
|
||||
|
||||
def render(self, x, y, h, r):
|
||||
self.open(750, 450)
|
||||
t = self.thickness
|
||||
b = self.burn
|
||||
|
||||
|
@ -81,8 +82,7 @@ class Silverware(Boxes):
|
|||
|
||||
self.close()
|
||||
|
||||
b = Silverware(750, 350, thickness=5.0, burn=0.05)
|
||||
if __name__ == '__main__':
|
||||
b = Silverware()
|
||||
b.parseArgs()
|
||||
b.render(250, 250/1.618, 120, 30)
|
||||
#b = Silverware(300, 300, thickness=3.0, burn=0.05)
|
||||
#b.fingerJointSettings = (b.thickness, b.thickness)
|
||||
#b.render(60, 60/1.618, 40, 10)
|
||||
|
|
|
@ -17,48 +17,33 @@
|
|||
from boxes import *
|
||||
|
||||
class TrayInsert(Boxes):
|
||||
def __init__(self, x, y, h, **kw):
|
||||
self.x, self.y, self.h = x, y, h
|
||||
t = kw.get("thickness", 4.0)
|
||||
Boxes.__init__(self, width=max(sum(x)+len(x)*t, sum(y)+len(y)*t)+2*t,
|
||||
height=(len(x)+len(y)-2)*(h+t)+2*t, **kw)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("sx", "sy", "h")
|
||||
|
||||
def render(self):
|
||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
||||
y = sum(self.y) + self.thickness * (len(self.y)-1)
|
||||
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||
y = sum(self.sy) + self.thickness * (len(self.sy)-1)
|
||||
h = self.h
|
||||
t = self.thickness
|
||||
|
||||
self.open(width=max(x, y) + 4*t,
|
||||
height=(len(self.sx)+len(self.sy)-2)*(h+t)+2*t)
|
||||
self.moveTo(t, t)
|
||||
|
||||
# Inner walls
|
||||
for i in range(len(self.x)-1):
|
||||
e = [SlottedEdge(self, self.y, slots=0.5*h), "e", "e", "e"]
|
||||
for i in range(len(self.sx)-1):
|
||||
e = [SlottedEdge(self, self.sy, slots=0.5*h), "e", "e", "e"]
|
||||
self.rectangularWall(y, h, e,
|
||||
move="up")
|
||||
for i in range(len(self.y)-1):
|
||||
for i in range(len(self.sy)-1):
|
||||
e = ["e", "e",
|
||||
SlottedEdge(self, self.x[::-1], "e", slots=0.5*h), "e"]
|
||||
SlottedEdge(self, self.sx[::-1], "e", slots=0.5*h), "e"]
|
||||
self.rectangularWall(x, h, e,
|
||||
move="up")
|
||||
self.close()
|
||||
|
||||
|
||||
# Calculate equidistant section
|
||||
x = 260 # width
|
||||
nx = 3
|
||||
y = 300 # depth
|
||||
ny = 4
|
||||
thickness=4.0
|
||||
dx = (x+thickness)/nx-thickness
|
||||
dy = (y+thickness)/ny-thickness
|
||||
|
||||
sx = [dx] * nx
|
||||
sy = [dy] * ny
|
||||
|
||||
# Or give sections by hand
|
||||
#sx = [80, 100, 80]
|
||||
#sy = [80, 120, 200]
|
||||
|
||||
b = TrayInsert(sx, sy, 80, thickness=thickness, burn=0.1)
|
||||
if __name__ == '__main__':
|
||||
b = TrayInsert()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
59
typetray.py
59
typetray.py
|
@ -17,45 +17,44 @@
|
|||
from boxes import *
|
||||
|
||||
class TypeTray(Boxes):
|
||||
def __init__(self, x, y, h, hi=None, **kw):
|
||||
self.x, self.y, self.h = x, y, h
|
||||
self.hi = hi or h
|
||||
Boxes.__init__(self, width=sum(x)+sum(y)+70, height=sum(y)+1*h+50, **kw)
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("sx", "sy", "h", "hi")
|
||||
|
||||
def xSlots(self):
|
||||
posx = -0.5 * self.thickness
|
||||
for x in self.x[:-1]:
|
||||
for x in self.sx[:-1]:
|
||||
posx += x + self.thickness
|
||||
posy = 0
|
||||
for y in self.y:
|
||||
for y in self.sy:
|
||||
self.fingerHolesAt(posx, posy, y)
|
||||
posy += y + self.thickness
|
||||
|
||||
def ySlots(self):
|
||||
posy = -0.5 * self.thickness
|
||||
for y in self.y[:-1]:
|
||||
for y in self.sy[:-1]:
|
||||
posy += y + self.thickness
|
||||
posx = 0
|
||||
for x in self.x:
|
||||
for x in self.sx:
|
||||
self.fingerHolesAt(posy, posx, x)
|
||||
posx += x + self.thickness
|
||||
|
||||
def xHoles(self):
|
||||
posx = -0.5 * self.thickness
|
||||
for x in self.x[:-1]:
|
||||
for x in self.sx[:-1]:
|
||||
posx += x + self.thickness
|
||||
self.fingerHolesAt(posx, 0, self.hi)
|
||||
|
||||
def yHoles(self):
|
||||
posy = -0.5 * self.thickness
|
||||
for y in self.y[:-1]:
|
||||
for y in self.sy[:-1]:
|
||||
posy += y + self.thickness
|
||||
self.fingerHolesAt(posy, 0, self.hi)
|
||||
|
||||
def fingerHole(self):
|
||||
dx = 50
|
||||
dy = 30
|
||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
||||
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||
self.moveTo(0.5*(x-dx), 5)
|
||||
self.edge(dx)
|
||||
self.corner(180, 0.5*dy)
|
||||
|
@ -65,12 +64,16 @@ class TypeTray(Boxes):
|
|||
#self.hole(0.5*x+30, 15, 10)
|
||||
|
||||
def render(self):
|
||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
||||
y = sum(self.y) + self.thickness * (len(self.y)-1)
|
||||
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||
y = sum(self.sy) + self.thickness * (len(self.sy)-1)
|
||||
h = self.h
|
||||
hi = self.hi
|
||||
hi = self.hi = self.hi or h
|
||||
t = self.thickness
|
||||
|
||||
self.open(width=x+y+10*t, height=y+(len(self.sx)+len(self.sy))*h+50)
|
||||
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||
surroundingspaces=0.5)
|
||||
|
||||
self.moveTo(t, t)
|
||||
# outer walls
|
||||
self.rectangularWall(x, h, "Ffef", callback=[
|
||||
|
@ -87,30 +90,18 @@ class TypeTray(Boxes):
|
|||
callback=[self.xSlots, self.ySlots],
|
||||
move="right")
|
||||
# Inner walls
|
||||
for i in range(len(self.x)-1):
|
||||
e = [SlottedEdge(self, self.y, "f", slots=0.5*hi), "f", "e", "f"]
|
||||
for i in range(len(self.sx)-1):
|
||||
e = [SlottedEdge(self, self.sy, "f", slots=0.5*hi), "f", "e", "f"]
|
||||
self.rectangularWall(y, hi, e,
|
||||
move="up")
|
||||
for i in range(len(self.y)-1):
|
||||
e = [SlottedEdge(self, self.x, "f"), "f",
|
||||
SlottedEdge(self, self.x[::-1], "e", slots=0.5*hi), "f"]
|
||||
for i in range(len(self.sy)-1):
|
||||
e = [SlottedEdge(self, self.sx, "f"), "f",
|
||||
SlottedEdge(self, self.sx[::-1], "e", slots=0.5*hi), "f"]
|
||||
self.rectangularWall(x, hi, e,
|
||||
move="up")
|
||||
self.close()
|
||||
|
||||
x = 260 # outer width
|
||||
nx = 3
|
||||
y = 300 # outer depth
|
||||
ny = 4
|
||||
thickness=4.0
|
||||
|
||||
dx = (x-thickness)/nx-thickness
|
||||
dy = (y-thickness)/ny-thickness
|
||||
sx = [dx] * nx
|
||||
sy = [dy] * ny
|
||||
#sy = [120, 300-3*thickness-120]
|
||||
|
||||
b = TypeTray(sx, sy, 78-thickness, 40, thickness=thickness, burn=0.1)
|
||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
||||
surroundingspaces=0.5)
|
||||
if __name__ == '__main__':
|
||||
b = TypeTray()
|
||||
b.parseArgs()
|
||||
b.render()
|
||||
|
|
Loading…
Reference in New Issue