boxespy/boxes/generators/ubox.py

112 lines
3.2 KiB
Python

#!/usr/bin/env python3
# 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/>.
from boxes import *
from boxes.generators.box2 import TopEdge, ChestLid
from boxes.edges import Bolts
import inspect
import math
class UBox(TopEdge, ChestLid):
"""Box various options for different stypes and lids"""
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)
self.edges[flex](cl, h=th)
self.edges["F"](x-2*r)
self.edges[flex](cl, h=th)
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
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()
def main():
b = UBox()
b.parseArgs()
b.render()
if __name__ == '__main__':
main()