From c0eca5ea5f0add085578bec66c261b8123cc99cf Mon Sep 17 00:00:00 2001 From: jens persson Date: Sun, 27 Jun 2021 12:52:31 +0200 Subject: [PATCH] Add labels to boxes Added labels to AngledBox, BasedBox, ClosedBox, Console2, DinRailBox, DisplayCase and ElectronicsBox --- boxes/generators/angledbox.py | 33 ++++++++++++++----------- boxes/generators/basedbox.py | 12 ++++----- boxes/generators/closedbox.py | 12 ++++----- boxes/generators/console2.py | 39 +++++++++++++++--------------- boxes/generators/dinrailbox.py | 20 +++++++++------ boxes/generators/displaycase.py | 12 ++++----- boxes/generators/electronicsbox.py | 18 ++++++++------ 7 files changed, 79 insertions(+), 67 deletions(-) diff --git a/boxes/generators/angledbox.py b/boxes/generators/angledbox.py index d46cd6c..2283f22 100644 --- a/boxes/generators/angledbox.py +++ b/boxes/generators/angledbox.py @@ -35,7 +35,7 @@ class AngledBox(Boxes): choices=["none", "angled hole", "angled lid", "angled lid2"], help="style of the top and lid") - def floor(self, x, y, n, edge='e', hole=None, move=None, callback=None): + def floor(self, x, y, n, edge='e', hole=None, move=None, callback=None, label=""): r, h, side = self.regularPolygon(2*n+2, h=y/2.0) t = self.thickness @@ -70,7 +70,7 @@ class AngledBox(Boxes): edge(l) self.edgeCorner(edge, edge, 360.0/(2*n + 2)) - self.move(tx, ty, move) + self.move(tx, ty, move, label=label) def render(self): @@ -108,36 +108,41 @@ class AngledBox(Boxes): with self.saved_context(): if b != "e": - self.floor(x, y , n, edge='f', move="right") + self.floor(x, y , n, edge='f', move="right", label="Bottom") if self.top == "angled lid": - self.floor(x, y, n, edge='e', move="right") - self.floor(x, y, n, edge='E', move="right") + self.floor(x, y, n, edge='e', move="right", label="Lower Lid") + self.floor(x, y, n, edge='E', move="right", label="Upper Lid") elif self.top in ("angled hole", "angled lid2"): - self.floor(x, y, n, edge='F', move="right", hole=True) + self.floor(x, y, n, edge='F', move="right", hole=True, label="Top Rim and Lid") if self.top == "angled lid2": - self.floor(x, y, n, edge='E', move="right") + self.floor(x, y, n, edge='E', move="right", label="Upper Lid") self.floor(x, y , n, edge='F', move="up only") fingers = self.top in ("angled lid2", "angled hole") self.rectangularWall(lx, h, move="right", - edges=b+"GfG" if fingers else b+"GeG") + edges=b+"GfG" if fingers else b+"GeG", + label="wall {}".format(1)) - for i in range(2): + for j in range(2): for i in range(n): if i % 2: self.rectangularWall(side, h, move="right", - edges=b+"GfG" if fingers else b+"GeG") + edges=b+"GfG" if fingers else b+"GeG", + label="wall {}".format(i+2+j*(n+1))) else: self.rectangularWall(side, h, move="right", - edges=b+"gfg" if fingers else b+"geg") + edges=b+"gfg" if fingers else b+"geg", + label="wall {}".format(i+2+j*(n+1))) - if i % 2: + if n % 2: self.rectangularWall(lx, h, move="right", - edges=b+"gfg" if fingers else b+"geg") + edges=b+"GfG" if fingers else b+"GeG", + label="wall {}".format(n+2)) else: self.rectangularWall(lx, h, move="right", - edges=b+"GfG" if fingers else b+"GeG") + edges=b+"gfg" if fingers else b+"geg", + label="wall {}".format(n+2)) diff --git a/boxes/generators/basedbox.py b/boxes/generators/basedbox.py index 12146a2..32baf1e 100644 --- a/boxes/generators/basedbox.py +++ b/boxes/generators/basedbox.py @@ -46,13 +46,13 @@ See ClosedBox for variant without a base. t = self.thickness - self.rectangularWall(x, h, "fFFF", move="right") - self.rectangularWall(y, h, "ffFf", move="up") - self.rectangularWall(y, h, "ffFf") - self.rectangularWall(x, h, "fFFF", move="left up") + 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") - self.rectangularWall(x, y, "hhhh") + self.rectangularWall(x, y, "ffff", move="right", label="Top") + self.rectangularWall(x, y, "hhhh", label="Base") diff --git a/boxes/generators/closedbox.py b/boxes/generators/closedbox.py index 5d63b13..4dced41 100644 --- a/boxes/generators/closedbox.py +++ b/boxes/generators/closedbox.py @@ -49,13 +49,13 @@ See BasedBox for variant with a base.""" d2 = d3 = None - self.rectangularWall(x, h, "FFFF", bedBolts=[d2] * 4, move="right") - self.rectangularWall(y, h, "FfFf", bedBolts=[d3, d2, d3, d2], move="up") - self.rectangularWall(y, h, "FfFf", bedBolts=[d3, d2, d3, d2]) - self.rectangularWall(x, h, "FFFF", bedBolts=[d2] *4, move="left up") + 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") - self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3]) + self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right", label="Top") + self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], label="Bottom") diff --git a/boxes/generators/console2.py b/boxes/generators/console2.py index cf57b08..772e2d8 100644 --- a/boxes/generators/console2.py +++ b/boxes/generators/console2.py @@ -190,7 +190,7 @@ To remove the panel you have to press in the four tabs at the side. It is easies self.move(tw, th, move) - def side(self, borders, bottom="s", move=None): + def side(self, borders, bottom="s", move=None, label=""): t = self.thickness bottom = self.edges.get(bottom, bottom) @@ -230,7 +230,7 @@ To remove the panel you have to press in the four tabs at the side. It is easies self.edges["f"](borders[-2]+bottom.startwidth()) self.corner(borders[-1]) - self.move(tw, th, move) + self.move(tw, th, move, label=label) def render(self): x, y, h = self.x, self.y, self.h @@ -248,42 +248,41 @@ To remove the panel you have to press in the four tabs at the side. It is easies self.latchpos = latchpos = 6*t borders = self.borders() - self.side(borders, bottom, move="right") - self.side(borders, bottom, move="right") + 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") # floor - self.rectangularWall( #front + 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") + move="right", label="Front") - # panel if self.glued_panel: - self.rectangularWall(borders[4], x, "EEEE", move="right") + self.rectangularWall(borders[4], x, "EEEE", move="right", label="Panel") elif self.removable_panel: - self.rectangularWall(borders[4], x-2*t, "hEhE", move="right") + self.rectangularWall(borders[4], x-2*t, "hEhE", move="right", label="Panel") else: - self.rectangularWall(borders[4], x, "FEFE", move="right") + self.rectangularWall(borders[4], x, "FEFE", move="right", label="Panel") - if len(borders) == 10: # top - self.rectangularWall(borders[6]-d2, x, "FEFe", move="right") + if len(borders) == 10: + self.rectangularWall(borders[6]-d2, x, "FEFe", move="right", label="Top") if self.removable_backwall: - self.rectangularWall( # back wall + 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") - self.rectangularWall(2*t, borders[-2]-4.05*t-latchpos, "EeEf", move="right") - self.rectangularWall(2*t, borders[-2]-4.05*t-latchpos, "EeEf", move="right") - # backwall bottom + 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") + 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") + ignore_widths=[0, 3], move="right", label="Back Wall") # hardware for panel if self.removable_panel: diff --git a/boxes/generators/dinrailbox.py b/boxes/generators/dinrailbox.py index 90348d4..71cd8d0 100644 --- a/boxes/generators/dinrailbox.py +++ b/boxes/generators/dinrailbox.py @@ -110,34 +110,38 @@ class DinRailBox(Boxes): o = self.rail_offset t = self.thickness - # lid 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") + move="right", label="Front") self.lid_lip(y-.1*t, move="rotated right") self.lid_lip(y-.1*t, move="rotated right") - # floor + self.rectangularWall(x, y, "ffff", callback=[ - lambda:self.fingerHolesAt(0, (y-w)/2-0.5*t+o-9, x, 0)],move="right") + 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") + ignore_widths=[1, 6], move="rotated right", + label="Left Side") self.rectangularWall(y, h, [dr, "F", "e", "F"], - ignore_widths=[1, 6], move="rotated mirror right") + ignore_widths=[1, 6], move="rotated mirror right", + label="Right Side") self.rectangularWall(x, h, ["h", "f", "e", "f"], callback=[None, None, self.lid_holes], - ignore_widths=[1, 6], move="up") + ignore_widths=[1, 6], move="up", + label="Bottom") self.rectangularWall(x, h, ["h", "f", "e", "f"], ignore_widths=[1, 6], callback=[ self.spring, None, self.lid_holes], - move="up") + move="up", + label="Top") self.rectangularWall(x, 8, "feee", callback=[ diff --git a/boxes/generators/displaycase.py b/boxes/generators/displaycase.py index ef7a341..d185dd6 100644 --- a/boxes/generators/displaycase.py +++ b/boxes/generators/displaycase.py @@ -51,11 +51,11 @@ class DisplayCase(Boxes): d2 = d3 = None - self.rectangularWall(x, h, "ffff", bedBolts=[d2] * 4, move="right") - self.rectangularWall(y, h, "fFfF", bedBolts=[d3, d2, d3, d2], move="up") - self.rectangularWall(y, h, "fFfF", bedBolts=[d3, d2, d3, d2]) - self.rectangularWall(x, h, "ffff", bedBolts=[d2] * 4, move="left up") + 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") - self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4) + self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4, move="right", label="Top") + self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4, label="Bottom") diff --git a/boxes/generators/electronicsbox.py b/boxes/generators/electronicsbox.py index 08320af..87e8862 100644 --- a/boxes/generators/electronicsbox.py +++ b/boxes/generators/electronicsbox.py @@ -71,22 +71,26 @@ class ElectronicsBox(Boxes): self.h = h = h - 3*t self.rectangularWall(x, h, "fFeF", callback=[self.wallxCB], - move="right") - self.rectangularWall(y, h, "ffef", callback=[self.wallyCB], move="up") - self.rectangularWall(y, h, "ffef", callback=[self.wallyCB]) + 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") + 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") + 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') + 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') + 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)])