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-08-17 15:07:41 +02:00
|
|
|
|
2016-07-31 14:15:06 +02:00
|
|
|
class FlexBox3(Boxes):
|
2016-03-08 21:53:29 +01:00
|
|
|
"""Box with living hinge"""
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "FlexBox"
|
|
|
|
|
2016-03-03 13:27:22 +01:00
|
|
|
def __init__(self):
|
|
|
|
Boxes.__init__(self)
|
2017-02-16 18:50:47 +01:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
|
2016-11-01 14:03:07 +01:00
|
|
|
self.addSettingsArgs(edges.FlexSettings)
|
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(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--z", action="store", type=float, default=100.0,
|
2016-03-03 13:27:22 +01:00
|
|
|
help="height of the box")
|
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--h", action="store", type=float, default=10.0,
|
2016-03-03 13:27:22 +01:00
|
|
|
help="height of the lid")
|
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--radius", action="store", type=float, default=10.0,
|
2016-03-03 13:27:22 +01:00
|
|
|
help="radius of the lids living hinge")
|
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--c", action="store", type=float, default=1.0,
|
2016-03-03 13:27:22 +01:00
|
|
|
dest="d", help="clearance of the lid")
|
2013-09-01 01:59:24 +02:00
|
|
|
|
2018-10-19 22:11:18 +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
|
2013-09-01 01:59:24 +02:00
|
|
|
|
2018-10-19 22:11:18 +02:00
|
|
|
self.moveTo(t, t)
|
2013-09-01 01:59:24 +02:00
|
|
|
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-08-17 15:07:41 +02:00
|
|
|
self.edges["f"](y - r)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90, r)
|
|
|
|
self.cc(callback, 2)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edge(x - r)
|
2013-09-01 01:59:24 +02:00
|
|
|
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)
|
|
|
|
|
2018-10-19 22:11:18 +02:00
|
|
|
self.move(x+2*t, y+t, move)
|
|
|
|
|
|
|
|
def surroundingWall(self, move=None):
|
2016-03-03 13:27:22 +01:00
|
|
|
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
|
2018-10-19 22:11:18 +02:00
|
|
|
t = self.thickness
|
|
|
|
|
2019-08-08 22:53:08 +02:00
|
|
|
tw = x + y - 2*r + self.c4 + 2*t + t
|
2018-10-19 22:11:18 +02:00
|
|
|
th = z + 4*t + 2*d
|
|
|
|
|
|
|
|
if self.move(tw, th, move, True):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(t, d + t)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
self.edges["F"](y - r, False)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edges["X"](self.c4, z + 2 * t)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(-90)
|
|
|
|
self.edge(d)
|
|
|
|
self.corner(90)
|
2019-08-08 22:53:08 +02:00
|
|
|
self.edges["f"](x - r + t)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edges["f"](z + 2 * t + 2 * d)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
2019-08-08 22:53:08 +02:00
|
|
|
self.edges["f"](x - r + t)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
self.edge(d)
|
|
|
|
self.corner(-90)
|
|
|
|
self.edge(self.c4)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.edges["F"](y - r)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edge(t)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.edges["f"](z)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edge(t)
|
2013-09-01 01:59:24 +02:00
|
|
|
self.corner(90)
|
|
|
|
|
2018-10-19 22:11:18 +02:00
|
|
|
self.move(tw, th, move)
|
|
|
|
|
|
|
|
def lidSide(self, move=None):
|
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
|
2016-08-17 15:07:41 +02:00
|
|
|
r2 = r + t if r + t <= h + t else h + t
|
2018-10-19 22:11:18 +02:00
|
|
|
|
2017-02-16 23:18:44 +01:00
|
|
|
if r < h:
|
|
|
|
r2 = r + t
|
2018-10-19 22:11:18 +02:00
|
|
|
base_l = x + 2 * t
|
|
|
|
if self.move(h+t, base_l+t, move, True):
|
|
|
|
return
|
|
|
|
|
2017-02-16 23:18:44 +01:00
|
|
|
self.edge(h + self.thickness - r2)
|
|
|
|
self.corner(90, r2)
|
2019-08-08 22:53:08 +02:00
|
|
|
self.edge(r - r2 + 1 * t)
|
2017-02-16 23:18:44 +01:00
|
|
|
else:
|
|
|
|
a = math.acos((r-h)/(r+t))
|
|
|
|
ang = math.degrees(a)
|
2019-08-08 22:53:08 +02:00
|
|
|
base_l = x + (r+t) * math.sin(a) - r + t
|
2018-10-19 22:11:18 +02:00
|
|
|
if self.move(h+t, base_l+t, move, True):
|
|
|
|
return
|
|
|
|
|
2017-02-16 23:18:44 +01:00
|
|
|
self.corner(90-ang)
|
|
|
|
self.corner(ang, r+t)
|
|
|
|
|
2019-08-08 22:53:08 +02:00
|
|
|
self.edges["F"](x - r + t)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edgeCorner("F", "f")
|
2013-09-15 19:20:34 +02:00
|
|
|
self.edges["g"](h)
|
2018-10-19 22:11:18 +02:00
|
|
|
self.edgeCorner("f", "e")
|
2017-02-16 23:18:44 +01:00
|
|
|
self.edge(base_l)
|
|
|
|
self.corner(90)
|
2013-09-01 01:59:24 +02:00
|
|
|
|
2018-10-19 22:11:18 +02:00
|
|
|
self.move(h+t, base_l+t, move)
|
|
|
|
|
2013-09-01 01:59:24 +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.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
|
2016-08-17 15:07:41 +02:00
|
|
|
r = self.radius = self.radius or min(x, y) / 2.0
|
2016-03-03 13:27:22 +01:00
|
|
|
thickness = self.thickness
|
|
|
|
|
|
|
|
self.c4 = c4 = math.pi * r * 0.5 * 0.95
|
2016-08-17 15:07:41 +02:00
|
|
|
self.latchsize = 8 * thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
width = 2 * x + y - 2 * r + c4 + 14 * thickness + 3 * h # lock
|
|
|
|
height = y + z + 8 * thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
|
|
|
|
|
2017-02-16 18:50:47 +01:00
|
|
|
s = edges.FingerJointSettings(self.thickness, finger=1.,
|
|
|
|
space=1., surroundingspaces=1)
|
|
|
|
s.edgeObjects(self, "gGH")
|
2013-09-01 01:59:24 +02:00
|
|
|
|
2019-01-12 23:16:11 +01:00
|
|
|
with self.saved_context():
|
|
|
|
self.surroundingWall(move="right")
|
|
|
|
self.rectangularWall(x, z, edges="FFFF", move="right")
|
|
|
|
self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right")
|
|
|
|
self.lidSide(move="right")
|
|
|
|
self.lidSide(move="mirror right")
|
2018-10-19 22:11:18 +02:00
|
|
|
|
|
|
|
self.surroundingWall(move="up only")
|
|
|
|
|
|
|
|
self.flexBoxSide(x, y, r, move="right")
|
|
|
|
self.flexBoxSide(x, y, r, move="mirror right")
|
2013-09-01 01:59:24 +02:00
|
|
|
self.rectangularWall(z, y, edges="fFeF")
|
|
|
|
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|