id int64 0 458k | file_name stringlengths 4 119 | file_path stringlengths 14 227 | content stringlengths 24 9.96M | size int64 24 9.96M | language stringclasses 1 value | extension stringclasses 14 values | total_lines int64 1 219k | avg_line_length float64 2.52 4.63M | max_line_length int64 5 9.91M | alphanum_fraction float64 0 1 | repo_name stringlengths 7 101 | repo_stars int64 100 139k | repo_forks int64 0 26.4k | repo_open_issues int64 0 2.27k | repo_license stringclasses 12 values | repo_extraction_date stringclasses 433 values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
25,600 | organpipe.py | florianfesti_boxes/boxes/generators/organpipe.py | # Copyright (C) 2013-2018 Florian Festi
#
# Based on pipecalc by Christian F. Coors
# https://github.com/ccoors/pipecalc
#
# 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 math import *
from boxes import *
pitches = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#' ,'b']
pressure_units = { 'Pa' : 1.0,
'mBar' : 100.,
'mmHg' : 133.322,
'mmH2O' : 9.80665,
}
class OrganPipe(Boxes): # Change class name!
"""Rectangular organ pipe based on pipecalc"""
ui_group = "Unstable" # see ./__init__.py for names
def getFrequency(self, pitch, octave, base_freq=440):
steps = pitches.index(pitch) + (octave-4)*12 - 9
return base_freq * 2**(steps/12.)
def getRadius(self, pitch, octave, intonation):
steps = pitches.index(pitch) + (octave-2)*12 + intonation
return 0.5 * 0.15555 * 0.957458**steps
def getAirSpeed(self, wind_pressure, air_density=1.2):
return (2.0 * (wind_pressure / air_density))**.5
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, finger=3.0, space=3.0,
surroundingspaces=1.0)
"""
air_temperature: f64,
"""
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--pitch", action="store", type=str, default="c",
choices=pitches,
help="pitch")
self.argparser.add_argument(
"--octave", action="store", type=int, default=2,
help="Octave in International Pitch Notation (2 == C)")
self.argparser.add_argument(
"--intonation", action="store", type=float, default=2.0,
help="Intonation Number. 2 for max. efficiency, 3 max.")
self.argparser.add_argument(
"--mouthratio", action="store", type=float, default=0.25,
help="mouth to circumference ratio (0.1 to 0.45). Determines the width to depth ratio")
self.argparser.add_argument(
"--cutup", action="store", type=float, default=0.3,
help="Cutup to mouth ratio")
self.argparser.add_argument(
"--mensur", action="store", type=int, default=0,
help="Distance in halftones in the Normalmensur by Töpfer")
self.argparser.add_argument(
"--windpressure", action="store", type=float, default=588.4,
help="uses unit selected below")
self.argparser.add_argument(
"--windpressure_units", action="store", type=str, default='Pa',
choices=pressure_units.keys(),
help="in Pa")
self.argparser.add_argument(
"--stopped", action="store", type=boolarg, default=False,
help="pipe is closed at the top")
def render(self):
t = self.thickness
f = self.getFrequency(self.pitch, self.octave, 440)
self.windpressure *= pressure_units.get(self.windpressure_units, 1.0)
speed_of_sound = 343.6 # XXX util::speed_of_sound(self.air_temperature); // in m/s
air_density = 1.2
air_speed = self.getAirSpeed(self.windpressure, air_density)
i = self.intonation
radius = self.getRadius(self.pitch, self.octave, i) * 1000
cross_section = pi * radius**2
circumference = pi * radius * 2.0
mouth_width = circumference * self.mouthratio
mouth_height = mouth_width * self.cutup
mouth_area = mouth_height * mouth_width
pipe_depth = cross_section / mouth_width
base_length = max(mouth_width, pipe_depth)
jet_thickness = (f**2 * i**2 * (.01 * mouth_height)**3) / air_speed**2
sound_power = (0.001 * pi * (air_density / speed_of_sound) * f**2
* (1.7 * (jet_thickness * speed_of_sound * f * mouth_area * mouth_area**.5)**.5)**2)
air_consumption_rate = air_speed * mouth_width * jet_thickness * 1E6
wavelength = speed_of_sound / f * 1000
if self.stopped:
theoretical_resonator_length = wavelength / 4.0
resonator_length = (-0.73 * (f * cross_section *1E-6 - 0.342466 * speed_of_sound * mouth_area**.5 * 1E-3)
/ (f * mouth_area**.5 * 1E-3))
else:
theoretical_resonator_length = wavelength / 2.0
resonator_length = (-0.73 * (f * cross_section * 1E-6 + 0.465753 * f * mouth_area**.5 * cross_section**.5 * 1E-6 - 0.684932 * speed_of_sound * mouth_area**.5 * 1E-3)
/ (f * mouth_area**.5 * 1E-3)) * 1E3
air_hole_diameter = 2.0 * ((mouth_width * jet_thickness * 10.0)**.5 / pi)
total_length = resonator_length + base_length
e = ["f", "e",
edges.CompoundEdge(self, "fef", (resonator_length - mouth_height - 10*t, mouth_height + 10*t, base_length)), "f"]
self.rectangularWall(total_length, pipe_depth, e, callback=[
lambda: self.fingerHolesAt(base_length-0.5*t, 0, pipe_depth-jet_thickness)],
move="up")
self.rectangularWall(total_length, pipe_depth, e, callback=[
lambda: self.fingerHolesAt(base_length-0.5*t, 0, pipe_depth-jet_thickness)],
move="up")
self.rectangularWall(total_length, mouth_width, "FeFF", callback=[
lambda: self.fingerHolesAt(base_length-0.5*t, 0, mouth_width)],
move="up")
e = [edges.CompoundEdge(self, "EF", (t*10, resonator_length - mouth_height - t*10)), 'e',
edges.CompoundEdge(self, "FE", (resonator_length - mouth_height - t*10, t*10)), 'e']
self.rectangularWall(resonator_length - mouth_height, mouth_width, e, move="up")
self.rectangularWall(base_length, mouth_width, "FeFF", move="right")
self.rectangularWall(mouth_width, pipe_depth, "fFfF", callback=[
lambda:self.hole(mouth_width/2, pipe_depth/2, d=air_hole_diameter)], move="right")
self.rectangularWall(mouth_width, pipe_depth - jet_thickness, "ffef", move="right")
| 6,697 | Python | .py | 122 | 45.344262 | 177 | 0.606107 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,601 | wallrollholder.py | florianfesti_boxes/boxes/generators/wallrollholder.py | # Copyright (C) 2013-2016 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 boxes.walledges import _WallMountedBox
class WallRollHolder(_WallMountedBox):
"""Holder for kitchen rolls or other rolls"""
description = """Needs a dowel or pipe as axle."""
ui_group = "WallMounted"
def __init__(self) -> None:
super().__init__()
self.argparser.add_argument(
"--width", action="store", type=float, default=275,
help="length of the axle in mm")
self.argparser.add_argument(
"--diameter", action="store", type=float, default=120,
help="maximum diameter of the roll in mm (choose generously)")
self.argparser.add_argument(
"--height", action="store", type=float, default=80,
help="height of mounting plate in mm")
self.argparser.add_argument(
"--axle", action="store", type=float, default=25,
help="diameter of the axle in mm including play")
def side(self, move=None):
d = self.diameter
a = self.axle
h = self.height
t = self.thickness
tw, th = h, (d + a) / 2 + 3 * t + self.edges["B"].spacing()
if self.move(tw, th, move, True):
return
self.moveTo(0, self.edges["B"].margin())
self.edges["B"](h)
self.fingerHolesAt(-(a/2+3*t), self.burn+self.edges["B"].endwidth(), d/2, 90)
self.polyline(0, 90, self.edges["B"].endwidth() + d/2,
(90, a/2 + 3*t))
r = a/2 + 3*t
a = math.atan2(float(d/2), (h-a-6*t))
alpha = math.degrees(a)
self.corner(alpha, r)
self.edge(((h-2*r)**2+(d/2)**2)**0.5)
self.corner(90-alpha, r)
self.edge(self.edges["B"].startwidth())
self.corner(90)
self.move(tw, th, move)
def backCB(self):
t = self.thickness
a = self.axle
h = self.height
w = self.width
plate = w + 2*t + h/2
self.wallHolesAt(h/4+t/2-3*t, 0, h, 90)
self.fingerHolesAt(h/4-3*t, h-3*t-a/2, h/4, 180)
self.wallHolesAt(h/4+t/2+t-3*t+w, 0, h, 90)
self.fingerHolesAt(h/4+2*t-3*t+w, h-3*t-a/2, h/4, 0)
def rings(self):
a = self.axle
r = a/2
t = self.thickness
self.moveTo(0, a+1.5*t, -90)
for i in range(2):
self.polyline(r-1.5*t, (180, r+3*t), 0, (180, 1.5*t), 0,
(-180, r), r-1.5*t, (180, 1.5*t))
self.moveTo(a-t, a+12*t, 180)
def render(self):
self.generateWallEdges()
t = self.thickness
w = self.width
d = self.diameter
a = self.axle
h = self.height
self.height = h = max(h, a+10*t)
self.side(move="right")
self.side(move="right")
self.rectangularTriangle(h/4, d/2, "ffe", num=2, r=3*t, move="right")
self.roundedPlate(w+h/2+2*t, h, edge="e", r=3*t,
extend_corners=False,
callback=[self.backCB], move="right")
self.rings()
| 3,735 | Python | .py | 90 | 32.811111 | 85 | 0.573127 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,602 | rack19box.py | florianfesti_boxes/boxes/generators/rack19box.py | # Copyright (C) 2013-2018 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 *
class Rack19Box(Boxes):
"""Closed box with screw on top for mounting in a 19" rack."""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0.5)
self.argparser.add_argument(
"--depth", action="store", type=float, default=100.,
help="inner depth in mm")
self.argparser.add_argument(
"--height", action="store", type=int, default=2,
choices=list(range(1, 17)),
help="height in rack units")
self.argparser.add_argument(
"--triangle", action="store", type=float, default=25.,
help="Sides of the triangles holding the lid in mm")
self.argparser.add_argument(
"--d1", action="store", type=float, default=2.,
help="Diameter of the inner lid screw holes in mm")
self.argparser.add_argument(
"--d2", action="store", type=float, default=3.,
help="Diameter of the lid screw holes in mm")
def wallxCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.x, self.h-1.5*t, self.triangle, 180)
def wallxfCB(self): # front
t = self.thickness
for x in (8.5, self.x+2*17.+2*t-8.5):
for y in (6., self.h-6.+t):
self.rectangularHole(x, y, 10, 6.5, r=3.25)
self.moveTo(t+17., t)
self.wallxCB()
def wallyCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.y, self.h-1.5*t, self.triangle, 180)
def _render(self, type):
t = self.thickness
self.h = h = self.height * 44.45 - 0.787 - t
if type == 10:
self.x = 219.0 - 2*t
else:
self.x = 448.0 - 2*t
x = self.x
y = self.y = self.depth
d1, d2 =self.d1, self.d2
tr = self.triangle
trh = tr / 3.
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB],
move="right", label="right")
self.flangedWall(x, h, "FFEF", callback=[self.wallxfCB], r=t,
flanges=[0., 17., -t, 17.], move="up", label="front")
self.rectangularWall(x, h, "fFeF", callback=[self.wallxCB],
label="back")
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB],
move="left up", label="left")
self.rectangularWall(x, y, "fFFF", move="up", label="bottom")
self.rectangularWall(x, y, callback=[
lambda:self.hole(trh, trh, d=d2)] * 4, move='right', label="lid")
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
def render(self):
self._render(type=19)
| 3,633 | Python | .py | 79 | 36.860759 | 78 | 0.594457 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,603 | displayshelf.py | florianfesti_boxes/boxes/generators/displayshelf.py | # Copyright (C) 2013-2016 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 *
class DisplayShelf(Boxes):
"""Shelf with slanted floors"""
ui_group = "Shelf"
# arguments/properties
num: int
x: float
y: float
h: float
angle: float
thickness: float
radians: float
sl: float
front_wall_height: float
include_back: bool
slope_top: bool
outside: bool
divider_wall_height: float
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(sx="400", y=100, h=300, outside=True)
self.argparser.add_argument(
"--num", action="store", type=int, default=3,
help="number of shelves")
self.argparser.add_argument(
"--front_wall_height", action="store", type=float, default=20.0,
help="height of front walls")
self.argparser.add_argument(
"--angle", action="store", type=float, default=30.0,
help="angle of floors (negative values for slanting backwards)")
self.argparser.add_argument(
"--include_back", action="store", type=boolarg, default=False,
help="Include panel on the back of the shelf")
self.argparser.add_argument(
"--include_front", action="store", type=boolarg, default=False,
help="Include panel on the front of the shelf (to be used backwards)")
self.argparser.add_argument(
"--include_bottom", action="store", type=boolarg, default=False,
help="Include horizontal panel on the bottom of the shelf")
self.argparser.add_argument(
"--slope_top", action="store", type=boolarg, default=False,
help="Slope the sides and the top by front wall height")
self.argparser.add_argument(
"--divider_wall_height", action="store", type=float, default=20.0,
help="height of divider walls")
self.argparser.add_argument(
"--bottom_distance", action="store", type=float, default=0.0,
help="height below the bottom shelf")
self.argparser.add_argument(
"--top_distance", action="store", type=float, default=0.0,
help="extra height above the top shelf")
def generate_finger_holes(self):
t = self.thickness
a = self.radians
hs = (self.sl + t) * math.sin(a) + math.cos(a) * t
b_offs = self.bottom_distance
h = self.h - b_offs - self.top_distance
if self.slope_top and self.include_bottom:
self.moveTo(0, self.edges["h"].startwidth())
if (h - abs(hs) - 3*t * (self.num - 1)) < 0:
raise ValueError("Need more hight to fit shelves")
for i in range(self.num):
pos_x = abs(0.5 * t * math.sin(a))
pos_y = hs - math.cos(a) * 0.5 * t + i * (h - abs(hs)) / (self.num - 0.5) + b_offs
if a < 0:
pos_y += -math.sin(a) * self.sl
self.fingerHolesAt(pos_x, pos_y, self.sl, -self.angle)
pos_x += math.cos(-a) * (self.sl + 0.5 * t) + math.sin(a) * 0.5 * t
pos_y += math.sin(-a) * (self.sl + 0.5 * t) + math.cos(a) * 0.5 * t
self.fingerHolesAt(pos_x, pos_y, self.front_wall_height, 90 - self.angle)
def generate_sloped_sides(self, width, height):
top_segment_height = height / self.num
a = self.radians
# Maximum size to cut out
vertical_cut = top_segment_height - self.front_wall_height
hypotenuse = vertical_cut / math.sin(a)
horizontal_cut = math.sqrt((hypotenuse ** 2) - (vertical_cut ** 2))
if horizontal_cut > width:
# Shrink the cut to keep the full height
horizontal_cut = width - 1 # keep a 1mm edge on the top
vertical_cut = horizontal_cut * math.tan(a)
hypotenuse = math.sqrt((horizontal_cut ** 2) + (vertical_cut ** 2))
top = width - horizontal_cut
self.front = front = height - vertical_cut
edges = 'he' if self.include_bottom else 'ee'
le = self.edges['h'].startwidth() if self.include_bottom else self.edges['e'].startwidth()
edges += 'f' if self.include_front else 'e'
edges += 'eefe' if self.include_back else 'eeee'
borders = [width, 90, le, 0, front, 90 - self.angle, hypotenuse, self.angle, top, 90, height, 0, le, 90]
self.polygonWall(borders, edge=edges, callback=[self.generate_finger_holes], move="up", label="left side")
self.polygonWall(borders, edge=edges, callback=[self.generate_finger_holes], move="up", label="right side")
def generate_rectangular_sides(self, width, height):
edges = 'h' if self.include_bottom else 'e'
edges += "fe" if self.include_front else "ee"
edges += "f" if self.include_back else "e"
self.rectangularWall(width, height, edges, callback=[self.generate_finger_holes], move="up", label="left side")
self.rectangularWall(width, height, edges, callback=[self.generate_finger_holes], move="up", label="right side")
def generate_shelve_finger_holes(self):
t = self.thickness
pos_x = -0.5 * t
for x in self.sx[:-1]:
pos_x += x + t
self.fingerHolesAt(pos_x, 0, self.sl, 90)
def generate_front_lip_finger_holes(self):
t = self.thickness
height = self.front_wall_height
if self.divider_wall_height < height:
height = self.divider_wall_height
pos_x = -0.5 * t
for x in self.sx[:-1]:
pos_x += x + t
self.fingerHolesAt(pos_x, 0, height, 90)
def generate_shelves(self):
if self.front_wall_height:
for i in range(self.num):
self.rectangularWall(
self.x,
self.sl,
"ffef",
callback=[self.generate_shelve_finger_holes],
move="up",
label=f"shelf {i + 1}"
)
self.rectangularWall(
self.x,
self.front_wall_height,
"Ffef",
callback=[self.generate_front_lip_finger_holes],
move="up",
label=f"front lip {i + 1}"
)
else:
for i in range(self.num):
self.rectangularWall(
self.x,
self.sl,
"Efef",
callback=[self.generate_shelve_finger_holes],
move="up",
label=f"shelf {i + 1}"
)
def generate_dividers(self):
edges_ = "feee"
if self.front_wall_height:
edges_ = "ffee"
if self.divider_wall_height > self.front_wall_height:
edges_ = [
"f",
edges.CompoundEdge(self, "fe", [self.front_wall_height, self.divider_wall_height - self.front_wall_height]),
"e",
"e"
]
for i in range(self.num):
for j in range(len(self.sx) -1):
self.rectangularWall(self.sl, self.divider_wall_height, edges_, move="up", label=f"divider {j + 1} for shelf {i + 1}")
def render(self):
# adjust to the variables you want in the local scope
sx, y, h = self.sx, self.y, self.h
front = self.front_wall_height
thickness = self.thickness
if self.outside:
bottom = thickness + self.edges["h"].startwidth() if self.include_bottom else True
self.sx = sx = self.adjustSize(sx, bottom)
self.y = y = self.adjustSize(y, self.include_back, self.include_front)
self.x = x = sum(sx) + thickness * (len(sx) - 1)
self.radians = a = math.radians(self.angle)
self.sl = (y - (thickness * (math.cos(a) + abs(math.sin(a)))) - max(0, math.sin(a) * front)) / math.cos(a)
# render your parts here
if self.slope_top:
self.generate_sloped_sides(y, h)
else:
self.generate_rectangular_sides(y, h)
self.generate_shelves()
self.generate_dividers()
b = "h" if self.include_bottom else "e"
if self.include_back:
self.rectangularWall(x, h, b + "FeF", label="back wall", move="up")
if self.include_front:
if self.slope_top:
self.rectangularWall(x, self.front, b + "FeF", label="front wall", move="up")
else:
self.rectangularWall(x, h, b + "FeF", label="front wall", move="up")
if self.include_bottom:
edges = "ff" if self.include_front else "ef"
edges += "ff" if self.include_back else "ef"
self.rectangularWall(x, y, edges, label="bottom wall", move="up")
| 9,551 | Python | .py | 201 | 36.651741 | 134 | 0.574922 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,604 | slidingdrawer.py | florianfesti_boxes/boxes/generators/slidingdrawer.py | from boxes import *
class SlidingDrawer(Boxes):
"""Sliding drawer box"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=60, y=100, h=30, outside='true')
self.addSettingsArgs(edges.FingerJointSettings, finger=2.0, space=2.0)
self.addSettingsArgs(edges.GroovedSettings, width=0.4)
self.argparser.add_argument(
"--play", action="store", type=float, default=0.15,
help="play between the two parts as multiple of the wall thickness")
def render(self):
x, y, h = self.x, self.y, self.h
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h)
t = self.thickness
p = self.play * t
y = y + t
if not self.outside:
x = x + 4*t+ 2*p
y = y + 3*t+ 2*p
h = h + 3*t+ 2*p
x2 = x - (2*t + 2*p)
y2 = y - (2*t + 2*p)
h2 = h - (t + 2*p)
self.rectangularWall(x2, h2, "FFzF", label="in box wall", move="right")
self.rectangularWall(y2, h2, "ffef", label="in box wall", move="up")
self.rectangularWall(y2, h2, "ffef", label="in box wall")
self.rectangularWall(x2, h2, "FFeF", label="in box wall", move="left up")
self.rectangularWall(y2, x2, "FfFf", label="in box bottom", move="up")
self.rectangularWall(y, x, "FFFe", label="out box bottom", move="right")
self.rectangularWall(y, x, "FFFe", label="out box top", move="up")
self.rectangularWall(y, h, "fffe", label="out box wall")
self.rectangularWall(y, h, "fffe", label="out box wall", move="up left")
self.rectangularWall(x, h, "fFfF", label="out box wall")
| 1,739 | Python | .py | 37 | 37.972973 | 81 | 0.574896 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,605 | flextest2.py | florianfesti_boxes/boxes/generators/flextest2.py | # 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/>.
from boxes import *
class FlexTest2(Boxes):
"""Piece for testing 2D flex settings"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser("x", "y")
self.argparser.add_argument(
"--fw", action="store", type=float, default=1,
help="distance of flex cuts in multiples of thickness")
def render(self):
x, y = self.x, self.y
self.rectangularWall(x, y, callback=[lambda: self.flex2D(x, y, self.fw)])
| 1,211 | Python | .py | 27 | 40.62963 | 81 | 0.691589 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,606 | notesholder.py | florianfesti_boxes/boxes/generators/notesholder.py | # Copyright (C) 2013-2019 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 boxes.edges import CompoundEdge, Edge
class USlotEdge(Edge):
def __init__(self, boxes, settings, edge="f"):
super().__init__(boxes, settings)
self.e = edge
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
l = length
o = self.settings
d = length * (1-o/100) / 2
r = min(3*self.thickness, (l-2*d)/2)
self.edges[self.e](d)
self.step(-self.edges[self.e].endwidth())
self.polyline(0, 90, 0, (-90, r), l-2*d-2*r, (-90, r), 0, 90)
self.step(self.edges[self.e].startwidth())
self.edges[self.e](d)
def margin(self) -> float:
return self.edges[self.e].margin()
def startwidth(self):
return self.edges[self.e].startwidth()
class HalfStackableEdge(edges.StackableEdge):
char = 'H'
def __call__(self, length, **kw):
s = self.settings
r = s.height / 2.0 / (1 - math.cos(math.radians(s.angle)))
l = r * math.sin(math.radians(s.angle))
p = 1 if self.bottom else -1
if self.bottom:
self.boxes.fingerHolesAt(0, s.height + self.settings.holedistance + 0.5 * self.boxes.thickness,
length, 0)
self.boxes.edge(s.width, tabs=1)
self.boxes.corner(p * s.angle, r)
self.boxes.corner(-p * s.angle, r)
self.boxes.edge(length - 1 * s.width - 2 * l)
def endwidth(self) -> float:
return self.settings.holedistance + self.settings.thickness
class NotesHolder(Boxes):
"""Box for holding a stack of paper, coasters etc"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
self.addSettingsArgs(edges.StackableSettings)
self.buildArgParser(sx="78*1", y=78, h=35)
self.argparser.add_argument(
"--bottom_edge", action="store",
type=ArgparseEdgeType("Fhsfe"), choices=list("Fhsfe"),
default="s",
help="edge type for bottom edge")
self.argparser.add_argument(
"--opening", action="store", type=float, default=40,
help="percent of front (or back) that's open")
self.argparser.add_argument(
"--back_openings", action="store", type=boolarg, default=False,
help="have openings on the back side, too")
def fingerHoleCB(self, lengths, height, posy=0.0):
def CB():
t = self.thickness
px = -0.5 * t
for x in lengths[:-1]:
px += x + t
self.fingerHolesAt(px, posy, height, 90)
return CB
def render(self):
sx, y, h = self.sx, self.y, self.h
t = self.thickness
x = sum(sx) + (len(sx) - 1) * t
o = max(0, min(self.opening, 100))
sides = x * (1-o/100) / 2
b = self.edges.get(self.bottom_edge, self.edges["F"])
if self.bottom_edge == "s":
b2 = HalfStackableEdge(self, self.edges["s"].settings,
self.edges["f"].settings)
b3 = self.edges["h"]
else:
b2 = b
b3 = b
b4 = Edge(self, None)
b4.startwidth = lambda: b3.startwidth()
for side in range(2):
with self.saved_context():
self.rectangularWall(y, h, [b, "F", "e", "F"],
ignore_widths=[1, 6], move="right")
# front walls
if self.opening == 0.0 or (side and not self.back_openings):
self.rectangularWall(x, h, [b, "f", "e", "f"],
ignore_widths=[1, 6], move="right")
else:
self.rectangularWall(sx[0] * (1-o/100) / 2, h,
[b2, "e", "e", "f"],
ignore_widths=[1, 6], move="right")
for ix in range(len(sx)-1):
left = sx[ix] * (1-o/100) / 2
right = sx[ix+1] * (1-o/100) / 2
h_e = t
bottom_edge = CompoundEdge(
self, [b3, b4, b3], [left, t, right])
self.rectangularWall(
left+right+t, h,
[bottom_edge, "e", "e", "e"],
callback=[lambda: self.fingerHolesAt(left+t/2, 0, h, 90)],
move="right")
self.rectangularWall(sx[-1] * (1-o/100) / 2, h,
[b2, "e", "e", "f"],
ignore_widths=[1, 6],
move="right mirror")
self.rectangularWall(x, h, [b, "F", "e", "F"],
ignore_widths=[1, 6], move="up only")
# hack to have it reversed in second go and then back to normal
sx = list(reversed(sx))
# bottom
if self.bottom_edge != "e":
outer_edge = "h" if self.bottom_edge == "f" else "f"
font_edge = back_edge = outer_edge
u_edge = USlotEdge(self, o, outer_edge)
outer_width = self.edges[outer_edge].startwidth()
if self.opening > 0.0:
front_edge = CompoundEdge(
self,
([u_edge, edges.OutSetEdge(self, outer_width)]*len(sx))[:-1],
([l for x in sx for l in (x, t)])[:-1])
if self.opening > 0.0 and self.back_openings:
back_edge = CompoundEdge(
self,
([u_edge, edges.OutSetEdge(self, outer_width)]*len(sx))[:-1],
([l for x in reversed(sx) for l in (x, t)])[:-1])
self.rectangularWall(
x, y,
[front_edge, outer_edge, back_edge, outer_edge],
callback=[self.fingerHoleCB(sx, y)],
move="up")
# innner walls
for i in range(len(sx)-1):
self.rectangularWall(
y, h, ("e" if self.bottom_edge=="e" else "f") + "fef",
move="right")
| 6,971 | Python | .py | 150 | 33.073333 | 107 | 0.509937 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,607 | gridfinitytraylayout.py | florianfesti_boxes/boxes/generators/gridfinitytraylayout.py | import argparse
import boxes
from boxes import Boxes, lids, restore
from boxes.Color import Color
from boxes.generators.traylayout import TrayLayout
class GridfinityTrayLayout(TrayLayout):
"""A Gridfinity Tray Generator based on TrayLayout"""
description = """
This is a general purpose gridfinity tray generator. You can create
somewhat arbitrarily shaped trays, or just do nothing for simple grid
shaped trays.
The dimensions are automatically calculated to fit perfectly into a
gridfinity grid (like the GridfinityBase, or any other Gridfinity
based base).
Edit the layout text graphics to adjust your tray.
You can replace the hyphens and vertical bars representing the walls
with a space character to remove the walls. You can replace the space
characters representing the floor by a "X" to remove the floor for
this compartment.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(lids.LidSettings)
self.buildArgParser(h=50)
self.outside = True # We're *always* outside for gridfinity
self.pitch = 42.0 # gridfinity pitch is defined as 42.
self.opening = 38
self.opening_margin = 2
self.argparser.add_argument("--hi", type=float, default=0, help="inner height of inner walls in mm (leave to zero for same as outer walls)")
self.argparser.add_argument("--nx", type=int, default=3, help="number of gridfinity grids in X direction")
self.argparser.add_argument("--ny", type=int, default=2, help="number of gridfinity grids in Y direction")
self.argparser.add_argument("--countx", type=int, default=5, help="split x into this many grid sections. 0 means same as --nx")
self.argparser.add_argument("--county", type=int, default=3, help="split y into this many grid sections. 0 means same as --ny")
self.argparser.add_argument("--margin", type=float, default=0.75, help="Leave this much total margin on the outside, in mm")
if self.UI == "web":
self.argparser.add_argument("--layout", type=str, help="You can hand edit this before generating", default="\n");
else:
self.argparser.add_argument(
"--input", action="store", type=argparse.FileType('r'),
default="traylayout.txt",
help="layout file")
self.layout = None
def generate_layout(self):
layout = ''
countx = self.countx
county = self.county
if countx == 0:
countx = self.nx
if county == 0:
county = self.ny
stepx = self.x / countx
stepy = self.y / county
for i in range(countx):
line = ' |' * i + f" ,> {stepx}mm\n"
layout += line
for i in range(county):
layout += "+-" * countx + f"+\n"
layout += "| " * countx + f"|{stepy}mm\n"
layout += "+-" * countx + "+\n"
return layout
@restore
def rectangularEtching(self, x, y, dx, dy, r=0, center_x=True, center_y=True):
"""
Draw a rectangular hole
:param x: x position
:param y: y position
:param dx: width
:param dy: height
:param r: (Default value = 0) radius of the corners
:param center_x: (Default value = True) if True, x position is the center, else the start
:param center_y: (Default value = True) if True, y position is the center, else the start
"""
r = min(r, dx/2., dy/2.)
x_start = x if center_x else x + dx / 2.0
y_start = y - dy / 2.0 if center_y else y
self.moveTo(x_start, y_start, 180)
self.edge(dx / 2.0 - r) # start with an edge to allow easier change of inner corners
for d in (dy, dx, dy, dx / 2.0 + r):
self.corner(-90, r)
self.edge(d - 2 * r)
def baseplate_etching(self):
x = -self.thickness - self.margin / 2
y = -self.thickness - self.margin / 2
o = self.opening
p = self.pitch
m = self.opening_margin
self.ctx.stroke()
with self.saved_context():
for xx in [0, self.nx-1]:
for yy in [0, self.ny-1]:
self.set_source_color(Color.ETCHING)
self.rectangularEtching(x+p/2+xx*p, y+p/2+yy*p, o-m, o-m)
self.ctx.stroke()
def render(self):
# Create a layout
self.x = self.pitch * self.nx - self.margin
self.y = self.pitch * self.ny - self.margin
self.outer_x = self.x
self.outer_y = self.y
self.prepare()
self.walls()
with self.saved_context():
self.base_plate(callback=[self.baseplate_etching],
move="mirror right")
foot = self.opening - self.opening_margin
for i in range(min(self.nx * self.ny, 4)):
self.rectangularWall(foot, foot, move="right")
self.base_plate(callback=[self.baseplate_etching],
move="up only")
self.lid(sum(self.x) + (len(self.x)-1) * self.thickness,
sum(self.y) + (len(self.y)-1) * self.thickness)
| 5,226 | Python | .py | 112 | 37.571429 | 148 | 0.609096 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,608 | carbonfilter.py | florianfesti_boxes/boxes/generators/carbonfilter.py | # 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 *
class CarbonFilter(Boxes):
"""Compact filter for activated char coal pellets"""
description = """The filter does not include the top rim. You need some rectangular wooden strip about 2-3cm in size to glue around. The x and y are without this rim and should be about 5 cm smaller that the nominal size.
The following sizes are currently hard coded:
* Height of rails on top: 50mm
* Borders on top: 40mm
* Char coal width (horizontal): 40mm
* Bottom width: 40 + 20 + 40 mm
For assembly it is important that all bottom plates are the same way up. This allows the ribs of adjacent pockets to pass beside each other.
There are three type of ribs:
* Those with staight tops go in the middle of the bottom plates
* Those pointier angle go at the outer sides and meet with the side bars
* The less pointy go at all other sides of the bottom plates that will end up on the inside
The last two types of ribs do not have finger joints on the outside but still need to be glued to the top beam of the adjacent pocket or the left or right side bar.
"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(x=550, y=550, h=250)
self.argparser.add_argument(
"--pockets", action="store", type=int, default=3,
help="number of V shaped filter pockets")
self.argparser.add_argument(
"--ribs", action="store", type=int, default=12,
help="number of ribs to hold the bottom and the mesh")
def sideCB(self):
x, y, h = self.x, self.y, self.h
t = self.thickness
p = self.pockets
posx = t
w = self.w
a = self.a
self.fingerHolesAt(t/2, h, 50, -90)
self.fingerHolesAt(x-t/2, h, 50, -90)
for i in range(p):
self.fingerHolesAt(posx + t/2, h, 50, -90+a)
self.fingerHolesAt(posx + 40 + t/2, h, 50, -90+a)
self.fingerHolesAt(posx + w - t/2, h, 50, -90-a)
self.fingerHolesAt(posx + w - 40 - t/2, h, 50, -90-a)
self.fingerHolesAt(posx + w/2 -50 + t, 3.5*t, 100 - 2*t, 0)
posx += w
def bottomCB(self):
t = self.thickness
for i in range(self.ribs):
self.fingerHolesAt((i+1) * self.y / (self.ribs + 1) - 1.5 * t,
0, 4*t, 90)
self.fingerHolesAt((i+1) * self.y / (self.ribs + 1) - 1.5 * t,
40 - t, 20, 90)
def topRailCB(self):
t = self.thickness
for i in range(self.ribs):
self.fingerHolesAt((i+1) * self.y / (self.ribs + 1) - 1.5 * t,
0, 30, 90)
def innerRibs(self, n, move=None):
x, y, h = self.x, self.y, self.h
t = self.thickness
a = self.a
a_ = math.radians(a)
l = (h-4*t) / math.cos(a_) - 0.5 * t * math.sin(a_)
tw = n * (20 + self.spacing) + l * math.sin(a_)
th = h-3*t - 20 * math.cos(a_) + self.spacing
if self.move(tw, th, move, True):
return
self.moveTo(0, t)
for i in range(n):
self.edges["f"](20)
self.polyline(0, 90-a, l - 50, 90, t, -90)
self.edges["f"](30)
self.polyline(0, 90 + a, 20-t, 90 - a, l-20 + t * math.sin(a_),
90+a)
self.moveTo(20 + self.spacing)
self.ctx.stroke()
self.move(tw, th, move, label="Inner ribs")
def sideHolders(self, n, move=None):
x, y, h = self.x, self.y, self.h
t = self.thickness
a = self.a
a_ = math.radians(a)
l = (h-4*t) / math.cos(a_) - 0.5 * t * math.sin(a_) - 50
tw = n * (10 + self.spacing) + l * math.sin(a_)
th = h - 4*t - 50
if self.move(tw, th, move, True):
return
for i in range(n):
self.polyline(10, 90-a, l, 90+a, 10, 90-a, l, 90+a)
self.ctx.stroke()
self.moveTo(10+self.spacing)
self.move(tw, th, move, label="Inner ribs")
def topStabilizers(self, n, move=None):
t = self.thickness
l = 2* (self.h-60) * math.sin(math.radians(self.a)) - 20
tw = n * (6*t + self.spacing)
th = l + 4*t
if self.move(tw, th, move, True):
return
self.moveTo(t)
for i in range(n):
for j in range(2):
self.polyline(0, 90, 2*t, -90, t, -90, 2*t, 90, 3*t, (90, t),
l+2*t, (90, t))
self.ctx.stroke()
self.moveTo(6*t + self.spacing)
self.move(tw, th, move, label="Inner ribs")
def outerRibs(self, n, n_edge, move=None):
x, y, h = self.x, self.y, self.h
t = self.thickness
a = self.a
a_ = math.radians(a)
l = (h-4*t) / math.cos(a_) + 0.5 * t * math.sin(a_)
dl = (20 - t) * (math.tan(math.pi/2 - 2*a_) + math.sin(a_))
dll = (20 - t) * (1 / math.sin(2*a_))
dl2 = (20 - t) * (math.tan(math.pi/2 - a_) + math.sin(a_))
dll2 = (20 - t) * (1 / math.sin(a_))
tw = (n // 2) * (40 + t) + l * math.sin(a_)
th = h + 5*t
if self.move(tw, th, move, True):
return
self.moveTo(2*t)
for i in range(n):
self.polyline(0*t + 20, (90, 2*t), 2*t, -a)
if i < n_edge:
self.polyline(l - dl2 - t * math.sin(a_), a,
dll2, 180 - a, 20)
else:
self.polyline(l - dl - t * math.sin(a_), 2*a,
dll, 180 - 2*a, 20)
self.edges["f"](30)
self.polyline(0, -90, t, 90, l - 50, a, t, -90)
self.edges["f"](4*t)
self.polyline(0, 90, 1*t, (90, 2*t))
self.moveTo(t + 40)# + self.spacing)
if i + 1 == n // 2:
self.moveTo(2*t+0.7*self.spacing, h + 5*t, 180)
self.ctx.stroke()
self.move(tw, th, move, label="Outer ribs")
def render(self):
# adjust to the variables you want in the local scope
x, y, h = self.x, self.y, self.h
self.y = y = self.adjustSize(y)
t = self.thickness
self.w = (x - 2*t) / self.pockets
self.a = math.degrees(math.atan((self.w - 100) / 2 / (h - 4*t)))
# sides
for i in range(2):
self.rectangularWall(x, h, callback=[self.sideCB], move="up")
for i in range(2):
self.rectangularWall(y, 50, "efef", label="Sides", move="up")
# top rails
for i in range(self.pockets * 4):
self.rectangularWall(y, 50, "efef",
callback=[self.topRailCB],
label="Top rails", move="up")
# bottoms
w = 100 - 2*t
for i in range(self.pockets):
self.rectangularWall(
y, w, "efef",
callback=[self.bottomCB, None, self.bottomCB],
label="bottom plate", move="up")
self.innerRibs(self.pockets * self.ribs * 2, move="up")
self.outerRibs(self.pockets * self.ribs * 2, self.ribs * 2, move="up")
self.sideHolders(self.pockets * 8, move="up")
self.topStabilizers(min(3, self.ribs) *self.pockets)
| 8,075 | Python | .py | 179 | 34.882682 | 225 | 0.540906 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,609 | birdhouse.py | florianfesti_boxes/boxes/generators/birdhouse.py | # Copyright (C) 2013-2022 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 *
class BirdHouse(Boxes):
"""Simple Bird House"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, finger=10.0,space=10.0)
self.buildArgParser(x=200, y=200, h=200)
self.argparser.add_argument(
"--roof_overhang", action="store", type=float, default=0.4,
help="overhang as fraction of the roof length")
def side(self, x, h, edges="hfeffef", callback=None, move=None):
angles = (90, 0, 45, 90, 45, 0, 90)
roof = 2**0.5 * x / 2
t = self.thickness
lengths = (x, h, t, roof, roof, t, h)
edges = [self.edges.get(e, e) for e in edges]
edges.append(edges[0]) # wrap around
tw = x + edges[1].spacing() + edges[-2].spacing()
th = h + x/2 + t + edges[0].spacing() + max(edges[3].spacing(), edges[4].spacing())
if self.move(tw, th, move, True):
return
self.moveTo(edges[-2].spacing())
for i in range(7):
self.cc(callback, i, y=self.burn+edges[i].startwidth())
edges[i](lengths[i])
self.edgeCorner(edges[i], edges[i+1], angles[i])
self.move(tw, th, move)
def roof(self, x, h, overhang, edges="eefe", move=None):
t = self.thickness
edges = [self.edges.get(e, e) for e in edges]
tw = x + 2*t + 2*overhang + edges[1].spacing() + edges[3].spacing()
th = h + 2*t + overhang + edges[0].spacing() + edges[2].spacing()
if self.move(tw, th, move, True):
return
self.moveTo(overhang + edges[3].spacing(), edges[0].margin())
edges[0](x + 2*t)
self.corner(90, overhang)
edges[1](h + 2*t)
self.edgeCorner(edges[1], edges[2])
self.fingerHolesAt(overhang + 0.5*t, edges[2].startwidth(), h, 90)
self.fingerHolesAt(x + overhang + 1.5*t, edges[2].startwidth(), h, 90)
edges[2](x + 2*t + 2*overhang)
self.edgeCorner(edges[2], edges[3])
edges[3](h + 2*t)
self.corner(90, overhang)
self.move(tw, th, move)
def side_hole(self, width):
self.rectangularHole(width/2, self.h/2,
0.75*width, 0.75*self.h,
r=self.thickness)
def render(self):
x, y, h = self.x, self.y, self.h
roof = 2**0.5 * x / 2
overhang = roof * self.roof_overhang
cbx = [lambda: self.side_hole(x)]
cby = [lambda: self.side_hole(y)]
self.side(x, h, callback=cbx, move="right")
self.side(x, h, callback=cbx, move="right")
self.rectangularWall(y, h, "hFeF", callback=cby, move="right")
self.rectangularWall(y, h, "hFeF", callback=cby, move="right")
self.rectangularWall(x, y, "ffff", move="right")
self.edges["h"].settings.setValues(self.thickness, relative=False, edge_width=overhang)
self.roof(y, roof, overhang, "eefe", move="right")
self.roof(y, roof, overhang, "eeFe", move="right")
| 3,763 | Python | .py | 79 | 39.443038 | 95 | 0.600218 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,610 | flexbox3.py | florianfesti_boxes/boxes/generators/flexbox3.py | # 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/>.
from boxes import *
class FlexBox3(Boxes):
"""Box with living hinge"""
ui_group = "FlexBox"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("x", "y", "outside")
self.argparser.add_argument(
"--z", action="store", type=float, default=100.0,
help="height of the box")
self.argparser.add_argument(
"--h", action="store", type=float, default=10.0,
help="height of the lid")
self.argparser.add_argument(
"--radius", action="store", type=float, default=10.0,
help="radius of the lids living hinge")
self.argparser.add_argument(
"--c", action="store", type=float, default=1.0,
dest="d", help="clearance of the lid")
def flexBoxSide(self, x, y, r, callback=None, move=None):
t = self.thickness
if self.move(x+2*t, y+t, move, True):
return
self.moveTo(t, t)
self.cc(callback, 0)
self.edges["f"](x)
self.corner(90, 0)
self.cc(callback, 1)
self.edges["f"](y - r)
self.corner(90, r)
self.cc(callback, 2)
self.edge(x - r)
self.corner(90, 0)
self.cc(callback, 3)
self.edges["f"](y)
self.corner(90)
self.move(x+2*t, y+t, move)
def surroundingWall(self, move=None):
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
t = self.thickness
tw = x + y - 2*r + self.c4 + 2*t + t
th = z + 4*t + 2*d
if self.move(tw, th, move, True):
return
self.moveTo(t, d + t)
self.edges["F"](y - r, False)
self.edges["X"](self.c4, z + 2 * t)
self.corner(-90)
self.edge(d)
self.corner(90)
self.edges["f"](x - r + t)
self.corner(90)
self.edges["f"](z + 2 * t + 2 * d)
self.corner(90)
self.edges["f"](x - r + t)
self.corner(90)
self.edge(d)
self.corner(-90)
self.edge(self.c4)
self.edges["F"](y - r)
self.corner(90)
self.edge(t)
self.edges["f"](z)
self.edge(t)
self.corner(90)
self.move(tw, th, move)
def lidSide(self, move=None):
x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h
t = self.thickness
r2 = r + t if r + t <= h + t else h + t
if r < h:
r2 = r + t
base_l = x + 2 * t
if self.move(h+t, base_l+t, move, True):
return
self.edge(h + self.thickness - r2)
self.corner(90, r2)
self.edge(r - r2 + 1 * t)
else:
a = math.acos((r-h)/(r+t))
ang = math.degrees(a)
base_l = x + (r+t) * math.sin(a) - r + t
if self.move(h+t, base_l+t, move, True):
return
self.corner(90-ang)
self.corner(ang, r+t)
self.edges["F"](x - r + t)
self.edgeCorner("F", "f")
self.edges["g"](h)
self.edgeCorner("f", "e")
self.edge(base_l)
self.corner(90)
self.move(h+t, base_l+t, move)
def render(self):
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
self.z = self.adjustSize(self.z)
x, y, z, d, h = self.x, self.y, self.z, self.d, self.h
r = self.radius = self.radius or min(x, y) / 2.0
thickness = self.thickness
self.c4 = c4 = math.pi * r * 0.5 * 0.95
self.latchsize = 8 * thickness
width = 2 * x + y - 2 * r + c4 + 14 * thickness + 3 * h # lock
height = y + z + 8 * thickness
s = edges.FingerJointSettings(self.thickness, finger=1.,
space=1., surroundingspaces=1)
s.edgeObjects(self, "gGH")
with self.saved_context():
self.surroundingWall(move="right")
self.rectangularWall(x, z, edges="FFFF", move="right")
self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right")
self.lidSide(move="right")
self.lidSide(move="mirror right")
self.surroundingWall(move="up only")
self.flexBoxSide(x, y, r, move="right")
self.flexBoxSide(x, y, r, move="mirror right")
self.rectangularWall(z, y, edges="fFeF")
| 5,257 | Python | .py | 134 | 29.940299 | 93 | 0.547899 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,611 | storageshelf.py | florianfesti_boxes/boxes/generators/storageshelf.py | # 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/>.
from boxes import *
from boxes.lids import _TopEdge
class StorageShelf(_TopEdge):
"""StorageShelf can be used to store Typetray"""
ui_group = "Shelf"
description = "This is a simple shelf box."
def __init__(self) -> None:
Boxes.__init__(self)
self.addTopEdgeSettings(fingerjoint={"surroundingspaces": 0.5},
roundedtriangle={"outset" : 1})
self.buildArgParser("x", "sy", "sh", "outside", "bottom_edge",
"top_edge")
self.argparser.add_argument(
"--retainer", action="store", type=float, default=0.0,
help="height of retaining wall at the front edges")
self.argparser.add_argument(
"--retainer_hole_edge", action="store", type=boolarg, default=False,
help="use finger hole edge for retainer walls")
def ySlots(self):
posy = -0.5 * self.thickness
h = sum(self.sh) + self.thickness * (len(self.sh) - 1)
for y in self.sy[:-1]:
posy += y + self.thickness
self.fingerHolesAt(posy, 0, h, 90)
def hSlots(self):
posh = -0.5 * self.thickness
for h in self.sh[:-1]:
posh += h + self.thickness
posy = 0
for y in reversed(self.sy):
self.fingerHolesAt(posh, posy, y)
posy += y + self.thickness
def yHoles(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
self.fingerHolesAt(posy, 0, self.x)
def hHoles(self):
posh = -0.5 * self.thickness
for h in self.sh[:-1]:
posh += h + self.thickness
self.fingerHolesAt(posh, 0, self.x)
def render(self):
if self.outside:
self.sy = self.adjustSize(self.sy)
self.sh = self.adjustSize(self.sh, self.top_edge, self.bottom_edge)
self.x = self.adjustSize(self.x, e2=False)
y = sum(self.sy) + self.thickness * (len(self.sy) - 1)
h = sum(self.sh) + self.thickness * (len(self.sh) - 1)
x = self.x
t = self.thickness
# outer walls
b = self.bottom_edge
t1, t2, t3, t4 = self.topEdges(self.top_edge)
#if top_edge is t put the handle on the x walls
if(self.top_edge=='t'):
t1,t2,t3,t4=(t2,t1,t4,t3)
self.closedtop = self.top_edge in "fFhŠY"
# x sides
self.ctx.save()
# outer walls
# XXX retainer
self.rectangularWall(x, h, [b, "F", t1, "e"], callback=[None, self.hHoles, ], move="up", label="left")
self.rectangularWall(x, h, [b, "e", t3, "F"], callback=[None, self.hHoles, ], move="up", label="right")
# floor
if b != "e":
e = "fffe"
if self.retainer:
e = "ffff"
self.rectangularWall(x, y, e, callback=[None, self.yHoles], move="up", label="bottom")
# inner walls
be = "f" if b != "e" else "e"
for i in range(len(self.sh) - 1):
e = ["f", edges.SlottedEdge(self, self.sy[::-1], "f", slots=0.5 * x), "f", "e"]
if self.retainer:
e[3] = "f"
self.rectangularWall(x, y, e, move="up", label="inner horizontal " + str(i+1))
# top / lid
if self.closedtop:
e = "FFFe" if self.top_edge == "f" else "fffe"
self.rectangularWall(x, y, e, callback=[None, self.yHoles, ], move="up", label="top")
else:
self.drawLid(x, y, self.top_edge)
self.ctx.restore()
self.rectangularWall(x, h, "ffff", move="right only", label="invisible")
# y walls
# outer walls
self.rectangularWall(y, h, [b, "f", t2, "f"], callback=[self.ySlots, self.hSlots,], move="up", label="back")
# inner walls
for i in range(len(self.sy) - 1):
# XXX retainer
e = [be, edges.SlottedEdge(self, self.sh, "e", slots=0.5 * x),
"e", "f"]
if self.closedtop:
e = [be, edges.SlottedEdge(self, self.sh, "e", slots=0.5 * x),"f", "f"]
self.rectangularWall(x, h, e, move="up", label="inner vertical " + str(i+1))
if self.retainer:
for i in range(len(self.sh)):
# XXX finger holes, F edges, left and right
e = "FEeE"
if self.retainer_hole_edge or (i == 0 and b == "h"):
e = "hEeE"
self.rectangularWall(y, self.retainer, e, move="up", label="retainer " + str(i+1))
| 5,300 | Python | .py | 117 | 35.282051 | 117 | 0.557927 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,612 | gridfinitybase.py | florianfesti_boxes/boxes/generators/gridfinitybase.py | # 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/>.
from boxes import *
from boxes import lids
class GridfinityBase(Boxes):
"""A parameterized Gridfinity base"""
description = """This is a configurable gridfinity base. This
design is based on
<a href="https://www.youtube.com/watch?app=desktop&v=ra_9zU-mnl8">Zach Freedman's Gridfinity system</a>"""
ui_group = "Tray"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, space=4, finger=4)
self.addSettingsArgs(lids.LidSettings)
self.argparser.add_argument("--x", type=int, default=3, help="number of grids in X direction")
self.argparser.add_argument("--y", type=int, default=2, help="number of grids in Y direction")
self.argparser.add_argument("--h", type=float, default=7*3, help="height of sidewalls of the tray (mm)")
self.argparser.add_argument("--m", type=float, default=0.5, help="Extra margin around the gridfinity base to allow it to drop into the carrier (mm)")
self.argparser.add_argument(
"--bottom_edge", action="store",
type=ArgparseEdgeType("Fhse"), choices=list("Fhse"),
default='F',
help="edge type for bottom edge")
self.argparser.add_argument("--pitch", type=int, default=42, help="The Gridfinity pitch, in mm. Should always be 42.")
self.argparser.add_argument("--opening", type=int, default=38, help="The cutout for each grid opening. Typical is 38.")
def generate_grid(self):
pitch = self.pitch
nx, ny = self.x, self.y
opening = self.opening
for col in range(nx):
for row in range(ny):
lx = col*pitch+pitch/2
ly = row*pitch+pitch/2
self.rectangularHole(lx, ly, opening, opening)
def create_base_plate(self):
pitch = self.pitch
nx, ny = self.x, self.y
opening = self.opening
self.rectangularWall(nx*pitch, ny*pitch, move="up", callback=[self.generate_grid])
def create_tray(self):
pitch = self.pitch
nx, ny = self.x, self.y
margin = self.m
x, y, h = nx*pitch, ny*pitch, self.h
t = self.thickness
x += 2*margin
y += 2*margin
t1, t2, t3, t4 = "eeee"
b = self.edges.get(self.bottom_edge, self.edges["F"])
sideedge = "F" # if self.vertical_edges == "finger joints" else "h"
self.rectangularWall(x, h, [b, sideedge, t1, sideedge],
ignore_widths=[1, 6], move="right")
self.rectangularWall(y, h, [b, "f", t2, "f"],
ignore_widths=[1, 6], move="up")
self.rectangularWall(y, h, [b, "f", t4, "f"],
ignore_widths=[1, 6], move="")
self.rectangularWall(x, h, [b, sideedge, t3, sideedge],
ignore_widths=[1, 6], move="left up")
if self.bottom_edge != "e":
self.rectangularWall(x, y, "ffff", move="up")
def render(self):
self.create_base_plate()
self.create_tray()
self.lid(self.x*self.pitch + 2*self.m,
self.y*self.pitch + 2*self.m)
| 3,874 | Python | .py | 77 | 41.61039 | 157 | 0.619551 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,613 | robotarm.py | florianfesti_boxes/boxes/generators/robotarm.py | # Copyright (C) 2017 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 boxes import robot, servos
class RobotArm(Boxes): # change class name here and below
"""Segments of servo powered robot arm"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
for i in range(1, 6):
ra = robot.RobotArg(True)
sa = servos.ServoArg()
self.argparser.add_argument(
"--type%i" % i, action="store", type=ra,
default="none", choices=ra.choices(),
help="type of arm segment")
self.argparser.add_argument(
"--servo%ia" % i, action="store", type=sa, default="Servo9g",
choices=sa.choices(), help="type of servo to use")
self.argparser.add_argument(
"--servo%ib" % i, action="store", type=sa, default="Servo9g",
choices=sa.choices(), help="type of servo to use on second side (if different is supported)")
self.argparser.add_argument(
"--length%i" % i, action="store", type=float, default=50.,
help="length of segment axle to axle")
def render(self):
for i in range(5, 0,-1):
armtype = getattr(self, "type%i" % i)
length = getattr(self, "length%i" % i)
servoA = getattr(self, "servo%ia" % i)
servoB = getattr(self, "servo%ib" % i)
armcls = getattr(robot, armtype, None)
if not armcls:
continue
servoClsA = getattr(servos, servoA)
servoClsB = getattr(servos, servoB)
armcls(self, servoClsA(self), servoClsB(self))(length, move="up")
| 2,418 | Python | .py | 50 | 39.44 | 109 | 0.615254 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,614 | display.py | florianfesti_boxes/boxes/generators/display.py | # Copyright (C) 2013-2016 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 *
class Display(Boxes):
"""Display for flyers or leaflets"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=150., h=200.0)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--radius", action="store", type=float, default=5.,
help="radius of the corners in mm")
self.argparser.add_argument(
"--angle", action="store", type=float, default=0.,
help="greater zero for top wider as bottom")
def render(self):
# adjust to the variables you want in the local scope
x, h, r = self.x, self.h, self.radius
a = self.angle
t = self.thickness
self.roundedPlate(0.7*x, x, r, "e", extend_corners=False, move="up")
oh = 1.2*h-2*r
if a > 0:
self.moveTo(math.sin(math.radians(a))*oh)
self.rectangularHole(x/2, h*0.2, 0.7*x+0.1*t, 1.3*t)
self.moveTo(r)
self.polyline(x-2*r, (90-a, r), oh, (90+a, r),
x-2*r+2*math.sin(math.radians(a))*oh,
(90+a, r), oh, (90-a, r))
| 1,894 | Python | .py | 42 | 38.142857 | 76 | 0.627579 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,615 | flexbox5.py | florianfesti_boxes/boxes/generators/flexbox5.py | # 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/>.
import math
import boxes
class FlexBox5(boxes.Boxes):
"""Box with living hinge and round corners"""
ui_group = "FlexBox"
def __init__(self) -> None:
boxes.Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(boxes.edges.FlexSettings)
self.buildArgParser("x", "h", "outside")
self.argparser.add_argument(
"--top_diameter", action="store", type=float, default=60,
help="diameter at the top")
self.argparser.add_argument(
"--bottom_diameter", action="store", type=float, default=60,
help="diameter at the bottom")
self.argparser.add_argument(
"--latchsize", action="store", type=float, default=8,
help="size of latch in multiples of thickness")
def flexBoxSide(self, callback=None, move=None):
t = self.thickness
r1, r2 = self.top_diameter/2., self.bottom_diameter/2
a = self.a
l = self.l
tw , th = l+r1+r2, 2*max(r1, r2)+2*t
if self.move(tw, th, move, True):
return
self.moveTo(r2, t)
self.cc(callback, 0)
self.edges["f"](l)
self.corner(180+2*a, r1)
self.cc(callback, 1)
self.latch(self.latchsize)
self.cc(callback, 2)
self.edges["f"](l - self.latchsize)
self.corner(180-2*a, r2)
self.move(tw, th, move)
def surroundingWall(self, move=None):
t = self.thickness
r1, r2 = self.top_diameter/2., self.bottom_diameter/2
h = self.h
a = self.a
l = self.l
c1 = math.radians(180+2*a) * r1
c2 = math.radians(180-2*a) * r2
tw = 2*l + c1 + c2
th = h + 2.5*t
if self.move(tw, th, move, True):
return
self.moveTo(0, 0.25*t)
self.edges["F"](l - self.latchsize, False)
self.edges["X"](c2, h + 2 * t)
self.edges["F"](l, False)
self.edges["X"](c1, h + 2 * t)
self.latch(self.latchsize, False)
self.edge(h + 2 * t)
self.latch(self.latchsize, False, True)
self.edge(c1)
self.edges["F"](l, False)
self.edge(c2)
self.edges["F"](l - self.latchsize, False)
self.corner(90)
self.edge(h + 2 * t)
self.corner(90)
self.move(tw, th, move)
def render(self):
if self.outside:
self.x = self.adjustSize(self.x)
self.h = self.adjustSize(self.h)
self.top_diameter = self.adjustSize(self.top_diameter)
self.bottom_diameter = self.adjustSize(self.bottom_diameter)
t = self.thickness
self.latchsize *= self.thickness
d_t, d_b = self.top_diameter, self.bottom_diameter
self.x = max(self.x, self.latchsize + 2*t + (d_t + d_b)/2)
d_c = self.x - d_t/2. - d_b/2.
self.a = math.degrees(math.asin((d_t-d_b)/2 / d_c))
self.l = d_c * math.cos(math.radians(self.a))
self.surroundingWall(move="up")
self.flexBoxSide(move="right")
self.flexBoxSide(move="mirror")
| 3,825 | Python | .py | 95 | 32.157895 | 73 | 0.601404 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,616 | airpurifier.py | florianfesti_boxes/boxes/generators/airpurifier.py | # Copyright (C) 2013-2016 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 *
class AirPurifier(Boxes):
"""Housing for the Nukit Open Air Purifier"""
ui_group = "Misc"
description = """See [Nukit Open Air Purifier](https://github.com/opennukit/Nukit-Open-Air-Purifier/)
"""
fan_holes = {
40.: 32.5,
60.: 50,
80.: 71.5,
92.: 82.5,
120.: 105,
140.: 125,
}
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.DoveTailSettings, size=2.0, depth=1)
self.buildArgParser(x=498., y=496.)
self.argparser.add_argument(
"--filter_height", action="store", type=float, default=46.77,
help="height of the filter along the flow direction (in mm)")
self.argparser.add_argument(
"--rim", action="store", type=float, default=30.,
help="rim around the filter holding it in place (in mm)")
self.argparser.add_argument(
"--fan_diameter", action="store", type=float, default=140.,
choices=list(self.fan_holes.keys()),
help="diameter of the fans (in mm)")
self.argparser.add_argument(
"--filters", action="store", type=int, default=2,
choices=(1, 2),
help="Filters on both sides or only one")
self.argparser.add_argument(
"--split_frames", action="store", type=BoolArg(), default=True,
help="Split frame pieces into four thin rectangles to save material")
self.argparser.add_argument(
"--fans_left", action="store", type=int, default=-1,
help="number of fans on the left side (-1 for maximal number)")
self.argparser.add_argument(
"--fans_right", action="store", type=int, default=-1,
help="number of fans on the right side (-1 for maximal number)")
self.argparser.add_argument(
"--fans_top", action="store", type=int, default=0,
help="number of fans on the top side (-1 for maximal number)")
self.argparser.add_argument(
"--fans_bottom", action="store", type=int, default=0,
help="number of fans on the bottom side (-1 for maximal number)")
self.argparser.add_argument(
"--screw_holes", action="store", type=float, default=5.,
help="diameter of the holes for screwing in the fans (in mm)")
def fanCB(self, n, h, l, fingerHoles=True, split_frames=False):
fh = self.filter_height
t = self.thickness
r = self.rim
def cb():
if fingerHoles:
heights = [fh + t/2]
if self.filters > 1:
heights.append(h - fh - t/2)
for h_ in heights:
if split_frames:
self.fingerHolesAt(0, h_, r, 0)
self.fingerHolesAt(r, h_, l-2*r, 0)
self.fingerHolesAt(l-r, h_, r, 0)
else:
self.fingerHolesAt(0, h_, l, 0)
max_n = int((l-20) // (self.fan_diameter + 10))
if n == -1:
n_ = max_n
else:
n_ = min(max_n, n)
if n_ == 0:
return
w = (l-20) / n_
x = 10 + w / 2
delta = self.fan_holes[self.fan_diameter] / 2
if self.filters==2:
posy = h / 2
else:
posy = (h + t + fh) / 2
for i in range(n_):
posx = x+i*w
self.hole(posx, posy, d=self.fan_diameter-4)
for dx in [-delta, delta]:
for dy in [-delta, delta]:
self.hole(posx + dx, posy + dy, d=self.screw_holes)
return cb
def render(self):
x, y, d = self.x, self.y, self.fan_diameter
t = self.thickness
r = self.rim
y = self.y = y - t # shorten by one thickness as we use the wall space
fh = self.filter_height
h = d + 2 + self.filters * (fh + t)
self.rectangularWall(x, d, "ffff", callback=[
self.fanCB(self.fans_top, d, x, False)], label="top", move="up")
self.rectangularWall(x, h, "ffff", callback=[
self.fanCB(self.fans_bottom, h, x)], label="bottom", move="up")
be = te = edges.CompoundEdge(self, "fff", (r, y - 2*r, r)) \
if self.split_frames else "f"
if self.filters==2:
le = edges.CompoundEdge(self, "EFE", (fh + t, d+2, fh + t))
else:
le = edges.CompoundEdge(self, "FE", (d+2, fh + t))
te = "f"
for fans in (self.fans_left, self.fans_right):
self.rectangularWall(
y, h, [be, "h", te, le],
callback=[self.fanCB(fans, h, y, split_frames=self.split_frames)],
move="up")
if self.split_frames:
e = edges.CompoundEdge(self, "DeD", (r, x - 2*r, r))
for _ in range(self.filters):
self.rectangularWall(x, r, ["E", "h", e, "h"], move="up")
self.rectangularWall(y - 2*r, r, "hded", move="up")
self.rectangularWall(y - 2*r, r, "hded", move="up")
self.rectangularWall(x, r, [e, "h", "h", "h"], move="up")
self.rectangularWall(x, r, ["F", "f", e, "f"], move="up")
self.rectangularWall(y - 2*r, r, "fded", move="up")
self.rectangularWall(y - 2*r, r, "fded", move="up")
self.rectangularWall(x, r, [e, "f", "f", "f"], move="up")
else:
for _ in range(self.filters):
self.rectangularWall(x, y, "Ffff", callback=[
lambda:self.rectangularHole(x/2, y/2, x - r, y - r, r=10)], move="up")
self.rectangularWall(x, y, "Ehhh", callback=[
lambda:self.rectangularHole(x/2, y/2, x - r, y - r, r=10)], move="up")
if self.filters==1:
self.rectangularWall(x, y, "hhhh", move="up")
| 6,801 | Python | .py | 144 | 35.569444 | 105 | 0.537255 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,617 | bottlestack.py | florianfesti_boxes/boxes/generators/bottlestack.py | # Copyright (C) 2013-2020 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 *
class BottleStack(Boxes):
"""Stack bottles in a fridge"""
description = """When rendered with the "double" option the parts with the double slots get connected the shorter beams in the asymmetrical slots.
Without the "double" option the stand is a bit more narrow.
"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.argparser.add_argument(
"--diameter", action="store", type=float, default=80,
help="diameter of the bottles in mm")
self.argparser.add_argument(
"--number", action="store", type=int, default=3,
help="number of bottles to hold in the bottom row")
self.argparser.add_argument(
"--depth", action="store", type=float, default=80,
help="depth of the stand along the base of the bottles")
self.argparser.add_argument(
"--double", action="store", type=boolarg, default=True,
help="two pieces that can be combined to up to double the width")
def front(self, h_sides, offset=0, move=None):
t = self.thickness
a = 60
nr = self.number
r1 = self.diameter / 2.0 # bottle
r2 = r1 / math.cos(math.radians(90-a)) - r1 # in between
if self.double:
r3 = 1.5*t # upper corners
else:
r3 = .5*t
h = (r1+r2) * (1-math.cos(math.radians(a)))
h_extra = 1*t
h_s = h_sides - t
p = 0.05*t # play
tw, th = nr * r1 * 2 + 2*r3, h + 2*t
if self.move(tw, th, move, True):
return
open_sides = r3 <= 0.5*t
if offset == 0:
slot = [0, 90, h_s, -90, t, -90, h_s, 90]
if open_sides:
self.moveTo(0, h_s)
self.polyline(r3-0.5*t)
self.polyline(*slot[4:])
else:
self.polyline(r3-0.5*t)
self.polyline(*slot)
for i in range(nr-open_sides):
self.polyline(2*r1-t)
self.polyline(*slot)
if open_sides:
self.polyline(2*r1-t)
self.polyline(*slot[:-3])
self.polyline(r3-0.5*t)
else:
self.polyline(r3-0.5*t)
else:
slot = [0, 90, h_s, -90, t, -90, h_s, 90]
h_s += t
slot2 = [0, 90, h_s, -90, t+2*p, -90, h_s, 90]
if open_sides:
self.moveTo(0, h_s)
self.polyline(t+p, -90, h_s, 90)
else:
self.polyline(r3-0.5*t-p)
self.polyline(*slot2)
self.polyline(t-p)
self.polyline(*slot)
self.polyline(2*r1-5*t)
self.polyline(*slot)
self.polyline(t-p)
self.polyline(*slot2)
for i in range(1, nr-open_sides):
self.polyline(2*r1-3*t-p)
self.polyline(*slot)
self.polyline(t-p)
self.polyline(*slot2)
if open_sides:
self.polyline(2*r1-3*t-p)
self.polyline(*slot)
self.polyline(t-p)
self.polyline(0, 90, h_s, -90, t+p)
else:
self.polyline(r3-0.5*t-p)
if open_sides:
h_extra -= h_s
self.polyline(0, 90, h_extra+h-r3, (90, r3))
for i in range(nr):
self.polyline(0, (a, r2), 0, (-2*a, r1), 0, (a, r2))
self.polyline(0, (90, r3), h_extra+h-r3, 90)
self.move(tw, th, move)
def side(self, l, h, short=False, move=None):
t = self.thickness
short = bool(short)
tw, th = l + 2*t - 4*t*short, h
if self.move(tw, th, move, True):
return
self.moveTo(t, 0)
self.polyline(l-3*t*short)
if short:
end = [90, h-t, 90, t, -90, t, 90]
else:
end = [(90, t), h-2*t, (90, t), 0, 90, t, -90, t, -90, t, 90]
self.polyline(0, *end)
self.polyline(l-2*t- 3*t*short)
self.polyline(0, *reversed(end))
self.move(tw, th, move)
def render(self):
t = self.thickness
d = self.depth
nr = self.number
h_sides = 2*t
pieces = 2 if self.double else 1
for offset in range(pieces):
self.front(h_sides, offset, move="up")
self.front(h_sides, offset, move="up")
for short in range(pieces):
for i in range(nr+1):
self.side(d, h_sides, short, move="up")
| 5,283 | Python | .py | 134 | 28.835821 | 150 | 0.530859 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,618 | _template.py | florianfesti_boxes/boxes/generators/_template.py | # Copyright (C) 2013-2016 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 *
class BOX(Boxes): # Change class name!
"""DESCRIPTION"""
ui_group = "Unstable" # see ./__init__.py for names
def __init__(self) -> None:
Boxes.__init__(self)
# Uncomment the settings for the edge types you use
# use keyword args to set default values
# self.addSettingsArgs(edges.FingerJointSettings, finger=1.0,space=1.0)
# self.addSettingsArgs(edges.DoveTailSettings)
# self.addSettingsArgs(edges.StackableSettings)
# self.addSettingsArgs(edges.HingeSettings)
# self.addSettingsArgs(edges.SlideOnLidSettings)
# self.addSettingsArgs(edges.ClickSettings)
# self.addSettingsArgs(edges.FlexSettings)
# self.addSettingsArgs(edges.HandleEdgeSettings)
# self.addSettingsArgs(edges.RoundedTriangleEdgeSettings)
# self.addSettingsArgs(edges.MountingSettings)
# remove cli params you do not need
self.buildArgParser(x=100, sx="3*50", y=100, sy="3*50", h=100, hi=0)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--XX", action="store", type=float, default=0.5,
help="DESCRIPTION")
def render(self):
# adjust to the variables you want in the local scope
x, y, h = self.x, self.y, self.h
t = self.thickness
# Create new Edges here if needed E.g.:
s = edges.FingerJointSettings(self.thickness, relative=False,
space = 10, finger=10,
width=self.thickness)
p = edges.FingerJointEdge(self, s)
p.char = "a" # 'a', 'A', 'b' and 'B' is reserved for being used within generators
self.addPart(p)
# render your parts here
| 2,498 | Python | .py | 50 | 42.26 | 89 | 0.665162 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,619 | planetary2.py | florianfesti_boxes/boxes/generators/planetary2.py | # Copyright (C) 2013-2016 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 *
class Planetary2(Boxes):
"""Balanced force Difference Planetary Gear (not yet working properly)"""
ui_group = "Unstable"
description = """Still has issues. The middle planetary gears set must not have a mashing sun gear as it can't be a proper gear set."""
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser("nema_mount")
self.argparser.add_argument(
"--profile", action="store", type=str, default="GT2_2mm",
choices=pulley.Pulley.getProfiles(),
help="profile of the teeth/belt")
self.argparser.add_argument(
"--sunteeth", action="store", type=int, default=20,
help="number of teeth on sun gear")
self.argparser.add_argument(
"--planetteeth", action="store", type=int, default=20,
help="number of teeth on planets")
self.argparser.add_argument(
"--maxplanets", action="store", type=int, default=0,
help="limit the number of planets (0 for as much as fit)")
self.argparser.add_argument(
"--deltateeth", action="store", type=int, default=1,
help="enable secondary ring with given delta to the ring gear")
self.argparser.add_argument(
"--modulus", action="store", type=float, default=1.0,
help="modulus of the teeth in mm")
self.argparser.add_argument(
"--shaft", action="store", type=float, default=6.,
help="diameter of the shaft")
self.argparser.add_argument(
"--screw1", action="store", type=float, default=2.4,
help="diameter of lower part of the screw hole")
self.argparser.add_argument(
"--screw2", action="store", type=float, default=4.,
help="diameter of upper part of the screw hole")
self.argparser.add_argument(
"--pinsize", action="store", type=float, default=3.1,
help="diameter of alignment pins")
# self.argparser.add_argument(
# "--stages", action="store", type=int, default=4,
# help="number of stages in the gear reduction")
def pins(self, r, rh, nr=0, angle=0.0):
self.moveTo(0, 0, angle)
if nr < 8:
ang = 20 + 10 * nr
else:
ang = 15 + 10 * (nr-8)
ang = 180 - ang
for a in (0, ang, -ang):
self.moveTo(0, 0, a)
self.hole(r, 0, rh)
self.moveTo(0, 0, -a)
def render(self):
ringteeth = self.sunteeth + 2 * self.planetteeth
t = self.thickness
spoke_width = 4 * t
pinsize = self.pinsize / 2.
pitch1, size1, xxx = self.gears.sizes(teeth=self.sunteeth,
dimension=self.modulus)
pitch2, size2, xxx = self.gears.sizes(teeth=self.planetteeth,
dimension=self.modulus)
pitch3, size3, xxx = self.gears.sizes(
teeth=ringteeth, internal_ring=True, spoke_width=spoke_width,
dimension=self.modulus)
planets = int(math.pi / (math.asin(float(self.planetteeth + 2) / (self.planetteeth + self.sunteeth))))
if self.maxplanets:
planets = min(self.maxplanets, planets)
# Make sure the teeth mash
ta = self.sunteeth + ringteeth
# There are sunteeth+ringteeth mashing positions for the planets
planetpositions = [round(i * ta / planets) * 360 / ta for i in range(planets)]
secondary_offsets = [((pos % (360. / (ringteeth - self.deltateeth))) -
(pos % (360. / ringteeth)) * ringteeth / self.planetteeth)
for pos in planetpositions]
ratio = (1 + (ringteeth / self.sunteeth)) * (-ringteeth/self.deltateeth)
# XXX make configurable?
profile_shift = 20
pressure_angle = 20
screw = self.screw1 / 2
# output
# XXX simple guess
belt = self.profile
pulleyteeth = int((size3-2*t) * math.pi / pulley.Pulley.spacing[belt][1])
numplanets = planets
deltamodulus = self.modulus * ringteeth / (ringteeth - self.deltateeth)
def holes(r):
def h():
self.hole(2*t, 2*t, r)
self.hole(size3-2*t, 2*t, r)
self.hole(2*t, size3-2*t, r)
self.hole(size3-2*t, size3-2*t, r)
return h
def planets():
self.moveTo(size3/2, size3/2)
for angle in planetpositions:
angle += 180 # compensate for 3 position in callback
self.moveTo(0, 0, angle)
self.hole((pitch1+pitch2), 0, size2/2)
self.moveTo(0, 0, -angle)
# Base
self.rectangularWall(size3, size3, callback=[
lambda: self.NEMA(self.nema_mount, size3 / 2, size3 / 2),
holes(screw), planets],
move="up")
def gear():
self.moveTo(size3 / 2, size3 / 2)
self.gears(teeth=ringteeth, dimension=self.modulus,
angle=pressure_angle, internal_ring=True,
spoke_width=spoke_width, teeth_only=True,
profile_shift=profile_shift, move="up")
# Lower primary ring gear
self.rectangularWall(size3, size3, callback=[gear, holes(screw)], move="up")
tl = 0.5*size3*(2**0.5-1)*2**0.5
screw = self.screw2 / 2
self.rectangularTriangle(tl, tl, num=8, callback=[
None, lambda:self.hole(2*t, 2*t, screw)], move='up')
# Secondary ring gears
def ring():
self.gears(teeth=ringteeth - self.deltateeth,
dimension=deltamodulus,
angle=pressure_angle, internal_ring=True,
spoke_width=spoke_width, teeth_only=True,
profile_shift=profile_shift)
for i in range(3):
self.hole((size3-6*t)/2+0.5*pinsize, 0, pinsize)
self.moveTo(0, 0, 120)
self.pulley(pulleyteeth, belt, callback=ring, move="up")
self.pulley(pulleyteeth, belt, callback=ring, move="up")
# Upper primary ring gear
self.rectangularWall(size3, size3, callback=[gear, holes(screw)], move="up")
# top cover plate
self.rectangularWall(size3, size3, callback=[holes(screw)], move="up")
# Sun gear
def sunpins():
self.hole(0.5*self.shaft+1.5*pinsize ,0, pinsize)
self.hole(-0.5*self.shaft-1.5*pinsize ,0, pinsize)
self.partsMatrix(4, 4, 'up', self.gears, teeth=self.sunteeth,
dimension=self.modulus, callback=sunpins,
angle=pressure_angle, mount_hole=self.shaft,
profile_shift=profile_shift)
# Planets
for i in range(numplanets):
with self.saved_context():
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
for j in range(2):
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i,
secondary_offsets[i]),
profile_shift=profile_shift, move="right")
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
profile_shift=profile_shift, move="up only")
self.text("1:%.1f" % abs(ratio))
| 8,894 | Python | .py | 176 | 37.329545 | 139 | 0.566889 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,620 | walldrillbox.py | florianfesti_boxes/boxes/generators/walldrillbox.py | # Copyright (C) 2013-2019 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 boxes.walledges import _WallMountedBox
from .drillstand import DrillStand
class WallDrillBox(DrillStand, _WallMountedBox):
"""Box for drills with each compartment with a different height"""
ui_group = "WallMounted"
def __init__(self) -> None:
_WallMountedBox.__init__(self) # don't call DrillStand.__init__
self.addSettingsArgs(edges.StackableSettings, height=1.0, width=3)
self.buildArgParser(sx="25*6", sy="10:20:30", sh="25:40:60")
self.argparser.add_argument(
"--extra_height", action="store", type=float, default=15.0,
help="height difference left to right")
def render(self):
self.generateWallEdges()
t = self.thickness
sx, sy, sh = self.sx, self.sy, self.sh
self.x = x = sum(sx) + len(sx)*t - t
self.y = y = sum(sy) + len(sy)*t - t
bottom_angle = math.atan(self.extra_height / x) # radians
self.xOutsideWall(sh[0], "hFeF", move="up")
for i in range(1, len(sy)):
self.xWall(i, move="up")
self.xOutsideWall(sh[-1], "hCec", move="up")
self.rectangularWall(x/math.cos(bottom_angle)-t*math.tan(bottom_angle), y, "fefe", callback=[self.bottomCB], move="up")
self.sideWall(edges="eBf", foot_height=2*t, move="right")
for i in range(1, len(sx)):
self.yWall(i, move="right")
self.sideWall(self.extra_height, foot_height=2*t, edges="eBf", move="right")
| 2,184 | Python | .py | 43 | 44.860465 | 127 | 0.66698 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,621 | ottosoles.py | florianfesti_boxes/boxes/generators/ottosoles.py | # Copyright (C) 2013-2018 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 *
class OttoSoles(Boxes):
"""Foam soles for the OttO bot"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=58., y=38.)
self.argparser.add_argument(
"--width", action="store", type=float, default=4.,
help="width of sole stripe")
self.argparser.add_argument(
"--chamfer", action="store", type=float, default=5.,
help="chamfer at the corners")
self.argparser.add_argument(
"--num", action="store", type=int, default=2,
help="number of soles")
def render(self):
x, y = self.x, self.y
c = self.chamfer
c2 = c * 2**0.5
w = min(self.width, c2 / 2. / math.tan(math.radians(22.5)))
w = self.width
w2 = w * 2**0.5 - c2 / 2
d = w * math.tan(math.radians(22.5))
self.edges["d"].settings.setValues(w, size=0.4, depth=0.3,
radius=0.05)
self.moveTo(0, y, -90)
for i in range(self.num*2):
if c2 >= 2 * d:
self.polyline((c2, 1), 45, (y-2*c, 1), 45, c2/2., 90)
self.edges["d"](w)
self.polyline(0, 90, c2/2-d, -45, (y-2*c-2*d, 1), -45,
(c2-2*d, 1), -45,
(x-2*c-2*d, 1), -45, c2/2-d, 90)
self.edges["D"](w)
self.polyline(0, 90, c2/2., 45, (x-2*c, 1), 45)
self.moveTo(0, w + c2/2. + 2*2**0.5*self.burn)
else:
self.polyline((c2, 1), 45, (y-2*c, 1), 45, c2/2., 90)
self.edges["d"](w2)
self.polyline(0, 45, (y-2*w, 1), -90, (x-2*w, 1), 45)
self.edges["D"](w2)
self.polyline(0, 90, c2/2., 45, (x-2*c, 3), 45)
self.moveTo(0, w * 2**0.5 + 2*2**0.5*self.burn)
| 2,630 | Python | .py | 58 | 35.051724 | 73 | 0.533203 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,622 | roundedregularbox.py | florianfesti_boxes/boxes/generators/roundedregularbox.py | # 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/>.
import math
import boxes
class RoundedRegularBox(boxes.Boxes):
"""Regular polygone box with vertical edges rounded"""
description = """"""
ui_group = "FlexBox"
def __init__(self) -> None:
boxes.Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(boxes.edges.DoveTailSettings)
self.addSettingsArgs(boxes.edges.FlexSettings)
self.buildArgParser(h="100.0")
self.argparser.add_argument(
"--sides", action="store", type=int, default=5,
help="number of sides")
self.argparser.add_argument(
"--inner_size", action="store", type=float, default=150,
help="diameter of the inner circle in mm")
self.argparser.add_argument(
"--radius", action="store", type=float, default=15,
help="Radius of the corners in mm")
self.argparser.add_argument(
"--wallpieces", action="store", type=int, default=0,
help="number of pieces for outer wall (0 for one per side)")
self.argparser.add_argument(
"--top", action="store", type=str, default="none",
choices=["closed", "hole", "lid",],
help="style of the top and lid")
def holeCB(self):
n = self.sides
t = self.thickness
poly = [self.side, (360 / n, self.radius-2*t)] * n
self.moveTo(-self.side/2, 2*t)
self.polygonWall(poly, edge="e", turtle=True)
def render(self):
n = self.sides
t = self.thickness
if self.wallpieces == 0:
self.wallpieces = n
_radius, height, side = self.regularPolygon(n, h=self.inner_size/2)
self.side = side = side - 2 * self.radius * math.tan(math.radians(360/2/n))
poly = [side/2, (360 / n, self.radius)]
parts = 1
for i in range(n-1):
if self.wallpieces * (i+1) / n >= parts:
poly.extend([side/2, 0, side/2, (360 / n, self.radius)])
parts += 1
else:
poly.extend([side, (360 / n, self.radius)])
poly.extend([side/2, 0])
with self.saved_context():
self.polygonWall(poly, move="right")
if self.top == "closed":
self.polygonWall(poly, move="right")
else:
self.polygonWall(poly, callback=[self.holeCB], move="right")
if self.top == "lid":
self.polygonWall([self.side, (360 / n, self.radius+t)] *n, edge="e", move="right")
self.polygonWall(poly, move="up")
self.moveTo(0, t)
self.polygonWalls(poly, self.h)
| 3,371 | Python | .py | 75 | 36.226667 | 98 | 0.608112 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,623 | smallpartstray.py | florianfesti_boxes/boxes/generators/smallpartstray.py | # Copyright (C) 2013-2016 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 boxes import lids
from boxes.edges import CompoundEdge
class SmallPartsTray(Boxes):
"""Tray with slants to easier get out game tokens or screws"""
ui_group = "Tray"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
# self.addSettingsArgs(edges.StackableSettings)
self.addSettingsArgs(lids.LidSettings)
self.buildArgParser(sx="50*3", y=100, h=30, outside=True)
self.argparser.add_argument(
"--angle", action="store", type=float, default=45.,
help="angle of the ramps")
self.argparser.add_argument(
"--rampheight", action="store", type=float, default=.5,
help="height of the ramps relative to to total height")
self.argparser.add_argument(
"--two_sided", action="store", type=boolarg, default=True,
help="have ramps on both sides. Enables sliding dividers")
self.argparser.add_argument(
"--front_panel", action="store", type=boolarg, default=True,
help="have a vertical wall at the ramp")
def innerWall(self, h, y, ramp_h, ramp_y, two_ramps, front=True,
move=None):
a = math.degrees(math.atan(ramp_h/ramp_y))
l = (ramp_h**2 + ramp_y**2)**.5
if two_ramps:
self.polygonWall(
[y-2*ramp_y, a, l, 90-a, h-ramp_h, 90, y,
90, h-ramp_h, 90-a, l, a],
"fffeff" if front else "ffeeef", move=move)
else:
self.polygonWall(
[y-ramp_y, 90, h, 90, y, 90, h-ramp_h, 90-a, l, a],
"ffeff" if front else "ffeef", move=move)
def outerWall(self, h, y, ramp_h, ramp_y, two_ramps, front=True,
move=None):
a = math.degrees(math.atan(ramp_h/ramp_y))
l = (ramp_h**2 + ramp_y**2)**.5
t = self.thickness
def cb():
with self.saved_context():
self.moveTo(ramp_y, 0, 180-a)
self.fingerHolesAt(0, 0.5*t, l, 0)
if two_ramps:
self.moveTo(y-ramp_y, 0, a)
self.fingerHolesAt(0, -0.5*t, l, 0)
if two_ramps:
self.rectangularWall(
y, h,
[CompoundEdge(self, "EFE", (ramp_y, y-2*ramp_y, ramp_y)),
CompoundEdge(self, "EF", (ramp_h, h-ramp_h)) if front else "e",
"e",
CompoundEdge(self, "FE", (h-ramp_h, ramp_h)) if front else "e"],
callback=[cb], move=move)
else:
self.rectangularWall(
y, h, [
CompoundEdge(self, "EF", (ramp_y, y-ramp_y)) if front else "e",
"F",
"e",
CompoundEdge(self, "FE", (h-ramp_h, ramp_h))],
callback=[cb], move=move)
def holeCB(self, sections, height):
def CB():
pos = -0.5 * self.thickness
for l in sections[:-1]:
pos += l + self.thickness
self.fingerHolesAt(pos, 0, height)
return CB
def render_simple_tray_divider(self, width, height, move):
"""
Simple movable divider. A wall with small feet for a little more stability.
"""
if self.move(width, height, move, True):
return
t = self.thickness
self.moveTo(t)
self.polyline(
width - 2 * t,
90,
t,
-90,
t,
90,
height - t,
90,
width,
90,
height - t,
90,
t,
-90,
t,
90,
)
self.move(width, height, move)
def render_simple_tray_divider_feet(self, move=None):
sqr2 = math.sqrt(2)
t = self.thickness
divider_foot_width = 2 * t
full_width = t + 2 * divider_foot_width
move_length = full_width / sqr2 + 2 * self.burn
move_width = full_width / sqr2 + 2 * self.burn
if self.move(move_width, move_length, move, True):
return
self.moveTo(self.burn)
self.ctx.save()
self.polyline(
sqr2 * divider_foot_width,
135,
t,
-90,
t,
-90,
t,
135,
sqr2 * divider_foot_width,
135,
full_width,
135,
)
self.ctx.restore()
self.moveTo(-self.burn / sqr2, self.burn * (1 + 1 / sqr2), 45)
self.moveTo(full_width)
self.polyline(
0,
135,
sqr2 * divider_foot_width,
135,
t,
-90,
t,
-90,
t,
135,
sqr2 * divider_foot_width,
135,
)
self.move(move_width, move_length, move)
def render(self):
# adjust to the variables you want in the local scope
sx, y, h = self.sx, self.y, self.h
t = self.thickness
a = self.angle
b = "e"
if self.outside:
self.sx = sx = self.adjustSize(sx)
self.h = h = self.adjustSize(h, False)
dy = t if self.front_panel else t / 2**0.5
self.y = y = self.adjustSize(y, dy, dy)
x = sum(sx) + (len(sx)-1) * t
ramp_h = h * self.rampheight
ramp_y = ramp_h / math.tan(math.radians(a))
if self.two_sided and (2*ramp_y + 3*t > y):
ramp_y = (y - 3*t) / 2
ramp_h = ramp_y * math.tan(math.radians(a))
elif ramp_y > y - t:
ramp_y = y - t
ramp_h = ramp_y * math.tan(math.radians(a))
ramp_l = (ramp_h**2 + ramp_y**2)**.5
with self.saved_context():
self.outerWall(h, y, ramp_h, ramp_y,
self.two_sided, self.front_panel, move="up")
self.outerWall(h, y, ramp_h, ramp_y,
self.two_sided, self.front_panel, move="mirror up")
for i in range(len(sx)-1):
self.innerWall(h, y, ramp_h, ramp_y,
self.two_sided, self.front_panel, move="up")
self.innerWall(h, y, ramp_h, ramp_y,
self.two_sided, self.front_panel, move="right only")
if self.front_panel:
self.rectangularWall(
x, h-ramp_h, "efef",
callback=[self.holeCB(sx, h-ramp_h)], move="up")
self.rectangularWall(x, ramp_l, "efef",
callback=[self.holeCB(sx, ramp_l)], move="up")
if self.two_sided:
self.rectangularWall(
x, y-2*ramp_y, "efef",
callback=[self.holeCB(sx, y-2*ramp_y)], move="up")
self.rectangularWall(
x, ramp_l, "efef",
callback=[self.holeCB(sx, ramp_l)], move="up")
if self.front_panel:
self.rectangularWall(
x, h-ramp_h, "efef",
callback=[self.holeCB(sx, h-ramp_h)], move="up")
else:
self.rectangularWall(
x, y-ramp_y, "efff",
callback=[self.holeCB(sx, y-ramp_y)], move="up")
self.rectangularWall(
x, h, "Ffef",
callback=[self.holeCB(sx, h)], move="up")
if self.two_sided:
with self.saved_context():
for l in self.sx:
self.render_simple_tray_divider(l, h, move="right")
self.partsMatrix(len(self.sx), 0, "right", self.render_simple_tray_divider_feet)
self.render_simple_tray_divider(l, h, move="up only")
self.lid(x, y)
| 8,531 | Python | .py | 218 | 27.188073 | 96 | 0.511116 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,624 | halfbox.py | florianfesti_boxes/boxes/generators/halfbox.py | # Copyright (C) 2013-2016 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 *
class HalfBox(Boxes):
"""Configurable half of a box which can be: a bookend, a hanging shelf, an angle clamping jig, ..."""
description = """This can be used to create:
* a hanging shelf:

* an angle clamping jig:

* a bookend:

and many more...
"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, finger=2.0,space=2.0)
self.addSettingsArgs(edges.MountingSettings)
self.buildArgParser(x=100, sy="50:50", h=100)
self.argparser.add_argument("--Clamping", action="store", type=boolarg, default=False, help="add clamping holes")
self.argparser.add_argument("--ClampingSize", action="store", type=float, default=25.0, help="diameter of clamping holes")
self.argparser.add_argument("--Mounting", action="store", type=boolarg, default=False, help="add mounting holes")
self.argparser.add_argument("--Sturdy", action="store", type=boolarg, default=False, help="create sturdy construction (e.g. shelf, clamping jig, ...)")
def polygonWallExt(self, borders, edge="f", turtle=False, callback=None, move=None):
# extended polygon wall.
# same as polygonWall, but with extended border parameters
# each border dataset consists of
# length
# turn angle
# radius of turn (without radius correction)
# edge type
for i in range(0, len(borders), 4):
self.cc(callback, i)
length = borders[i]
next_angle = borders[i+1]
next_radius = borders[i+2]
next_edge = borders[i+3]
e = self.edges.get(next_edge, next_edge)
if i == 0:
self.moveTo(0,e.margin(),0)
e(length)
if self.debug:
self.hole(0, 0, 1, color=Color.ANNOTATIONS)
self.corner(next_angle, tabs=0, radius=next_radius)
def xHoles(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
self.fingerHolesAt(posy, 0, self.x)
def hHoles(self):
posy = -0.5 * self.thickness
for y in reversed(self.sy[1:]):
posy += y + self.thickness
self.fingerHolesAt(posy, 0, self.h)
def render(self):
# adjust to the variables you want in the local scope
x, h = self.x, self.h
d = self.ClampingSize
t = self.thickness
# triangle with sides: x (horizontal), h (upwards) and l
# angles: 90° between x & h
# b between h & l
# c between l & x
l = math.sqrt(x * x + h * h)
b = math.degrees(math.asin(x / l))
c = math.degrees(math.asin(h / l))
if x > h:
if 90 + b + c < 179:
b = 180 - b
else:
if 90 + b + c < 179:
c = 180 - c
# small triangle top: 2*t, h1, l1
h1 = (2*t)/x*h
l1 = (2*t)/x*l
# small triangle left: x2, 2*t, l2
x2 = (2*t)/h*x
l2 = (2*t)/h*l
# render your parts here
if self.Sturdy:
width = sum(self.sy) + (len(self.sy) - 1) * t
self.rectangularWall(x, width, "fffe", callback=[None, self.xHoles, None, None], move="right", label="bottom")
self.rectangularWall(h, width, "fGfF" if self.Mounting else "fefF", callback=[None, None, None, self.hHoles], move="up", label="back")
self.rectangularWall(x, width, "fffe", callback=[None, self.xHoles, None, None], move="left only", label="invisible")
for i in range(2):
self.move(x+x2+2*t + self.edges["f"].margin(), h+h1+2*t + self.edges["f"].margin(), "right", True, label="side " + str(i))
self.polygonWallExt(borders=[x2, 0, 0, "e", x, 0, 0, "h",2*t, 90, 0, "e", 2*t, 0, 0, "e", h, 0, 0, "h",h1, 180-b, 0, "e", l+l1+l2, 180-c, 0, "e"])
if self.Clamping:
self.hole(0, 0, 1, color=Color.ANNOTATIONS)
self.rectangularHole(x/2+x2,2*t+d/2,dx=d,dy=d,r=d/8)
self.rectangularHole((x+x2+2*t)-2*t-d/2,h/2+2*t,dx=d,dy=d,r=d/8)
self.move(x+x2+2*t + self.edges["f"].margin(), h+h1+2*t + self.edges["f"].margin(), "right", False, label="side " + str(i))
if len(self.sy) > 1:
for i in range(len(self.sy) - 1):
self.move(x + self.edges["f"].margin(), h + self.edges["f"].margin(), "right", True, label="support " + str(i))
self.polygonWallExt(borders=[x, 90, 0, "f", h, 180-b, 0, "f", l, 180-c, 0, "e"])
if self.Clamping:
self.rectangularHole(x/2,d/2-t/2,dx=d,dy=d+t,r=d/8)
self.rectangularHole(x-d/2+t/2,h/2,dx=d+t,dy=d,r=d/8)
self.move(x + self.edges["f"].margin(), h + self.edges["f"].margin(), "right", False, label="support " + str(i))
else:
self.sy.insert(0,0)
self.sy.append(0)
width = sum(self.sy) + (len(self.sy) - 1) * t
self.rectangularWall(x, width, "efee", callback=[None, self.xHoles, None, None], move="right", label="bottom")
self.rectangularWall(h, width, "eGeF" if self.Mounting else "eeeF", callback=[None, None, None, self.hHoles], move="up", label="side")
self.rectangularWall(x, width, "efee", callback=[None, self.xHoles, None, None], move="left only", label="invisible")
for i in range(len(self.sy) - 1):
self.move(x + self.edges["f"].margin(), h + self.edges["f"].margin(), "right", True, label="support " + str(i))
self.polygonWallExt(borders=[x, 90, 0, "f", h, 180-b, 0, "f", l, 180-c, 0, "e"])
if self.Clamping:
self.rectangularHole(x/2,d/2,dx=d,dy=d,r=d/8)
self.rectangularHole(x-d/2,h/2,dx=d,dy=d,r=d/8)
self.move(x + self.edges["f"].margin(), h + self.edges["f"].margin(), "right", False, label="support " + str(i))
| 7,034 | Python | .py | 127 | 45.094488 | 162 | 0.57552 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,625 | spool.py | florianfesti_boxes/boxes/generators/spool.py | # Copyright (C) 2013-2016 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 *
class Spool(Boxes):
"""A simple spool"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(h=100)
self.argparser.add_argument(
"--outer_diameter", action="store", type=float, default=200.0,
help="diameter of the flanges")
self.argparser.add_argument(
"--inner_diameter", action="store", type=float, default=80.0,
help="diameter of the center part")
self.argparser.add_argument(
"--axle_diameter", action="store", type=float, default=40.0,
help="diameter of the axle hole (axle not part of drawing)")
self.argparser.add_argument(
"--sides", action="store", type=int, default=8,
help="number of pieces for the center part")
self.argparser.add_argument(
"--reinforcements", action="store", type=int, default=8,
help="number of reinforcement ribs per side")
self.argparser.add_argument(
"--reinforcement_height", action="store", type=float, default=0.0,
help="height of reinforcement ribs on the flanges")
def sideCB(self):
self.hole(0, 0, d=self.axle_diameter)
r, h, side = self.regularPolygon(self.sides, radius=self.inner_diameter/2)
t = self.thickness
for i in range(self.sides):
self.fingerHolesAt(-side/2, h+0.5*self.thickness, side, 0)
self.moveTo(0, 0, 360 / self.sides)
if self.reinforcement_height:
for i in range(self.reinforcements):
self.fingerHolesAt(
self.axle_diameter / 2, 0, h-self.axle_diameter / 2, 0)
self.fingerHolesAt(
r + t, 0, self.outer_diameter / 2 - r - t, 0)
self.moveTo(0, 0, 360 / self.reinforcements)
def reinforcementCB(self):
for i in range(self.reinforcements):
self.fingerHolesAt(
self.axle_diameter / 2, 0,
(self.inner_diameter - self.axle_diameter) / 2 + self.thickness, 0)
self.moveTo(0, 0, 360 / self.reinforcements)
def render(self):
t = self.thickness
r, h, side = self.regularPolygon(self.sides, radius=self.inner_diameter/2)
for i in range(2):
self.parts.disc(
self.outer_diameter, callback=self.sideCB, move="right")
for i in range(self.sides):
self.rectangularWall(side, self.h, "fefe", move="right")
if self.reinforcement_height:
for i in range(self.reinforcements*2):
edge = edges.CompoundEdge(
self, "fef",
[self.outer_diameter / 2 - r - t,
r - h + t,
h - self.axle_diameter / 2])
self.trapezoidWall(
self.reinforcement_height - t,
(self.outer_diameter - self.axle_diameter) / 2,
(self.inner_diameter - self.axle_diameter) / 2 + t,
["e", "f", "e", edge],
move="right")
for i in range(2):
self.parts.disc(
self.inner_diameter + 2*t,
hole=self.axle_diameter,
callback=self.reinforcementCB,
move="right")
| 4,149 | Python | .py | 87 | 36.402299 | 83 | 0.585679 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,626 | bottletag.py | florianfesti_boxes/boxes/generators/bottletag.py | # Copyright (C) 2013-2016 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 *
class BottleTag(Boxes):
"""Paper slip over bottle tag"""
ui_group = "Misc" # see ./__init__.py for names
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser()
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--width", action="store", type=float, default=72,
help="width of neck tag")
self.argparser.add_argument(
"--height", action="store", type=float, default=98,
help="height of neck tag")
self.argparser.add_argument(
"--min_diameter", action="store", type=float, default=24,
help="inner diameter of bottle neck hole")
self.argparser.add_argument(
"--max_diameter", action="store", type=float, default=50,
help="outer diameter of bottle neck hole")
self.argparser.add_argument(
"--radius", action="store", type=float, default=15,
help="corner radius of bottom tag")
self.argparser.add_argument(
"--segment_width", action="store", type=int, default=3,
help="inner segment width")
def render(self):
# adjust to the variables you want in the local scope
width = self.width
height = self.height
r_min = self.min_diameter / 2
r_max = self.max_diameter / 2
r = self.radius
segment_width = self.segment_width
# tag outline
self.moveTo(r)
self.edge(width - r - r)
self.corner(90, r)
self.edge(height - width / 2.0 - r)
self.corner(180, width / 2)
self.edge(height - width / 2.0 - r)
self.corner(90, r)
# move to centre of hole and cut the inner circle
self.moveTo(width / 2 - r, height - width / 2)
with self.saved_context():
self.moveTo(0, -r_min)
self.corner(360, r_min)
# draw the radial lines approx 2mm apart on r_min
seg_angle = math.degrees(segment_width / r_min)
# for neatness, we want an integral number of cuts
num = math.floor(360 / seg_angle)
for i in range(num):
with self.saved_context():
self.moveTo(0, 0, i * 360.0 / num)
self.moveTo(r_min)
self.edge(r_max - r_min)
# Add some right angle components to reduce tearing
with self.saved_context():
self.moveTo(0, 0, 90)
self.edge(0.5)
with self.saved_context():
self.moveTo(0, 0, -90)
self.edge(0.5)
| 3,374 | Python | .py | 77 | 34.532468 | 73 | 0.598418 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,627 | atreus21.py | florianfesti_boxes/boxes/generators/atreus21.py | """Generator for a split atreus keyboard."""
from boxes import Boxes, restore
from .keyboard import Keyboard
class Atreus21(Boxes, Keyboard):
"""Generator for a split atreus keyboard."""
ui_group = 'Misc'
btn_size = 15.6
half_btn = btn_size / 2
border = 6
def __init__(self) -> None:
super().__init__()
self.add_common_keyboard_parameters(
# By default, columns from Atreus 21
default_columns_definition=f'4@3/4@6/4@11/4@5/4@0/1@{self.btn_size * 0.5}'
)
def render(self):
"""Renders the keyboard."""
self.moveTo(10, 30)
case_x, case_y = self._case_x_y()
margin = 2 * self.border + 1
for reverse in [False, True]:
# keyholder
self.outer()
self.half(reverse=reverse)
self.holes()
self.moveTo(case_x + margin)
# support
self.outer()
self.half(self.support, reverse=reverse)
self.holes()
self.moveTo(-case_x - margin, case_y + margin)
# hotplug
self.outer()
self.half(self.hotplug, reverse=reverse)
self.holes()
self.moveTo(case_x + margin)
# border
self.outer()
self.rim()
self.holes()
self.moveTo(-case_x - margin, case_y + margin)
def holes(self, diameter=3, margin=1.5):
case_x, case_y = self._case_x_y()
for x in [-margin, case_x + margin]:
for y in [-margin, case_y + margin]:
self.hole(x, y, d=diameter)
def micro(self):
x = 17.9
y = 33
b = self.border
case_x, case_y = self._case_x_y()
self.rectangularHole(
x * -.5 + case_x + b * .5,
y * -.5 + case_y + b * .5,
x, y
)
@restore
def rim(self):
x, y = self._case_x_y()
self.moveTo(x * .5, y * .5)
self.rectangularHole(0, 0, x, y, 5)
@restore
def outer(self):
x, y = self._case_x_y()
b = self.border
self.moveTo(0, -b)
corner = [90, b]
self.polyline(*([x, corner, y, corner] * 2))
@restore
def half(self, hole_cb=None, reverse=False):
if hole_cb is None:
hole_cb = self.key
self.moveTo(self.half_btn, self.half_btn)
self.apply_callback_on_columns(
hole_cb,
self.columns_definition,
reverse=reverse,
)
def support(self):
self.configured_plate_cutout(support=True)
def hotplug(self):
self.pcb_holes(
with_hotswap=self.hotswap_enable,
with_pcb_mount=self.pcb_mount_enable,
with_diode=self.diode_enable,
with_led=self.led_enable,
)
def key(self):
self.configured_plate_cutout()
# get case sizes
def _case_x_y(self):
spacing = Keyboard.STANDARD_KEY_SPACING
margin = spacing - self.btn_size
x = len(self.columns_definition) * spacing - margin
y = max(offset + keys * spacing for (offset, keys) in self.columns_definition) - margin
return x, y
| 3,209 | Python | .py | 96 | 23.875 | 95 | 0.535252 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,628 | __init__.py | florianfesti_boxes/boxes/generators/__init__.py | from __future__ import annotations
import importlib
import inspect
import os
import pkgutil
from types import ModuleType
from typing import Any
import boxes
ui_groups_by_name = {}
class UIGroup:
def __init__(self, name: str, title: str | None = None, description: str = "", image: str = "") -> None:
self.name = name
self.title = title or name
self.description = description
self._image = image
self.generators: list[Any] = []
# register
ui_groups_by_name[name] = self
def add(self, box) -> None:
self.generators.append(box)
self.generators.sort(key=lambda b: getattr(b, '__name__', None) or b.__class__.__name__)
@property
def thumbnail(self) -> str:
return self._image and f"{self._image}-thumb.jpg"
@property
def image(self) -> str:
return self._image and f"{self._image}.jpg"
ui_groups: list[UIGroup] = [
UIGroup("Box", "Boxes", image="UniversalBox"),
UIGroup("FlexBox", "Boxes with flex", image="RoundedBox"),
UIGroup("Tray", "Trays and Drawer Inserts", image="TypeTray"),
UIGroup("Shelf", "Shelves", image="DisplayShelf"),
UIGroup("WallMounted", image="WallTypeTray"),
UIGroup("Holes", "Hole patterns", image=""),
UIGroup("Part", "Parts and Samples", image="BurnTest"),
UIGroup("Misc", image="TrafficLight"),
UIGroup("Unstable", description="Generators are still untested or need manual adjustment to be useful."),
]
def getAllBoxGenerators() -> dict[str, type[boxes.Boxes]]:
generators = {}
path = __path__
if "BOXES_GENERATOR_PATH" in os.environ:
path.extend(os.environ.get("BOXES_GENERATOR_PATH", "").split(":"))
for importer, modname, ispkg in pkgutil.walk_packages(path=path, prefix=__name__ + '.'):
module = importlib.import_module(modname)
if module.__name__.split('.')[-1].startswith("_"):
continue
for k, v in module.__dict__.items():
if v is boxes.Boxes:
continue
if inspect.isclass(v) and issubclass(v, boxes.Boxes) and v.__name__[0] != '_':
generators[modname + '.' + v.__name__] = v
return generators
def getAllGeneratorModules() -> dict[str, ModuleType]:
generators = {}
path = __path__
if "BOXES_GENERATOR_PATH" in os.environ:
path.extend(os.environ.get("BOXES_GENERATOR_PATH", "").split(":"))
for importer, modname, ispkg in pkgutil.walk_packages(
path=path,
prefix=__name__ + '.',
onerror=lambda x: None):
module = importlib.import_module(modname)
generators[modname.split('.')[-1]] = module
return generators
| 2,696 | Python | .py | 65 | 34.892308 | 109 | 0.626911 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,629 | walltypetray.py | florianfesti_boxes/boxes/generators/walltypetray.py | # 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/>.
from boxes import *
from boxes.lids import _TopEdge
from boxes.walledges import _WallMountedBox
class WallTypeTray(_WallMountedBox, _TopEdge):
"""Type tray - allows only continuous walls"""
def __init__(self) -> None:
super().__init__()
self.addSettingsArgs(edges.StackableSettings)
self.buildArgParser("sx", "sy", "h", "hi", "outside", "bottom_edge")
self.argparser.add_argument(
"--back_height", action="store", type=float, default=0.0,
help="additional height of the back wall")
self.argparser.add_argument(
"--radius", action="store", type=float, default=0.0,
help="radius for strengthening walls with the hooks")
def xSlots(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
posy = 0
for y in self.sy:
self.fingerHolesAt(posx, posy, y)
posy += y + self.thickness
def ySlots(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
posx = 0
for x in reversed(self.sx):
self.fingerHolesAt(posy, posx, x)
posx += x + self.thickness
def xHoles(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
self.fingerHolesAt(posx, 0, self.hi)
def yHoles(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
self.fingerHolesAt(posy, 0, self.hi)
def render(self):
self.generateWallEdges()
b = self.bottom_edge
if self.outside:
self.sx = self.adjustSize(self.sx)
self.sy = self.adjustSize(self.sy)
self.h = self.adjustSize(self.h, b, e2=False)
if self.hi:
self.hi = self.adjustSize(self.hi, b, e2=False)
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
y = sum(self.sy) + self.thickness * (len(self.sy) - 1)
h = self.h
bh = self.back_height
sameh = not self.hi
hi = self.hi = self.hi or h
t = self.thickness
# outer walls
# x sides
self.ctx.save()
# outer walls
self.rectangularWall(x, h, [b, "f", "e", "f"], callback=[self.xHoles], move="up")
self.rectangularWall(x, h+bh, [b, "C", "e", "c"], callback=[self.mirrorX(self.xHoles, x), ], move="up")
# floor
if b != "e":
self.rectangularWall(x, y, "ffff", callback=[
self.xSlots, self.ySlots], move="up")
# Inner walls
be = "f" if b != "e" else "e"
for i in range(len(self.sy) - 1):
e = [edges.SlottedEdge(self, self.sx, be), "f",
edges.SlottedEdge(self, self.sx[::-1], "e", slots=0.5 * hi), "f"]
self.rectangularWall(x, hi, e, move="up")
# y walls
# outer walls
self.trapezoidSideWall(y, h, h+bh, [b, "B", "e", "h"], radius=self.radius, callback=[self.yHoles, ], move="up")
self.moveTo(0, 8)
self.trapezoidSideWall(y, h+bh, h, [b, "h", "e", "b"], radius=self.radius, callback=[self.mirrorX(self.yHoles, y), ], move="up")
self.moveTo(0, 8)
# inner walls
for i in range(len(self.sx) - 1):
e = [edges.SlottedEdge(self, self.sy, be, slots=0.5 * hi),
"f", "e", "f"]
self.rectangularWall(y, hi, e, move="up")
| 4,271 | Python | .py | 98 | 34.469388 | 136 | 0.57377 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,630 | drillstand.py | florianfesti_boxes/boxes/generators/drillstand.py | # Copyright (C) 2013-2019 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/>.
import boxes
from boxes import *
class DrillStand(Boxes):
"""Box for drills with each compartment of a different height"""
description = """Note: `sh` gives the height of the rows front to back. It though should have the same number of entries as `sy`. These heights are the one on the left side and increase throughout the row. To have each compartment a bit higher than the previous one the steps in `sh` should be a bit bigger than `extra_height`.
Assembly:

Start with putting the slots of the inner walls together. Be especially careful with adding the bottom. It is always asymmetrical and flush with the right/lower side while being a little short on the left/higher side to not protrude into the side wall.
| | |
| ---- | ---- |
|  |  |
| Then add the front and the back wall. | Add the very left and right walls last. |
|  |  |
"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.StackableSettings, height=1.0, width=3)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(sx="25*6", sy="10:20:30", sh="25:40:60")
self.argparser.add_argument(
"--extra_height", action="store", type=float, default=15.0,
help="height difference left to right")
def yWall(self, nr, move=None):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
eh = self.extra_height * (sum(sx[:nr])+ nr*t - t)/x
tw, th = sum(sy) + t * len(sy) + t, max(sh) + eh
if self.move(tw, th, move, True):
return
self.moveTo(t)
self.polyline(y, 90)
self.edges["f"](sh[-1]+eh)
self.corner(90)
for i in range(len(sy)-1, 0, -1):
s1 = max(sh[i]-sh[i-1], 0) + 4*t
s2 = max(sh[i-1]-sh[i], 0) + 4*t
self.polyline(sy[i], 90, s1, -90, t, -90, s2, 90)
self.polyline(sy[0], 90)
self.edges["f"](sh[0] + eh)
self.corner(90)
self.move(tw, th, move)
def sideWall(self, extra_height=0.0, foot_height=0.0, edges="šFf", move=None):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
eh = extra_height
fh = foot_height
edges = [self.edges.get(e, e) for e in edges]
tw = sum(sy) + t * len(sy) + t
th = max(sh) + eh + fh + edges[0].spacing()
if self.move(tw, th, move, True):
return
self.moveTo(edges[0].margin())
edges[0](y+2*t)
self.edgeCorner(edges[0], "e")
self.edge(fh)
self.step(edges[1].startwidth() - t)
edges[1](sh[-1]+eh)
self.edgeCorner(edges[1], "e")
for i in range(len(sy)-1, 0, -1):
self.edge(sy[i])
if sh[i] > sh[i-1]:
self.fingerHolesAt(0.5*t, self.burn, sh[i]+eh, 90)
self.polyline(t, 90, sh[i] - sh[i-1], -90)
else:
self.polyline(0, -90, sh[i-1] - sh[i], 90, t)
self.fingerHolesAt(-0.5*t, self.burn, sh[i-1]+eh)
self.polyline(sy[0])
self.edgeCorner("e", edges[2])
edges[2](sh[0]+eh)
self.step(t - edges[2].endwidth())
self.polyline(fh)
self.edgeCorner("e", edges[0])
self.move(tw, th, move)
def xWall(self, nr, move=None):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
eh = self.extra_height
tw, th = x + 2*t, sh[nr] + eh + t
a = math.degrees(math.atan(eh / x))
fa = 1 / math.cos(math.radians(a))
if self.move(tw, th, move, True):
return
self.moveTo(t, eh+t, -a)
for i in range(len(sx)-1):
self.edges["f"](fa*sx[i])
h = min(sh[nr - 1], sh[nr])
s1 = h - 3.95*t + self.extra_height * (sum(sx[:i+1]) + i*t)/x
s2 = h - 3.95*t + self.extra_height * (sum(sx[:i+1]) + i*t + t)/x
self.polyline(0, 90+a, s1, -90, t, -90, s2, 90-a)
self.edges["f"](fa*sx[-1])
self.polyline(0, 90+a)
self.edges["f"](sh[nr]+eh)
self.polyline(0, 90, x, 90)
self.edges["f"](sh[nr])
self.polyline(0, 90+a)
self.move(tw, th, move)
def xOutsideWall(self, h, edges="fFeF", move=None):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
edges = [self.edges.get(e, e) for e in edges]
eh = self.extra_height
tw = x + edges[1].spacing() + edges[3].spacing()
th = h + eh + edges[0].spacing() + edges[2].spacing()
a = math.degrees(math.atan(eh / x))
fa = 1 / math.cos(math.radians(a))
if self.move(tw, th, move, True):
return
self.moveTo(edges[3].spacing(), eh+edges[0].margin(), -a)
self.edge(t*math.tan(math.radians(a)))
if isinstance(edges[0], boxes.edges.FingerHoleEdge):
with self.saved_context():
self.moveTo(0, 0, a)
self.fingerHolesAt(
0, 1.5*t, x*fa - t*math.tan(math.radians(a)), -a)
self.edge(x*fa - t*math.tan(math.radians(a)))
elif isinstance(edges[0], boxes.edges.FingerJointEdge):
edges[0](x*fa - t*math.tan(math.radians(a)))
else:
raise ValueError("Only edges h and f supported: ")
self.corner(a)
self.edgeCorner(edges[0], "e", 90)
self.corner(-90)
self.edgeCorner("e", edges[1], 90)
edges[1](eh+h)
self.edgeCorner(edges[1], edges[2], 90)
edges[2](x)
self.edgeCorner(edges[2], edges[3], 90)
edges[3](h)
self.edgeCorner(edges[3], "e", 90)
self.corner(-90)
self.edgeCorner("e", edges[0], 90)
self.moveTo(0, self.burn+edges[0].startwidth(), 0)
for i in range(1, len(sx)):
posx = sum(sx[:i]) + i*t - 0.5 * t
length = h + self.extra_height * (sum(sx[:i]) + i*t - t)/x
self.fingerHolesAt(posx, h, length, -90)
self.move(tw, th, move)
def bottomCB(self):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
eh = self.extra_height
a = math.degrees(math.atan(eh / x))
fa = 1 / math.cos(math.radians(a))
posy = -0.5 * t
for i in range(len(sy)-1):
posy += sy[i] + t
posx = -t * math.tan(math.radians(a)) # left side is clipped
for j in range(len(sx)):
self.fingerHolesAt(posx, posy, fa*sx[j], 0)
posx += fa*sx[j] + fa*t
def render(self):
t = self.thickness
sx, sy, sh = self.sx, self.sy, self.sh
self.x = x = sum(sx) + len(sx)*t - t
self.y = y = sum(sy) + len(sy)*t - t
bottom_angle = math.atan(self.extra_height / x) # radians
self.xOutsideWall(sh[0], "hFeF", move="up")
for i in range(1, len(sy)):
self.xWall(i, move="up")
self.xOutsideWall(sh[-1], "hfef", move="up")
self.rectangularWall(x/math.cos(bottom_angle)-t*math.tan(bottom_angle), y, "fefe", callback=[self.bottomCB], move="up")
self.sideWall(foot_height=self.extra_height+2*t, move="right")
for i in range(1, len(sx)):
self.yWall(i, move="right")
self.sideWall(self.extra_height, 2*t, move="right")
| 8,445 | Python | .py | 180 | 37.933333 | 331 | 0.57282 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,631 | brick_sorter.py | florianfesti_boxes/boxes/generators/brick_sorter.py | # Copyright (C) 2023 fidoriel
#
# 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 collections import OrderedDict
from typing import Tuple
from boxes import *
class BrickSorter(Boxes):
"""Stackable nestable sorting sieve for bricks"""
description = """## Stackable nestable sorting sieve for bricks
A stackable sorting sieve for bricks, nestable for storage.
You will need to export all 5 levels, to get a full sieve.
If you feel you do not need the upper levels, just do not export them.
x,y,h are the dimensions for the largest sieve,
they will be the outer dimensions of the box,
the smaller sieves will be nested inside, therefore smaller.
Of course 256mm or 384mm (base plate size) are recommended values for x and y,
but you can use any value you like.
Full set of all 5 levels:


Stacked for Usage:

Nested for Storage:

In Use:

"""
ui_group = "Box"
# level name, size of the holes in mm, and the thickness of the grid
sieve_sizes = OrderedDict(
(
("large_sieve", (30, 5)),
("medium_sieve", (20, 5)),
("small_sieve", (15, 4)),
("tiny_sieve", (10, 3)),
)
)
bottom_edge: str = "h"
level: str
radius: int
wiggle: float
edge_width: int = 3
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, edge_width=self.edge_width)
self.buildArgParser(x=256, y=256, h=120)
self.level_desc = list(self.sieve_sizes.keys()) + ["bottom"]
self.argparser.add_argument(
"--level",
action="store",
type=str,
default="large_sieve",
choices=self.level_desc,
help="Level of the nestable sieve",
)
self.argparser.add_argument(
"--radius",
action="store",
type=int,
default=3,
help="Radius of the corners of the sieve pattern in mm. Enter 30 for circular holes.",
)
self.argparser.add_argument(
"--wiggle",
action="store",
type=float,
default=4,
help="Wiggle room, that the layers can slide in each other."
)
for action in self.argparser._actions:
if action.dest in ["x", "y"]:
action.help = "outer width of the most outer layer"
@property
def _sieve_grid_thickness(self) -> int:
return self.sieve_sizes[self.level][1]
@property
def _sieve_level_index(self) -> int:
"""Return the index of the current sieve level, where 0 is the most outer sieve"""
return self.level_desc.index(self.level)
@property
def _outer_height_after_nesting(self) -> float:
return self.h - (((self.edge_width + 1) * self.thickness) * self._sieve_level_index) - (self._sieve_level_index * 2)
def _xy_after_nesting(self, a: float) -> float:
return a - ((2 * self.thickness + self.wiggle) * self._sieve_level_index)
@property
def _outer_x_after_nesting(self) -> float:
return self._xy_after_nesting(self.x)
@property
def _outer_y_after_nesting(self) -> float:
return self._xy_after_nesting(self.y)
@property
def _level_hole_size(self) -> float:
return self.sieve_sizes[self.level][0]
def _calc_hole_count(self, inner_mm_after_nesting: float) -> int:
return int(
(inner_mm_after_nesting - self._sieve_grid_thickness)
/ (self._level_hole_size + self._sieve_grid_thickness)
)
def _calc_grid_size_width_offset(
self, inner_mm_after_nesting: float
) -> Tuple[int, float]:
"""Return the size of the grid and the offset from the outer top right corner"""
hole_count = self._calc_hole_count(inner_mm_after_nesting)
grid_size = (
self._level_hole_size + self._sieve_grid_thickness
) * hole_count + self._sieve_grid_thickness
offset = (inner_mm_after_nesting - grid_size) / 2
return hole_count, offset
def _draw_sieve(self, x: float, y: float) -> None:
if self.level == "bottom":
raise Exception("Cannot draw sieve pattern on bottom level")
x_count, x_offset = self._calc_grid_size_width_offset(x)
y_count, y_offset = self._calc_grid_size_width_offset(y)
size = self._level_hole_size
for relx in range(x_count):
for rely in range(y_count):
x_pos = (
x
- x_offset
- size
- relx * (size + self._sieve_grid_thickness)
- self._sieve_grid_thickness
)
y_pos = (
y
- y_offset
- size
- rely * (size + self._sieve_grid_thickness)
- self._sieve_grid_thickness
)
self.rectangularHole(
x=x_pos,
y=y_pos,
dx=size,
dy=size,
r=self.radius,
center_x=False,
center_y=False,
)
def render(self):
# this is directly adapted from ABox.render
x, y, h = (
self._outer_x_after_nesting,
self._outer_y_after_nesting,
self._outer_height_after_nesting,
)
t1, t2, t3, t4 = "eeee"
b = self.edges.get(self.bottom_edge, self.edges["F"])
sideedge = "F"
self.x = x = self.adjustSize(x, sideedge, sideedge)
self.y = y = self.adjustSize(y)
self.h = h = self.adjustSize(h, b, t1)
with self.saved_context():
self.rectangularWall(
x, h, [b, sideedge, t1, sideedge], ignore_widths=[1, 6], move="up"
)
self.rectangularWall(
x, h, [b, sideedge, t3, sideedge], ignore_widths=[1, 6], move="up"
)
if self.level == "bottom":
callback = None
else:
callback = [lambda: self._draw_sieve(x, y)]
self.rectangularWall(x, y, "ffff", move="up", callback=callback)
self.rectangularWall(
x, h, [b, sideedge, t3, sideedge], ignore_widths=[1, 6], move="right only"
)
self.rectangularWall(y, h, [b, "f", t2, "f"], ignore_widths=[1, 6], move="up")
self.rectangularWall(y, h, [b, "f", t4, "f"], ignore_widths=[1, 6], move="up")
| 7,389 | Python | .py | 180 | 31.688889 | 124 | 0.585842 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,632 | laptopstand.py | florianfesti_boxes/boxes/generators/laptopstand.py | # Copyright (C) 2013-2016 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 math import *
from boxes import *
class LaptopStand(Boxes): # Change class name!
"""A simple X shaped frame to support a laptop on a given angle"""
ui_group = "Misc" # see ./__init__.py for names
def __init__(self) -> None:
Boxes.__init__(self)
self.argparser.add_argument(
"--l_depth",
action="store",
type=float,
default=250,
help="laptop depth - front to back (mm)",
)
self.argparser.add_argument(
"--l_thickness",
action="store",
type=float,
default=10,
help="laptop thickness (mm)",
)
self.argparser.add_argument(
"--angle",
action="store",
type=float,
default=15,
help="desired tilt of keyboard (deg)",
)
self.argparser.add_argument(
"--ground_offset",
action="store",
type=float,
default=10,
help="desired height between bottom of laptop and ground at lowest point (front of laptop stand)",
)
self.argparser.add_argument(
"--nub_size",
action="store",
type=float,
default=10,
help="desired thickness of the supporting edge",
)
def render(self):
calcs = self.perform_calculations()
self.laptopstand_triangles(calcs, move="up")
def perform_calculations(self):
# a
angle_rads_a = math.radians(self.angle)
# h
height = self.l_depth * math.sin(angle_rads_a)
# y
base = sqrt(2) * self.l_depth * math.cos(angle_rads_a)
# z
hyp = self.l_depth * sqrt(math.pow(math.cos(angle_rads_a), 2) + 1)
# b
angle_rads_b = math.atan(math.tan(angle_rads_a) / math.sqrt(2))
# g
base_extra = (
1
/ math.cos(angle_rads_b)
* (self.nub_size - self.ground_offset * math.sin(angle_rads_b))
)
# x
lip_outer = (
self.ground_offset / math.cos(angle_rads_b)
+ self.l_thickness
- self.nub_size * math.tan(angle_rads_b)
)
bottom_slot_depth = (height / 4) + (self.ground_offset / 2)
top_slot_depth_big = (
height / 4 + self.ground_offset / 2 + (self.thickness * height) / (2 * base)
)
top_slot_depth_small = (
height / 4 + self.ground_offset / 2 - (self.thickness * height) / (2 * base)
)
half_hyp = (hyp * (base - self.thickness)) / (2 * base)
return dict(
height=height,
base=base,
hyp=hyp,
angle=math.degrees(angle_rads_b),
base_extra=base_extra,
lip_outer=lip_outer,
bottom_slot_depth=bottom_slot_depth,
top_slot_depth_small=top_slot_depth_small,
top_slot_depth_big=top_slot_depth_big,
half_hyp=half_hyp,
)
def laptopstand_triangles(self, calcs, move=None):
tw = calcs["base"] + self.spacing + 2 * (calcs["base_extra"] + math.sin(math.radians(calcs["angle"]))*(calcs["lip_outer"]+1))
th = calcs["height"] + 2 * self.ground_offset + self.spacing
if self.move(tw, th, move, True):
return
self.moveTo(calcs["base_extra"]+self.spacing + math.sin(math.radians(calcs["angle"]))*(calcs["lip_outer"]+1))
self.draw_triangle(calcs, top=False)
self.moveTo(calcs["base"] - self.spacing,
th, 180)
self.draw_triangle(calcs, top=True)
self.move(tw, th, move)
@restore
def draw_triangle(self, calcs, top):
# Rear end
self.moveTo(0, calcs["height"] + self.ground_offset, -90)
self.edge(calcs["height"] + self.ground_offset)
self.corner(90)
foot_length = 10 + self.nub_size
base_length_without_feet = (
calcs["base"] - foot_length * 2 - 7 # -7 to account for extra width gained by 45deg angles
)
if top:
# Bottom without slot
self.polyline(
foot_length, 45,
5, -45,
base_length_without_feet, -45,
5, 45,
foot_length + calcs["base_extra"], 0,
)
else:
# Bottom with slot
self.polyline(
foot_length, 45,
5, -45,
(base_length_without_feet - self.thickness) / 2, 90,
calcs["bottom_slot_depth"] - 3.5, -90,
self.thickness, -90,
calcs["bottom_slot_depth"] - 3.5, 90,
(base_length_without_feet - self.thickness) / 2, -45,
5, 45,
foot_length + calcs["base_extra"], 0,
)
# End nub
self.corner(90 - calcs["angle"])
self.edge(calcs["lip_outer"])
self.corner(90, 1)
self.edge(self.nub_size - 2)
self.corner(90, 1)
self.edge(self.l_thickness)
self.corner(-90)
if top:
# Top with slot
self.edge(calcs["half_hyp"])
self.corner(90 + calcs["angle"])
self.edge(calcs["top_slot_depth_small"])
self.corner(-90)
self.edge(self.thickness)
self.corner(-90)
self.edge(calcs["top_slot_depth_big"])
self.corner(90 - calcs["angle"])
self.edge(calcs["half_hyp"])
else:
# Top without slot
self.edge(calcs["hyp"])
self.corner(90 + calcs["angle"])
| 6,361 | Python | .py | 168 | 27.434524 | 133 | 0.542607 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,633 | magazinefile.py | florianfesti_boxes/boxes/generators/magazinefile.py | # 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/>.
from boxes import *
from boxes.lids import _TopEdge
class MagazineFile(Boxes):
"""Open magazine file"""
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=100, y=200, h=300, hi=0, outside=False)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.MountingSettings, margin=0, num=1)
self.argparser.add_argument(
"--top_edge", action="store",
type=ArgparseEdgeType("eG"), choices=list("eG"),
default="e", help="edge type for top edge")
def side(self, w, h, hi, top_edge):
r = min(h - hi, w) / 2.0
if (h - hi) > w:
r = w / 2.0
lx = 0
ly = (h - hi) - w
else:
r = (h - hi) / 2.0
lx = (w - 2 * r) / 2.0
ly = 0
top_edge = self.edges.get(top_edge, top_edge)
e_w = self.edges["F"].startwidth()
self.moveTo(3, 3)
self.edge(e_w)
self.edges["F"](w)
self.edge(e_w)
self.corner(90)
self.edge(e_w)
self.edges["F"](hi)
self.corner(90)
self.edge(e_w)
top_edge(lx)
self.corner(-90, r)
self.edge(ly)
self.corner(90, r)
top_edge(lx)
self.edge(e_w)
self.corner(90)
self.edges["F"](h)
self.edge(e_w)
self.corner(90)
def render(self):
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h, e2=False)
x, y, h, = self.x, self.y, self.h
self.hi = hi = self.hi or (h / 2.0)
t = self.thickness
t1, t2, t3, t4 = _TopEdge.topEdges(self, self.top_edge)
with self.saved_context():
self.rectangularWall(x, h, ["F", "f", t2, "f"], move="up")
self.rectangularWall(x, hi, "Ffef", move="up")
self.rectangularWall(x, y, "ffff")
self.rectangularWall(x, h, "Ffef", move="right only")
self.side(y, h, hi, t1)
self.moveTo(y + 15, h + hi + 15, 180)
self.side(y, h, hi, t3)
| 2,852 | Python | .py | 75 | 30.066667 | 73 | 0.576547 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,634 | agricolainsert.py | florianfesti_boxes/boxes/generators/agricolainsert.py | # Copyright (C) 2020 Guillaume Collic
#
# 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/>.
import math
from functools import partial
from boxes import Boxes, edges
from .dividertray import DividerSlotsEdge, SlotDescriptionsGenerator
class AgricolaInsert(Boxes):
"""
Agricola Revised Edition game box insert, including some expansions.
"""
ui_group = "Misc"
description = """
This insert was designed with 3 mm plywood in mind, and should work fine with
materials around this thickness.
This is an insert for the [Agricola Revised Edition](https://boardgamegeek.com/boardgame/200680/agricola-revised-edition)
board game. It is specifically designed around the [Farmers Of The Moor expansion](https://boardgamegeek.com/boardgameexpansion/257344/agricola-farmers-moor),
and should also store the [5-6 players expansion](https://boardgamegeek.com/boardgameexpansion/210625/agricola-expansion-5-and-6-players)
(not tested, but I tried to take everything into account for it, please inform
us if you tested it).
It can be stored inside the original game box, including the 2 expansions,
with the lid slightly raised.
The parts of a given element are mostly generated next to each other vertically.
It should be straightforward to match them.
Here are the different elements, from left to right in the generated file.
#### Card tray
The cards are all kept in a tray, with paper dividers to sort them easily. When
the tray is not full of cards, wood dividers slides in slots in order to keep
the cards from falling into the empty space.
There should be enough space for the main game, Farmers Of The Moor, and the 5-6
player expansion, but not much more than that.
To keep a lower profile, the cards are at a slight angle, and the paper dividers
tabs are horizontal instead of vertical.
A small wall keeps the card against one side while the tabs protrude on the
other side, above the small wall.
The wall with the big hole is the sloped one. It goes between the two
"comb-like" walls first, with its two small holes at the bottom. Then there is a
low-height long wall with a sloped edge which should go from the sloped wall to
the other side. You can finish the tray with the last wall at the end.
#### Upper level trays
4 trays with movable walls are used to store resources. They were designed to
store them in this order:
* Stone / Vegetable / Pig / Cow
* Reed / Grain / Sheep
* Wood / Clay
* Food / Fire
The wall would probably be better if fixed instead of movable, but I would like
to test with the 5-6 player expansion to be sure their positions are correct
with it too.
The little feet of the movable wall should be glued. The triangles are put
horizontally, with their bases towards the sides.
#### Lower level tray
The lower level tray is used to store the horses.
#### Room/Field tiles
Two boxes are generated to store the room/field tiles. One for the wood/field,
the other for the clay/stone. They are stored with the main opening upside, but
I prefer to use them during play with this face on the side.
#### Moor/Forest and miscellaneous tiles
A box is generated to store the Moor/Forest tiles, and some other tiles such as
the "multiple resources" cardboard tokens.
The Moor/Forest tiles are at the same height as the Room/Field, and the upper
level trays are directly on them. The horse box and player box are slightly
lower. This Moor/Forest box have a lowered corner (the one for the miscellaneous
tiles). Two cardboard pieces can be stored between the smaller boxes and the
upper level trays (as seen on the picture).
Be sure to match the pieces so that the walls with smaller heights are next to
each other.
#### Players bit boxes
Each player has its own box where the bits of his color are stored.
The cardboard bed from Farmers Of The Moor is central to this box.
* The fences are stored inside the bed
* The bed is placed in the box, with holes to keep it there (and to take less
height)
* The stables are stored in the two corners
* The five farmers are stored between the bed and the three walls, alternatively
head up and head down.
During assembly, the small bars are put in the middle holes. The two bigger
holes at the ends are used for the bed feet. The bar keeps the bed from
protruding underneath.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.0)
def render(self):
player_box_height = 34.5
player_box_inner_width = 50.5
bigger_box_inner_height = 36.7
row_width = 37.2
tray_inner_height = 17
box_width = 218
card_tray_height = (
self.thickness * 2 + tray_inner_height + bigger_box_inner_height
)
card_tray_width = (
305.35 - player_box_inner_width * 2 - row_width * 2 - 9 * self.thickness
)
self.render_card_divider_tray(card_tray_height, box_width, card_tray_width)
self.render_upper_token_trays(tray_inner_height, box_width)
wood_room_box_width = 39.8
self.render_room_box(wood_room_box_width, bigger_box_inner_height, row_width)
stone_room_box_width = 26.7
self.render_room_box(stone_room_box_width, bigger_box_inner_height, row_width)
moor_box_length = 84.6
self.render_moor_box(
bigger_box_inner_height, player_box_height, row_width, moor_box_length
)
horse_box_margin = 0.5
horse_box_length = (
box_width
- wood_room_box_width
- stone_room_box_width
- moor_box_length
- 6 * self.thickness
- horse_box_margin
)
self.render_horse_box(player_box_height, row_width, horse_box_length)
for _ in range(6):
self.render_player_box(player_box_height, player_box_inner_width)
def render_card_divider_tray(
self, card_tray_height, card_tray_length, card_tray_width
):
"""
The whole tray which contains the cards, including its dividers.
Cards are at an angle, to save height.
"""
self.ctx.save()
tray_inner_length = card_tray_length - self.thickness
margin_for_score_sheet = 0 # 3 if you want more space for score sheet
sleeved_cards_width = 62 + margin_for_score_sheet
rad = math.acos(card_tray_height / sleeved_cards_width)
angle = math.degrees(rad)
cos = math.cos(rad)
tan = math.tan(rad)
sin = math.sin(rad)
slots_number = 19
slot_depth = 30
slot_descriptions = SlotDescriptionsGenerator().generate_all_same_angles(
[tray_inner_length / slots_number for _ in range(slots_number)],
self.thickness,
0.2,
slot_depth,
card_tray_height,
angle,
)
slot_descriptions.adjust_to_target_length(tray_inner_length)
sloped_wall_height = sleeved_cards_width - self.thickness * (tan + 1 / tan)
sloped_wall_posx_at_y0 = (
tray_inner_length - sloped_wall_height * tan - cos * self.thickness
)
sloped_wall_posx = sloped_wall_posx_at_y0 + cos * self.thickness / 2
sloped_wall_posy = sin * self.thickness / 2
dse = DividerSlotsEdge(self, slot_descriptions.descriptions)
for _ in range(2):
self.rectangularWall(
tray_inner_length,
card_tray_height,
["e", "e", dse, "f"],
move="up",
callback=[
partial(
lambda: self.fingerHolesAt(
sloped_wall_posx,
sloped_wall_posy,
sloped_wall_height,
angle=90 - angle,
)
)
],
)
# generate spacer
spacer_height = card_tray_height / 2
spacer_spacing = card_tray_width-99.8
spacer_upper_width = sloped_wall_posx_at_y0 + spacer_height * tan
self.trapezoidWall(
spacer_height,
spacer_upper_width,
sloped_wall_posx_at_y0,
"fefe",
move="up rotated",
)
self.rectangularWall(
card_tray_width,
card_tray_height,
"eFeF",
move="up",
callback=[
partial(
lambda: self.fingerHolesAt(
spacer_spacing - self.thickness / 2, 0, spacer_height
)
)
],
)
self.rectangularWall(
card_tray_width,
sloped_wall_height,
"efef",
move="up",
callback=[
partial(
self.generate_card_tray_sloped_wall_holes,
card_tray_width,
sloped_wall_height,
spacer_height,
spacer_spacing,
rad,
)
],
)
self.ctx.restore()
self.rectangularWall(card_tray_length, 0, "FFFF", move="right only")
self.ctx.save()
divider_height = sleeved_cards_width - self.thickness * tan
self.generate_divider(
card_tray_width, divider_height, slot_depth, spacer_spacing, "up"
)
self.explain(
[
"Wood divider",
"Hard separation to keep the card",
"from slipping in empty space left.",
"Takes more space, but won't move.",
"Duplicate as much as you want",
"(I use 2).",
]
)
self.ctx.restore()
self.rectangularWall(card_tray_width, 0, "ffff", move="right only")
self.ctx.save()
self.generate_paper_divider(
card_tray_width, sleeved_cards_width, slot_depth, spacer_spacing, "up"
)
self.explain(
[
"Paper divider",
"Soft separation to search easily",
"the card group you need",
"(by expansion, number of player,",
"etc.).",
"Duplicate as much as you want",
"(I use 7).",
]
)
self.ctx.restore()
self.rectangularWall(card_tray_width, 0, "ffff", move="right only")
def explain(self, strings):
self.text(
str.join(
"\n",
strings,
),
fontsize=7,
align="bottom left",
)
def generate_sloped_wall_holes(self, side_wall_length, rad, sloped_wall_height):
cos = math.cos(rad)
tan = math.tan(rad)
sin = math.sin(rad)
posx_at_y0 = side_wall_length - sloped_wall_height * tan
posx = posx_at_y0 - cos * self.thickness / 2
posy = sin * self.thickness / 2
self.fingerHolesAt(posx, posy, sloped_wall_height, angle=90 - math.degrees(rad))
def generate_card_tray_sloped_wall_holes(
self, side_wall_length, sloped_wall_height, spacer_height, spacer_spacing, rad
):
# Spacer finger holes
self.fingerHolesAt(
side_wall_length - (spacer_spacing - self.thickness / 2),
# the sloped wall doesn't exactly touch the bottom of the spacer
-self.thickness * math.tan(rad),
spacer_height / math.cos(rad),
)
# Big hole to access "lost" space behind sloped wall
radius = 5
padding = 8
total_loss = 2 * radius + 2 * padding
self.moveTo(radius + padding, padding)
self.polyline(
side_wall_length - total_loss,
(90, radius),
sloped_wall_height - total_loss,
(90, radius),
side_wall_length - total_loss,
(90, radius),
sloped_wall_height - total_loss,
(90, radius),
)
def generate_paper_divider(self, width, height, slot_depth, spacer_spacing, move):
"""
A card separation made of paper, which moves freely in the card tray.
Takes less space and easy to manipulate, but won't block cards in place.
"""
if self.move(width, height, move, True):
return
margin = 0.5
actual_width = width - margin
self.polyline(
actual_width - spacer_spacing,
90,
height - slot_depth,
-90,
spacer_spacing,
90,
slot_depth,
90,
actual_width,
90,
height,
90,
)
# Move for next piece
self.move(width, height, move)
def generate_divider(self, width, height, slot_depth, spacer_spacing, move):
"""
A card separation made of wood which slides in the side slots.
Can be useful to do hard separations, but takes more space and
less movable than the paper ones.
"""
total_width = width + 2 * self.thickness
if self.move(total_width, height, move, True):
return
radius = 16
padding = 20
divider_notch_depth = 35
self.polyline(
self.thickness + spacer_spacing + padding - radius,
(90, radius),
divider_notch_depth - radius - radius,
(-90, radius),
width - 2 * radius - 2 * padding - spacer_spacing,
(-90, radius),
divider_notch_depth - radius - radius,
(90, radius),
self.thickness + padding - radius,
90,
slot_depth,
90,
self.thickness,
-90,
height - slot_depth,
90,
width - spacer_spacing,
90,
height - slot_depth,
-90,
self.thickness + spacer_spacing,
90,
slot_depth,
)
# Move for next piece
self.move(total_width, height, move)
def render_horse_box(self, player_box_height, row_width, width):
"""
Box for the horses on lower level. Same height as player boxes.
"""
length = 2 * row_width + 3 * self.thickness
self.render_simple_tray(width, length, player_box_height)
def render_moor_box(
self, bigger_box_inner_height, player_box_height, row_width, length
):
"""
Box for the moor/forest tiles, and the cardboard tokens with multiple
units of resources.
A corner is lowered (the one for the tokens) at the same height as player boxes
to store 2 levels of small boards there.
"""
self.ctx.save()
height = bigger_box_inner_height
lowered_height = player_box_height - self.thickness
lowered_corner_height = height - lowered_height
corner_length = 53.5
self.rectangularWall(
length,
2 * row_width + self.thickness,
"FfFf",
move="up",
callback=[
partial(
lambda: self.fingerHolesAt(
0, row_width + 0.5 * self.thickness, length, 0
)
)
],
)
for i in range(2):
self.rectangularWall(
length,
lowered_height,
[
"f",
"f",
MoorBoxSideEdge(
self, corner_length, lowered_corner_height, i % 2 == 0
),
"f",
],
move="up",
)
self.rectangularWall(length, height / 2, "ffef", move="up")
for i in range(2):
self.rectangularWall(
2 * row_width + self.thickness,
lowered_height,
[
"F",
"F",
MoorBoxHoleEdge(self, height, lowered_corner_height, i % 2 == 0),
"F",
],
move="up",
callback=[
partial(self.generate_side_finger_holes, row_width, height / 2)
],
)
self.ctx.restore()
self.rectangularWall(length, 0, "FFFF", move="right only")
def generate_side_finger_holes(self, row_width, height):
self.fingerHolesAt(row_width + 0.5 * self.thickness, 0, height)
def render_room_box(self, width, height, row_width):
"""
A box in which storing room/field tiles.
"""
border_height = 12
room_box_length = row_width * 2 + self.thickness
self.ctx.save()
self.rectangularWall(
room_box_length,
height,
"eFfF",
move="up",
callback=[partial(self.generate_side_finger_holes, row_width, height)],
)
self.rectangularWall(
room_box_length,
width,
"FFfF",
move="up",
callback=[partial(self.generate_side_finger_holes, row_width, width)],
)
self.rectangularWall(
room_box_length,
border_height,
"FFeF",
move="up",
callback=[
partial(self.generate_side_finger_holes, row_width, border_height)
],
)
for _ in range(3):
self.trapezoidWall(width, height, border_height, "ffef", move="up")
self.ctx.restore()
self.rectangularWall(room_box_length, 0, "FFFF", move="right only")
def render_player_box(self, player_box_height, player_box_inner_width):
"""
A box in which storing all the bits of a single player,
including (and designed for) the cardboard bed from Farmers Of The Moor.
"""
self.ctx.save()
bed_inner_height = player_box_height - self.thickness
bed_inner_length = 66.75
bed_inner_width = player_box_inner_width
cardboard_bed_foot_height = 6.5
cardboard_bed_hole_margin = 5
cardboard_bed_hole_length = 12
bed_head_length = 20
bed_foot_height = 18
support_length = 38
bed_edge = Bed2SidesEdge(
self, bed_inner_length, bed_head_length, bed_foot_height
)
noop_edge = edges.NoopEdge(self)
self.ctx.save()
optim_180_x = (
bed_inner_length + self.thickness + bed_head_length + 2 * self.spacing
)
optim_180_y = 2 * bed_foot_height - player_box_height + 2 * self.spacing
for _ in range(2):
self.rectangularWall(
bed_inner_length,
bed_inner_height,
["F", bed_edge, noop_edge, "F"],
move="up",
)
self.moveTo(optim_180_x, optim_180_y, -180)
self.ctx.restore()
self.moveTo(0, bed_inner_height + self.thickness + self.spacing + optim_180_y)
self.rectangularWall(
bed_inner_length,
bed_inner_width,
"feff",
move="up",
callback=[
partial(
self.generate_bed_holes,
bed_inner_width,
cardboard_bed_hole_margin,
cardboard_bed_hole_length,
support_length,
)
],
)
self.ctx.save()
self.rectangularWall(
bed_inner_width,
bed_inner_height,
["F", "f", BedHeadEdge(self, bed_inner_height - 15), "f"],
move="right",
)
for _ in range(2):
self.rectangularWall(
cardboard_bed_foot_height - self.thickness,
support_length,
"efee",
move="right",
)
self.ctx.restore()
self.rectangularWall(
bed_inner_width,
bed_inner_height,
"Ffef",
move="up only",
)
self.ctx.restore()
self.rectangularWall(
bed_inner_length + bed_head_length + self.spacing - self.thickness,
0,
"FFFF",
move="right only",
)
def generate_bed_holes(self, width, margin, hole_length, support_length):
support_start = margin + hole_length
bed_width = 29.5
bed_space_to_wall = (width - bed_width) / 2
bed_feet_width = 3
posy_1 = bed_space_to_wall
posy_2 = width - bed_space_to_wall
for y, direction in [(posy_1, 1), (posy_2, -1)]:
bed_feet_middle_y = y + direction * bed_feet_width / 2
support_middle_y = y + direction * self.thickness / 2
self.rectangularHole(
margin,
bed_feet_middle_y,
hole_length,
bed_feet_width,
center_x=False,
)
self.fingerHolesAt(support_start, support_middle_y, support_length, angle=0)
self.rectangularHole(
support_start + support_length,
bed_feet_middle_y,
hole_length,
bed_feet_width,
center_x=False,
)
def render_upper_token_trays(self, tray_inner_height, box_width):
"""
Upper level : multiple trays for each resource
(beside horses which are on the lower level)
"""
tray_height = tray_inner_height + self.thickness
upper_level_width = 196
upper_level_length = box_width
row_width = upper_level_width / 3
# Stone / Vegetable / Pig / Cow
self.render_simple_tray(row_width, upper_level_length, tray_height, 3)
# Reed / Grain / Sheep
self.render_simple_tray(row_width, upper_level_length * 2 / 3, tray_height, 2)
# Wood / Clay
self.render_simple_tray(row_width, upper_level_length * 2 / 3, tray_height, 1)
# Food / Fire
self.render_simple_tray(upper_level_length / 3, row_width * 2, tray_height, 1)
def render_simple_tray(self, outer_width, outer_length, outer_height, dividers=0):
"""
One of the upper level trays, with movable dividers.
"""
width = outer_width - 2 * self.thickness
length = outer_length - 2 * self.thickness
height = outer_height - self.thickness
self.ctx.save()
self.rectangularWall(width, length, "FFFF", move="up")
for _ in range(2):
self.rectangularWall(width, height, "ffef", move="up")
self.ctx.restore()
self.rectangularWall(width, length, "FFFF", move="right only")
for _ in range(2):
self.rectangularWall(height, length, "FfFe", move="right")
if dividers:
self.ctx.save()
for _ in range(dividers):
self.render_simple_tray_divider(width, height, "up")
self.ctx.restore()
self.render_simple_tray_divider(width, height, "right only")
def render_simple_tray_divider(self, width, height, move):
"""
Simple movable divider. A wall with small feet for a little more stability.
"""
if self.move(height, width, move, True):
return
t = self.thickness
self.polyline(
height - t,
90,
t,
-90,
t,
90,
width - 2 * t,
90,
t,
-90,
t,
90,
height - t,
90,
width,
90,
)
self.move(height, width, move)
self.render_simple_tray_divider_feet(width, height, move)
def render_simple_tray_divider_feet(self, width, height, move):
sqr2 = math.sqrt(2)
t = self.thickness
divider_foot_width = 2 * t
full_width = t + 2 * divider_foot_width
move_length = self.spacing + full_width / sqr2
move_width = self.spacing + max(full_width, height)
if self.move(move_width, move_length, move, True):
return
self.ctx.save()
self.polyline(
sqr2 * divider_foot_width,
135,
t,
-90,
t,
-90,
t,
135,
sqr2 * divider_foot_width,
135,
full_width,
135,
)
self.ctx.restore()
self.moveTo(-self.burn / sqr2, self.burn * (1 + 1 / sqr2), 45)
self.moveTo(full_width)
self.polyline(
0,
135,
sqr2 * divider_foot_width,
135,
t,
-90,
t,
-90,
t,
135,
sqr2 * divider_foot_width,
135,
)
self.move(move_width, move_length, move)
class MoorBoxSideEdge(edges.BaseEdge):
"""
Edge for the sides of the moor tiles box
"""
def __init__(self, boxes, corner_length, corner_height, lower_corner) -> None:
super().__init__(boxes, None)
self.corner_height = corner_height
self.lower_corner = lower_corner
self.corner_length = corner_length
def __call__(self, length, **kw):
radius = self.corner_height / 2
if self.lower_corner:
self.polyline(
length - self.corner_height - self.corner_length,
(90, radius),
0,
(-90, radius),
self.corner_length,
)
else:
self.polyline(length)
def startwidth(self) -> float:
return self.corner_height
def endwidth(self) -> float:
return 0.0 if self.lower_corner else self.corner_height
class MoorBoxHoleEdge(edges.BaseEdge):
"""
Edge which does the notches for the moor tiles box
"""
def __init__(self, boxes, height, corner_height, lower_corner) -> None:
super().__init__(boxes, None)
self.height = height
self.corner_height = corner_height
self.lower_corner = lower_corner
def __call__(self, length, **kw):
one_side_width = (length - self.thickness) / 2
notch_width = 20
radius = 6
upper_edge = (one_side_width - notch_width - 2 * radius) / 2
hole_start = 10
lowered_hole_start = 2
hole_depth = self.height - 2 * radius
lower_edge = notch_width - 2 * radius
one_side_polyline = lambda margin1, margin2: [
upper_edge,
(90, radius),
hole_depth - margin1,
(-90, radius),
lower_edge,
(-90, radius),
hole_depth - margin2,
(90, radius),
upper_edge,
]
normal_side_polyline = one_side_polyline(hole_start, hole_start)
corner_side_polyline = one_side_polyline(
lowered_hole_start, lowered_hole_start + self.corner_height
)
full_polyline = (
normal_side_polyline
+ [0, self.thickness, 0]
+ (corner_side_polyline if self.lower_corner else normal_side_polyline)
)
self.polyline(*full_polyline)
def startwidth(self) -> float:
return self.corner_height
def endwidth(self) -> float:
return 0.0 if self.lower_corner else self.corner_height
class BedHeadEdge(edges.BaseEdge):
"""
Edge which does the head side of the Agricola player box
"""
def __init__(self, boxes, hole_depth) -> None:
super().__init__(boxes, None)
self.hole_depth = hole_depth
def __call__(self, length, **kw):
hole_length = 16
upper_corner = 10
lower_corner = 6
depth = self.hole_depth - upper_corner - lower_corner
upper_edge = (length - hole_length - 2 * upper_corner) / 2
lower_edge = hole_length - 2 * lower_corner
self.polyline(
upper_edge,
(90, upper_corner),
depth,
(-90, lower_corner),
lower_edge,
(-90, lower_corner),
depth,
(90, upper_corner),
upper_edge,
)
class Bed2SidesEdge(edges.BaseEdge):
"""
Edge which does a bed like shape, skipping the next corner.
The next edge should be a NoopEdge
"""
def __init__(self, boxes, bed_length, full_head_length, full_foot_height) -> None:
super().__init__(boxes, None)
self.bed_length = bed_length
self.full_head_length = full_head_length
self.full_foot_height = full_foot_height
def __call__(self, bed_height, **kw):
foot_corner = 6
middle_corner = 3
head_corner = 10
foot_height = self.full_foot_height - self.thickness - foot_corner
head_length = self.full_head_length - head_corner - self.thickness
corners = foot_corner + middle_corner + head_corner
head_height = bed_height - foot_height - corners
middle_length = self.bed_length - head_length - corners
self.polyline(
foot_height,
(90, foot_corner),
middle_length,
(-90, middle_corner),
head_height,
(90, head_corner),
head_length,
)
| 30,067 | Python | .py | 793 | 27.461538 | 158 | 0.567978 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,635 | silverwarebox.py | florianfesti_boxes/boxes/generators/silverwarebox.py | # 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/>.
from boxes import Boxes, restore
class Silverware(Boxes):
"""
Cuttlery stand with carrying grip
using flex for rounded corners
"""
ui_group = "Unstable"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=250, y=154, h=120)
self.argparser.add_argument(
"--cornerradius", action="store", type=int, default=30,
help="Radius of the corners")
self.argparser.add_argument(
"--handleheight", action="store", type=int, default=150,
help="Height of the handle")
self.argparser.add_argument(
"--handlewidth", action="store", type=int, default=120,
help="Width of the handle")
####################################################################
### Parts
####################################################################
def basePlate(self, x, y, r):
self.roundedPlate(x, y, r, extend_corners=False, callback=[
lambda: self.fingerHolesAt(x / 3.0 - r, 0, 0.5 * (y - self.thickness)),
lambda: self.fingerHolesAt(x / 6.0, 0, 0.5 * (y - self.thickness)),
lambda: self.fingerHolesAt(y / 2.0 - r, 0, x),
lambda: self.fingerHolesAt(x / 2.0 - r, 0, 0.5 * (y - self.thickness))
])
def wall(self, x=100, y=100, h=100, r=0):
self.surroundingWall(x, y, r, h, top="E", bottom='h', callback={
0: lambda: self.fingerHolesAt(x / 6.0, 0, h - 10),
4: lambda: self.fingerHolesAt(x / 3.0 - r, 0, h - 10),
1: lambda: self.fingerHolesAt(y / 2.0 - r, 0, h - 10),
3: lambda: self.fingerHolesAt(y / 2.0 - r, 0, h - 10),
2: lambda: self.fingerHolesAt(x / 2.0 - r, 0, h - 10),
},
move="up")
@restore
def centerWall(self, x, h):
self.moveTo(self.edges["f"].spacing(), self.edges["f"].spacing())
for i in range(2, 5):
self.fingerHolesAt(i * x / 6.0, 0, h - 10)
self.edges["f"](x)
self.corner(90)
self.edges["f"](h - 10)
self.corner(90)
self.handle(x, self.handleheight, self.handlewidth)
self.corner(90)
self.edges["f"](h - 10)
self.corner(90)
self.ctx.stroke()
##################################################
### main
##################################################
def render(self):
x = self.x
y = self.y
h = self.h
r = self.cornerradius
t = self.thickness
b = self.burn
self.wall(x, y, h, r)
self.centerWall(x, h)
self.moveTo(x + 2 * self.edges["f"].spacing())
l = (y - t) / 2.0
for _ in range(3):
self.rectangularWall(l, h - 10, edges="ffef", move="right")
self.moveTo(-3.0 * (l + 2 * t + 8 * b), h - 10 + 2 * t + 8 * b)
self.basePlate(x, y, r)
| 3,623 | Python | .py | 84 | 35.130952 | 83 | 0.535267 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,636 | wallwrenchholder.py | florianfesti_boxes/boxes/generators/wallwrenchholder.py | # Copyright (C) 2013-2019 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 boxes.walledges import _WallMountedBox
class SlottedEdge(edges.Edge):
def __call__(self, length, **kw):
n = self.number
t = self.thickness
self.polyline(t, 45)
l = t
for i in range(n):
w = self.min_width * ((n-i)/n) + self.max_width * (i / n)
s = self.min_strength * ((n-i)/n) + self.max_strength * (i / n)
if i == n-1:
self.polyline(w-s/2+2*s, (-180, s/2), w - 0.5*s,
(180, s/2))
l += s *2 * 2**0.5
else:
self.polyline(w-s/2+2*s, (-180, s/2), w - 0.5*s,
(135, s/2), self.extra_distance, (45, s/2))
l += s *2 * 2**0.5 + self.extra_distance
self.polyline(0, -45)
self.edge(length-l)
class WallWrenchHolder(_WallMountedBox):
"""Hold a set of wrenches at a wall"""
def __init__(self) -> None:
super().__init__()
# remove cli params you do not need
self.buildArgParser(x=100)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--depth", action="store", type=float, default=30.0,
help="depth of the sides (in mm)")
self.argparser.add_argument(
"--number", action="store", type=int, default=11,
help="number of wrenches (in mm)")
self.argparser.add_argument(
"--min_width", action="store", type=float, default=8.0,
help="width of smallest wrench (in mm)")
self.argparser.add_argument(
"--max_width", action="store", type=float, default=25.0,
help="width of largest wrench (in mm)")
self.argparser.add_argument(
"--min_strength", action="store", type=float, default=3.0,
help="strength of smallest wrench (in mm)")
self.argparser.add_argument(
"--max_strength", action="store", type=float, default=5.0,
help="strength of largest wrench (in mm)")
self.argparser.add_argument(
"--extra_distance", action="store", type=float, default=0.0,
help="additional distance between wrenches (in mm)")
def render(self):
self.generateWallEdges()
h = ((self.min_strength + self.max_strength) * self.number * 2**0.5
+ self.extra_distance * (self.number - 1)
+ self.max_width)
t = self.thickness
x = self.x-2*t
self.rectangularWall(self.depth, h,
["e", "B", "e", SlottedEdge(self, None)],
move="right")
self.rectangularWall(self.depth, h,
["e", "B", "e", SlottedEdge(self, None)],
move="right")
self.rectangularWall(x, h, "eDed",
# callback=[lambda:self.fingerHolesAt(x/2, 0, h, 90)],
move="right")
| 3,683 | Python | .py | 79 | 36.278481 | 75 | 0.567447 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,637 | holepattern.py | florianfesti_boxes/boxes/generators/holepattern.py | # Copyright (C) 2013-2022 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 *
class HolePattern(Boxes):
"""Generate hole patterns in different simple shapes"""
ui_group = "Holes"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(fillHolesSettings, fill_pattern="hex")
self.buildArgParser("x", "y")
self.argparser.add_argument(
"--shape", action="store", type=str, default="rectangle",
choices=["rectangle", "ellipse", "oval", "hexagon", "octagon"],
help="Shape of the hole pattern")
def render(self):
x, y = self.x, self.y
if self.shape == "ellipse":
border = [(x * (.5+math.sin(math.radians(a))/2),
y * (.5+math.cos(math.radians(a))/2))
for a in range(0, 360, 18)]
elif self.shape == "oval":
r = min(x, y) / 2
dx = max(x-y, 0)
dy = max(y-x, 0)
border = [(r * (.5+math.cos(math.radians(a))/2) +
(dx if q in [0, 3] else 0),
r * (.5+math.sin(math.radians(a))/2) +
(dy if q in [1, 2] else 0))
for q in range(4)
for a in range(90*q, 90*q+91, 18)]
elif self.shape == "hexagon":
dx = min(y / (3**.5) / 2, x / 2)
border = [(dx, 0), (x-dx, 0), (x, .5*y),
(x-dx, y), (dx, y), (0, .5*y)]
elif self.shape == "octagon":
d = (2**.5/(2+2*2**.5))
d2 = 1 -d
border = [(d*x, 0), (d2*x, 0), (x, d*y), (x, d2*y),
(d2*x, y), (d*x, y), (0, d2*y), (0, d*y)]
else: # "rectangle"
border = [(0, 0), (x, 0), (x, y), (0, y)]
self.fillHoles(
pattern=self.fillHoles_fill_pattern,
border=border,
max_radius=self.fillHoles_hole_max_radius,
hspace=self.fillHoles_space_between_holes,
bspace=self.fillHoles_space_to_border,
min_radius=self.fillHoles_hole_min_radius,
style=self.fillHoles_hole_style,
bar_length=self.fillHoles_bar_length,
max_random=self.fillHoles_max_random
)
| 2,907 | Python | .py | 64 | 34.984375 | 75 | 0.539005 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,638 | dinrailbox.py | florianfesti_boxes/boxes/generators/dinrailbox.py | # Copyright (C) 2013-2020 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 *
class DinRailEdge(edges.FingerHoleEdge):
def __init__(self, boxes, settings, width=35.0, offset=0.0) -> None:
super().__init__(boxes, settings)
self.width = width
self.offset = offset
def startwidth(self) -> float:
return 8 + self.settings.thickness
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
with self.saved_context():
self.fingerHoles(
0, self.burn + 8 + self.settings.thickness / 2, length, 0,
bedBolts=bedBolts, bedBoltSettings=bedBoltSettings)
w = self.width
o = self.offset
l = length
self.polyline((l-w)/2-o, 45, 2.75*2**.5, 90, 2.75*2**.5, -45, .5, -90,
w+0.25,
-90, 1, 30, 5*2*3**-.5, 60, (l-w)/2+o-3.25)
class DinRailBox(Boxes):
"""Box for DIN rail used in electrical junction boxes"""
ui_group = "WallMounted"
def latch(self, l, move=None):
t = self.thickness
tw = l+3+6+t
th = 8
if self.move(tw, th, move, True):
return
self.moveTo(tw, th, 180)
self.polyline(2, 90, 0, (-180, 1.5), 0, 90, l+1.2*t, 90,
3, -90, 1, 30, 2*2*3**-.5, 90, 4.5*2*3**-.5, 60,
4+1.25, 90, 4.5, -90, t+4, -90, 2, 90, l-.8*t-9, 90, 2, -90, 5+t, 90, 4, 90)
self.move(tw, th, move)
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=.8)
self.buildArgParser(x=70, y=90, h=60)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--rail_width", action="store", type=float, default=35.,
help="width of the rail (typically 35 or 15mm)")
self.argparser.add_argument(
"--rail_offset", action="store", type=float, default=0.,
help="offset of the rail from the middle of the box (in mm)")
def spring(self):
t = self.thickness
l = min(self.x/2-1.5*t, 50)
self.moveTo(self.x/2-l, -6-t, 0)
self.polyline(l+0.525*t, 90 , 6, 90 , 1.1*t, 90, 3, -90, l-0.525*t,
180, l-0.525*t, -90, 1+0.1*t, 90, t-0.5, -90, 2)
def lid_lip(self, l, move=None):
t = self.thickness
tw, th = l+2, t+8
if self.move(tw, th, move, True):
return
self.moveTo(1, t)
self.edges["f"](l)
poly = [0, 90, 6, -60, 0, (120, 2*3**-.5), 0, 30, 2, 90, 5,
(-180, .5), 5, 90]
self.polyline(*(poly+[l-2*3]+list(reversed(poly))))
self.move(tw, th, move)
def lid_holes(self):
t = self.thickness
self.rectangularHole(0.55*t, 7, 1.1*t, 1.6)
self.rectangularHole(self.x-0.55*t, 7, 1.1*t, 1.6)
def render(self):
# adjust to the variables you want in the local scope
x, y, h = self.x, self.y, self.h
w = self.rail_width
o = self.rail_offset
t = self.thickness
self.rectangularWall(x, y, "EEEE", callback=[
lambda:self.fingerHolesAt(.55*t, .05*t, y-.1*t, 90), None,
lambda:self.fingerHolesAt(.55*t, .05*t, y-.1*t, 90), None],
move="right", label="Lid")
self.lid_lip(y-.1*t, move="rotated right")
self.lid_lip(y-.1*t, move="rotated right")
self.rectangularWall(x, y, "ffff",
callback=[
lambda:self.fingerHolesAt(0, (y-w)/2-0.5*t+o-9, x, 0)],
move="right", label="Back")
# Change h edge to 8mm!
self.edges["f"].settings.setValues(t, False, edge_width=8)
dr = DinRailEdge(self, self.edges["f"].settings, w, o)
self.rectangularWall(y, h, [dr, "F", "e", "F"],
ignore_widths=[1, 6], move="rotated right",
label="Left Side upsidedown")
self.rectangularWall(y, h, [dr, "F", "e", "F"],
ignore_widths=[1, 6], move="rotated mirror right",
label="Right Side")
self.rectangularWall(x, h, ["h", "f", "e", "f"],
ignore_widths=[1, 6], callback=[
self.spring, None, self.lid_holes],
move="up",
label="Bottom")
self.rectangularWall(x, h, ["h", "f", "e", "f"],
callback=[None, None, self.lid_holes],
ignore_widths=[1, 6], move="up",
label="Top")
self.rectangularWall(x, 8, "feee", callback=[
lambda:self.rectangularHole(x/2, 2.05-0.5*t, t, t+4.1)], move="up")
self.latch((y-w)/2+o, move="up")
| 5,569 | Python | .py | 116 | 36.439655 | 98 | 0.533665 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,639 | bookholder.py | florianfesti_boxes/boxes/generators/bookholder.py | # Copyright (C) 2013-2019 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 *
class BookHolder(Boxes):
"""Angled display stand for books, ring files, flyers, postcards, or business cards."""
description = """
Smaller versions for postcards (with a small ledge) and for business cards:


BookHolder with default parameters (A4 size, landscape, back_support):

"""
ui_group = "Misc"
def __init__(self) -> None:
super().__init__()
self.addSettingsArgs(edges.FingerJointSettings)
# Default size: DIN A4 (210mm * 297mm)
self.argparser.add_argument(
"--book_width", action="store", type=float, default=297.0,
help="total width of book stand")
self.argparser.add_argument(
"--book_height", action="store", type=float, default=210.0,
help="height of the front plate")
self.argparser.add_argument(
"--book_depth", action="store", type=float, default=40.0,
help="larger sizes for books with more pages")
self.argparser.add_argument(
"--ledge_height", action="store", type=float, default=0.0,
help="part in front to hold the book open (0 to turn off)")
self.argparser.add_argument(
"--angle", action="store", type=float, default=75.0,
help="degrees between floor and front plate")
self.argparser.add_argument(
"--bottom_support", action="store", type=float, default=20.0,
help="extra material on bottom to raise book up")
self.argparser.add_argument(
"--back_support", action="store", type=float, default=50.0,
help="height of additional support in the back (0 to turn off)")
self.argparser.add_argument(
"--radius", action="store", type=float, default=-1.0,
help="radius at the sharp corners (negative for radius=thickness)")
def sideWall(self, move=None):
# main angle
alpha = self.angle
# opposite angle
beta = 90 - alpha
# 1. Calculate the tall right triangle between front plate and back
# self.book_height is hypotenuse
# vertical piece
a = self.book_height * math.sin(math.radians(alpha))
# horizontal piece
b = self.book_height * math.sin(math.radians(beta))
# 2. Calculate the smaller triangle between bottom of book and front edge
# self.book_depth is hypotenuse, angles are the same as in other triangle but switched
# vertical piece
c = self.book_depth * math.sin(math.radians(beta))
# horizontal piece
d = self.book_depth * math.sin(math.radians(alpha))
# 3. Total dimensions
# Highest point on the right where the book back rests
max_height_back = a + self.bottom_support + self.radius
# Highest point on the left where the book bottom rests
max_height_front = c + self.bottom_support + self.radius
total_height = max(max_height_back, max_height_front)
offset_s = math.sin(math.radians(alpha)) * self.radius
offset_c = math.cos(math.radians(alpha)) * self.radius
total_width = self.radius + offset_c + b + d + offset_s + self.radius
if self.move(total_width, total_height, move, True):
return
# Line on bottom
self.polyline(total_width, 90)
# Fingerholes for back support
if self.back_support > 0:
posx = self.bottom_support
posy = 2 * self.thickness
self.fingerHolesAt(posx, posy, self.back_support, 0)
# Back line straight up
self.polyline(max_height_back - offset_c - self.radius, 0)
self.corner((90+alpha, self.radius))
# Line for front plate
self.edges.get("F")(self.book_height)
self.corner(-90)
# Line where bottom of book rests
self.edges.get("F")(self.book_depth)
self.corner((90+beta, self.radius))
# Front line straight down
self.polyline(max_height_front - offset_s - self.radius, 90)
self.move(total_width, total_height, move)
def front_ledge(self, move):
total_height = self.ledge_height + self.thickness
if self.move(self.width, total_height, move, True):
return
self.moveTo(self.radius, 0)
h = total_height - self.radius
w = self.width - 2 * self.radius
self.edges.get("e")(w)
self.corner((90, self.radius))
self.edges.get("e")(h)
self.corner(90)
self.edges.get("F")(self.width)
self.corner(90)
self.edges.get("e")(h)
self.corner((90, self.radius))
self.move(self.width, total_height, move)
def render(self):
self.width = self.book_width - 2 * self.thickness
if self.radius < 0:
self.radius = self.thickness
# Back support
if self.back_support > 0:
self.rectangularWall(self.width, self.back_support, "efef", move="up", label="back support")
# Front ledge and fingers for lower plate
e = "e"
if self.ledge_height > 0:
self.front_ledge(move="up")
e = "f"
# Lower plate for book
self.rectangularWall(self.width, self.book_depth, e + "fFf", move="up", label="book bottom")
# Front plate
self.rectangularWall(self.width, self.book_height, "ffef", move="right", label="book back")
# Side walls
self.sideWall(move="right")
self.sideWall(move="right")
| 6,415 | Python | .py | 135 | 38.985185 | 104 | 0.63616 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,640 | drillbox.py | florianfesti_boxes/boxes/generators/drillbox.py | # 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/>.
from boxes import ArgparseEdgeType, Boxes, Color, edges
from boxes.lids import LidSettings, _TopEdge
class DrillBox(_TopEdge):
"""A parametrized box for drills"""
description = """ """
ui_group = "Tray"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings,
space=3, finger=3, surroundingspaces=1)
self.addSettingsArgs(edges.RoundedTriangleEdgeSettings, outset=1)
self.addSettingsArgs(edges.StackableSettings)
self.addSettingsArgs(edges.MountingSettings)
self.addSettingsArgs(LidSettings)
self.argparser.add_argument(
"--top_edge", action="store",
type=ArgparseEdgeType("eStG"), choices=list("eStG"),
default="e", help="edge type for top edge")
self.buildArgParser(sx="25*3", sy="60*4", sh="5:25:10",
bottom_edge="h")
self.argparser.add_argument(
"--holes",
action="store",
type=int,
default=3,
help="Number of holes for each size",
)
self.argparser.add_argument(
"--firsthole",
action="store",
type=float,
default=1.0,
help="Smallest hole",
)
self.argparser.add_argument(
"--holeincrement",
action="store",
type=float,
default=.5,
help="increment between holes",
)
def sideholes(self, l):
t = self.thickness
h = -0.5 * t
for d in self.sh[:-1]:
h += d + t
self.fingerHolesAt(0, h, l, angle=0)
def drillholes(self, description=False):
y = 0
d = self.firsthole
for dy in self.sy:
x = 0
for dx in self.sx:
iy = dy / self.holes
for k in range(self.holes):
self.hole(x + dx / 2, y + (k + 0.5) * iy, d=d + 0.05)
if description:
self.rectangularHole(x + dx / 2, y + dy / 2, dx - 2, dy - 2, color=Color.ETCHING)
self.text(
"%.1f" % d,
x + 2,
y + 2,
270,
align="right",
fontsize=6,
color=Color.ETCHING,
)
# TODO: make the fontsize dynamic to make the text fit in all cases
d += self.holeincrement
x += dx
y += dy
def render(self):
x = sum(self.sx)
y = sum(self.sy)
h = sum(self.sh) + self.thickness * (len(self.sh)-1)
b = self.bottom_edge
t1, t2, t3, t4 = self.topEdges(self.top_edge)
self.rectangularWall(
x, h, [b, "f", t1, "F"],
ignore_widths=[1, 6],
callback=[lambda: self.sideholes(x)], move="right")
self.rectangularWall(
y, h, [b, "f", t2, "F"], callback=[lambda: self.sideholes(y)],
ignore_widths=[1, 6],
move="up")
self.rectangularWall(
y, h, [b, "f", t3, "F"], callback=[lambda: self.sideholes(y)],
ignore_widths=[1, 6])
self.rectangularWall(
x, h, [b, "f", t4, "F"],
ignore_widths=[1, 6],
callback=[lambda: self.sideholes(x)], move="left up")
if b != "e":
self.rectangularWall(x, y, "ffff", move="right")
for d in self.sh[:-2]:
self.rectangularWall(
x, y, "ffff", callback=[self.drillholes], move="right")
self.rectangularWall(
x, y, "ffff",
callback=[lambda: self.drillholes(description=True)],
move="right")
self.lid(x, y, self.top_edge)
| 4,627 | Python | .py | 116 | 28.594828 | 101 | 0.534682 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,641 | castle.py | florianfesti_boxes/boxes/generators/castle.py | # 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/>.
from boxes import *
class Castle(Boxes):
"""Castle tower with two walls"""
description = """This was done as a table decoration. May be at some point in the future someone will create a proper castle
with towers and gates and walls that can be attached in multiple configurations."""
ui_group = "Unstable"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
def render(self, t_x=70, t_h=250, w1_x=300, w1_h=120, w2_x=100, w2_h=120):
s = edges.FingerJointSettings(10.0, relative=True,
space=1, finger=1,
width=self.thickness)
s.edgeObjects(self, "pPQ")
self.moveTo(0, 0)
self.rectangularWall(t_x, t_h, edges="efPf", move="right", callback=[lambda: self.fingerHolesAt(t_x * 0.5, 0, w1_h, 90), ])
self.rectangularWall(t_x, t_h, edges="efPf", move="right")
self.rectangularWall(t_x, t_h, edges="eFPF", move="right", callback=[lambda: self.fingerHolesAt(t_x * 0.5, 0, w2_h, 90), ])
self.rectangularWall(t_x, t_h, edges="eFPF", move="right")
self.rectangularWall(w1_x, w1_h, "efpe", move="right")
self.rectangularWall(w2_x, w2_h, "efpe", move="right")
| 1,980 | Python | .py | 35 | 50.057143 | 131 | 0.666322 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,642 | wallpliersholder.py | florianfesti_boxes/boxes/generators/wallpliersholder.py | # Copyright (C) 2013-2019 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 boxes.walledges import _WallMountedBox
class WallPliersHolder(_WallMountedBox):
"""Bar to hang pliers on"""
def __init__(self) -> None:
super().__init__()
self.buildArgParser(sx="100*3", y=50, h=50, outside=True)
self.argparser.add_argument(
"--angle", action="store", type=float, default=45,
help="bracing angle - less for more bracing")
def brace(self, h, d, a, outside=False, move=None):
t = self.thickness
tw = d + self.edges["b"].spacing() + self.edges["f"].spacing()
th = self.h_t
if self.move(tw, th, move, True):
return
self.moveTo(self.edges["b"].spacing())
r = d / 4
l = (d + t - r) / math.sin(math.radians(a))
if outside:
self.polyline(t, (90-a, r), l, (a, r))
self.edges["h"](h)
self.polyline(0, 90, d + 2*t, 90)
else:
self.polyline(0, (90-a, r), l, (a, r), 0, 90, t, -90)
self.edges["f"](h)
self.polyline(0, 90, d, 90)
self.edges["b"](h + (d+t-r) * math.tan(math.radians(90-a)) + r)
self.polyline(0, 90)
self.move(tw, th, move)
def frontCB(self):
t = self.thickness
posx = -t
for dx in self.sx[:-1]:
posx += dx + t
self.fingerHolesAt(posx, 0, self.h, 90)
def backCB(self):
t = self.thickness
posx = -t
for dx in self.sx[:-1]:
posx += dx + t
self.wallHolesAt(posx, 0, self.h_t, 90)
def render(self):
self.generateWallEdges()
if self.outside:
self.sx = self.adjustSize(self.sx)
sx, y, h = self.sx, self.y, self.h
t = self.thickness
r = y / 4
self.h_t = h + (y+t-r) * math.tan(math.radians(90-self.angle)) + r
self.rectangularWall(sum(sx) + (len(sx)-1) * t, h, "efef", callback=[self.frontCB], move="up")
self.rectangularWall(sum(sx) + (len(sx)-1) * t, self.h_t, "eCec", callback=[self.backCB], move="up")
for i in range(len(sx)+1):
self.brace(h, y, self.angle, i<2, move="right")
| 2,879 | Python | .py | 68 | 34.514706 | 109 | 0.582945 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,643 | rack10box.py | florianfesti_boxes/boxes/generators/rack10box.py | # Copyright (C) 2018 Sebastian Reichel
#
# 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.generators.rack19box import Rack19Box
class Rack10Box(Rack19Box):
"""Closed box with screw on top for mounting in a 10" rack."""
def render(self):
self._render(type=10)
| 895 | Python | .py | 19 | 45.052632 | 73 | 0.75 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,644 | platonic.py | florianfesti_boxes/boxes/generators/platonic.py | # Copyright (C) 2020 Norbert Szulc
#
# 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 boxes.edges import FingerJointEdge
class UnevenFingerJointEdge(FingerJointEdge):
"""Uneven finger joint edge """
char = 'u'
description = "Uneven Finger Joint"
positive = True
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
# copied from original
positive = self.positive
s, f, thickness = self.settings.space, self.settings.finger, self.settings.thickness
p = 1 if positive else -1
fingers, leftover = self.calcFingers(length, bedBolts)
if not positive:
play = self.settings.play
f += play
s -= play
leftover -= play
shift = (f + s) / 2 # we shift all fingers to make them un even
if (leftover < shift):
leftover = shift
self.edge((leftover + shift)/2, tabs=1) # Whole point of this class
l1,l2 = self.fingerLength(self.settings.angle)
h = l1-l2
d = (bedBoltSettings or self.bedBoltSettings)[0]
for i in range(fingers):
if i != 0:
if not positive and bedBolts and bedBolts.drawBolt(i):
self.hole(0.5 * s,
0.5 * self.settings.thickness, 0.5 * d)
if positive and bedBolts and bedBolts.drawBolt(i):
self.bedBoltHole(s, bedBoltSettings)
else:
self.edge(s)
if positive and self.settings.style == "springs":
self.polyline(
0, -90 * p, 0.8*h, (90 * p, 0.2*h),
0.1 * h, 90, 0.9*h, -180, 0.9*h, 90,
f - 0.6*h,
90, 0.9*h, -180, 0.9*h, 90, 0.1*h,
(90 * p, 0.2 *h), 0.8*h, -90 * p)
else:
self.polyline(0, -90 * p, h, 90 * p, f, 90 * p, h, -90 * p)
self.edge((leftover - shift)/2, tabs=1) # Whole point of this class
# Unstable
class UnevenFingerJointEdgeCounterPart(UnevenFingerJointEdge):
"""Uneven finger joint edge - other side"""
char = 'U'
description = "Uneven Finger Joint (opposing side)"
positive = False
class Platonic(Boxes):
"""Platonic solids generator"""
ui_group = "Unstable" # see ./__init__.py for names
description = """
"""
SOLIDS = {
"tetrahedron": (4, 3),
"cube": (6, 4),
"octahedron": (8, 3),
"dodecahedron": (12, 5),
"icosahedro": (20, 3),
}
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0)
self.buildArgParser(x=60, outside=True) # x should be treated as edge length, TODO: change that
self.argparser.add_argument(
"--type", action="store", type=str, default=list(self.SOLIDS)[0],
choices=list(self.SOLIDS),
help="type of platonic solid")
def render(self):
# adjust to the variables you want in the local scope
e = self.x
t = self.thickness
faces, corners = self.SOLIDS[self.type]
u = UnevenFingerJointEdge(self, self.edges["f"].settings)
self.addPart(u)
uc = UnevenFingerJointEdgeCounterPart(self, self.edges["f"].settings)
self.addPart(uc)
for _ in range(faces):
self.regularPolygonWall(corners, side=e, edges="u", move="right")
| 4,170 | Python | .py | 95 | 34.905263 | 104 | 0.601335 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,645 | wallstairs.py | florianfesti_boxes/boxes/generators/wallstairs.py | # Copyright (C) 2013-2019 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.walledges import _WallMountedBox
class WallStairs(_WallMountedBox):
"""Platforms in different heights e.g. for screw drivers"""
description = """You are supposed to add holes or slots to the stair tops yourself using Inkscape or another vector drawing or CAD program.
sh gives height of the stairs from front to back. Note that the overall width and height is bigger than the nominal values as walls and the protrusions are not included in the measurements.
"""
def __init__(self) -> None:
super().__init__()
self.buildArgParser(sx="250/3", sy="40*3", sh="30:100:180")
self.argparser.add_argument(
"--braceheight", action="store", type=float, default=30,
help="height of the brace at the bottom back (in mm). Zero for none")
def yWall(self, move=None):
t = self.thickness
x, sx, y, sy, sh = self.x, self.sx, self.y, self.sy, self.sh
tw, th = sum(sy), max(sh) + t
if self.move(tw, th, move, True):
return
self.polyline(y-t, 90)
self.edges["f"](self.braceheight)
self.step(t)
self.edges["A"](sh[-1] - self.braceheight)
self.corner(90)
for i in range(len(sy)-1, 0, -1):
self.edges["f"](sy[i])
self.step(sh[i-1]-sh[i])
self.edges["f"](sy[0])
self.polyline(0, 90, sh[0], 90)
self.move(tw, th, move)
def yCB(self, width):
t = self.thickness
posx = -0.5 * t
for dx in self.sx[:-1]:
posx += dx + t
self.fingerHolesAt(posx, 0, width, 90)
def render(self):
self.generateWallEdges()
self.extra_height = 20
t = self.thickness
sx, sy, sh = self.sx, self.sy, self.sh
self.x = x = sum(sx) + len(sx)*t - t
self.y = y = sum(sy)
for w in sy:
self.rectangularWall(
x, w, "eheh", callback=[lambda:self.yCB(w)], move="up")
if self.braceheight:
self.rectangularWall(
x, self.braceheight, "eheh",
callback=[lambda:self.yCB(self.braceheight)], move="up")
for i in range(len(sx) + 1):
self.yWall(move="right")
| 2,926 | Python | .py | 65 | 37.353846 | 189 | 0.620956 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,646 | makitapowersupply.py | florianfesti_boxes/boxes/generators/makitapowersupply.py | # Copyright (C) 2013-2016 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 *
class MakitaPowerSupply(Boxes):
"""Bench power supply powered with Maktia 18V battery or laptop power supply"""
description = """
Vitamins: DSP5005 (or similar) power supply, two banana sockets, two 4.8mm flat terminals with flat soldering tag
To allow powering by laptop power supply: flip switch, Lenovo round socket (or adjust right hole for different socket)
"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.argparser.add_argument("--banana_socket_diameter", action="store",
type=float, default=8.0,
help="diameter of the banana socket mounting holes")
self.argparser.add_argument("--flipswitch_diameter", action="store",
type=float, default=6.3,
help="diameter of the flipswitch mounting hole (disabled of no secondary power)")
self.argparser.add_argument("--secondary_power", action="store",
default="ibm-barrel",
choices=["ibm-barrel", "usb-c", "none"],
help="style of secondary power input")
def side(self, l, h=14, move=None):
t = self.thickness
tw, th = h+t, l
if self.move(tw, th, move, True):
return
self.moveTo(t, 0)
self.polyline(h, 90, l-h/3**0.5, 60, h*2/3**0.5, 120)
self.edges["f"](l)
self.move(tw, th, move)
def side2(self, l, h=14, move=None):
t = self.thickness
tw, th = h, l-10
if self.move(tw, th, move, True):
return
if h > 14:
self.polyline(h, 90, l-12, 90, h-14, 90, 50-12, -90, 8, -90)
else:
self.polyline(h, 90, l-50, 90, h-6, -90)
self.polyline(11, 90, 1, -90, 27, (90, 1),
3, (90, 1), l-12, 90)
self.move(tw, th, move)
def bottom(self):
t = self.thickness
m = self.x / 2
self.fingerHolesAt(m-30.5-0.5*t, 10, self.l)
self.fingerHolesAt(m+30.5+0.5*t, 10, self.l)
self.rectangularHole(m-19, 10+34, 0.8, 6.25)
self.rectangularHole(m+19, 10+34, 0.8, 6.25)
self.rectangularHole(m, 7.5, 35, 5)
def front(self):
d_b = self.banana_socket_diameter
d_f = self.flipswitch_diameter
secondary_power_style = self.secondary_power
self.hole(10, self.h/2, d=d_b)
self.hole(30, self.h/2, d=d_b)
if secondary_power_style == "ibm-barrel":
self.hole(50, self.h/2, d=d_f)
self.rectangularHole(76, 6.4, 12.4, 12.4)
if secondary_power_style == "usb-c":
self.hole(50, self.h/2, d=d_f)
self.rectangularHole(75, 2.6, 9.2, 3.2, r=1)
def back(self):
n = int((self.h-2*self.thickness) // 8)
offs = (self.h - n*8.0) / 2 + 4
for i in range(n):
self.rectangularHole(self.x/2, i*8+offs, self.x-20, 5, r=2.5)
def regulatorCB(self):
self.rectangularHole(21, 9.5, 35, 5)
self.rectangularHole(5, 33+12, 10, 10)
self.rectangularHole(42-5, 33+12, 10, 10)
for x in [3.5, 38.5]:
for y in [3.5, 65]:
self.hole(x, y, 1.0)
def render(self):
# adjust to the variables you want in the local scope
t = self.thickness
l = self.l = 64
hm = 15.5
self.x, self.y, self.h = x, y, h = 85, 75, 35
self.rectangularWall(x, h, "FFFF", callback=[self.front], move="right")
self.rectangularWall(y, h, "FfFf", move="up")
self.rectangularWall(y, h, "FfFf")
self.rectangularWall(x, h, "FFFF", callback=[self.back], move="left up")
self.rectangularWall(x, y, "ffff", callback=[self.bottom], move="right")
self.rectangularWall(x, y, "ffff", callback=[
lambda: self.rectangularHole(x/2, y-20-5, 76, 40)], move="")
self.rectangularWall(x, y, "ffff", move="left up only")
self.side(l, hm, move="right")
self.side(l, hm, move="right mirror")
self.side2(l, hm, move="right")
self.side2(l, hm, move="right mirror")
| 4,847 | Python | .py | 106 | 37.339623 | 119 | 0.601828 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,647 | wallconsole.py | florianfesti_boxes/boxes/generators/wallconsole.py | # Copyright (C) 2013-2019 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.walledges import _WallMountedBox
class WallConsole(_WallMountedBox):
"""Outset and angled plate to mount stuff to"""
def __init__(self) -> None:
super().__init__()
self.buildArgParser(sx="100", h=100, outside=True)
self.argparser.add_argument(
"--top_depth", action="store", type=float, default=50,
help="depth at the top")
self.argparser.add_argument(
"--bottom_depth", action="store", type=float, default=35,
help="depth at the bottom")
def backHoles(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
self.wallHolesAt(posx, 0, self.h, 90)
def frontHoles(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
self.fingerHolesAt(posx, 0, self.front, 90)
def render(self):
self.generateWallEdges()
if self.outside:
self.sx = self.adjustSize(self.sx)
self.h = self.adjustSize(self.h)
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
h = self.h
td = self.top_depth
bd = self.bottom_depth
self.front = (h**2 + (td-bd)**2)**0.5
self.rectangularWall(x, h, "eCec", callback=[self.backHoles],
move="up")
self.rectangularWall(x, self.front, "eFeF",
callback=[self.frontHoles], move="up")
for i in range(len(self.sx)+1):
self.trapezoidWall(h, td, bd, "befe", move="up")
| 2,312 | Python | .py | 52 | 36.365385 | 73 | 0.617372 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,648 | photoframe.py | florianfesti_boxes/boxes/generators/photoframe.py | # Copyright (C) 2013-2016 Florian Festi, 2024 marauder37
#
# 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/>.
import inspect
import logging
import math
from dataclasses import dataclass, fields
from boxes import BoolArg, Boxes, Color, edges
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
@dataclass
class Dimensions:
"""
Calculate the dimensions of a photo frame with matting and glass.
What changes if the user specifies the dimensions of the glass?
- the matting outer dimension is fixed by the glass instead of calculated out from the photo
- the matting width and height must be calculated from the photo dimensions
- so you can't have golden matting or user-specified matting width/height
"""
x: float
y: float
golden_mat: bool
matting_w_param: float
matting_h_param: float
matting_overlap: float
glass_w: float
glass_h: float
frame_w: float
frame_overlap: float
split_front_param: bool
split_middle_param: bool
guide_fudge: float = 2.0
def __post_init__(self):
self.check_matting_params()
self.check()
@property
def photo_x(self):
"""Width of the photo"""
return self.x
@property
def photo_y(self):
"""Height of the photo"""
return self.y
@property
def frame_h(self):
"""
Width of the top and bottom sections of the framing 'border' formed by the top layer
I can't think of a reason for this to be different from frame_w, but if you think of one,
this is where to handle it.
"""
return self.frame_w
@property
def mat_hole_x(self):
"""Width of the hole in the matting that shows the photo"""
return self.photo_x - 2 * self.matting_overlap
@property
def mat_hole_y(self):
"""Height of the hole in the matting that shows the photo"""
return self.photo_y - 2 * self.matting_overlap
@property
def golden_matting_width(self):
"""
Calculate the width of the matting border that gives a golden ratio for the matting+photo area / photo area
See e.g. https://robertreiser.photography/golden-ratio-print-borders/
"""
phi = (1 + math.sqrt(5)) / 2
a = 4
x = self.mat_hole_x
y = self.mat_hole_y
b = 2 * (x + y)
c = -(phi - 1) * x * y
disc = b**2 - 4 * a * c
x1 = (-b + math.sqrt(disc)) / (2 * a)
return x1
@property
def fixed_glass_size(self) -> bool:
"""
Whether user has specified the size of the glass, or we should work it out from the photo
"""
return bool(self.glass_w and self.glass_h)
@property
def matting_w(self):
"""
Width of the visible matting border on the sides of photo, not including the bit that's hidden by the frame
"""
if self.fixed_glass_size:
visible = self.glass_w - 2 * self.frame_overlap
return (visible - self.mat_hole_x) / 2
if self.golden_mat:
return self.golden_matting_width
return self.matting_w_param
@property
def matting_h(self):
"""
Height of the visible matting border on the top and bottom of photo, not including the bit that's hidden by the frame
"""
if self.fixed_glass_size:
visible = self.glass_h - 2 * self.frame_overlap
return (visible - self.mat_hole_y) / 2
if self.golden_mat:
return self.golden_matting_width
return self.matting_h_param
@property
def mat_x(self):
"""Width of the matting including the bit that's hidden by the frame"""
return self.mat_hole_x + 2 * self.matting_w + 2 * self.frame_overlap
@property
def mat_y(self):
"""Height of the matting including the bit that's hidden by the frame"""
return self.mat_hole_y + 2 * self.matting_h + 2 * self.frame_overlap
@property
def visible_mat_ratio(self):
"""
Ratio of the visible matting area to the visible photo area
For the most aesthetic result, this should be the golden ratio phi ~= 1.618.
Contrary to popular belief, this is all about the area, not length of side or perimeter.
"""
visible_mat_area = self.window_x * self.window_y
visible_photo_area = self.mat_hole_x * self.mat_hole_y
return visible_mat_area / visible_photo_area
@property
def pocket_x(self):
"""Width of the pocket formed by the guide including the fudge"""
return self.mat_x + self.guide_fudge
@property
def pocket_y(self):
"""Height of the pocket formed by the guide including the fudge"""
return self.base_y - self.guide_h
@property
def guide_w(self):
"""Width of the guide that holds the matting and glass in place"""
return (self.base_x - self.pocket_x) / 2
@property
def guide_h(self):
"""Height of the guide that holds the matting and glass in place"""
return (self.base_y - self.mat_y) / 2
@property
def window_x(self):
"""Width of the window that shows the photo"""
return self.mat_x - self.frame_overlap * 2
@property
def window_y(self):
"""Height of the window that shows the photo"""
return self.mat_y - self.frame_overlap * 2
@property
def base_x(self):
"""Width of the base layer, which is also the overall width of the piece"""
return self.window_x + 2 * self.frame_w
@property
def base_y(self):
"""Height of the base layer, which is also the overall height of the piece"""
return self.window_y + 2 * self.frame_h
@property
def centre_x(self):
"""
Midpoint of the whole frame
"""
return self.base_x / 2
@property
def centre_y(self):
"""
Midpoint of the whole frame
"""
return self.base_y / 2
@property
def split_middle(self):
return self.split_middle_param
@property
def unsplit_middle(self):
return not self.split_middle_param
@property
def split_front(self):
return self.split_front_param
@property
def unsplit_front(self):
return not self.split_front_param
def check_matting_params(self):
whinge_threshold_mm = 0.5
if self.golden_mat and self.fixed_glass_size:
calc = f"Calculated matting width x: {self.matting_w:.1f}, y: {self.matting_h:.1f} for glass {self.glass_w:.1f} x {self.glass_h:.1f}."
advice = "If you want to specify the glass size, do not use golden matting."
raise ValueError(f"Cannot have golden matting and fixed glass size at the same time. {calc} {advice}")
if self.fixed_glass_size and (self.matting_w_param or self.matting_h_param):
d_w = self.matting_w_param - self.matting_w
d_h = self.matting_h_param - self.matting_h
if abs(d_w) > whinge_threshold_mm or abs(d_h) > whinge_threshold_mm:
msg = f"Calculated matting width {self.matting_w:.1f} differs from specified matting widths {self.matting_w_param:.1f}, {self.matting_h_param:.1f}."
advice = "If you want to specify the matting widths, set the glass size to zero. If you want to specify the glass size, set the matting widths to 0."
logger.warning(msg)
raise ValueError(f"Fixed glass size and explicit matting dimensions are mutually exclusive. {msg} {advice}")
if self.golden_mat and (self.matting_w_param or self.matting_h_param):
d_w = self.matting_w_param - self.golden_matting_width
d_h = self.matting_h_param - self.golden_matting_width
if abs(d_w) > whinge_threshold_mm or abs(d_h) > whinge_threshold_mm:
msg = f"Golden matting width {self.golden_matting_width:.1f} differs from specified matting widths {self.matting_w_param:.1f}, {self.matting_h_param:.1f}"
advice = "If you want to specify the matting width, set the glass size to zero. If you want to specify the glass size, set the matting widths to 0."
logger.warning(msg)
raise ValueError(f"Golden matting and explicit matting dimensions are mutually exclusive. {msg} {advice}")
def check(self):
photo_info = f"Photo: {self.photo_x:.0f} x {self.photo_y:.0f}"
mat_hole_info = f"Matting hole: {self.mat_hole_x:.0f} x {self.mat_hole_y:.0f} (O {self.matting_overlap:.0f})"
matting_w_info = f"Matting widths: {self.matting_w:.0f} sides, {self.matting_h:.0f} top/bottom"
mat_info = f"Mat size: {self.mat_x:.0f} x {self.mat_y:.0f} (W {self.matting_w:.0f}, H {self.matting_h:.0f})"
base_info = f"Back of frame: {self.base_x} x {self.base_y} (W {self.frame_w:.0f}, H {self.frame_h:.0f})"
base_x_info = f"Back of frame x: {self.base_x:.0f} = {self.window_x:.0f} + 2 * ({self.frame_w:.0f} - {self.frame_overlap:.0f})"
base_y_info = f"Back of frame y: {self.base_y:.0f} = {self.window_y:.0f} + 2 * ({self.frame_h:.0f} - {self.frame_overlap:.0f})"
window_info = f"Viewing window in front layer: {self.window_x} x {self.window_y} (rim {self.frame_overlap:.0f})"
pocket_info = f"Pocket for glass and matting: {self.pocket_x:.0f} x {self.pocket_y:.0f} (guide {self.guide_fudge:.0f})"
if self.fixed_glass_size:
glass_info = f"Glass size: {self.glass_w:.0f} x {self.glass_h:.0f} (fixed)"
else:
glass_info = "Glass size: not specified"
info = [
photo_info,
mat_hole_info,
matting_w_info,
glass_info,
mat_info,
window_info,
pocket_info,
base_info,
base_x_info,
base_y_info,
]
issues = []
for field in fields(self):
if isinstance(getattr(self, field.name), float):
v = getattr(self, field.name)
if v < 0:
issues.append(f"{field.name} must be positive")
# Check all properties
for name, value in inspect.getmembers(self.__class__, lambda o: isinstance(o, property)):
prop_value = getattr(self, name)
if isinstance(prop_value, float):
if prop_value < 0:
issues.append(f"{name} must be positive")
if issues:
info_str = "\n".join(info)
issues_str = "\n".join(issues)
raise ValueError(f"Invalid dimensions:\n{issues_str}\n{info_str}")
class PhotoFrame(Boxes):
"""
3-layer photo frame with a slot at the top to slide matboard/acrylic/glass over the photo after glue-up.
"""
ui_group = "Misc"
description = """
3-layer photo frame.
Selected excellent features:
* easy to change the photo after glue-up, without disassembling the frame
* calculates the ideal matting size for your photo based on ancient Greek mathematics
* can make the frame in one piece or split into 4 pieces to save material
* can make a frame to fit the piece of glass/acrylic you already have
* adds a hole for hanging the frame on the wall
Features available in the mysterious future:
* rounded corners
* a stand on the back to display the frame on a table
## How to frame things like a pro
There are 1 or 2 things that you can't change when framing: the size of the artwork
and the size of the glass. So we generate everything else to fit those measurements.
Set `x` and `y` to the dimensions of the actual artwork.
* If your photo has a border, measure inside it.
* If your photo does not have a border, still measure the actual artwork. Don't reduce the dimensions to allow for mounting. We do that separately.
A real pro measures the photo, calculates the matting, and cuts the glass to fit the matting.
We will assume that you are not in fact a real pro, and can't be trusted with a glass cutter.
So measure your glass and we'll calculate the matting to suit it. If you aren't using glass,
we'll calculate the matting size based on "golden ratio of areas" like the pros do. Everyone
will think your frame is perfect, but they won't know why.
Matting is just cardboard. Its jobs are to keep the glass off the photo, provide a clean border around the artwork,
and make the whole thing look fancy. You can attach the photo to the matting or to the back of the frame.
Either way, the matting conceals all sorts of sins like bad cuts, glue marks, or mounting with blue painter's tape.
Matting also lets you reuse the frame for different sized photos. Just generate a new mat with the same glass dimensions.
The hole in the matting is smaller than the photo. This is so the photo doesn't fall out.
Even if your photo has a border, the hole needs to be a bit smaller than the photo,
or you will struggle to line up the photo without the edges showing.
Recommended overlaps are given in the settings. Don't worry about "losing" too much of the photo.
The matting will make the photo look bigger and more important. There's never anything
interesting in the last 2mm of a photo anyway.
"""
x = 100
y = 150
golden_mat = True
matting_w = 0
matting_h = 0
matting_overlap = 2
glass_w = 0
glass_h = 0
frame_w = 20.0
frame_overlap = 5.0
split_middle = True # not exposed in the UI
split_front = True
mount_hole_dia = 6.0
guide_fudge = 2.0
d = None
def __init__(self) -> None:
Boxes.__init__(self)
self.add_arguments()
def render(self):
self.d = Dimensions(
x=self.x,
y=self.y,
golden_mat=self.golden_mat,
matting_w_param=self.matting_w,
matting_h_param=self.matting_h,
matting_overlap=self.matting_overlap,
glass_w=self.glass_w,
glass_h=self.glass_h,
frame_w=self.frame_w,
frame_overlap=self.frame_overlap,
split_middle_param=self.split_middle,
split_front_param=self.split_front,
guide_fudge=self.guide_fudge,
)
self.render_base()
self.render_middle()
self.render_front()
self.render_matting()
self.render_photo()
def render_middle(self):
"""
Render the middle layer of the frame, which holds the matting and glass in place
Local variable `stack_n` is reserved for future use where multiple middle layers
are needed to hold thicker glass or matting. I have needed this in the past
but not often enough to add it to the UI.
"""
stack_n = 1
if self.d.unsplit_middle:
for _ in range(stack_n):
self.middle_unsplit()
if self.d.split_middle:
for _ in range(stack_n):
self.middle_split()
def middle_split(self):
lyr = "Middle"
d = self.d
edge_types = "DeD"
edge_lengths = (d.guide_w, d.base_x - 2 * d.guide_w, d.guide_w)
e = edges.CompoundEdge(self, edge_types, edge_lengths)
move = "up"
self.rectangularWall(d.base_x, d.guide_h, ["e", "e", e, "e"], move=move, label=f"{lyr} btm {d.base_x:.0f}x{d.guide_h:.0f}")
self.rectangularWall(d.pocket_y, d.guide_w, "edee", move=move, label=f"{lyr} side {d.guide_w:.0f}x{d.pocket_y:.0f}")
self.rectangularWall(d.pocket_y, d.guide_w, "edee", move=move, label=f"{lyr} side {d.guide_w:.0f}x{d.pocket_y:.0f}")
def middle_unsplit(self):
lyr = "Middle"
d = self.d
dims_str = f"{lyr} {d.base_x:.0f}x{d.base_y:.0f} with pocket {d.pocket_x:.0f}x{d.pocket_y:.0f} for mat {d.mat_x:.0f}x{d.mat_y:.0f}"
border_str = f"Widths {d.guide_w:.0f}x {d.guide_h:.0f}y x-fudge {d.guide_fudge:.0f}"
label = f"{dims_str}\n{border_str}"
# start at bottom left
poly = [d.base_x, 90, d.base_y, 90, d.guide_w, 90, d.pocket_y, -90, d.pocket_x, -90, d.pocket_y, 90, d.guide_w, 90, d.base_y, 90]
self.polygonWall(poly, "eeee", move="up", label=label)
def render_matting(self):
d = self.d
dims_str = f"Matting {d.mat_x:.0f}x{d.mat_y:.0f} - {d.mat_hole_x:.0f}x{d.mat_hole_y:.0f} (ratio {d.visible_mat_ratio:.2f})"
border_str = f"Borders {d.matting_w:.0f}w {d.matting_h:.0f}h"
overlap_str = f"Overlaps photo {d.matting_overlap:.0f}, frame {d.frame_overlap:.0f}"
label = f"{dims_str}\n{border_str}\n{overlap_str}"
callback = [lambda: self.rectangularHole(d.mat_x / 2, d.mat_y / 2, d.mat_hole_x, d.mat_hole_y, r=0.0)]
self.rectangularWall(d.mat_x, d.mat_y, "eeee", callback=callback, move="right", label=label)
def golden_matting_width(self, photo_width, photo_height):
# Calculate the width of the matting border
phi = (1 + math.sqrt(5)) / 2
a = 4
b = 2 * (photo_width + photo_height)
c = -(phi - 1) * photo_width * photo_height
disc = b**2 - 4 * a * c
x1 = (-b + math.sqrt(disc)) / (2 * a)
return x1
# Function to display the results
def display_results(self, photo_width, photo_height, matting_width):
photo_area = photo_width * photo_height
photo_perimeter = 2 * (photo_width + photo_height)
mat_x = photo_width + 2 * matting_width
mat_y = photo_height + 2 * matting_width
mat_perimeter = 2 * (mat_x + mat_y)
total_area = (photo_width + 2 * matting_width) * (photo_height + 2 * matting_width)
ratio = total_area / photo_area
diff = total_area - photo_area
logger.debug(f"\n\nPhoto dims: {photo_width:.0f} x {photo_height:.0f}")
logger.debug(f"Photo perimeter: {photo_perimeter:.0f}")
logger.debug(f"Photo area: {photo_area:.0f}")
logger.debug(f"Mat dims: {mat_x:.0f} x {mat_y:.0f}")
logger.debug(f"Mat perimeter: {mat_perimeter:.0f}")
logger.debug(f"Mat area: {diff:.0f}")
logger.debug(f"Total area: {total_area:.0f}")
logger.debug(f"Matting width: {matting_width:.1f}")
logger.debug(f"Ratio: {ratio:.2f}")
def render_front(self):
if self.d.unsplit_front:
self.front_unsplit()
if self.d.split_front:
self.front_split()
def front_unsplit(self):
lyr = "Front"
d = self.d
dims_str = f"{lyr} {d.base_x:.0f}x{d.base_y:.0f} - {d.window_x:.0f}x{d.window_y:.0f}"
border_str = f"Widths {d.frame_w:.0f}x {d.frame_h:.0f}y {d.frame_overlap:.0f} overlap"
label = f"{dims_str}\n{border_str}"
callback = [lambda: self.rectangularHole(d.centre_x, d.centre_y, d.window_x, d.window_y)]
self.rectangularWall(d.base_x, d.base_y, "eeee", callback=callback, move="up", label=label)
def front_split(self):
lyr = "Front"
d = self.d
hypo_h = math.sqrt(2 * d.frame_h**2)
hypo_w = math.sqrt(2 * d.frame_w**2)
tops = [d.base_x, 90 + 45, hypo_h, 90 - 45, d.base_x - 2 * d.frame_h, 90 - 45, hypo_h, None]
sides = [d.base_y, 90 + 45, hypo_w, 90 - 45, d.base_y - 2 * d.frame_w, 90 - 45, hypo_w, None]
for bit in ("top", "btm"):
label = f"{lyr} {bit} {d.base_x:.0f}x{d.frame_h:.0f}"
self.polygonWall(tops, "eded", move="up", label=label)
for bit in "LR":
label = f"{lyr} side {bit} {d.frame_w:.0f}x{d.base_y:.0f}"
self.polygonWall(sides, "eDeD", move="up", label=label)
def render_base(self):
d = self.d
label = f"Base {d.base_x:.0f}x{d.base_y:.0f} for photo {d.photo_x:.0f}x{d.photo_y:.0f}"
callback = [lambda: self.photo_registration_rectangle(), None, None, None]
holes = self.edgesettings.get("Mounting", {}).get("num", 0)
self.rectangularWall(d.base_x, d.base_y, "eeGe" if holes else "eeee", callback=callback, move="up", label=label)
# I can't work out the interface for roundedPlate with edge settings other than "e"
# so no rounded corners for you!
# self.roundedPlate(d.base_x, d.base_y, d.corner_radius, "e", callback, extend_corners=False, move="up", label=label)
def photo_registration_rectangle(self):
"""
Draw a rectangle with registration marks for the photo
"""
d = self.d
self.set_source_color(Color.ETCHING)
self.rectangular_etching(d.centre_x, d.centre_y, d.photo_x, d.photo_y)
self.ctx.stroke()
def rectangular_etching(self, x, y, dx, dy, r=0.0, center_x=True, center_y=True):
"""
Draw a rectangular etching (from GridfinityTrayLayout.rectangularEtching)
Same as rectangularHole, but with no burn margin
:param x: x position
:param y: y position
:param dx: width
:param dy: height
:param r: (Default value = 0) radius of the corners
:param center_x: (Default value = True) if True, x position is the center, else the start
:param center_y: (Default value = True) if True, y position is the center, else the start
"""
logger.debug(f"rectangular_etching: {x=} {y=} {dx=} {dy=} {r=} {center_x=} {center_y=}")
r = min(r, dx / 2.0, dy / 2.0)
x_start = x if center_x else x + dx / 2.0
y_start = y - dy / 2.0 if center_y else y
self.moveTo(x_start, y_start, 180)
self.edge(dx / 2.0 - r) # start with an edge to allow easier change of inner corners
for d in (dy, dx, dy, dx / 2.0 + r):
self.corner(-90, r)
self.edge(d - 2 * r)
def add_arguments(self):
# landlords seem to love using 8GA screws in masonry sleeves for wall mounts
self.addSettingsArgs(edges.MountingSettings, num=3, d_head=8.0, d_shaft=4.0)
self.addSettingsArgs(edges.DoveTailSettings, size=2.0, depth=1.0)
self.buildArgParser()
self.argparser.add_argument(
"--x",
action="store",
type=float,
default=self.x,
help="Width of the photo, not including any border",
)
self.argparser.add_argument(
"--y",
action="store",
type=float,
default=self.y,
help="Height of the photo, not including any border",
)
self.argparser.add_argument(
"--golden_mat", action="store", type=BoolArg(), default=self.golden_mat, help="Use golden ratio to calculate matting width"
)
self.argparser.add_argument(
"--matting_w",
action="store",
type=float,
default=self.matting_w,
help="Width of the matting border around the sides of the photo",
)
self.argparser.add_argument(
"--matting_h",
action="store",
type=float,
default=self.matting_h,
help="Width of the matting border around top/bottom of the photo",
)
self.argparser.add_argument(
"--matting_overlap",
action="store",
type=float,
default=self.matting_overlap,
help="Matting overlap of the photo, e.g. 2mm if photo has border, 5mm if not",
)
self.argparser.add_argument(
"--glass_w",
action="store",
type=float,
default=self.glass_w,
help="Width of the pre-cut glass or acrylic",
)
self.argparser.add_argument(
"--glass_h",
action="store",
type=float,
default=self.glass_h,
help="Height of the pre-cut glass or acrylic",
)
self.argparser.add_argument(
"--frame_w",
action="store",
type=float,
default=self.frame_w,
help="Width of the frame border around the matting",
)
self.argparser.add_argument(
"--guide_fudge",
action="store",
type=float,
default=self.guide_fudge,
help="Clearance in the guide pocket to help slide the matting/glass in",
)
self.argparser.add_argument(
"--frame_overlap",
action="store",
type=float,
default=self.frame_overlap,
help="Frame overlap to hold the matting/glass in place",
)
self.argparser.add_argument(
"--split_front",
action="store",
type=BoolArg(),
default=self.split_front,
help="Split front into thin rectangles to save material",
)
def render_photo(self):
d = self.d
self.set_source_color(Color.ANNOTATIONS)
label = f"Photo {d.photo_x:.0f}x{d.photo_y:.0f}"
self.rectangularWall(d.photo_x, d.photo_y, "eeee", label=label, move="up")
self.set_source_color(Color.BLACK)
| 25,619 | Python | .py | 553 | 37.74141 | 171 | 0.617215 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,649 | two_piece.py | florianfesti_boxes/boxes/generators/two_piece.py | # Copyright (C) 2013-2018 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 *
class TwoPiece(Boxes):
"""A two piece box where top slips over the bottom half to form the enclosure."""
description = """
Set *hi* larger than *h* to leave gap between the inner and outer shell. This can be used to make opening the box easier. Set *hi* smaller to only have a small inner ridge that will allow the content to be more visible after opening.

"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser("x", "y", "h", "hi", "outside")
self.addSettingsArgs(edges.FingerJointSettings, finger=2.0, space=2.0)
self.argparser.add_argument(
"--play", action="store", type=float, default=0.15,
help="play between the two parts as multiple of the wall thickness")
def render(self):
# adjust to the variables you want in the local scope
x, y, h = self.x, self.y, self.h
hi = self.hi or self.h
t = self.thickness
p = self.play * t
if self.outside:
x -= 4*t + 2*p
y -= 4*t + 2*p
h -= 2 * t
hi -= 2 * t
# Adjust h edge with play
self.edges["f"].settings.setValues(t, False, edge_width=self.edges["f"].settings.edge_width + p)
for i in range(2):
d = i * 2 * (t+p)
height = [hi, h][i]
with self.saved_context():
self.rectangularWall(x+d, height, "fFeF", move="right")
self.rectangularWall(y+d, height, "ffef", move="right")
self.rectangularWall(x+d, height, "fFeF", move="right")
self.rectangularWall(y+d, height, "ffef", move="right")
self.rectangularWall(y, height, "ffef", move="up only")
self.rectangularWall(x, y, "hhhh", bedBolts=None, move="right")
self.rectangularWall(x+d, y+d, "FFFF", bedBolts=None, move="right")
| 2,653 | Python | .py | 53 | 42.698113 | 233 | 0.635872 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,650 | wallpinrow.py | florianfesti_boxes/boxes/generators/wallpinrow.py | # Copyright (C) 2013-2019 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 boxes.walledges import _WallMountedBox
class PinEdge(edges.BaseEdge):
def __call__(self, length, **kw):
w2 = self.settings.pinwidth/2
l = self.settings.pinlength
s = self.settings.pinspacing
inc = self.settings.pinspacing_increment
t = self.settings.thickness
pin = [0, -90, l+t-w2, (180, w2), l+t-w2, -90]
self.edge(s/2-w2)
s += inc/2
for i in range(self.pins-1):
self.polyline(*pin, s-2*w2)
s+=inc
self.polyline(*pin, s/2-w2-inc/4)
def margin(self) -> float:
return self.settings.thickness+self.settings.pinlength
class WallPinRow(_WallMountedBox):
"""Outset and angled plate to mount stuff to"""
def __init__(self) -> None:
super().__init__()
self.argparser.add_argument(
"--pins", action="store", type=int, default=8,
help="number of pins")
self.argparser.add_argument(
"--pinlength", action="store", type=float, default=35,
help="length of pins (in mm)")
self.argparser.add_argument(
"--pinwidth", action="store", type=float, default=10,
help="width of pins (in mm)")
self.argparser.add_argument(
"--pinspacing", action="store", type=float, default=35,
help="space from middle to middle of pins (in mm)")
self.argparser.add_argument(
"--pinspacing_increment", action="store", type=float, default=0.0,
help="increase spacing from left to right (in mm)")
self.argparser.add_argument(
"--angle", action="store", type=float, default=20.0,
help="angle of the pins pointing up (in degrees)")
self.argparser.add_argument(
"--hooks", action="store", type=int, default=3,
help="number of hooks into the wall")
self.argparser.add_argument(
"--h", action="store", type=float, default=50.0,
help="height of the front plate (in mm) - needs to be at least 7 time the thickness")
def frontCB(self):
s = self.pinspacing
inc = self.pinspacing_increment
t = self.thickness
pos = s/2
s += 0.5*inc
for i in range(self.pins):
self.rectangularHole(pos, 2*t, self.pinwidth, t)
pos += s
s+=inc
for i in range(1, self.hooks-1):
self.fingerHolesAt(i*self.x/(self.hooks-1), self.h/2, self.h/2)
def backCB(self):
t = self.thickness
self.fingerHolesAt(0, 2*t, self.x, 0)
if self.angle < 0.001:
return
for i in range(1, self.hooks-1):
self.fingerHolesAt(i*self.x/(self.hooks-1), 3*t, self.h/2-3*t)
def sideWall(self, move=None):
a = self.angle
ar = math.radians(a)
h = self.h
t = self.thickness
sh = math.sin(ar)*6*t + math.cos(ar)*h
tw = self.edges["a"].margin() + math.sin(ar)*h + math.cos(ar)*6*t
th = sh + 6
if self.move(tw, th, move, True):
return
self.moveTo(self.edges["a"].margin())
self.polyline(math.sin(ar)*h, a, 4*t)
self.fingerHolesAt(-3.5*t, 0, h/2, 90)
self.edgeCorner("e", "h")
self.edges["h"](h)
self.polyline(0, 90-a, math.cos(ar)*6*t, 90)
self.edges["a"](sh)
self.corner(90)
self.move(tw, th, move)
def supportWall(self, move=None):
a = self.angle
ar = math.radians(a)
h = self.h
t = self.thickness
sh = math.sin(ar)*6*t + math.cos(ar)*h
tw = self.edges["a"].margin() + max(
math.sin(ar)*h/2 + math.cos(ar)*5*t,
math.sin(ar)*h)
th = sh + 6
if self.move(tw, th, move, True):
return
self.moveTo(self.edges["a"].margin())
if a > 0.001:
self.polyline(math.sin(ar)*h, a+90, 3*t)
self.edges["f"](h/2-3*t)
self.polyline(0, -90)
self.polyline(4*t, 90)
self.edges["f"](h/2)
self.polyline(math.sin(ar)*2*t, 90-a,
math.cos(ar)*4*t - math.sin(ar)**2*2*t, 90)
if a > 0.001:
self.edges["a"](sh)
else:
self.edges["a"](h/2)
self.corner(90)
self.move(tw, th, move)
def render(self):
self.generateWallEdges()
p = PinEdge(self, self)
n = self.pins
t = self.thickness
if self.h < 7*t:
self.h = 7*t
self.x = x = n*self.pinspacing + (n)*(n-1)/2 *self.pinspacing_increment
self.rectangularWall(x, 3*t, [p, "e", "f", "e"], move="up")
self.rectangularWall(x, self.h, "efef", callback=[self.frontCB],
move="up")
self.rectangularWall(x, self.h/2, "efef", callback=[self.backCB],
move="up")
self.sideWall(move="right")
for i in range(self.hooks-2):
self.supportWall(move="right")
self.sideWall(move="right")
| 5,790 | Python | .py | 142 | 31.415493 | 97 | 0.568324 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,651 | hooks.py | florianfesti_boxes/boxes/generators/hooks.py | # Copyright (C) 2013-2018 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 *
class Hook(Boxes):
"""A hook with a rectangular mouth to mount at the wall"""
ui_group = "Misc" # see ./__init__.py for names
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0.5)
self.argparser.add_argument("--width", action="store",
type=float, default=40.,
help="width of the hook (back plate is a bit wider)")
self.argparser.add_argument("--height", action="store",
type=float, default=40.,
help="inner height of the hook")
self.argparser.add_argument("--depth", action="store",
type=float, default=40.,
help="inner depth of the hook")
self.argparser.add_argument("--strength", action="store",
type=float, default=20.,
help="width of the hook from the side")
self.argparser.add_argument("--angle", action="store",
type=float, default=45.,
help="angle of the support underneath")
def render(self):
self.angle = min(self.angle, 80)
t = self.thickness
w = self.width - 2*t # inner width
d, h, s = self.depth, self.height, self.strength
self.rectangularWall(w + 4*t, self.height_back, 'Eeee', callback=self.back_callback, move='right')
self.sidewall(d, h, s, self.angle, move='right')
self.sidewall(d, h, s, self.angle, move='right')
self.rectangularWall(d, w, 'FFFf', move='right')
self.rectangularWall(h - t, w, 'FFFf', move='right', callback=[
lambda: self.hole((h - t)/2, w/2, d=17)])
self.rectangularWall(s-t, w, 'FeFf', move='right')
def back_callback(self, n):
if n != 0:
return
t = self.thickness
h = self.h_a + self.strength
self.fingerHolesAt(1.5*t, 0, h)
self.fingerHolesAt(self.width + .5*t, 0, h)
self.fingerHolesAt(2*t, h + t/2, self.width - 2*t, 0)
x_h = self.width/2 + t
y1 = h + self.height/2
y2 = self.strength/2
y3 = (y1 + y2) / 2
self.hole(x_h, y1, d=3)
self.hole(x_h, y2, d=3)
self.hole(x_h, y3, d=3)
@property
def height_back(self):
return self.strength + self.height + self.h_a
@property
def h_a(self):
return self.depth * math.tan(math.radians(self.angle))
def sidewall(self, depth, height, strength, angle=60., move=None):
t = self.thickness
h_a = depth * math.tan(math.radians(angle))
l_a = depth / math.cos(math.radians(angle))
f_edge = self.edges['f']
x_total = depth + strength + f_edge.margin()
y_total = strength + height + h_a
if self.move(x_total, y_total, move, before=True):
return
self.moveTo(f_edge.margin())
self.polyline(strength, angle, l_a, 90-angle, height+strength, 90)
f_edge(strength - t)
self.corner(90)
f_edge(height - t)
self.polyline(t, -90, t)
f_edge(depth)
self.corner(90)
f_edge(h_a + strength)
self.corner(90)
self.move(x_total, y_total, move)
| 3,912 | Python | .py | 89 | 35.88764 | 106 | 0.609763 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,652 | angledcutjig.py | florianfesti_boxes/boxes/generators/angledcutjig.py | # Copyright (C) 2013-2016 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 *
class AngledCutJig(Boxes): # Change class name!
"""Jig for making angled cuts in a laser cutter"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.)
# remove cli params you do not need
self.buildArgParser(x=50, y=100)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--angle", action="store", type=float, default=45.,
help="Angle of the cut")
def bottomCB(self):
t = self.thickness
self.fingerHolesAt(10-t, 4.5*t, 20, 0)
self.fingerHolesAt(30+t, 4.5*t, self.x, 0)
self.fingerHolesAt(10-t, self.y-4.5*t, 20, 0)
self.fingerHolesAt(30+t, self.y-4.5*t, self.x, 0)
def render(self):
# adjust to the variables you want in the local scope
x, y = self.x, self.y
t = self.thickness
th = x * math.tan(math.radians(90-self.angle))
l = (x**2 + th**2)**0.5
th2 = 20 * math.tan(math.radians(self.angle))
l2 = (20**2 + th2**2)**0.5
self.rectangularWall(30+x+2*t, y, callback=[self.bottomCB], move="right")
self.rectangularWall(l, y, callback=[
lambda:self.fingerHolesAt(0, 4.5*t, l, 0), None,
lambda:self.fingerHolesAt(0, 4.5*t, l, 0), None],
move="right")
self.rectangularWall(l2, y, callback=[
lambda:self.fingerHolesAt(0, 4.5*t, l2, 0), None,
lambda:self.fingerHolesAt(0, 4.5*t, l2, 0), None],
move="right")
self.rectangularTriangle(x, th, "fef", num=2, move="up")
self.rectangularTriangle(20, th2, "fef", num=2, move="up")
| 2,505 | Python | .py | 52 | 40.519231 | 81 | 0.62925 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,653 | paintbox.py | florianfesti_boxes/boxes/generators/paintbox.py | # Copyright (C) 2013-2016 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 Boxes, boolarg, edges
class PaintStorage(Boxes):
"""Stackable storage for hobby paint or other things"""
webinterface = True
ui_group = "Shelf" # see ./__init__.py for names
canheight: int
candiameter: int
minspace: int
additional_bottom: int
additional_top: int
hexpattern: bool
drawer: bool
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.StackableSettings)
self.buildArgParser(x=100, y=300)
self.argparser.add_argument(
"--canheight", action="store", type=int, default=50,
help="Height of the paintcans")
self.argparser.add_argument(
"--candiameter", action="store", type=int, default=30,
help="Diameter of the paintcans")
self.argparser.add_argument(
"--minspace", action="store", type=int, default=10,
help="Minimum space between the paintcans")
self.argparser.add_argument(
"--additional_bottom", action="store", type=boolarg, default=False,
help="Additional bottom/floor with holes the paintcans go through")
self.argparser.add_argument(
"--additional_top", action="store", type=boolarg, default=False,
help="Additional top/floor with holes the paintcans go through")
self.argparser.add_argument(
"--hexpattern", action="store", type=boolarg, default=False,
help="Use hexagonal arrangement for the holes instead of orthogonal")
self.argparser.add_argument(
"--drawer", action="store", type=boolarg, default=False,
help="Create a stackable drawer instead")
def paintholes(self):
"""Place holes for the paintcans evenly"""
if self.hexpattern:
self.moveTo(self.minspace / 2, self.minspace / 2)
settings = self.hexHolesSettings
settings.diameter = self.candiameter
settings.distance = self.minspace
settings.style = 'circle'
self.hexHolesRectangle(self.y - 1 * self.minspace,
self.x - 1 * self.minspace,
settings)
return
n_x = int(self.x / (self.candiameter + self.minspace))
n_y = int(self.y / (self.candiameter + self.minspace))
if n_x <= 0 or n_y <= 0:
return
spacing_x = (self.x - n_x * self.candiameter) / n_x
spacing_y = (self.y - n_y * self.candiameter) / n_y
for i in range(n_y):
for j in range(n_x):
self.hole(i * (self.candiameter + spacing_y) + (self.candiameter + spacing_y) / 2,
j * (self.candiameter + spacing_x) + (self.candiameter + spacing_x) / 2,
self.candiameter / 2)
def sidesCb(self):
x, y = self.x, self.y
t = self.thickness
stack = self.edges['s'].settings
h = self.canheight - stack.height - stack.holedistance + t
hx = 1 / 2. * x
hh = h / 4.
hr = min(hx, hh) / 2
if not self.drawer:
self.rectangularHole(h / 3, (x / 2.0) - t, hh, hx, r=hr)
self.fingerHolesAt(((self.canheight/3)*2)-t*2, -t, x, 90)
if self.additional_bottom:
self.fingerHolesAt((self.canheight / 6) - (t / 2), -t, x, 90)
if self.additional_top:
self.fingerHolesAt(self.canheight - ((self.canheight / 6) + t), -t, x, 90)
else:
self.rectangularHole(h / 3, (x / 2.0) - t, hh, hx, r=hr)
def render(self):
# adjust to the variables you want in the local scope
x, y = self.x, self.y
t = self.thickness
stack = self.edges['s'].settings
h = self.canheight - stack.height - stack.holedistance + t
wall_callbacks = [self.sidesCb]
if not self.drawer:
wall_keys = "EsES"
bottom_keys = "EfEf"
else:
wall_keys = "FsFS"
bottom_keys = "FfFf"
# Walls
self.rectangularWall(
h, x - 2 * t, wall_keys,
ignore_widths=[1, 2, 5, 6],
callback=wall_callbacks, move="up",
)
self.rectangularWall(
h, x - 2 * t, wall_keys,
ignore_widths=[1, 2, 5, 6],
callback=wall_callbacks, move="right"
)
# Plates
self.rectangularWall(
0.8 * stack.height + stack.holedistance, x, "eeee", move=""
)
self.rectangularWall(
0.8 * stack.height + stack.holedistance, x, "eeee", move="down right"
)
# Bottom
self.rectangularWall(
y, x - 2 * t, bottom_keys, ignore_widths=[1, 2, 5, 6], move="up"
)
if not self.drawer:
# Top
self.rectangularWall(y, x, "efef", callback=[self.paintholes], move="up")
if self.additional_bottom:
self.rectangularWall(y, x, "efef", callback=[self.paintholes], move="up")
if self.additional_top:
self.rectangularWall(y, x, "efef", callback=[self.paintholes], move="up")
else:
# Sides
self.rectangularWall(y, h, "efff", move="up")
self.rectangularWall(y, h, "efff", move="up")
| 6,103 | Python | .py | 138 | 34.050725 | 98 | 0.582394 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,654 | arcade.py | florianfesti_boxes/boxes/generators/arcade.py | # Copyright (C) 2013-2016 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 *
class Arcade(Boxes):
"""Desktop Arcade Machine"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.argparser.add_argument(
"--width", action="store", type=float, default=450.0,
help="inner width of the console")
self.argparser.add_argument(
"--monitor_height", action="store", type=float, default=350.0,
help="inner width of the console")
self.argparser.add_argument(
"--keyboard_depth", action="store", type=float, default=150.0,
help="inner width of the console")
def side(self, move=None):
# TODO: Add callbacks
y, h = self.y, self.h
t = self.thickness
r = 10
d_30 = 2* r * math.tan(math.radians(15))
tw, th = y+2*r+(self.front+t) * math.sin(math.radians(15)), h+2*r+(self.topback+t)/2**0.5
if self.move(tw, th, move, True):
return
self.moveTo(r+(self.front+t) * math.sin(math.radians(15)), 0)
with self.saved_context():
self.moveTo(0, r)
self.polyline(y, 90, h, 45, self.topback+t, 90, self.top+2*t, 90, 100, -90, self.monitor_height, -30, self.keyboard_depth+2*t, 90, self.front+t, 75)
self.fingerHolesAt(10, r+t/2, self.bottom, 0)
self.polyline(y, (90, r))
self.fingerHolesAt(0.5*t, r+t/2, self.back, 0)
self.fingerHolesAt(h-40-40, r+t/2, self.back, 0)
self.polyline(h, (45, r))
self.fingerHolesAt(0, r+t/2, self.topback, 0)
self.fingerHolesAt(self.topback+t/2, r+t, self.top, 90)
self.fingerHolesAt(self.topback, self.top+r+1.5*t, self.speaker, -180)
self.polyline(self.topback+t, (90, r), self.top+2*t, (90, r), 100-2*r, (-90, r), self.monitor_height-2*r-d_30, (-30, r))
self.fingerHolesAt(-d_30+t, r+.5*t, self.keyboard_depth, 0)
self.fingerHolesAt(-d_30+0.5*t, r+t, self.keyback, 90)
self.fingerHolesAt(self.keyboard_depth-d_30+1.5*t, r+t, self.front, 90)
self.polyline(self.keyboard_depth-d_30+2*t, (90, r), self.front+t, (75, r))
self.move(tw, th, move)
def keyboard(self):
# Add holes for the joystick and buttons here
pass
def speakers(self):
self.hole(self.width/4., 50, 40)
self.hole(self.width*3/4., 50, 40)
def render(self):
width = self.width
t = self.thickness
self.back = 40
self.front = 120
self.keyback = 50
self.speaker = 150
self.top = 100
self.topback = 200
y, h = self.y, self.h = 540, 450
y = self.y = ((self.topback+self.top+3*t-100+self.monitor_height) / 2**0.5
+ (self.keyboard_depth+2*t)*math.cos(math.radians(15))
- (self.front+t) * math.sin(math.radians(15)))
h = self.h = ((self.monitor_height-self.topback+self.top+1*t+100) / 2**0.5 +
+ (self.keyboard_depth+2*t)*math.sin(math.radians(15))
+ (self.front+t) * math.cos(math.radians(15)))
self.bottom = y-40-0.5*t
self.backwall = h-40
# Floor
self.rectangularWall(width, self.bottom, "efff", move="up")
# Back
self.rectangularWall(width, self.back, "Ffef", move="up")
self.rectangularWall(width, self.backwall, move="up")
self.rectangularWall(width, self.back, "efef", move="up")
# Front bottom
self.rectangularWall(width, self.front, "efff", move="up")
self.rectangularWall(width, self.keyboard_depth, "FfFf", callback=[self.keyboard], move="up")
self.rectangularWall(width, self.keyback, "ffef", move="up")
# Top
self.rectangularWall(width, self.speaker, "efff", callback=[None, None, self.speakers], move="up")
self.rectangularWall(width, self.top, "FfFf", move="up")
self.rectangularWall(width, self.topback, "ffef", move="up")
# Sides
self.side(move="up")
self.side(move="up")
| 4,774 | Python | .py | 97 | 40.639175 | 160 | 0.610777 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,655 | spicesrack.py | florianfesti_boxes/boxes/generators/spicesrack.py | # Copyright (C) 2013-2019 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 *
class FrontEdge(edges.Edge):
def __call__(self, length, **kw):
with self.saved_context():
a = 90
r = (self.diameter +self.space) / 2
self.ctx.scale(1, self.edge_width/r)
for i in range(self.numx):
self.corner(-a)
self.corner(180, r)
self.corner(-a)
self.moveTo(length)
def margin(self) -> float:
return self.edge_width
class SpicesRack(Boxes):
"""Rack for cans of spices"""
ui_group = "Shelf"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.0)
self.argparser.add_argument(
"--diameter", action="store", type=float, default=55.,
help="diameter of spice cans")
self.argparser.add_argument(
"--height", action="store", type=float, default=60.,
help="height of the cans that needs to be supported")
self.argparser.add_argument(
"--space", action="store", type=float, default=10.,
help="space between cans")
self.argparser.add_argument(
"--numx", action="store", type=int, default=5,
help="number of cans in a row")
self.argparser.add_argument(
"--numy", action="store", type=int, default=6,
help="number of cans in a column")
self.argparser.add_argument(
"--in_place_supports", action="store", type=boolarg, default=False,
help="place supports pieces in holes (check for fit yourself)")
self.argparser.add_argument(
"--feet", action="store", type=boolarg, default=False,
help="add feet so the rack can stand on the ground")
def support(self, width, height, move=None):
t = self.thickness
tw = width + t
th = height
r = min(width - 2*t, height - 2*t)
if self.move(tw, th, move, True):
return
self.polyline(width-r, 90, 0, (-90, r), 0, 90, height-r, 90, width, 90)
self.edges["f"](height)
self.move(tw, th, move)
def foot(self, width, height, move=None):
t = self.thickness
tw, th = height, width + t
if self.move(tw, th, move, True):
return
self.moveTo(0, t)
self.edges["f"](height)
self.polyline(0, 90, width, 90, 0, (90, height), width-height, 90)
self.move(tw, th, move)
def holes(self):
w = 2* self.base_r
r = self.diameter / 2
a = self.base_angle
l = self.hole_length
self.moveTo(0, self.hole_distance)
with self.saved_context():
self.ctx.scale(1, l/self.base_h)
self.moveTo(self.space/2, 0, 90)
for i in range(self.numx):
self.polyline(0, -a, 0, (-180+2*a, r), 0, -90-a, w, -90)
self.moveTo(0, -(self.diameter+self.space))
self.ctx.stroke()
if self.feet and not self.feet_done:
self.feet_done = True
return
if not self.in_place_supports:
return
inner_width = self.hole_distance + self.hole_length/3
t = self.thickness
for i in range(self.numx-1):
with self.saved_context():
self.moveTo((self.diameter+self.space)*(i+0.5)- (inner_width+t)/2, self.spacing)
self.support(inner_width, (self.h-t)/2)
def backCB(self):
t = self.thickness
dy = self.h/2 - t/2
for i in range(self.numy):
self.fingerHolesAt(0, (i+1)*self.h-0.5*self.thickness-dy, self.x, 0)
for j in range(1, self.numx):
self.fingerHolesAt(
j*(self.diameter+self.space),
(i+1)*self.h-t-dy, (self.h-t)/2, -90)
def render(self):
self.feet_done = False
t = self.thickness
self.x = x = self.numx * (self.diameter+self.space)
d = self.diameter
self.base_angle = 10
self.base_r = self.diameter/2 * math.cos(math.radians(self.base_angle))
self.base_h = self.diameter/2 * (1-math.sin(math.radians(self.base_angle)))
self.angle = math.degrees(math.atan(self.base_r/self.height))
self.hole_length = (self.base_h**2+self.height**2)**0.5
self.hole_distance = (self.diameter-self.base_r) * math.sin(math.radians(self.angle))
self.h = (self.space + d) / math.cos(math.radians(self.angle))
h = self.numy * self.h - self.h / 2 + 6*t
width = self.hole_distance + self.hole_length + self.space/2
inner_width = self.hole_distance + self.hole_length/3
self.edge_width = width - inner_width
for i in range(self.numy):
self.rectangularWall(x, inner_width,[
"f", "e", FrontEdge(self, self), "e"],
callback=[self.holes], move="up")
self.rectangularWall(x, h,
callback=[self.backCB,
None,
lambda:self.hole(3*t, 3*t, 1.5),
lambda:self.hole(3*t, 3*t, 1.5),
], move="up")
if not self.in_place_supports:
self.partsMatrix((self.numx-1)*self.numy, self.numx-1, "up",
self.support, inner_width, (self.h-t)/2)
if self.feet:
self.partsMatrix(self.numx-1, self.numx-1, "up",
self.foot, width, (self.h-t)/2)
| 6,318 | Python | .py | 139 | 34.410072 | 96 | 0.564687 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,656 | rackbox.py | florianfesti_boxes/boxes/generators/rackbox.py | # Copyright (C) 2013-2017 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 *
class RackBox(Boxes):
"""Closed box with screw on top and mounting holes"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.2)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--triangle", action="store", type=float, default=25.,
help="Sides of the triangles holding the lid in mm")
self.argparser.add_argument(
"--d1", action="store", type=float, default=2.,
help="Diameter of the inner lid screw holes in mm")
self.argparser.add_argument(
"--d2", action="store", type=float, default=3.,
help="Diameter of the lid screw holes in mm")
self.argparser.add_argument(
"--d3", action="store", type=float, default=4.,
help="Diameter of the mounting screw holes in mm")
self.argparser.add_argument(
"--holedist", action="store", type=float, default=7.,
help="Distance of the screw holes from the wall in mm")
def wallxCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.x, self.h-1.5*t, self.triangle, 180)
def wallxfCB(self): # front
t = self.thickness
hd = self.holedist
for x in (hd, self.x+3*hd+2*t):
for y in (hd, self.h-hd+t):
self.hole(x, y, self.d3/2.)
self.moveTo(t+2*hd, t)
self.wallxCB()
def wallyCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.y, self.h-1.5*t, self.triangle, 180)
def render(self):
t = self.thickness
x, y, h = self.x, self.y, self.h
d1, d2, d3 =self.d1, self.d2, self.d3
hd = self.holedist
tr = self.triangle
trh = tr / 3.
if self.outside:
self.x = x = self.adjustSize(x)
self.y = y = self.adjustSize(y)
self.h = h = h - 1 * t
else:
self.h = h = h + 2 * t # compensate for lid
self.rectangularWall(x, h, "fFeF", callback=[self.wallxCB],
move="right")
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB], move="up")
self.flangedWall(x, h, "FFeF", callback=[self.wallxfCB], r=t,
flanges=[0., 2*hd, 0, 2*hd])
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB],
move="left up")
self.rectangularWall(x, y, "fFFF", move="right")
self.rectangularWall(x, y, callback=[
lambda:self.hole(trh, trh, d=d2)] * 4, move='up')
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
| 3,610 | Python | .py | 78 | 37.346154 | 78 | 0.601251 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,657 | sidehingebox.py | florianfesti_boxes/boxes/generators/sidehingebox.py | # Copyright (C) 2024 Guillaume Collic
#
# 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/>.
import math
from boxes import *
class SideHingeBox(Boxes):
"""Box, with an hinge that does not protrude from the back of the box, and a latch."""
description = """
This box is another take on a hinge box.
The hinges doesn't protrude from the box, but the sides needs double walls.
When opened, 2 sides are opening, improving access inside the box.
An optional latch is included, based on a mechanical switch and a 3D printed button.
The latch is one-way: the box can be closed freely
(this side of the button is angled, and totally smooth since it's the printing bed surface),
but can't be inadvertently opened.
"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser("x", "y", "h", "outside")
self.addSettingsArgs(edges.FingerJointSettings, finger=2.0, space=2.0)
self.argparser.add_argument(
"--play", action="store", type=float, default=0.15,
help="play between the two sides as multiple of the wall thickness")
self.argparser.add_argument(
"--hinge_center", action="store", type=float, default=0.0,
help="distance between the hinge center and adjacent sides (0.0 for default)")
self.argparser.add_argument(
"--hinge_radius", action="store", type=float, default=5.5,
help="radius of the hinge inner circle")
self.argparser.add_argument(
"--cherrymx_latches", action="store", type=int, default=0,
choices=[0, 1, 2],
help="add one or two latches, based on 3D printing and a cherry mx compatible mechanical keyboard switch")
def render(self):
x, yi, hi = self.x, self.y, self.h
t = self.thickness
p = self.play * t
hinge_radius = self.hinge_radius
hinge_center = self.hinge_center if self.hinge_center else 2*t + hinge_radius
latches = self.cherrymx_latches
self.mx_width = 15.4
self.mx_length = t+16.4+2.8 #2.8 can be removed if the switch is trimmed flush
if self.outside:
x -= 2*t
yi -= 4*t + 2*p
hi -= 2*t
yo = yi + 2*(t+p)
ho = hi + t
# one side is shared between inside and outside part,
# so that the lid can rotate and lay flat, without touching the inner bottom
fingered_hi = 2*hinge_center-t
# a small gap is also needed for both part to rotate freely
# (for a rounded angled finish, a gapless version could be added, with manual sanding or mechanical round milling)
gap = math.sqrt(abs(pow(hinge_center*math.sqrt(2),2)-pow(hinge_center-t,2)))-hinge_center
fingered_ho = ho - gap - 2*hinge_center
with self.saved_context():
self.inner_side(x, hi, hinge_center, hinge_radius, fingered_hi, latches, reverse=True)
self.rectangularWall(
yi,
hi,
"fFeF",
callback=[lambda:self.back_cb(yi, latches)],
move="right",
label="inner - full side D")
self.inner_side(x, hi, hinge_center, hinge_radius, fingered_hi, latches)
self.rectangularWall(0, hi, "ffef", move="up only")
with self.saved_context():
self.outer_side(x, ho, hinge_center, hinge_radius, fingered_ho, latches)
with self.saved_context():
self.rectangularWall(yo, fingered_ho, "fFeF", move="up", label="outer - small side B")
self.moveTo(t+p,0)
self.rectangularWall(yi, fingered_hi, "eFfF", move="right", label="inner - small side B")
self.rectangularWall(yo, 0, "fFeF", move="right only")
self.outer_side(x, ho, hinge_center, hinge_radius, fingered_ho, latches, reverse=True)
self.rectangularWall(0, ho, "ffef", move="up only")
bottom_callback = [
lambda:self.fingerHolesAt(x-self.mx_width-t/2, 0, self.mx_length),
lambda:self.back_cb(yi, latches),
lambda:self.fingerHolesAt(self.mx_width+t/2, 0, self.mx_length) if latches>1 else None,
] if latches else None
self.rectangularWall(x, yi, "FFFF", callback=bottom_callback, move="right", label="inner - bottom")
self.rectangularWall(x, yo, "FEFF", move="right", label="outer - upper lid")
for _ in range(2):
self.rectangularWall(2*t, 1.5*t, "eeee", move="right")
if latches:
for _ in range(latches):
with self.saved_context():
self.rectangularWall(self.mx_width, self.mx_width, "eeee", move="right")
self.rectangularWall(self.mx_width, self.mx_width, "ffef", move="right")
self.rectangularWall(self.mx_length, self.mx_width, "ffeF", move="right")
self.rectangularWall(self.mx_length, self.mx_width, "ffeF", move="up only")
self.text(f"""
OpenSCAD code for 3D printing the cherry MX latch button:
#############################################
play = 0.1;
plywood_t = {t};
ear_t = 0.4;
ear_d = 15;
btn_d = 11.4;
btn_ext_h = min(plywood_t, 3.7);
btn_h = ear_t + plywood_t + btn_ext_h;
module mx_outer() {{
translate([0,0,btn_h+4])
mirror([0,0,1])
linear_extrude(height = 4.2) {{
offset(r=1, $fn=32){{
square([4.5, 2.8], center=true);
}}
}};
}}
module mx_inner() {{
translate([0,0,btn_h+4.01])
mirror([0,0,1])
for (rect = [ [4.05, 1.32], [1.22, 5] ]) {{
linear_extrude(height = 4)
square(rect, center=true);
hull() {{
linear_extrude(height = 0.01)
offset(delta = 0.4)
square(rect, center=true);
translate([0, 0, 0.5])
linear_extrude(height = 0.01)
square(rect, center=true);
}};
}}
}}
angle = atan2(btn_ext_h+0.2, btn_d/2);
rotate([0, angle, 0]) difference(){{
union(){{
cylinder(d=btn_d-2*play, h=btn_h, $fn=512);
translate([0, 0, btn_h-ear_t/2])
cube([btn_d/2, ear_d, ear_t], center=true);
mx_outer();
}}
rotate([0, 90-angle, 0])
translate([0, -btn_d/2, 0])
cube(btn_d);
mx_inner();
}}""")
def back_cb(self, y, latches):
if latches>0:
self.fingerHolesAt(self.mx_length+self.thickness/2, 0, self.mx_width)
if latches>1:
self.fingerHolesAt(y-self.mx_length-self.thickness/2, 0, self.mx_width)
def inner_side_cb(self, x, reverse):
if reverse:
self.fingerHolesAt(x-self.mx_width-self.thickness/2, 0, self.mx_width)
self.circle(x-self.mx_width/2, self.mx_width/2, 5.7+self.burn)
else:
self.fingerHolesAt(self.mx_width+self.thickness/2, 0, self.mx_width)
self.circle(self.mx_width/2, self.mx_width/2, 5.7+self.burn)
def inner_side(self, x, h, hinge_center, hinge_radius, fingered_h, latches, reverse=False):
sides = Inner2SidesEdge(
self, x, h, hinge_center, hinge_radius, fingered_h, reverse
)
noop_edge = edges.NoopEdge(self, margin=self.thickness if reverse else 0)
self.rectangularWall(
x,
h,
["f", "f", sides, noop_edge] if reverse else["f", sides, noop_edge, "f"],
move="right",
label="inner - hinge side " + ("A" if reverse else "C"),
callback=[
lambda: self.inner_side_cb(x, reverse)
] if (latches and reverse) or latches>1 else None,
)
def outer_side(self, x, h, hinge_center, hinge_radius, fingered_h, latches, reverse=False):
t = self.thickness
sides = Outer2SidesEdge(
self, x, h, hinge_center, hinge_radius, fingered_h, reverse
)
noop_edge = edges.NoopEdge(self, margin=t if reverse else 0)
latch_x, latch_y = (t+self.mx_width/2, self.mx_width/2)
if reverse:
latch_x, latch_y = latch_y, latch_x
self.rectangularWall(
x,
h,
["f", "E", sides, noop_edge] if reverse else["f", sides, noop_edge, "E"],
move="right",
label="outer - hinge side " + ("C" if reverse else "A"),
callback=[
None,
None,
lambda: self.circle(latch_x, latch_y, 5.7+self.burn)
] if (latches and not reverse) or latches>1 else None,
)
class Inner2SidesEdge(edges.BaseEdge):
"""
The next edge should be a NoopEdge
"""
def __init__(self, boxes, length, height, hinge_center, hinge_radius, fingered_h, reverse) -> None:
super().__init__(boxes, None)
self.length = length
self.height = height
self.hinge_center=hinge_center
self.hinge_radius=hinge_radius
self.fingered_h=fingered_h
self.reverse=reverse
def __call__(self, _, **kw):
actions = [self.hinge_hole, self.fingers, self.smooth_corner]
actions = list(reversed(actions)) if self.reverse else actions
for action in actions:
action()
def fingers(self):
self.boxes.edges['f'](self.fingered_h)
def smooth_corner(self):
# the corner has to be rounded to rotate freely
hinge_to_lid = self.height+self.boxes.thickness-self.hinge_center
hinge_to_side = self.hinge_center-self.boxes.thickness
corner_height = hinge_to_lid-math.sqrt(math.pow(hinge_to_lid, 2) - math.pow(hinge_to_side, 2))
angle = math.degrees(math.asin(hinge_to_side/hinge_to_lid))
path = [
self.height-self.fingered_h-corner_height,
(90-angle, 0),
0,
(angle, hinge_to_lid),
self.boxes.thickness+self.length-self.hinge_center,
]
path = list(reversed(path)) if self.reverse else path
self.polyline(*path)
def hinge_hole(self):
direction = -1 if self.reverse else 1
x = direction*(self.hinge_center-self.boxes.thickness-self.boxes.burn)
y = self.hinge_center-self.boxes.thickness
t = self.boxes.thickness
self.boxes.rectangularHole(x, y, 1.5*t, t)
def margin(self) -> float:
return 0 if self.reverse else self.boxes.edges['f'].margin()
class Outer2SidesEdge(edges.BaseEdge):
"""
The next edge should be a NoopEdge
"""
def __init__(self, boxes, length, height, hinge_center, hinge_radius, fingered_h, reverse) -> None:
super().__init__(boxes, None)
self.length = length
self.height = height
self.hinge_center=hinge_center
self.hinge_radius=hinge_radius
self.fingered_h=fingered_h
self.reverse=reverse
def __call__(self, _, **kw):
actions = [self.fingers, self.smooth_corner, self.hinge_hole]
actions = list(reversed(actions)) if self.reverse else actions
for action in actions:
action()
def fingers(self):
self.boxes.edges['f'](self.fingered_h)
def smooth_corner(self):
# the corner has to be rounded to rotate freely
path = [
0,
(-90, 0),
self.boxes.thickness,
(90, 0),
self.height-self.fingered_h-self.hinge_center,
(90, self.hinge_center),
self.boxes.thickness+self.length-self.hinge_center,
]
path = list(reversed(path)) if self.reverse else path
self.polyline(*path)
@restore
@holeCol
def hinge_hole(self):
direction = -1 if self.reverse else 1
x = direction*(self.hinge_center-self.length-self.boxes.thickness-self.boxes.burn)
y = self.hinge_center
t = self.boxes.thickness
self.boxes.circle(x, y, self.hinge_radius)
self.boxes.rectangularHole(x, y, t, 1.5*t)
def margin(self) -> float:
return 0 if self.reverse else self.boxes.edges['f'].margin()
| 12,521 | Python | .py | 284 | 35.53169 | 122 | 0.608182 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,658 | displaycase.py | florianfesti_boxes/boxes/generators/displaycase.py | # Copyright (C) 2013-2014 Florian Festi
# Copyright (C) 2018 Alexander Bulimov
#
# 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 *
class DisplayCase(Boxes):
"""Fully closed box intended to be cut from transparent acrylics and to serve as a display case."""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--overhang",
action="store",
type=float,
default=2,
help="overhang for joints in mm",
)
def render(self):
x, y, h = self.x, self.y, self.h
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h)
t = self.thickness
d2 = edges.Bolts(2)
d3 = edges.Bolts(3)
d2 = d3 = None
self.rectangularWall(x, h, "ffff", bedBolts=[d2] * 4, move="right", label="Wall 1")
self.rectangularWall(y, h, "fFfF", bedBolts=[d3, d2, d3, d2], move="up", label="Wall 2")
self.rectangularWall(y, h, "fFfF", bedBolts=[d3, d2, d3, d2], label="Wall 4")
self.rectangularWall(x, h, "ffff", bedBolts=[d2] * 4, move="left up", label="Wall 3")
self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4, move="right", label="Top")
self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4, label="Bottom")
| 2,131 | Python | .py | 46 | 39.652174 | 103 | 0.637548 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,659 | flextest.py | florianfesti_boxes/boxes/generators/flextest.py | # 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/>.
from boxes import *
class FlexTest(Boxes):
"""Piece for testing different flex settings"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("x", "y")
def render(self):
x, y = self.x, self.y
self.moveTo(5, 5)
self.edge(10)
self.edges["X"](x, y)
self.edge(10)
self.corner(90)
self.edge(y)
self.corner(90)
self.edge(x + 20)
self.corner(90)
self.edge(y)
self.corner(90)
| 1,284 | Python | .py | 35 | 31.6 | 73 | 0.665056 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,660 | breadbox.py | florianfesti_boxes/boxes/generators/breadbox.py | # Copyright (C) 2013-2022 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 *
class BreadBox(Boxes):
"""A BreadBox with a gliding door"""
ui_group = "FlexBox"
description = """Beware of the rolling shutter effect! Use wax on sliding surfaces.
"""
def side(self, l, h, r, move=None):
t = self.thickness
if self.move(l+2*t, h+2*t, move, True):
return
self.moveTo(t, t)
self.ctx.save()
n = self.n
a = 90. / n
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
self.fingerHolesAt(2*t, 0, h-r, 90)
self.moveTo(2.5*t, h-r, 90-a/2)
for i in range(n):
self.fingerHolesAt(0, 0.5*t, ls, 0)
self.moveTo(ls, 0, -a)
self.moveTo(0, 0, a/2)
self.fingerHolesAt(0, 0.5*t, l / 2 - r, 0)
self.ctx.restore()
self.edges["f"](l)
self.polyline(t, 90, h-r, (90, r+t), l/2-r, 90, t, -90, 0,)
self.edges["f"](l/2)
self.polyline(0, 90)
self.edges["f"](h)
self.move(l+2*t, h+2*t, move)
def cornerRadius(self, r, two=False, move=None):
s = self.spacing
if self.move(r, r+s, move, True):
return
for i in range(2 if two else 1):
self.polyline(r, 90, r, 180, 0, (-90, r), 0 ,-180)
self.moveTo(r, r+s, 180)
self.move(r, r+s, move)
def rails(self, l, h, r, move=None):
t = self.thickness
s = self.spacing
tw, th = l/2+2.5*t+3*s, h+1.5*t+3*s
if self.move(tw, th, move, True):
return
self.moveTo(2.5*t+s, 0)
self.polyline(l/2-r, (90, r+t), h-r, 90, t, 90, h-r, (-90, r), l/2-r, 90, t, 90)
self.moveTo(-t-s, t+s)
self.polyline(l/2-r, (90, r+t), h-r, 90, t, 90, h-r, (-90, r), l/2-r, 90, t, 90)
self.moveTo(+t-s, t+s)
self.polyline(l/2-r, (90, r-1.5*t), h-r, 90, t, 90, h-r, (-90, r-2.5*t), l/2-r, 90, t, 90)
self.moveTo(-t-s, t+s)
self.polyline(l/2-r, (90, r-1.5*t), h-r, 90, t, 90, h-r, (-90, r-2.5*t), l/2-r, 90, t, 90)
self.move(tw, th, move)
def door(self, l, h, move=None):
t = self.thickness
if self.move(l, h, move, True):
return
self.fingerHolesAt(t, t, h-2*t)
self.edge(2*t)
self.edges["X"](l-2*t, h)
self.polyline(0, 90, h, 90, l, 90, h, 90)
self.move(l, h, move)
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0.5)
self.addSettingsArgs(edges.FlexSettings, distance=.75, connection=2.)
self.buildArgParser(x=150, y=100, h=100)
self.argparser.add_argument(
"--radius", action="store", type=float, default=40.0,
help="radius of the corners")
def render(self):
x, y, h, r = self.x, self.y, self.h, self.radius
self.n = n = 3
if not r:
self.radius = r = h / 2
self.radius = r = min(r, h/2)
t = self.thickness
self.ctx.save()
self.side(x, h, r, move="right")
self.side(x, h, r, move="right")
self.rectangularWall(y, h, "fFfF", move="right")
self.ctx.restore()
self.side(x, h, r, move="up only")
self.rectangularWall(x, y, "FEFF", move="right")
self.rectangularWall(x/2, y, "FeFF", move="right")
self.door(x/2 + h - 2*r + 0.5*math.pi*r + 2*t, y-0.2*t, move="right")
self.rectangularWall(2*t, y-2.2*t, edges="eeef", move="right")
a = 90. / n
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
edges.FingerJointSettings(t, angle=a).edgeObjects(self, chars="aA")
edges.FingerJointSettings(t, angle=a/2).edgeObjects(self, chars="bB")
self.rectangularWall(h-r, y, "fbfe", move="right")
self.rectangularWall(ls, y, "fafB", move="right")
for i in range(n-2):
self.rectangularWall(ls, y, "fafA", move="right")
self.rectangularWall(ls, y, "fbfA", move="right")
self.rectangularWall(x/2 - r, y, "fefB", move="right")
self.rails(x, h, r, move="right mirror")
self.cornerRadius(r, two=True, move="right")
| 4,869 | Python | .py | 112 | 35.241071 | 98 | 0.565586 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,661 | flexbook.py | florianfesti_boxes/boxes/generators/flexbook.py | # Copyright (C) 2024 Oliver Jensen
#
# 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 *
class FlexBook(Boxes):
"""Box with living hinge styled after a book."""
ui_group = "FlexBox"
description = """
If you have an enclosure, arrange the living hinge to be as close to your extractor fan as possible.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser(x=75.0, y=35.0, h=125.0)
self.argparser.add_argument(
"--latchsize", action="store", type=float, default=8,
help="size of latch in multiples of thickness")
self.argparser.add_argument(
"--recess_wall", action="store", type=boolarg, default=False,
help="Whether to recess the inner wall for easier object removal")
def flexBookSide(self, h, x, r, callback=None, move=None):
t = self.thickness
tw, th = h+t, x+2*t+r
if self.move(tw, th, move, True):
return
self.fingerHolesAt(0, x+1.5*t, h, 0)
self.edges["F"](h)
self.corner(90, 0)
self.edges["e"](t)
self.edges["f"](x + t)
self.corner(180, r)
self.edges["e"](x + 2*t)
self.corner(90)
self.move(tw, th, move)
def flexBookRecessedWall(self, h, y, include_recess, callback=None, move=None):
t = self.thickness
tw, th = h, y+2*t
if self.move(tw, th, move, True):
return
# TODO: figure out math for gentler angles
cutout_radius = min(h/4, y/8)
cutout_angle = 90
cutout_predist = y * 0.2
cutout_angle_dist = h/2 - 2 * cutout_radius
cutout_base_dist = y - (y * .4) - 4 * cutout_radius
self.moveTo(0, t)
self.edges["f"](h)
self.corner(90,)
self.edges["e"](y)
self.corner(90)
self.edges["f"](h)
self.corner(90)
if include_recess:
self.polyline(
cutout_predist,
(cutout_angle, cutout_radius),
cutout_angle_dist,
(-cutout_angle, cutout_radius),
cutout_base_dist,
(-cutout_angle, cutout_radius),
cutout_angle_dist,
(cutout_angle, cutout_radius),
cutout_predist)
else :
self.edges["e"](y)
self.corner(90)
self.move(tw, th, move)
def flexBookLatchWall(self, h, y, latchSize, callback=None, move=None):
t = self.thickness
if self.recess_wall:
x_adjust = 0
else:
x_adjust = 3 * t
tw, th = h+t+x_adjust, y+2*t
if self.move(tw, th, move, True):
return
self.moveTo(x_adjust, t)
self.edges["f"](h)
self.corner(90)
self.edges["f"](y)
self.corner(90)
self.edges["f"](h)
self.corner(90)
self.rectangularHole(y/2, -1.5*t, latchSize - 2*t, t)
self.polyline(
(y-latchSize) / 2,
-90,
2.5*t,
(90, t/2),
latchSize - t,
(90, t/2),
2.5*t,
-90,
(y-latchSize) / 2,
90
)
self.move(tw, th, move)
def flexBookCover(self, move=None):
x, y = self.x, self.y
latchSize = self.latchsize
c4 = self.c4
t = self.thickness
tw = 2*x + 6*t + 2*c4 + t
th = y + 4*t
if self.move(tw, th, move, True):
return
self.moveTo(2*t, 0)
self.edges["h"](x+t)
self.edges["X"](2*c4 + t, y + 4*t) # extra thickness here to make it fit
self.edges["e"](x+t)
self.corner(90, 2*t)
self.edges["e"](y/2)
self.rectangularHole(0, 1.5*t, latchSize, t)
self.rectangularHole((latchSize+7*t)/2, 3.5*t, t, t)
self.rectangularHole(-(latchSize+7*t)/2, 3.5*t, t, t)
self.edges["e"](y/2)
self.corner(90, 2*t)
self.edges["e"](x+t + 2*c4 + t) # corresponding extra thickness
self.edges["h"](x+t)
self.corner(90, 2*t)
self.edges["h"](y)
self.corner(90, 2*t)
if False:
# debug lines
self.moveTo(0, 2*t)
self.edges["e"](x+t + 2*c4 + x+t + t)
self.corner(90)
self.edges["e"](y)
self.corner(90)
self.edges["e"](x+t + 2*c4 + x+t + t)
self.corner(90)
self.edges["e"](y)
self.corner(90)
self.edges["e"](x)
self.corner(90)
self.edges["e"](y)
self.corner(90)
self.edges["e"](x)
self.corner(90)
self.edges["e"](y)
self.corner(90)
self.move(tw, th, move)
def flexBookLatchBracket(self, isCover, move=None):
t = self.thickness
round = t/3
tw, th = 5*t, 5.5*t
if self.move(tw, th, move, True):
return
if isCover:
self.edge(5*t)
else:
self.edge(t)
self.corner(90)
self.edge(2*t - round)
self.corner(-90, round)
self.edge(1.5*t - round)
self.rectangularHole(0, 1.5 * t, t, t)
self.edge(1.5*t - round)
self.corner(-90, round)
self.edge(2*t - round)
self.corner(90)
self.edge(t)
self.corner(90)
self.edge(3*t)
self.corner(180, 2.5 * t)
self.edge(3*t)
if not isCover:
# anchor pin
self.moveTo(-1.5*t, 1.25*t)
self.ctx.stroke()
self.rectangularWall(t, 2*t)
self.move(tw, th, move)
def flexBookLatchPin(self, move=None):
t = self.thickness
l = self.latchsize
tw, th = l + 4*t, 5*t
if self.move(tw, th, move, True):
return
round = t/3
self.moveTo(2*t, 0)
self.polyline(
l,
90,
2*t,
-90,
2*t - round,
(90, round),
2*t - 2*round,
(90, round),
3*t - round,
-90,
t - round,
(90, round),
l - 2*t - 2*round,
(90, round),
t - round,
-90,
3*t - round,
(90, round),
2*t - 2*round,
(90, round),
2*t - round,
-90,
2*t,
90)
self.move(tw, th, move)
def render(self):
# I found it easier to conceptualize swapping y and h
y = self.h
self.h = self.y
self.y = y
t = self.thickness
self.radius = self.h / 2
self.c4 = c4 = math.pi * self.radius * 0.5
self.latchsize *= self.thickness
self.flexBookCover(move="up")
self.flexBookRecessedWall(self.h, self.y, self.recess_wall, move="mirror right")
self.flexBookLatchWall(self.h, self.y, self.latchsize, move="right")
with self.saved_context():
self.flexBookSide(self.h, self.x, self.radius, move="right")
self.flexBookSide(self.h, self.x, self.radius, move="mirror right")
self.flexBookSide(self.h, self.x, self.radius, move="up only")
with self.saved_context():
self.flexBookLatchBracket(False, move="up")
self.flexBookLatchBracket(False, move="up")
self.flexBookLatchBracket(False, move="right only")
with self.saved_context():
self.flexBookLatchBracket(True, move="up")
self.flexBookLatchBracket(True, move="up")
self.flexBookLatchBracket(False, move="right only")
l = self.latchsize
self.rectangularWall(
4*t, l,
callback=[lambda: self.rectangularHole(2*t, l/2, 2.5*t, .8*l, r=2*t)],
move="right")
self.flexBookLatchPin(move="right")
| 8,732 | Python | .py | 248 | 24.947581 | 100 | 0.528091 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,662 | royalgame.py | florianfesti_boxes/boxes/generators/royalgame.py | # Copyright (C) 2013-2016 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 *
class RoyalGame(Boxes):
"""The Royal Game of Ur"""
ui_group = "Misc"
description = """Most of the blue lines need to be engraved by cutting with high speed and low power. But there are three blue holes that actually need to be cut: The grip hole in the lid and two tiny rectangles on the top and bottom for the lid to grip into.


"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(x=200)
def dice(self, size, num=1, move=None):
s = size
r = s / 20.0
dr = r * 2
h = s/2*3**0.5
t = self.thickness
tw, th = (num + 0.5) * size, size
if self.move(tw, th, move, True):
return
self.moveTo(r, 0)
for i in range(2*num):
self.polyline((s-t)/2-dr, 90, h/2-r, -90, t, -90, h/2-r, 90, (s-t)/2-dr, (120, r), s-2*dr, (120, r), s-2*dr, (120, r))
self.ctx.stroke()
if i % 2:
self.moveTo(.5*s - 2*dr, s, 180)
else:
self.moveTo(1.5*s -2*dr, s, 180)
self.move(tw, th, move)
def five(self, x, y, s):
self.hole(x, y, 0.05*s)
self.hole(x, y, 0.12*s)
for dx in (-1, 1):
for dy in (-1, 1):
self.hole(x+dx*.25*s, y+dy*.25*s, 0.05*s)
self.hole(x+dx*.25*s, y+dy*.25*s, 0.12*s)
@restore
@holeCol
def _castle(self, x, y, s):
l = s/7*2**0.5
self.moveTo(x-s/2 + s/14, y-s/2, 45)
self.polyline(*([l, -90, l, 90]*3 + [l/2, 90])*4)
def castle(self, x, y, s):
self._castle(x, y, 0.9*s)
self._castle(x, y, 0.5*s)
self.five(x, y, 0.4*s)
def castles(self, x, y, s):
for dx in (-1, 1):
for dy in (-1, 1):
self._castle(x+dx*0.25*s, y+dy*0.25*s, 0.4*s)
self.five(x+dx*0.25*s, y+dy*0.25*s, 0.3*s)
@restore
@holeCol
def rosette(self, x, y, s):
self.moveTo(x, y, 22.5)
with self.saved_context():
self.moveTo(0.1*s, 0, -30)
for i in range(8):
self.polyline(0, (60, 0.35*s), 0, 120, 0, (60, 0.35*s), 0,
-120, 0, (45, 0.1*s), 0, -120)
self.moveTo(0, 0, -22.5)
self.moveTo(0.175*s, 0)
for i in range(8):
self.polyline(0, (67.5, 0.32*s), 0, 90, 0, (67.5, 0.32*s), 0, -180)
@holeCol
def eyes(self, x, y, s):
for dx in (-1, 1):
for dy in (-1, 1):
posx = x+dx*0.3*s
posy = y+dy*0.25*s
self.rectangularHole(posx, posy, 0.4*s, 0.5*s)
self.hole(posx, posy, 0.05*s)
with self.saved_context():
self.moveTo(posx, posy-0.2*s, 60)
self.corner(60, 0.4*s)
self.corner(120)
self.corner(60, 0.4*s)
self.corner(120)
self.moveTo(0, 0, -60)
self.moveTo(0, -0.05*s, 60)
self.corner(60, 0.5*s)
self.corner(120)
self.corner(60, 0.5*s)
for i in range(4):
self.rectangularHole(x, y + (i-1.5)*s*0.25, 0.12*s, 0.12*s)
def race(self, x, y, s):
for dx in range(4):
for dy in range(4):
posx = (dx-1.5) * s / 4.5 + x
posy = (dy-1.5) * s / 4.5 + y
self.rectangularHole(posx, posy, s/5, s/5)
if dx in (1, 2) and dy in (0,3):
continue
self.hole(posx, posy, s/20)
def top(self):
patterns = [
[self.castle, self.rosette, None, None, self.eyes, self.five, self.eyes, self.rosette],
[self.five, self.eyes, self.castles, self.five, self.rosette, self.castles, self.five, self.race]]
s = self.size
for x in range(8):
for y in range(3):
if x in [2, 3] and y != 1:
continue
posx = (0.5+x) * s
posy = (0.5+y) * s
self.rectangularHole(posx, posy, 0.9*s, 0.9*s)
pattern = patterns[y % 2][x]
if pattern:
pattern(posx, posy, 0.9*s)
def player1(self):
for i in range(3):
self.hole(0, 0, r=self.size * (i+2) / 12)
def player2(self, x=0, y=0):
s = self.size
self.hole(x, y, 0.07*s)
for dx in (-1, 1):
for dy in (-1, 1):
self.hole(x+dx*.2*s, y+dy*.2*s, 0.07*s)
def render(self):
x = self.x
t = self.thickness
self.size = size = x / 8.0
h = size/2 * 3**0.5
y = 3 * size
self.rectangularWall(x, h, "FLFF", move="right")
self.rectangularWall(y, h, "nlmE", callback=[
lambda:self.hole(y/2, h/2, d=0.6*h)], move="up")
self.rectangularWall(y, h, "FfFf")
self.rectangularWall(x, h, "FeFF", move="left up")
self.rectangularWall(x, y, "fMff", move="up")
self.rectangularWall(x, y, "fNff", callback=[self.top,], move="up")
self.partsMatrix(7, 7, "up", self.parts.disc, 0.8*size, callback=self.player1)
self.partsMatrix(7, 7, "up", self.parts.disc, 0.8*size, callback=self.player2)
self.dice(size, 4, move="up")
self.dice(size, 4, move="up")
| 6,256 | Python | .py | 150 | 31.066667 | 263 | 0.512521 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,663 | regularbox.py | florianfesti_boxes/boxes/generators/regularbox.py | # 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/>.
from boxes import *
from boxes.generators.bayonetbox import BayonetBox
class RegularBox(BayonetBox):
"""Box with regular polygon as base"""
description = """For short side walls that don't fit a connecting finger reduce *surroundingspaces* and *finger* in the Finger Joint Settings.
The lids needs to be glued. For the bayonet lid all outside rings attach to the bottom, all inside rings to the top.
"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1)
self.buildArgParser("h", "outside")
self.argparser.add_argument(
"--radius_bottom", action="store", type=float, default=50.0,
help="inner radius of the box bottom (at the corners)")
self.argparser.add_argument(
"--radius_top", action="store", type=float, default=50.0,
help="inner radius of the box top (at the corners)")
self.argparser.add_argument(
"--n", action="store", type=int, default=5,
help="number of sides")
self.argparser.add_argument(
"--top", action="store", type=str, default="none",
choices=["none", "hole", "angled hole", "angled lid", "angled lid2", "round lid", "bayonet mount", "closed"],
help="style of the top and lid")
self.argparser.add_argument(
"--alignment_pins", action="store", type=float, default=1.0,
help="diameter of the alignment pins for bayonet lid")
self.argparser.add_argument(
"--bottom", action="store", type=str, default="closed",
choices=["none", "closed", "hole", "angled hole", "angled lid", "angled lid2", "round lid"],
help="style of the bottom and bottom lid")
self.lugs=6
def render(self):
r0, r1, h, n = self.radius_bottom, self.radius_top, self.h, self.n
if self.outside:
r0 = r0 - self.thickness / math.cos(math.radians(360/(2*n)))
r1 = r1 - self.thickness / math.cos(math.radians(360/(2*n)))
if self.top == "none":
h = self.adjustSize(h, False)
elif "lid" in self.top and self.top != "angled lid":
h = self.adjustSize(h) - self.thickness
else:
h = self.adjustSize(h)
t = self.thickness
r0, sh0, side0 = self.regularPolygon(n, radius=r0)
r1, sh1, side1 = self.regularPolygon(n, radius=r1)
# length of side edges
#l = (((side0-side1)/2)**2 + (sh0-sh1)**2 + h**2)**0.5
l = ((r0-r1)**2 + h**2)**.5
# angles of sides -90° aka half of top angle of the full pyramid sides
a = math.degrees(math.asin((side1-side0)/2/l))
# angle between sides (in boxes style change of travel)
phi = 180 - 2 * math.degrees(
math.asin(math.cos(math.pi/n) / math.cos(math.radians(a))))
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
fingerJointSettings.setValues(self.thickness, angle=phi)
fingerJointSettings.edgeObjects(self, chars="gGH")
beta = math.degrees(math.atan((sh1-sh0)/h))
angle_bottom = 90 + beta
angle_top = 90 - beta
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
fingerJointSettings.setValues(self.thickness, angle=angle_bottom)
fingerJointSettings.edgeObjects(self, chars="yYH")
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
fingerJointSettings.setValues(self.thickness, angle=angle_top)
fingerJointSettings.edgeObjects(self, chars="zZH")
def drawTop(r, sh, top_type, joint_type):
if top_type == "closed":
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right")
elif top_type == "angled lid":
self.regularPolygonWall(corners=n, r=r, edges='e', move="right")
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
elif top_type in ("angled hole", "angled lid2"):
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right",
callback=[lambda:self.regularPolygonAt(
0, 0, n, h=sh-t)])
if top_type == "angled lid2":
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
elif top_type in ("hole", "round lid"):
self.regularPolygonWall(corners=n, r=r, edges=joint_type[1], move="right",
hole=(sh-t)*2)
if top_type == "round lid":
self.parts.disc(sh*2, move="right")
if self.top == "bayonet mount":
self.diameter = 2*sh
self.parts.disc(sh*2-0.1*t, callback=self.lowerCB,
move="right")
self.regularPolygonWall(corners=n, r=r, edges='F',
callback=[self.upperCB], move="right")
self.parts.disc(sh*2, move="right")
with self.saved_context():
drawTop(r0, sh0, self.bottom, "yY")
drawTop(r1, sh1, self.top, "zZ")
self.regularPolygonWall(corners=n, r=max(r0, r1), edges='F', move="up only")
fingers_top = self.top in ("closed", "hole", "angled hole",
"round lid", "angled lid2", "bayonet mount")
fingers_bottom = self.bottom in ("closed", "hole", "angled hole",
"round lid", "angled lid2")
t_ = self.edges["G"].startwidth()
bottom_edge = ('y' if fingers_bottom else 'e')
top_edge = ('z' if fingers_top else 'e')
d_top = max(0, -t_ * math.sin(math.radians(a)))
d_bottom = max(0.0, t_ * math.sin(math.radians(a)))
l -= (d_top + d_bottom)
if n % 2:
e = bottom_edge + 'ege' + top_edge + 'eeGee'
borders = [side0, 90-a, d_bottom, 0, l, 0, d_top, 90+a, side1,
90+a, d_top, -90, t_, 90, l, 90, t_, -90, d_bottom, 90-a]
for i in range(n):
self.polygonWall(borders, edge=e, correct_corners=False,
move="right")
else:
borders0 = [side0, 90-a,
d_bottom, -90, t_, 90, l, 90, t_, -90, d_top,
90+a, side1, 90+a,
d_top, -90, t_, 90, l, 90, t_, -90, d_bottom, 90-a]
e0 = bottom_edge + 'eeGee' + top_edge + 'eeGee'
borders1 = [side0, 90-a, d_bottom, 0, l, 0, d_top, 90+a, side1,
90+a, d_top, 0, l, 0, d_bottom, 90-a]
e1 = bottom_edge + 'ege' + top_edge + 'ege'
for i in range(n//2):
self.polygonWall(borders0, edge=e0, correct_corners=False,
move="right")
self.polygonWall(borders1, edge=e1, correct_corners=False,
move="right")
| 7,820 | Python | .py | 140 | 43.164286 | 146 | 0.566183 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,664 | trianglelamp.py | florianfesti_boxes/boxes/generators/trianglelamp.py | # Copyright (C) 2013-2016 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 *
class CornerEdge(edges.Edge):
char = "C"
def startwidth(self) -> float:
return self.boxes.thickness * math.tan(math.radians(90-22.5))
def __call__(self, length, bedBolts=None, bedBoltSettings=None, **kw):
with self.saved_context():
self.ctx.stroke()
self.set_source_color(Color.RED)
self.moveTo(0, self.startwidth())
self.edge(length)
self.ctx.stroke()
self.set_source_color(Color.BLACK)
super().__call__(length, bedBolts=None, bedBoltSettings=None, **kw)
class TriangleLamp(Boxes):
"""Triangle LED Lamp"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, finger=3.0,space=3.0,
surroundingspaces=0.5)
self.buildArgParser(x=250, h=40)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--cornersize", action="store", type=float, default=30,
help="short side of the corner triangles")
self.argparser.add_argument(
"--screenholesize", action="store", type=float, default=4,
help="diameter of the holes in the screen")
self.argparser.add_argument(
"--screwholesize", action="store", type=float, default=2,
help="diameter of the holes in the wood")
self.argparser.add_argument(
"--sharpcorners", action="store", type=boolarg, default=False,
help="extend walls for 45° corners. Requires grinding a 22.5° bevel.")
def CB(self, l, size):
def f():
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, size, 0)
self.fingerHolesAt(l, self.h-1.5*t, size, 180)
return f
def render(self):
# adjust to the variables you want in the local scope
x, h = self.x, self.h
l = (x**2+x**2)**.5
c = self.cornersize
t = self.thickness
r1 = self.screwholesize / 2
r2 = self.screenholesize / 2
self.addPart(CornerEdge(self, None))
self.rectangularTriangle(x, x, num=2, move="up", callback=[
lambda: self.hole(2/3.*c, 1/4.*c, r2),
lambda: (self.hole(1/3.*c, 1/3.*c, r2),
self.hole(x-2/3.*c, 1/4.*c, r2)),
])
self.rectangularTriangle(x, x, "fff", num=2, move="up")
C = 'e'
if self.sharpcorners:
C = 'C'
self.rectangularWall(x, h, "Ffe"+C, callback=[self.CB(x, c)],
move="up")
self.rectangularWall(x, h, "Ffe"+C, callback=[self.CB(x, c)],
move="up")
self.rectangularWall(x, h, "F"+C+"eF", callback=[self.CB(x, c)],
move="up")
self.rectangularWall(x, h, "F"+C+"eF", callback=[self.CB(x, c)],
move="up")
self.rectangularWall(l, h, "F"+C+"e" + C,
callback=[self.CB(l, c*2**.5)], move="up")
self.rectangularWall(l, h, "F"+C+"e" + C,
callback=[self.CB(l, c*2**.5)], move="up")
self.rectangularTriangle(c, c, "ffe", num=2, move="right", callback=[
lambda:self.hole(2/3.*c,1/3.*c, r1)])
self.rectangularTriangle(c, c, "fef", num=4, move="up", callback=[
lambda: self.hole(2/3.*c, 1/4.*c, r1)])
| 4,203 | Python | .py | 89 | 37.044944 | 82 | 0.579115 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,665 | unevenheightbox.py | florianfesti_boxes/boxes/generators/unevenheightbox.py | # Copyright (C) 2013-2018 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 *
class UnevenHeightBox(Boxes):
"""Box with different height in each corner"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.GroovedSettings)
self.buildArgParser("x", "y", "outside", bottom_edge="F")
self.argparser.add_argument(
"--height0", action="store", type=float, default=50,
help="height of the front left corner in mm")
self.argparser.add_argument(
"--height1", action="store", type=float, default=50,
help="height of the front right corner in mm")
self.argparser.add_argument(
"--height2", action="store", type=float, default=100,
help="height of the right back corner in mm")
self.argparser.add_argument(
"--height3", action="store", type=float, default=100,
help="height of the left back corner in mm")
self.argparser.add_argument(
"--lid", action="store", type=boolarg, default=False,
help="add a lid (works best with high corners opposing each other)")
self.argparser.add_argument(
"--lid_height", action="store", type=float, default=0,
help="additional height of the lid")
self.argparser.add_argument(
"--edge_types", action="store", type=str, default="eeee",
help="which edges are flat (e) or grooved (z,Z), counter-clockwise from the front")
def render(self):
x, y = self.x, self.y
heights = [self.height0, self.height1, self.height2, self.height3]
edge_types = self.edge_types
if len(edge_types) != 4 or any(et not in "ezZ" for et in edge_types):
raise ValueError("Wrong edge_types style: %s)" % edge_types)
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
for i in range(4):
heights[i] = self.adjustSize(heights[i], self.bottom_edge,
self.lid)
t = self.thickness
h0, h1, h2, h3 = heights
b = self.bottom_edge
self.trapezoidWall(x, h0, h1, [b, "F", edge_types[0], "F"], move="right")
self.trapezoidWall(y, h1, h2, [b, "f", edge_types[1], "f"], move="right")
self.trapezoidWall(x, h2, h3, [b, "F", edge_types[2], "F"], move="right")
self.trapezoidWall(y, h3, h0, [b, "f", edge_types[3], "f"], move="right")
with self.saved_context():
if b != "e":
self.rectangularWall(x, y, "ffff", move="up")
if self.lid:
maxh = max(heights)
lidheights = [maxh-h+self.lid_height for h in heights]
h0, h1, h2, h3 = lidheights
lidheights += lidheights
edges = ["E" if (lidheights[i] == 0.0 and lidheights[i+1] == 0.0) else "f" for i in range(4)]
self.rectangularWall(x, y, edges, move="up")
if self.lid:
self.moveTo(0, maxh+self.lid_height+self.edges["F"].spacing()+self.edges[b].spacing()+1*self.spacing, 180)
edge_inverse = {"e": "e", "z": "Z", "Z": "z"}
edge_types = [edge_inverse[et] for et in edge_types]
self.trapezoidWall(y, h0, h3, "Ff" + edge_types[3] + "f", move="right" +
(" only" if h0 == h3 == 0.0 else ""))
self.trapezoidWall(x, h3, h2, "FF" + edge_types[2] + "F", move="right" +
(" only" if h3 == h2 == 0.0 else ""))
self.trapezoidWall(y, h2, h1, "Ff" + edge_types[1] + "f", move="right" +
(" only" if h2 == h1 == 0.0 else ""))
self.trapezoidWall(x, h1, h0, "FF" + edge_types[0] + "F", move="right" +
(" only" if h1 == h0 == 0.0 else ""))
| 4,591 | Python | .py | 85 | 43.411765 | 118 | 0.577154 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,666 | rollholder.py | florianfesti_boxes/boxes/generators/rollholder.py | # Copyright (C) 2013-2016 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 *
class RollHolder(Boxes):
"""Holder for kitchen rolls or other rolls"""
description = """Needs a dowel or pipe as axle."""
ui_group = "WallMounted"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.argparser.add_argument(
"--width", action="store", type=float, default=275,
help="length of the axle in mm")
self.argparser.add_argument(
"--diameter", action="store", type=float, default=120,
help="maximum diameter of the roll in mm (choose generously)")
self.argparser.add_argument(
"--height", action="store", type=float, default=80,
help="height of mounting plate in mm")
self.argparser.add_argument(
"--axle", action="store", type=float, default=25,
help="diameter of the axle in mm including play")
self.argparser.add_argument(
"--screw_holes", action="store", type=float, default=4,
help="diameter of mounting holes in mm")
self.argparser.add_argument(
"--one_piece", action="store", type=boolarg, default=True,
help="have a continuous back plate instead of two separate holders")
def side(self, move=None):
d = self.diameter
a = self.axle
h = self.height
t = self.thickness
tw, th = h, (d + a) / 2 + 4 * t
if self.move(tw, th, move, True):
return
self.moveTo(0, t)
self.edges["f"](h)
self.fingerHolesAt(-(a/2+3*t), self.burn, d/2, 90)
self.polyline(0, 90, d/2, (90, a/2 + 3*t))
r = a/2 + 3*t
a = math.atan2(float(d/2), (h-a-6*t))
alpha = math.degrees(a)
self.corner(alpha, r)
self.edge(((h-2*r)**2+(d/2)**2)**0.5)
self.corner(90-alpha, r)
self.corner(90)
self.move(tw, th, move)
def backCB(self):
t = self.thickness
a = self.axle
h = self.height
w = self.width
plate = w + 2*t + h/2 if self.one_piece else h/2 + t
self.fingerHolesAt(h/4+t/2-3*t, 0, h, 90)
self.fingerHolesAt(h/4-3*t, h-3*t-a/2, h/4, 180)
if self.one_piece:
self.fingerHolesAt(h/4+t/2+t-3*t+w, 0, h, 90)
self.fingerHolesAt(h/4+2*t-3*t+w, h-3*t-a/2, h/4, 0)
for x in (0, plate-6*t):
for y in (3*t, h-3*t):
self.hole(x, y, d=self.screw_holes)
def rings(self):
a = self.axle
r = a/2
t = self.thickness
self.moveTo(0, a+1.5*t, -90)
for i in range(2):
self.polyline(r-1.5*t, (180, r+3*t), 0, (180, 1.5*t), 0,
(-180, r), r-1.5*t, (180, 1.5*t))
self.moveTo(a-t, a+12*t, 180)
def render(self):
t = self.thickness
w = self.width
d = self.diameter
a = self.axle
h = self.height
self.height = h = max(h, a+10*t)
self.side(move="right")
self.side(move="right")
self.rectangularTriangle(h/4, d/2, "ffe", num=2, r=3*t, move="right")
if self.one_piece:
self.roundedPlate(w+h/2+2*t, h, edge="e", r=3*t,
extend_corners=False,
callback=[self.backCB], move="right")
else:
self.roundedPlate(h/2+t, h, edge="e", r=3*t,
extend_corners=False,
callback=[self.backCB], move="right")
self.roundedPlate(h/2+t, h, edge="e", r=3*t,
extend_corners=False,
callback=[self.backCB], move="right mirror")
self.rings()
| 4,478 | Python | .py | 105 | 32.6 | 80 | 0.557883 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,667 | laserholdfast.py | florianfesti_boxes/boxes/generators/laserholdfast.py | # Copyright (C) 2013-2016 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 *
class LaserHoldfast(Boxes):
"""A holdfast for honey comb tables of laser cutters"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(x=25, h=40)
self.argparser.add_argument(
"--hookheight", action="store", type=float, default=5.0,
help="height of the top hook")
self.argparser.add_argument(
"--shaftwidth", action="store", type=float, default=5.0,
help="width of the shaft")
def render(self):
# adjust to the variables you want in the local scope
x, hh, h, sw = self.x, self.hookheight, self.h, self.shaftwidth
t = self.thickness
a = 30
r = x/math.radians(a)
self.polyline(hh+h, (180, sw/2), h, -90+a/2, 0, (-a, r), 0, (180, hh/2), 0, (a, r+hh), 0 , -a/2, sw-math.sin(math.radians(a/2))*hh , 90)
| 1,605 | Python | .py | 34 | 41.705882 | 144 | 0.65621 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,668 | cardholder.py | florianfesti_boxes/boxes/generators/cardholder.py | # Copyright (C) 2013-2021 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 *
class CardHolder(Boxes):
"""Shelf for holding (multiple) piles of playing cards / notes"""
ui_group = "Shelf"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.StackableSettings)
self.addSettingsArgs(edges.GroovedSettings)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=1.0)
self.buildArgParser(sx="68*3", y=100, h=40, outside=False)
self.argparser.add_argument(
"--angle", action="store", type=float, default=7.5,
help="backward angle of floor")
self.argparser.add_argument(
"--stackable", action="store", type=boolarg, default=True,
help="make holders stackable")
def side(self):
t = self.thickness
a = math.radians(self.angle)
pos_y = self.y - abs(0.5 * t * math.sin(a))
pos_h = t - math.cos(a) * 0.5 * t
self.fingerHolesAt(pos_y, pos_h, self.y, 180-self.angle)
def fingerHoleCB(self, length, posy=0.0):
def CB():
t = self.thickness
px = -0.5 * t
for x in self.sx[:-1]:
px += x + t
self.fingerHolesAt(px, posy, length, 90)
return CB
def middleWall(self, move=None):
y, h = self.y , self.h
a = self.angle
t = self.thickness
tw = y + t
th = h
if self.move(tw, th, move, True):
return
self.moveTo(t, t, a)
self.edges["f"](y)
self.polyline(0, 90-a, h-t-y*math.sin(math.radians(a)), 90,
y*math.cos(math.radians(a)), 90)
self.edges["f"](h-t)
self.move(tw, th, move)
def render(self):
sx, y = self.sx, self.y
t = self.thickness
bottom = "Å¡" if self.stackable else "e"
top = "S" if self.stackable else "e"
if self.outside:
self.sx = sx = self.adjustSize(sx)
h = self.h = self.adjustSize(self.h, bottom, top)
else:
h = self.h = self.h + t + y * math.sin(math.radians(self.angle))
self.x = x = sum(sx) + t * (len(sx) - 1)
self.rectangularWall(y, h, [bottom, "F", top, "e"],
ignore_widths=[1, 6],
callback=[self.side], move="up")
self.rectangularWall(y, h, [bottom, "F", top, "e"],
ignore_widths=[1, 6],
callback=[self.side], move="up mirror")
nx = len(sx)
f_lengths = []
for val in self.sx:
f_lengths.append(val)
f_lengths.append(t)
f_lengths = f_lengths[:-1]
frontedge = edges.CompoundEdge(
self, "e".join("z" * nx), f_lengths)
self.rectangularWall(x, y, [frontedge, "f", "e", "f"],
callback=[self.fingerHoleCB(y)], move="up")
self.rectangularWall(x, h, bottom + "f" + top + "f",
ignore_widths=[1, 6],
callback=[self.fingerHoleCB(h-t, t)], move="up")
for i in range(nx-1):
self.middleWall(move="right")
| 3,883 | Python | .py | 90 | 33 | 78 | 0.560329 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,669 | wallplaneholder.py | florianfesti_boxes/boxes/generators/wallplaneholder.py | # Copyright (C) 2013-2019 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.walledges import _WallMountedBox
class WallPlaneHolder(_WallMountedBox):
"""Hold a plane to a wall"""
def __init__(self) -> None:
super().__init__()
self.argparser.add_argument(
"--width", action="store", type=float, default=80,
help="width of the plane")
self.argparser.add_argument(
"--length", action="store", type=float, default=250,
help="length of the plane")
self.argparser.add_argument(
"--hold_length", action="store", type=float, default=30,
help="length of the part holding the plane over the front")
self.argparser.add_argument(
"--height", action="store", type=float, default=80,
help="height of the front of plane")
def side(self):
l, w, h = self.length, self.width, self.height
hl = self.hold_length
t = self.thickness
self.fingerHolesAt(1.5*t, 2*t, 0.25*l, 90)
self.fingerHolesAt(1.5*t, 2*t+0.75*l, 0.25*l, 90)
self.fingerHolesAt(2.5*t+h, 2*t+l-hl, hl, 90)
self.fingerHolesAt(2*t, 1.5*t, h+2*t, 0)
def render(self):
self.generateWallEdges()
l, w, h = self.length, self.width, self.height
t = self.thickness
self.rectangularWall(h+4*t, l+2*t, "eeea", callback=[self.side],
move="right")
self.rectangularWall(h+4*t, l+2*t, "eeea", callback=[self.side],
move="right")
self.rectangularWall(w, h+2*t, "efFf", move="up")
self.rectangularWall(w, 0.25*l, "ffef", move="up")
self.rectangularWall(w, 0.25*l, "efef", move="up")
self.rectangularWall(w, self.hold_length, "efef", move="up")
| 2,451 | Python | .py | 51 | 40.27451 | 73 | 0.628344 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,670 | dicebox.py | florianfesti_boxes/boxes/generators/dicebox.py | # Copyright (C) 2022 Erik Snider (SniderThanYou@gmail.com)
#
# 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 *
class DiceBox(Boxes):
"""Box with lid and integraded hinge for storing dice"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(
edges.FingerJointSettings,
surroundingspaces=2.0)
self.addSettingsArgs(
edges.ChestHingeSettings,
finger_joints_on_box=True,
finger_joints_on_lid=True)
self.buildArgParser(
x=100,
y=100,
h=18,
outside=True)
self.argparser.add_argument(
"--lidheight", action="store", type=float, default=18,
help="height of lid in mm")
self.argparser.add_argument(
"--hex_hole_corner_radius", action="store", type=float, default=5,
help="The corner radius of the hexagonal dice holes, in mm")
self.argparser.add_argument(
"--magnet_diameter", action="store", type=float, default=6,
help="The diameter of magnets for holding the box closed, in mm")
def diceCB(self):
t = self.thickness
xi = self.x - 2 * t
yi = self.y - 2 * t
xc = xi / 2
yc = yi / 2
cr = self.hex_hole_corner_radius
# -4*t because there are four gaps across:
# 2 between the outer holes and the finger joints
# 2 between the outer holes and the center hole
# /6 because there are 6 apothems across, 2 for each hexagon
apothem = (min(xi, yi) - 4 * t) / 6
r = apothem * 2 / math.sqrt(3)
# dice
centers = [[xc, yc]] # start with one in the center
polar_r = 2 * apothem + t # the full width of a hexagon, plus a gap of t width
for i in range(6):
theta = i * math.pi / 3 # 60 degrees each step
centers.append(
[
xc + polar_r * math.cos(theta),
yc + polar_r * math.sin(theta),
]
)
for center in centers:
self.regularPolygonHole(x=center[0], y=center[1], n=6, r=r, corner_radius=cr, a=30)
# magnets
d = self.magnet_diameter
mo = t + d/2
self.hole(mo, mo, d=d)
self.hole(xi-mo, mo, d=d)
def render(self):
x, y, h, hl = self.x, self.y, self.h, self.lidheight
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h)
hl = self.adjustSize(hl)
t = self.thickness
hy = self.edges["O"].startwidth()
hy2 = self.edges["P"].startwidth()
e1 = edges.CompoundEdge(self, "eF", (hy-t, h-hy+t))
e2 = edges.CompoundEdge(self, "Fe", (h-hy+t, hy-t))
e_back = ("F", e1, "F", e2)
p = self.edges["o"].settings.pin_height
e_inner_1 = edges.CompoundEdge(self, "fe", (y-p, p))
e_inner_2 = edges.CompoundEdge(self, "ef", (p, y-p))
e_inner_topbot = ("f", e_inner_1, "f", e_inner_2)
self.ctx.save()
self.rectangularWall(x, y, e_inner_topbot, move="up", callback=[self.diceCB])
self.rectangularWall(x, y, e_inner_topbot, move="up", callback=[self.diceCB])
self.rectangularWall(x, h, "FFFF", ignore_widths=[1,2,5,6], move="up")
self.rectangularWall(x, h, e_back, move="up")
self.rectangularWall(x, hl, "FFFF", ignore_widths=[1,2,5,6], move="up")
self.rectangularWall(x, hl-hy2+t, "FFqF", move="up")
self.ctx.restore()
self.rectangularWall(x, y, "ffff", move="right only")
self.rectangularWall(y, x, "ffff", move="up")
self.rectangularWall(y, x, "ffff", move="up")
self.rectangularWall(y, hl-hy2+t, "Ffpf", ignore_widths=[5,6], move="up")
self.rectangularWall(y, h-hy+t, "OfFf", ignore_widths=[5,6], move="up")
self.rectangularWall(y, h-hy+t, "Ffof", ignore_widths=[5,6], move="up")
self.rectangularWall(y, hl-hy2+t, "PfFf", ignore_widths=[5,6], move="up")
| 4,744 | Python | .py | 104 | 36.586538 | 95 | 0.587319 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,671 | winerack.py | florianfesti_boxes/boxes/generators/winerack.py | # Copyright (C) 2013-2016 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 *
class WineRack(Boxes):
"""Honey Comb Style Wine Rack"""
ui_group = "Shelf"
def __init__(self) -> None:
Boxes.__init__(self)
# Uncomment the settings for the edge types you use
self.addSettingsArgs(edges.FingerJointSettings)
# remove cli params you do not need
self.buildArgParser(x=400, y=300, h=210)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--radius", action="store", type=float, default=46.,
help="Radius of comb")
self.argparser.add_argument(
"--walls", action="store", type=str, default="all",
choices=("minimal", "no_verticals", "all"),
help="which of the honey comb walls to add")
def hexFingerHoles(self, x, y, l, angle=90):
with self.saved_context():
self.moveTo(x, y, angle)
self.moveTo(self.delta, 0, 0)
self.fingerHolesAt(0, 0, l-2*self.delta, 0)
def wallCB(self, frontwall=False, backwall=False):
r = self.r
x, y, h = self.x, self.y, self.h
dx, dy = self.dx, self.dy
cx, cy = self.cx, self.cy
t = self.thickness
if cy % 2:
ty = cy // 2 * (2*dy + 2*r) + 2*dy + r
else:
ty = cy // 2 * (2*dy + 2*r) + dy
self.moveTo((x-dx*2*cx)/2, (y-ty) / 2)
wmin = self.walls == "minimal"
for i in range(cy//2 + cy % 2):
if not frontwall and self.walls == "all":
self.hexFingerHoles(0, (2*r+2*dy)*i+dy, r, 90)
for j in range(cx):
if not backwall:
self.hole(j*2*dx+dx, (2*r+2*dy)*i + r, dx-t)
if frontwall:
continue
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i, r, 150)
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i, r, 30)
if self.walls == "all":
self.hexFingerHoles(j*2*dx+2*dx, (2*r+2*dy)*i+dy, r, 90)
if wmin and i == cy//2: # top row
continue
if j>0 or not wmin:
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i+r+2*dy, r, -150)
if j<cx-1 or not wmin:
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i+r+2*dy, r, -30)
if i < cy//2:
for j in range(cx):
if not frontwall and self.walls == "all":
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i+r+2*dy, r, 90)
if not backwall:
for j in range(1, cx):
self.hole(j*2*dx, (2*r+2*dy)*i + 2*r + dy, dx-t)
if cy % 2:
pass
else:
i = cy // 2
for j in range(cx):
if frontwall or wmin:
break
if j > 0:
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i, r, 150)
if j < cx -1:
self.hexFingerHoles(j*2*dx+dx, (2*r+2*dy)*i, r, 30)
def render(self):
x, y, h, radius = self.x, self.y, self.h, self.radius
t = self.thickness
r = self.r = 2 * (radius + t) * math.tan(math.pi/6)
self.dx = dx = r * math.cos(math.pi/6)
self.dy = dy = r * math.sin(math.pi/6)
self.cx = cx = int((x-2*t) // (2*dx))
self.cy = cy = int((y-dy-t) // (r+dy))
self.delta = 3**0.5/6.*t
self.rectangularWall(x, y, callback=[self.wallCB], move="up")
self.rectangularWall(x, y, callback=[lambda:self.wallCB(backwall=True)], move="up")
self.rectangularWall(x, y, callback=[lambda:self.wallCB(frontwall=True)], move="up")
if self.walls == "all":
tc = (cy//2 + cy % 2) * (6 * cx + 1)
else:
tc = (cy//2 + cy % 2) * (4 * cx)
if self.walls == "minimal":
tc -= 2 * (cy//2) # roofs of outer cells
if cy % 2:
if self.walls == "all":
tc -= cx
else:
if self.walls != "minimal":
tc += 2 * cx - 2 # very top row
self.partsMatrix(tc, cx, "up", self.rectangularWall, r-2*self.delta, h, "fefe")
| 4,943 | Python | .py | 110 | 33.709091 | 92 | 0.52182 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,672 | wallcaliperholder.py | florianfesti_boxes/boxes/generators/wallcaliperholder.py | # Copyright (C) 2013-2019 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.walledges import _WallMountedBox
class WallCaliper(_WallMountedBox):
"""Holds a single caliper to a wall"""
def __init__(self) -> None:
super().__init__()
# remove cli params you do not need
self.buildArgParser(h=100)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--width", action="store", type=float, default=18.0,
help="width of the long end")
self.argparser.add_argument(
"--height", action="store", type=float, default=6.0,
help="height of the body")
def side(self, move=None):
t = self.thickness
h = self.h
hc = self.height
tw = self.edges["b"].spacing() + hc + 8*t
if self.move(tw, h, move, True):
return
self.moveTo(self.edges["b"].startwidth())
self.polyline(5*t+hc, (90, 2*t), h/2-2*t, (180, 1.5*t), 0.25*h,
-90, hc, -90, 0.75*h-2*t, (90, 2*t), 2*t, 90)
self.edges["b"](h)
self.move(tw, h, move)
def render(self):
self.generateWallEdges()
t = self.thickness
h = self.h
self.side(move="right")
self.side(move="right")
w = self.width
self.flangedWall(w, h, flanges=[0, 2*t, 0, 2*t], edges="eeee",
r=2*t,
callback=[lambda:(self.wallHolesAt(1.5*t, 0, h, 90), self.wallHolesAt(w+2.5*t, 0, h, 90))])
| 2,196 | Python | .py | 50 | 36.16 | 116 | 0.608818 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,673 | piratechest.py | florianfesti_boxes/boxes/generators/piratechest.py | # Copyright (C) 2013-2016 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 *
class PirateChest(Boxes):
"""Box with polygon lid with chest hinges."""
description = """Do not assemble sides before attaching the lid!
Hinge of the lid has to be placed first because it is impossible
to get it in position without removing the side wall. The lid can
be a bit tricky to assemble. Keep track of how the parts fit together.
Part with label "lid back" is placed in the hinges"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, finger=1.0,space=1.0)
self.addSettingsArgs(edges.HingeSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--n", action="store", type=int, default=5,
help="number of sides on the lid. n ≥ 3")
def render(self):
# adjust to the variables you want in the local scope
x, y, h = self.x, self.y, self.h
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h, "f", False)
t = self.thickness
n = self.n
if (n < 3):
raise ValueError("number of sides on the lid must be greater or equal to 3 (got %i)" % n)
hy = self.edges["O"].startwidth()
h -= hy
if (h < 0):
raise ValueError("box to low to allow for hinge (%i)" % h)
# create edge for non 90 degree joints in the lid
fingerJointSettings = copy.deepcopy(self.edges["f"].settings)
fingerJointSettings.setValues(self.thickness, angle=180./(n-1))
fingerJointSettings.edgeObjects(self, chars="gGH")
# render all parts
self.ctx.save()
self.rectangularWall(x, y, "FFFF", move="up", label="Bottom")
frontlid, toplids, backlid = self.topside(y, n = n, move="only", bottom='P')
self.rectangularWall(x, backlid, "qFgF", move="up", label="lid back")
for _ in range(n-2):
self.rectangularWall(x, toplids, "GFgF", move="up", label="lid top")
self.rectangularWall(x, frontlid, "GFeF", move="up", label="lid front")
self.ctx.restore()
self.rectangularWall(x, y, "FFFF", move="right only")
with self.saved_context():
self.rectangularWall(x, h, "fFQF", ignore_widths=[2, 5], move="right", label="front")
self.rectangularWall(y, h, "ffof", ignore_widths=[5], move="right", label="right")
self.rectangularWall(0, h, "eeep", move="right only")
self.rectangularWall(x, h, "fFoF", move="up only")
self.rectangularWall(x, 0, "Peee", move="up only")
e1 = edges.CompoundEdge(self, "Fe", (h, hy))
e2 = edges.CompoundEdge(self, "eF", (hy, h))
e_back = ("f", e1, "e", e2)
with self.saved_context():
self.rectangularWall(x, h+hy, e_back, move="right", label="back") # extend back to correct height
self.rectangularWall(0, h, "ePee", move="right only")
self.rectangularWall(y, h, "ffOf", ignore_widths=[2], move="right", label="left")
self.rectangularWall(x, h, "fFOF", move="up only")
self.rectangularWall(x, 0, "peee", move="up only")
self.topside(y, n = n, move="right", bottom='p', label="lid left")
self.topside(y, n = n, move="right", bottom='P', label="lid right")
def topside(self, y, n, bottom, move=None, label=""):
radius, hp, side = self.regularPolygon((n - 1) * 2, h=y/2.0)
tx = y + 2 * self.edges.get('f').spacing()
lidheight = hp if n % 2 else radius
ty = lidheight + self.edges.get('f').spacing() + self.edges.get(bottom).spacing()
if self.move(tx, ty, move, before=True):
return side/2 + self.edges.get(bottom).spacing(), side, side/2
self.moveTo(self.edges.get('f').margin(), self.edges.get(bottom).margin())
self.edges.get(bottom)(y)
self.corner(90)
if bottom == 'p':
self.edges.get('f')(side/2 + self.edges.get(bottom).spacing())
else:
self.edges.get('f')(side/2)
self.corner(180 / (n - 1))
for _ in range(n-2):
self.edges.get('f')(side)
self.corner(180 / (n - 1))
if bottom == 'P':
self.edges.get('f')(side/2 + self.edges.get(bottom).spacing())
else:
self.edges.get('f')(side/2)
self.corner(90)
self.move(tx, ty, move, label=label)
return side/2 + self.edges.get(bottom).spacing(), side, side/2
| 5,282 | Python | .py | 102 | 43.294118 | 109 | 0.612471 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,674 | discrack.py | florianfesti_boxes/boxes/generators/discrack.py | # Copyright (C) 2019 chrysn <chrysn@fsfe.org>
#
# 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 math import cos, pi, sin, sqrt
from boxes import *
def offset_radius_in_square(squareside, angle, outset):
"""From the centre of a square, rotate by an angle relative to the
vertical, move away from the center (down if angle = 0), and then in a
right angle until the border of the square. Return the length of that last
segment.
Note that for consistency with other boxes.py methods, angle is given in
degree.
>>> # Without rotation, it's always half the square length
>>> offset_radius_in_square(20, 0, 0)
10.0
>>> offset_radius_in_square(20, 0, 5)
10.0
>>> # Without offset, it's half square length divided by cos(angle) -- at
>>> # least before it hits the next wall
>>> offset_radius_in_square(20, 15, 0) # doctest:+ELLIPSIS
10.35276...
>>> offset_radius_in_square(20, 45, 0) # doctest:+ELLIPSIS
14.1421...
>>> # Positive angles make the segment initially shorter...
>>> offset_radius_in_square(20, 5, 10) < 10
True
>>> # ... while negative angles make it longer.
>>> offset_radius_in_square(20, -5, 10) > 10
True
"""
if angle <= -90:
return offset_radius_in_square(squareside, angle + 180, outset)
if angle > 90:
return offset_radius_in_square(squareside, angle - 180, outset)
angle = angle / 180 * pi
step_right = outset * sin(angle)
step_down = outset * cos(angle)
try:
len_right = (squareside / 2 - step_right) / cos(angle)
except ZeroDivisionError:
return squareside / 2
if angle == 0:
return len_right
if angle > 0:
len_up = (squareside / 2 + step_down) / sin(angle)
return min(len_up, len_right)
else: # angle < 0
len_down = - (squareside / 2 - step_down) / sin(angle)
return min(len_down, len_right)
class DiscRack(Boxes):
"""A rack for storing disk-shaped objects vertically next to each other"""
ui_group = "Shelf"
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser(sx="20*10")
self.argparser.add_argument(
"--disc_diameter", action="store", type=float, default=150.0,
help="Disc diameter in mm")
self.argparser.add_argument(
"--disc_thickness", action="store", type=float, default=5.0,
help="Thickness of the discs in mm")
self.argparser.add_argument(
"--lower_factor", action="store", type=float, default=0.75,
help="Position of the lower rack grids along the radius")
self.argparser.add_argument(
"--rear_factor", action="store", type=float, default=0.75,
help="Position of the rear rack grids along the radius")
self.argparser.add_argument(
"--disc_outset", action="store", type=float, default=3.0,
help="Additional space kept between the disks and the outbox of the rack")
# These can be parameterized, but the default value of pulling them up
# to the box front is good enough for so many cases it'd only clutter
# the user interface.
#
# The parameters can be resurfaced when there is something like rare or
# advanced settings.
'''
self.argparser.add_argument(
"--lower_outset", action="store", type=float, default=0.0,
help="Space in front of the disk slits (0: automatic)")
self.argparser.add_argument(
"--rear_outset", action="store", type=float, default=0.0,
help="Space above the disk slits (0: automatic)")
'''
self.argparser.add_argument(
"--angle", action="store", type=float, default=18,
help="Backwards slant of the rack")
self.addSettingsArgs(edges.FingerJointSettings)
def parseArgs(self, *args, **kwargs):
Boxes.parseArgs(self, *args, **kwargs)
self.lower_outset = self.rear_outset = 0
self.calculate()
def calculate(self):
self.outer = self.disc_diameter + 2 * self.disc_outset
r = self.disc_diameter / 2
# distance between radius line and front (or rear) end of the slit
self.lower_halfslit = r * sqrt(1 - self.lower_factor**2)
self.rear_halfslit = r * sqrt(1 - self.rear_factor**2)
if True: # self.lower_outset == 0: # when lower_outset parameter is re-enabled
toplim = offset_radius_in_square(self.outer, self.angle, r * self.lower_factor)
# With typical positive angles, the lower surface of board will be limiting
bottomlim = offset_radius_in_square(self.outer, self.angle, r * self.lower_factor + self.thickness)
self.lower_outset = min(toplim, bottomlim) - self.lower_halfslit
if True: # self.rear_outset == 0: # when rear_outset parameter is re-enabled
# With typical positive angles, the upper surface of board will be limiting
toplim = offset_radius_in_square(self.outer, -self.angle, r * self.rear_factor)
bottomlim = offset_radius_in_square(self.outer, -self.angle, r * self.rear_factor + self.thickness)
self.rear_outset = min(toplim, bottomlim) - self.rear_halfslit
# front outset, space to radius, space to rear part, plus nothing as fingers extend out
self.lower_size = self.lower_outset + \
self.lower_halfslit + \
r * self.rear_factor
self.rear_size = r * self.lower_factor + \
self.rear_halfslit + \
self.rear_outset
self.warn_on_demand()
def warn_on_demand(self):
warnings = []
# Are the discs supported on the outer ends?
def word_thickness(length):
if length > 0:
return f"very thin ({length:.2g} mm at a thickness of {self.thickness:.2g} mm)"
if length < 0:
return "absent"
if self.rear_outset < self.thickness:
warnings.append("Rear upper constraint is %s. Consider increasing the disc outset parameter, or move the angle away from 45°." % word_thickness(self.rear_outset))
if self.lower_outset < self.thickness:
warnings.append("Lower front constraint is %s. Consider increasing the disc outset parameter, or move the angle away from 45°." % word_thickness(self.lower_outset))
# Are the discs supported where the grids meet?
r = self.disc_diameter / 2
inner_lowerdistance = r * self.rear_factor - self.lower_halfslit
inner_reardistance = r * self.lower_factor - self.rear_halfslit
if inner_lowerdistance < 0 or inner_reardistance < 0:
warnings.append("Corner is inside the disc radios, discs would not be supported. Consider increasing the factor parameters.")
# Won't the type-H edge on the rear side make the whole contraption
# wiggle?
max_slitlengthplush = offset_radius_in_square(
self.outer, self.angle, r * self.rear_factor + self.thickness)
slitlengthplush = self.rear_halfslit + self.thickness * ( 1 +
self.edgesettings['FingerJoint']['edge_width'])
if slitlengthplush > max_slitlengthplush:
warnings.append("Joint would protrude from lower box edge. Consider increasing the disc outset parameter, or move the angle away from 45°.")
# Can the discs be removed at all?
# Does not need explicit checking, for Thales' theorem tells us that at
# the point where there is barely support in the corner, three contact
# points on the circle form just a semicircle and the discs can be
# inserted/removed. When we keep the other contact points and move the
# slits away from the corner, the disc gets smaller and thus will fit
# through the opening that is as wide as the diameter of the largest
# possible circle.
# Act on warnings
if warnings:
self.argparser.error("\n".join(warnings))
def sidewall_holes(self):
r = self.disc_diameter / 2
self.moveTo(self.outer/2, self.outer/2, -self.angle)
# can now move down to paint horizontal lower part, or right to paint
# vertical rear part
with self.saved_context():
self.moveTo(
r * self.rear_factor,
-r * self.lower_factor - self.thickness/2,
90)
self.fingerHolesAt(0, 0, self.lower_size)
with self.saved_context():
self.moveTo(
r * self.rear_factor + self.thickness/2,
-r * self.lower_factor,
0)
self.fingerHolesAt(0, 0, self.rear_size)
if self.debug:
self.circle(0, 0, self.disc_diameter / 2)
def _draw_slits(self, inset, halfslit):
total_x = 0
for x in self.sx:
center_x = total_x + x / 2
total_x += x
self.rectangularHole(inset, center_x, 2 * halfslit, self.disc_thickness)
if self.debug:
self.ctx.rectangle(inset - halfslit, center_x - x/2, 2 * halfslit, x)
def lower_holes(self):
r = self.disc_diameter / 2
inset = self.lower_outset + self.lower_halfslit
self._draw_slits(inset, self.lower_halfslit)
def rear_holes(self):
r = self.disc_diameter / 2
inset = r * self.lower_factor
self._draw_slits(inset, self.rear_halfslit)
def render(self):
o = self.outer
self.lower_factor = min(self.lower_factor, 0.99)
self.rear_factor = min(self.rear_factor, 0.99)
self.rectangularWall(o, o, "eeee", move="right", callback=[self.sidewall_holes])
self.rectangularWall(o, o, "eeee", move="right mirror", callback=[self.sidewall_holes])
self.rectangularWall(self.lower_size, sum(self.sx), "fffe", move="right", callback=[self.lower_holes])
self.rectangularWall(self.rear_size, sum(self.sx), "fefh", move="right", callback=[self.rear_holes])
| 10,763 | Python | .py | 207 | 42.792271 | 176 | 0.635315 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,675 | coindisplay.py | florianfesti_boxes/boxes/generators/coindisplay.py | # Copyright (C) 2013-2016 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 *
class CoinHolderSideEdge(edges.BaseEdge):
char = "B"
def __call__(self, length, **kw):
a_l = self.coin_plate
a_l2 = self.settings.coin_plate * math.sin(self.settings.angle)
a = math.degrees(self.settings.angle)
self.corner(-a)
# Draw the angled edge, but set the thickness to two temporarily
# as two pieces will go on top of another
self.edges["F"].settings.thickness = self.thickness * 2
self.edges["F"](a_l)
self.edges["F"].settings.thickness = self.thickness
self.polyline(0, 90+a, a_l2, -90)
def margin(self) -> float:
return self.settings.coin_plate_x
class CoinDisplay(Boxes):
"""A showcase for a single coin"""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--coin_d", action="store", type=float, default=20.0,
help="The diameter of the coin in mm")
self.argparser.add_argument(
"--coin_plate", action="store", type=float, default=50.0,
help="The size of the coin plate")
self.argparser.add_argument(
"--coin_showcase_h", action="store", type=float, default=50.0,
help="The height of the coin showcase piece")
self.argparser.add_argument(
"--angle", action="store", type=float, default=30,
help="The angle that the coin will tilt as")
def bottomHoles(self):
"""
Function that puts two finger holes at the bottom cube plate for the coin holder
"""
self.fingerHolesAt(self.x/2 - self.thickness - self.thickness/2 - (self.coin_plate/2), self.y/2+self.coin_plate_x/2-self.thickness, self.coin_plate_x, -90)
self.fingerHolesAt(self.x/2 - self.thickness + self.thickness/2 + (self.coin_plate/2), self.y/2+self.coin_plate_x/2-self.thickness, self.coin_plate_x, -90)
self.fingerHolesAt(self.x/2-self.coin_plate/2-self.thickness, self.y/2-self.coin_plate_x/2-self.thickness*1.5, self.coin_plate, 0)
def coinCutout(self):
"""
Function that puts a circular hole in the coin holder piece
"""
self.hole(self.coin_plate/2, self.coin_plate/2, self.coin_d/2)
def render(self):
x, y, h = self.x, self.y, self.h
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h)
t = self.thickness
d2 = edges.Bolts(2)
d3 = edges.Bolts(3)
d2 = d3 = None
self.addPart(CoinHolderSideEdge(self, self))
self.angle = math.radians(self.angle)
self.coin_plate_x = self.coin_plate * math.cos(self.angle)
self.rectangularWall(x, h, "FFFF", bedBolts=[d2] * 4, move="right", label="Wall 1")
self.rectangularWall(y, h, "FfFf", bedBolts=[d3, d2, d3, d2], move="up", label="Wall 2")
self.rectangularWall(y, h, "FfFf", bedBolts=[d3, d2, d3, d2], label="Wall 4")
self.rectangularWall(x, h, "FFFF", bedBolts=[d2] *4, move="left up", label="Wall 3")
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right", label="Top")
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right", label="Bottom", callback=[self.bottomHoles])
# Draw the coin holder side holsers
e = ["f", "f", "B", "e"]
self.rectangularWall(self.coin_plate_x, self.coin_showcase_h, e, move="right", label="CoinSide1")
self.rectangularWall(self.coin_plate_x, self.coin_showcase_h, e, move="right", label="CoinSide2")
self.rectangularWall(self.coin_plate, self.coin_plate, "efef", move="left down", label="Coin Plate Base")
self.rectangularWall(self.coin_plate, self.coin_plate, "efef", move="down", label="Coin Plate", callback=[self.coinCutout])
self.rectangularWall(self.coin_plate, self.coin_showcase_h, "fFeF", move="down", label="CoinSide3")
| 4,797 | Python | .py | 87 | 47.310345 | 163 | 0.644748 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,676 | shutterbox.py | florianfesti_boxes/boxes/generators/shutterbox.py | # Copyright (C) 2013-2016 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 *
class ShutterBox(Boxes):
"""Box with a rolling shutter made of flex"""
ui_group = "FlexBox"
description = """Beware of the rolling shutter effect! Use wax on sliding surfaces.


"""
def side(self, l, h, r, style, move=None):
t = self.thickness
if self.move(l+2*t, h+2*t, move, True):
return
self.moveTo(t, t)
self.ctx.save()
n = self.n
a = 90. / n
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
#self.hole(l-r, r, r-2.5*t)
if style == "double":
#self.hole(r, r, r-2.5*t)
self.ctx.save()
self.fingerHolesAt(r, 2*t, l-2*r, 0)
self.moveTo(r, 2.5*t, 180 - a/2)
for i in range(n):
self.fingerHolesAt(0, 0.5*t, ls, 0)
self.moveTo(ls, 0, -a)
if h - 2*r > 2*t:
self.moveTo(0, 0, a/2)
self.fingerHolesAt(0, 0.5*t, h - 2*r, 0)
self.ctx.restore()
else:
self.fingerHolesAt(0, 2*t, l-r, 0)
self.moveTo(l-r, 2.5*t, a/2)
for i in range(n):
self.fingerHolesAt(0, -0.5*t, ls, 0)
self.moveTo(ls, 0, a)
if h - 2*r > 2*t:
self.moveTo(0, 0, -a/2)
self.fingerHolesAt(0, -0.5*t, h - 2*r, 0)
self.ctx.restore()
self.edges["f"](l)
self.corner(90)
self.edges["f"](h-r)
self.polyline(0, -90, t, 90, 0, (90, r+t))
if style == "single":
self.polyline(l-r, 90, t)
self.edges["f"](h)
else:
self.polyline(l-2*r, (90, r+t), 0, 90, t, -90)
self.edges["f"](h-r)
self.move(l+2*t, h+2*t, move)
def cornerRadius(self, r, two=False, move=None):
s = self.spacing
if self.move(r, r+s, move, True):
return
for i in range(2 if two else 1):
self.polyline(r, 90, r, 180, 0, (-90, r), 0 ,-180)
self.moveTo(r, r+s, 180)
self.move(r, r+s, move)
def rails(self, l, r, move=None):
t = self.thickness
s = self.spacing
tw, th = l+2.5*t+3*s, r+1.5*t+3*s
if self.move(tw, th, move, True):
return
self.moveTo(2.5*t+s, 0)
self.polyline(l-r, (90, r+t), 0, 90, t, 90, 0, (-90, r), l-r, 90, t, 90)
self.moveTo(-t-s, t+s)
self.polyline(l-r, (90, r+t), 0, 90, t, 90, 0, (-90, r), l-r, 90, t, 90)
self.moveTo(0.5*t, t+s)
self.polyline(l-r, (90, r-1.5*t), 0, 90, t, 90, 0, (-90, r-2.5*t), l-r, 90, t, 90)
self.moveTo(-t-s, t+s)
self.polyline(l-r, (90, r-1.5*t), 0, 90, t, 90, 0, (-90, r-2.5*t), l-r, 90, t, 90)
self.move(tw, th, move)
def rails2(self, l, r, move=None):
t = self.thickness
s = self.spacing
tw, th = l+2.5*t+3*s, 2*r+t
if self.move(tw, th, move, True):
return
self.moveTo(r+t, 0)
for i in range(2):
self.polyline(l-2*r, (90, r+t), 0, 90, t, 90, 0, (-90, r), l-2*r,
(-90, r), 0, 90, t, 90, 0, (90, r+t))
self.moveTo(0, 1.5*t)
self.polyline(l-2*r, (90, r-1.5*t), 0, 90, t, 90, 0, (-90, r-2.5*t), l-2*r,
(-90, r-2.5*t), 0, 90, t, 90, 0, (90, r-1.5*t))
self.moveTo(0, r)
self.move(tw, th, move)
def door(self, l, h, move=None):
t = self.thickness
if self.move(l, h, move, True):
return
self.fingerHolesAt(t, t, h-2*t)
self.edge(2*t)
self.edges["X"](l-2*t, h)
self.polyline(0, 90, h, 90, l, 90, h, 90)
self.move(l, h, move)
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0.5)
self.addSettingsArgs(edges.FlexSettings, distance=.75, connection=2.)
self.buildArgParser(x=100, y=150, h=100)
self.argparser.add_argument(
"--radius", action="store", type=float, default=40.0,
help="radius of the corners")
self.argparser.add_argument(
"--style", action="store", type=str, default="single",
choices=["single", "double"],
help="Number of rounded top corners")
def render(self):
x, y, h, r = self.x, self.y, self.h, self.radius
style = self.style
self.n = n = 3
if not r:
self.radius = r = h / 2
self.radius = r = min(r, h/2)
t = self.thickness
self.ctx.save()
self.side(y, h, r, style, move="right")
self.side(y, h, r, style, move="right")
if style == "single":
self.rectangularWall(x, h, "fFEF", move="right")
else:
self.rectangularWall(x, h-r, "fFeF", move="right")
self.rectangularWall(x, h-r, "fFeF", move="right")
if style == "double":
self.cornerRadius(r, two=True, move="right")
self.cornerRadius(r, two=True, move="right")
if style == "single":
self.rails(y, r, move="right")
else:
self.rails2(y, r, move="right")
self.ctx.restore()
self.side(y, h, r, style, move="up only")
self.rectangularWall(y, x, "FFFF", move="right")
if style == "single":
self.door(y-r+0.5*math.pi*r + 3*t, x-0.2*t, move="right")
else:
self.door(y-2*r+math.pi*r + 3*t, x-0.2*t, move="right")
self.rectangularWall(2*t, x-2.2*t, edges="eeef", move="right")
a = 90. / n
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
edges.FingerJointSettings(t, angle=a).edgeObjects(self, chars="aA")
edges.FingerJointSettings(t, angle=a/2).edgeObjects(self, chars="bB")
if style == "double":
if h - 2*r > 2*t:
self.rectangularWall(h - 2*r, x, "fBfe", move="right")
self.rectangularWall(ls, x, "fAfb", move="right")
else:
self.rectangularWall(ls, x, "fAfe", move="right")
for i in range(n-2):
self.rectangularWall(ls, x, "fAfa", move="right")
self.rectangularWall(ls, x, "fBfa", move="right")
self.rectangularWall(y-2*r, x, "fbfb", move="right")
else:
self.rectangularWall(y-r, x, "fbfe", move="right")
self.rectangularWall(ls, x, "fafB", move="right")
for i in range(n-2):
self.rectangularWall(ls, x, "fafA", move="right")
if h - 2*r > 2*t:
self.rectangularWall(ls, x, "fbfA", move="right")
self.rectangularWall(h - 2*r, x, "fefB", move="right")
else:
self.rectangularWall(ls, x, "fefA", move="right")
| 7,567 | Python | .py | 179 | 32.379888 | 90 | 0.528626 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,677 | polehook.py | florianfesti_boxes/boxes/generators/polehook.py | # Copyright (C) 2013-2016 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 *
class PoleHook(Boxes): # change class name here and below
"""Hook for pole like things to be clamped to another pole"""
def __init__(self) -> None:
Boxes.__init__(self)
# Uncomment the settings for the edge types you use
self.addSettingsArgs(edges.FingerJointSettings)
# Add non default cli params if needed (see argparse std lib)
self.argparser.add_argument(
"--diameter", action="store", type=float, default=50.,
help="diameter of the thing to hook")
self.argparser.add_argument(
"--screw", action="store", type=float, default=7.8,
help="diameter of the screw in mm")
self.argparser.add_argument(
"--screwhead", action="store", type=float, default=13.,
help="with of the screw head in mm")
self.argparser.add_argument(
"--screwheadheight", action="store", type=float, default=5.5,
help="height of the screw head in mm")
self.argparser.add_argument(
"--pin", action="store", type=float, default=4.,
help="diameter of the pin in mm")
def fork(self, d, w, edge="e", full=True, move=None):
tw = d + 2 * w
th = 2 * d
if self.move(tw, th, move, True):
return
e = self.edges.get(edge, edge)
self.moveTo(0, e.margin())
if e is self.edges["e"]:
self.bedBoltHole(tw)
else:
e(tw, bedBolts=edges.Bolts(1))
if full:
self.hole(-0.5*w, 2*d, self.pin/2)
self.polyline(0, 90, 2*d, (180, w/2), d, (-180, d/2),
0.5*d, (180, w/2), 1.5 * d, 90)
else:
self.polyline(0, 90, d, 90, w, 90, 0, (-180, d/2),
0.5*d, (180, w/2), 1.5 * d, 90)
self.move(tw, th, move)
def lock(self, l1, l2, w, move=None):
l1 += w/2
l2 += w/2
if self.move(l1, l2, move, True):
return
self.hole(w/2, w/2, self.pin/2)
self.moveTo(w/2, 0)
self.polyline(l2-w, (180, w/2), l2-2*w, (-90, w/2), l1-2*w, (180, w/2),
l1-w, (90, w/2))
self.move(l1, l2, move)
def backplate(self):
tw = self.diameter + 2*self.ww
t = self.thickness
b = edges.Bolts(1)
bs = (0.0, )
self.fingerHolesAt(-tw/2, -2*t, tw, 0, bedBolts=b, bedBoltSettings=bs)
self.fingerHolesAt(-tw/2, 0, tw, 0, bedBolts=b, bedBoltSettings=bs)
self.fingerHolesAt(-tw/2, +2*t, tw, 0, bedBolts=b, bedBoltSettings=bs)
def clamp(self):
d = self.diameter + 2 * self.ww
self.moveTo(10, -0.5*d, 90)
self.edge(d)
self.moveTo(0, -8, -180)
self.edge(d)
def render(self):
# adjust to the variables you want in the local scope
d = self.diameter
t = self.thickness
shh = self.screwheadheight
self.bedBoltSettings = (self.screw, self.screwhead, shh, d/4+shh, d/4) # d, d_nut, h_nut, l, l
self.ww = ww = 4*t
self.fork(d, ww, "f", move="right")
self.fork(d, ww, "f", move="right")
self.fork(d, ww, "f", full=False, move="right")
self.fork(d, ww, full=False, move="right")
self.fork(d, ww, full=False, move="right")
self.parts.disc(d+2*ww, callback=self.backplate, hole=self.screw, move="right")
self.parts.disc(d+2*ww, hole=self.screw, move="right")
self.parts.disc(d+2*ww, callback=self.clamp, hole=self.screw+0.5*t, move="right")
self.parts.disc(d+2*ww, hole=self.screw+0.5*t, move="right")
self.parts.wavyKnob(50, callback=lambda:self.nutHole(self.screwhead),
move="right")
self.parts.wavyKnob(50, callback=lambda:self.nutHole(self.screwhead),
move="right")
self.parts.wavyKnob(50, hole=self.screw+0.5*t, move="right")
ll = ((d**2 + (0.5*(d+ww))**2)**0.5) - 0.5 * d
for i in range(3):
self.lock(ll, ll, ww, move="right")
for i in range(2):
self.parts.disc(ww, move="up")
| 4,862 | Python | .py | 106 | 36.556604 | 103 | 0.576769 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,678 | ubox.py | florianfesti_boxes/boxes/generators/ubox.py | # Copyright (C) 2013-2017 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 boxes.lids import LidSettings, _TopEdge
class UBox(_TopEdge):
"""Box various options for different stypes and lids"""
ui_group = "FlexBox"
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.angle = 0
def U(self, x, y, r, edge="e", move=None, label=""):
e = self.edges.get(edge, edge)
w = self.edges["f"].spacing()
tw = x+2*w
th = y+w+e.spacing()
if self.move(tw, th, move, True, label=label):
return
self.moveTo(w+r, w)
self.edges["f"](x-2*r)
self.corner(90, r)
self.edges["f"](y-r)
self.edgeCorner("f", e)
e(x)
self.edgeCorner(e, "f")
self.edges["f"](y-r)
self.corner(90, r)
self.move(tw, th, move, label=label)
def Uwall(self, x, y, h, r, edges="ee", move=None, label=""):
e = [self.edges.get(edge, edge) for edge in edges]
w = self.edges["F"].spacing()
cl = r*math.pi/2
tw = 2*y + x - 4*(cl-r) + e[0].spacing() + e[1].spacing()
th = h + 2*w
if self.move(tw, th, move, True, label=label):
return
self.moveTo(e[0].spacing())
for nr, flex in enumerate("XE"):
self.edges["F"](y-r)
if x-2*r > 0.1 * self.thickness:
self.edges[flex](cl, h=th)
self.edges["F"](x-2*r)
self.edges[flex](cl, h=th)
else:
self.edges[flex](2*cl+x-2*r, h=th)
self.edges["F"](y-r)
self.edgeCorner("F", e[nr])
e[nr](h)
self.edgeCorner(e[nr], "F")
self.move(tw, th, move, label=label)
def render(self):
x, y, h, r = self.x, self.y, self.h, self.radius
self.radius = r = min(r, x/2.0, y)
_ = self.translations.gettext
t1, t2, t3, t4 = self.topEdges(self.top_edge)
self.U(x, y, r, t1, move="right", label=_("left"))
self.U(x, y, r, t3, move="up", label=_("right"))
self.U(x, y, r, t3, move="left only")
self.Uwall(x, y, h, r, [t2, t4], move="up", label=_("wall"))
self.drawLid(x, h, self.top_edge)
self.lid(x, h, self.top_edge)
| 3,254 | Python | .py | 79 | 32.974684 | 73 | 0.570885 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,679 | bayonetbox.py | florianfesti_boxes/boxes/generators/bayonetbox.py | # Copyright (C) 2013-2019 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 *
class BayonetBox(Boxes):
"""Round box made from layers with twist on top"""
description = """Glue together - all outside rings to the bottom, all inside rings to the top."""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.argparser.add_argument(
"--diameter", action="store", type=float, default=50.,
help="Diameter of the box in mm")
self.argparser.add_argument(
"--lugs", action="store", type=int, default=10,
help="number of locking lugs")
self.argparser.add_argument(
"--alignment_pins", action="store", type=float, default=1.0,
help="diameter of the alignment pins")
self.buildArgParser("outside")
def alignmentHoles(self, inner=False, outer=False):
d = self.diameter
r = d / 2
t = self.thickness
p = 0.05*t
l = self.lugs
a = 180 / l
with self.saved_context():
for i in range(3):
if outer:
self.hole(r-t/2, 0, d=self.alignment_pins)
if inner:
self.hole(r-2*t-p, 0, d=self.alignment_pins)
self.moveTo(0, 0, 360/3)
def lowerLayer(self, asPart=False, move=None):
d = self.diameter
r = d / 2
t = self.thickness
p = 0.05*t
l = self.lugs
a = 180 / l
if asPart:
if self.move(d, d, move, True):
return
self.moveTo(d/2, d/2)
self.alignmentHoles(inner=True)
self.hole(0, 0, r=d/2 - 2.5*t)
self.moveTo(d/2 - 1.5*t, 0, -90)
for i in range(l):
self.polyline(0, (-4/3*a, r-1.5*t), 0, 90, 0.5*t, -90, 0, (-2/3*a, r-t), 0, -90, 0.5*t, 90)
if asPart:
self.move(d, d, move)
def lowerCB(self):
d = self.diameter
r = d / 2
t = self.thickness
p = 0.05*t
l = self.lugs
a = 180 / l
self.alignmentHoles(outer=True)
with self.saved_context():
self.lowerLayer()
self.moveTo(d/2 - 1.5*t+p, 0, -90)
for i in range(l):
self.polyline(0, (-2/3*a, r-1.5*t+p), 0, 90, 0.5*t, -90, 0, (-4/3*a, r-t+p), 0, -90, 0.5*t, 90)
def upperCB(self):
d = self.diameter
r = d / 2
t = self.thickness
p = 0.05*t
l = self.lugs
a = 180 / l
self.hole(0, 0, r=d/2 - 2.5*t)
self.hole(0, 0, r=d/2 - 1.5*t)
self.alignmentHoles(inner=True, outer=True)
self.moveTo(d/2 - 1.5*t, 0, -90)
for i in range(l):
self.polyline(0, (-1.3*a, r-1.5*t+p), 0, 90, 0.5*t, -90, 0, (-0.7*a, r-t+p), 0, -90, 0.5*t, 90)
def render(self):
d = self.diameter
t = self.thickness
p = 0.05*t
if not self.outside:
self.diameter = d = d - 3*t
self.parts.disc(d, callback=lambda: self.alignmentHoles(outer=True), move="right")
self.parts.disc(d, callback=lambda: (self.alignmentHoles(outer=True), self.hole(0, 0, d/2-1.5*t)), move="right")
self.parts.disc(d, callback=self.lowerCB, move="right")
self.parts.disc(d, callback=self.upperCB, move="right")
self.parts.disc(d, callback=lambda : self.alignmentHoles(inner=True),move="right")
| 4,076 | Python | .py | 100 | 31.96 | 120 | 0.566109 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,680 | burntest.py | florianfesti_boxes/boxes/generators/burntest.py | # Copyright (C) 2013-2019 Florian Festi
# Copyright (C) 2024 Seth Fischer
#
# 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 datetime import date
from boxes import *
class BurnTest(Boxes):
"""Test different burn values"""
description = """This generator will make shapes that you can use to select
optimal value for burn parameter for other generators. After burning try to
attach sides with the same value and use best fitting one on real projects.
In this generator set burn in the Default Settings to the lowest value
to be tested. To get an idea cut a rectangle with known nominal size and
measure the shrinkage due to the width of the laser cut. Now you can
measure the burn value that you should use in other generators. It is half
the difference of the overall size as shrinkage is occurring on both
sides. You can use the reference rectangle as it is rendered without burn
correction.
See also LBeam that can serve as compact BurnTest and FlexTest for testing flex settings.
"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(x=100)
self.argparser.add_argument(
"--step",
action="store",
type=float,
default=0.01,
help="increases in burn value between the sides",
)
self.argparser.add_argument(
"--pairs",
action="store",
type=int,
default=2,
help="number of pairs (each testing four burn values)",
)
self.argparser.add_argument(
"--date",
action="store",
type=boolarg,
default=False,
help="add current date etching to each piece",
)
self.argparser.add_argument(
"--id",
action="store",
type=str,
default="",
help="add identifier etching to each piece",
)
def render(self):
font = {
"fontsize": 12.5 * self.x / 100 if self.x < 81 else 10,
"align": "center",
"color": Color.ETCHING,
}
font_meta = font.copy()
font_meta["fontsize"] = font["fontsize"] * 0.75
today = date.today().strftime("%Y-%m-%d")
x, s = self.x, self.step
t = self.thickness
self.moveTo(t, t)
for cnt in range(self.pairs):
for i in range(4):
self.text("%.3fmm" % self.burn, x / 2, t, **font)
if self.date and i == 3:
self.text(today, x / 2, 20, **font_meta)
if self.id and i == 1:
self.text(self.id, x / 2, 20, **font_meta)
self.edges["f"](x)
self.corner(90)
self.burn += s
self.burn -= 4 * s
self.moveTo(x + 2 * t + self.spacing, -t)
for i in range(4):
self.text("%.3fmm" % self.burn, x / 2, t, **font)
if self.date and i == 3:
self.text(today, x / 2, 20, **font_meta)
if self.id and i == 1:
self.text(self.id, x / 2, 20, **font_meta)
self.edges["F"](x)
self.polyline(t, 90, t)
self.burn += s
self.moveTo(x + 2 * t + self.spacing, t)
| 4,013 | Python | .py | 98 | 31.734694 | 89 | 0.587994 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,681 | storagerack.py | florianfesti_boxes/boxes/generators/storagerack.py | # 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/>.
from boxes import *
class StorageRack(Boxes):
"""StorageRack to store boxes and trays which have their own floor"""
ui_group = "Shelf"
description = """
Drawers are not included:


"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.StackableSettings)
self.argparser.add_argument(
"--depth", action="store", type=float, default=200,
help="depth of the rack")
self.argparser.add_argument(
"--rail", action="store", type=float, default=30,
help="depth of the rack")
self.buildArgParser("x", "sh", "outside", "bottom_edge")
self.argparser.add_argument(
"--top_edge", action="store",
type=ArgparseEdgeType("FheSŠ"), choices=list("FheSŠ"),
default="F",
help="edge type for top edge")
def hHoles(self):
posh = -0.5 * self.thickness
for h in self.sh[:-1]:
posh += h + self.thickness
self.fingerHolesAt(posh, 0, self.depth)
def backHoles(self):
posh = -0.5 * self.thickness
for nr, h in enumerate(self.sh[:-1]):
posh += h + self.thickness
if ((self.bottom_edge == "e" and nr == 0) or
(self.top_edge == "e" and nr == len(self.sh) - 2)):
self.fingerHolesAt(0, posh, self.x, 0)
else:
self.fingerHolesAt(0, posh, self.rail, 0)
self.fingerHolesAt(self.x, posh, self.rail, 180)
def render(self):
if self.outside:
self.depth = self.adjustSize(self.depth, e2=False)
self.sh = self.adjustSize(self.sh, self.top_edge, self.bottom_edge)
self.x = self.adjustSize(self.x)
h = sum(self.sh) + self.thickness * (len(self.sh) - 1)
x = self.x
d = self.depth
t = self.thickness
# outer walls
b = self.bottom_edge
t = self.top_edge
self.closedtop = self.top_edge in "fFhŠ"
# sides
self.ctx.save()
# side walls
self.rectangularWall(d, h, [b, "F", t, "E"], callback=[None, self.hHoles, ], move="up")
self.rectangularWall(d, h, [b, "E", t, "F"], callback=[None, self.hHoles, ], move="up")
# full floors
self.rectangularWall(d, x, "fffE", move="up")
self.rectangularWall(d, x, "fffE", move="up")
num = len(self.sh)-1
if b == "e":
num -= 1
if t == "e":
num -= 1
for i in range(num):
self.rectangularWall(d, self.rail, "ffee", move="up")
self.rectangularWall(d, self.rail, "feef", move="up")
self.ctx.restore()
self.rectangularWall(d, h, "ffff", move="right only")
# back wall
self.rectangularWall(x, h, [b, "f", t, "f"], callback=[self.backHoles], move="up")
| 3,745 | Python | .py | 87 | 34.609195 | 95 | 0.597081 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,682 | pulley.py | florianfesti_boxes/boxes/generators/pulley.py | # Copyright (C) 2013-2016 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 boxes import pulley
class Pulley(Boxes):
"""Timing belt pulleys for different profiles"""
ui_group = "Part"
def __init__(self) -> None:
Boxes.__init__(self)
# remove cli params you do not need
self.buildArgParser(h=6.)
self.argparser.add_argument(
"--profile", action="store", type=str, default="GT2_2mm",
choices=pulley.Pulley.getProfiles(),
help="profile of the teeth/belt")
self.argparser.add_argument(
"--teeth", action="store", type=int, default=20,
help="number of teeth")
self.argparser.add_argument(
"--axle", action="store", type=float, default=5,
help="diameter of the axle")
self.argparser.add_argument(
"--insideout", action="store", type=BoolArg(), default=False,
help="create a ring gear with the belt being pushed against from within")
self.argparser.add_argument(
"--top", action="store", type=float, default=0,
help="overlap of top rim (zero for none)")
# Add non default cli params if needed (see argparse std lib)
# self.argparser.add_argument(
# "--XX", action="store", type=float, default=0.5,
# help="DESCRIPTION")
def disk(self, diameter, hole, callback=None, move=""):
w = diameter + 2 * self.spacing
if self.move(w, w, move, before=True):
return
self.moveTo(w / 2, w / 2)
self.cc(callback, None, 0.0, 0.0)
if hole:
self.hole(0, 0, hole / 2.0)
self.moveTo(diameter / 2 + self.burn, 0, 90)
self.corner(360, diameter / 2)
self.move(w, w, move)
def render(self):
# adjust to the variables you want in the local scope
t = self.thickness
if self.top:
self.disk(
self.pulley.diameter(self.teeth, self.profile) + 2 * self.top,
self.axle, move="right")
for i in range(int(math.ceil(self.h / self.thickness))):
self.pulley(self.teeth, self.profile, insideout=self.insideout, r_axle=self.axle / 2.0, move="right")
| 2,894 | Python | .py | 63 | 37.984127 | 113 | 0.626908 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,683 | traylayout.py | florianfesti_boxes/boxes/generators/traylayout.py | # Copyright (C) 2016 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 __future__ import annotations
import io
import boxes
from boxes import *
from boxes import lids
class TrayLayoutFile(Boxes):
"""Generate a layout file for a typetray."""
# This class generates the skeleton text file that can then be edited
# to describe the actual box
description = """This is a two step process. This is step 1.
The layout is based on a grid of sizes in x and y direction.
Choose how many distances you need in both directions.
The actual sizes and all other settings can be entered in the second step."""
webinterface = False
ui_group = "Tray"
sx: list[float] = [] # arg input
sy: list[float] = [] # arg input
hwalls: list[list[bool]] = []
vwalls: list[list[bool]] = []
floors: list[list[bool]] = []
def __init__(self, input=None, webargs=False) -> None:
Boxes.__init__(self)
self.argparser = argparse.ArgumentParser()
self.buildArgParser("sx", "sy")
self.argparser.add_argument(
"--output", action="store", type=str, default="traylayout.txt",
help="Name of the layout text file.")
def open(self) -> None:
# Use empty open and close methods to avoid initializing the whole drawing infrastructure.
pass
def close(self):
# Use empty open and close methods to avoid initializing the whole drawing infrastructure.
return io.BytesIO(bytes(str(self), 'utf-8'))
def fillDefault(self, sx: list[float], sy: list[float]) -> None:
self.sx = sx
self.sy = sy
x = len(sx)
y = len(sy)
self.hwalls = [[True for _ in range(x)] for _ in range(y + 1)]
self.vwalls = [[True for _ in range(x + 1)] for _ in range(y)]
self.floors = [[True for _ in range(x)] for _ in range(y)]
def __str__(self) -> str:
r = []
for i, x in enumerate(self.sx):
r.append(" |" * i + " ,> %.1fmm\n" % x)
for hwalls, vwalls, floors, y in zip(self.hwalls, self.vwalls, self.floors, self.sy):
r.append("".join("+" + " -"[h] for h in hwalls) + "+\n")
r.append("".join((" |"[v] + "X "[f] for v, f in zip(vwalls, floors))) + " |"[vwalls[-1]] + " %.1fmm\n" % y)
r.append("".join("+" + " -"[h] for h in self.hwalls[-1]) + "+\n")
return "".join(r)
def render(self) -> None:
self.fillDefault(self.sx, self.sy)
class TrayLayout(Boxes):
"""Generate a typetray from a layout file."""
# This class reads in the layout either from a file (with --input) or
# as string (with --layout) and turns it into a drawing for a box.
ui_group = "Tray"
description = """This is a two step process. This is step 2.
Edit the layout text graphics to adjust your tray.
Put in the sizes for each column and row. You can replace the hyphens and
vertical bars representing the walls with a space character to remove the walls.
You can replace the space characters representing the floor by a "X" to remove the floor for this compartment.
"""
def __init__(self) -> None:
super().__init__()
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(lids.LidSettings)
self.buildArgParser("h", "hi", "outside", "sx", "sy")
if self.UI == "web":
self.argparser.add_argument(
"--layout", action="store", type=str, default="\n")
else:
self.argparser.add_argument(
"--input", action="store", type=argparse.FileType('r'),
default="traylayout.txt",
help="layout file")
self.layout = None
def vWalls(self, x: int, y: int) -> int:
"""Number of vertical walls at a crossing."""
result = 0
if y > 0 and self.vwalls[y - 1][x]:
result += 1
if y < len(self.y) and self.vwalls[y][x]:
result += 1
return result
def hWalls(self, x: int, y: int) -> int:
"""Number of horizontal walls at a crossing."""
result = 0
if x > 0 and self.hwalls[y][x - 1]:
result += 1
if x < len(self.x) and self.hwalls[y][x]:
result += 1
return result
def vFloor(self, x: int, y: int) -> bool:
"""Is there floor under vertical wall."""
if y >= len(self.y):
return False
return (x > 0 and self.floors[y][x - 1]) or (x < len(self.x) and self.floors[y][x])
def hFloor(self, x: int, y: int) -> bool:
"""Is there floor under horizontal wall."""
if x >= len(self.x):
return False
return (y > 0 and self.floors[y - 1][x]) or (y < len(self.y) and self.floors[y][x])
@restore
def edgeAt(self, edge, x, y, length, angle=0):
self.moveTo(x, y, angle)
edge = self.edges.get(edge, edge)
edge(length)
def prepare(self):
if self.layout:
self.parse(self.layout.split('\n'))
else:
with open(self.input) as f:
self.parse(f.read())
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h, e2=False)
if self.hi:
self.hi = self.adjustSize(self.hi, e2=False)
self.hi = self.hi or self.h
self.edges["s"] = boxes.edges.Slot(self, self.hi / 2.0)
self.edges["C"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi)
self.edges["D"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi, outset=self.thickness)
def walls(self, move=None):
lx = len(self.x)
ly = len(self.y)
# t = self.thickness
# b = self.burn
# t2 = self.thickness / 2.0
self.ctx.save()
# Horizontal Walls
for y in range(ly + 1):
if y == 0 or y == ly:
h = self.h
else:
h = self.hi
start = 0
end = 0
while end < lx:
lengths = []
edges = []
while start < lx and not self.hwalls[y][start]:
start += 1
if start == lx:
break
end = start
while end < lx and self.hwalls[y][end]:
if self.hFloor(end, y):
edges.append("f")
else:
edges.append("E")
lengths.append(self.x[end])
if self.hFloor(end, y) == 0 and self.hFloor(end + 1, y) == 0:
edges.append("EDs"[self.vWalls(end + 1, y)])
else:
edges.append("eCs"[self.vWalls(end + 1, y)])
lengths.append(self.thickness)
end += 1
# remove last "slot"
lengths.pop()
edges.pop()
self.rectangularWall(sum(lengths), h, [
boxes.edges.CompoundEdge(self, edges, lengths),
"f" if self.vWalls(end, y) else "e",
"e",
"f" if self.vWalls(start, y) else "e"],
move="right")
start = end
self.ctx.restore()
self.rectangularWall(10, h, "ffef", move="up only")
self.ctx.save()
# Vertical Walls
for x in range(lx + 1):
if x == 0 or x == lx:
h = self.h
else:
h = self.hi
start = 0
end = 0
while end < ly:
lengths = []
edges = []
while start < ly and not self.vwalls[start][x]:
start += 1
if start == ly:
break
end = start
while end < ly and self.vwalls[end][x]:
if self.vFloor(x, end):
edges.append("f")
else:
edges.append("E")
lengths.append(self.y[end])
if self.vFloor(x, end) == 0 and self.vFloor(x, end + 1) == 0:
edges.append("EDs"[self.hWalls(x, end + 1)])
else:
edges.append("eCs"[self.hWalls(x, end + 1)])
lengths.append(self.thickness)
end += 1
# remove last "slot"
lengths.pop()
edges.pop()
upper = [{"f": "e",
"s": "s",
"e": "e",
"E": "e",
"C": "e",
"D": "e"}[e] for e in reversed(edges)]
edges = ["e" if e == "s" else e for e in edges]
self.rectangularWall(sum(lengths), h, [
boxes.edges.CompoundEdge(self, edges, lengths),
"eFf"[self.hWalls(x, end)],
boxes.edges.CompoundEdge(self, upper, list(reversed(lengths))),
"eFf"[self.hWalls(x, start)]],
move="right")
start = end
self.ctx.restore()
self.rectangularWall(10, h, "ffef", move="up only")
def base_plate(self, callback=None, move=None):
lx = len(self.x)
ly = len(self.y)
t = self.thickness
w = self.edges["F"].startwidth()
b = self.burn
t2 = self.thickness / 2.0
tw = sum(self.x) + (lx - 1) * t + 2 * w
th = sum(self.y) + (ly - 1) * t + 2 * w
if self.move(tw, th, move, True):
return
for i, (x, y, a) in enumerate((
(w, w + b, 0),
(tw - w, w + b, 90),
(tw - w, th - w + b, 180),
(w, th - w + b, 270))):
self.cc(callback, i, x, y, a)
# Horizontal lines
posy = w - t
for y in range(ly, -1, -1):
posx = w
for x in range(lx):
if self.hwalls[y][x]:
e = "F"
else:
e = "e"
if y < ly and self.floors[y][x]:
if y > 0 and self.floors[y - 1][x]:
# Inside Wall
if self.hwalls[y][x]:
self.fingerHolesAt(posx, posy + t2, self.x[x], angle=0)
else:
# Top edge
self.edgeAt(e, posx + self.x[x],
posy + w + b, self.x[x],
-180)
if x == 0 or not self.floors[y][x - 1]:
self.edgeAt("e", posx - w, posy + w + b, w, 0)
elif y == 0 or not self.floors[y - 1][x - 1]:
self.edgeAt("e", posx - t, posy + w + b, t, 0)
if x == lx - 1 or not self.floors[y][x + 1]:
self.edgeAt("e", posx + self.x[x], posy + w + b, w, 0)
elif y > 0 and self.floors[y - 1][x]:
# Bottom Edge
self.edgeAt(e, posx, posy - b + t - w, self.x[x])
if x == 0 or not self.floors[y-1][x - 1]:
self.edgeAt("e", posx - w, posy + t - w - b, w)
elif x == 0 or y == ly or not self.floors[y][x - 1]:
self.edgeAt("e", posx - t, posy + t - w - b, t)
if x == lx - 1 or y == 0 or not self.floors[y-1][x + 1]:
self.edgeAt("e", posx + self.x[x], posy + t -w - b, w)
posx += self.x[x] + self.thickness
posy += self.y[y - 1] + self.thickness
posx = w - t
for x in range(lx + 1):
posy = w
for y in range(ly - 1, -1, -1):
if self.vwalls[y][x]:
e = "F"
else:
e = "e"
if x > 0 and self.floors[y][x - 1]:
if x < lx and self.floors[y][x]:
# Inside wall
if self.vwalls[y][x]:
self.fingerHolesAt(posx + t2, posy, self.y[y])
else:
# Right edge
self.edgeAt(e, posx + w + b, posy, self.y[y], 90)
if y == 0 or not self.floors[y-1][x-1]:
self.edgeAt("e", posx + w + b, posy + self.y[y], w, 90)
elif x == lx or y == 0 or not self.floors[y - 1][x]:
self.edgeAt("e", posx + w + b, posy + self.y[y], t, 90)
if y == ly - 1 or not self.floors[y+1][x-1]:
self.edgeAt("e", posx + w + b, posy - w, w, 90)
elif x < lx and self.floors[y][x]:
# Left edge
self.edgeAt(e, posx + t - w - b, posy + self.y[y], self.y[y], -90)
if y == 0 or not self.floors[y - 1][x]:
self.edgeAt("e", posx + t - w - b,
posy + self.y[y] + w, w, -90)
elif x == 0 or y == 0 or not self.floors[y - 1][x - 1]:
self.edgeAt("e", posx + t - w - b,
posy + self.y[y] + t, t, -90)
if y == ly - 1 or not self.floors[y + 1][x]:
self.edgeAt("e", posx + t - w - b, posy, w, -90)
posy += self.y[y] + self.thickness
if x < lx:
posx += self.x[x] + self.thickness
self.move(tw, th, move)
def parse(self, input):
x = []
y = []
hwalls = []
vwalls = []
floors = []
for nr, line in enumerate(input):
if not line or line[0] == "#":
continue
m = re.match(r"( \|)* ,>\s*(\d*\.?\d+)\s*mm\s*", line)
if m:
x.append(float(m.group(2)))
continue
if line[0] == '+':
w = []
for n, c in enumerate(line[:len(x) * 2 + 1]):
if n % 2:
if c == ' ':
w.append(False)
elif c == '-':
w.append(True)
else:
pass
# raise ValueError(line)
else:
if c != '+':
pass
# raise ValueError(line)
hwalls.append(w)
if line[0] in " |":
w = []
f = []
for n, c in enumerate(line[:len(x) * 2 + 1]):
if n % 2:
if c in 'xX':
f.append(False)
elif c == ' ':
f.append(True)
else:
raise ValueError("""Can't parse line %i in layout: expected " ", "x" or "X" for char #%i""" % (nr + 1, n + 1))
else:
if c == ' ':
w.append(False)
elif c == '|':
w.append(True)
else:
raise ValueError("""Can't parse line %i in layout: expected " ", or "|" for char #%i""" % (nr + 1, n + 1))
floors.append(f)
vwalls.append(w)
m = re.match(r"([ |][ xX])+[ |]\s*(\d*\.?\d+)\s*mm\s*", line)
if not m:
raise ValueError("""Can't parse line %i in layout: Can read height of the row""" % (nr + 1))
else:
y.append(float(m.group(2)))
# check sizes
lx = len(x)
ly = len(y)
if lx == 0:
raise ValueError("Need more than one wall in x direction")
if ly == 0:
raise ValueError("Need more than one wall in y direction")
if len(hwalls) != ly + 1:
raise ValueError("Wrong number of horizontal wall lines: %i (%i expected)" % (len(hwalls), ly + 1))
for nr, walls in enumerate(hwalls):
if len(walls) != lx:
raise ValueError("Wrong number of horizontal walls in line %i: %i (%i expected)" % (nr, len(walls), lx))
if len(vwalls) != ly:
raise ValueError("Wrong number of vertical wall lines: %i (%i expected)" % (len(vwalls), ly))
for nr, walls in enumerate(vwalls):
if len(walls) != lx + 1:
raise ValueError("Wrong number of vertical walls in line %i: %i (%i expected)" % (nr, len(walls), lx + 1))
self.x = x
self.y = y
self.hwalls = hwalls
self.vwalls = vwalls
self.floors = floors
def render(self) -> None:
self.prepare()
self.walls()
self.base_plate(move="up")
self.lid(sum(self.x) + (len(self.x)-1) * self.thickness,
sum(self.y) + (len(self.y)-1) * self.thickness)
| 17,956 | Python | .py | 405 | 29.676543 | 138 | 0.454873 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,684 | typetray.py | florianfesti_boxes/boxes/generators/typetray.py | # 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/>.
from boxes import *
from boxes import Color, edges
from boxes.lids import LidSettings, _TopEdge
class FingerHoleEdgeSettings(edges.Settings):
"""Settings for FingerHoleEdge
Values:
* absolute_params
* radius : 10.0 : maximal radius (in mm)
* absolute_depth : 0.0 : depth of the hole in mm (in addition to the relative)
* absolute_width : 0.0 : width of the hole in mm (in addition to the relative)
* relative_depth : 0.0 : depth of the hole as fraction of the wall
* relative_width : 0.3 : width of the hole as fraction of the wall width
"""
absolute_params = {
"radius": 10.,
"absolute_depth": 0.0,
"relative_depth" : 0.9,
"absolute_width" : 0.0,
"relative_width" : 0.3,
}
wallheight = 0.0
class FingerHoleEdge(edges.BaseEdge):
"""An edge with room to get your fingers around cards"""
char = "A"
def __call__(self, length, **kw):
width = min(self.settings.absolute_width + length * self.settings.relative_width, length)
depth = min(self.settings.absolute_depth + self.settings.wallheight * self.settings.relative_depth, self.settings.wallheight)
r = min(width/2, depth, self.settings.radius)
if depth < 1e-9 or width < 1e-9:
self.boxes.edge(length, tabs=2)
return
poly = (((length - width) / 2, 1), 90, depth-r, (-90, r))
self.polyline(*poly, (width - 2*r, 1), *reversed(poly))
class TypeTray(_TopEdge):
"""Type tray - allows only continuous walls"""
ui_group = "Tray"
def __init__(self) -> None:
Boxes.__init__(self)
self.addTopEdgeSettings(fingerjoint={"surroundingspaces": 0.5},
roundedtriangle={"outset" : 1})
self.addSettingsArgs(LidSettings)
self.buildArgParser("sx", "sy", "h", "hi", "outside", "bottom_edge",
"top_edge")
self.argparser.add_argument(
"--back_height", action="store", type=float, default=0.0,
help="additional height of the back wall - e top edge only")
self.argparser.add_argument(
"--radius", action="store", type=float, default=0.0,
help="radius for strengthening side walls with back_height")
self.argparser.add_argument(
"--gripheight", action="store", type=float, default=30,
dest="gh", help="height of the grip hole in mm")
self.argparser.add_argument(
"--gripwidth", action="store", type=float, default=70,
dest="gw", help="width of th grip hole in mm (zero for no hole)")
self.argparser.add_argument(
"--handle", type=boolarg, default=False, help="add handle to the bottom (changes bottom edge in the front)")
self.argparser.add_argument(
"--fingerholes", action="store", type=str, default="none",
choices=["none", "inside-only", "front", "back", "front-and-back"],
help="Decide which outer walls should have finger hole, too")
label_group = self.argparser.add_argument_group("Compartment Labels")
label_group.add_argument(
"--text_size", action="store", type=int, default=12,
help="Textsize in mm for the traycontent")
label_group.add_argument(
"--text_alignment", action="store", type=str, default="left",
choices=['left', 'center', 'right'],
help="Text Alignment")
label_group.add_argument(
"--text_distance_x", action="store", type=float, default=2.0,
help="Distance in X from edge of tray in mm. Has no effect when text is centered.")
label_group.add_argument(
"--text_distance_y", action="store", type=float, default=2.0,
help="Distance in Y from edge of tray in mm.")
label_group.add_argument(
"--text_at_front", action="store", type=boolarg, default=False,
help="Start compartement labels on the front")
if self.UI == "web":
label_group.add_argument(
"--label_text", action="store", type=str, default="\n",
help="Every line is the text for one compartment. Beginning with front left")
else:
label_group.add_argument(
"--label_file", action="store", type=argparse.FileType('r'),
help="file with compartment labels. One line per compartment")
self.addSettingsArgs(FingerHoleEdgeSettings)
@property
def fingerholedepth(self):
if self.fingerhole == 'custom':
return self.fingerhole_depth
elif self.fingerhole == 'regular':
a = self.h/4
if a < 35:
return a
else:
return 35
elif self.fingerhole == 'deep':
return self.h-self.thickness-10
elif self.fingerhole == 'none':
return 0
def xSlots(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
posy = 0
for y in self.sy:
self.fingerHolesAt(posx, posy, y)
posy += y + self.thickness
def ySlots(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
posx = 0
for x in reversed(self.sx):
self.fingerHolesAt(posy, posx, x)
posx += x + self.thickness
def xHoles(self):
posx = -0.5 * self.thickness
for x in self.sx[:-1]:
posx += x + self.thickness
self.fingerHolesAt(posx, 0, self.hi)
def yHoles(self):
posy = -0.5 * self.thickness
for y in self.sy[:-1]:
posy += y + self.thickness
self.fingerHolesAt(posy, 0, self.hi)
def gripHole(self):
if not self.gw:
return
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
r = min(self.gw, self.gh) / 2.0
self.rectangularHole(x / 2.0, self.gh * 1.5, self.gw, self.gh, r)
def textCB(self):
## declare text-variables
textsize = self.text_size
texty = self.hi - textsize - self.text_distance_y
if self.text_alignment == 'center':
texty -= self.fingerholedepth
textdistance = self.sx[0] + self.thickness
## Generate text-fields for each tray
for n in range(len(self.sx)):
# Break for-loop if further list is empty
if self.textnumber >= len(self.textcontent):
break
textx = n * (self.sx[0] + self.thickness)
# Calculate textposition
if self.text_alignment == 'left':
textx += self.text_distance_x
elif self.text_alignment == 'center':
textx += self.sx[0] / 2
elif self.text_alignment == 'right':
textx += self.sx[0] - self.text_distance_x
# Generate text
self.text(
"%s" % self.textcontent[self.textnumber],
textx,
texty,
0,
align=self.text_alignment,
fontsize=textsize,
color=Color.ETCHING)
self.textnumber +=1
def render(self):
if self.outside:
self.sx = self.adjustSize(self.sx)
self.sy = self.adjustSize(self.sy)
self.h = self.adjustSize(self.h, e2=False)
if self.hi:
self.hi = self.adjustSize(self.hi, e2=False)
x = sum(self.sx) + self.thickness * (len(self.sx) - 1)
y = sum(self.sy) + self.thickness * (len(self.sy) - 1)
h = self.h
sameh = not self.hi
hi = self.hi = self.hi or h
t = self.thickness
s = FingerHoleEdgeSettings(self.thickness, True,
**self.edgesettings.get("FingerHoleEdge", {}))
s.wallheight = 0 if self.fingerholes == "none" else self.hi
p = FingerHoleEdge(self, s)
self.addPart(p)
# outer walls
b = self.bottom_edge
tl, tb, tr, tf = self.topEdges(self.top_edge)
self.closedtop = self.top_edge in "fFhŠ"
bh = self.back_height if self.top_edge == "e" else 0.0
self.textcontent = []
if hasattr(self, "label_text"):
self.textcontent = self.label_text.split("\r\n")
else:
if self.label_file:
with open(self.label_file) as f:
self.textcontent = f.readlines()
self.textnumber = 0
# x sides
self.ctx.save()
# floor
if b != "e":
if self.handle:
self.rectangularWall(x, y, "ffYf", callback=[self.xSlots, self.ySlots], move="up", label="bottom")
else:
self.rectangularWall(x, y, "ffff", callback=[self.xSlots, self.ySlots], move="up", label="bottom")
# front
if self.text_at_front:
frontCBs = [lambda:(self.textCB(), self.mirrorX(self.xHoles, x)()),
None, self.gripHole]
else:
frontCBs = [self.mirrorX(self.xHoles, x), None, self.gripHole]
# finger holes at front wall
if not self.closedtop and \
self.fingerholes in ("front", "front-and-back"):
tf = edges.SlottedEdge(self, self.sx[::-1], "A")
if bh:
self.rectangularWall(
x, h, ["f" if self.handle else b, "f", tf, "f"],
callback=frontCBs, move="up", label="front")
else:
self.rectangularWall(
x, h, ["f" if self.handle else b, "F", tf, "F"],
callback=frontCBs, ignore_widths=[] if self.handle else [1, 6],
move="up", label="front")
# Inner walls
be = "f" if b != "e" else "e"
######
for i in range(len(self.sy) - 1):
e = [edges.SlottedEdge(self, self.sx, be), "f",
edges.SlottedEdge(self, self.sx[::-1], "A", slots=0.5 * hi), "f"]
if self.closedtop and sameh:
e = [edges.SlottedEdge(self, self.sx, be), "f",
edges.SlottedEdge(self, self.sx[::-1], "f", slots=0.5 * hi), "f"]
self.rectangularWall(x, hi, e, move="up", callback=[self.textCB],
label=f"inner x {i+1}")
# back
# finger holes at back wall
if not self.closedtop and \
self.fingerholes in ("back", "front-and-back"):
tb = edges.SlottedEdge(self, self.sx, "A")
if bh:
self.rectangularWall(x, h+bh, [b, "f", tb, "f"],
callback=[self.xHoles],
ignore_widths=[],
move="up", label="back")
else:
self.rectangularWall(x, h, [b, "F", tb, "F"],
callback=[self.xHoles],
ignore_widths=[1, 6],
move="up", label="back")
# top / lid
if self.closedtop and sameh:
e = "FFFF" if self.top_edge == "f" else "ffff"
self.rectangularWall(x, y, e, callback=[
self.xSlots, self.ySlots], move="up", label="top")
else:
self.drawLid(x, y, self.top_edge)
self.lid(x, y, self.top_edge)
self.ctx.restore()
self.rectangularWall(x, hi, "ffff", move="right only")
# y walls
# outer walls - left/right
if bh:
self.trapezoidSideWall(
y, h, h+bh, [b, "h", "e", "h"],
radius=self.radius, callback=[self.yHoles, ],
move="up", label="left side")
self.trapezoidSideWall(
y, h+bh, h, [b, "h", "e", "h"], radius=self.radius,
callback=[self.mirrorX(self.yHoles, y), ],
move="up", label="right side")
else:
self.rectangularWall(
y, h, [b, "f", tl, "f"], callback=[self.yHoles, ],
ignore_widths=[6] if self.handle else [1, 6],
move="up", label="left side")
self.rectangularWall(
y, h, [b, "f", tr, "f"],
callback=[self.mirrorX(self.yHoles, y), ],
ignore_widths=[1] if self.handle else [1, 6],
move="up", label="right side")
# inner walls
for i in range(len(self.sx) - 1):
e = [edges.SlottedEdge(self, self.sy, be, slots=0.5 * hi),
"f", "e", "f"]
if self.closedtop and sameh:
e = [edges.SlottedEdge(self, self.sy, be, slots=0.5 * hi),"f",
edges.SlottedEdge(self, self.sy[::-1], "f"), "f"]
self.rectangularWall(y, hi, e, move="up", label=f"inner y {i+1}")
| 13,585 | Python | .py | 300 | 33.713333 | 133 | 0.548307 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,685 | flexbox.py | florianfesti_boxes/boxes/generators/flexbox.py | # 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/>.
import math
import boxes
class FlexBox(boxes.Boxes):
"""Box with living hinge and round corners"""
ui_group = "FlexBox"
def __init__(self) -> None:
boxes.Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(boxes.edges.FlexSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--radius", action="store", type=float, default=15,
help="Radius of the latch in mm")
self.argparser.add_argument(
"--latchsize", action="store", type=float, default=8,
help="size of latch in multiples of thickness")
def flexBoxSide(self, x, y, r, callback=None, move=None):
t = self.thickness
if self.move(x+2*t, y+t, move, True):
return
self.moveTo(t+r, t)
for i, l in zip(range(2), (x, y)):
self.cc(callback, i)
self.edges["f"](l - 2 * r)
self.corner(90, r)
self.cc(callback, 2)
self.edge(x - 2 * r)
self.corner(90, r)
self.cc(callback, 3)
self.latch(self.latchsize)
self.cc(callback, 4)
self.edges["f"](y - 2 * r - self.latchsize)
self.corner(90, r)
self.move(x+2*t, y+t, move)
def surroundingWall(self, move=None):
x, y, h, r = self.x, self.y, self.h, self.radius
t = self.thickness
c4 = math.pi * r * 0.5
tw = 2*x + 2*y - 8*r + 4*c4
th = h + 2.5*t
if self.move(tw, th, move, True):
return
self.moveTo(0, 0.25*t)
self.edges["F"](y - 2 * r - self.latchsize, False)
if x - 2 * r < t:
self.edges["X"](2 * c4 + x - 2 * r, h + 2 * t)
else:
self.edges["X"](c4, h + 2 * t)
self.edges["F"](x - 2 * r, False)
self.edges["X"](c4, h + 2 * t)
self.edges["F"](y - 2 * r, False)
if x - 2 * r < t:
self.edges["X"](2 * c4 + x - 2 * r, h + 2 * t)
else:
self.edges["X"](c4, h + 2 * t)
self.edge(x - 2 * r)
self.edges["X"](c4, h + 2 * t)
self.latch(self.latchsize, False)
self.edge(h + 2 * t)
self.latch(self.latchsize, False, True)
self.edge(c4)
self.edge(x - 2 * r)
self.edge(c4)
self.edges["F"](y - 2 * r, False)
self.edge(c4)
self.edges["F"](x - 2 * r, False)
self.edge(c4)
self.edges["F"](y - 2 * r - self.latchsize, False)
self.corner(90)
self.edge(h + 2 * t)
self.corner(90)
self.move(tw, th, move)
def render(self):
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h)
x, y, h = self.x, self.y, self.h
self.latchsize *= self.thickness
r = self.radius or min(x, y - self.latchsize) / 2.0
r = min(r, x / 2.0)
self.radius = r = min(r, max(0, (y - self.latchsize) / 2.0))
self.surroundingWall(move="up")
self.flexBoxSide(self.x, self.y, self.radius, move="right")
self.flexBoxSide(self.x, self.y, self.radius, move="mirror")
| 3,960 | Python | .py | 99 | 31.575758 | 73 | 0.560188 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,686 | desksign.py | florianfesti_boxes/boxes/generators/desksign.py | # 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/>.
from boxes import *
class Desksign(Boxes):
"""Simple diagonal plate with stands to show name or message."""
description = """Text to be engraved can be generated by inputting the label and fontsize fields.
height represents the area that can be used for writing text, does not match the actual
height when standing. Generated text is put in the center. Currently only a single
line of text is supported."""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.StackableSettings, width=2.0) # used for feet
self.argparser.add_argument(
"--width", action="store", type=float, default=150,
help="plate width in mm (excluding holes)")
self.argparser.add_argument(
"--height", action="store", type=float, default=80,
help="plate height in mm")
self.argparser.add_argument(
"--angle", action="store", type=float, default=60,
help="plate angle in degrees (90 is vertical)")
self.argparser.add_argument(
"--label", action="store", type=str, default="",
help="optional text to engrave (leave blank to omit)")
self.argparser.add_argument(
"--fontsize", action="store", type=float, default=20,
help="height of text")
self.argparser.add_argument(
"--feet", action="store", type=boolarg, default=False,
help="add raised feet")
self.argparser.add_argument(
"--mirror", action="store", type=boolarg, default=True,
help="mirrors one of the stand so the same side of the material can be placed on the outside")
def render(self):
width = self.width
height = self.height
angle = self.angle
feet = self.feet
mirror = self.mirror
t = self.thickness
if not (0 < angle and angle < 90):
raise ValueError("angle has to between 0 and 90 degrees")
base = math.cos(math.radians(angle)) * height
h = math.sin(math.radians(angle)) * height
label = self.label
fontsize = self.fontsize
if label and fontsize:
self.rectangularWall(width, height, "eheh", move="right", callback=[
lambda: self.text("%s" % label, width/2, (height-fontsize)/2,
fontsize = fontsize, align="center", color=Color.ETCHING)]) # add text
else:
self.rectangularWall(width, height, "eheh", move="right") # front
# stands at back/side
edge = "šef" if feet else "eef"
if mirror:
self.rectangularTriangle(base, h, edge, num=1, move="right")
self.rectangularTriangle(base, h, edge, num=1, move="mirror right")
else:
self.rectangularTriangle(base, h, edge, num=2, move="right")
| 3,681 | Python | .py | 73 | 41.493151 | 106 | 0.636161 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,687 | wallchiselholder.py | florianfesti_boxes/boxes/generators/wallchiselholder.py | # Copyright (C) 2013-2019 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 boxes.walledges import _WallMountedBox
class FrontEdge(edges.Edge):
def __call__(self, length, **kw):
td = self.tooldiameter
rh = self.holediameter / 2.0
r = self.radius
sw = self.slot_width
a = math.degrees(math.asin((r+sw/2)/(r+rh)))
l = (td - sw - 2*r) / 2
for i in range(self.number):
self.polyline(l, (180-a, r), 0, (-360+2*a, rh), 0, (180-a, r), l)
class WallChiselHolder(_WallMountedBox):
"""Wall tool holder for chisels, files and similar tools"""
def __init__(self) -> None:
super().__init__()
self.buildArgParser(h=120)
self.argparser.add_argument(
"--tooldiameter", action="store", type=float, default=30.,
help="diameter of the tool including space to grab")
self.argparser.add_argument(
"--holediameter", action="store", type=float, default=30.,
help="diameter of the hole for the tool (handle should not fit through)")
self.argparser.add_argument(
"--slot_width", action="store", type=float, default=5.,
help="width of slots")
#self.argparser.add_argument(
# "--angle", action="store", type=float, default=0.,
# help="angle of the top - positive for leaning backwards")
self.argparser.add_argument(
"--radius", action="store", type=float, default=5.,
help="radius at the slots")
self.argparser.add_argument(
"--number", action="store", type=int, default=6,
help="number of tools/slots")
self.argparser.add_argument(
"--hooks", action="store", type=str, default="all",
choices=("all", "odds", "everythird"),
help="amount of hooks / braces")
def brace(self, i):
n = self.number
if i in (0, n):
return True
# fold for symmetry
#if i > n//2:
# i = n - i
if self.hooks == "all":
return True
elif self.hooks == "odds":
return not (i % 2)
elif self.hooks == "everythird":
return not (i % 3)
def braces(self):
return sum(self.brace(i) for i in range(self.number+1))
def backCB(self):
n = self.number
rt = self.holediameter
wt = self.tooldiameter
t = self.thickness
d = min(2*t, (wt-rt)/4.)
self.wallHolesAt(d, 0, self.h, 90)
self.wallHolesAt(n*wt-d, 0, self.h, 90)
for i in range(1, n):
if self.brace(i):
self.wallHolesAt(i*wt, 0, self.h, 90)
def topCB(self):
n = self.number
rt = self.holediameter
wt = self.tooldiameter
t = self.thickness
l = self.depth
d = min(2*t, (wt-rt)/4.)
self.fingerHolesAt(d, 0, l, 90)
self.fingerHolesAt(n*wt-d, 0, l, 90)
for i in range(1, n):
if self.brace(i):
self.fingerHolesAt(i*wt, 0, l, 90)
def render(self):
self.generateWallEdges()
t = self.thickness
wt = self.tooldiameter
n = self.number
self.depth = depth = wt + 4*t
self.rectangularWall(n*wt, self.h, "eeee", callback=[self.backCB], move="up")
self.rectangularWall(n*wt, depth, [FrontEdge(self, None), "e","e","e"], callback=[self.topCB], move="up")
self.moveTo(0, t)
self.rectangularTriangle(depth, self.h, "fbe", r=3*t, num=self.braces())
| 4,226 | Python | .py | 101 | 33.39604 | 113 | 0.589856 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,688 | shoe.py | florianfesti_boxes/boxes/generators/shoe.py | # Copyright (C) 2013-2016 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 *
class Shoe(Boxes):
"""Shoe shaped box"""
description = """Shoe shaped box with flat sides and rounded top.
Works best if flex if under slight compression.
Make sure that the following conditions are met:
y > tophole + r + fronttop;
height > frontheight."""
ui_group = "Misc"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.FlexSettings)
self.argparser.add_argument(
"--width", action="store", type=float, default=65,
help="width of the shoe")
self.argparser.add_argument(
"--length", action="store", type=float, default=175,
help="length front to back")
self.argparser.add_argument(
"--height", action="store", type=float, default=100,
help="height at the back of the shoe")
self.argparser.add_argument(
"--frontheight", action="store", type=float, default=35,
help="height at the front of the shoe")
self.argparser.add_argument(
"--fronttop", action="store", type=float, default=20,
help="length of the flat part at the front of the shoe")
self.argparser.add_argument(
"--tophole", action="store", type=float, default=75,
help="length of the opening at the top")
self.argparser.add_argument(
"--radius", action="store", type=float, default=30,
help="radius of the bend")
def render(self):
x, y, h = self.width, self.length, self.height
t = self.thickness
hf = self.frontheight
yg = self.tophole
tf = self.fronttop
r=self.radius
if (hf > h):
# Give an error because the result will be wrong with possible unconnected paths
raise ValueError("Height at front of shoe must be less than height at back of shoe.")
stretch = (self.edges["X"].settings.stretch)
self.ctx.save()
self.rectangularWall(y, x, "FFFF", move="up", label="Bottom")
lf,a=self.shoeside(y,h,hf,yg,tf,r, move="up", label="Side")
self.shoeside(y,h,hf,yg,tf,r, move="mirror up", label="Side")
self.ctx.restore()
self.rectangularWall(y, x, "FFFF", move="right only")
self.rectangularWall(x, h, "ffef", move="up", label="Back")
self.rectangularWall(x, hf, "ffff", move="up", label="front")
dr = a*(r-t)/stretch
self.shoelip(x, tf, dr, lf, label="top")
def shoelip(self, x, tf, dr, lf, move=None, label=""):
w = self.edges["F"].spacing()
th = tf + dr + lf + self.edges["F"].spacing() + self.edges["e"].spacing()
tw = x + 2*w
if self.move(tw, th, move, True, label=label):
return
self.moveTo(self.edges["F"].spacing(), self.edges["e"].spacing())
self.edges["F"](x)
self.edgeCorner("F", "F")
self.edges["F"](tf)
self.edges["X"](dr, h=x+2*w)
self.edges["F"](lf)
self.edgeCorner("F", "e")
self.edges["e"](x)
self.edgeCorner("e", "F")
self.edges["F"](lf)
self.edges["E"](dr)
self.edges["F"](tf)
self.edgeCorner("F", "F")
self.move(tw, th, move, label=label)
def shoeside(self, y, h, hf, yg, tf, r, move=None, label=""):
import math
tx = y + 2 * self.edges.get('F').spacing()
ty = h + self.edges.get('f').spacing() + self.edges.get("e").spacing()
if self.move(tx, ty, move, before=True):
return
lf = math.sqrt((h-hf)**2+(y-yg-tf)**2)
af = 90-math.degrees(math.atan((h-hf)/(y-yg-tf)))
atemp = math.degrees(math.atan((h-hf-r)/(y-yg-tf)))
dtemp = math.sqrt((h-hf-r)**2+(y-yg-tf)**2)
lf = math.sqrt(dtemp**2-r**2)
af = 90-atemp-math.degrees(math.atan(r/lf))
self.moveTo(self.edges.get('f').margin(), self.edges.get("f").margin())
self.edges.get('f')(y)
self.edgeCorner(self.edges["f"],self.edges["F"],90)
self.edges.get('F')(hf)
self.edgeCorner(self.edges["F"],self.edges["f"],90)
self.edges.get('f')(tf)
self.corner(af-90,r)
self.edges.get('f')(lf)
self.edgeCorner(self.edges["f"],self.edges["e"],90-af)
self.edges.get('e')(yg)
self.edgeCorner(self.edges["e"],self.edges["F"],90)
self.edges.get('F')(h)
self.edgeCorner(self.edges["F"],self.edges["f"],90)
self.move(tx, ty, move, label=label)
return lf,math.radians(90-af)
| 5,328 | Python | .py | 116 | 37.534483 | 97 | 0.596874 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,689 | rectangularWall.py | florianfesti_boxes/boxes/generators/rectangularWall.py | # Copyright (C) 2013-2016 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 *
class RectangularWall(Boxes):
"""Simple wall with options for different edges"""
ui_group = "Part" # see ./__init__.py for names
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.CabinetHingeSettings)
self.addSettingsArgs(edges.ClickSettings)
self.addSettingsArgs(edges.DoveTailSettings)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.GearSettings)
self.addSettingsArgs(edges.GripSettings)
self.addSettingsArgs(edges.HingeSettings)
self.addSettingsArgs(edges.ChestHingeSettings)
self.addSettingsArgs(edges.SlideOnLidSettings)
self.addSettingsArgs(edges.StackableSettings)
self.buildArgParser(x=100, h=100)
self.argparser.add_argument(
"--bottom_edge", action="store",
type=ArgparseEdgeType("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"), choices=list("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"),
default="e", help="edge type for bottom edge")
self.argparser.add_argument(
"--right_edge", action="store",
type=ArgparseEdgeType("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"), choices=list("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"),
default="e", help="edge type for right edge")
self.argparser.add_argument(
"--top_edge", action="store",
type=ArgparseEdgeType("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"), choices=list("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"),
default="e", help="edge type for top edge")
self.argparser.add_argument(
"--left_edge", action="store",
type=ArgparseEdgeType("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"), choices=list("cCdDeEfFghiIjJkKlLmMnNoOpPqQRsSšŠuUvV"),
default="e", help="edge type for left edge")
def cb(self, nr):
t = self.thickness
if self.edgetypes[nr] == "f":
self.fingerHolesAt(0, -2.5*t, self.h if nr % 2 else self.x, 0)
def render(self):
# adjust to the variables you want in the local scope
t = self.thickness
self.edgetypes = [self.bottom_edge, self.right_edge, self.top_edge, self.left_edge]
self.moveTo(3*t, 3*t)
self.rectangularWall(self.x, self.h, self.edgetypes, callback=self.cb)
| 3,063 | Python | .py | 57 | 45.912281 | 130 | 0.69869 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,690 | sevensegmentclock.py | florianfesti_boxes/boxes/generators/sevensegmentclock.py | # 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/>.
from boxes import *
from .sevensegment import SevenSegmentPattern
class SevenSegmentClock(SevenSegmentPattern):
"""Seven segment clock build with LED stripe"""
description = """You need a LED stripe that is wound through all segments in an S pattern and then continuing to the next digit while the stripe being upright on its side. Selecting *debug* gives a better idea how things fit together.
Adding a diffuser on top or at the bottom of the segment holes will probably enhance the visuals. Just using paper may be enough.
There is currently not a lot of space for electronics and this generator is still untested. Good luck!
"""
ui_group = "Misc"
ui_group = "Unstable"
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.argparser.add_argument(
"--height", action="store", type=float, default=100.0,
help="height of the front panel (with walls if outside is selected) in mm")
self.argparser.add_argument(
"--h", action="store", type=float, default=20.0,
help="depth (with walls if outside is selected) in mm")
self.buildArgParser(outside=False)
def frontCB(self):
x = self.height
self.hole(1.27*x, 0.4*x, 0.05*x)
self.hole(1.27*x, 0.6*x, 0.05*x)
self.moveTo(0.1*x, 0.1*x)
for i in range(2):
for j in range(2):
self.seven_segments(.8 * x)
#self.seven_holes(.8 * x)
self.moveTo(.6 * x)
self.moveTo(0.1 * x)
def backCB(self):
x = self.height
self.moveTo(0.1*x, 0.1*x)
for i in range(2):
for j in range(2):
self.seven_segment_holes(.8 * x)
self.moveTo(.6 * x)
self.moveTo(0.1 * x)
def render(self):
height, h = self.height, self.h
if self.outside:
height = self.height = self.adjustSize(height)
h = self.h = self.adjustSize(h)
t = self.thickness
y = (3*0.60 + 0.1 + 0.2) * height + 0.55 * 0.8 * height
self.rectangularWall(height, h, "FFFF", move="right")
self.rectangularWall(y, h, "FfFf", move="up")
self.rectangularWall(y, h, "FfFf")
self.rectangularWall(height, h, "FFFF", move="left up")
with self.saved_context():
self.rectangularWall(y, height, "ffff", callback=[self.frontCB], move="right")
self.rectangularWall(y, height, "ffff", callback=[self.backCB], move="right")
self.rectangularWall(y, height, "ffff", move="up only")
self.seven_segment_separators(0.8*height, h, 4)
| 3,385 | Python | .py | 69 | 41.318841 | 238 | 0.643528 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,691 | console2.py | florianfesti_boxes/boxes/generators/console2.py | # Copyright (C) 2013-2020 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 *
class Console2(Boxes):
"""Console with slanted panel and service hatches"""
ui_group = "Box"
description = """
This box is designed as a housing for electronic projects. It has hatches that can be re-opened with simple tools. It intentionally cannot be opened with bare hands - if build with thin enough material.
#### Caution
There is a chance that the latches of the back wall or the back wall itself interfere with the front panel or its mounting frame/lips. The generator does not check for this. So depending on the variant chosen you might need to make the box deeper (increase y parameter) or the panel angle steeper (increase angle parameter) until there is enough room.
It's also possible that the frame of the panel interferes with the floor if the hi parameter is too small.
#### Assembly instructions
The main body is easy to assemble by starting with the floor and then adding the four walls and (if present) the top piece.
If the back wall is removable you need to add the lips and latches. The U-shaped clamps holding the latches in place need to be clued in place without also gluing the latches themselves. Make sure the springs on the latches point inwards and the angled ends point to the side walls as shown here:

If the panel is removable you need to add the springs with the tabs to the side lips. This photo shows the variant which has the panel glued to the frame:

If space is tight you may consider not gluing the cross pieces in place and remove them after the glue-up. This may prevent the latches of the back wall and the panel from interfering with each other.
The variant using finger joints only has the two side lips without the cross bars.
#### Re-Opening
The latches at the back wall lock in place when closed. To open them they need to be pressed in and can then be moved aside.
To remove the panel you have to press in the four tabs at the side. It is easiest to push them in and then pull the panel up a little bit so the tabs stay in.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=.5)
self.addSettingsArgs(edges.StackableSettings)
self.buildArgParser(x=100, y=100, h=100, bottom_edge="s",
outside=False)
self.argparser.add_argument(
"--front_height", action="store", type=float, default=30,
help="height of the front below the panel (in mm)")
self.argparser.add_argument(
"--angle", action="store", type=float, default=50,
help="angle of the front panel (90°=upright)")
self.argparser.add_argument(
"--removable_backwall", action="store", type=boolarg, default=True,
help="have latches at the backwall")
self.argparser.add_argument(
"--removable_panel", action="store", type=boolarg, default=True,
help="The panel is held by tabs and can be removed")
self.argparser.add_argument(
"--glued_panel", action="store", type=boolarg, default=True,
help="the panel is glued and not held by finger joints")
def borders(self):
x, y, h, fh = self.x, self.y, self.h, self.front_height
t = self.thickness
panel = min((h-fh)/math.cos(math.radians(90-self.angle)),
y/math.cos(math.radians(self.angle)))
top = y - panel * math.cos(math.radians(self.angle))
h = fh + panel * math.sin(math.radians(self.angle))
if top>0.1*t:
borders = [y, 90, fh, 90-self.angle, panel, self.angle, top,
90, h, 90]
else:
borders = [y, 90, fh, 90-self.angle, panel, self.angle+90, h, 90]
return borders
def latch(self, move=None):
t = self.thickness
s = 0.1 * t
tw, th = 8*t, 3*t
if self.move(tw, th, move, True):
return
self.moveTo(0, 1.2*t)
self.polyline(t, -90, .2*t, 90, 2*t, -90, t, 90, t, 90, t, -90, 3*t,
90, t, -90, t, 90, t, 90, 2*t, 90, 0.5*t,
-94, 4.9*t, 94, .5*t, 86, 4.9*t, -176, 5*t,
-90, 1.0*t, 90, t, 90, 1.8*t, 90)
self.move(tw, th, move)
def latch_clamp(self, move=None):
t = self.thickness
s = 0.1 * t
tw, th = 4*t, 4*t
if self.move(tw, th, move, True):
return
self.moveTo(0.5*t)
self.polyline(t-0.5*s, 90, 2.5*t+.5*s, -90, t+s, -90, 2.5*t+.5*s, 90, t-0.5*s, 90,
t, -90, 0.5*t, 90, 2*t, 45, 2**.5*t, 45, 2*t, 45, 2**.5*t, 45, 2*t, 90, 0.5*t, -90, t, 90)
self.move(tw, th, move)
@restore
@holeCol
def latch_hole(self, posx):
t = self.thickness
s = 0.1 * t
self.moveTo(posx, 2*t, 180)
path = [1.5*t, -90, t, -90, t-0.5*s, 90]
path = path + [2*t] + list(reversed(path))
path = path[:-1] + [3*t] + list(reversed(path[:-1]))
self.polyline(*path)
def panel_side(self, l, move=None):
t = self.thickness
s = 0.1 * t
tw, th = l, 3*t
if not self.glued_panel:
th += t
if self.move(tw, th, move, True):
return
self.rectangularHole(3*t, 1.5*t, 3*t, 1.05*t)
self.rectangularHole(l-3*t, 1.5*t, 3*t, 1.05*t)
self.rectangularHole(l/2, 1.5*t, 2*t, t)
if self.glued_panel:
self.polyline(*([l, 90, t, 90, t, -90, t, -90, t, 90, t, 90]*2))
else:
self.polyline(l, 90, 3*t, 90)
self.edges["f"](l)
self.polyline(0, 90, 3*t, 90)
self.move(tw, th, move)
def panel_lock(self, l, move=None):
t = self.thickness
l -= 4*t
tw, th = l, 2.5*t
if self.move(tw, th, move, True):
return
end = [l/2-3*t, -90, 1.5*t, (90, .5*t), t, (90, .5*t),
t, 90, .5*t, -90, 0.5*t, -90, 0, (90, .5*t), 0, 90,]
self.moveTo(l/2-t, 2*t, -90)
self.polyline(*([t, 90, 2*t, 90, t, -90] + end + [l] +
list(reversed(end))))
self.move(tw, th, move)
def panel_cross_beam(self, l, move=None):
t = self.thickness
tw, th = l+2*t, 3*t
if self.move(tw, th, move, True):
return
self.moveTo(t, 0)
self.polyline(*([l, 90, t, -90, t, 90, t, 90, t, -90, t, 90]*2))
self.move(tw, th, move)
def side(self, borders, bottom="s", move=None, label=""):
t = self.thickness
bottom = self.edges.get(bottom, bottom)
tw = borders[0] + 2* self.edges["f"].spacing()
th = borders[-2] + bottom.spacing() + self.edges["f"].spacing()
if self.move(tw, th, move, True):
return
d1 = t * math.cos(math.radians(self.angle))
d2 = t * math.sin(math.radians(self.angle))
self.moveTo(t, 0)
bottom(borders[0])
self.corner(90)
self.edges["f"](borders[2]+bottom.endwidth()-d1)
self.edge(d1)
self.corner(borders[3])
if self.removable_panel:
self.rectangularHole(3*t, 1.5*t, 2.5*t, 1.05*t)
if not self.removable_panel and not self.glued_panel:
self.edges["f"](borders[4])
else:
self.edge(borders[4])
if self.removable_panel:
self.rectangularHole(-3*t, 1.5*t, 2.5*t, 1.05*t)
if len(borders) == 10:
self.corner(borders[5])
self.edge(d2)
self.edges["f"](borders[6]-d2)
self.corner(borders[-3])
if self.removable_backwall:
self.rectangularHole(self.latchpos, 1.55*t, 1.1*t, 1.1*t)
self.edge(borders[-2]-t)
self.edges["f"](t+bottom.startwidth())
else:
self.edges["f"](borders[-2]+bottom.startwidth())
self.corner(borders[-1])
self.move(tw, th, move, label=label)
def render(self):
x, y, h = self.x, self.y, self.h
t = self.thickness
bottom = self.edges.get(self.bottom_edge)
if self.outside:
self.x = x = self.adjustSize(x)
self.y = y = self.adjustSize(y)
self.h = h = self.adjustSize(h, bottom)
d1 = t * math.cos(math.radians(self.angle))
d2 = t * math.sin(math.radians(self.angle))
self.latchpos = latchpos = 6*t
borders = self.borders()
self.side(borders, bottom, move="right", label="Left Side")
self.side(borders, bottom, move="right", label="Right Side")
self.rectangularWall(borders[0], x, "ffff", move="right", label="Floor")
self.rectangularWall(
borders[2]-d1, x, ("F", "e", "F", bottom), ignore_widths=[7, 4],
move="right", label="Front")
if self.glued_panel:
self.rectangularWall(borders[4], x, "EEEE", move="right", label="Panel")
elif self.removable_panel:
self.rectangularWall(borders[4], x-2*t, "hEhE", move="right", label="Panel")
else:
self.rectangularWall(borders[4], x, "FEFE", move="right", label="Panel")
if len(borders) == 10:
self.rectangularWall(borders[6]-d2, x, "FEFe", move="right", label="Top")
if self.removable_backwall:
self.rectangularWall(
borders[-2]-1.05*t, x, "EeEe",
callback=[
lambda:self.latch_hole(latchpos),
lambda: self.fingerHolesAt(.5*t, 0, borders[-2]-4.05*t-latchpos),
lambda:self.latch_hole(borders[-2]-1.2*t-latchpos),
lambda: self.fingerHolesAt(.5*t, 3.05*t+latchpos, borders[-2]-4.05*t-latchpos)],
move="right",
label="Back Wall")
self.rectangularWall(2*t, borders[-2]-4.05*t-latchpos, "EeEf", move="right", label="Guide")
self.rectangularWall(2*t, borders[-2]-4.05*t-latchpos, "EeEf", move="right", label="Guide")
self.rectangularWall(t, x, ("F", bottom, "F", "e"),
ignore_widths=[0, 3], move="right", label="Bottom Back")
else:
self.rectangularWall(borders[-2], x, ("F", bottom, "F", "e"),
ignore_widths=[0, 3], move="right", label="Back Wall")
# hardware for panel
if self.removable_panel:
if self.glued_panel:
self.panel_cross_beam(x-2.05*t, "rotated right")
self.panel_cross_beam(x-2.05*t, "rotated right")
self.panel_lock(borders[4], "up")
self.panel_lock(borders[4], "up")
self.panel_side(borders[4], "up")
self.panel_side(borders[4], "up")
# hardware for back wall
if self.removable_backwall:
self.latch(move="up")
self.latch(move="up")
self.partsMatrix(4, 2, "up", self.latch_clamp)
| 11,787 | Python | .py | 232 | 40.728448 | 351 | 0.586765 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,692 | basedbox.py | florianfesti_boxes/boxes/generators/basedbox.py | # 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/>.
from boxes import *
class BasedBox(Boxes):
"""Fully closed box on a base"""
ui_group = "Box"
description = """This box is more of a building block than a finished item.
Use a vector graphics program (like Inkscape) to add holes or adjust the base
plate. The width of the "brim" can also be adjusted with the **edge_width**
parameter in the **Finger Joints Settings**.
See ClosedBox for variant without a base.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser("x", "y", "h", "outside")
def render(self):
x, y, h = self.x, self.y, self.h
if self.outside:
x = self.adjustSize(x)
y = self.adjustSize(y)
h = self.adjustSize(h)
t = self.thickness
self.rectangularWall(x, h, "fFFF", move="right", label="Wall 1")
self.rectangularWall(y, h, "ffFf", move="up", label="Wall 2")
self.rectangularWall(y, h, "ffFf", label="Wall 4")
self.rectangularWall(x, h, "fFFF", move="left up", label="Wall 3")
self.rectangularWall(x, y, "ffff", move="right", label="Top")
self.rectangularWall(x, y, "hhhh", label="Base")
| 1,931 | Python | .py | 41 | 42.04878 | 79 | 0.675546 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,693 | electronicsbox.py | florianfesti_boxes/boxes/generators/electronicsbox.py | # Copyright (C) 2013-2017 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 *
class ElectronicsBox(Boxes):
"""Closed box with screw on top and mounting holes"""
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--triangle", action="store", type=float, default=25.,
help="Sides of the triangles holding the lid in mm")
self.argparser.add_argument(
"--d1", action="store", type=float, default=2.,
help="Diameter of the inner lid screw holes in mm")
self.argparser.add_argument(
"--d2", action="store", type=float, default=3.,
help="Diameter of the lid screw holes in mm")
self.argparser.add_argument(
"--d3", action="store", type=float, default=3.,
help="Diameter of the mounting screw holes in mm")
self.argparser.add_argument(
"--outsidemounts", action="store", type=boolarg, default=True,
help="Add external mounting points")
self.argparser.add_argument(
"--holedist", action="store", type=float, default=7.,
help="Distance of the screw holes from the wall in mm")
def wallxCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.x, self.h-1.5*t, self.triangle, 180)
def wallyCB(self):
t = self.thickness
self.fingerHolesAt(0, self.h-1.5*t, self.triangle, 0)
self.fingerHolesAt(self.y, self.h-1.5*t, self.triangle, 180)
def render(self):
t = self.thickness
self.h = h = self.h + 2*t # compensate for lid
x, y, h = self.x, self.y, self.h
d1, d2, d3 =self.d1, self.d2, self.d3
hd = self.holedist
tr = self.triangle
trh = tr / 3.
if self.outside:
self.x = x = self.adjustSize(x)
self.y = y = self.adjustSize(y)
self.h = h = h - 3*t
self.rectangularWall(x, h, "fFeF", callback=[self.wallxCB],
move="right", label="Wall 1")
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB],
move="up", label="Wall 2")
self.rectangularWall(y, h, "ffef", callback=[self.wallyCB],
label="Wall 4")
self.rectangularWall(x, h, "fFeF", callback=[self.wallxCB],
move="left up", label="Wall 3")
if not self.outsidemounts:
self.rectangularWall(x, y, "FFFF", callback=[
lambda:self.hole(hd, hd, d=d3)] *4, move="right",
label="Bottom")
else:
self.flangedWall(x, y, edges="FFFF",
flanges=[0.0, 2*hd, 0., 2*hd], r=hd,
callback=[
lambda:self.hole(hd, hd, d=d3)] * 4, move='up',
label="Bottom")
self.rectangularWall(x, y, callback=[
lambda:self.hole(trh, trh, d=d2)] * 4, move='up', label="Top")
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
| 3,949 | Python | .py | 82 | 38 | 74 | 0.588739 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,694 | abox.py | florianfesti_boxes/boxes/generators/abox.py | # 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/>.
from boxes import *
from boxes.lids import LidSettings
class ABox(Boxes):
"""A simple Box"""
description = "This box is kept simple on purpose. If you need more features have a look at the UniversalBox."
ui_group = "Box"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(LidSettings)
self.buildArgParser("x", "y", "h", "outside", "bottom_edge")
def render(self):
x, y, h = self.x, self.y, self.h
t = self.thickness
t1, t2, t3, t4 = "eeee"
b = self.edges.get(self.bottom_edge, self.edges["F"])
sideedge = "F" # if self.vertical_edges == "finger joints" else "h"
if self.outside:
self.x = x = self.adjustSize(x, sideedge, sideedge)
self.y = y = self.adjustSize(y)
self.h = h = self.adjustSize(h, b, t1)
with self.saved_context():
self.rectangularWall(x, h, [b, sideedge, t1, sideedge],
ignore_widths=[1, 6], move="up")
self.rectangularWall(x, h, [b, sideedge, t3, sideedge],
ignore_widths=[1, 6], move="up")
if self.bottom_edge != "e":
self.rectangularWall(x, y, "ffff", move="up")
self.lid(x, y)
self.rectangularWall(x, h, [b, sideedge, t3, sideedge],
ignore_widths=[1, 6], move="right only")
self.rectangularWall(y, h, [b, "f", t2, "f"],
ignore_widths=[1, 6], move="up")
self.rectangularWall(y, h, [b, "f", t4, "f"],
ignore_widths=[1, 6], move="up")
| 2,411 | Python | .py | 49 | 40.102041 | 114 | 0.6 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,695 | doubleflexdoorbox.py | florianfesti_boxes/boxes/generators/doubleflexdoorbox.py | # 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/>.
import math
import boxes
class DoubleFlexDoorBox(boxes.Boxes):
"""Box with two part lid with living hinges and round corners"""
ui_group = "FlexBox"
def __init__(self) -> None:
boxes.Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.addSettingsArgs(boxes.edges.FlexSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--radius", action="store", type=float, default=15,
help="Radius of the latch in mm")
self.argparser.add_argument(
"--latchsize", action="store", type=float, default=8,
help="size of latch in multiples of thickness")
def flexBoxSide(self, x, y, r, callback=None, move=None):
t = self.thickness
ll = (x - 2*r) / 2 - self.latchsize
if self.move(x+2*t, y+2*t, move, True):
return
self.moveTo(t+r, t)
for i, l in zip(range(2), (x, y)):
self.cc(callback, i)
self.edges["f"](l - 2 * r)
self.corner(90, r)
self.cc(callback, 2)
self.edge(ll)
self.latch(self.latchsize)
self.latch(self.latchsize, reverse=True)
self.edge(ll)
self.corner(90, r)
self.cc(callback, 3)
self.edges["f"](y - 2 * r)
self.corner(90, r)
self.move(x+2*t, y+2*t, move)
def surroundingWall(self, x, y, h, r, move=None):
t = self.thickness
c4 = math.pi * r * 0.5
tw = 2*x + 2*y - 8*r + 4*c4
th = h + 2.5*t
if self.move(tw, th, move, True):
return
self.moveTo(0, 0.25*t, -90)
self.latch(self.latchsize, False, True)
self.edge((x-2*r)/2 - self.latchsize, False)
if y - 2 * r < t:
self.edges["X"](2 * c4 + y - 2 * r, h + 2 * t)
else:
self.edges["X"](c4, h + 2 * t)
self.edges["F"](y - 2 * r, False)
self.edges["X"](c4, h + 2 * t)
self.edges["F"](x - 2 * r, False)
if y - 2 * r < t:
self.edges["X"](2 * c4 + y - 2 * r, h + 2 * t)
else:
self.edges["X"](c4, h + 2 * t)
self.edges["F"](y - 2 * r)
self.edges["X"](c4, h + 2 * t)
self.edge((x-2*r)/2 - self.latchsize, False)
self.latch(self.latchsize, False)
self.edge(h + 2 * t)
self.latch(self.latchsize, False, True)
self.edge((x-2*r)/2 - self.latchsize, False)
self.edge(c4)
self.edges["F"](y - 2 * r)
self.edge(c4)
self.edges["F"](x - 2 * r, False)
self.edge(c4)
self.edges["F"](y - 2 * r, False)
self.edge(c4)
self.edge((x-2*r)/2 - self.latchsize)
self.latch(self.latchsize, False, False)
self.edge(h + 2 * t)
self.move(tw, th, move)
def render(self):
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h)
t = self.thickness
self.latchsize *= t
x, y, h = self.x, self.y, self.h
r = self.radius or min(x - 2*self.latchsize, y) / 2.0
r = min(r, y / 2.0)
self.radius = r = min(r, max(0, (x - 2*self.latchsize) / 2.0))
# swap y and h for more consistent axis names
self.surroundingWall(x, h, y, r, move="up")
self.flexBoxSide(x, h, r, move="right")
self.flexBoxSide(x, h, r, move="mirror")
| 4,208 | Python | .py | 104 | 32 | 73 | 0.561765 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,696 | edges.py | florianfesti_boxes/boxes/generators/edges.py | # Copyright (C) 2013-2016 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 *
class Edges(Boxes):
"""Print all registered Edge types"""
webinterface = False
def __init__(self) -> None:
Boxes.__init__(self)
def render(self):
self.ctx = None
self._buildObjects()
chars = self.edges.keys()
for c in sorted(chars, key=lambda x:(x.lower(), x.isupper())):
print("%s %s - %s" %(c, self.edges[c].__class__.__name__,
self.edges[c].__doc__))
| 1,162 | Python | .py | 27 | 38.62963 | 73 | 0.671391 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,697 | flexbox2.py | florianfesti_boxes/boxes/generators/flexbox2.py | # 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/>.
from boxes import *
class FlexBox2(Boxes):
"""Box with living hinge and top corners rounded"""
ui_group = "FlexBox"
def __init__(self) -> None:
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.addSettingsArgs(edges.FlexSettings)
self.buildArgParser("x", "y", "h", "outside")
self.argparser.add_argument(
"--radius", action="store", type=float, default=15,
help="Radius of the corners in mm")
self.argparser.add_argument(
"--latchsize", action="store", type=float, default=8,
help="size of latch in multiples of thickness")
def flexBoxSide(self, y, h, r, callback=None, move=None):
t = self.thickness
if self.move(y+2*t, h+t, move, True):
return
self.moveTo(t, t)
self.cc(callback, 0)
self.edges["f"](y)
self.corner(90, 0)
self.cc(callback, 1)
self.edges["f"](h - r)
self.corner(90, r)
self.cc(callback, 2)
self.edge(y - 2 * r)
self.corner(90, r)
self.cc(callback, 3)
self.latch(self.latchsize)
self.cc(callback, 4)
self.edges["f"](h - r - self.latchsize)
self.corner(90)
self.move(y+2*t, h+t, move)
def surroundingWall(self, move=None):
y, h, x, r = self.y, self.h, self.x, self.radius
t = self.thickness
tw = y + h - 3*r + 2*self.c4 + self.latchsize + t
th = x + 2.5*t
if self.move(tw, th, move, True):
return
self.moveTo(t, .25*t)
self.edges["F"](h - r, False)
if (y - 2 * r < t):
self.edges["X"](2 * self.c4 + y - 2 * r, x + 2 * t)
else:
self.edges["X"](self.c4, x + 2 * t)
self.edge(y - 2 * r)
self.edges["X"](self.c4, x + 2 * t)
self.latch(self.latchsize, False)
self.edge(x + 2 * t)
self.latch(self.latchsize, False, True)
self.edge(self.c4)
self.edge(y - 2 * r)
self.edge(self.c4)
self.edges["F"](h - r)
self.corner(90)
self.edge(t)
self.edges["f"](x)
self.edge(t)
self.corner(90)
self.move(tw, th, move)
def render(self):
if self.outside:
self.y = self.adjustSize(self.y)
self.h = self.adjustSize(self.h)
self.x = self.adjustSize(self.x)
self.latchsize *= self.thickness
self.radius = self.radius or min(self.y / 2.0, self.h - self.latchsize)
self.radius = min(self.radius, self.y / 2.0)
self.radius = min(self.radius, max(0, self.h - self.latchsize))
self.c4 = c4 = math.pi * self.radius * 0.5
self.moveTo(2 * self.thickness, self.thickness)
with self.saved_context():
self.surroundingWall(move="right")
self.rectangularWall(self.y, self.x, edges="FFFF")
self.surroundingWall(move="up only")
self.flexBoxSide(self.y, self.h, self.radius, move="right")
self.flexBoxSide(self.y, self.h, self.radius, move= "mirror right")
self.rectangularWall(self.x, self.h - self.radius - self.latchsize, edges="fFeF")
| 3,923 | Python | .py | 95 | 33.021053 | 89 | 0.593167 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,698 | tetris.py | florianfesti_boxes/boxes/generators/tetris.py | # Copyright (C) 2013-2016 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 *
class Tetris(Boxes):
"""3D Tetris shapes"""
ui_group = "Misc"
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.argparser.add_argument(
"--blocksize", action="store", type=float, default=40.,
help="size of a square")
self.argparser.add_argument(
"--shape", action="store", type=str, default="L",
choices=['I', 'L', 'O', 'S', 'T'],
help="shape of the piece")
def cb(self, nr):
t = self.thickness
s = self.blocksize
self.ctx.stroke()
self.set_source_color(Color.ETCHING)
if nr == 0:
if self.shape in "LT":
for i in range(1, 3):
with self.saved_context():
self.moveTo(s*i - t, 0, 90)
self.edge(s - 2*t)
if self.shape == "L":
self.moveTo(s*2, s - t, 0)
else: # "T"
self.moveTo(s, s - t, 0)
self.edge(s - 2*t)
if self.shape == "I":
for i in range(1, 4):
with self.saved_context():
self.moveTo(s*i - t, 0, 90)
self.edge(s - 2*t)
if self.shape == "S" and nr in (0, 1, 4, 5):
self.moveTo(s - t, 0, 90)
self.edge(s - 2*t)
if self.shape == "O":
self.moveTo(s - t, 0, 90)
self.edge(s - t)
self.ctx.stroke()
def render(self):
# adjust to the variables you want in the local scope
t = self.thickness
s = self.blocksize
if self.shape == "L":
borders = [3*s - 2*t, 90, 2*s - 2*t, 90, s - 2*t, 90,
s, -90, 2*s, 90, s - 2*t, 90]
elif self.shape == "I":
borders = [4*s - 2*t, 90, s - 2*t, 90 ] * 2
elif self.shape == "S":
borders = [2 * s - 2 * t, 90, s, -90, s, 90, s - 2 * t, 90] *2
elif self.shape == "O":
borders = [2*s - 2*t, 90] * 4
elif self.shape == "T":
borders = [90, s - 2*t, 90, s, -90, s, 90]
borders = [3*s - 2*t] + borders + [s - 2*t] + list(reversed(borders))
self.polygonWall(borders=borders, callback=self.cb, move="right")
self.polygonWall(borders=borders, callback=self.cb,
move="mirror right")
self.polygonWalls(borders=borders, h=s - 2 * t)
| 3,231 | Python | .py | 76 | 31.960526 | 81 | 0.523082 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
25,699 | paperbox.py | florianfesti_boxes/boxes/generators/paperbox.py | # Copyright (C) 2020 Guillaume Collic
#
# 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/>.
import math
from boxes import Boxes
class PaperBox(Boxes):
"""
Box made of paper, with lid.
"""
ui_group = "Misc"
description = """
This box is made of paper.
There is marks in the "outside leftover paper" to help see where to fold
(cutting with tabs helps use them). The cut is very precise, and could be too tight if misaligned when glued. A plywood box (such as a simple TypeTray) of the same size is a great guide during folding and gluing. Just fold the box against it. Accurate quick and easy.
A paper creaser (or bone folder) is also useful.
"""
def __init__(self) -> None:
Boxes.__init__(self)
self.buildArgParser("x", "y", "h")
self.argparser.add_argument(
"--design",
action="store",
type=str,
default="automatic",
choices=("automatic", "widebox", "tuckbox"),
help="different design for paper consumption optimization. The tuckbox also has locking cut for its lid.",
)
self.argparser.add_argument(
"--lid_height",
type=float,
default=15,
help="Height of the lid (part which goes inside the box)",
)
self.argparser.add_argument(
"--lid_radius",
type=float,
default=7,
help="Angle, in radius, of the round corner of the lid",
)
self.argparser.add_argument(
"--lid_sides",
type=float,
default=20,
help="Width of the two sides upon which goes the lid",
)
self.argparser.add_argument(
"--margin",
type=float,
default=0,
help="Margin for the glued sides",
)
self.argparser.add_argument(
"--mark_length",
type=float,
default=1.5,
help="Length of the folding outside mark",
)
self.argparser.add_argument(
"--tab_angle_rad",
type=float,
default=math.atan(2 / 25),
help="Angle (in radian) of the sides which are to be glued inside the box",
)
self.argparser.add_argument(
"--finger_hole_diameter",
type=float,
default=15,
help="Diameter of the hole to help catch the lid",
)
def render(self):
if self.design == "automatic":
self.design = "tuckbox" if self.h > self.y else "widebox"
path = (
self.tuckbox(self.x, self.y, self.h)
if self.design == "tuckbox"
else self.widebox(self.x, self.y, self.h)
)
self.polyline(*path)
def tuckbox(self, width, length, height):
lid_cut_length = min(10, length / 2, width / 5)
half_side = (
self.mark(self.mark_length)
+ [
0,
90,
]
+ self.ear_description(length, lid_cut_length)
+ [
0,
-90,
length,
0,
]
+ self.lid_cut(lid_cut_length)
+ self.lid_tab(width - 2 * self.thickness)
+ [0]
+ self.lid_cut(lid_cut_length, reverse=True)
+ [
length,
-90,
]
+ self.ear_description(length, lid_cut_length, reverse=True)
+ self.mark(self.mark_length)
)
return (
[height, 0]
+ half_side
+ self.side_with_finger_hole(width, self.finger_hole_diameter)
+ self.mark(self.mark_length)
+ [
0,
90,
]
+ self.tab_description(length - self.margin - self.thickness, height)
+ [
0,
90,
]
+ self.mark(self.mark_length)
+ [width]
+ list(reversed(half_side))
)
def widebox(self, width, length, height):
half_side = (
self.mark(self.mark_length)
+ [
0,
90,
]
+ self.tab_description(length / 2 - self.margin, height)
+ [
0,
-90,
height,
0,
]
+ self.mark(self.mark_length)
+ [
0,
90,
]
+ self.tab_description(self.lid_sides, length)
+ [
0,
90,
]
+ self.mark(self.mark_length)
+ [
height,
-90,
]
+ self.tab_description(length / 2 - self.margin, height)
+ [
length,
0,
]
+ self.mark(self.mark_length)
)
return (
self.side_with_finger_hole(width, self.finger_hole_diameter)
+ half_side
+ self.lid_tab(width)
+ list(reversed(half_side))
)
def lid_tab(self, width):
return [
self.lid_height - self.lid_radius,
(90, self.lid_radius),
width - 2 * self.lid_radius,
(90, self.lid_radius),
self.lid_height - self.lid_radius,
]
def mark(self, length):
if length == 0:
return []
return [
0,
-90,
length,
180,
length,
-90,
]
def lid_cut(self, length, reverse=False):
path = [
90,
length + self.thickness,
-180,
length,
90,
]
return [0] + (list(reversed(path)) if reverse else path)
def side_with_finger_hole(self, width, finger_hole_diameter):
half_width = (width - finger_hole_diameter) / 2
return [
half_width,
90,
0,
(-180, finger_hole_diameter / 2),
0,
90,
half_width,
0,
]
def tab_description(self, height, width):
deg = math.degrees(self.tab_angle_rad)
side = height / math.cos(self.tab_angle_rad)
end_width = width - 2 * height * math.tan(self.tab_angle_rad)
return [
0,
deg - 90,
side,
90 - deg,
end_width,
90 - deg,
side,
deg - 90,
]
def ear_description(self, length, lid_cut_length, reverse=False):
ear_depth = max(lid_cut_length, self.lid_height)
radius = min(self.lid_radius, ear_depth - lid_cut_length)
start_margin = self.thickness
end_margin = 2 * self.burn
path = [
start_margin,
-90,
lid_cut_length,
90,
0,
(-90, radius),
0,
90,
length - radius - start_margin - end_margin,
90,
ear_depth,
-90,
end_margin,
]
return (list(reversed(path)) if reverse else path) + [0]
| 7,896 | Python | .py | 250 | 20.464 | 267 | 0.493701 | florianfesti/boxes | 970 | 351 | 40 | GPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |