Move Lid details and creation into own LidSettings class

Add new ontop and overthetop lid styles

Replace _ChestLid mixin class. Currently supported for UBox, UniversalBox
and ABox

Resolves: #356
This commit is contained in:
Florian Festi 2023-04-06 21:06:28 +02:00
parent 72aeb95bd5
commit 70162bdfb2
5 changed files with 98 additions and 39 deletions

View File

@ -634,6 +634,10 @@ class Boxes:
# HexHoles # HexHoles
self.hexHolesSettings = HexHolesSettings(self.thickness, True, self.hexHolesSettings = HexHolesSettings(self.thickness, True,
**self.edgesettings.get("HexHoles", {})) **self.edgesettings.get("HexHoles", {}))
# Lids
self.lidSettings = lids.LidSettings(self.thickness, True,
**self.edgesettings.get("Lid", {}))
self.lid = lids.Lid(self, self.lidSettings)
# Nuts # Nuts
self.addPart(NutHole(self, None)) self.addPart(NutHole(self, None))

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import * from boxes import *
from boxes.lids import LidSettings
class ABox(Boxes): class ABox(Boxes):
"""A simple Box""" """A simple Box"""
@ -26,11 +27,8 @@ class ABox(Boxes):
def __init__(self) -> None: def __init__(self) -> None:
Boxes.__init__(self) Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings) self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(LidSettings)
self.buildArgParser("x", "y", "h", "outside", "bottom_edge") self.buildArgParser("x", "y", "h", "outside", "bottom_edge")
#self.argparser.add_argument(
# "--lid", action="store", type=str, default="default (none)",
# choices=("default (none)", "chest", "flat"),
# help="additional lid (for straight top_edge only)")
def render(self): def render(self):
x, y, h = self.x, self.y, self.h x, y, h = self.x, self.y, self.h
@ -53,7 +51,7 @@ class ABox(Boxes):
if self.bottom_edge != "e": if self.bottom_edge != "e":
self.rectangularWall(x, y, "ffff", move="up") self.rectangularWall(x, y, "ffff", move="up")
#self.drawAddOnLid(x, y, self.lid) self.lid(x, y)
self.rectangularWall(x, h, [b, sideedge, t3, sideedge], self.rectangularWall(x, h, [b, sideedge, t3, sideedge],
ignore_widths=[1, 6], move="right only") ignore_widths=[1, 6], move="right only")

View File

@ -15,10 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import * from boxes import *
from boxes.lids import _TopEdge, _ChestLid from boxes.lids import _TopEdge, LidSettings
class UBox(_TopEdge, _ChestLid): class UBox(_TopEdge):
"""Box various options for different stypes and lids""" """Box various options for different stypes and lids"""
ui_group = "FlexBox" ui_group = "FlexBox"
@ -27,14 +27,11 @@ class UBox(_TopEdge, _ChestLid):
Boxes.__init__(self) Boxes.__init__(self)
self.addTopEdgeSettings() self.addTopEdgeSettings()
self.addSettingsArgs(edges.FlexSettings) self.addSettingsArgs(edges.FlexSettings)
self.addSettingsArgs(LidSettings)
self.buildArgParser("top_edge", "x", "y", "h") self.buildArgParser("top_edge", "x", "y", "h")
self.argparser.add_argument( self.argparser.add_argument(
"--radius", action="store", type=float, default=30.0, "--radius", action="store", type=float, default=30.0,
help="radius of bottom corners") help="radius of bottom corners")
self.argparser.add_argument(
"--lid", action="store", type=str, default="default (none)",
choices=("default (none)", "chest", "flat"),
help="additional lid")
self.angle = 0 self.angle = 0
def U(self, x, y, r, edge="e", move=None, label=""): def U(self, x, y, r, edge="e", move=None, label=""):
@ -102,6 +99,6 @@ class UBox(_TopEdge, _ChestLid):
self.Uwall(x, y, h, r, [t2, t4], move="up", label=_("wall")) self.Uwall(x, y, h, r, [t2, t4], move="up", label=_("wall"))
self.drawLid(x, h, self.top_edge) self.drawLid(x, h, self.top_edge)
self.drawAddOnLid(x, h, self.lid) self.lid(x, h, self.top_edge)

