From c39b33ad140e3bf2f2c3815c7c2970a927a9c0ea Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sat, 12 Nov 2016 21:39:12 +0100 Subject: [PATCH] New BinTray generator --- boxes/generators/bintray.py | 137 ++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 boxes/generators/bintray.py diff --git a/boxes/generators/bintray.py b/boxes/generators/bintray.py new file mode 100644 index 0000000..62f40e5 --- /dev/null +++ b/boxes/generators/bintray.py @@ -0,0 +1,137 @@ +#!/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 . + +from boxes import * +import math + +class BinFrontEdge(edges.BaseEdge): + char = "B" + def __call__(self, length, **kw): + f = self.settings.front + a1 = math.degrees(math.atan(f/(1-f))) + a2 = 45 + a1 + for i, l in enumerate(self.settings.sy): + self.corner(-a1) + self.edges["e"](l* (f**2+(1-f)**2)**0.5) + self.corner(a2) + self.edges["f"](l*f*2**0.5) + self.corner(-45) + if i < len(self.settings.sy)-1: + self.edge(self.thickness) + + def margin(self): + return max(self.settings.sy) * 0.5*2**0.5 + +class BinTray(Boxes): + """A Type tray variant to be used up right with sloped walls in front""" + + def __init__(self): + Boxes.__init__(self) + self.buildArgParser("sx", "sy", "h", "outside") + self.addSettingsArgs(edges.FingerJointSettings, finger=2.0, space=2.0, + surroundingspaces=0.5) + self.argparser.add_argument( + "--front", action="store", type=float, default=0.4, + help="fraction of bin height covert with slope") + + def xSlots(self): + posx = -0.5 * self.thickness + for x in self.sx[:-1]: + posx += x + self.thickness + posy = 0 + for y in self.sy: + self.fingerHolesAt(posx, posy, y) + posy += y + self.thickness + + def ySlots(self): + posy = -0.5 * self.thickness + for y in self.sy[:-1]: + posy += y + self.thickness + posx = 0 + for x in self.sx: + self.fingerHolesAt(posy, posx, x) + posx += x + self.thickness + + def xHoles(self): + posx = -0.5 * self.thickness + for x in self.sx[:-1]: + posx += x + self.thickness + self.fingerHolesAt(posx, 0, self.hi) + + def frontHoles(self, i): + def CB(): + posx = -0.5 * self.thickness + for x in self.sx[:-1]: + posx += x + self.thickness + self.fingerHolesAt(posx, 0, self.sy[i]*self.front*2**0.5) + return CB + + def yHoles(self): + posy = -0.5 * self.thickness + for y in self.sy[:-1]: + posy += y + self.thickness + self.fingerHolesAt(posy, 0, self.hi) + + def render(self): + if self.outside: + self.sx = self.adjustSize(self.sx) + self.sy = self.adjustSize(self.sy) + self.h = self.adjustSize(self.h, e2=False) + + x = sum(self.sx) + self.thickness * (len(self.sx) - 1) + y = sum(self.sy) + self.thickness * (len(self.sy) - 1) + h = self.h + hi = self.hi = h + t = self.thickness + + self.open() + + self.addPart(BinFrontEdge(self, self)) + + # outer walls + self.rectangularWall(x, h, "Ffef", callback=[self.xHoles], move="right") + self.rectangularWall(y, h, "FFBF", callback=[self.yHoles, ], move="up") + self.rectangularWall(y, h, "FFBF", callback=[self.yHoles, ]) + self.rectangularWall(x, h, "Ffef", callback=[self.xHoles, ], move="left") + self.rectangularWall(y, h, "FFBF", move="up only") + + # floor + 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", "B", "f"] + self.rectangularWall(y, hi, e, 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, move="up") + + # Front walls + for i in range(len(self.sy)): + self.rectangularWall(x, self.sy[i]*self.front*2**0.5, "eFeF", callback=[self.frontHoles(i)], move="up") + + self.close() + + +def main(): + b = BinTray() + b.parseArgs() + b.render() + + +if __name__ == '__main__': + main()