2017-01-19 21:36:43 +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/>.
|
|
|
|
|
2020-12-29 20:44:38 +01:00
|
|
|
import boxes
|
2017-01-19 21:36:43 +01:00
|
|
|
|
|
|
|
|
2020-12-29 20:44:38 +01:00
|
|
|
class RoundedBox(boxes.Boxes):
|
2017-03-06 19:57:50 +01:00
|
|
|
"""Box with vertical edges rounded"""
|
2017-01-19 21:36:43 +01:00
|
|
|
|
2021-09-26 17:04:18 +02:00
|
|
|
description = """
|
|
|
|
Default: edge_style = f Finger Joint:
|
|
|
|
![Finger Joint](static/samples/RoundedBox-2.jpg)
|
|
|
|
|
|
|
|
Alternative: edge_style = h Edge (parallel Finger Joint Holes):
|
|
|
|
![Finger Joint Holes](static/samples/RoundedBox-3.jpg)
|
|
|
|
|
|
|
|
With lid:
|
|
|
|
"""
|
|
|
|
|
2017-02-13 17:31:58 +01:00
|
|
|
ui_group = "FlexBox"
|
|
|
|
|
2017-01-19 21:36:43 +01:00
|
|
|
def __init__(self):
|
2020-12-29 20:44:38 +01:00
|
|
|
boxes.Boxes.__init__(self)
|
|
|
|
self.addSettingsArgs(boxes.edges.FingerJointSettings)
|
2022-01-05 18:29:29 +01:00
|
|
|
self.addSettingsArgs(boxes.edges.DoveTailSettings)
|
2020-12-29 20:44:38 +01:00
|
|
|
self.addSettingsArgs(boxes.edges.FlexSettings)
|
2021-12-17 21:27:06 +01:00
|
|
|
self.buildArgParser("x", "y", "outside", sh="100.0")
|
2017-01-19 21:36:43 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--radius", action="store", type=float, default=15,
|
|
|
|
help="Radius of the corners in mm")
|
2018-08-06 19:08:14 +02:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--wallpieces", action="store", type=int, default=1,
|
2022-03-12 18:24:11 +01:00
|
|
|
choices=[1, 2, 3, 4], help="number of pieces for outer wall")
|
2020-02-28 17:43:48 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--edge_style", action="store",
|
2020-12-29 20:44:38 +01:00
|
|
|
type=boxes.ArgparseEdgeType("fFh"), choices=list("fFh"),
|
2020-02-28 17:43:48 +01:00
|
|
|
default="f",
|
|
|
|
help="edge type for top and bottom edges")
|
2017-01-21 13:52:33 +01:00
|
|
|
self.argparser.add_argument(
|
|
|
|
"--top", action="store", type=str, default="none",
|
|
|
|
choices=["closed", "hole", "lid",],
|
|
|
|
help="style of the top and lid")
|
|
|
|
|
|
|
|
def hole(self):
|
|
|
|
t = self.thickness
|
|
|
|
x, y, r = self.x, self.y, self.radius
|
|
|
|
|
2020-02-28 17:43:48 +01:00
|
|
|
dr = 2*t
|
|
|
|
if self.edge_style == "h":
|
|
|
|
dr = t
|
|
|
|
|
|
|
|
if r > dr:
|
|
|
|
r -= dr
|
2017-01-21 13:52:33 +01:00
|
|
|
else:
|
2020-02-28 17:43:48 +01:00
|
|
|
x += dr - 2*r
|
|
|
|
y += dr - 2*r
|
|
|
|
self.moveTo(dr-r, 0)
|
2017-01-21 13:52:33 +01:00
|
|
|
r = 0
|
|
|
|
|
2020-02-28 17:43:48 +01:00
|
|
|
lx = x - 2*r - 2*dr
|
|
|
|
ly = y - 2*r - 2*dr
|
2017-01-21 13:52:33 +01:00
|
|
|
|
2020-02-28 17:43:48 +01:00
|
|
|
self.moveTo(0, dr)
|
2017-01-21 13:52:33 +01:00
|
|
|
for l in (lx, ly, lx, ly):
|
|
|
|
self.edge(l);
|
|
|
|
self.corner(90, r)
|
2017-01-19 21:36:43 +01:00
|
|
|
|
2021-12-17 21:27:06 +01:00
|
|
|
def cb(self, nr):
|
|
|
|
h = 0.5 * self.thickness
|
|
|
|
|
|
|
|
left, l, right = self.surroundingWallPiece(nr, self.x, self.y, self.radius, self.wallpieces)
|
|
|
|
for dh in self.sh[:-1]:
|
|
|
|
h += dh
|
|
|
|
self.fingerHolesAt(0, h, l, 0)
|
|
|
|
|
2017-01-19 21:36:43 +01:00
|
|
|
def render(self):
|
|
|
|
|
2021-12-17 21:27:06 +01:00
|
|
|
x, y, sh, r = self.x, self.y, self.sh, self.radius
|
2017-01-19 21:36:43 +01:00
|
|
|
|
|
|
|
if self.outside:
|
2017-02-25 15:52:51 +01:00
|
|
|
self.x = x = self.adjustSize(x)
|
|
|
|
self.y = y = self.adjustSize(y)
|
2021-12-17 21:27:06 +01:00
|
|
|
self.sh = sh = self.adjustSize(sh)
|
2017-01-19 21:36:43 +01:00
|
|
|
|
2017-01-21 13:52:33 +01:00
|
|
|
r = self.radius = min(r, y / 2.0)
|
|
|
|
|
2017-01-19 21:36:43 +01:00
|
|
|
t = self.thickness
|
|
|
|
|
2021-12-17 21:27:06 +01:00
|
|
|
h = sum(sh) + t * (len(sh) - 1)
|
2020-02-28 17:43:48 +01:00
|
|
|
es = self.edge_style
|
|
|
|
|
|
|
|
corner_holes = True
|
|
|
|
if self.edge_style == "f":
|
|
|
|
pe = "F"
|
|
|
|
ec = False
|
|
|
|
elif self.edge_style == "F":
|
|
|
|
pe = "f"
|
|
|
|
ec = False
|
|
|
|
else: # "h"
|
|
|
|
pe = "f"
|
|
|
|
corner_holes = True
|
|
|
|
ec = True
|
|
|
|
|
2019-01-12 23:16:11 +01:00
|
|
|
with self.saved_context():
|
2020-02-28 17:43:48 +01:00
|
|
|
self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces,
|
|
|
|
extend_corners=ec, move="right")
|
2021-12-17 21:27:06 +01:00
|
|
|
for dh in self.sh[:-1]:
|
|
|
|
self.roundedPlate(x, y, r, "f", wallpieces=self.wallpieces,
|
|
|
|
extend_corners=False, move="right")
|
2020-02-28 17:43:48 +01:00
|
|
|
self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces,
|
|
|
|
extend_corners=ec, move="right",
|
2019-01-12 23:16:11 +01:00
|
|
|
callback=[self.hole] if self.top != "closed" else None)
|
|
|
|
if self.top == "lid":
|
2020-02-28 17:43:48 +01:00
|
|
|
r_extra = self.edges[self.edge_style].spacing()
|
|
|
|
self.roundedPlate(x+2*r_extra,
|
|
|
|
y+2*r_extra,
|
|
|
|
r+r_extra,
|
|
|
|
"e", wallpieces=self.wallpieces,
|
|
|
|
extend_corners=False, move="right")
|
2019-01-12 23:16:11 +01:00
|
|
|
|
2020-02-28 17:43:48 +01:00
|
|
|
self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces, move="up only")
|
2017-01-19 21:36:43 +01:00
|
|
|
|
2021-12-17 21:27:06 +01:00
|
|
|
self.surroundingWall(x, y, r, h, pe, pe, pieces=self.wallpieces,
|
|
|
|
callback=self.cb)
|
2017-01-19 21:36:43 +01:00
|
|
|
|
|
|
|
|