View File

@ -16,9 +16,9 @@
from boxes import * from boxes import *
from boxes.edges import Bolts from boxes.edges import Bolts
from boxes.lids import _TopEdge, _ChestLid from boxes.lids import _TopEdge
class UniversalBox(_TopEdge, _ChestLid): class UniversalBox(_TopEdge):
"""Box with various options for different styles and lids""" """Box with various options for different styles and lids"""
ui_group = "Box" ui_group = "Box"
@ -28,6 +28,7 @@ class UniversalBox(_TopEdge, _ChestLid):
self.addTopEdgeSettings(roundedtriangle={"outset" : 1}, self.addTopEdgeSettings(roundedtriangle={"outset" : 1},
hinge={"outset" : True}) hinge={"outset" : True})
self.addSettingsArgs(edges.FlexSettings) self.addSettingsArgs(edges.FlexSettings)
self.addSettingsArgs(lids.LidSettings)
self.buildArgParser("top_edge", "bottom_edge", self.buildArgParser("top_edge", "bottom_edge",
"x", "y", "h", "outside") "x", "y", "h", "outside")
self.argparser.add_argument( self.argparser.add_argument(
@ -35,10 +36,6 @@ class UniversalBox(_TopEdge, _ChestLid):
default="finger joints", default="finger joints",
choices=("finger joints", "finger holes"), choices=("finger joints", "finger holes"),
help="connections used for the vertical edges") help="connections used for the vertical edges")
self.argparser.add_argument(
"--lid", action="store", type=str, default="default (none)",
choices=("default (none)", "chest", "flat"),
help="additional lid (for straight top_edge only)")
def top_hole(self, x, y, top_edge): def top_hole(self, x, y, top_edge):
t = self.thickness t = self.thickness
@ -93,7 +90,7 @@ class UniversalBox(_TopEdge, _ChestLid):
lambda:self.top_hole(x, y, self.top_edge)], move="up", label="top hole") lambda:self.top_hole(x, y, self.top_edge)], move="up", label="top hole")
self.set_source_color(Color.BLACK) self.set_source_color(Color.BLACK)
self.drawLid(x, y, self.top_edge, [d2, d3]) self.drawLid(x, y, self.top_edge, [d2, d3])
self.drawAddOnLid(x, y, self.lid) self.lid(x, y, self.top_edge)
self.rectangularWall(x, h, [b, sideedge, tf, sideedge], self.rectangularWall(x, h, [b, sideedge, tf, sideedge],
ignore_widths=[1, 6], ignore_widths=[1, 6],

View File

@ -13,25 +13,101 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import * from boxes import edges, Boxes
class _ChestLid(Boxes): class LidSettings(edges.Settings):
def getR(self, x, angle=0): """Settings for the Lid
Values:
*absolute
* style : "none" : type of lid to create
* relative (in multiples of thickness)
* height : 4.0 : height of the brim (if any)
* play : 0.1 : play when sliding the lid on (if applicable)
"""
absolute_params = {
"style" : ("none", "flat", "chest", "overthetop", "ontop"),
}
relative_params = {
"height" : 4.0,
"play" : 0.1,
}
class Lid:
def __init__(self, boxes, settings):
self.boxes = boxes
self.settings = settings
def __getattr__(self, name):
"""Hack for using unalter code form Boxes class"""
if hasattr(self.settings, name):
return getattr(self.settings, name)
return getattr(self.boxes, name)
def handleCB(self, x, y):
def cb():
pass
return cb
def __call__(self, x, y, edge=None):
t = self.thickness
style = self.settings.style
height = self.height
if style == "flat":
self.rectangularWall(x, y, "eeee", move="right", label="lid bottom")
self.rectangularWall(x, y, "EEEE", move="up", label="lid top")
elif style == "chest":
self.chestSide(x, move="right", label="lid right")
self.chestSide(x, move="up", label="lid left")
self.chestSide(x, move="left only", label="invisible")
self.chestTop(x, y, move="up", label="lid top")
elif style in ("overthetop", "ontop"):
x2 = x
y2 = y
if style == "overthetop":
x2 += 2*t + self.play
y2 += 2*t + self.play
self.rectangularWall(x2, y2, "ffff", move="up")
self.rectangularWall(x2, self.height, "eFFF",
ignore_widths=[1, 2, 5, 6], move="up")
self.rectangularWall(x2, self.height, "eFFF",
ignore_widths=[1, 2, 5, 6], move="up")
self.rectangularWall(y2, self.height, "efFf",
ignore_widths=[1, 2, 5, 6], move="up")
self.rectangularWall(y2, self.height, "efFf",
ignore_widths=[1, 2, 5, 6], move="up")
if style == "ontop":
self.rectangularWall(y - self.play, height + 2*t, "eeee",
move="up")
self.rectangularWall(y - self.play, height + 2*t, "eeee",
move="up")
else:
return False
return True
def getChestR(self, x, angle=0):
t = self.thickness t = self.thickness
d = x - 2*math.sin(math.radians(angle)) * (3*t) d = x - 2*math.sin(math.radians(angle)) * (3*t)
r = d / 2.0 / math.cos(math.radians(angle)) r = d / 2.0 / math.cos(math.radians(angle))
return r return r
def side(self, x, angle=0, move="", label=""): def chestSide(self, x, angle=0, move="", label=""):
if "a" not in self.edges: if "a" not in self.edges:
s = edges.FingerJointSettings(self.thickness, True, s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0) finger=1.0, space=1.0)
s.edgeObjects(self, "aA.") s.edgeObjects(self, "aA.")
t = self.thickness t = self.thickness
r = self.getR(x, angle) r = self.getChestR(x, angle)
if self.move(x+2*t, 0.5*x+3*t, move, True, label=label): if self.move(x+2*t, 0.5*x+3*t, move, True, label=label):
return return
@ -45,14 +121,14 @@ class _ChestLid(Boxes):
self.move(x+2*t, 0.5*x+3*t, move, False, label=label) self.move(x+2*t, 0.5*x+3*t, move, False, label=label)
def top(self, x, y, angle=0, move=None, label=""): def chestTop(self, x, y, angle=0, move=None, label=""):
if "a" not in self.edges: if "a" not in self.edges:
s = edges.FingerJointSettings(self.thickness, True, s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0) finger=1.0, space=1.0)
s.edgeObjects(self, "aA.") s.edgeObjects(self, "aA.")
t = self.thickness t = self.thickness
l = math.radians(180-2*angle) * self.getR(x, angle) l = math.radians(180-2*angle) * self.getChestR(x, angle)
tw = l + 6*t tw = l + 6*t
th = y+2*t th = y+2*t
@ -75,19 +151,6 @@ class _ChestLid(Boxes):
self.move(tw, th, move, label=label) self.move(tw, th, move, label=label)
def drawAddOnLid(self, x, y, style):
if style == "flat":
self.rectangularWall(x, y, "eeee", move="right", label="lid bottom")
self.rectangularWall(x, y, "EEEE", move="up", label="lid top")
elif style == "chest":
self.side(x, move="right", label="lid right")
self.side(x, move="up", label="lid left")
self.side(x, move="left only", label="invisible")
self.top(x, y, move="up", label="lid top")
else:
return False
return True
class _TopEdge(Boxes): class _TopEdge(Boxes):
def addTopEdgeSettings(self, fingerjoint={}, stackable={}, hinge={}, def addTopEdgeSettings(self, fingerjoint={}, stackable={}, hinge={},