Use .saved_context() instead of .ctx.save() and .restore()

This commit is contained in:
Florian Festi 2019-01-12 23:16:11 +01:00
parent 1724f67bdf
commit 2ba6fa1bf3
20 changed files with 202 additions and 231 deletions

View File

@ -45,10 +45,9 @@ class AllEdges(Boxes):
for c in chars:
self.moveTo(0, 15*t)
self.ctx.save()
self.moveTo(x, 0, 180)
self.edges[c](x, h=4*t)
self.ctx.restore()
with self.saved_context():
self.moveTo(x, 0, 180)
self.edges[c](x, h=4*t)
self.text("%s - %s" % (c, self.edges[c].description), y=5*t)
self.close()

View File

@ -54,16 +54,15 @@ class AngledBox(Boxes):
self.moveTo((tx-lx)/2., 0)
if hole:
self.ctx.save()
hr, hh, hside = self.regularPolygon(2*n+2, h=y/2.0-t)
dx = side - hside
hlx = lx - dx
with self.saved_context():
hr, hh, hside = self.regularPolygon(2*n+2, h=y/2.0-t)
dx = side - hside
hlx = lx - dx
self.moveTo(dx/2.0, t+edge.spacing())
for i, l in enumerate(([hlx] + ([hside] * n))* 2):
self.edge(l)
self.corner(360.0/(2*n + 2))
self.ctx.restore()
self.moveTo(dx/2.0, t+edge.spacing())
for i, l in enumerate(([hlx] + ([hside] * n))* 2):
self.edge(l)
self.corner(360.0/(2*n + 2))
for i, l in enumerate(([lx] + ([side] * n))* 2):
self.cc(callback, i, 0, edge.startwidth() + self.burn)
@ -105,16 +104,15 @@ class AngledBox(Boxes):
edges.FingerJointSettings(self.thickness, True, angle=360./(2 * (n+1))).edgeObjects(self, chars="gGH")
self.ctx.save()
self.floor(x, y , n, edge='F', move="right")
if self.top == "angled lid":
self.floor(x, y, n, edge='e', move="right")
self.floor(x, y, n, edge='E', move="right")
elif self.top in ("angled hole", "angled lid2"):
self.floor(x, y, n, edge='F', move="right", hole=True)
if self.top == "angled lid2":
with self.saved_context():
self.floor(x, y , n, edge='F', move="right")
if self.top == "angled lid":
self.floor(x, y, n, edge='e', move="right")
self.floor(x, y, n, edge='E', move="right")
self.ctx.restore()
elif self.top in ("angled hole", "angled lid2"):
self.floor(x, y, n, edge='F', move="right", hole=True)
if self.top == "angled lid2":
self.floor(x, y, n, edge='E', move="right")
self.floor(x, y , n, edge='F', move="up only")
fingers = self.top in ("angled lid2", "angled hole")

View File

@ -113,28 +113,25 @@ class CardBox(Boxes):
p.char = "A"
self.addPart(p)
self.ctx.save()
with self.saved_context():
# Lid
self.rectangularWall(x-t*.2, y, "Feee", move="right")
# Bottom
self.rectangularWall(x, y, "ffff", callback=[self.divider_bottom],
move="right")
# Lid
self.rectangularWall(x-t*.2, y, "Feee", move="right")
# Bottom
self.rectangularWall(x, y, "ffff", callback=[self.divider_bottom],
move="right")
self.ctx.restore()
self.rectangularWall(x, y, "EEEE", move="up only")
self.ctx.save()
# Back
self.rectangularWall(x, h, "FFEF",
callback=[self.divider_back_and_front],
move="right")
# Front
self.rectangularWall(x, h, "FFaF",
callback=[self.divider_back_and_front],
move="right")
with self.saved_context():
# Back
self.rectangularWall(x, h, "FFEF",
callback=[self.divider_back_and_front],
move="right")
# Front
self.rectangularWall(x, h, "FFaF",
callback=[self.divider_back_and_front],
move="right")
self.ctx.restore()
self.rectangularWall(x, h, "EEEE", move="up only")
#lip of the lid

