TrayLayout: Split render() into several methods
to allow better re-use in GridfinityTrayLayout. Mirror the base plate of the GridfinityTrayLayout so the engravings for the feet are on "the bottom". Related: #533
This commit is contained in:
parent
a96a78f439
commit
20dadbbb04
|
@ -81,8 +81,8 @@ this compartment.
|
|||
self.edge(d - 2 * r)
|
||||
|
||||
def baseplate_etching(self):
|
||||
x = 0
|
||||
y = 0
|
||||
x = -self.thickness - self.margin / 2
|
||||
y = -self.thickness - self.margin / 2
|
||||
o = self.opening
|
||||
p = self.pitch
|
||||
m = self.opening_margin
|
||||
|
@ -100,14 +100,12 @@ this compartment.
|
|||
self.y = self.pitch * self.ny - self.margin
|
||||
self.outer_x = self.x
|
||||
self.outer_y = self.y
|
||||
super().render()
|
||||
# relies on still being at the place of the base plate
|
||||
self.baseplate_etching()
|
||||
|
||||
self.prepare()
|
||||
self.walls()
|
||||
self.base_plate(callback=[self.baseplate_etching],
|
||||
move="mirror right")
|
||||
foot = self.opening - self.opening_margin
|
||||
self.move(self.outer_x, self.outer_y, "right", before=False)
|
||||
n_grids = self.nx * self.ny
|
||||
if n_grids > 4:
|
||||
n_grids = 4
|
||||
for i in range(n_grids):
|
||||
for i in range(min(self.nx * self.ny, 4)):
|
||||
self.rectangularWall(foot, foot, move="right")
|
||||
|
||||
|
|
|
@ -154,8 +154,7 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
edge = self.edges.get(edge, edge)
|
||||
edge(length)
|
||||
|
||||
def render(self):
|
||||
|
||||
def prepare(self):
|
||||
if self.layout:
|
||||
self.parse(self.layout.split('\n'))
|
||||
else:
|
||||
|
@ -170,23 +169,17 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
self.hi = self.adjustSize(self.hi, e2=False)
|
||||
|
||||
self.hi = hi = self.hi or self.h
|
||||
self.edges["s"] = boxes.edges.Slot(self, self.hi / 2.0)
|
||||
self.edges["C"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi)
|
||||
self.edges["D"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi, outset=self.thickness)
|
||||
|
||||
def walls(self, move=None):
|
||||
lx = len(self.x)
|
||||
ly = len(self.y)
|
||||
t = self.thickness
|
||||
b = self.burn
|
||||
t2 = self.thickness / 2.0
|
||||
|
||||
hasfloor = False
|
||||
|
||||
for line in self.floors:
|
||||
for f in line:
|
||||
hasfloor |= f
|
||||
|
||||
|
||||
self.edges["s"] = boxes.edges.Slot(self, self.hi / 2.0)
|
||||
self.edges["C"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi)
|
||||
self.edges["D"] = boxes.edges.CrossingFingerHoleEdge(self, self.hi, outset=t)
|
||||
|
||||
self.ctx.save()
|
||||
|
||||
|
@ -242,6 +235,7 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
self.rectangularWall(10, h, "ffef", move="up only")
|
||||
self.ctx.save()
|
||||
|
||||
|
||||
# Vertical Walls
|
||||
for x in range(lx + 1):
|
||||
if x == 0 or x == lx:
|
||||
|
@ -298,12 +292,25 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
|
||||
self.ctx.restore()
|
||||
self.rectangularWall(10, h, "ffef", move="up only")
|
||||
self.moveTo(2 * self.thickness, 2 * self.thickness)
|
||||
self.ctx.save()
|
||||
|
||||
##########################################################
|
||||
### Baseplate
|
||||
##########################################################
|
||||
def base_plate(self, callback=None, move=None):
|
||||
lx = len(self.x)
|
||||
ly = len(self.y)
|
||||
t = self.thickness
|
||||
b = self.burn
|
||||
t2 = self.thickness / 2.0
|
||||
|
||||
tw, th = sum(self.x) + (lx+1) * t, sum(self.y) + (ly + 1) * t
|
||||
|
||||
if self.move(tw, th, move, True):
|
||||
return
|
||||
|
||||
for i, (x, y, a) in enumerate((
|
||||
(t, t + b, 0),
|
||||
(tw - t, t + b, 90),
|
||||
(tw - t, th - t + b, 180),
|
||||
(t, th - t + b, 270))):
|
||||
self.cc(callback, i, x, y, a)
|
||||
|
||||
# Horizontal lines
|
||||
posy = 0
|
||||
|
@ -368,6 +375,8 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
if x < lx:
|
||||
posx += self.x[x] + self.thickness
|
||||
|
||||
self.move(tw, th, move)
|
||||
|
||||
def parse(self, input):
|
||||
x = []
|
||||
y = []
|
||||
|
@ -450,3 +459,8 @@ You can replace the space characters representing the floor by a "X" to remove t
|
|||
self.hwalls = hwalls
|
||||
self.vwalls = vwalls
|
||||
self.floors = floors
|
||||
|
||||
def render(self):
|
||||
self.prepare()
|
||||
self.walls()
|
||||
self.base_plate()
|
||||
|
|
Loading…
Reference in New Issue