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:
Florian Festi 2023-02-15 21:48:59 +01:00
parent a96a78f439
commit 20dadbbb04
2 changed files with 39 additions and 27 deletions

View File

@ -81,8 +81,8 @@ this compartment.
self.edge(d - 2 * r) self.edge(d - 2 * r)
def baseplate_etching(self): def baseplate_etching(self):
x = 0 x = -self.thickness - self.margin / 2
y = 0 y = -self.thickness - self.margin / 2
o = self.opening o = self.opening
p = self.pitch p = self.pitch
m = self.opening_margin m = self.opening_margin
@ -100,14 +100,12 @@ this compartment.
self.y = self.pitch * self.ny - self.margin self.y = self.pitch * self.ny - self.margin
self.outer_x = self.x self.outer_x = self.x
self.outer_y = self.y self.outer_y = self.y
super().render()
# relies on still being at the place of the base plate self.prepare()
self.baseplate_etching() self.walls()
self.base_plate(callback=[self.baseplate_etching],
move="mirror right")
foot = self.opening - self.opening_margin foot = self.opening - self.opening_margin
self.move(self.outer_x, self.outer_y, "right", before=False) for i in range(min(self.nx * self.ny, 4)):
n_grids = self.nx * self.ny
if n_grids > 4:
n_grids = 4
for i in range(n_grids):
self.rectangularWall(foot, foot, move="right") self.rectangularWall(foot, foot, move="right")

View File

@ -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 = self.edges.get(edge, edge)
edge(length) edge(length)
def render(self): def prepare(self):
if self.layout: if self.layout:
self.parse(self.layout.split('\n')) self.parse(self.layout.split('\n'))
else: 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 = self.adjustSize(self.hi, e2=False)
self.hi = hi = self.hi or self.h 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) lx = len(self.x)
ly = len(self.y) ly = len(self.y)
t = self.thickness t = self.thickness
b = self.burn b = self.burn
t2 = self.thickness / 2.0 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() 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.rectangularWall(10, h, "ffef", move="up only")
self.ctx.save() self.ctx.save()
# Vertical Walls # Vertical Walls
for x in range(lx + 1): for x in range(lx + 1):
if x == 0 or x == lx: 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.ctx.restore()
self.rectangularWall(10, h, "ffef", move="up only") self.rectangularWall(10, h, "ffef", move="up only")
self.moveTo(2 * self.thickness, 2 * self.thickness)
self.ctx.save()
########################################################## def base_plate(self, callback=None, move=None):
### Baseplate 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 # Horizontal lines
posy = 0 posy = 0
@ -368,6 +375,8 @@ You can replace the space characters representing the floor by a "X" to remove t
if x < lx: if x < lx:
posx += self.x[x] + self.thickness posx += self.x[x] + self.thickness
self.move(tw, th, move)
def parse(self, input): def parse(self, input):
x = [] x = []
y = [] y = []
@ -450,3 +459,8 @@ You can replace the space characters representing the floor by a "X" to remove t
self.hwalls = hwalls self.hwalls = hwalls
self.vwalls = vwalls self.vwalls = vwalls
self.floors = floors self.floors = floors
def render(self):
self.prepare()
self.walls()
self.base_plate()