Commit 71a15c22 authored by Travis Howse's avatar Travis Howse

Added the autoplater stuff and a debug function

parent 2704c88d
......@@ -18,13 +18,15 @@ class showstl(wx.Window):
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.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.cb=wx.Button(self,label="Put at 100,100",pos=(300,size[1]-70))
self.db=wx.Button(self,label="Delete",pos=(300,size[1]-40))
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]-80))
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.sb.Bind(wx.EVT_BUTTON,self.snap)
self.cb.Bind(wx.EVT_BUTTON,self.center)
self.db.Bind(wx.EVT_BUTTON,self.delete)
self.ab.Bind(wx.EVT_BUTTON,self.autoplate)
#self.SetBackgroundColour((0,0,0))
#wx.FutureCall(200,self.paint)
self.i=0
......@@ -79,6 +81,114 @@ class showstl(wx.Window):
stltool.emitstl(name,facets,"plater_export")
print "wrote ",name
def testingloadfile(self,name):
print name
if not(os.path.exists(name)):
return
path = os.path.split(name)[0]
self.basedir=path
t=time.time()
#print name
if name.lower().endswith(".stl"):
newname=name
c=1
while newname in self.models:
newname=name+"(%d)"%c
c+=1
self.models[newname]=stltool.stl(name)
self.models[newname].offsets=[0,0,0]
self.models[newname].rot=0
minx,miny,minz,maxx,maxy,maxz=(10000,10000,10000,0,0,0)
for i in self.models[newname].facets:
for j in i[1]:
if j[0]<minx:
minx=j[0]
if j[1]<miny:
miny=j[1]
if j[2]<minz:
minz=j[2]
if j[0]>maxx:
maxx=j[0]
if j[1]>maxy:
maxy=j[1]
if j[2]>maxz:
maxz=j[2]
self.models[newname].dims=[minx,maxx,miny,maxy,minz,maxz]
#if minx<0:
# self.models[newname].offsets[0]=-minx
#if miny<0:
# self.models[newname].offsets[1]=-miny
self.models[newname].bitmap=wx.EmptyBitmap(800,800,32)
dc=wx.MemoryDC()
dc.SelectObject(self.models[newname].bitmap)
dc.SetBackground(wx.Brush((0,0,0,0)))
dc.SetBrush(wx.Brush((0,0,0,255)))
#dc.DrawRectangle(-1,-1,10000,10000)
dc.SetBrush(wx.Brush(wx.Colour(128,255,128)))
dc.SetPen(wx.Pen(wx.Colour(128,128,128)))
m=self.models[newname]
#m.offsets=[10,10,0]
print m.offsets,m.dims
scale=2
for i in m.facets:#random.sample(m.facets,min(100000,len(m.facets))):
dc.DrawPolygon([wx.Point(400+scale*p[0],(400+scale*p[1])) for p in i[1]])
#if(time.time()-t)>5:
# break
dc.SelectObject(wx.NullBitmap)
m.bitmap.SetMask(wx.Mask(m.bitmap,wx.Colour(0,0,0,255)))
#print time.time()-t
self.l.Append([stlwrap(self.models[newname],newname)])
i=self.l.GetFirstSelected()
if i != -1:
self.l.Select(i,0)
self.l.Select(self.l.GetItemCount()-1)
self.Refresh()
def autoplate(self,event):
print "Autoplating"
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\big_gear.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\big_gear.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\big_gear.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\big_gear.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\prusabits\\stl\\x-end-idler.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\prusabits\\stl\\x-end-idler.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\prusabits\\stl\\x-end-idler.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\prusabits\\stl\\pla-bushing.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\prusabits\\stl\\pla-bushing.stl')
self.testingloadfile('C:\\Users\\tjhowse\\reprap\\models\\top.stl')
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):
dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
......
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