View File

@ -108,11 +108,11 @@ class FlexBox2(Boxes):
self.open()
self.moveTo(2 * self.thickness, self.thickness)
self.ctx.save()
self.surroundingWall(move="right")
self.rectangularWall(self.y, self.x, edges="FFFF")
self.ctx.restore()
with self.saved_context():
self.surroundingWall(move="right")
self.rectangularWall(self.y, self.x, edges="FFFF")
self.surroundingWall(move="up only")
self.flexBoxSide(self.y, self.h, self.radius, move="right")

View File

@ -152,13 +152,12 @@ class FlexBox3(Boxes):
space=1., surroundingspaces=1)
s.edgeObjects(self, "gGH")
self.ctx.save()
self.surroundingWall(move="right")
self.rectangularWall(x, z, edges="FFFF", move="right")
self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right")
self.lidSide(move="right")
self.lidSide(move="mirror right")
self.ctx.restore()
with self.saved_context():
self.surroundingWall(move="right")
self.rectangularWall(x, z, edges="FFFF", move="right")
self.rectangularWall(h, z + 2 * (d + self.thickness), edges="GeGF", move="right")
self.lidSide(move="right")
self.lidSide(move="mirror right")
self.surroundingWall(move="up only")

View File

@ -73,10 +73,9 @@ class JigsawPuzzle(Boxes): # change class name here and below
self.corner(parity * 90)
# if level == 3 and parity>0: # and random.random() < 100*0.5**(self.depth-2):
# self.corner(-360, 0.4*self.size/2**self.depth)
# self.ctx.save()
# self.corner(parity*-90)
# self.edge(self.size/2**self.depth)
# self.ctx.restore()
# with self.savedcontext():
# self.corner(parity*-90)
# self.edge(self.size/2**self.depth)
def render(self):
size = self.size

View File

