2019-03-23 12:34:45 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (C) 2013-2019 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 *
|
2023-04-17 22:10:29 +02:00
|
|
|
from boxes.edges import Edge, CompoundEdge
|
2019-03-23 12:34:45 +01:00
|
|
|
|
|
|
|
class USlotEdge(Edge):
|
|
|
|
|
|
|
|
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
|
|
|
|
l = length
|
2023-04-17 22:10:29 +02:00
|
|
|
o = self.settings
|
|
|
|
d = length * (1-o/100) / 2
|
2019-10-19 21:42:44 +02:00
|
|
|
r = min(3*self.thickness, (l-2*d)/2)
|
|
|
|
self.edges["f"](d)
|
|
|
|
self.polyline(0, 90, 0, (-90, r), l-2*d-2*r, (-90, r), 0, 90)
|
|
|
|
self.edges["f"](d)
|
|
|
|
|
2023-01-23 20:08:04 +01:00
|
|
|
def margin(self) -> float:
|
2019-11-04 08:52:26 +01:00
|
|
|
return self.edges["f"].margin()
|
|
|
|
|
2019-10-19 21:42:44 +02:00
|
|
|
class HalfStackableEdge(edges.StackableEdge):
|
|
|
|
|
|
|
|
char = 'H'
|
|
|
|
|
|
|
|
def __call__(self, length, **kw):
|
|
|
|
s = self.settings
|
|
|
|
r = s.height / 2.0 / (1 - math.cos(math.radians(s.angle)))
|
|
|
|
l = r * math.sin(math.radians(s.angle))
|
|
|
|
p = 1 if self.bottom else -1
|
|
|
|
|
|
|
|
if self.bottom:
|
|
|
|
self.boxes.fingerHolesAt(0, s.height + self.settings.holedistance + 0.5 * self.boxes.thickness,
|
|
|
|
length, 0)
|
|
|
|
|
|
|
|
self.boxes.edge(s.width, tabs=1)
|
|
|
|
self.boxes.corner(p * s.angle, r)
|
|
|
|
self.boxes.corner(-p * s.angle, r)
|
|
|
|
self.boxes.edge(length - 1 * s.width - 2 * l)
|
|
|
|
|
2023-01-23 20:08:04 +01:00
|
|
|
def endwidth(self) -> float:
|
2019-10-19 21:42:44 +02:00
|
|
|
return self.settings.holedistance + self.settings.thickness
|
2019-03-23 12:34:45 +01:00
|
|
|
|
|
|
|
class NotesHolder(Boxes):
|
|
|
|
"""Box for holding a stack of paper, coasters etc"""
|
|
|
|
|
|
|
|
ui_group = "Box"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2019-03-23 12:34:45 +01:00
|
|
|
Boxes.__init__(self)
|
2019-10-19 21:42:44 +02:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
|
2019-03-23 12:34:45 +01:00
|
|
|
self.addSettingsArgs(edges.StackableSettings)
|
2023-04-17 22:10:29 +02:00
|
|
|
self.buildArgParser(sx="78", y=78, h=35, bottom_edge="s")
|
2019-03-23 12:34:45 +01:00
|
|
|
self.argparser.add_argument(
|
2019-10-19 21:42:44 +02:00
|
|
|
"--opening", action="store", type=float, default=40,
|
|
|
|
help="percent of front that's open")
|
2019-03-23 12:34:45 +01:00
|
|
|
|
2023-04-17 22:10:29 +02:00
|
|
|
def fingerHoleCB(self, lengths, height, posy=0.0):
|
|
|
|
def CB():
|
|
|
|
t = self.thickness
|
|
|
|
px = -0.5 * t
|
|
|
|
for x in lengths[:-1]:
|
|
|
|
px += x + t
|
|
|
|
self.fingerHolesAt(px, posy, height, 90)
|
|
|
|
return CB
|
|
|
|
|
2019-03-23 12:34:45 +01:00
|
|
|
def render(self):
|
2023-04-17 22:10:29 +02:00
|
|
|
sx, y, h = self.sx, self.y, self.h
|
2019-03-23 12:34:45 +01:00
|
|
|
t = self.thickness
|
|
|
|
|
2023-04-17 22:10:29 +02:00
|
|
|
x = sum(sx) + (len(sx) - 1) * t
|
|
|
|
|
2019-10-19 21:42:44 +02:00
|
|
|
o = max(0, min(self.opening, 100))
|
|
|
|
sides = x * (1-o/100) / 2
|
2019-03-23 12:34:45 +01:00
|
|
|
|
|
|
|
b = self.edges.get(self.bottom_edge, self.edges["F"])
|
2019-10-19 21:42:44 +02:00
|
|
|
if self.bottom_edge == "s":
|
|
|
|
b2 = HalfStackableEdge(self, self.edges["s"].settings,
|
|
|
|
self.edges["f"].settings)
|
2023-04-17 22:10:29 +02:00
|
|
|
b3 = self.edges["h"]
|
2019-10-19 21:42:44 +02:00
|
|
|
else:
|
|
|
|
b2 = b
|
2023-04-17 22:10:29 +02:00
|
|
|
b3 = b
|
|
|
|
|
|
|
|
b4 = Edge(self, None)
|
|
|
|
b4.startwidth = lambda: b3.startwidth()
|
2019-03-23 12:34:45 +01:00
|
|
|
|
|
|
|
with self.saved_context():
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(y, h, [b, "F", "e", "F"],
|
|
|
|
ignore_widths=[1, 6], move="right")
|
2023-04-17 22:10:29 +02:00
|
|
|
# front walls
|
2019-10-19 21:42:44 +02:00
|
|
|
if self.opening == 0.0:
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(x, h, [b, "f", "e", "f"],
|
|
|
|
ignore_widths=[1, 6], move="right")
|
2019-10-19 21:42:44 +02:00
|
|
|
else:
|
2023-04-17 22:10:29 +02:00
|
|
|
self.rectangularWall(sx[0] * (1-o/100) / 2, h,
|
|
|
|
[b2, "e", "e", "f"],
|
2019-12-14 14:18:38 +01:00
|
|
|
ignore_widths=[1, 6], move="right")
|
2023-04-17 22:10:29 +02:00
|
|
|
for ix in range(len(sx)-1):
|
|
|
|
left = sx[ix] * (1-o/100) / 2
|
|
|
|
right = sx[ix+1] * (1-o/100) / 2
|
|
|
|
h_e = t
|
|
|
|
bottom_edge = CompoundEdge(
|
|
|
|
self, [b3, b4, b3], [left, t, right])
|
|
|
|
self.rectangularWall(
|
|
|
|
left+right+t, h,
|
|
|
|
[bottom_edge, "e", "e", "e"],
|
|
|
|
callback=[lambda: self.fingerHolesAt(left+t/2, 0, h, 90)],
|
|
|
|
move="right")
|
|
|
|
|
|
|
|
self.rectangularWall(sx[-1] * (1-o/100) / 2, h,
|
|
|
|
[b2, "e", "e", "f"],
|
2019-12-14 14:18:38 +01:00
|
|
|
ignore_widths=[1, 6], move="right mirror")
|
2019-03-23 12:34:45 +01:00
|
|
|
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(x, h, [b, "F", "e", "F"],
|
|
|
|
ignore_widths=[1, 6], move="up only")
|
2019-03-23 12:34:45 +01:00
|
|
|
|
2019-11-04 08:52:26 +01:00
|
|
|
with self.saved_context():
|
2019-12-14 14:18:38 +01:00
|
|
|
self.rectangularWall(y, h, [b, "F", "e", "F"], ignore_widths=[1, 6], move="right")
|
2023-04-17 22:10:29 +02:00
|
|
|
self.rectangularWall(x, h, [b, "f", "e", "f"],
|
|
|
|
callback=[self.fingerHoleCB(sx, h)],
|
|
|
|
ignore_widths=[1, 6], move="right")
|
2019-11-04 08:52:26 +01:00
|
|
|
self.rectangularWall(y, h, [b, "F", "e", "F"], move="up only")
|
2019-03-23 12:34:45 +01:00
|
|
|
|
2019-10-19 21:42:44 +02:00
|
|
|
if self.bottom_edge != "e":
|
2019-11-04 08:52:26 +01:00
|
|
|
if self.opening == 0.0:
|
|
|
|
self.rectangularWall(x, y, ["f", "f", "f", "f"], move="up")
|
|
|
|
else:
|
2023-04-17 22:10:29 +02:00
|
|
|
u_edge = USlotEdge(self, o)
|
|
|
|
print([l for x in sx for l in (x, t)])
|
|
|
|
front = CompoundEdge(
|
|
|
|
self,
|
|
|
|
([u_edge, "e"]*len(sx))[:-1],
|
|
|
|
([l for x in sx for l in (x, t)])[:-1])
|
|
|
|
self.rectangularWall(x, y, [front, "f", "f", "f"],
|
|
|
|
callback=[self.fingerHoleCB(sx, y)],
|
|
|
|
move="up")
|
|
|
|
# innner walls
|
|
|
|
for i in range(len(sx)-1):
|
|
|
|
self.rectangularWall(
|
|
|
|
y, h, ("e" if self.bottom_edge=="e" else "f") + "fef",
|
|
|
|
move="right")
|