2017-02-12 09:08:14 +01:00
|
|
|
#!/usr/bin/env python3
|
2017-02-12 22:23:19 +01:00
|
|
|
# Copyright (C) 2013-2017 Florian Festi
|
2017-02-12 09:08:14 +01: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 *
|
2023-04-06 21:06:28 +02:00
|
|
|
from boxes.lids import _TopEdge, LidSettings
|
2022-12-31 15:52:55 +01:00
|
|
|
|
2017-02-12 09:08:14 +01:00
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
class UBox(_TopEdge):
|
2017-02-12 09:08:14 +01:00
|
|
|
"""Box various options for different stypes and lids"""
|
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "FlexBox"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2017-02-12 09:08:14 +01:00
|
|
|
Boxes.__init__(self)
|
|
|
|
self.addTopEdgeSettings()
|
|
|
|
self.addSettingsArgs(edges.FlexSettings)
|
2023-04-06 21:06:28 +02:00
|
|
|
self.addSettingsArgs(LidSettings)
|
2017-02-12 09:08:14 +01:00
|
|
|
self.buildArgParser("top_edge", "x", "y", "h")
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--radius", action="store", type=float, default=30.0,
|
|
|
|
help="radius of bottom corners")
|
|
|
|
self.angle = 0
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
def U(self, x, y, r, edge="e", move=None, label=""):
|
2017-02-12 09:08:14 +01:00
|
|
|
|
|
|
|
e = self.edges.get(edge, edge)
|
|
|
|
|
|
|
|
w = self.edges["f"].spacing()
|
|
|
|
tw = x+2*w
|
|
|
|
th = y+w+e.spacing()
|
2022-05-14 10:35:58 +02:00
|
|
|
if self.move(tw, th, move, True, label=label):
|
2017-02-12 09:08:14 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(w+r, w)
|
|
|
|
self.edges["f"](x-2*r)
|
|
|
|
self.corner(90, r)
|
|
|
|
self.edges["f"](y-r)
|
|
|
|
self.edgeCorner("f", e)
|
|
|
|
e(x)
|
|
|
|
self.edgeCorner(e, "f")
|
|
|
|
self.edges["f"](y-r)
|
|
|
|
self.corner(90, r)
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
self.move(tw, th, move, label=label)
|
2017-02-12 09:08:14 +01:00
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
def Uwall(self, x, y, h, r, edges="ee", move=None, label=""):
|
2017-02-12 09:08:14 +01:00
|
|
|
|
|
|
|
e = [self.edges.get(edge, edge) for edge in edges]
|
|
|
|
|
|
|
|
w = self.edges["F"].spacing()
|
|
|
|
cl = r*math.pi/2
|
|
|
|
|
|
|
|
tw = 2*y + x - 4*(cl-r) + e[0].spacing() + e[1].spacing()
|
|
|
|
th = h + 2*w
|
2022-05-14 10:35:58 +02:00
|
|
|
if self.move(tw, th, move, True, label=label):
|
2017-02-12 09:08:14 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(e[0].spacing())
|
|
|
|
|
|
|
|
for nr, flex in enumerate("XE"):
|
|
|
|
self.edges["F"](y-r)
|
2017-02-15 19:33:10 +01:00
|
|
|
if x-2*r > 0.1 * self.thickness:
|
|
|
|
self.edges[flex](cl, h=th)
|
|
|
|
self.edges["F"](x-2*r)
|
|
|
|
self.edges[flex](cl, h=th)
|
|
|
|
else:
|
|
|
|
self.edges[flex](2*cl+x-2*r, h=th)
|
2017-02-12 09:08:14 +01:00
|
|
|
self.edges["F"](y-r)
|
|
|
|
self.edgeCorner("F", e[nr])
|
|
|
|
e[nr](h)
|
|
|
|
self.edgeCorner(e[nr], "F")
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
self.move(tw, th, move, label=label)
|
2017-02-12 09:08:14 +01:00
|
|
|
|
|
|
|
def render(self):
|
|
|
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
|
|
|
|
2017-02-15 19:33:10 +01:00
|
|
|
self.radius = r = min(r, x/2.0, y)
|
|
|
|
|
2023-02-25 15:57:38 +01:00
|
|
|
_ = self.translations.gettext
|
2017-02-12 09:08:14 +01:00
|
|
|
t1, t2, t3, t4 = self.topEdges(self.top_edge)
|
|
|
|
|
2023-02-25 15:57:38 +01:00
|
|
|
self.U(x, y, r, t1, move="right", label=_("left"))
|
|
|
|
self.U(x, y, r, t3, move="up", label=_("right"))
|
|
|
|
self.U(x, y, r, t3, move="left only")
|
|
|
|
self.Uwall(x, y, h, r, [t2, t4], move="up", label=_("wall"))
|
2017-02-12 09:08:14 +01:00
|
|
|
|
2017-03-15 23:45:22 +01:00
|
|
|
self.drawLid(x, h, self.top_edge)
|
2023-04-06 21:06:28 +02:00
|
|
|
self.lid(x, h, self.top_edge)
|
2017-02-12 09:08:14 +01:00
|
|
|
|
|
|
|
|