From 0d07f48b7f41a2514150bb6af472aef9dd5c61b0 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Fri, 8 Feb 2019 17:43:15 +0100 Subject: [PATCH] Remove .open() call from the .render() method Having this call there was necessary in the past as the open() method would need the canvas size as a parameter. This is now determined automatically after rendering. Still calling open() is deprecated but won't result in an error. --- boxes/__init__.py | 3 +++ boxes/generators/_template.py | 2 -- boxes/generators/alledges.py | 2 -- boxes/generators/angledbox.py | 1 - boxes/generators/angledcutjig.py | 2 -- boxes/generators/arcade.py | 2 -- boxes/generators/bintray.py | 1 - boxes/generators/cardbox.py | 1 - boxes/generators/castle.py | 1 - boxes/generators/closedbox.py | 1 - boxes/generators/concaveknob.py | 2 -- boxes/generators/display.py | 2 -- boxes/generators/displaycase.py | 1 - boxes/generators/displayshelf.py | 2 -- boxes/generators/drillbox.py | 1 - boxes/generators/electronicsbox.py | 1 - boxes/generators/flexbox.py | 1 - boxes/generators/flexbox2.py | 1 - boxes/generators/flexbox3.py | 1 - boxes/generators/flexbox4.py | 1 - boxes/generators/flextest.py | 1 - boxes/generators/flextest2.py | 1 - boxes/generators/folder.py | 1 - boxes/generators/gear.py | 2 -- boxes/generators/gearbox.py | 2 -- boxes/generators/hingebox.py | 1 - boxes/generators/hooks.py | 1 - boxes/generators/integratedhingebox.py | 1 - boxes/generators/jigsaw.py | 2 -- boxes/generators/lamp.py | 1 - boxes/generators/laserclamp.py | 1 - boxes/generators/lbeam.py | 1 - boxes/generators/magazinefile.py | 1 - boxes/generators/nemamount.py | 1 - boxes/generators/openbox.py | 1 - boxes/generators/organpipe.py | 2 -- boxes/generators/ottobody.py | 1 - boxes/generators/ottolegs.py | 2 -- boxes/generators/ottosoles.py | 2 -- boxes/generators/paintbox.py | 2 -- boxes/generators/planetary.py | 2 -- boxes/generators/planetary2.py | 2 -- boxes/generators/polehook.py | 2 -- boxes/generators/pulley.py | 2 -- boxes/generators/rack19box.py | 1 - boxes/generators/rackbox.py | 1 - boxes/generators/rectangularWall.py | 2 -- boxes/generators/regularbox.py | 1 - boxes/generators/robotarm.py | 2 -- boxes/generators/rotary.py | 2 -- boxes/generators/roundedbox.py | 1 - boxes/generators/royalgame.py | 2 -- boxes/generators/shutterbox.py | 2 -- boxes/generators/silverwarebox.py | 1 - boxes/generators/stachel.py | 2 -- boxes/generators/trafficlight.py | 2 -- boxes/generators/trayinsert.py | 1 - boxes/generators/traylayout.py | 1 - boxes/generators/two_piece.py | 2 -- boxes/generators/typetray.py | 1 - boxes/generators/ubox.py | 1 - boxes/generators/unevenheightbox.py | 1 - boxes/generators/universalbox.py | 1 - boxes/generators/waivyknob.py | 2 -- boxes/generators/winerack.py | 1 - scripts/boxes | 1 + scripts/boxes_example.ipynb | 6 +++--- scripts/boxesserver | 1 + 68 files changed, 8 insertions(+), 94 deletions(-) diff --git a/boxes/__init__.py b/boxes/__init__.py index cff030d..46d2cff 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -219,6 +219,7 @@ class Boxes: def __init__(self): self.formats = formats.Formats() + self.ctx = None description = self.__doc__ if self.description: description += "\n\n" + self.description @@ -277,6 +278,8 @@ class Boxes: Call this function from your .render() method """ + if self.ctx is not None: + return self.bedBoltSettings = (3, 5.5, 2, 20, 15) # d, d_nut, h_nut, l, l1 self.hexHolesSettings = (5, 3, 'circle') # r, dist, style diff --git a/boxes/generators/_template.py b/boxes/generators/_template.py index 4688d7f..b3e7625 100644 --- a/boxes/generators/_template.py +++ b/boxes/generators/_template.py @@ -47,8 +47,6 @@ class BOX(Boxes): # Change class name! # adjust to the variables you want in the local scope x, y, h = self.x, self.y, self.h t = self.thickness - # Initialize canvas - self.open() # Create new Edges here if needed E.g.: s = edges.FingerJointSettings(self.thickness, relative=False, diff --git a/boxes/generators/alledges.py b/boxes/generators/alledges.py index 60410d8..8942fd0 100644 --- a/boxes/generators/alledges.py +++ b/boxes/generators/alledges.py @@ -36,8 +36,6 @@ class AllEdges(Boxes): def render(self): x = self.x t = self.thickness - # Initialize canvas - self.open() chars = list(self.edges.keys()) chars.sort(key=lambda c: c.lower() + (c if c.isupper() else '')) diff --git a/boxes/generators/angledbox.py b/boxes/generators/angledbox.py index 9a808ea..e8fd034 100644 --- a/boxes/generators/angledbox.py +++ b/boxes/generators/angledbox.py @@ -72,7 +72,6 @@ class AngledBox(Boxes): self.move(tx, ty, move) def render(self): - self.open() x, y, h, n = self.x, self.y, self.h, self.n diff --git a/boxes/generators/angledcutjig.py b/boxes/generators/angledcutjig.py index 997dd65..1457989 100644 --- a/boxes/generators/angledcutjig.py +++ b/boxes/generators/angledcutjig.py @@ -44,8 +44,6 @@ class AngledCutJig(Boxes): # Change class name! # adjust to the variables you want in the local scope x, y = self.x, self.y t = self.thickness - # Initialize canvas - self.open() th = x * math.tan(math.radians(90-self.angle)) l = (x**2 + th**2)**0.5 diff --git a/boxes/generators/arcade.py b/boxes/generators/arcade.py index be92982..6b2e79a 100644 --- a/boxes/generators/arcade.py +++ b/boxes/generators/arcade.py @@ -76,8 +76,6 @@ class Arcade(Boxes): self.top = 100-t self.topback = 200-0.5*t - # Initialize canvas - self.open() # Floor self.rectangularWall(width, self.bottom, "efff", move="up") # Back diff --git a/boxes/generators/bintray.py b/boxes/generators/bintray.py index 048a1ee..ab912df 100644 --- a/boxes/generators/bintray.py +++ b/boxes/generators/bintray.py @@ -106,7 +106,6 @@ class BinTray(Boxes): hi = self.hi = h t = self.thickness - self.open() self.addPart(BinFrontEdge(self, self)) self.addPart(BinFrontSideEdge(self, self)) diff --git a/boxes/generators/cardbox.py b/boxes/generators/cardbox.py index ceb58d4..c02da93 100644 --- a/boxes/generators/cardbox.py +++ b/boxes/generators/cardbox.py @@ -96,7 +96,6 @@ class CardBox(Boxes): self.fingerHolesAt(0.5*t + (c+t)*i, 0, y, 90) def render(self): - self.open() h = self.h t = self.thickness diff --git a/boxes/generators/castle.py b/boxes/generators/castle.py index 3475987..eabadcc 100644 --- a/boxes/generators/castle.py +++ b/boxes/generators/castle.py @@ -27,7 +27,6 @@ class Castle(Boxes): 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): - self.open() s = edges.FingerJointSettings(10.0, relative=True, space=1, finger=1, width=self.thickness) diff --git a/boxes/generators/closedbox.py b/boxes/generators/closedbox.py index 818835c..397cc45 100644 --- a/boxes/generators/closedbox.py +++ b/boxes/generators/closedbox.py @@ -28,7 +28,6 @@ class ClosedBox(Boxes): self.buildArgParser("x", "y", "h", "outside") def render(self): - self.open() x, y, h = self.x, self.y, self.h diff --git a/boxes/generators/concaveknob.py b/boxes/generators/concaveknob.py index 2c61b50..9e7b0b9 100644 --- a/boxes/generators/concaveknob.py +++ b/boxes/generators/concaveknob.py @@ -49,8 +49,6 @@ class ConcaveKnob(Boxes): def render(self): t = self.thickness - # Initialize canvas - self.open() self.parts.concaveKnob(self.diameter, self.serrations, self.rounded, self.angle, callback=lambda:self.dHole(0, 0, diff --git a/boxes/generators/display.py b/boxes/generators/display.py index 37ef265..afac626 100644 --- a/boxes/generators/display.py +++ b/boxes/generators/display.py @@ -40,8 +40,6 @@ class Display(Boxes): x, h, r = self.x, self.h, self.radius a = self.angle t = self.thickness - # Initialize canvas - self.open() self.roundedPlate(0.7*x, x, r, "e", move="up") diff --git a/boxes/generators/displaycase.py b/boxes/generators/displaycase.py index e29442b..ef7a341 100644 --- a/boxes/generators/displaycase.py +++ b/boxes/generators/displaycase.py @@ -36,7 +36,6 @@ class DisplayCase(Boxes): ) def render(self): - self.open() x, y, h = self.x, self.y, self.h diff --git a/boxes/generators/displayshelf.py b/boxes/generators/displayshelf.py index ec28bdc..6b975d7 100644 --- a/boxes/generators/displayshelf.py +++ b/boxes/generators/displayshelf.py @@ -61,8 +61,6 @@ class DisplayShelf(Boxes): # change class name here and below if self.outside: x = self.adjustSize(x) - # Initialize canvas - self.open() a = math.radians(self.angle) diff --git a/boxes/generators/drillbox.py b/boxes/generators/drillbox.py index 5cf9540..a3ccd6d 100644 --- a/boxes/generators/drillbox.py +++ b/boxes/generators/drillbox.py @@ -54,7 +54,6 @@ in 0.5mm steps, 3 holes each size""" x, y, h = self.x, self.y, self.h t = self.thickness - self.open() self.edges["f"].settings.setValues(self.thickness, space=3, finger=3, surroundingspaces=1) self.rectangularWall(x, h, "FfeF", callback=[self.holesx], move="right") diff --git a/boxes/generators/electronicsbox.py b/boxes/generators/electronicsbox.py index 0c1f91c..b63ce8f 100644 --- a/boxes/generators/electronicsbox.py +++ b/boxes/generators/electronicsbox.py @@ -56,7 +56,6 @@ class ElectronicsBox(Boxes): self.fingerHolesAt(self.y, self.h-1.5*t, self.triangle, 180) def render(self): - self.open() t = self.thickness self.h = h = self.h + 2*t # compensate for lid diff --git a/boxes/generators/flexbox.py b/boxes/generators/flexbox.py index 2d38188..8da4dc6 100644 --- a/boxes/generators/flexbox.py +++ b/boxes/generators/flexbox.py @@ -116,7 +116,6 @@ class FlexBox(boxes.Boxes): r = min(r, x / 2.0) self.radius = r = min(r, max(0, (y - self.latchsize) / 2.0)) - self.open() self.surroundingWall(move="up") self.flexBoxSide(self.x, self.y, self.radius, move="right") diff --git a/boxes/generators/flexbox2.py b/boxes/generators/flexbox2.py index 417113a..c395142 100644 --- a/boxes/generators/flexbox2.py +++ b/boxes/generators/flexbox2.py @@ -105,7 +105,6 @@ class FlexBox2(Boxes): self.radius = min(self.radius, max(0, self.h - self.latchsize)) self.c4 = c4 = math.pi * self.radius * 0.5 - self.open() self.moveTo(2 * self.thickness, self.thickness) diff --git a/boxes/generators/flexbox3.py b/boxes/generators/flexbox3.py index f1e3076..2f919b0 100644 --- a/boxes/generators/flexbox3.py +++ b/boxes/generators/flexbox3.py @@ -146,7 +146,6 @@ class FlexBox3(Boxes): width = 2 * x + y - 2 * r + c4 + 14 * thickness + 3 * h # lock height = y + z + 8 * thickness - self.open() s = edges.FingerJointSettings(self.thickness, finger=1., space=1., surroundingspaces=1) diff --git a/boxes/generators/flexbox4.py b/boxes/generators/flexbox4.py index 3ff5e1c..8652a40 100644 --- a/boxes/generators/flexbox4.py +++ b/boxes/generators/flexbox4.py @@ -110,7 +110,6 @@ class FlexBox4(Boxes): self.radius = min(self.radius, max(0, self.y - self.latchsize)) self.c4 = c4 = math.pi * self.radius * 0.5 - self.open() self.surroundingWall(move="up") self.flexBoxSide(self.x, self.y, self.radius, move="right") diff --git a/boxes/generators/flextest.py b/boxes/generators/flextest.py index 2d1139a..77433f8 100644 --- a/boxes/generators/flextest.py +++ b/boxes/generators/flextest.py @@ -29,7 +29,6 @@ class FlexTest(Boxes): def render(self): x, y = self.x, self.y - self.open() self.moveTo(5, 5) self.edge(10) diff --git a/boxes/generators/flextest2.py b/boxes/generators/flextest2.py index afcfc95..364b7cf 100644 --- a/boxes/generators/flextest2.py +++ b/boxes/generators/flextest2.py @@ -32,7 +32,6 @@ class FlexTest2(Boxes): def render(self): x, y = self.x, self.y - self.open() self.rectangularWall(x, y, callback=[lambda: self.flex2D(x, y, self.fw)]) diff --git a/boxes/generators/folder.py b/boxes/generators/folder.py index 1b80716..8d110a8 100644 --- a/boxes/generators/folder.py +++ b/boxes/generators/folder.py @@ -33,7 +33,6 @@ class Folder(Boxes): def render(self): x, y, r, h = self.x, self.y, self.r, self.h c2 = math.pi * h - self.open() self.moveTo(r + self.thickness, self.thickness) self.edge(x - r) self.edges["X"](c2, y) diff --git a/boxes/generators/gear.py b/boxes/generators/gear.py index da73a70..c74fe83 100644 --- a/boxes/generators/gear.py +++ b/boxes/generators/gear.py @@ -56,8 +56,6 @@ class Gears(Boxes): def render(self): # adjust to the variables you want in the local scope t = self.thickness - # Initialize canvas - self.open() if not self.shaft2: self.shaft2 = self.shaft1 diff --git a/boxes/generators/gearbox.py b/boxes/generators/gearbox.py index 0bc12df..547d686 100644 --- a/boxes/generators/gearbox.py +++ b/boxes/generators/gearbox.py @@ -42,8 +42,6 @@ class GearBox(Boxes): help="number of stages in the gear reduction") def render(self): - # Initialize canvas - self.open() if self.teeth2 < self.teeth1: self.teeth2, self.teeth1 = self.teeth1, self.teeth2 diff --git a/boxes/generators/hingebox.py b/boxes/generators/hingebox.py index bb7831f..45b212c 100644 --- a/boxes/generators/hingebox.py +++ b/boxes/generators/hingebox.py @@ -34,7 +34,6 @@ class HingeBox(Boxes): help="split the lid in y direction (mm)") def render(self): - self.open() x, y, h, hl = self.x, self.y, self.h, self.lidheight s = self.splitlid diff --git a/boxes/generators/hooks.py b/boxes/generators/hooks.py index ef959fb..4d3a8b7 100644 --- a/boxes/generators/hooks.py +++ b/boxes/generators/hooks.py @@ -43,7 +43,6 @@ class Hook(Boxes): help="angle of the support underneeth") def render(self): - self.open() self.angle = min(self.angle, 80) t = self.thickness diff --git a/boxes/generators/integratedhingebox.py b/boxes/generators/integratedhingebox.py index 14e576c..dbc2132 100644 --- a/boxes/generators/integratedhingebox.py +++ b/boxes/generators/integratedhingebox.py @@ -33,7 +33,6 @@ class IntegratedHingeBox(Boxes): def render(self): - self.open() x, y, h, hl = self.x, self.y, self.h, self.lidheight diff --git a/boxes/generators/jigsaw.py b/boxes/generators/jigsaw.py index a237db6..7bcfcd1 100644 --- a/boxes/generators/jigsaw.py +++ b/boxes/generators/jigsaw.py @@ -80,8 +80,6 @@ class JigsawPuzzle(Boxes): # change class name here and below def render(self): size = self.size t = self.thickness - # Initialize canvas - self.open() self.burn = 0.0 self.moveTo(10, 10) self.hilbert(self.depth) diff --git a/boxes/generators/lamp.py b/boxes/generators/lamp.py index f27425d..84b96b7 100644 --- a/boxes/generators/lamp.py +++ b/boxes/generators/lamp.py @@ -90,7 +90,6 @@ class Lamp(Boxes): h : height box """ - self.open() # self.edges["f"].settings = (5, 5) # XXX diff --git a/boxes/generators/laserclamp.py b/boxes/generators/laserclamp.py index 3510b17..be3fcf8 100644 --- a/boxes/generators/laserclamp.py +++ b/boxes/generators/laserclamp.py @@ -85,7 +85,6 @@ parts sliding on each other to reduce friction. def render(self): t = self. thickness h_max, h_min, h_extra = self.maxheight, self.minheight,self.extraheight - self.open() if h_extra and h_extra < 2*t: h_extra = 2*t diff --git a/boxes/generators/lbeam.py b/boxes/generators/lbeam.py index 323ba01..9624163 100644 --- a/boxes/generators/lbeam.py +++ b/boxes/generators/lbeam.py @@ -35,7 +35,6 @@ class LBeam(Boxes): y = self.adjustSize(y, False) - self.open() self.rectangularWall(x, h, "eFee", move="right") self.rectangularWall(y, h, "eeef") diff --git a/boxes/generators/magazinefile.py b/boxes/generators/magazinefile.py index 7629b4e..901fa5f 100644 --- a/boxes/generators/magazinefile.py +++ b/boxes/generators/magazinefile.py @@ -69,7 +69,6 @@ class MagazinFile(Boxes): self.hi = hi = self.hi or (h / 2.0) t = self.thickness - self.open() with self.saved_context(): self.rectangularWall(x, h, "Ffef", move="up") diff --git a/boxes/generators/nemamount.py b/boxes/generators/nemamount.py index cf2b21c..a827e8a 100644 --- a/boxes/generators/nemamount.py +++ b/boxes/generators/nemamount.py @@ -36,7 +36,6 @@ class NemaMount(Boxes): x = y = h = motor + 2*t - self.open() self.rectangularWall(x, y, "ffef", callback=[ lambda: self.NEMA(self.size, x/2, y/2)], move="right") diff --git a/boxes/generators/openbox.py b/boxes/generators/openbox.py index eaeaba1..cb90a22 100644 --- a/boxes/generators/openbox.py +++ b/boxes/generators/openbox.py @@ -35,7 +35,6 @@ class OpenBox(Boxes): y = self.adjustSize(y, False) h = self.adjustSize(h, False) - self.open() d2 = [edges.Bolts(2)] d3 = [edges.Bolts(3)] diff --git a/boxes/generators/organpipe.py b/boxes/generators/organpipe.py index d955b82..30bd82e 100644 --- a/boxes/generators/organpipe.py +++ b/boxes/generators/organpipe.py @@ -126,8 +126,6 @@ class OrganPipe(Boxes): # Change class name! total_length = resonator_length + base_length - # Initialize canvas - self.open() e = ["f", "e", edges.CompoundEdge(self, "fef", (resonator_length - mouth_height - 10*t, mouth_height + 10*t, base_length)), "f"] diff --git a/boxes/generators/ottobody.py b/boxes/generators/ottobody.py index 92c8835..63eb9ba 100644 --- a/boxes/generators/ottobody.py +++ b/boxes/generators/ottobody.py @@ -98,7 +98,6 @@ class OttoBody(Boxes): self.move(w+4, h+8+t, move) def render(self): - self.open() self.x = x = 60. self.y = y = 60. diff --git a/boxes/generators/ottolegs.py b/boxes/generators/ottolegs.py index 38defd0..86e8e5a 100644 --- a/boxes/generators/ottolegs.py +++ b/boxes/generators/ottolegs.py @@ -104,8 +104,6 @@ class OttoLegs(Boxes): def render(self): # adjust to the variables you want in the local scope t = self.thickness - # Initialize canvas - self.open() ws = 25 lx, ly, lh = 12.4, 23.5, max(self.length, ws+6+t) diff --git a/boxes/generators/ottosoles.py b/boxes/generators/ottosoles.py index aad3168..23141a5 100644 --- a/boxes/generators/ottosoles.py +++ b/boxes/generators/ottosoles.py @@ -45,8 +45,6 @@ class OttoSoles(Boxes): w2 = w * 2**0.5 - c2 / 2 d = w * math.tan(math.radians(22.5)) - # Initialize canvas - self.open() self.edges["d"].settings.setValues(w, size=0.4, depth=0.3, radius=0.05) diff --git a/boxes/generators/paintbox.py b/boxes/generators/paintbox.py index b6284e1..ca91b52 100644 --- a/boxes/generators/paintbox.py +++ b/boxes/generators/paintbox.py @@ -68,8 +68,6 @@ class PaintStorage(Boxes): x, y = self.x, self.y t = self.thickness - # Initialize canvas - self.open() stack = self.edges['s'].settings h = self.canheight - stack.height - stack.holedistance + t diff --git a/boxes/generators/planetary.py b/boxes/generators/planetary.py index 739add9..ff0b029 100644 --- a/boxes/generators/planetary.py +++ b/boxes/generators/planetary.py @@ -49,8 +49,6 @@ class Planetary(Boxes): # help="number of stages in the gear reduction") def render(self): - # Initialize canvas - self.open() ringteeth = self.sunteeth + 2 * self.planetteeth spoke_width = 3 * self.shaft diff --git a/boxes/generators/planetary2.py b/boxes/generators/planetary2.py index d3140be..c6dd5a1 100644 --- a/boxes/generators/planetary2.py +++ b/boxes/generators/planetary2.py @@ -77,8 +77,6 @@ class Planetary2(Boxes): def render(self): - # Initialize canvas - self.open() ringteeth = self.sunteeth + 2 * self.planetteeth t = self.thickness diff --git a/boxes/generators/polehook.py b/boxes/generators/polehook.py index da4aac7..27b1f8c 100644 --- a/boxes/generators/polehook.py +++ b/boxes/generators/polehook.py @@ -99,8 +99,6 @@ class PoleHook(Boxes): # change class name here and below # adjust to the variables you want in the local scope d = self.diameter t = self.thickness - # Initialize canvas - self.open() shh = self.screwheadheight self.bedBoltSettings = (self.screw, self.screwhead, shh, d/4+shh, d/4) # d, d_nut, h_nut, l, l diff --git a/boxes/generators/pulley.py b/boxes/generators/pulley.py index 01c1511..2be87c9 100644 --- a/boxes/generators/pulley.py +++ b/boxes/generators/pulley.py @@ -69,8 +69,6 @@ class Pulley(Boxes): def render(self): # adjust to the variables you want in the local scope t = self.thickness - # Initialize canvas - self.open() if self.top: self.disk( diff --git a/boxes/generators/rack19box.py b/boxes/generators/rack19box.py index 1a984f4..97a6e2a 100644 --- a/boxes/generators/rack19box.py +++ b/boxes/generators/rack19box.py @@ -63,7 +63,6 @@ class Rack19Box(Boxes): def _render(self, type): - self.open() t = self.thickness self.h = h = self.height * 44.45 - 0.787 - t diff --git a/boxes/generators/rackbox.py b/boxes/generators/rackbox.py index 00f9330..3d40d15 100644 --- a/boxes/generators/rackbox.py +++ b/boxes/generators/rackbox.py @@ -64,7 +64,6 @@ class RackBox(Boxes): def render(self): - self.open() t = self.thickness self.h = h = self.h + 2*t # compensate for lid diff --git a/boxes/generators/rectangularWall.py b/boxes/generators/rectangularWall.py index f2a7a04..d76c444 100644 --- a/boxes/generators/rectangularWall.py +++ b/boxes/generators/rectangularWall.py @@ -62,8 +62,6 @@ class RectangularWall(Boxes): def render(self): # adjust to the variables you want in the local scope - # Initialize canvas - self.open() t = self.thickness self.edgetypes = [self.bottom_edge, self.right_edge, self.top_edge, self.left_edge] diff --git a/boxes/generators/regularbox.py b/boxes/generators/regularbox.py index 2f14110..559b1ef 100644 --- a/boxes/generators/regularbox.py +++ b/boxes/generators/regularbox.py @@ -38,7 +38,6 @@ class RegularBox(Boxes): help="style of the top and lid") def render(self): - self.open() r, h, n = self.radius, self.h, self.n diff --git a/boxes/generators/robotarm.py b/boxes/generators/robotarm.py index 8df6568..10d0ae0 100644 --- a/boxes/generators/robotarm.py +++ b/boxes/generators/robotarm.py @@ -44,8 +44,6 @@ class RobotArm(Boxes): # change class name here and below help="length of segment axle to axle") def render(self): - # Initialize canvas - self.open() for i in range(5, 0,-1): armtype = getattr(self, "type%i" % i) diff --git a/boxes/generators/rotary.py b/boxes/generators/rotary.py index b1e625c..0816d1d 100644 --- a/boxes/generators/rotary.py +++ b/boxes/generators/rotary.py @@ -189,8 +189,6 @@ class Rotary(Boxes): a = self.a = self.axle bw, bh = self.beamwidth, self.beamheight - # Initialize canvas - self.open() # self.spacing = 0.1 * t # Change settings of default edges if needed. E.g.: diff --git a/boxes/generators/roundedbox.py b/boxes/generators/roundedbox.py index 3d00859..7a77f29 100644 --- a/boxes/generators/roundedbox.py +++ b/boxes/generators/roundedbox.py @@ -58,7 +58,6 @@ class RoundedBox(Boxes): self.corner(90, r) def render(self): - self.open() x, y, h, r = self.x, self.y, self.h, self.radius diff --git a/boxes/generators/royalgame.py b/boxes/generators/royalgame.py index 1181987..f082d26 100644 --- a/boxes/generators/royalgame.py +++ b/boxes/generators/royalgame.py @@ -163,8 +163,6 @@ class RoyalGame(Boxes): # Change class name! self.size = size = x / 8.0 h = size/2 * 3**0.5 y = 3 * size - # Initialize canvas - self.open() self.rectangularWall(x, h, "FLFF", move="right") self.rectangularWall(y, h, "nlmE", callback=[ diff --git a/boxes/generators/shutterbox.py b/boxes/generators/shutterbox.py index d916231..77978ba 100644 --- a/boxes/generators/shutterbox.py +++ b/boxes/generators/shutterbox.py @@ -159,8 +159,6 @@ class ShutterBox(Boxes): self.radius = r = min(r, h/2) t = self.thickness - # Initialize canvas - self.open() self.ctx.save() self.side(x, h, r, style, move="right") self.side(x, h, r, style, move="right") diff --git a/boxes/generators/silverwarebox.py b/boxes/generators/silverwarebox.py index 8e2278d..233d47e 100644 --- a/boxes/generators/silverwarebox.py +++ b/boxes/generators/silverwarebox.py @@ -91,7 +91,6 @@ class Silverware(Boxes): h = self.h r = self.cornerradius - self.open() t = self.thickness b = self.burn diff --git a/boxes/generators/stachel.py b/boxes/generators/stachel.py index 6eb0285..7d9fb2c 100644 --- a/boxes/generators/stachel.py +++ b/boxes/generators/stachel.py @@ -86,8 +86,6 @@ class Stachel(Boxes): def render(self): - # Initialize canvas - self.open() ri = self.flutediameter / 2.0 ro = ri + self.wall diff --git a/boxes/generators/trafficlight.py b/boxes/generators/trafficlight.py index 7592585..2d9e4cf 100644 --- a/boxes/generators/trafficlight.py +++ b/boxes/generators/trafficlight.py @@ -122,8 +122,6 @@ When turned by 90°, it can be also used to create a bottle holder.""" th = n * (h + t) - t - # Initialize canvas - self.open() self.addPart(ShadyEdge(self, None)) diff --git a/boxes/generators/trayinsert.py b/boxes/generators/trayinsert.py index a5ba063..7bd1481 100644 --- a/boxes/generators/trayinsert.py +++ b/boxes/generators/trayinsert.py @@ -37,7 +37,6 @@ class TrayInsert(Boxes): h = self.h t = self.thickness - self.open() # Inner walls for i in range(len(self.sx) - 1): diff --git a/boxes/generators/traylayout.py b/boxes/generators/traylayout.py index e4e0e7e..ebd4c49 100644 --- a/boxes/generators/traylayout.py +++ b/boxes/generators/traylayout.py @@ -151,7 +151,6 @@ class TrayLayout2(TrayLayout): for f in line: hasfloor |= f - self.open() self.edges["s"] = boxes.edges.Slot(self, self.hi / 2.0) self.edges["C"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi) diff --git a/boxes/generators/two_piece.py b/boxes/generators/two_piece.py index 24d71e6..953f55d 100644 --- a/boxes/generators/two_piece.py +++ b/boxes/generators/two_piece.py @@ -44,8 +44,6 @@ class TwoPiece(Boxes): y -= 4*t + 2*p h -= 2 * t - # Initialize canvas - self.open() # Adjust h edge with play self.edges["f"].settings.setValues(t, False, edge_width=self.edges["f"].settings.edge_width + p) diff --git a/boxes/generators/typetray.py b/boxes/generators/typetray.py index f256235..212e014 100644 --- a/boxes/generators/typetray.py +++ b/boxes/generators/typetray.py @@ -88,7 +88,6 @@ class TypeTray(_TopEdge): hi = self.hi = self.hi or h t = self.thickness - self.open() # outer walls b = self.bottom_edge diff --git a/boxes/generators/ubox.py b/boxes/generators/ubox.py index 6aaf767..77dbebc 100644 --- a/boxes/generators/ubox.py +++ b/boxes/generators/ubox.py @@ -93,7 +93,6 @@ class UBox(_TopEdge, _ChestLid): self.radius = r = min(r, x/2.0, y) - self.open() t1, t2, t3, t4 = self.topEdges(self.top_edge) diff --git a/boxes/generators/unevenheightbox.py b/boxes/generators/unevenheightbox.py index 3196ba6..53db80f 100644 --- a/boxes/generators/unevenheightbox.py +++ b/boxes/generators/unevenheightbox.py @@ -69,7 +69,6 @@ class UnevenHeightBox(Boxes): def render(self): - self.open() x, y = self.x, self.y heights = [self.height0, self.height1, self.height2, self.height3] diff --git a/boxes/generators/universalbox.py b/boxes/generators/universalbox.py index a772f0c..4fa21d8 100644 --- a/boxes/generators/universalbox.py +++ b/boxes/generators/universalbox.py @@ -56,7 +56,6 @@ class UniversalBox(_TopEdge, _ChestLid): x, y, h = self.x, self.y, self.h t = self.thickness - self.open() t1, t2, t3, t4 = self.topEdges(self.top_edge) b = self.edges.get(self.bottom_edge, self.edges["F"]) diff --git a/boxes/generators/waivyknob.py b/boxes/generators/waivyknob.py index 1b185ce..aa101b6 100644 --- a/boxes/generators/waivyknob.py +++ b/boxes/generators/waivyknob.py @@ -46,8 +46,6 @@ class WaivyKnob(Boxes): def render(self): t = self.thickness - # Initialize canvas - self.open() angle = self.serrationangle self.parts.waivyKnob(self.diameter, self.serrations, angle, callback=lambda:self.dHole(0, 0, d=self.bolthole, diff --git a/boxes/generators/winerack.py b/boxes/generators/winerack.py index e7d2c73..7ac5bb4 100644 --- a/boxes/generators/winerack.py +++ b/boxes/generators/winerack.py @@ -110,7 +110,6 @@ class WineRack(Boxes): self.cy = cy = int((y-dy-t) // (r+dy)) self.delta = 3**0.5/6.*t - self.open() 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") diff --git a/scripts/boxes b/scripts/boxes index 63dfd04..473f72c 100755 --- a/scripts/boxes +++ b/scripts/boxes @@ -68,6 +68,7 @@ def run_generator(name, args): if lower_name in generators.keys(): box = generators[lower_name]() box.parseArgs(args) + box.open() box.render() box.close() else: diff --git a/scripts/boxes_example.ipynb b/scripts/boxes_example.ipynb index 1c7389d..339fcbf 100644 --- a/scripts/boxes_example.ipynb +++ b/scripts/boxes_example.ipynb @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": { "scrolled": true }, @@ -36,7 +36,7 @@ "data": { "image/svg+xml": [ "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -96,7 +96,6 @@ " def render(self):\n", " x, y, h = self.x, self.y, self.h\n", " t = self.thickness\n", - " self.open()\n", " \n", " # render-magic goes here\n", " \n", @@ -113,6 +112,7 @@ "b = Example()\n", "fd, fn = tempfile.mkstemp()\n", "b.parseArgs(['--reference=0', '--debug=0', '--output=' + fn])\n", + "b.open()\n", "b.render()\n", "b.close()\n", "\n", diff --git a/scripts/boxesserver b/scripts/boxesserver index 914650a..e5a61fd 100755 --- a/scripts/boxesserver +++ b/scripts/boxesserver @@ -395,6 +395,7 @@ Create boxes and more with a laser cutter! box.format, [('Content-type', 'application/unknown; charset=utf-8')])) fd, box.output = tempfile.mkstemp() + box.open() box.render() box.close() result = open(box.output).readlines()