Create generator for wall mounted (spice) rack

This commit is contained in:
Phillip Thelen 2023-07-20 22:45:02 +02:00
parent 63ff58544d
commit 6b6dea2611
1 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
# Copyright (C) 2013-2023 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/>.
from boxes import *
from functools import partial
class WallRack(Boxes):
"""Rack spices or other things to be mounted on a wall"""
ui_group = "Shelf"
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.0)
self.buildArgParser(x=200, y=50, sh="100*3", outside=False)
self.argparser.add_argument(
"--top_edge", action="store",
type=ArgparseEdgeType("eEGy"), choices=list("eEGy"),
default="e", help="edge type for top edge")
self.argparser.add_argument("--full_height_top", type=boolarg, default=True, help="Add full height of topmost rack to the back panel")
self.argparser.add_argument(
"--wall_height", action="store", type=float, default=20.0,
help="height of walls")
self.argparser.add_argument(
"--back_height", action="store", type=float, default=1.5,
help="height of the back as fraction of the front height")
self.argparser.add_argument(
"--flat_bottom", type=boolarg, default=False, help="Make bottom Flat, so that the rack can also stand")
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")
def generate_shelves(self, x, y, front_height, back_height):
for i in range(len(self.sh)):
self.rectangularWall(x, y, "ffff", move="up", label=f"shelf {i+1}")
self.rectangularWall(x, front_height, "Ffef", move="up", label=f"front lip {i+1}")
self.trapezoidWall(y, front_height, back_height, "FfeF", move="right", label=f"right lip {i+1}")
self.trapezoidWall(y, front_height, back_height, "FfeF", move="up", label=f"left lip {i+1}")
self.move(y + self.thickness*2, back_height, "left", before=True)
#Generate finger holes for back part
def generate_finger_holes(self, x, back_height):
t = self.thickness
offset = -self.sh[0] + (0 if self.flat_bottom else t)
for i in self.sh:
offset += i
pos_y = offset
self.fingerHolesAt(t*0.5, pos_y, x, 0)
pos_y += t*0.5
self.fingerHolesAt(0, pos_y, back_height, 90)
self.fingerHolesAt(x+t, pos_y, back_height, 90)
def render(self):
x, y, front_height = self.x, self.y, self.wall_height
back_height = front_height * self.back_height
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
front_height = self.adjustSize(front_height)
back_height = self.adjustSize(back_height)
if self.full_height_top:
total_height = sum(self.sh)
else:
total_height = sum(self.sh[:-1]) + back_height
self.rectangularWall(x+self.thickness, total_height, "EE" + self.top_edge + "E",
callback=[partial(self.generate_finger_holes, x, back_height)], label="back wall", move="right")
self.generate_shelves(x, y, front_height, back_height)