2016-12-10 17:27:30 +01:00
|
|
|
#!/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
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from boxes import *
|
2020-06-23 19:17:05 +02:00
|
|
|
from boxes.generators.bayonetbox import BayonetBox
|
2022-12-31 15:52:55 +01:00
|
|
|
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2020-06-23 19:17:05 +02:00
|
|
|
class RegularBox(BayonetBox):
|
2017-03-09 17:45:43 +01:00
|
|
|
"""Box with regular polygon as base"""
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2022-01-11 09:07:09 +01:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "Box"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2016-12-10 17:27:30 +01:00
|
|
|
Boxes.__init__(self)
|
2022-01-11 09:07:09 +01:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
|
2016-12-10 17:27:30 +01:00
|
|
|
self.buildArgParser("h", "outside")
|
|
|
|
self.argparser.add_argument(
|
2019-07-07 21:39:24 +02:00
|
|
|
"--radius_bottom", action="store", type=float, default=50.0,
|
|
|
|
help="inner radius of the box bottom (at the corners)")
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--radius_top", action="store", type=float, default=50.0,
|
|
|
|
help="inner radius of the box top (at the corners)")
|
2016-12-10 17:27:30 +01:00
|
|
|
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",
|
2019-07-07 21:39:24 +02:00
|
|
|
choices=["none", "hole", "angled hole", "angled lid", "angled lid2", "round lid", "bayonet mount", "closed"],
|
2016-12-10 17:27:30 +01:00
|
|
|
help="style of the top and lid")
|
2020-10-13 16:07:31 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--alignment_pins", action="store", type=float, default=1.0,
|
|
|
|
help="diameter of the alignment pins for bayonet lid")
|
2019-07-07 21:39:24 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--bottom", action="store", type=str, default="closed",
|
|
|
|
choices=["none", "closed", "hole", "angled hole", "angled lid", "angled lid2", "round lid"],
|
|
|
|
help="style of the bottom and bottom lid")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2020-06-23 19:17:05 +02:00
|
|
|
self.lugs=6
|
|
|
|
|
2016-12-10 17:27:30 +01:00
|
|
|
def render(self):
|
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
r0, r1, h, n = self.radius_bottom, self.radius_top, self.h, self.n
|
2016-12-10 17:27:30 +01:00
|
|
|
|
|
|
|
if self.outside:
|
2019-07-07 21:39:24 +02:00
|
|
|
r0 = r0 - self.thickness / math.cos(math.radians(360/(2*n)))
|
|
|
|
r1 = r1 - self.thickness / math.cos(math.radians(360/(2*n)))
|
2016-12-17 11:36:26 +01:00
|
|
|
if self.top == "none":
|
|
|
|
h = self.adjustSize(h, False)
|
|
|
|
elif "lid" in self.top and self.top != "angled lid":
|
|
|
|
h = self.adjustSize(h) - self.thickness
|
|
|
|
else:
|
|
|
|
h = self.adjustSize(h)
|
2016-12-10 17:27:30 +01:00
|
|
|
|
|
|
|
t = self.thickness
|
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
|
|
|
|
r0, sh0, side0 = self.regularPolygon(n, radius=r0)
|
|
|
|
r1, sh1, side1 = self.regularPolygon(n, radius=r1)
|
|
|
|
|
|
|
|
# length of side edges
|
|
|
|
#l = (((side0-side1)/2)**2 + (sh0-sh1)**2 + h**2)**0.5
|
|
|
|
l = ((r0-r1)**2 + h**2)**.5
|
|
|
|
# angles of sides -90° aka half of top angle of the full pyramide sides
|
|
|
|
a = math.degrees(math.asin((side1-side0)/2/l))
|
|
|
|
# angle between sides (in boxes style change of travel)
|
|
|
|
phi = 180 - 2 * math.degrees(
|
|
|
|
math.asin(math.cos(math.pi/n) / math.cos(math.radians(a))))
|
|
|
|
|
2018-04-25 21:53:49 +02:00
|
|
|
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
|
2019-07-07 21:39:24 +02:00
|
|
|
fingerJointSettings.setValues(self.thickness, angle=phi)
|
2018-04-25 21:53:49 +02:00
|
|
|
fingerJointSettings.edgeObjects(self, chars="gGH")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
beta = math.degrees(math.atan((sh1-sh0)/h))
|
|
|
|
angle_bottom = 90 + beta
|
|
|
|
angle_top = 90 - beta
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
|
|
|
|
fingerJointSettings.setValues(self.thickness, angle=angle_bottom)
|
|
|
|
fingerJointSettings.edgeObjects(self, chars="yYH")
|
|
|
|
|
|
|
|
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
|
|
|
|
fingerJointSettings.setValues(self.thickness, angle=angle_top)
|
|
|
|
fingerJointSettings.edgeObjects(self, chars="zZH")
|
|
|
|
|
|
|
|
|
|
|
|
def drawTop(r, sh, top_type, joint_type):
|
|
|
|
if top_type == "closed":
|
|
|
|
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right")
|
|
|
|
elif top_type == "angled lid":
|
2019-01-12 23:16:11 +01:00
|
|
|
self.regularPolygonWall(corners=n, r=r, edges='e', move="right")
|
2016-12-17 11:24:47 +01:00
|
|
|
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
|
2019-07-07 21:39:24 +02:00
|
|
|
elif top_type in ("angled hole", "angled lid2"):
|
|
|
|
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right",
|
2019-01-12 23:16:11 +01:00
|
|
|
callback=[lambda:self.regularPolygonAt(
|
|
|
|
0, 0, n, h=sh-t)])
|
2019-07-07 21:39:24 +02:00
|
|
|
if top_type == "angled lid2":
|
2019-01-12 23:16:11 +01:00
|
|
|
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
|
2019-07-07 21:39:24 +02:00
|
|
|
elif top_type in ("hole", "round lid"):
|
|
|
|
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right",
|
2019-01-12 23:16:11 +01:00
|
|
|
hole=(sh-t)*2)
|
2019-07-07 21:39:24 +02:00
|
|
|
if top_type == "round lid":
|
2019-01-12 23:16:11 +01:00
|
|
|
self.parts.disc(sh*2, move="right")
|
2020-06-23 19:17:05 +02:00
|
|
|
if self.top == "bayonet mount":
|
|
|
|
self.diameter = 2*sh
|
2020-10-13 16:07:31 +02:00
|
|
|
self.parts.disc(sh*2-0.1*t, callback=self.lowerCB,
|
|
|
|
move="right")
|
2020-06-23 19:17:05 +02:00
|
|
|
self.regularPolygonWall(corners=n, r=r, edges='F',
|
|
|
|
callback=[self.upperCB], move="right")
|
|
|
|
self.parts.disc(sh*2, move="right")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
with self.saved_context():
|
|
|
|
drawTop(r0, sh0, self.bottom, "yY")
|
|
|
|
drawTop(r1, sh1, self.top, "zZ")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
self.regularPolygonWall(corners=n, r=max(r0, r1), edges='F', move="up only")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
fingers_top = self.top in ("closed", "hole", "angled hole",
|
|
|
|
"round lid", "angled lid2", "bayonet mount")
|
|
|
|
fingers_bottom = self.bottom in ("closed", "hole", "angled hole",
|
|
|
|
"round lid", "angled lid2")
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
t_ = self.edges["G"].startwidth()
|
|
|
|
bottom_edge = ('y' if fingers_bottom else 'e')
|
|
|
|
top_edge = ('z' if fingers_top else 'e')
|
|
|
|
d_top = max(0, -t_ * math.sin(math.radians(a)))
|
|
|
|
d_bottom = max(0.0, t_ * math.sin(math.radians(a)))
|
|
|
|
l -= (d_top + d_bottom)
|
2016-12-10 17:27:30 +01:00
|
|
|
|
2019-07-07 21:39:24 +02:00
|
|
|
if n % 2:
|
|
|
|
e = bottom_edge + 'ege' + top_edge + 'eeGee'
|
|
|
|
borders = [side0, 90-a, d_bottom, 0, l, 0, d_top, 90+a, side1,
|
|
|
|
90+a, d_top, -90, t_, 90, l, 90, t_, -90, d_bottom, 90-a]
|
|
|
|
for i in range(n):
|
|
|
|
self.polygonWall(borders, edge=e, correct_corners=False,
|
|
|
|
move="right")
|
|
|
|
else:
|
|
|
|
borders0 = [side0, 90-a,
|
|
|
|
d_bottom, -90, t_, 90, l, 90, t_, -90, d_top,
|
|
|
|
90+a, side1, 90+a,
|
|
|
|
d_top, -90, t_, 90, l, 90, t_, -90, d_bottom, 90-a]
|
|
|
|
e0 = bottom_edge + 'eeGee' + top_edge + 'eeGee'
|
|
|
|
borders1 = [side0, 90-a, d_bottom, 0, l, 0, d_top, 90+a, side1,
|
|
|
|
90+a, d_top, 0, l, 0, d_bottom, 90-a]
|
|
|
|
e1 = bottom_edge + 'ege' + top_edge + 'ege'
|
|
|
|
for i in range(n//2):
|
|
|
|
self.polygonWall(borders0, edge=e0, correct_corners=False,
|
|
|
|
move="right")
|
|
|
|
self.polygonWall(borders1, edge=e1, correct_corners=False,
|
|
|
|
move="right")
|