2013-05-30 18:38:10 +02:00
|
|
|
#!/usr/bin/python
|
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-05-30 18:38:10 +02:00
|
|
|
|
|
|
|
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
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latchsize = 8*thickness
|
|
|
|
|
2013-05-30 18:38:10 +02:00
|
|
|
width = 2*x + 2*y - 8*r + 4*c4 + 4*thickness
|
2014-03-15 13:23:02 +01:00
|
|
|
height = y + z + 4*thickness
|
2013-05-30 18:38:10 +02:00
|
|
|
boxes.Boxes.__init__(self, width, height, thickness=thickness)
|
|
|
|
|
|
|
|
@boxes.restore
|
|
|
|
def flexBoxSide(self, x, y, r, callback=None):
|
|
|
|
self.moveTo(r, 0)
|
|
|
|
for i, l in zip(range(2), (x, y)):
|
|
|
|
self.cc(callback, i)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.fingerJointEdge(l-2*r)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 2)
|
|
|
|
self.edge(x-2*r)
|
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 3)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latch(self.latchsize)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.cc(callback, 4)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.fingerJointEdge(y-2*r-self.latchsize)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
|
|
|
|
def surroundingWall(self):
|
|
|
|
x, y, z, r = self.x, self.y, self.z, self.r
|
|
|
|
|
|
|
|
c4 = math.pi * r * 0.5
|
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
self.edges["F"](y-2*r-self.latchsize, False)
|
|
|
|
self.flexEdge(c4, z+2*self.thickness)
|
|
|
|
self.edges["F"](x-2*r, False)
|
|
|
|
self.flexEdge(c4, z+2*self.thickness)
|
|
|
|
self.edges["F"](y-2*r, False)
|
|
|
|
self.flexEdge(c4, z+2*self.thickness)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(x-2*r)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.flexEdge(c4, z+2*self.thickness)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latch(self.latchsize, False)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(z+2*self.thickness)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latch(self.latchsize, False, True)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(c4)
|
|
|
|
self.edge(x-2*r)
|
|
|
|
self.edge(c4)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.edges["F"](y-2*r, False)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(c4)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.edges["F"](x-2*r, False)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(c4)
|
2013-07-20 10:49:45 +02:00
|
|
|
self.edges["F"](y-2*r-self.latchsize, False)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edge(z+2*self.thickness)
|
|
|
|
self.corner(90)
|
|
|
|
|
|
|
|
def render(self):
|
|
|
|
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(2*self.x+3*self.thickness, 0)
|
|
|
|
self.ctx.scale(-1, 1)
|
|
|
|
self.flexBoxSide(self.x, self.y, self.r)
|
|
|
|
|
2014-03-21 21:08:54 +01:00
|
|
|
self.close()
|
2013-05-30 18:38:10 +02:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
2014-03-15 16:13:24 +01:00
|
|
|
b = FlexBox(50, 70, 50, r=15)
|
2013-05-30 18:38:10 +02:00
|
|
|
b.render()
|