boxespy/boxes/generators/angledbox.py

148 lines
5.2 KiB
Python
Raw Normal View History

2016-12-30 23:01:57 +01:00
#!/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 *
import math
import copy
2016-12-30 23:01:57 +01:00
class AngledBox(Boxes):
"""Box with both ends cornered"""
ui_group = "Box"
2016-12-30 23:01:57 +01:00
def __init__(self):
Boxes.__init__(self)
2017-02-09 18:47:20 +01:00
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser("x", "y", "h", "outside", "bottom_edge")
2016-12-30 23:01:57 +01:00
self.argparser.add_argument(
"--n", action="store", type=int, default=5,
help="number of walls at one side (1+)")
self.argparser.add_argument(
"--top", action="store", type=str, default="none",
choices=["none", "angled hole", "angled lid", "angled lid2"],
help="style of the top and lid")
def floor(self, x, y, n, edge='e', hole=None, move=None, callback=None, label=""):
2016-12-30 23:01:57 +01:00
r, h, side = self.regularPolygon(2*n+2, h=y/2.0)
t = self.thickness
if n % 2:
lx = x - 2 * h + side
else:
lx = x - 2 * r + side
edge = self.edges.get(edge, edge)
tx = x + 2 * edge.spacing()
ty = y + 2 * edge.spacing()
if self.move(tx, ty, move, before=True):
return
self.moveTo((tx-lx)/2., edge.margin())
2016-12-30 23:01:57 +01:00
if hole:
with self.saved_context():
hr, hh, hside = self.regularPolygon(2*n+2, h=y/2.0-t)
dx = side - hside
hlx = lx - dx
2016-12-30 23:01:57 +01:00
self.moveTo(dx/2.0, t+edge.spacing())
for i, l in enumerate(([hlx] + ([hside] * n))* 2):
self.edge(l)
self.corner(360.0/(2*n + 2))
2016-12-30 23:01:57 +01:00
for i, l in enumerate(([lx] + ([side] * n))* 2):
self.cc(callback, i, 0, edge.startwidth() + self.burn)
edge(l)
self.edgeCorner(edge, edge, 360.0/(2*n + 2))
self.move(tx, ty, move, label=label)
2016-12-30 23:01:57 +01:00
def render(self):
x, y, h, n = self.x, self.y, self.h, self.n
b = self.bottom_edge
2016-12-30 23:01:57 +01:00
if n < 1:
n = self.n = 1
if x < y:
x, y = y, x
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
if self.top == "none":
h = self.adjustSize(h, False)
elif "lid" in self.top and self.top != "angled lid":
h = self.adjustSize(h) - self.thickness
else:
h = self.adjustSize(h)
t = self.thickness
r, hp, side = self.regularPolygon(2*n+2, h=y/2.0)
2016-12-30 23:01:57 +01:00
if n % 2:
lx = x - 2 * hp + side
2016-12-30 23:01:57 +01:00
else:
lx = x - 2 * r + side
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
fingerJointSettings.setValues(self.thickness, angle=360./(2 * (n+1)))
fingerJointSettings.edgeObjects(self, chars="gGH")
2016-12-30 23:01:57 +01:00
with self.saved_context():
if b != "e":
self.floor(x, y , n, edge='f', move="right", label="Bottom")
if self.top == "angled lid":
self.floor(x, y, n, edge='e', move="right", label="Lower Lid")
self.floor(x, y, n, edge='E', move="right", label="Upper Lid")
elif self.top in ("angled hole", "angled lid2"):
self.floor(x, y, n, edge='F', move="right", hole=True, label="Top Rim and Lid")
if self.top == "angled lid2":
self.floor(x, y, n, edge='E', move="right", label="Upper Lid")
2016-12-30 23:01:57 +01:00
self.floor(x, y , n, edge='F', move="up only")
fingers = self.top in ("angled lid2", "angled hole")
2016-12-30 23:01:57 +01:00
cnt = 0
for j in range(2):
cnt += 1
if j == 0 or n % 2:
self.rectangularWall(lx, h, move="right",
edges=b+"GfG" if fingers else b+"GeG",
label="wall {}".format(cnt))
else:
self.rectangularWall(lx, h, move="right",
edges=b+"gfg" if fingers else b+"geg",
label="wall {}".format(cnt))
2016-12-30 23:01:57 +01:00
for i in range(n):
cnt += 1
if (i+j*((n+1)%2)) % 2: # reverse for second half if even n
2016-12-30 23:01:57 +01:00
self.rectangularWall(side, h, move="right",
edges=b+"GfG" if fingers else b+"GeG",
label="wall {}".format(cnt))
2016-12-30 23:01:57 +01:00
else:
self.rectangularWall(side, h, move="right",
edges=b+"gfg" if fingers else b+"geg",
label="wall {}".format(cnt))
2016-12-30 23:01:57 +01:00