Commit 716ab0e9 authored by Kliment Yanev's avatar Kliment Yanev

Fast plater

parent 88a7b10c
......@@ -69,8 +69,12 @@ 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)
r=i.rot
o=i.offsets
if r != 0:
i=i.rotate([0,0,-r])
if o != [0,0,0]:
i=i.translate([o[0],-o[1],o[2]])
facets+=i.facets
stltool.emitstl(name,facets,"plater_export")
print "wrote ",name
......@@ -95,6 +99,46 @@ class showstl(wx.Window):
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()
......@@ -134,16 +178,19 @@ class showstl(wx.Window):
else:
event.Skip()
def cr(self):
time.sleep(0.01)
def rotateafter(self):
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,5*(self.i-self.previ)])
self.models[self.l.GetItemText(i)].offsets=o
#o=self.models[self.l.GetItemText(i)].offsets
self.models[self.l.GetItemText(i)].rot+=5*(self.i-self.previ)
#self.models[self.l.GetItemText(i)].offsets=o
self.previ=self.i
wx.CallAfter(self.Refresh)
self.Refresh()
def cr(self):
time.sleep(0.01)
wx.CallAfter(self.rotateafter)
self.triggered=0
def rot(self, event):
......@@ -181,9 +228,21 @@ class showstl(wx.Window):
dc.SetBrush(wx.Brush(wx.Colour(128,255,128)))
dc.SetPen(wx.Pen(wx.Colour(128,128,128)))
t=time.time()
dcs=wx.MemoryDC()
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],400-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]])
b=m.bitmap
#print b
im=b.ConvertToImage()
#print im
imgc = wx.Point( im.GetWidth()/2,im.GetHeight()/2 )
#print math.radians(5*(self.i-self.previ))
im= im.Rotate( math.radians(m.rot), imgc, 0)
bm=wx.BitmapFromImage(im)
dcs.SelectObject(bm)
bsz=bm.GetSize()
dc.Blit(scale*m.offsets[0]-bsz[0]/2,400-(scale*m.offsets[1]+bsz[1]/2),bsz[0],bsz[1],dcs,0,0,useMask=1)
#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],400-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]])
#if(time.time()-t)>5:
# break
del dc
......
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