From 2575cc39df78d13d74eee3523e88800f17a52bf6 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Tue, 23 Jun 2020 19:17:05 +0200 Subject: [PATCH] Add support for a bayonet mount lid to the RegularBox Adjust BayonetBox to make the pieces usable from outside --- boxes/generators/bayonetbox.py | 35 ++++++++++++++++++++++++++-------- boxes/generators/regularbox.py | 15 ++++++++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/boxes/generators/bayonetbox.py b/boxes/generators/bayonetbox.py index 990568a..6f2b674 100644 --- a/boxes/generators/bayonetbox.py +++ b/boxes/generators/bayonetbox.py @@ -33,6 +33,29 @@ class BayonetBox(Boxes): help="number of locking lugs") self.buildArgParser("outside") + def lowerLayer(self, asPart=False, move=None): + d = self.diameter + r = d / 2 + t = self.thickness + p = 0.05*t + l = self.lugs + + a = 180 / l + + if asPart: + if self.move(d, d, move, True): + return + self.moveTo(d/2, d/2) + + self.hole(0, 0, r=d/2 - 2.5*t) + self.moveTo(d/2 - 1.5*t, 0, -90) + + for i in range(l): + self.polyline(0, (-4/3*a, r-1.5*t), 0, 90, 0.5*t, -90, 0, (-2/3*a, r-t), 0, -90, 0.5*t, 90) + + if asPart: + self.move(d, d, move) + def lowerCB(self): d = self.diameter r = d / 2 @@ -41,18 +64,14 @@ class BayonetBox(Boxes): l = self.lugs a = 180 / l - - self.hole(0, 0, r=d/2 - 2.5*t) - self.moveTo(d/2 - 1.5*t, 0, -90) - for i in range(l): - self.polyline(0, (-4/3*a, r-1.5*t), 0, 90, 0.5*t, -90, 0, (-2/3*a, r-t), 0, -90, 0.5*t, 90) + with self.saved_context(): + self.lowerLayer() - self.moveTo(0, p) - + self.moveTo(d/2 - 1.5*t+p, 0, -90) for i in range(l): self.polyline(0, (-2/3*a, r-1.5*t+p), 0, 90, 0.5*t, -90, 0, (-4/3*a, r-t+p), 0, -90, 0.5*t, 90) - + def upperCB(self): d = self.diameter diff --git a/boxes/generators/regularbox.py b/boxes/generators/regularbox.py index 559b1ef..53504c4 100644 --- a/boxes/generators/regularbox.py +++ b/boxes/generators/regularbox.py @@ -15,9 +15,10 @@ # along with this program. If not, see . from boxes import * +from boxes.generators.bayonetbox import BayonetBox import copy -class RegularBox(Boxes): +class RegularBox(BayonetBox): """Box with regular polygon as base""" ui_group = "Box" @@ -34,9 +35,11 @@ class RegularBox(Boxes): 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"], + choices=["none", "hole", "angled hole", "angled lid", "angled lid2", "round lid", "bayonet mount"], help="style of the top and lid") + self.lugs=6 + def render(self): r, h, n = self.radius, self.h, self.n @@ -74,12 +77,18 @@ class RegularBox(Boxes): hole=(sh-t)*2) if self.top == "round lid": self.parts.disc(sh*2, move="right") + if self.top == "bayonet mount": + self.diameter = 2*sh + self.lowerLayer(asPart=True, move="right") + self.regularPolygonWall(corners=n, r=r, edges='F', + callback=[self.upperCB], move="right") + self.parts.disc(sh*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 = self.top in ("hole", "angled hole", "round lid", - "angled lid2") + "angled lid2", "bayonet mount") if n % 2: for i in range(n):