Added new autoplate function

Crudely arranges the added STLs on the bed. Does not attempt to optimise for
space or anything, just arranges them in a rough grid.
master
Travis Howse 2011-09-08 20:17:17 +10:00
parent 2704c88dd1
commit 762b76f7ba
1 changed files with 282 additions and 250 deletions

View File

@ -18,13 +18,15 @@ class showstl(wx.Window):
wx.Window.__init__(self,parent,size=size,pos=pos) wx.Window.__init__(self,parent,size=size,pos=pos)
self.l=wx.ListCtrl(self,style=wx.LC_LIST,size=(300,130),pos=(0,size[1]-130)) self.l=wx.ListCtrl(self,style=wx.LC_LIST,size=(300,130),pos=(0,size[1]-130))
self.eb=wx.Button(self,label="Export",pos=(300,size[1]-130)) self.eb=wx.Button(self,label="Export",pos=(300,size[1]-130))
self.sb=wx.Button(self,label="Snap to Z=0",pos=(300,size[1]-100)) self.sb=wx.Button(self,label="Snap to Z=0",pos=(300,size[1]-105))
self.cb=wx.Button(self,label="Put at 100,100",pos=(300,size[1]-70)) self.cb=wx.Button(self,label="Put at 100,100",pos=(300,size[1]-80))
self.db=wx.Button(self,label="Delete",pos=(300,size[1]-40)) self.db=wx.Button(self,label="Delete",pos=(300,size[1]-55))
self.ab=wx.Button(self,label="Auto",pos=(300,size[1]-30))
self.eb.Bind(wx.EVT_BUTTON,self.export) self.eb.Bind(wx.EVT_BUTTON,self.export)
self.sb.Bind(wx.EVT_BUTTON,self.snap) self.sb.Bind(wx.EVT_BUTTON,self.snap)
self.cb.Bind(wx.EVT_BUTTON,self.center) self.cb.Bind(wx.EVT_BUTTON,self.center)
self.db.Bind(wx.EVT_BUTTON,self.delete) self.db.Bind(wx.EVT_BUTTON,self.delete)
self.ab.Bind(wx.EVT_BUTTON,self.autoplate)
#self.SetBackgroundColour((0,0,0)) #self.SetBackgroundColour((0,0,0))
#wx.FutureCall(200,self.paint) #wx.FutureCall(200,self.paint)
self.i=0 self.i=0
@ -79,6 +81,36 @@ class showstl(wx.Window):
stltool.emitstl(name,facets,"plater_export") stltool.emitstl(name,facets,"plater_export")
print "wrote ",name print "wrote ",name
def autoplate(self,event):
print "Autoplating"
separation = 2
bedsize = [200,200,100]
cursor = [0,0,0]
newrow = 0
for i in self.models:
x = abs(self.models[i].dims[0] - self.models[i].dims[1])
y = abs(self.models[i].dims[2] - self.models[i].dims[3])
centre = [x/2, y/2]
centreoffset = [self.models[i].dims[0] + centre[0], self.models[i].dims[2] + centre[1]]
if (newrow == 0) or (newrow < y):
newrow = y
#To the person who works out why the offsets are applied differently here:
# Good job, it confused the hell out of me.
self.models[i].offsets[0] = cursor[0] + centre[0] - centreoffset[0]
self.models[i].offsets[1] = cursor[1] + centre[1] + centreoffset[1]
cursor[0] += x+separation
if cursor[0] >= bedsize[0]:
cursor[0] = 0
cursor[1] += newrow+separation
newrow = 0
self.models[i].offsets[0] = cursor[0] + centre[0] - centreoffset[0]
self.models[i].offsets[1] = cursor[1] + centre[1] + centreoffset[1]
cursor[0] += x+separation
if (cursor[1]+y) >= bedsize[1]:
print "Bed full, sorry sir :("
self.Refresh()
return
self.Refresh()
def right(self,event): def right(self,event):
dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST) dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)