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 *
|
2019-01-03 11:13:27 +01:00
|
|
|
from boxes.lids import _TopEdge
|
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"
|
|
|
|
|
2016-03-03 13:27:22 +01:00
|
|
|
def __init__(self):
|
|
|
|
Boxes.__init__(self)
|
2019-01-11 21:28:38 +01:00
|
|
|
self.addTopEdgeSettings(fingerjoint={"surroundingspaces": 0.5},
|
|
|
|
roundedtriangle={"outset" : 1})
|
2019-01-03 11:13:27 +01:00
|
|
|
self.buildArgParser("sx", "sy", "h", "hi", "outside", "bottom_edge",
|
|
|
|
"top_edge")
|
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)")
|
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
|
|
|
|
|
2016-03-03 13:27:22 +01:00
|
|
|
|
2013-11-26 22:53:45 +01:00
|
|
|
# outer walls
|
2018-08-16 20:49:12 +02:00
|
|
|
b = self.bottom_edge
|
2019-01-03 11:13:27 +01:00
|
|
|
t1, t2, t3, t4 = self.topEdges(self.top_edge)
|
2020-09-19 22:39:30 +02:00
|
|
|
self.closedtop = self.top_edge in "fFh"
|
2017-11-14 20:21:01 +01:00
|
|
|
|
2018-12-26 14:39:45 +01:00
|
|
|
# x sides
|
|
|
|
|
|
|
|
self.ctx.save()
|
|
|
|
|
|
|
|
# outer walls
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(x, h, [b, "F", t1, "F"], callback=[self.xHoles, None, self.gripHole],
|
|
|
|
ignore_widths=[1, 6], move="up")
|
|
|
|
self.rectangularWall(x, h, [b, "F", t3, "F"], callback=[self.mirrorX(self.xHoles, x), ],
|
|
|
|
ignore_widths=[1, 6], move="up")
|
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":
|
|
|
|
self.rectangularWall(x, y, "ffff", callback=[
|
2018-12-26 14:39:45 +01:00
|
|
|
self.xSlots, self.ySlots], move="up")
|
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"]
|
|
|
|
|
|
|
|
self.rectangularWall(x, hi, e, move="up")
|
|
|
|
|
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=[
|
|
|
|
self.xSlots, self.ySlots], move="up")
|
|
|
|
else:
|
|
|
|
self.drawLid(x, y, self.top_edge)
|
|
|
|
|
2018-12-26 14:39:45 +01:00
|
|
|
self.ctx.restore()
|
|
|
|
self.rectangularWall(x, hi, "ffff", move="right only")
|
|
|
|
|
|
|
|
# y walls
|
|
|
|
|
|
|
|
# outer walls
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(y, h, [b, "f", t2, "f"], callback=[self.yHoles, ],
|
|
|
|
ignore_widths=[1, 6], move="up")
|
|
|
|
self.rectangularWall(y, h, [b, "f", t4, "f"], callback=[self.mirrorX(self.yHoles, y), ],
|
|
|
|
ignore_widths=[1, 6], move="up")
|
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"]
|
2016-08-17 15:07:41 +02:00
|
|
|
self.rectangularWall(y, hi, e, move="up")
|
|
|
|
|
|
|
|
|
2013-11-06 22:49:32 +01:00
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|