boxespy/boxes/generators/flexbox2.py

122 lines
3.8 KiB
Python
Raw Normal View History

#!/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-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
2016-07-31 14:15:06 +02:00
class FlexBox2(Boxes):
"""Box with living hinge and top corners rounded"""
2016-08-17 15:07:41 +02:00
ui_group = "FlexBox"
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
2016-08-17 15:07:41 +02:00
"--radius", action="store", type=float, default=15,
help="Radius of the corners in mm")
2018-10-19 21:46:30 +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 21:45:26 +02:00
def flexBoxSide(self, y, h, r, callback=None, move=None):
t = self.thickness
if self.move(y+2*t, h+t, move, True):
return
self.moveTo(t, t)
2013-05-30 18:38:10 +02:00
self.cc(callback, 0)
self.edges["f"](y)
2013-05-30 18:38:10 +02:00
self.corner(90, 0)
self.cc(callback, 1)
self.edges["f"](h - r)
2013-05-30 18:38:10 +02:00
self.corner(90, r)
self.cc(callback, 2)
self.edge(y - 2 * r)
2013-05-30 18:38:10 +02:00
self.corner(90, r)
self.cc(callback, 3)
self.latch(self.latchsize)
2013-05-30 18:38:10 +02:00
self.cc(callback, 4)
self.edges["f"](h - r - self.latchsize)
2013-05-30 18:38:10 +02:00
self.corner(90)
2018-10-19 21:45:26 +02:00
self.move(y+2*t, h+t, move)
def surroundingWall(self, move=None):
y, h, x, r = self.y, self.h, self.x, self.radius
2018-10-19 21:45:26 +02:00
t = self.thickness
tw = y + h - 3*r + 2*self.c4 + self.latchsize + t
th = x + 2.5*t
if self.move(tw, th, move, True):
return
2016-08-17 15:07:41 +02:00
2018-10-19 21:45:26 +02:00
self.moveTo(t, .25*t)
self.edges["F"](h - r, False)
2016-08-17 15:07:41 +02:00
2018-10-19 21:45:26 +02:00
if (y - 2 * r < t):
self.edges["X"](2 * self.c4 + y - 2 * r, x + 2 * t)
else:
2018-10-19 21:45:26 +02:00
self.edges["X"](self.c4, x + 2 * t)
self.edge(y - 2 * r)
2018-10-19 21:45:26 +02:00
self.edges["X"](self.c4, x + 2 * t)
2016-08-17 15:07:41 +02:00
self.latch(self.latchsize, False)
2018-10-19 21:45:26 +02:00
self.edge(x + 2 * t)
self.latch(self.latchsize, False, True)
self.edge(self.c4)
self.edge(y - 2 * r)
self.edge(self.c4)
self.edges["F"](h - r)
2013-05-30 18:38:10 +02:00
self.corner(90)
2018-10-19 21:45:26 +02:00
self.edge(t)
self.edges["f"](x)
2018-10-19 21:45:26 +02:00
self.edge(t)
2013-05-30 18:38:10 +02:00
self.corner(90)
2018-10-19 21:45:26 +02:00
self.move(tw, th, move)
2013-05-30 18:38:10 +02:00
def render(self):
2016-08-17 15:07:41 +02:00
if self.outside:
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h)
self.x = self.adjustSize(self.x)
2018-10-19 21:46:30 +02:00
self.latchsize *= self.thickness
self.radius = self.radius or min(self.y / 2.0, self.h - self.latchsize)
self.radius = min(self.radius, self.y / 2.0)
self.radius = min(self.radius, max(0, self.h - self.latchsize))
2016-07-09 10:35:45 +02:00
self.c4 = c4 = math.pi * self.radius * 0.5
2016-08-17 15:07:41 +02:00
self.moveTo(2 * self.thickness, self.thickness)
with self.saved_context():
self.surroundingWall(move="right")
self.rectangularWall(self.y, self.x, edges="FFFF")
2018-10-19 21:45:26 +02:00
self.surroundingWall(move="up only")
2016-08-17 15:07:41 +02:00
2018-10-19 21:45:26 +02:00
self.flexBoxSide(self.y, self.h, self.radius, move="right")
self.flexBoxSide(self.y, self.h, self.radius, move= "mirror right")
self.rectangularWall(self.x, self.h - self.radius - self.latchsize, edges="fFeF")
2013-05-30 18:38:10 +02:00
2016-08-17 15:07:41 +02:00