Skip to content

Commit

Permalink
Hinge: Make style internal, support "flush_inset"
Browse files Browse the repository at this point in the history
"flush_inset" allows the hinge to make use if ignore_widths, though
exending over the wall and connecting seamlessly with F edges around the
corner.

Adjusted TypeTray, UBox and UniversalBox to make use of this.

Resolves: #372, #576
  • Loading branch information
florianfesti committed Jan 3, 2025
1 parent 01215e0 commit d4b238c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
48 changes: 28 additions & 20 deletions boxes/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,21 +1294,17 @@ class HingeSettings(Settings):
Values:
* absolute_params
* style : "outset" : "outset" or "flush"
* outset : False : have lid overlap at the sides (similar to OutSetEdge)
* pinwidth : 1.0 : set to lower value to get disks surrounding the pins
* grip_percentage" : 0 : percentage of the lid that should get grips
* relative (in multiples of thickness)
* hingestrength : 1 : thickness of the arc holding the pin in place (multiples of thickness)
* axle : 2 : diameter of the pin hole (multiples of thickness)
* grip_length : 0 : fixed length of the grips on he lids (multiples of thickness)
"""
absolute_params = {
"style": ("outset", "flush"),
"outset": False,
"pinwidth": 0.5,
"grip_percentage": 0,
Expand All @@ -1320,6 +1316,8 @@ class HingeSettings(Settings):
"grip_length": 0,
}

style = "outset" # "outset", "flush", "flush_inset"

def checkValues(self) -> None:
if self.axle / self.thickness < 0.1:
raise ValueError("HingeSettings: 'axle' need to be at least 0.1 strong")
Expand Down Expand Up @@ -1420,16 +1418,16 @@ def flushlen(self) -> float:
return self.settings.axle + 2.0 * self.settings.hingestrength + 0.5 * self.settings.thickness

def __call__(self, l, **kw):
hlen = getattr(self, self.settings.style + 'len', self.outsetlen)()
hlen = getattr(self, self.settings.style + 'len', self.flushlen)()

if self.layout & 1:
getattr(self, self.settings.style, self.outset)()
if self.layout in (1, 3):
getattr(self, self.settings.style, self.flush)()

self.edge(l - (self.layout & 1) * hlen - bool(self.layout & 2) * hlen,
tabs=2)

if self.layout & 2:
getattr(self, self.settings.style, self.outset)(True)
if self.layout in (2, 3):
getattr(self, self.settings.style, self.flush)(True)


class HingePin(BaseEdge):
Expand Down Expand Up @@ -1457,7 +1455,12 @@ def endwidth(self) -> float:
return self.settings.outset * self.boxes.thickness

def margin(self) -> float:
return self.settings.thickness
if self.settings.outset and (
self.grip_percentage > 0.0 or
self.settings.grip_length > 0.0 ):
return self.settings.thickness + self.boxes.edges['g'].margin()
else:
return self.settings.thickness

def outset(self, _reversed: bool = False) -> None:
t: float = self.settings.thickness
Expand Down Expand Up @@ -1501,8 +1504,11 @@ def outsetlen(self):
def flush(self, _reversed: bool = False) -> None:
t: float = self.settings.thickness
pinl = (self.settings.axle ** 2 - t ** 2) ** 0.5 * self.settings.pinwidth
d = (self.settings.axle - pinl) / 2.0
pin = (self.settings.hingestrength + d, -90.,
d = d1 = (self.settings.axle - pinl) / 2.0
if self.settings.style == "flush_inset":
d1 -= self.settings.thickness

pin = (self.settings.hingestrength + d1, -90.,
t, 90.,
pinl,
90.,
Expand All @@ -1526,14 +1532,16 @@ def flush(self, _reversed: bool = False) -> None:

def flushlen(self):
l = self.settings.hingestrength + self.settings.axle
if self.settings.style == "flush_inset":
l -= self.settings.thickness

if self.settings.outset:
l += self.settings.hingestrength + 0.5 * self.settings.thickness

return l

def __call__(self, l, **kw):
plen = getattr(self, self.settings.style + 'len', self.outsetlen)()
plen = getattr(self, self.settings.style + 'len', self.flushlen)()
glen = l * self.settings.grip_percentage / 100 + \
self.settings.grip_length

Expand All @@ -1542,18 +1550,18 @@ def __call__(self, l, **kw):

glen = min(glen, l - plen)

if self.layout & 1 and self.layout & 2:
getattr(self, self.settings.style, self.outset)()
if self.layout == 3:
getattr(self, self.settings.style, self.flush)()
self.edge(l - 2 * plen, tabs=2)
getattr(self, self.settings.style, self.outset)(True)
elif self.layout & 1:
getattr(self, self.settings.style, self.outset)()
getattr(self, self.settings.style, self.flush)(True)
elif self.layout == 1:
getattr(self, self.settings.style, self.flush)()
self.edge(l - plen - glen, tabs=2)
self.edges['g'](glen)
else:
else: # self.layout == 2
self.edges['g'](glen)
self.edge(l - plen - glen, tabs=2)
getattr(self, self.settings.style, self.outset)(True)
getattr(self, self.settings.style, self.flush)(True)


#############################################################################
Expand Down
9 changes: 7 additions & 2 deletions boxes/generators/typetray.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ def render(self):
tl, tb, tr, tf = self.topEdges(self.top_edge)
self.closedtop = self.top_edge in "fFhŠ"

ignore_widths = [1, 6]
if self.top_edge in "ik":
self.edges[self.top_edge].settings.style = "flush_inset"
ignore_widths = [1, 3, 4, 6]

bh = self.back_height if self.top_edge == "e" else 0.0

self.textcontent = []
Expand Down Expand Up @@ -272,7 +277,7 @@ def render(self):
else:
self.rectangularWall(
x, h, ["f" if self.handle else b, "F", tf, "F"],
callback=frontCBs, ignore_widths=[] if self.handle else [1, 6],
callback=frontCBs, ignore_widths=[] if self.handle else ignore_widths,
move="up", label="front")


Expand Down Expand Up @@ -308,7 +313,7 @@ def render(self):
else:
self.rectangularWall(x, h, [b, "F", tb, "F"],
callback=[self.xHoles],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
move="up", label="back")

# top / lid
Expand Down
16 changes: 12 additions & 4 deletions boxes/generators/ubox.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,25 @@ def Uwall(self, x, y, h, r, edges="ee", move=None, label=""):
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")

if edges[0] in (self.edges["i"], self.edges["k"]):
# hinged lids, mimic ignor_widths
self.edgeCorner("e", e[nr])
e[nr](h + self.edges["F"].startwidth() +
self.edges["F"].endwidth())
self.edgeCorner(e[nr], "e")
else:
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.edges["i"].settings.style = "flush_inset"

_ = self.translations.gettext
t1, t2, t3, t4 = self.topEdges(self.top_edge)

Expand Down
16 changes: 11 additions & 5 deletions boxes/generators/universalbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ def render(self):
self.y = y = self.adjustSize(y)
self.h = h = self.adjustSize(h, b, self.top_edge)

ignore_widths = [1, 6]
if self.top_edge in "ik":
self.edges[self.top_edge].settings.style = "flush_inset"
ignore_widths = [1, 3, 4, 6]

with self.saved_context():
self.rectangularWall(x, h, [b, sideedge, tf, sideedge],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
bedBolts=[d2], move="up", label="front")
self.rectangularWall(x, h, [b, sideedge, tb, sideedge],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
bedBolts=[d2], move="up", label="back")

if self.bottom_edge != "e":
Expand All @@ -90,15 +95,16 @@ def render(self):
self.rectangularWall(x+4*t, y+4*t, callback=[
lambda:self.top_hole(x, y, self.top_edge)], move="up", label="top hole")
self.set_source_color(Color.BLACK)

self.drawLid(x, y, self.top_edge, [d2, d3])
self.lid(x, y, self.top_edge)

self.rectangularWall(x, h, [b, sideedge, tf, sideedge],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
bedBolts=[d2], move="right only", label="invisible")
self.rectangularWall(y, h, [b, "f", tl, "f"],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
bedBolts=[d3], move="up", label="left")
self.rectangularWall(y, h, [b, "f", tr, "f"],
ignore_widths=[1, 6],
ignore_widths=ignore_widths,
bedBolts=[d3], move="up", label="right")

0 comments on commit d4b238c

Please sign in to comment.