Skip to content

Commit

Permalink
Move Lid details and creation into own LidSettings class
Browse files Browse the repository at this point in the history
Add new ontop and overthetop lid styles

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

Resolves: florianfesti#356
  • Loading branch information
florianfesti committed Apr 6, 2023
1 parent 72aeb95 commit 70162bd
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 39 deletions.
4 changes: 4 additions & 0 deletions boxes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ def _buildObjects(self):
# HexHoles
self.hexHolesSettings = HexHolesSettings(self.thickness, True,
**self.edgesettings.get("HexHoles", {}))
# Lids
self.lidSettings = lids.LidSettings(self.thickness, True,
**self.edgesettings.get("Lid", {}))
self.lid = lids.Lid(self, self.lidSettings)

# Nuts
self.addPart(NutHole(self, None))
Expand Down
8 changes: 3 additions & 5 deletions boxes/generators/abox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from boxes import *
from boxes.lids import LidSettings

class ABox(Boxes):
"""A simple Box"""
Expand All @@ -26,11 +27,8 @@ class ABox(Boxes):
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(LidSettings)
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):
x, y, h = self.x, self.y, self.h
Expand All @@ -53,7 +51,7 @@ def render(self):

if self.bottom_edge != "e":
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],
ignore_widths=[1, 6], move="right only")
Expand Down
11 changes: 4 additions & 7 deletions boxes/generators/ubox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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"""

ui_group = "FlexBox"
Expand All @@ -27,14 +27,11 @@ def __init__(self) -> None:
Boxes.__init__(self)
self.addTopEdgeSettings()
self.addSettingsArgs(edges.FlexSettings)
self.addSettingsArgs(LidSettings)
self.buildArgParser("top_edge", "x", "y", "h")
self.argparser.add_argument(
"--radius", action="store", type=float, default=30.0,
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

def U(self, x, y, r, edge="e", move=None, label=""):
Expand Down Expand Up @@ -102,6 +99,6 @@ def render(self):
self.Uwall(x, y, h, r, [t2, t4], move="up", label=_("wall"))

self.drawLid(x, h, self.top_edge)
self.drawAddOnLid(x, h, self.lid)
self.lid(x, h, self.top_edge)


11 changes: 4 additions & 7 deletions boxes/generators/universalbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

from boxes import *
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"""

ui_group = "Box"
Expand All @@ -28,17 +28,14 @@ def __init__(self) -> None:
self.addTopEdgeSettings(roundedtriangle={"outset" : 1},
hinge={"outset" : True})
self.addSettingsArgs(edges.FlexSettings)
self.addSettingsArgs(lids.LidSettings)
self.buildArgParser("top_edge", "bottom_edge",
"x", "y", "h", "outside")
self.argparser.add_argument(
"--vertical_edges", action="store", type=str,
default="finger joints",
choices=("finger joints", "finger holes"),
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):
t = self.thickness
Expand Down Expand Up @@ -93,7 +90,7 @@ def render(self):
lambda:self.top_hole(x, y, self.top_edge)], move="up", label="top hole")
self.set_source_color(Color.BLACK)
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],
ignore_widths=[1, 6],
Expand Down
103 changes: 83 additions & 20 deletions boxes/lids.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,101 @@
# 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 *
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
d = x - 2*math.sin(math.radians(angle)) * (3*t)

r = d / 2.0 / math.cos(math.radians(angle))
return r

def side(self, x, angle=0, move="", label=""):
def chestSide(self, x, angle=0, move="", label=""):
if "a" not in self.edges:
s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0)
s.edgeObjects(self, "aA.")

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):
return

Expand All @@ -45,14 +121,14 @@ def side(self, x, angle=0, move="", 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:
s = edges.FingerJointSettings(self.thickness, True,
finger=1.0, space=1.0)
s.edgeObjects(self, "aA.")

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
th = y+2*t
Expand All @@ -75,19 +151,6 @@ def top(self, x, y, angle=0, move=None, 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):

def addTopEdgeSettings(self, fingerjoint={}, stackable={}, hinge={},
Expand Down

0 comments on commit 70162bd

Please sign in to comment.