Skip to content

Commit

Permalink
Code cleanup and example regenerated
Browse files Browse the repository at this point in the history
  • Loading branch information
JGrzybowski committed Oct 18, 2024
1 parent 43aa46e commit 2476c34
Show file tree
Hide file tree
Showing 2 changed files with 832 additions and 27 deletions.
42 changes: 15 additions & 27 deletions boxes/generators/hobbycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class HobbyCase(Boxes):
ui_group = "Tray"

description = """
The hobby case is defined by units, "cells" of the case.
You define depth, height and widths of the cells.
The hobby case is defined by units, "cells" of the case.
You define depth, height and widths of the cells.
By combining dimensions with number of columns and rows slots for shelves are generated.
Slots can be populated by:
- shelves (horizontal piece of plywood that covers full width and depth of the column. You can put anything on them, but they also provide some structural integrity. It is recommended to have a least one shelve every 2-4 slots (depending on the unit height)
Expand All @@ -44,13 +44,7 @@ def __init__(self) -> None:
self.argparser.add_argument("--shelves_n", action="store", type=argparseSections, default="2:3:2", help="How many shelves should each column have eg. 2:3:2. Use integers only!")
self.argparser.add_argument("--add_rails", action="store", type=boolarg, default=True, help="Should rails be generated for slots unpopulated by shelves?")
self.argparser.add_argument("--add_cover", action="store", type=boolarg, default=True, help="Should cover for the case be generated?")
self.addSettingsArgs(boxes.edges.StackableSettings, angle=90, width=0.0, height=2.0, help="")

@restore
def edgeAt(self, edge, x, y, length, angle=0):
self.moveTo(x, y, angle)
edge = self.edges.get(edge, edge)
edge(length)
self.addSettingsArgs(boxes.edges.StackableSettings, angle=90, width=0.0, height=2.0)

def prepare(self):
self.cols = len(self.unit_w)
Expand All @@ -66,22 +60,20 @@ def prepare(self):

s = self.edgesettings.get("FingerJoint", {})
s["width"] = 2.0
doubleFingerJointSettings = edges.FingerJointSettings(self.thickness, True,
**self.edgesettings.get("FingerJoint", {}))
doubleFingerJointSettings = edges.FingerJointSettings(self.thickness, True, **self.edgesettings.get("FingerJoint", {}))
self.addPart(edges.FingerHoles(self, doubleFingerJointSettings), name="doubleFingerHolesAt")

def topAndBottomHolesCallback(self):
for col in range(1, self.cols):
posx = sum(self.unit_w[:col]) + (col * 2 - 1) * self.thickness
self.doubleFingerHolesAt(posx, 0, self.internal_depth, angle=90)

def topAndBottom(self, move="up"):
def top_and_bottom(self, move="up"):
for name in ["bottom", "top"]:
self.rectangularWall(
self.total_w, self.external_depth, "fFeF",
callback=[self.topAndBottomHolesCallback],
move=move,
label="%s (%ix%i)" % (name, self.total_w, self.external_depth))
self.rectangularWall(self.total_w, self.external_depth, "fFeF",
callback=[self.topAndBottomHolesCallback],
move=move,
label="%s (%ix%i)" % (name, self.total_w, self.external_depth))

def slotsHolesCallback(self):
for row in range(1, self.rows):
Expand All @@ -91,23 +83,21 @@ def slotsHolesCallback(self):
def verticalWall(self, x, y, edges=None, move=None, label=None):
self.rectangularWall(x, y, edges, callback=[self.slotsHolesCallback], move=move, label=label)

def verticalWalls(self, move="up"):
def vertical_walls(self, move="up"):
self.ctx.save()
x_inner = self.internal_depth
x_outer = self.external_depth
y = self.rows * self.unit_h + (self.rows + 1) * self.thickness

self.rectangularWall(x_outer, y,
edges="feff",
self.rectangularWall(x_outer, y, "feff",
callback=[self.slotsHolesCallback],
move="right",
label="left\n(%ix%i)" % (x_outer, y))

for i in range(2 * (self.cols - 1)):
self.verticalWall(x_inner, y, "feff", move="right", label="vertical wall\n(%ix%i)" % (x_inner, y))

self.rectangularWall(x_outer, y,
edges="feff",
self.rectangularWall(x_outer, y, "feff",
callback=[self.slotsHolesCallback],
move="up",
label="right\n(%ix%i)" % (x_outer, y))
Expand Down Expand Up @@ -162,17 +152,15 @@ def base_plate(self, move="up"):
posy = F + 0.5 * self.thickness
self.doubleFingerHolesAt(posx, posy, ty, angle=90)

self.rectangularWall(tx, ty,
["F","F","F","F"],
label="base plate\n(%ix%i)" % (tx, ty), move=move)
self.rectangularWall(tx, ty, "FFFF", label="base plate\n(%ix%i)" % (tx, ty), move=move)

def render(self) -> None:
self.prepare()
self.base_plate()
if self.add_cover:
self.cover()
self.topAndBottom()
self.verticalWalls()
self.top_and_bottom()
self.vertical_walls()
self.shelves()
if self.add_rails:
self.rails()
Loading

0 comments on commit 2476c34

Please sign in to comment.