2016-07-11 23:01:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-10-19 19:15:55 +02:00
|
|
|
# Copyright (C) 2013-2018 Florian Festi
|
2016-06-14 20:36:26 +02:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
from boxes import *
|
|
|
|
import math
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-31 14:15:06 +02:00
|
|
|
class FlexBox4(Boxes):
|
2016-06-14 20:36:26 +02:00
|
|
|
"""Box with living hinge and left corners rounded"""
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "FlexBox"
|
|
|
|
|
2016-06-14 20:36:26 +02:00
|
|
|
def __init__(self):
|
|
|
|
Boxes.__init__(self)
|
2016-11-01 14:03:07 +01:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings)
|
|
|
|
self.addSettingsArgs(edges.FlexSettings)
|
2016-07-09 22:52:48 +02:00
|
|
|
self.buildArgParser("x", "y", "h", "outside")
|
2016-06-14 20:36:26 +02:00
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--radius", action="store", type=float, default=15,
|
2016-06-14 20:36:26 +02:00
|
|
|
help="Radius of the corners in mm")
|
2018-10-19 19:20:23 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--latchsize", action="store", type=float, default=8,
|
|
|
|
help="size of latch in multiples of thickness")
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2018-10-19 19:15:55 +02:00
|
|
|
def flexBoxSide(self, x, y, r, callback=None, move=None):
|
|
|
|
t = self.thickness
|
|
|
|
|
|
|
|
if self.move(x+2*t, y+t, move, True):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(t, t)
|
|
|
|
|
2016-06-14 20:36:26 +02:00
|
|
|
self.cc(callback, 0)
|
|
|
|
self.edges["f"](x)
|
|
|
|
self.corner(90, 0)
|
|
|
|
self.cc(callback, 1)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edges["f"](y - r)
|
2016-06-14 20:36:26 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 2)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(x - 2 * r)
|
2016-06-14 20:36:26 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 3)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edges["e"](y - r - self.latchsize)
|
2016-06-14 20:36:26 +02:00
|
|
|
self.cc(callback, 4)
|
|
|
|
self.latch(self.latchsize)
|
|
|
|
self.corner(90)
|
|
|
|
|
2018-10-19 19:15:55 +02:00
|
|
|
self.move(x+2*t, y+t, move)
|
|
|
|
|
|
|
|
def surroundingWall(self, move=None):
|
2016-06-14 20:36:26 +02:00
|
|
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
2018-10-19 19:15:55 +02:00
|
|
|
c4 = self.c4
|
|
|
|
|
2017-04-11 21:09:41 +02:00
|
|
|
t = self.thickness
|
2018-10-19 19:15:55 +02:00
|
|
|
|
|
|
|
tw, th = 2*c4 + 2*y + x - 4*r + 2*t, h + 2.5*t
|
|
|
|
|
|
|
|
if self.move(tw, th, move, True):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(t, 0.25*t)
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edges["F"](y - r, False)
|
|
|
|
if (x - 2 * r < self.thickness):
|
2018-10-19 19:15:55 +02:00
|
|
|
self.edges["X"](2 * c4 + x - 2 * r, h + 2 * self.thickness)
|
2016-06-14 20:36:26 +02:00
|
|
|
else:
|
2018-10-19 19:15:55 +02:00
|
|
|
self.edges["X"](c4, h + 2 * self.thickness)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(x - 2 * r)
|
2018-10-19 19:15:55 +02:00
|
|
|
self.edges["X"](c4, h + 2 * self.thickness)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
self.edge(y - r - self.latchsize)
|
2017-04-11 21:09:41 +02:00
|
|
|
self.latch(self.latchsize+t, False)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(h + 2 * self.thickness)
|
2017-04-11 21:09:41 +02:00
|
|
|
self.latch(self.latchsize+t, False, True)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(y - r - self.latchsize)
|
2018-10-19 19:15:55 +02:00
|
|
|
self.edge(c4)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(x - 2 * r)
|
2018-10-19 19:15:55 +02:00
|
|
|
self.edge(c4)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edges["F"](y - r)
|
2016-06-14 20:36:26 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edge(self.thickness)
|
|
|
|
self.edges["f"](h)
|
|
|
|
self.edge(self.thickness)
|
|
|
|
self.corner(90)
|
|
|
|
|
2018-10-19 19:15:55 +02:00
|
|
|
self.move(tw, th, move)
|
|
|
|
|
2016-06-14 20:36:26 +02:00
|
|
|
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)
|
|
|
|
|
2018-10-19 19:20:23 +02:00
|
|
|
self.latchsize *= self.thickness
|
2016-08-17 15:07:41 +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))
|
2018-10-19 10:02:16 +02:00
|
|
|
self.c4 = c4 = math.pi * self.radius * 0.5
|
2016-06-14 20:36:26 +02:00
|
|
|
|
|
|
|
|
2018-10-19 19:15:55 +02:00
|
|
|
self.surroundingWall(move="up")
|
|
|
|
self.flexBoxSide(self.x, self.y, self.radius, move="right")
|
|
|
|
self.flexBoxSide(self.x, self.y, self.radius, move="mirror right")
|
2016-06-14 20:36:26 +02:00
|
|
|
self.rectangularWall(self.x, self.h, edges="FeFF")
|
2018-10-19 19:15:55 +02:00
|
|
|
|
2016-06-14 20:36:26 +02:00
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|