diff --git a/boxes/__init__.py b/boxes/__init__.py index 6b3ba93..46a716c 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -1689,6 +1689,42 @@ class Boxes: self.move(overallwidth, overallheight, move) + def surroundingWallPiece(self, cbnr, x, y, r, pieces=1): + """ + Return the geometry of a pices of surroundingWall with the given + callback number. + :param cbnr: number of the callback corresponding to + this part of the wall + :param x: width of matching roundedPlate + :param y: height of matching roundedPlate + :param r: corner radius of matching roundedPlate + :param pieces: (Default value = 1) number of separate pieces + :return: (left, length, right) left and right are Booleans that are + True if the start or end of the wall is on that side. + """ + if pieces<=2 and (y - 2 * r) < 1E-3: + # remove zero length y sides + sides = (x/2-r, x - 2*r, x - 2*r) + if pieces > 0: # hack to get the right splits + pieces += 1 + else: + sides = (x/2-r, y - 2*r, x - 2*r, y - 2*r, x - 2*r) + + wallcount = 0 + for nr, l in enumerate(sides): + if self._splitWall(pieces, nr) and nr > 0: + if wallcount == cbnr: + return (False, l/2, True) + wallcount += 1 + if wallcount == cbnr: + return (True, l/2, False) + wallcount += 1 + else: + if wallcount == cbnr: + return (False, l, False) + wallcount += 1 + return (False, 0.0, False) + def surroundingWall(self, x, y, r, h, bottom='e', top='e', left="D", right="d", diff --git a/boxes/generators/roundedbox.py b/boxes/generators/roundedbox.py index 374ca1f..92ff96c 100644 --- a/boxes/generators/roundedbox.py +++ b/boxes/generators/roundedbox.py @@ -36,7 +36,7 @@ With lid: boxes.Boxes.__init__(self) self.addSettingsArgs(boxes.edges.FingerJointSettings) self.addSettingsArgs(boxes.edges.FlexSettings) - self.buildArgParser("x", "y", "h", "outside") + self.buildArgParser("x", "y", "outside", sh="100.0") self.argparser.add_argument( "--radius", action="store", type=float, default=15, help="Radius of the corners in mm") @@ -77,19 +77,28 @@ With lid: self.edge(l); self.corner(90, r) + def cb(self, nr): + h = 0.5 * self.thickness + + left, l, right = self.surroundingWallPiece(nr, self.x, self.y, self.radius, self.wallpieces) + for dh in self.sh[:-1]: + h += dh + self.fingerHolesAt(0, h, l, 0) + def render(self): - x, y, h, r = self.x, self.y, self.h, self.radius + x, y, sh, r = self.x, self.y, self.sh, self.radius if self.outside: self.x = x = self.adjustSize(x) self.y = y = self.adjustSize(y) - self.h = h = self.adjustSize(h) + self.sh = sh = self.adjustSize(sh) r = self.radius = min(r, y / 2.0) t = self.thickness + h = sum(sh) + t * (len(sh) - 1) es = self.edge_style corner_holes = True @@ -107,6 +116,9 @@ With lid: with self.saved_context(): self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces, extend_corners=ec, move="right") + for dh in self.sh[:-1]: + self.roundedPlate(x, y, r, "f", wallpieces=self.wallpieces, + extend_corners=False, move="right") self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces, extend_corners=ec, move="right", callback=[self.hole] if self.top != "closed" else None) @@ -120,6 +132,7 @@ With lid: self.roundedPlate(x, y, r, es, wallpieces=self.wallpieces, move="up only") - self.surroundingWall(x, y, r, h, pe, pe, pieces=self.wallpieces) + self.surroundingWall(x, y, r, h, pe, pe, pieces=self.wallpieces, + callback=self.cb)