2016-07-11 23:01:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-03-16 18:26:12 +01:00
|
|
|
# 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/>.
|
2013-12-07 17:40:08 +01:00
|
|
|
|
2022-07-28 22:27:48 +02:00
|
|
|
from boxes import Boxes, edges, Color, ArgparseEdgeType
|
2023-04-07 21:32:28 +02:00
|
|
|
from boxes.lids import _TopEdge, LidSettings
|
2013-12-07 17:40:08 +01:00
|
|
|
|
2022-07-28 22:27:48 +02:00
|
|
|
class DrillBox(_TopEdge):
|
2021-05-16 20:35:01 +02:00
|
|
|
"""A parametrized box for drills"""
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2023-04-01 13:02:53 +02:00
|
|
|
description = """![Multiple DrillBoxes](static/samples/DrillBoxes.jpg) """
|
|
|
|
|
2021-12-12 17:51:04 +01:00
|
|
|
ui_group = "Tray"
|
|
|
|
|
2023-01-08 19:41:02 +01:00
|
|
|
def __init__(self) -> None:
|
2016-03-03 13:27:22 +01:00
|
|
|
Boxes.__init__(self)
|
2022-07-28 22:27:48 +02:00
|
|
|
|
2021-12-12 17:19:13 +01:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings,
|
|
|
|
space=3, finger=3, surroundingspaces=1)
|
2022-07-28 22:27:48 +02:00
|
|
|
self.addSettingsArgs(edges.RoundedTriangleEdgeSettings, outset=1)
|
|
|
|
self.addSettingsArgs(edges.StackableSettings)
|
|
|
|
self.addSettingsArgs(edges.MountingSettings)
|
2023-04-07 21:32:28 +02:00
|
|
|
self.addSettingsArgs(LidSettings)
|
2022-07-28 22:27:48 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--top_edge", action="store",
|
|
|
|
type=ArgparseEdgeType("eStG"), choices=list("eStG"),
|
|
|
|
default="e", help="edge type for top edge")
|
2021-12-12 17:44:18 +01:00
|
|
|
self.buildArgParser(sx="25*3", sy="60*4", sh="5:25:10",
|
|
|
|
bottom_edge="h")
|
2021-05-16 20:35:01 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--holes",
|
|
|
|
action="store",
|
|
|
|
type=int,
|
|
|
|
default=3,
|
|
|
|
help="Number of holes for each size",
|
|
|
|
)
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--firsthole",
|
|
|
|
action="store",
|
|
|
|
type=float,
|
|
|
|
default=1.0,
|
|
|
|
help="Smallest hole",
|
|
|
|
)
|
|
|
|
self.argparser.add_argument(
|
|
|
|
"--holeincrement",
|
|
|
|
action="store",
|
|
|
|
type=float,
|
|
|
|
default=.5,
|
|
|
|
help="increment between holes",
|
|
|
|
)
|
2013-12-07 17:40:08 +01:00
|
|
|
|
2021-12-12 17:44:18 +01:00
|
|
|
def sideholes(self, l):
|
|
|
|
t = self.thickness
|
|
|
|
h = -0.5 * t
|
|
|
|
for d in self.sh[:-1]:
|
|
|
|
h += d + t
|
|
|
|
self.fingerHolesAt(0, h, l, angle=0)
|
2013-12-07 17:40:08 +01:00
|
|
|
|
|
|
|
|
2021-05-16 20:35:01 +02:00
|
|
|
def drillholes(self, description=False):
|
|
|
|
y = 0
|
|
|
|
d = self.firsthole
|
|
|
|
for dy in self.sy:
|
|
|
|
x = 0
|
|
|
|
for dx in self.sx:
|
|
|
|
iy = dy / self.holes
|
|
|
|
for k in range(self.holes):
|
2021-11-08 11:29:13 +01:00
|
|
|
self.hole(x + dx / 2, y + (k + 0.5) * iy, d=d + 0.05)
|
2021-05-16 20:35:01 +02:00
|
|
|
if description:
|
2021-06-01 21:59:21 +02:00
|
|
|
self.rectangularHole(x + dx / 2, y + dy / 2, dx - 2, dy - 2, color=Color.ETCHING)
|
2021-05-16 20:35:01 +02:00
|
|
|
self.text(
|
|
|
|
"%.1f" % d,
|
|
|
|
x + 2,
|
|
|
|
y + 2,
|
|
|
|
270,
|
|
|
|
align="right",
|
|
|
|
fontsize=6,
|
2021-06-01 21:59:21 +02:00
|
|
|
color=Color.ETCHING,
|
2021-05-16 20:35:01 +02:00
|
|
|
)
|
|
|
|
# TODO: make the fontsize dynamic to make the text fit in all cases
|
|
|
|
d += self.holeincrement
|
|
|
|
x += dx
|
|
|
|
y += dy
|
2014-01-21 22:44:22 +01:00
|
|
|
|
2013-12-07 17:40:08 +01:00
|
|
|
def render(self):
|
2021-05-16 20:35:01 +02:00
|
|
|
x = sum(self.sx)
|
|
|
|
y = sum(self.sy)
|
2021-12-12 17:44:18 +01:00
|
|
|
|
|
|
|
h = sum(self.sh) + self.thickness * (len(self.sh)-1)
|
2021-12-12 17:25:01 +01:00
|
|
|
b = self.bottom_edge
|
2022-07-28 22:27:48 +02:00
|
|
|
t1, t2, t3, t4 = self.topEdges(self.top_edge)
|
2013-12-07 17:40:08 +01:00
|
|
|
|
2021-12-12 17:25:01 +01:00
|
|
|
self.rectangularWall(
|
2022-07-28 22:27:48 +02:00
|
|
|
x, h, [b, "f", t1, "F"],
|
2022-07-28 22:33:33 +02:00
|
|
|
ignore_widths=[1, 6],
|
2021-12-12 17:44:18 +01:00
|
|
|
callback=[lambda: self.sideholes(x)], move="right")
|
2021-12-12 17:25:01 +01:00
|
|
|
self.rectangularWall(
|
2022-07-28 22:27:48 +02:00
|
|
|
y, h, [b, "f", t2, "F"], callback=[lambda: self.sideholes(y)],
|
2022-07-28 22:33:33 +02:00
|
|
|
ignore_widths=[1, 6],
|
2022-07-28 22:27:48 +02:00
|
|
|
move="up")
|
2021-12-12 17:25:01 +01:00
|
|
|
self.rectangularWall(
|
2022-07-28 22:33:33 +02:00
|
|
|
y, h, [b, "f", t3, "F"], callback=[lambda: self.sideholes(y)],
|
|
|
|
ignore_widths=[1, 6])
|
2021-12-12 17:25:01 +01:00
|
|
|
self.rectangularWall(
|
2022-07-28 22:27:48 +02:00
|
|
|
x, h, [b, "f", t4, "F"],
|
2022-07-28 22:33:33 +02:00
|
|
|
ignore_widths=[1, 6],
|
2021-12-12 17:44:18 +01:00
|
|
|
callback=[lambda: self.sideholes(x)], move="left up")
|
2021-12-12 17:25:01 +01:00
|
|
|
if b != "e":
|
|
|
|
self.rectangularWall(x, y, "ffff", move="right")
|
2021-12-12 17:44:18 +01:00
|
|
|
for d in self.sh[:-2]:
|
|
|
|
self.rectangularWall(
|
|
|
|
x, y, "ffff", callback=[self.drillholes], move="right")
|
|
|
|
self.rectangularWall(
|
|
|
|
x, y, "ffff",
|
|
|
|
callback=[lambda: self.drillholes(description=True)],
|
|
|
|
move="right")
|
2023-04-07 21:32:28 +02:00
|
|
|
self.lid(x, y, self.top_edge)
|