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 *
|
2017-02-12 22:23:19 +01:00
|
|
|
from boxes.lids import _TopEdge, _ChestLid
|
2017-02-12 09:08:14 +01:00
|
|
|
import math
|
|
|
|
|
2017-02-12 22:23:19 +01:00
|
|
|
class UBox(_TopEdge, _ChestLid):
|
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"
|
|
|
|
|
2017-02-12 09:08:14 +01:00
|
|
|
def __init__(self):
|
|
|
|
Boxes.__init__(self)
|
|
|
|
self.addTopEdgeSettings()
|
|
|
|
self.addSettingsArgs(edges.FlexSettings)
|
|
|
|
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.argparser.add_argument(
|
|
|
|
"--lid", action="store", type=str, default="default (none)",
|
|
|
|
choices=("default (none)", "chest", "flat"),
|
|
|
|
help="additional lid")
|
|
|
|
self.angle = 0
|
|
|
|
|
|
|
|
def U(self, x, y, r, edge="e", move=None):
|
|
|
|
|
|
|
|
e = self.edges.get(edge, edge)
|
|
|
|
|
|
|
|
w = self.edges["f"].spacing()
|
|
|
|
tw = x+2*w
|
|
|
|
th = y+w+e.spacing()
|
|
|
|
if self.move(tw, th, move, True):
|
|
|
|
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)
|
|
|
|
|
|
|
|
self.move(tw, th, move)
|
|
|
|
|
|
|
|
def Uwall(self, x, y, h, r, edges="ee", move=None):
|
|
|
|
|
|
|
|
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
|
|
|
|
if self.move(tw, th, move, True):
|
|
|
|
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")
|
|
|
|
|
|
|
|
self.move(tw, th, move)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-02-12 09:08:14 +01:00
|
|
|
self.open()
|
|
|
|
|
|
|
|
t1, t2, t3, t4 = self.topEdges(self.top_edge)
|
|
|
|
|
|
|
|
self.U(x, y, r, t1, move="right")
|
|
|
|
self.U(x, y, r, t3, move="up")
|
|
|
|
self.U(x, y, r, t3, move="left only")
|
|
|
|
self.Uwall(x, y, h, r, [t2, t4], move="up")
|
|
|
|
|
|
|
|
self.drawLid(x, y, self.top_edge)
|
|
|
|
self.drawAddOnLid(x, y, self.lid)
|
|
|
|
|
|
|
|
self.close()
|
|
|
|
|