diff --git a/boxes/generators/cardbox.py b/boxes/generators/cardbox.py index a3c6bda..9aba721 100644 --- a/boxes/generators/cardbox.py +++ b/boxes/generators/cardbox.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # Copyright (C) 2013-2014 Florian Festi # Copyright (C) 2018 jens persson +# Copyright (C) 2023 Manuel Lohoff # # 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 @@ -15,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from boxes import edges, Boxes +from boxes import edges, Boxes, BoolArg class InsetEdgeSettings(edges.Settings): @@ -42,13 +43,14 @@ class FingerHoleEdgeSettings(edges.Settings): """Settings for FingerHoleEdge""" absolute_params = { "wallheight": 0, + "fingerholedepth": 0, } class FingerHoleEdge(edges.BaseEdge): """An edge with room to get your fingers around cards""" def __call__(self, length, **kw): - depth = self.settings.wallheight-self.thickness-10 + depth = self.settings.fingerholedepth-10 self.edge(length/2-10, tabs=2) self.corner(90) self.edge(depth, tabs=2) @@ -59,107 +61,194 @@ class FingerHoleEdge(edges.BaseEdge): class CardBox(Boxes): - """Box for storage of playing cards""" + """Box for storage of playing cards, with versatile options""" ui_group = "Box" description = """ -#### Building instructions +### Description +Versatile Box for Storage of playing cards. Multiple different styles of storage are supportet, e.g. a flat storage or a trading card deck box style storage. See images for ideas. +#### Building instructions Place inner walls on floor first (if any). Then add the outer walls. Glue the two walls without finger joins to the inside of the side walls. Make sure there is no squeeze out on top, as this is going to form the rail for the lid. -Add the top of the rails to the sides and the grip rail to the lid. - +Add the top of the rails to the sides (front open) or to the back and front (right side open) and the grip rail to the lid. Details of the lid and rails - ![Details](static/samples/CardBox-detail.jpg) - Whole box (early version still missing grip rail on the lid): """ def __init__(self) -> None: Boxes.__init__(self) + self.addSettingsArgs(edges.FingerJointSettings) - self.buildArgParser(h=30) + self.buildArgParser(y=68, h=92, outside=False, sx="65*4") self.argparser.add_argument( - "--cardwidth", action="store", type=float, default=65, - help="Width of the cards") + "--openingdirection", action="store", type=str, default="front", + choices=['front', 'right'], + help="Direction in which the lid slides open. Lid length > Lid width recommended.") self.argparser.add_argument( - "--cardheight", action="store", type=float, default=90, - help="Height of the cards") + "--fingerhole", action="store", type=str, default="regular", + choices=['regular', 'deep', 'custom'], + help="Depth of cutout to grab the cards") self.argparser.add_argument( - "--num", action="store", type=int, default=2, - help="number of compartments") + "--fingerhole_depth", action="store", type=float, default=20, + help="Depth of cutout if fingerhole is set to 'custom'. Disabled otherwise.") + self.argparser.add_argument( + "--add_lidtopper", action="store", type=BoolArg(), default=False, + help="Add an additional lid topper for optical reasons and customisation" + ) @property + def fingerholedepth(self): + if self.fingerhole == 'custom': + return self.fingerhole_depth + elif self.fingerhole == 'regular': + a = self.h/4 + if a < 35: + return a + else: + return 35 + elif self.fingerhole == 'deep': + return self.h-self.thickness-10 + + #inner dimensions of surrounding box (disregarding inlays) + @property + def boxhight(self): + if self.outside: + return self.h - 3 * self.thickness + else: + return self.h + @property def boxwidth(self): - return self.num * (self.cardwidth + self.thickness) + self.thickness + return (len(self.sx) + 1) * self.thickness + sum(self.sx) + @property + def boxdepth(self): + if not self.outside: + if self.openingdirection == 'right': + return self.y + 2 * self.thickness + else: + return self.y + else: + return self.y - 2 * self.thickness def divider_bottom(self): t = self.thickness - c = self.cardwidth - y = self.cardheight + sx = self.sx + y = self.boxdepth - for i in range(1, self.num): - self.fingerHolesAt(0.5*t + (c+t)*i, 0, y, 90) + pos = 0.5 * t + for i in sx[:-1]: + pos += i + t + self.fingerHolesAt(pos, 0, y, 90) def divider_back_and_front(self): t = self.thickness - c = self.cardwidth - y = self.h - for i in range(1, self.num): - self.fingerHolesAt(0.5*t + (c+t)*i, 0, y, 90) + sx = self.sx + y = self.boxhight + + pos = 0.5 * t + for i in sx[:-1]: + pos += i + t + self.fingerHolesAt(pos, 0, y, 90) def render(self): - h = self.h t = self.thickness + h = self.boxhight x = self.boxwidth - y = self.cardheight + y = self.boxdepth + sx = self.sx s = InsetEdgeSettings(thickness=t) p = InsetEdge(self, s) p.char = "a" self.addPart(p) - s = FingerHoleEdgeSettings(thickness=t, wallheight=h) + s = FingerHoleEdgeSettings(thickness=t, wallheight=h, fingerholedepth=self.fingerholedepth) p = FingerHoleEdge(self, s) p.char = "A" self.addPart(p) - with self.saved_context(): - self.rectangularWall(x-t*.2, y, "eeFe", move="right", label="Lid") - self.rectangularWall(x, y, "ffff", callback=[self.divider_bottom], - move="right", label="Bottom") - self.rectangularWall(x, y, "eEEE", move="up only") - self.rectangularWall(x-t*.2, t, "fEeE", move="up", label="Lid Lip") + if self.openingdirection == 'right': + with self.saved_context(): + self.rectangularWall(x, y-t*.2, "eFee", move="right", label="Lid") + self.rectangularWall(x, y, "ffff", callback=[self.divider_bottom], + move="right", label="Bottom") + self.rectangularWall(x, y, "eEEE", move="up only") + self.rectangularWall(x, t, "feee", move="up", label="Lip Front") + self.rectangularWall(x, t, "eefe", move="up", label="Lip Back") - with self.saved_context(): - self.rectangularWall(x, h+t, "FFEF", + with self.saved_context(): + self.rectangularWall(x, h+t, "FfFf", callback=[self.divider_back_and_front], move="right", label="Back") - self.rectangularWall(x, h+t, "FFaF", + self.rectangularWall(x, h+t, "FfFf", callback=[self.divider_back_and_front], - move="right", + move="right", label="Front") - self.rectangularWall(x, h+t, "EEEE", move="up only") + self.rectangularWall(x, h+t, "EEEE", move="up only") + with self.saved_context(): + self.rectangularWall(y, h+t, "FFEF", move="right", label="Outer Side Left") + self.rectangularWall(y, h+t, "FFaF", move="right", label="Outer Side Right") + self.rectangularWall(y, h+t, "fFfF", move="up only") - with self.saved_context(): - self.rectangularWall(y, h+t, "FfFf", move="right", label="Outer Side Left") - self.rectangularWall(y, h+t, "FfFf", move="right", label="Outer Side Right") - self.rectangularWall(y, h+t, "fFfF", move="up only") + with self.saved_context(): + self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Left") + self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Right") + self.rectangularWall(y, h, "eAee", move="up only") - with self.saved_context(): - self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Left") - self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Right") - self.rectangularWall(y, h, "eAee", move="up only") + with self.saved_context(): + self.rectangularWall(y-t*.2, t, "fEeE", move="right", label="Lid Lip") + self.rectangularWall(y, t*2, "efee", move="up only") - with self.saved_context(): - self.rectangularWall(y, t, "eefe", move="right", label="Lip Left") - self.rectangularWall(y, t, "feee", move="right", label="Lip Right") - self.rectangularWall(y, t*2, "efee", move="up only") + for i in range(len(sx) - 1): + self.rectangularWall(h, y, "fAff", move="right", label="Divider") - for i in range(self.num - 1): - self.rectangularWall(h, y, "fAff", move="right", label="Divider") + for c in sx: + self.rectangularWall(c, h, "eeee", move="right", label="Front inlay") + self.rectangularWall(c, h, "eeee", move="right", label="Back inlay") + if self.add_lidtopper: + self.rectangularWall(x, y - 2*t, "eeee", move="right", label="Lid topper") + + elif self.openingdirection == 'front': + with self.saved_context(): + self.rectangularWall(x - t * .2, y, "eeFe", move="right", label="Lid") + self.rectangularWall(x, y, "ffff", callback=[self.divider_bottom], + move="right", label="Bottom") + self.rectangularWall(x, y, "eEEE", move="up only") + self.rectangularWall(x - t * .2, t, "fEeE", move="up", label="Lid Lip") + + with self.saved_context(): + self.rectangularWall(x, h + t, "FFEF", + callback=[self.divider_back_and_front], + move="right", + label="Back") + self.rectangularWall(x, h + t, "FFaF", + callback=[self.divider_back_and_front], + move="right", + label="Front") + self.rectangularWall(x, h + t, "EEEE", move="up only") + + with self.saved_context(): + self.rectangularWall(y, h + t, "FfFf", move="right", label="Outer Side Left") + self.rectangularWall(y, h + t, "FfFf", move="right", label="Outer Side Right") + self.rectangularWall(y, h + t, "fFfF", move="up only") + + with self.saved_context(): + self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Left") + self.rectangularWall(y, h, "Aeee", move="right", label="Inner Side Right") + self.rectangularWall(y, h, "eAee", move="up only") + + with self.saved_context(): + self.rectangularWall(y, t, "eefe", move="right", label="Lip Left") + self.rectangularWall(y, t, "feee", move="right", label="Lip Right") + self.rectangularWall(y, t * 2, "efee", move="up only") + + for i in range(len(sx) - 1): + self.rectangularWall(h, y, "fAff", move="right", label="Divider") + + if self.add_lidtopper: + self.rectangularWall(x, y - 2 * t, "eeee", move="right", label="Lid topper (optional)")