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")
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
@ -42,14 +65,10 @@ class BayonetBox(Boxes):
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)
self.moveTo(0, p)
with self.saved_context():
self.lowerLayer()
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)

View File

@ -15,9 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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):