2018-03-15 19:08:47 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (C) 2013-2018 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 *
|
|
|
|
|
|
|
|
|
|
|
|
class UnevenHeightBox(Boxes):
|
|
|
|
"""Box with different height in each corner"""
|
|
|
|
|
|
|
|
ui_group = "Box"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2018-03-15 19:08:47 +01:00
|
|
|
Boxes.__init__(self)
|
|
|
|
self.addSettingsArgs(edges.FingerJointSettings)
|
2020-09-28 23:45:54 +02:00
|
|
|
self.addSettingsArgs(edges.GroovedSettings)
|
2018-03-15 20:46:00 +01:00
|
|
|
self.buildArgParser("x", "y", "outside", bottom_edge="F")
|
2018-03-15 19:08:47 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--height0", action="store", type=float, default=50,
|
|
|
|
help="height of the front left corner in mm")
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--height1", action="store", type=float, default=50,
|
|
|
|
help="height of the front right corner in mm")
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--height2", action="store", type=float, default=100,
|
|
|
|
help="height of the right back corner in mm")
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--height3", action="store", type=float, default=100,
|
|
|
|
help="height of the left back corner in mm")
|
2018-03-17 17:19:47 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--lid", action="store", type=boolarg, default=False,
|
|
|
|
help="add a lid (works best with high corners opposing each other)")
|
2020-08-26 22:22:10 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--lid_height", action="store", type=float, default=0,
|
|
|
|
help="additional height of the lid")
|
2020-09-28 23:45:54 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--edge_types", action="store", type=str, default="eeee",
|
|
|
|
help="which edges are flat (e) or grooved (z,Z), counter-clockwise from the front")
|
2018-03-15 19:08:47 +01:00
|
|
|
|
|
|
|
def render(self):
|
|
|
|
|
|
|
|
x, y = self.x, self.y
|
|
|
|
heights = [self.height0, self.height1, self.height2, self.height3]
|
|
|
|
|
2020-09-28 23:45:54 +02:00
|
|
|
edge_types = self.edge_types
|
|
|
|
if len(edge_types) != 4 or any(et not in "ezZ" for et in edge_types):
|
|
|
|
raise ValueError("Wrong edge_types style: %s)" % edge_types)
|
|
|
|
|
2018-03-15 19:08:47 +01:00
|
|
|
if self.outside:
|
|
|
|
x = self.adjustSize(x)
|
|
|
|
y = self.adjustSize(y)
|
|
|
|
for i in range(4):
|
2019-09-01 15:46:38 +02:00
|
|
|
heights[i] = self.adjustSize(heights[i], self.bottom_edge,
|
|
|
|
self.lid)
|
2018-03-15 19:08:47 +01:00
|
|
|
|
|
|
|
t = self.thickness
|
2018-03-17 21:04:24 +01:00
|
|
|
h0, h1, h2, h3 = heights
|
2018-03-15 20:46:00 +01:00
|
|
|
b = self.bottom_edge
|
2018-03-15 19:08:47 +01:00
|
|
|
|
2020-09-28 23:45:54 +02:00
|
|
|
self.trapezoidWall(x, h0, h1, [b, "F", edge_types[0], "F"], move="right")
|
|
|
|
self.trapezoidWall(y, h1, h2, [b, "f", edge_types[1], "f"], move="right")
|
|
|
|
self.trapezoidWall(x, h2, h3, [b, "F", edge_types[2], "F"], move="right")
|
|
|
|
self.trapezoidWall(y, h3, h0, [b, "f", edge_types[3], "f"], move="right")
|
2018-03-15 19:08:47 +01:00
|
|
|
|
2019-01-12 23:16:11 +01:00
|
|
|
with self.saved_context():
|
|
|
|
if b != "e":
|
|
|
|
self.rectangularWall(x, y, "ffff", move="up")
|
|
|
|
|
|
|
|
if self.lid:
|
|
|
|
maxh = max(heights)
|
2020-08-26 22:22:10 +02:00
|
|
|
lidheights = [maxh-h+self.lid_height for h in heights]
|
2019-01-12 23:16:11 +01:00
|
|
|
h0, h1, h2, h3 = lidheights
|
|
|
|
lidheights += lidheights
|
|
|
|
edges = ["E" if (lidheights[i] == 0.0 and lidheights[i+1] == 0.0) else "f" for i in range(4)]
|
|
|
|
self.rectangularWall(x, y, edges, move="up")
|
2018-03-17 17:19:47 +01:00
|
|
|
|
|
|
|
if self.lid:
|
2020-09-28 23:45:54 +02:00
|
|
|
self.moveTo(0, maxh+self.lid_height+self.edges["F"].spacing()+self.edges[b].spacing()+1*self.spacing, 180)
|
|
|
|
edge_inverse = {"e": "e", "z": "Z", "Z": "z"}
|
|
|
|
edge_types = [edge_inverse[et] for et in edge_types]
|
|
|
|
|
|
|
|
self.trapezoidWall(y, h0, h3, "Ff" + edge_types[3] + "f", move="right" +
|
2018-03-17 21:04:24 +01:00
|
|
|
(" only" if h0 == h3 == 0.0 else ""))
|
2020-09-28 23:45:54 +02:00
|
|
|
self.trapezoidWall(x, h3, h2, "FF" + edge_types[2] + "F", move="right" +
|
2018-03-17 21:04:24 +01:00
|
|
|
(" only" if h3 == h2 == 0.0 else ""))
|
2020-09-28 23:45:54 +02:00
|
|
|
self.trapezoidWall(y, h2, h1, "Ff" + edge_types[1] + "f", move="right" +
|
2018-03-17 21:04:24 +01:00
|
|
|
(" only" if h2 == h1 == 0.0 else ""))
|
2020-09-28 23:45:54 +02:00
|
|
|
self.trapezoidWall(x, h1, h0, "FF" + edge_types[0] + "F", move="right" +
|
2018-03-17 21:04:24 +01:00
|
|
|
(" only" if h1 == h0 == 0.0 else ""))
|
2018-03-15 19:08:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|