2016-07-11 23:01:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-03-16 18:26:12 +01:00
|
|
|
# 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/>.
|
2013-11-06 22:49:32 +01:00
|
|
|
|
|
|
|
from boxes import *
|
2023-04-07 21:32:28 +02:00
|
|
|
from boxes.lids import _TopEdge, LidSettings
|
2013-11-06 22:49:32 +01:00
|
|
|
|
2019-01-03 11:13:27 +01:00
|
|
|
class TypeTray(_TopEdge):
|
2016-03-15 21:29:03 +01:00
|
|
|
"""Type tray - allows only continuous walls"""
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "Tray"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2016-03-03 13:27:22 +01:00
|
|
|
Boxes.__init__(self)
|
2019-01-11 21:28:38 +01:00
|
|
|
self.addTopEdgeSettings(fingerjoint={"surroundingspaces": 0.5},
|
|
|
|
roundedtriangle={"outset" : 1})
|
2023-04-09 22:23:34 +02:00
|
|
|
self.addSettingsArgs(LidSettings)
|
2019-01-03 11:13:27 +01:00
|
|
|
self.buildArgParser("sx", "sy", "h", "hi", "outside", "bottom_edge",
|
|
|
|
"top_edge")
|
2021-10-30 20:42:50 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--back_height", action="store", type=float, default=0.0,
|
2023-01-02 00:32:42 +01:00
|
|
|
help="additional height of the back wall - e top edge only")
|
2021-10-30 20:42:50 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--radius", action="store", type=float, default=0.0,
|
|
|
|
help="radius for strengthening side walls with back_height")
|
2016-03-15 20:29:49 +01:00
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--gripheight", action="store", type=float, default=30,
|
2016-03-15 20:29:49 +01:00
|
|
|
dest="gh", help="height of the grip hole in mm")
|
|
|
|
self.argparser.add_argument(
|
2016-08-17 15:07:41 +02:00
|
|
|
"--gripwidth", action="store", type=float, default=70,
|
2016-03-15 20:29:49 +01:00
|
|
|
dest="gw", help="width of th grip hole in mm (zero for no hole)")
|
2022-06-16 18:06:58 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--handle", type=boolarg, default=False, help="add handle to the bottom (changes bottom edge in the front)",
|
|
|
|
)
|
2013-11-06 22:49:32 +01:00
|
|
|
|
|
|
|
def xSlots(self):
|
|
|
|
posx = -0.5 * self.thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
for x in self.sx[:-1]:
|
2013-11-06 22:49:32 +01:00
|
|
|
posx += x + self.thickness
|
|
|
|
posy = 0
|
2016-03-03 13:27:22 +01:00
|
|
|
for y in self.sy:
|
2013-11-06 22:49:32 +01:00
|
|
|
self.fingerHolesAt(posx, posy, y)
|
|
|
|
posy += y + self.thickness
|
|
|
|
|
|
|
|
def ySlots(self):
|
|
|
|
posy = -0.5 * self.thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
for y in self.sy[:-1]:
|
2013-11-06 22:49:32 +01:00
|
|
|
posy += y + self.thickness
|
|
|
|
posx = 0
|
2018-04-25 23:36:32 +02:00
|
|
|
for x in reversed(self.sx):
|
2013-11-06 22:49:32 +01:00
|
|
|
self.fingerHolesAt(posy, posx, x)
|
|
|
|
posx += x + self.thickness
|
|
|
|
|
|
|
|
def xHoles(self):
|
|
|
|
posx = -0.5 * self.thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
for x in self.sx[:-1]:
|
2013-11-06 22:49:32 +01:00
|
|
|
posx += x + self.thickness
|
2013-12-01 16:13:29 +01:00
|
|
|
self.fingerHolesAt(posx, 0, self.hi)
|
2013-11-06 22:49:32 +01:00
|
|
|
|
|
|
|
def yHoles(self):
|
|
|
|
posy = -0.5 * self.thickness
|
2016-03-03 13:27:22 +01:00
|
|
|
for y in self.sy[:-1]:
|
2013-11-06 22:49:32 +01:00
|
|
|
posy += y + self.thickness
|
2013-12-01 16:13:29 +01:00
|
|
|
self.fingerHolesAt(posy, 0, self.hi)
|
2013-11-06 22:49:32 +01:00
|
|
|
|
2016-03-15 20:29:49 +01:00
|
|
|
def gripHole(self):
|
|
|
|
if not self.gw:
|
|
|
|
return
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
|
2016-03-15 20:29:49 +01:00
|
|
|
r = min(self.gw, self.gh) / 2.0
|
2016-08-17 15:07:41 +02:00
|
|
|
self.rectangularHole(x / 2.0, self.gh * 1.5, self.gw, self.gh, r)
|
2013-11-06 22:49:32 +01:00
|
|
|
|
|
|
|
def render(self):
|
2016-07-09 22:52:48 +02:00
|
|
|
if self.outside:
|
|
|
|
self.sx = self.adjustSize(self.sx)
|
|
|
|
self.sy = self.adjustSize(self.sy)
|
|
|
|
self.h = self.adjustSize(self.h, e2=False)
|
|
|
|
if self.hi:
|
|
|
|
self.hi = self.adjustSize(self.hi, e2=False)
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
|
|
|
|
y = sum(self.sy) + self.thickness * (len(self.sy) - 1)
|
2013-11-06 22:49:32 +01:00
|
|
|
h = self.h
|
2017-11-14 20:21:01 +01:00
|
|
|
sameh = not self.hi
|
2016-03-03 13:27:22 +01:00
|
|
|
hi = self.hi = self.hi or h
|
2013-11-06 22:49:32 +01:00
|
|
|
t = self.thickness
|
|
|
|
|
2013-11-26 22:53:45 +01:00
|
|
|
# outer walls
|
2018-08-16 20:49:12 +02:00
|
|
|
b = self.bottom_edge
|
2022-10-01 12:58:02 +02:00
|
|
|
tl, tb, tr, tf = self.topEdges(self.top_edge)
|
2022-05-08 12:20:29 +02:00
|
|
|
self.closedtop = self.top_edge in "fFhŠ"
|
2017-11-14 20:21:01 +01:00
|
|
|
|
2021-10-30 20:42:50 +02:00
|
|
|
bh = self.back_height if self.top_edge == "e" else 0.0
|
|
|
|
|
2018-12-26 14:39:45 +01:00
|
|
|
# x sides
|
|
|
|
|
|
|
|
self.ctx.save()
|
|
|
|
|
2022-08-20 09:23:25 +02:00
|
|
|
# outer walls - front/back
|
2021-11-06 22:44:23 +01:00
|
|
|
if bh:
|
2022-10-01 12:58:02 +02:00
|
|
|
self.rectangularWall(x, h+bh, [b, "f", tb, "f"],
|
2022-10-01 12:52:06 +02:00
|
|
|
callback=[self.xHoles],
|
2021-11-06 22:49:23 +01:00
|
|
|
ignore_widths=[],
|
2022-08-20 09:23:25 +02:00
|
|
|
move="up", label="back")
|
2022-10-01 12:58:02 +02:00
|
|
|
self.rectangularWall(x, h, ["f" if self.handle else b, "f", tf, "f"],
|
2022-10-01 12:52:06 +02:00
|
|
|
callback=[self.mirrorX(self.xHoles, x),
|
|
|
|
None, self.gripHole],
|
|
|
|
move="up", label="front")
|
2021-11-06 22:44:23 +01:00
|
|
|
else:
|
2022-10-01 12:58:02 +02:00
|
|
|
self.rectangularWall(x, h, [b, "F", tb, "F"],
|
2022-10-01 12:52:06 +02:00
|
|
|
callback=[self.xHoles],
|
2021-11-06 22:49:23 +01:00
|
|
|
ignore_widths=[1, 6],
|
2022-08-20 09:23:25 +02:00
|
|
|
move="up", label="back")
|
2022-10-01 12:58:02 +02:00
|
|
|
self.rectangularWall(x, h, ["f" if self.handle else b, "F", tf, "F"],
|
2022-10-01 12:52:06 +02:00
|
|
|
callback=[self.mirrorX(self.xHoles, x),
|
|
|
|
None, self.gripHole],
|
2022-06-16 18:06:58 +02:00
|
|
|
ignore_widths=[] if self.handle else [1, 6],
|
2022-10-01 12:52:06 +02:00
|
|
|
move="up", label="front")
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2013-11-26 22:53:45 +01:00
|
|
|
# floor
|
2018-12-08 18:21:36 +01:00
|
|
|
if b != "e":
|
2022-06-16 18:06:58 +02:00
|
|
|
if self.handle:
|
2022-08-20 09:23:25 +02:00
|
|
|
self.rectangularWall(x, y, "ffYf", callback=[self.xSlots, self.ySlots], move="up", label="bottom")
|
2022-06-16 18:06:58 +02:00
|
|
|
else:
|
2022-08-20 09:23:25 +02:00
|
|
|
self.rectangularWall(x, y, "ffff", callback=[self.xSlots, self.ySlots], move="up", label="bottom")
|
2017-11-14 20:21:01 +01:00
|
|
|
|
2013-11-26 22:53:45 +01:00
|
|
|
# Inner walls
|
2018-12-08 18:21:36 +01:00
|
|
|
|
|
|
|
be = "f" if b != "e" else "e"
|
|
|
|
|
2018-12-26 14:39:45 +01:00
|
|
|
for i in range(len(self.sy) - 1):
|
|
|
|
e = [edges.SlottedEdge(self, self.sx, be), "f",
|
|
|
|
edges.SlottedEdge(self, self.sx[::-1], "e", slots=0.5 * hi), "f"]
|
|
|
|
if self.closedtop and sameh:
|
|
|
|
e = [edges.SlottedEdge(self, self.sx, be), "f",
|
|
|
|
edges.SlottedEdge(self, self.sx[::-1], "f", slots=0.5 * hi), "f"]
|
|
|
|
|
2022-10-01 12:52:06 +02:00
|
|
|
self.rectangularWall(x, hi, e, move="up", label=f"inner x {i+1}")
|
2018-12-26 14:39:45 +01:00
|
|
|
|
2019-01-10 22:27:36 +01:00
|
|
|
# top / lid
|
|
|
|
if self.closedtop and sameh:
|
|
|
|
e = "FFFF" if self.top_edge == "f" else "ffff"
|
|
|
|
self.rectangularWall(x, y, e, callback=[
|
2022-10-01 12:52:06 +02:00
|
|
|
self.xSlots, self.ySlots], move="up", label="top")
|
2019-01-10 22:27:36 +01:00
|
|
|
else:
|
|
|
|
self.drawLid(x, y, self.top_edge)
|
2023-04-07 21:32:28 +02:00
|
|
|
self.lid(x, y, self.top_edge)
|
2019-01-10 22:27:36 +01:00
|
|
|
|
2018-12-26 14:39:45 +01:00
|
|
|
self.ctx.restore()
|
|
|
|
self.rectangularWall(x, hi, "ffff", move="right only")
|
|
|
|
|
|
|
|
# y walls
|
|
|
|
|
2022-08-20 09:23:25 +02:00
|
|
|
# outer walls - left/right
|
2021-10-30 20:42:50 +02:00
|
|
|
|
|
|
|
if bh:
|
|
|
|
self.trapezoidSideWall(
|
2021-11-06 22:49:23 +01:00
|
|
|
y, h, h+bh, [b, "h", "e", "h"],
|
2022-10-01 12:52:06 +02:00
|
|
|
radius=self.radius, callback=[self.yHoles, ],
|
|
|
|
move="up", label="left side")
|
2021-10-30 20:42:50 +02:00
|
|
|
self.trapezoidSideWall(
|
2021-11-06 22:49:23 +01:00
|
|
|
y, h+bh, h, [b, "h", "e", "h"], radius=self.radius,
|
2022-10-01 12:52:06 +02:00
|
|
|
callback=[self.mirrorX(self.yHoles, y), ],
|
|
|
|
move="up", label="right side")
|
2021-10-30 20:42:50 +02:00
|
|
|
else:
|
|
|
|
self.rectangularWall(
|
2022-10-01 12:58:02 +02:00
|
|
|
y, h, [b, "f", tl, "f"], callback=[self.yHoles, ],
|
2022-06-16 18:06:58 +02:00
|
|
|
ignore_widths=[6] if self.handle else [1, 6],
|
2022-10-01 12:52:06 +02:00
|
|
|
move="up", label="left side")
|
2021-10-30 20:42:50 +02:00
|
|
|
self.rectangularWall(
|
2022-10-01 12:58:02 +02:00
|
|
|
y, h, [b, "f", tr, "f"],
|
2021-10-30 20:42:50 +02:00
|
|
|
callback=[self.mirrorX(self.yHoles, y), ],
|
2022-06-16 18:06:58 +02:00
|
|
|
ignore_widths=[1] if self.handle else [1, 6],
|
2022-10-01 12:52:06 +02:00
|
|
|
move="up", label="right side")
|
2018-12-26 14:39:45 +01:00
|
|
|
|
|
|
|
# inner walls
|
2016-08-17 15:07:41 +02:00
|
|
|
for i in range(len(self.sx) - 1):
|
2018-12-08 18:21:36 +01:00
|
|
|
e = [edges.SlottedEdge(self, self.sy, be, slots=0.5 * hi),
|
2017-11-14 20:21:01 +01:00
|
|
|
"f", "e", "f"]
|
|
|
|
if self.closedtop and sameh:
|
2018-12-08 18:21:36 +01:00
|
|
|
e = [edges.SlottedEdge(self, self.sy, be, slots=0.5 * hi),"f",
|
2017-11-14 20:21:01 +01:00
|
|
|
edges.SlottedEdge(self, self.sy[::-1], "f"), "f"]
|
2022-10-01 12:52:06 +02:00
|
|
|
self.rectangularWall(y, hi, e, move="up", label=f"inner y {i+1}")
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
|
2013-11-06 22:49:32 +01:00
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|