Commit ffe154b9 authored by Guillaume Seguin's avatar Guillaume Seguin

Add alternative autoplating method based on a packing algorithm

Packing algorithm is unlicensed for now, will import it when/if it gets a
GPL-compatible license
parent 8f2a5b3f
...@@ -150,6 +150,23 @@ class Plater(wx.Frame): ...@@ -150,6 +150,23 @@ class Plater(wx.Frame):
def autoplate(self, event = None): def autoplate(self, event = None):
print _("Autoplating") print _("Autoplating")
separation = 2 separation = 2
try:
from printrun import packer
p = packer.Packer()
for i in self.models:
width = abs(self.models[i].dims[0] - self.models[i].dims[1])
height = abs(self.models[i].dims[2] - self.models[i].dims[3])
p.add_rect(width, height, data = i)
# FIXME: probably wrong, not taking offsets into account
centerx = self.build_dimensions[0] / 2
centery = self.build_dimensions[1] / 2
rects = p.pack(padding = separation,
center = packer.Vector2(centerx, centery))
for rect in rects:
i = rect.data
self.models[i].offsets[0] = rect.position.x
self.models[i].offsets[1] = rect.position.y
except ImportError:
bedsize = self.build_dimensions[0:3] bedsize = self.build_dimensions[0:3]
cursor = [0, 0, 0] cursor = [0, 0, 0]
newrow = 0 newrow = 0
...@@ -159,14 +176,16 @@ class Plater(wx.Frame): ...@@ -159,14 +176,16 @@ class Plater(wx.Frame):
x = abs(self.models[i].dims[0] - self.models[i].dims[1]) x = abs(self.models[i].dims[0] - self.models[i].dims[1])
y = abs(self.models[i].dims[2] - self.models[i].dims[3]) y = abs(self.models[i].dims[2] - self.models[i].dims[3])
centre = [x / 2, y / 2] centre = [x / 2, y / 2]
centreoffset = [self.models[i].dims[0] + centre[0], self.models[i].dims[2] + centre[1]] centreoffset = [self.models[i].dims[0] + centre[0],
self.models[i].dims[2] + centre[1]]
if (cursor[0] + x + separation) >= bedsize[0]: if (cursor[0] + x + separation) >= bedsize[0]:
cursor[0] = 0 cursor[0] = 0
cursor[1] += newrow + separation cursor[1] += newrow + separation
newrow = 0 newrow = 0
if (newrow == 0) or (newrow < y): if (newrow == 0) or (newrow < y):
newrow = y newrow = y
#To the person who works out why the offsets are applied differently here: # To the person who works out why the offsets are applied
# differently here:
# Good job, it confused the hell out of me. # Good job, it confused the hell out of me.
self.models[i].offsets[0] = cursor[0] + centre[0] - centreoffset[0] self.models[i].offsets[0] = cursor[0] + centre[0] - centreoffset[0]
self.models[i].offsets[1] = cursor[1] + centre[1] - centreoffset[1] self.models[i].offsets[1] = cursor[1] + centre[1] - centreoffset[1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment