2017-02-12 22:23:19 +01:00
|
|
|
# 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/>.
|
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
from boxes import edges, Boxes
|
2017-02-12 22:23:19 +01:00
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
class LidSettings(edges.Settings):
|
2017-02-12 22:23:19 +01:00
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
"""Settings for the Lid
|
|
|
|
Values:
|
|
|
|
*absolute
|
|
|
|
|
|
|
|
* style : "none" : type of lid to create
|
|
|
|
|
|
|
|
* relative (in multiples of thickness)
|
|
|
|
|
|
|
|
* height : 4.0 : height of the brim (if any)
|
|
|
|
* play : 0.1 : play when sliding the lid on (if applicable)
|
|
|
|
"""
|
|
|
|
|
|
|
|
absolute_params = {
|
|
|
|
"style" : ("none", "flat", "chest", "overthetop", "ontop"),
|
|
|
|
}
|
|
|
|
|
|
|
|
relative_params = {
|
|
|
|
"height" : 4.0,
|
|
|
|
"play" : 0.1,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Lid:
|
|
|
|
|
|
|
|
def __init__(self, boxes, settings):
|
|
|
|
self.boxes = boxes
|
|
|
|
self.settings = settings
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
"""Hack for using unalter code form Boxes class"""
|
|
|
|
if hasattr(self.settings, name):
|
|
|
|
return getattr(self.settings, name)
|
|
|
|
return getattr(self.boxes, name)
|
|
|
|
|
|
|
|
def handleCB(self, x, y):
|
|
|
|
def cb():
|
|
|
|
pass
|
|
|
|
|
|
|
|
return cb
|
|
|
|
|
|
|
|
def __call__(self, x, y, edge=None):
|
|
|
|
t = self.thickness
|
|
|
|
style = self.settings.style
|
|
|
|
height = self.height
|
|
|
|
if style == "flat":
|
|
|
|
self.rectangularWall(x, y, "eeee", move="right", label="lid bottom")
|
|
|
|
self.rectangularWall(x, y, "EEEE", move="up", label="lid top")
|
|
|
|
elif style == "chest":
|
|
|
|
self.chestSide(x, move="right", label="lid right")
|
|
|
|
self.chestSide(x, move="up", label="lid left")
|
|
|
|
self.chestSide(x, move="left only", label="invisible")
|
|
|
|
self.chestTop(x, y, move="up", label="lid top")
|
|
|
|
elif style in ("overthetop", "ontop"):
|
|
|
|
x2 = x
|
|
|
|
y2 = y
|
|
|
|
if style == "overthetop":
|
|
|
|
x2 += 2*t + self.play
|
|
|
|
y2 += 2*t + self.play
|
|
|
|
self.rectangularWall(x2, y2, "ffff", move="up")
|
|
|
|
self.rectangularWall(x2, self.height, "eFFF",
|
|
|
|
ignore_widths=[1, 2, 5, 6], move="up")
|
|
|
|
self.rectangularWall(x2, self.height, "eFFF",
|
|
|
|
ignore_widths=[1, 2, 5, 6], move="up")
|
|
|
|
self.rectangularWall(y2, self.height, "efFf",
|
|
|
|
ignore_widths=[1, 2, 5, 6], move="up")
|
|
|
|
self.rectangularWall(y2, self.height, "efFf",
|
|
|
|
ignore_widths=[1, 2, 5, 6], move="up")
|
|
|
|
if style == "ontop":
|
|
|
|
self.rectangularWall(y - self.play, height + 2*t, "eeee",
|
|
|
|
move="up")
|
|
|
|
self.rectangularWall(y - self.play, height + 2*t, "eeee",
|
|
|
|
move="up")
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def getChestR(self, x, angle=0):
|
2017-02-12 22:23:19 +01:00
|
|
|
t = self.thickness
|
|
|
|
d = x - 2*math.sin(math.radians(angle)) * (3*t)
|
|
|
|
|
|
|
|
r = d / 2.0 / math.cos(math.radians(angle))
|
|
|
|
return r
|
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
def chestSide(self, x, angle=0, move="", label=""):
|
2017-02-12 22:23:19 +01:00
|
|
|
if "a" not in self.edges:
|
|
|
|
s = edges.FingerJointSettings(self.thickness, True,
|
|
|
|
finger=1.0, space=1.0)
|
|
|
|
s.edgeObjects(self, "aA.")
|
|
|
|
|
|
|
|
t = self.thickness
|
2023-04-06 21:06:28 +02:00
|
|
|
r = self.getChestR(x, angle)
|
2022-05-14 10:35:58 +02:00
|
|
|
if self.move(x+2*t, 0.5*x+3*t, move, True, label=label):
|
2017-02-12 22:23:19 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.moveTo(t, 0)
|
|
|
|
self.edge(x)
|
|
|
|
self.corner(90+angle)
|
|
|
|
self.edges["a"](3*t)
|
|
|
|
self.corner(180-2*angle, r)
|
|
|
|
self.edges["a"](3*t)
|
|
|
|
self.corner(90+angle)
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
self.move(x+2*t, 0.5*x+3*t, move, False, label=label)
|
2017-02-12 22:23:19 +01:00
|
|
|
|
2023-04-06 21:06:28 +02:00
|
|
|
def chestTop(self, x, y, angle=0, move=None, label=""):
|
2017-02-12 22:23:19 +01:00
|
|
|
if "a" not in self.edges:
|
|
|
|
s = edges.FingerJointSettings(self.thickness, True,
|
|
|
|
finger=1.0, space=1.0)
|
|
|
|
s.edgeObjects(self, "aA.")
|
|
|
|
|
|
|
|
t = self.thickness
|
2023-04-06 21:06:28 +02:00
|
|
|
l = math.radians(180-2*angle) * self.getChestR(x, angle)
|
2017-02-12 22:23:19 +01:00
|
|
|
|
|
|
|
tw = l + 6*t
|
|
|
|
th = y+2*t
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
if self.move(tw, th, move, True, label=label):
|
2017-02-12 22:23:19 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.edges["A"](3*t)
|
|
|
|
self.edges["X"](l, y+2*t)
|
|
|
|
self.edges["A"](3*t)
|
|
|
|
self.corner(90)
|
|
|
|
self.edge(y+2*t)
|
|
|
|
self.corner(90)
|
|
|
|
self.edges["A"](3*t)
|
|
|
|
self.edge(l)
|
|
|
|
self.edges["A"](3*t)
|
|
|
|
self.corner(90)
|
|
|
|
self.edge(y+2*t)
|
|
|
|
self.corner(90)
|
|
|
|
|
2022-05-14 10:35:58 +02:00
|
|
|
self.move(tw, th, move, label=label)
|
2017-02-12 22:23:19 +01:00
|
|
|
|
|
|
|
class _TopEdge(Boxes):
|
|
|
|
|
2019-01-11 21:28:38 +01:00
|
|
|
def addTopEdgeSettings(self, fingerjoint={}, stackable={}, hinge={},
|
2023-04-06 20:21:44 +02:00
|
|
|
cabinethinge={}, slideonlid={}, click={},
|
2022-06-16 14:59:36 +02:00
|
|
|
roundedtriangle={}, mounting={}, handle={}):
|
2019-01-11 21:28:38 +01:00
|
|
|
self.addSettingsArgs(edges.FingerJointSettings, **fingerjoint)
|
|
|
|
self.addSettingsArgs(edges.StackableSettings, **stackable)
|
|
|
|
self.addSettingsArgs(edges.HingeSettings, **hinge)
|
|
|
|
self.addSettingsArgs(edges.CabinetHingeSettings, **cabinethinge)
|
2023-04-06 20:21:44 +02:00
|
|
|
self.addSettingsArgs(edges.SlideOnLidSettings, **slideonlid)
|
2019-01-11 21:28:38 +01:00
|
|
|
self.addSettingsArgs(edges.ClickSettings, **click)
|
|
|
|
self.addSettingsArgs(edges.RoundedTriangleEdgeSettings, **roundedtriangle)
|
2022-05-25 23:31:55 +02:00
|
|
|
self.addSettingsArgs(edges.MountingSettings, **mounting)
|
2022-06-16 14:59:36 +02:00
|
|
|
self.addSettingsArgs(edges.HandleEdgeSettings, **handle)
|
2017-02-12 22:23:19 +01:00
|
|
|
|
|
|
|
def topEdges(self, top_edge):
|
2022-08-31 00:13:00 +02:00
|
|
|
"""Return top edges belonging to given main edge type
|
|
|
|
as a list containing edge for left, back, right, front.
|
|
|
|
"""
|
2022-10-01 13:10:16 +02:00
|
|
|
tl = tb = tr = tf = self.edges.get(top_edge, self.edges["e"])
|
|
|
|
|
|
|
|
if tl.char == "i":
|
|
|
|
tb = tf = "e"
|
2023-04-01 21:04:58 +02:00
|
|
|
tl = "j"
|
2022-10-01 13:10:16 +02:00
|
|
|
elif tl.char == "k":
|
2023-04-01 21:04:58 +02:00
|
|
|
tl = tr = "e"
|
2022-10-01 13:10:16 +02:00
|
|
|
elif tl.char == "L":
|
|
|
|
tl = "M"
|
2023-04-01 21:04:58 +02:00
|
|
|
tf = "e"
|
2022-10-01 13:10:16 +02:00
|
|
|
tr = "N"
|
|
|
|
elif tl.char == "v":
|
2023-04-01 21:04:58 +02:00
|
|
|
tl = tr = tf = "e"
|
2022-10-01 13:10:16 +02:00
|
|
|
elif tl.char == "t":
|
2023-04-01 21:04:58 +02:00
|
|
|
tf = tb = "e"
|
2022-10-01 13:10:16 +02:00
|
|
|
elif tl.char == "G":
|
|
|
|
tl = tb = tr = tf = "e"
|
2022-05-25 23:31:55 +02:00
|
|
|
if self.edges["G"].settings.side == edges.MountingSettings.PARAM_LEFT:
|
2022-10-01 13:10:16 +02:00
|
|
|
tl = "G"
|
2022-05-25 23:31:55 +02:00
|
|
|
elif self.edges["G"].settings.side == edges.MountingSettings.PARAM_RIGHT:
|
2022-10-01 13:10:16 +02:00
|
|
|
tr = "G"
|
2022-05-25 23:31:55 +02:00
|
|
|
elif self.edges["G"].settings.side == edges.MountingSettings.PARAM_FRONT:
|
2022-10-01 13:10:16 +02:00
|
|
|
tf = "G"
|
2022-05-25 23:31:55 +02:00
|
|
|
else: #PARAM_BACK
|
2022-10-01 13:10:16 +02:00
|
|
|
tb = "G"
|
|
|
|
elif tl.char == "y":
|
|
|
|
tl = tb = tr = tf = "e"
|
2022-06-16 14:59:36 +02:00
|
|
|
if self.edges["y"].settings.on_sides == True:
|
2022-10-01 13:10:16 +02:00
|
|
|
tl = tr = "y"
|
2022-06-16 14:59:36 +02:00
|
|
|
else:
|
2022-10-01 13:10:16 +02:00
|
|
|
tb = tf = "y"
|
|
|
|
elif tl.char == "Y":
|
|
|
|
tl = tb = tr = tf = "h"
|
2022-06-16 14:59:36 +02:00
|
|
|
if self.edges["Y"].settings.on_sides == True:
|
2022-10-01 13:10:16 +02:00
|
|
|
tl = tr = "Y"
|
2022-06-16 14:59:36 +02:00
|
|
|
else:
|
2022-10-01 13:10:16 +02:00
|
|
|
tb = tf = "Y"
|
|
|
|
return [tl, tb, tr, tf]
|
2017-02-12 22:23:19 +01:00
|
|
|
|
|
|
|
def drawLid(self, x, y, top_edge, bedBolts=[None, None]):
|
|
|
|
d2, d3 = bedBolts
|
|
|
|
if top_edge == "c":
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(x, y, "CCCC", bedBolts=[d2, d3, d2, d3], move="up", label="top")
|
2017-02-12 22:23:19 +01:00
|
|
|
elif top_edge == "f":
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(x, y, "FFFF", move="up", label="top")
|
2022-06-16 14:59:36 +02:00
|
|
|
elif top_edge in "FhŠY":
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(x, y, "ffff", move="up", label="top")
|
2017-02-12 22:23:19 +01:00
|
|
|
elif top_edge == "L":
|
2023-04-01 21:04:58 +02:00
|
|
|
self.rectangularWall(x, y, "Enlm", move="up", label="lid top")
|
2017-02-12 22:23:19 +01:00
|
|
|
elif top_edge == "i":
|
2023-04-01 21:04:58 +02:00
|
|
|
self.rectangularWall(x, y, "EJeI", move="up", label="lid top")
|
2017-02-12 22:23:19 +01:00
|
|
|
elif top_edge == "k":
|
|
|
|
outset = self.edges["k"].settings.outset
|
|
|
|
self.edges["k"].settings.setValues(self.thickness, outset=True)
|
|
|
|
lx = x/2.0-0.1*self.thickness
|
|
|
|
self.edges['k'].settings.setValues(self.thickness, grip_length=5)
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(lx, y, "IeJe", move="right", label="lid top left")
|
2023-04-01 21:04:58 +02:00
|
|
|
self.rectangularWall(lx, y, "IeJe", move="mirror up", label="lid top right")
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(lx, y, "IeJe", move="left only", label="invisible")
|
2017-02-12 22:23:19 +01:00
|
|
|
self.edges["k"].settings.setValues(self.thickness, outset=outset)
|
2019-11-04 17:13:12 +01:00
|
|
|
elif top_edge == "S":
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(x, y, "ffff", move="up", label="lid top")
|
|
|
|
self.rectangularWall(x, 0, "sFeF", move="up", label="lid top left")
|
|
|
|
self.rectangularWall(x, 0, "sFeF", move="up", label="lid top right")
|
|
|
|
self.rectangularWall(y, 0, "sfef", move="up", label="lid top front")
|
|
|
|
self.rectangularWall(y, 0, "sfef", move="up", label="lid top back")
|
2017-02-12 22:23:19 +01:00
|
|
|
elif top_edge == "v":
|
2022-05-14 10:35:58 +02:00
|
|
|
self.rectangularWall(x, y, "VEEE", move="up", label="lid top")
|
2017-02-12 22:23:19 +01:00
|
|
|
self.edges["v"].parts(move="up")
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|