@ -64,6 +64,13 @@ class Lamp(Boxes):
def __init__(self):
Boxes.__init__(self)
self.addSettingsArgs(edges.FingerJointSettings)
self.buildArgParser(x=220, y=75, h=70)
self.argparser.add_argument(
"--radius", action="store", type=float, default="105",
help="radius of the lamp")
self.argparser.add_argument(
"--width", action="store", type=float, default="10",
help="width of the ring")
def side(self, y, h):
return
@ -74,7 +81,7 @@ class Lamp(Boxes):
self.edges["f"](h)
self.corner(90)
def render(self, r, w, x, y, h):
def render(self):
"""
r : radius of lamp
w : width of surrounding ring
@ -87,6 +94,9 @@ class Lamp(Boxes):
# self.edges["f"].settings = (5, 5) # XXX
x, y, h = self.x, self.y, self.h
r, w = self.radius, self.width
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
self.addPart(RoundedTriangle(self, s))
@ -108,13 +118,13 @@ class Lamp(Boxes):
self.surroundingWall(d, d, r, 120, top='h', bottom='h', callback=[
None, hole, None, hole], move="up")
self.ctx.save()
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
# sides
self.rectangularWall(y, h, "fftf", move="right")
self.rectangularWall(y, h, "fftf")
self.ctx.restore()
with self.saved_context():
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
# sides
self.rectangularWall(y, h, "fftf", move="right")
self.rectangularWall(y, h, "fftf")
self.rectangularWall(x, y, edges="fFfF", holesMargin=5,
move="up only")

View File

@ -71,12 +71,10 @@ class MagazinFile(Boxes):
self.open()
self.ctx.save()
self.rectangularWall(x, h, "Ffef", move="up")
self.rectangularWall(x, hi, "Ffef", move="up")
self.rectangularWall(y, x, "ffff")
self.ctx.restore()
with self.saved_context():
self.rectangularWall(x, h, "Ffef", move="up")
self.rectangularWall(x, hi, "Ffef", move="up")
self.rectangularWall(x, y, "ffff")
self.rectangularWall(x, h, "Ffef", move="right only")
self.side(y, h, hi)

View File

@ -138,12 +138,11 @@ class OttoBody(Boxes):
# bottom
self.rectangularWall(x, y, "ffff", callback=[self.bottomCB], move="up")
# PCB mounts
self.ctx.save()
self.PCB_Clamp(y-53.5, 4.5, hl, move="right")
self.PCB_Clamp(y-50, 4.5, hl, move="right")
self.PCB_Clip(3.5, hl, move="right")
self.rectangularWall(15, 15, callback=[self.buttonCB])
self.ctx.restore()
with self.saved_context():
self.PCB_Clamp(y-53.5, 4.5, hl, move="right")
self.PCB_Clamp(y-50, 4.5, hl, move="right")
self.PCB_Clip(3.5, hl, move="right")
self.rectangularWall(15, 15, callback=[self.buttonCB])
self.PCB_Clamp(y-53.5, 4.5, hl, move="up only")
# servo mounts
self.moveTo(0, 50)

View File

@ -187,22 +187,21 @@ class Planetary2(Boxes):
# Planets
for i in range(numplanets):
self.ctx.save()
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
for j in range(2):
with self.saved_context():
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i,
secondary_offsets[i]),
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
self.ctx.restore()
for j in range(2):
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i,
secondary_offsets[i]),
profile_shift=profile_shift, move="right")
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
callback=lambda:self.pins(0.25*size2, pinsize, i),
profile_shift=profile_shift, move="right")
self.gears(teeth=self.planetteeth, dimension=self.modulus,
angle=pressure_angle,
@ -210,13 +209,3 @@ class Planetary2(Boxes):
self.text("1:%.1f" % abs(ratio))
self.close()
def main():
b = Planetary()
b.parseArgs()
b.render()
if __name__ == '__main__':
main()

View File

@ -56,7 +56,6 @@ class Pulley(Boxes):
if self.move(w, w, move, before=True):
return
self.ctx.save()
self.moveTo(w / 2, w / 2)
self.cc(callback, None, 0.0, 0.0)
@ -65,7 +64,6 @@ class Pulley(Boxes):
self.moveTo(diameter / 2 + self.burn, 0, 90)
self.corner(360, diameter / 2)
self.ctx.restore()
self.move(w, w, move)
def render(self):

View File

@ -59,24 +59,23 @@ class RegularBox(Boxes):
r, sh, side = self.regularPolygon(n, radius=r)
self.ctx.save()
self.regularPolygonWall(corners=n, r=r, edges='F', move="right")
if self.top == "angled lid":
self.regularPolygonWall(corners=n, r=r, edges='e', move="right")
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
elif self.top in ("angled hole", "angled lid2"):
self.regularPolygonWall(corners=n, r=r, edges='F', move="right",
callback=[lambda:self.regularPolygonAt(
0, 0, n, h=sh-t)])
if self.top == "angled lid2":
with self.saved_context():
self.regularPolygonWall(corners=n, r=r, edges='F', move="right")
if self.top == "angled lid":
self.regularPolygonWall(corners=n, r=r, edges='e', move="right")
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
elif self.top in ("hole", "round lid"):
self.regularPolygonWall(corners=n, r=r, edges='F', move="right",
hole=(sh-t)*2)
if self.top == "round lid":
self.parts.disc(sh*2, move="right")
elif self.top in ("angled hole", "angled lid2"):
self.regularPolygonWall(corners=n, r=r, edges='F', move="right",
callback=[lambda:self.regularPolygonAt(
0, 0, n, h=sh-t)])
if self.top == "angled lid2":
self.regularPolygonWall(corners=n, r=r, edges='E', move="right")
elif self.top in ("hole", "round lid"):
self.regularPolygonWall(corners=n, r=r, edges='F', move="right",
hole=(sh-t)*2)
if self.top == "round lid":
self.parts.disc(sh*2, move="right")
self.ctx.restore()
self.regularPolygonWall(corners=n, r=r, edges='F', move="up only")
side = 2 * math.sin(math.radians(180.0/n)) * r

View File

@ -211,19 +211,19 @@ class Rotary(Boxes):
60, t + 2)], move="up")
self.rectangularWall(hl, hh, edges="hfef", callback=[self.holderBaseCB], move="up")
self.rectangularWall(hl, hw, edges="ffff", callback=[lambda: self.hole(hl / 2 - 16 - 20, 25, 5)], move="up")
self.ctx.save()
self.rectangularWall(hw, hh, edges="hFeF", callback=[
lambda: self.hole(hw / 2, hh - 20, 4)],move="right")
self.rectangularWall(hw, hh, edges="hFeF", move="right")
# Top
th = self.th = 30
# sides
self.rectangularWall(hw + 20, th, edges="fFeF", move="right",
callback=[lambda: self.fingerHolesAt(20 - 0.5 * t, 0, th)])
self.rectangularWall(hw + 20, th, edges="fFeF", move="right",
callback=[lambda: self.fingerHolesAt(20 - 0.5 * t, 0, th)])
self.ctx.restore()
with self.saved_context():
self.rectangularWall(hw, hh, edges="hFeF", callback=[
lambda: self.hole(hw / 2, hh - 20, 4)],move="right")
self.rectangularWall(hw, hh, edges="hFeF", move="right")
# Top
th = self.th = 30
# sides
self.rectangularWall(hw + 20, th, edges="fFeF", move="right",
callback=[lambda: self.fingerHolesAt(20 - 0.5 * t, 0, th)])
self.rectangularWall(hw + 20, th, edges="fFeF", move="right",
callback=[lambda: self.fingerHolesAt(20 - 0.5 * t, 0, th)])
self.rectangularWall(hw, hh, edges="hFeF", move="up only")
outset = OutsetEdge(self, None)
@ -251,32 +251,31 @@ class Rotary(Boxes):
self.link(hl - 40, 25, a, True, move="up")
self.link(hl - 40, 25, a, True, move="up")
self.ctx.save()
self.rectangularWall(hw - 2 * t - 2, 60, edges="efef", move="right")
self.rectangularWall(hw - 4 * t - 4, 60, edges="efef", move="right")
# Spindel auxiliaries
self.parts.waivyKnob(50, callback=lambda: self.nutHole("M8"), move="right")
self.parts.waivyKnob(50, callback=lambda: self.nutHole("M8"), move="right")
self.ctx.restore()
with self.saved_context():
self.rectangularWall(hw - 2 * t - 2, 60, edges="efef", move="right")
self.rectangularWall(hw - 4 * t - 4, 60, edges="efef", move="right")
# Spindel auxiliaries
self.parts.waivyKnob(50, callback=lambda: self.nutHole("M8"), move="right")
self.parts.waivyKnob(50, callback=lambda: self.nutHole("M8"), move="right")
self.rectangularWall(hw - 2 * t - 4, 60, edges="efef", move="up only")
self.ctx.save()
slot = edges.SlottedEdge(self, [(30 - t) / 2, (30 - t) / 2], slots=15)
self.rectangularWall(30, 30, edges=["e", "e", slot, "e"],
callback=[lambda: self.hole(7, 23, self.axle / 2)], move="right")
self.rectangularWall(30, 30, edges=["e", "e", slot, "e"],
callback=[lambda: self.hole(7, 23, self.axle / 2)], move="right")
leftover = (hw - 6 * t - 6 - 20) / 2.0
slot = edges.SlottedEdge(self, [leftover, 20, leftover], slots=15)
self.rectangularWall(hw - 4 * t - 6, 30, edges=[slot, "e", "e", "e"],
with self.saved_context():
slot = edges.SlottedEdge(self, [(30 - t) / 2, (30 - t) / 2], slots=15)
self.rectangularWall(30, 30, edges=["e", "e", slot, "e"],
callback=[lambda: self.hole(7, 23, self.axle / 2)], move="right")
self.rectangularWall(30, 30, edges=["e", "e", slot, "e"],
callback=[lambda: self.hole(7, 23, self.axle / 2)], move="right")
leftover = (hw - 6 * t - 6 - 20) / 2.0
slot = edges.SlottedEdge(self, [leftover, 20, leftover], slots=15)
self.rectangularWall(hw - 4 * t - 6, 30, edges=[slot, "e", "e", "e"],
callback=[lambda: self.hole((hw - 4 * t - 6) / 2., 15, 4)], move="right")
for i in range(3):
self.rectangularWall(20, 30,
for i in range(3):
self.rectangularWall(20, 30,
callback=[lambda: self.nutHole("M8", 10, 15)], move="right")
self.rectangularWall(20, 30,
callback=[lambda: self.hole(10, 15, 4)], move="right")
self.rectangularWall(20, 30,
callback=[lambda: self.hole(10, 15, 4)], move="right")
self.ctx.restore()
self.rectangularWall(30, 30, move="up only")
self.h = h = bh + 2 + 1.0 * d # height of outer pieces
@ -291,10 +290,9 @@ class Rotary(Boxes):
move="up")
self.rectangularWall(3.6 * d, ow, edges="ffff", move="up")
self.rectangularWall(3.6 * d, ow, edges="ffff", move="up")
self.ctx.save()
self.rectangularWall(ow, h, edges="hFFH", move="right")
self.rectangularWall(ow, h, edges="hFFH", move="right")
self.ctx.restore()
with self.saved_context():
self.rectangularWall(ow, h, edges="hFFH", move="right")
self.rectangularWall(ow, h, edges="hFFH", move="right")
self.rectangularWall(ow, h, edges="hFFH", move="up only")
# Motor block
@ -302,13 +300,12 @@ class Rotary(Boxes):
self.rectangularWall(3.6 * d, h, edges=["h", "f", MotorEdge(self, None),"f"], callback=[self.mainPlate], move="up")
self.rectangularWall(3.6 * d, h, edges=["h", "f", MotorEdge(self, None),"f"], callback=[self.frontPlate], move="up")
self.rectangularWall(3.6 * d, mw, edges="ffff", move="up")
self.ctx.save()
self.rectangularWall(mw, h, edges="hFeH", move="right")
self.rectangularWall(mw, h, edges="hFeH", move="right")
with self.saved_context():
self.rectangularWall(mw, h, edges="hFeH", move="right")
self.rectangularWall(mw, h, edges="hFeH", move="right")
self.pulley(88, "GT2_2mm", r_axle=a / 2.0, move="right")
self.pulley(88, "GT2_2mm", r_axle=a / 2.0, move="right")
self.ctx.restore()
self.pulley(88, "GT2_2mm", r_axle=a / 2.0, move="right")
self.pulley(88, "GT2_2mm", r_axle=a / 2.0, move="right")
self.rectangularWall(mw, h, edges="hFeH", move="up only")
self.axle = 19

View File

@ -71,13 +71,13 @@ class RoundedBox(Boxes):
t = self.thickness
self.ctx.save()
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="right")
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="right",
callback=[self.hole] if self.top != "closed" else None)
if self.top == "lid":
self.roundedPlate(x, y, r, "E", wallpieces=self.wallpieces, move="right")
self.ctx.restore()
with self.saved_context():
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="right")
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="right",
callback=[self.hole] if self.top != "closed" else None)
if self.top == "lid":
self.roundedPlate(x, y, r, "E", wallpieces=self.wallpieces, move="right")
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="up only")
self.surroundingWall(x, y, r, h, "F", "F", pieces=self.wallpieces)

View File

@ -84,12 +84,11 @@ class RoyalGame(Boxes): # Change class name!
@holeCol
def rosette(self, x, y, s):
self.moveTo(x, y, 22.5)
self.ctx.save()
self.moveTo(0.1*s, 0, -30)
for i in range(8):
self.polyline(0, (60, 0.35*s), 0, 120, 0, (60, 0.35*s), 0,
-120, 0, (45, 0.1*s), 0, -120)
self.ctx.restore()
with self.saved_context():
self.moveTo(0.1*s, 0, -30)
for i in range(8):
self.polyline(0, (60, 0.35*s), 0, 120, 0, (60, 0.35*s), 0,
-120, 0, (45, 0.1*s), 0, -120)
self.moveTo(0, 0, -22.5)
self.moveTo(0.175*s, 0)
for i in range(8):
@ -103,18 +102,17 @@ class RoyalGame(Boxes): # Change class name!
posy = y+dy*0.25*s
self.rectangularHole(posx, posy, 0.4*s, 0.5*s)
self.hole(posx, posy, 0.05*s)
self.ctx.save()
self.moveTo(posx, posy-0.2*s, 60)
self.corner(60, 0.4*s)
self.corner(120)
self.corner(60, 0.4*s)
self.corner(120)
self.moveTo(0, 0, -60)
self.moveTo(0, -0.05*s, 60)
self.corner(60, 0.5*s)
self.corner(120)
self.corner(60, 0.5*s)
self.ctx.restore()
with self.saved_context():
self.moveTo(posx, posy-0.2*s, 60)
self.corner(60, 0.4*s)
self.corner(120)
self.corner(60, 0.4*s)
self.corner(120)
self.moveTo(0, 0, -60)
self.moveTo(0, -0.05*s, 60)
self.corner(60, 0.5*s)
self.corner(120)
self.corner(60, 0.5*s)
for i in range(4):
self.rectangularHole(x, y + (i-1.5)*s*0.25, 0.12*s, 0.12*s)

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from boxes import Boxes
from boxes import Boxes, restore
class Silverware(Boxes):
@ -64,9 +64,8 @@ class Silverware(Boxes):
},
move="up")
@restore
def centerWall(self, x, h):
self.ctx.save()
self.moveTo(self.edges["f"].spacing(), self.edges["f"].spacing())
for i in range(2, 5):
self.fingerHolesAt(i * x / 6.0, 0, h - 10)
@ -81,9 +80,6 @@ class Silverware(Boxes):
self.corner(90)
self.edges["f"](h - 10)
self.corner(90)
self.ctx.restore()
self.moveTo(x + 2 * self.edges["f"].spacing())
##################################################
### main
@ -101,6 +97,7 @@ class Silverware(Boxes):
self.wall(x, y, h, r)
self.centerWall(x, h)
self.moveTo(x + 2 * self.edges["f"].spacing())
l = (y - t) / 2.0

View File

@ -52,12 +52,11 @@ class TwoPiece(Boxes):
for i in range(2):
d = i * 2 * (t+p)
self.ctx.save()
self.rectangularWall(x+d, h, "fFeF", bedBolts=None, move="right")
self.rectangularWall(y+d, h, "ffef", bedBolts=None, move="right")
self.rectangularWall(x+d, h, "fFeF", bedBolts=None, move="right")
self.rectangularWall(y+d, h, "ffef", bedBolts=None, move="right")
self.ctx.restore()
with self.saved_context():
self.rectangularWall(x+d, h, "fFeF", bedBolts=None, move="right")
self.rectangularWall(y+d, h, "ffef", bedBolts=None, move="right")
self.rectangularWall(x+d, h, "fFeF", bedBolts=None, move="right")
self.rectangularWall(y+d, h, "ffef", bedBolts=None, move="right")
self.rectangularWall(y, h, "ffef", bedBolts=None, move="up only")
self.rectangularWall(x, y, "hhhh", bedBolts=None, move="right")

View File

@ -89,22 +89,19 @@ class UnevenHeightBox(Boxes):
self.wall(x, h2, h3, [b, "F", "F"], move="right")
self.wall(y, h3, h0, [b, "f", "f"], move="right")
self.ctx.save()
with self.saved_context():
if b != "e":
self.rectangularWall(x, y, "ffff", move="up")
if b != "e":
self.rectangularWall(x, y, "ffff", move="up")
if self.lid:
maxh = max(heights)
lidheights = [maxh-h for h in heights]
h0, h1, h2, h3 = lidheights
lidheights += lidheights
edges = ["E" if (lidheights[i] == 0.0 and lidheights[i+1] == 0.0) else "f" for i in range(4)]
self.rectangularWall(x, y, edges, move="up")
if self.lid:
maxh = max(heights)
lidheights = [maxh-h for h in heights]
h0, h1, h2, h3 = lidheights
lidheights += lidheights
edges = ["E" if (lidheights[i] == 0.0 and lidheights[i+1] == 0.0) else "f" for i in range(4)]
self.rectangularWall(x, y, edges, move="up")
self.ctx.restore()
self.moveTo(0, maxh+self.edges["F"].spacing()+self.edges[b].spacing()+3*self.spacing, 180)
self.wall(y, h0, h3, "Fff", move="right" +
(" only" if h0 == h3 == 0.0 else ""))

View File

@ -67,25 +67,24 @@ class UniversalBox(_TopEdge, _ChestLid):
d2 = d3 = None
self.ctx.save()
self.rectangularWall(x, h, [b, "F", t1, "F"],
bedBolts=[d2], move="up")
self.rectangularWall(x, h, [b, "F", t3, "F"],
bedBolts=[d2], move="up")
with self.saved_context():
self.rectangularWall(x, h, [b, "F", t1, "F"],
bedBolts=[d2], move="up")
self.rectangularWall(x, h, [b, "F", t3, "F"],
bedBolts=[d2], move="up")
if self.bottom_edge != "e":
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="up")
if (self.drawLid(x, y, self.top_edge, [d2, d3]) and
self.bottom_edge != "e"):
self.rectangularWall(x, y, "ffff", move="left only")
if self.top_edge in "fF":
self.set_source_color(Color.RED)
self.rectangularWall(x+4*t, y+4*t, callback=[
lambda:self.top_hole(x, y, self.top_edge)], move="right")
self.set_source_color(Color.BLACK)
self.drawAddOnLid(x, y, self.lid)
if self.bottom_edge != "e":
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="up")
if (self.drawLid(x, y, self.top_edge, [d2, d3]) and
self.bottom_edge != "e"):
self.rectangularWall(x, y, "ffff", move="left only")
if self.top_edge in "fF":
self.set_source_color(Color.RED)
self.rectangularWall(x+4*t, y+4*t, callback=[
lambda:self.top_hole(x, y, self.top_edge)], move="right")
self.set_source_color(Color.BLACK)
self.drawAddOnLid(x, y, self.lid)
self.ctx.restore()
self.rectangularWall(x, h, [b, "F", t3, "F"],
bedBolts=[d2], move="right only")
self.rectangularWall(y, h, [b, "f", t2, "f"],

View File

@ -39,11 +39,10 @@ class WineRack(Boxes):
help="which of the honey comb walls to add")
def hexFingerHoles(self, x, y, l, angle=90):
self.ctx.save()
self.moveTo(x, y, angle)
self.moveTo(self.delta, 0, 0)
self.fingerHolesAt(0, 0, l-2*self.delta, 0)
self.ctx.restore()
with self.saved_context():
self.moveTo(x, y, angle)
self.moveTo(self.delta, 0, 0)
self.fingerHolesAt(0, 0, l-2*self.delta, 0)
def wallCB(self, frontwall=False, backwall=False):
r = self.r