boxespy/typetray.py

114 lines
4.1 KiB
Python
Raw Normal View History

2016-02-12 21:22:32 +01:00
#!/usr/bin/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 *
class TypeTray(Boxes):
2016-03-15 21:29:03 +01:00
"""Type tray - allows only continuous walls"""
def __init__(self):
Boxes.__init__(self)
self.buildArgParser("sx", "sy", "h", "hi")
2016-03-15 20:29:49 +01:00
self.argparser.add_argument(
"--gripheight", action="store", type=float, default=30,
dest="gh", help="height of the grip hole in mm")
self.argparser.add_argument(
"--gripwidth", action="store", type=float, default=70,
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
for x in self.sx[:-1]:
2013-11-06 22:49:32 +01:00
posx += x + self.thickness
posy = 0
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
for y in self.sy[:-1]:
2013-11-06 22:49:32 +01:00
posy += y + self.thickness
posx = 0
for x in 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
for x in self.sx[:-1]:
2013-11-06 22:49:32 +01:00
posx += x + self.thickness
self.fingerHolesAt(posx, 0, self.hi)
2013-11-06 22:49:32 +01:00
def yHoles(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
2013-11-06 22:49:32 +01:00
posy += y + self.thickness
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
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
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):
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
hi = self.hi = self.hi or h
2013-11-06 22:49:32 +01:00
t = self.thickness
2016-03-15 20:38:30 +01:00
self.open(width=2*max(x,y)+10*t, height=(len(self.sx)+len(self.sy))*(h+2*t)+4*t)
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
surroundingspaces=0.5)
2013-11-06 22:49:32 +01:00
self.moveTo(t, t)
# outer walls
self.rectangularWall(x, h, "Ffef", callback=[
2016-03-15 20:29:49 +01:00
self.xHoles, None, self.gripHole],
2013-11-06 22:49:32 +01:00
move="right")
self.rectangularWall(y, h, "FFeF", callback=[self.yHoles,],
move="up")
self.rectangularWall(y, h, "FFeF", callback=[self.yHoles,])
self.rectangularWall(x, h, "Ffef", callback=[self.xHoles,],
move="left up")
# floor
2013-11-06 22:49:32 +01:00
self.rectangularWall(x, y, "ffff",
callback=[self.xSlots, self.ySlots],
move="right")
# Inner walls
for i in range(len(self.sx)-1):
e = [edges.SlottedEdge(self, self.sy, "f", slots=0.5*hi), "f", "e", "f"]
self.rectangularWall(y, hi, e,
2013-11-06 22:49:32 +01:00
move="up")
for i in range(len(self.sy)-1):
e = [edges.SlottedEdge(self, self.sx, "f"), "f",
edges.SlottedEdge(self, self.sx[::-1], "e", slots=0.5*hi), "f"]
self.rectangularWall(x, hi, e,
2013-11-06 22:49:32 +01:00
move="up")
2014-03-21 21:08:54 +01:00
self.close()
2013-11-06 22:49:32 +01:00
2016-03-23 22:05:06 +01:00
def main():
b = TypeTray()
b.parseArgs()
b.render()
2016-03-23 22:05:06 +01:00
if __name__ == '__main__':
main()