Add support for a bayonet mount lid to the RegularBox

Adjust BayonetBox to make the pieces usable from outside
This commit is contained in:
Florian Festi 2020-06-23 19:17:05 +02:00
parent 604ea923af
commit 2575cc39df
2 changed files with 39 additions and 11 deletions

View File

@ -33,6 +33,29 @@ class BayonetBox(Boxes):
help="number of locking lugs") help="number of locking lugs")
self.buildArgParser("outside") 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): def lowerCB(self):
d = self.diameter d = self.diameter
r = d / 2 r = d / 2
@ -41,18 +64,14 @@ class BayonetBox(Boxes):
l = self.lugs l = self.lugs
a = 180 / l 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): with self.saved_context():
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) self.lowerLayer()
self.moveTo(0, p) self.moveTo(d/2 - 1.5*t+p, 0, -90)
for i in range(l): 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) 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): def upperCB(self):
d = self.diameter d = self.diameter

View File

@ -15,9 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import * from boxes import *
from boxes.generators.bayonetbox import BayonetBox
import copy import copy
class RegularBox(Boxes): class RegularBox(BayonetBox):
"""Box with regular polygon as base""" """Box with regular polygon as base"""
ui_group = "Box" ui_group = "Box"
@ -34,9 +35,11 @@ class RegularBox(Boxes):
help="number of sides") help="number of sides")
self.argparser.add_argument( self.argparser.add_argument(
"--top", action="store", type=str, default="none", "--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") help="style of the top and lid")
self.lugs=6
def render(self): def render(self):
r, h, n = self.radius, self.h, self.n r, h, n = self.radius, self.h, self.n
@ -74,12 +77,18 @@ class RegularBox(Boxes):
hole=(sh-t)*2) hole=(sh-t)*2)
if self.top == "round lid": if self.top == "round lid":
self.parts.disc(sh*2, move="right") 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") self.regularPolygonWall(corners=n, r=r, edges='F', move="up only")
side = 2 * math.sin(math.radians(180.0/n)) * r side = 2 * math.sin(math.radians(180.0/n)) * r
fingers = self.top in ("hole", "angled hole", "round lid", fingers = self.top in ("hole", "angled hole", "round lid",
"angled lid2") "angled lid2", "bayonet mount")
if n % 2: if n % 2:
for i in range(n): for i in range(n):