2016-02-12 21:22:32 +01:00
|
|
|
#!/usr/bin/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-05-30 18:38:10 +02:00
|
|
|
|
2013-06-15 23:25:31 +02:00
|
|
|
from boxes import *
|
2013-05-30 18:38:10 +02:00
|
|
|
import math
|
|
|
|
|
2013-06-15 23:25:31 +02:00
|
|
|
class FlexBox(Boxes):
|
2016-03-08 21:53:29 +01:00
|
|
|
"""Box with living hinge and top corners rounded"""
|
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", "h", "outside")
|
2016-03-03 13:27:22 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--radius", action="store", type=float, default=15,
|
|
|
|
help="Radius of the corners in mm")
|
2013-05-30 18:38:10 +02:00
|
|
|
|
2013-06-15 23:25:31 +02:00
|
|
|
@restore
|
2013-05-30 18:38:10 +02:00
|
|
|
def flexBoxSide(self, x, y, r, callback=None):
|
|
|
|
self.cc(callback, 0)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](x)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90, 0)
|
|
|
|
self.cc(callback, 1)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](y-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)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](y-r-self.latchsize)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90)
|
|
|
|
|
|
|
|
def surroundingWall(self):
|
2016-03-03 13:27:22 +01:00
|
|
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
2013-05-30 18:38:10 +02:00
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
self.edges["F"](y-r, False)
|
2016-07-09 10:49:30 +02:00
|
|
|
if (x-2*r < self.thickness):
|
|
|
|
self.edges["X"](2*self.c4+x-2*r, h+2*self.thickness)
|
2013-07-20 18:09:51 +02:00
|
|
|
else:
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["X"](self.c4, h+2*self.thickness)
|
2013-07-20 18:09:51 +02:00
|
|
|
self.edge(x-2*r)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["X"](self.c4, h+2*self.thickness)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latch(self.latchsize, False)
|
2016-03-03 13:27:22 +01:00
|
|
|
self.edge(h+2*self.thickness)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.latch(self.latchsize, False, True)
|
|
|
|
self.edge(self.c4)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(x-2*r)
|
2013-06-03 09:49:51 +02:00
|
|
|
self.edge(self.c4)
|
2013-07-20 18:09:51 +02:00
|
|
|
self.edges["F"](y-r)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edge(self.thickness)
|
2016-03-03 13:27:22 +01:00
|
|
|
self.edges["f"](h)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.edge(self.thickness)
|
|
|
|
self.corner(90)
|
|
|
|
|
|
|
|
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.h = self.adjustSize(self.h)
|
|
|
|
|
2016-03-03 13:27:22 +01:00
|
|
|
self.latchsize = 8*self.thickness
|
2016-07-09 10:35:45 +02:00
|
|
|
self.radius = self.radius or min(self.x/2.0, self.y-self.latchsize)
|
|
|
|
self.radius = min(self.radius, self.x/2.0)
|
|
|
|
self.radius = min(self.radius, max(0, self.y-self.latchsize))
|
|
|
|
self.c4 = c4 = math.pi * self.radius * 0.5
|
2016-03-03 13:27:22 +01:00
|
|
|
|
2016-06-07 20:20:35 +02:00
|
|
|
self.open()
|
2016-03-03 13:27:22 +01:00
|
|
|
|
|
|
|
self.fingerJointSettings = (4, 4)
|
|
|
|
|
2013-05-30 18:38:10 +02:00
|
|
|
self.moveTo(2*self.thickness, self.thickness)
|
|
|
|
self.ctx.save()
|
|
|
|
self.surroundingWall()
|
2016-03-03 13:27:22 +01:00
|
|
|
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")
|
2013-05-30 18:38:10 +02:00
|
|
|
self.ctx.restore()
|
2016-03-03 13:27:22 +01:00
|
|
|
self.moveTo(0, self.h+4*self.thickness)
|
|
|
|
self.flexBoxSide(self.x, self.y, self.radius)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.moveTo(2*self.x+3*self.thickness, 0)
|
|
|
|
self.ctx.scale(-1, 1)
|
2016-03-03 13:27:22 +01:00
|
|
|
self.flexBoxSide(self.x, self.y, self.radius)
|
2013-05-30 18:38:10 +02:00
|
|
|
self.ctx.scale(-1, 1)
|
|
|
|
self.moveTo(2*self.thickness, 0)
|
2016-03-03 13:27:22 +01:00
|
|
|
self.rectangularWall(self.h, self.y-self.radius-self.latchsize, edges="fFeF")
|
2014-03-21 21:08:54 +01:00
|
|
|
self.close()
|
2013-05-30 18:38:10 +02:00
|
|
|
|
2016-03-23 22:05:06 +01:00
|
|
|
def main():
|
2016-03-03 13:27:22 +01:00
|
|
|
b = FlexBox()
|
|
|
|
b.parseArgs()
|
2013-05-30 18:38:10 +02:00
|
|
|
b.render()
|
2016-03-23 22:05:06 +01:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
main()
|