2016-07-11 23:01:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-03-16 18:26:12 +01:00
|
|
|
# Copyright (C) 2013-2014 Florian Festi
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-01 01:59:24 +02:00
|
|
|
|
|
|
|
from boxes import *
|
|
|
|
import math
|
|
|
|
|
2016-07-31 14:15:06 +02:00
|
|
|
class FlexBox3(Boxes):
|
2016-03-08 21:53:29 +01:00
|
|
|
"""Box with living hinge"""
|
2016-03-03 13:27:22 +01:00
|
|
|
def __init__(self):
|
|
|
|
Boxes.__init__(self)
|
2016-07-09 22:52:48 +02:00
|
|
|
self.buildArgParser("x", "y", "outside")
|
2016-03-03 13:27:22 +01:00
|
|
|
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")
|
2013-09-01 01:59:24 +02:00
|
|
|
|
|
|
|
def rectangleCorner(self, edge1=None, edge2=None):
|
|
|
|
edge1 = self.edges.get(edge1, edge1)
|
|
|
|
edge2 = self.edges.get(edge2, edge2)
|
|
|
|
if edge2:
|
2016-04-18 22:05:11 +02:00
|
|
|
self.edge(edge2.startwidth())
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
if edge1:
|
2016-04-18 22:05:11 +02:00
|
|
|
self.edge(edge1.endwidth())
|
2013-09-01 01:59:24 +02:00
|
|
|
|
|
|
|
@restore
|
|
|
|
def flexBoxSide(self, x, y, r, callback=None):
|
|
|
|
self.cc(callback, 0)
|
2016-04-02 20:29:09 +02:00
|
|
|
self.edges["f"](x)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90, 0)
|
|
|
|
self.cc(callback, 1)
|
2016-04-02 20:29:09 +02:00
|
|
|
self.edges["f"](y-r)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 2)
|
|
|
|
self.edge(x-r)
|
|
|
|
self.corner(90, 0)
|
|
|
|
self.cc(callback, 3)
|
2016-04-02 20:29:09 +02:00
|
|
|
self.edges["f"](y)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
|
|
|
|
def surroundingWall(self):
|
2016-03-03 13:27:22 +01:00
|
|
|
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
|
2013-09-01 01:59:24 +02:00
|
|
|
|
|
|
|
self.edges["F"](y-r, False)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["X"](self.c4, z+2*self.thickness)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(-90)
|
|
|
|
self.edge(d)
|
|
|
|
self.corner(90)
|
2013-09-15 19:20:34 +02:00
|
|
|
self.edges["f"](x-r+d)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edges["f"](z+2*self.thickness+2*d)
|
|
|
|
self.corner(90)
|
2013-09-15 19:20:34 +02:00
|
|
|
self.edges["f"](x-r+d)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edge(d)
|
|
|
|
self.corner(-90)
|
|
|
|
self.edge(self.c4)
|
|
|
|
self.edges["F"](y-r)
|
|
|
|
self.corner(90)
|
|
|
|
self.edge(self.thickness)
|
|
|
|
self.edges["f"](z)
|
|
|
|
self.edge(self.thickness)
|
|
|
|
self.corner(90)
|
|
|
|
|
|
|
|
@restore
|
|
|
|
def lidSide(self):
|
2016-03-03 13:27:22 +01:00
|
|
|
x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h
|
2013-09-01 01:59:24 +02:00
|
|
|
t = self.thickness
|
|
|
|
r2 = r+t if r+t <=h+t else h+t
|
|
|
|
self.moveTo(self.thickness, self.thickness)
|
|
|
|
self.edge(h+self.thickness-r2)
|
|
|
|
self.corner(90, r2)
|
|
|
|
self.edge(r-r2+2*t)
|
|
|
|
self.edges["F"](x-r)
|
|
|
|
self.rectangleCorner("F", "f")
|
2013-09-15 19:20:34 +02:00
|
|
|
self.edges["g"](h)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.rectangleCorner("f", "e")
|
|
|
|
self.edge(x+2*t)
|
|
|
|
|
|
|
|
def render(self):
|
2016-07-09 22:52:48 +02:00
|
|
|
if self.outside:
|
|
|
|
self.x = self.adjustSize(self.x)
|
|
|
|
self.y = self.adjustSize(self.y)
|
|
|
|
self.z = self.adjustSize(self.z)
|
|
|
|
|
2016-03-03 13:27:22 +01:00
|
|
|
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
|
|
|
|
|
2016-06-07 20:20:35 +02:00
|
|
|
self.open()
|
2016-03-03 13:27:22 +01:00
|
|
|
|
|
|
|
self.edges["f"].settings.setValues(
|
|
|
|
self.thickness, finger=2, space=2, surroundingspaces=1)
|
|
|
|
|
2016-03-25 14:02:52 +01:00
|
|
|
s = edges.FingerJointSettings(self.thickness, surroundingspaces=1)
|
|
|
|
g = edges.FingerJointEdge(self, s)
|
2016-03-03 13:27:22 +01:00
|
|
|
g.char = "g"
|
|
|
|
self.addPart(g)
|
2016-03-25 14:02:52 +01:00
|
|
|
G = edges.FingerJointEdgeCounterPart(self, s)
|
2016-03-03 13:27:22 +01:00
|
|
|
G.char = "G"
|
|
|
|
self.addPart(G)
|
2013-09-01 01:59:24 +02:00
|
|
|
|
|
|
|
self.moveTo(2*self.thickness, self.thickness+2*d)
|
|
|
|
self.ctx.save()
|
|
|
|
self.surroundingWall()
|
2016-07-27 22:19:32 +02:00
|
|
|
self.moveTo(x+y-2*r+self.c4+2*self.thickness, -2*d-self.thickness)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.rectangularWall(x, z, edges="FFFF", move="right")
|
|
|
|
self.rectangularWall(h, z+2*(d+self.thickness),
|
2013-09-15 19:20:34 +02:00
|
|
|
edges="GeGF", move="right")
|
2013-09-01 01:59:24 +02:00
|
|
|
self.lidSide()
|
|
|
|
self.moveTo(2*h+5*self.thickness, 0)
|
|
|
|
self.ctx.scale(-1, 1)
|
|
|
|
self.lidSide()
|
|
|
|
|
|
|
|
self.ctx.restore()
|
2013-09-15 19:20:34 +02:00
|
|
|
self.moveTo(0, z+4*self.thickness+2*d)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.flexBoxSide(x, y, r)
|
|
|
|
self.moveTo(2*x+3*self.thickness, 2*d)
|
|
|
|
self.ctx.scale(-1, 1)
|
|
|
|
self.flexBoxSide(x, y, r)
|
|
|
|
self.ctx.scale(-1, 1)
|
|
|
|
self.moveTo(2*self.thickness, -self.thickness)
|
|
|
|
self.rectangularWall(z, y, edges="fFeF")
|
|
|
|
|
2014-03-21 21:08:54 +01:00
|
|
|
self.close()
|
2013-09-01 01:59:24 +02:00
|
|
|
|
2016-03-23 22:05:06 +01:00
|
|
|
def main():
|
2016-07-31 14:15:06 +02:00
|
|
|
b = FlexBox3() #100, 40, 100, r=20, h=10, thickness=4.0)
|
2016-03-03 13:27:22 +01:00
|
|
|
b.parseArgs()
|
2013-09-01 01:59:24 +02:00
|
|
|
b.render()
|
2016-03-23 22:05:06 +01:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
main()
|