Source code for boxes.generators.regularbox

#!/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
#   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 *
from boxes.generators.bayonetbox import BayonetBox

[docs]class RegularBox(BayonetBox): """Box with regular polygon as base""" description = """For short side walls that don't fit a connecting finger reduce *surroundingspaces* and *finger* in the Finger Joint Settings. The lids needs to be glued. For the bayonet lid all outside rings attach to the bottom, all inside rings to the top. """ ui_group = "Box" def __init__(self) -> None: Boxes.__init__(self) self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1) self.buildArgParser("h", "outside") self.argparser.add_argument( "--radius", action="store", type=float, default=50.0, help="inner radius if the box (at the corners)") self.argparser.add_argument( "--n", action="store", type=int, default=5, help="number of sides") self.argparser.add_argument( "--top", action="store", type=str, default="none", choices=["none", "hole", "angled hole", "angled lid", "angled lid2", "round lid", "bayonet mount"], help="style of the top and lid") self.argparser.add_argument( "--alignment_pins", action="store", type=float, default=1.0, help="diameter of the alignment pins for bayonet lid") self.lugs=6 def render(self): r, h, n = self.radius, self.h, self.n if self.outside: r = r = r - self.thickness / math.cos(math.radians(360/(2*n))) if == "none": h = self.adjustSize(h, False) elif "lid" in and != "angled lid": h = self.adjustSize(h) - self.thickness else: h = self.adjustSize(h) t = self.thickness fingerJointSettings = copy.deepcopy(self.edges["f"].settings) fingerJointSettings.setValues(self.thickness, angle=360./n) fingerJointSettings.edgeObjects(self, chars="gGH") r, sh, side = self.regularPolygon(n, radius=r) with self.saved_context(): self.regularPolygonWall(corners=n, r=r, edges='F', move="right") if == "angled lid": self.regularPolygonWall(corners=n, r=r, edges='e', move="right") self.regularPolygonWall(corners=n, r=r, edges='E', move="right") elif in ("angled hole", "angled lid2"): self.regularPolygonWall(corners=n, r=r, edges='F', move="right", callback=[lambda:self.regularPolygonAt( 0, 0, n, h=sh-t)]) if == "angled lid2": self.regularPolygonWall(corners=n, r=r, edges='E', move="right") elif in ("hole", "round lid"): self.regularPolygonWall(corners=n, r=r, edges='F', move="right", hole=(sh-t)*2) if == "round lid":*2, move="right") if == "bayonet mount": self.diameter = 2*sh*2-0.1*t, callback=self.lowerCB, move="right") self.regularPolygonWall(corners=n, r=r, edges='F', callback=[self.upperCB], move="right")*2, move="right") self.regularPolygonWall(corners=n, r=r, edges='F', move="up only") side = 2 * math.sin(math.radians(180.0/n)) * r fingers = in ("hole", "angled hole", "round lid", "angled lid2", "bayonet mount") if n % 2: for i in range(n): self.rectangularWall(side, h, move="right", edges="fgfG" if fingers else "fgeG") else: for i in range(n//2): self.rectangularWall(side, h, move="right", edges="fGfG" if fingers else "fGeG") self.rectangularWall(side, h, move="right", edges="fgfg" if fingers else "fgeg")