Commit 85078b82 authored by kliment's avatar kliment

First working version of the plater tool.

parent 9b1b45d0
......@@ -16,10 +16,14 @@ class showstl(wx.Window):
def __init__(self,parent,size,pos):
wx.Window.__init__(self,parent,size=size,pos=pos)
self.l=wx.ListCtrl(self,size=(300,100),pos=(0,size[1]-100))
self.b=wx.Button(self,label="Export",pos=(300,size[1]-100))
self.b.Bind(wx.EVT_BUTTON,self.export)
self.eb=wx.Button(self,label="Export",pos=(300,size[1]-100))
self.sb=wx.Button(self,label="Snap to Z=0",pos=(300,size[1]-70))
self.cb=wx.Button(self,label="Put at 100,100",pos=(300,size[1]-40))
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.SetBackgroundColour((0,0,0))
wx.FutureCall(200,self.paint)
#wx.FutureCall(200,self.paint)
self.i=0
self.previ=0
self.Bind(wx.EVT_MOUSEWHEEL,self.rot)
......@@ -32,6 +36,22 @@ class showstl(wx.Window):
self.initpos=None
self.prevsel=-1
def center(self,event):
i=self.l.GetFirstSelected()
if i != -1:
m=self.models[self.l.GetItemText(i)]
m.offsets=[100,100,m.offsets[2]]
self.Refresh()
def snap(self,event):
i=self.l.GetFirstSelected()
if i != -1:
m=self.models[self.l.GetItemText(i)]
m.offsets[2]=-1.0*min(m.facetsminz)[0]
#print m.offsets[2]
self.Refresh()
def export(self,event):
dlg=wx.FileDialog(self,"Pick file to save to",self.basedir,style=wx.FD_SAVE)
dlg.SetWildcard("STL files (;*.stl;)")
......@@ -39,6 +59,8 @@ class showstl(wx.Window):
name=dlg.GetPath()
facets=[]
for i in self.models.values():
if i.offsets != [0,0,0]:
i=i.translate(i.offsets)
facets+=i.facets
stltool.emitstl(name,facets,"plater_export")
print "wrote ",name
......@@ -56,10 +78,15 @@ class showstl(wx.Window):
t=time.time()
#print name
if name.lower().endswith(".stl"):
self.models[name]=stltool.stl(name)
self.models[name].offsets=[0,0,0]
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]
#print time.time()-t
self.l.Append([stlwrap(self.models[name],name)])
self.l.Append([stlwrap(self.models[newname],newname)])
self.Refresh()
#print time.time()-t
......@@ -72,7 +99,7 @@ class showstl(wx.Window):
#print (p[0]-self.initpos[0]),(p[1]-self.initpos[1])
t=time.time()
m=self.models[self.l.GetItemText(i)]
m.offsets=[m.offsets[0]+0.5*(p[0]-self.initpos[0]),m.offsets[1]+0.5*(p[1]-self.initpos[1]),m.offsets[2]]
m.offsets=[m.offsets[0]+0.5*(p[0]-self.initpos[0]),m.offsets[1]-0.5*(p[1]-self.initpos[1]),m.offsets[2]]
#self.models[self.l.GetItemText(i)]=self.models[self.l.GetItemText(i)].translate([0.5*(p[0]-self.initpos[0]),0.5*(p[1]-self.initpos[1]),0])
#print time.time()-t
self.Refresh()
......@@ -97,7 +124,9 @@ class showstl(wx.Window):
if(self.i!=self.previ):
i=self.l.GetFirstSelected()
if i != -1:
o=self.models[self.l.GetItemText(i)].offsets
self.models[self.l.GetItemText(i)]=self.models[self.l.GetItemText(i)].rotate([0,0,self.i-self.previ])
self.models[self.l.GetItemText(i)].offsets=o
self.previ=self.i
wx.CallAfter(self.Refresh)
self.triggered=0
......@@ -125,23 +154,31 @@ class showstl(wx.Window):
if dc is None:
dc=wx.ClientDC(self)
offset=[0,0]
scale=3
scale=2
dc.SetPen(wx.Pen(wx.Colour(100,100,100)))
for i in xrange(20):
dc.DrawLine(0,i*scale*10,400,i*scale*10)
dc.DrawLine(i*scale*10,0,i*scale*10,400)
dc.SetPen(wx.Pen(wx.Colour(0,0,0)))
for i in xrange(4):
dc.DrawLine(0,i*scale*50,400,i*scale*50)
dc.DrawLine(i*scale*50,0,i*scale*50,400)
dc.SetBrush(wx.Brush(wx.Colour(128,255,128)))
dc.SetPen(wx.Pen(wx.Colour(128,255,128)))
dc.SetPen(wx.Pen(wx.Colour(128,128,128)))
t=time.time()
for m in self.models.values():
for i in m.facets:#random.sample(m.facets,min(100000,len(m.facets))):
dc.DrawPolygon([wx.Point(offset[0]+scale*m.offsets[0]+scale*p[0],0-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]])
dc.DrawPolygon([wx.Point(offset[0]+scale*m.offsets[0]+scale*p[0],400-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]])
#if(time.time()-t)>5:
# break
del dc
print time.time()-t
#print time.time()-t
#s.export()
class stlwin(wx.Frame):
def __init__(self,size=(600,700)):
def __init__(self,size=(400,500)):
wx.Frame.__init__(self,None,title="Right-click to add a file",size=size)
self.s=showstl(self,(600,700),(0,0))
self.s=showstl(self,(400,500),(0,0))
if __name__ == '__main__':
app = wx.App(False)
......
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