Commit 6785eb65 authored by Steven Devijver's avatar Steven Devijver

Run everything through right, distinguish on extension to delegate to load_stl & load_scad

parent b644182a
...@@ -29,7 +29,7 @@ class showstl(wx.Window): ...@@ -29,7 +29,7 @@ class showstl(wx.Window):
self.cb=wx.Button(self,label="Put at 100,100",pos=(300,size[1]-80)) 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.db=wx.Button(self,label="Delete",pos=(300,size[1]-55))
self.ab=wx.Button(self,label="Auto",pos=(300,size[1]-30)) self.ab=wx.Button(self,label="Auto",pos=(300,size[1]-30))
self.lb.Bind(wx.EVT_BUTTON,self.load) self.lb.Bind(wx.EVT_BUTTON,self.right)
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)
...@@ -72,32 +72,6 @@ class showstl(wx.Window): ...@@ -72,32 +72,6 @@ class showstl(wx.Window):
self.l.Select(self.l.GetCount()-1) self.l.Select(self.l.GetCount()-1)
self.Refresh() self.Refresh()
def load(self,event):
dlg=wx.FileDialog(self,"Pick file to load",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard("OpenSCAD files (;*.scad;)")
self.models={}
if(dlg.ShowModal() == wx.ID_OK):
name=dlg.GetPath()
lf=open(name)
s=[i.replace("\n","").replace("\r","").replace(";","") for i in lf]
lf.close()
for i in s:
parts = i.split()
translate_list = eval(parts[0])
rotate_list = eval(parts[1])
stl_file = eval(parts[2])
newname=os.path.split(stl_file.lower())[1]
c=1
while newname in self.models:
newname=os.path.split(stl_file.lower())[1]
newname=newname+"(%d)"%c
c+=1
stl_path = os.path.join(os.path.split(name)[0:len(os.path.split(stl_file))-1])
stl_full_path = os.path.join(stl_path[0],str(stl_file))
self.load_stl(stl_full_path,stl_file,translate_list,rotate_list[2])
def export(self,event): def export(self,event):
dlg=wx.FileDialog(self,"Pick file to save to",self.basedir,style=wx.FD_SAVE) dlg=wx.FileDialog(self,"Pick file to save to",self.basedir,style=wx.FD_SAVE)
dlg.SetWildcard("STL files (;*.stl;)") dlg.SetWildcard("STL files (;*.stl;)")
...@@ -159,10 +133,38 @@ class showstl(wx.Window): ...@@ -159,10 +133,38 @@ class showstl(wx.Window):
self.Refresh() 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,"Pick file to load",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard("STL files (;*.stl;)") dlg.SetWildcard("STL files (;*.stl;)|*.stl|OpenSCAD files (;*.scad;)|*.scad")
if(dlg.ShowModal() == wx.ID_OK): if(dlg.ShowModal() == wx.ID_OK):
name=dlg.GetPath() name=dlg.GetPath()
if (name.lower().endswith(".stl")):
self.load_stl(event,name)
elif (name.lower().endswith(".scad")):
self.load_scad(event,name)
def load_scad(self,event,name):
lf=open(name)
s=[i.replace("\n","").replace("\r","").replace(";","") for i in lf]
lf.close()
self.models={}
for i in s:
parts = i.split()
translate_list = eval(parts[0])
rotate_list = eval(parts[1])
stl_file = eval(parts[2])
newname=os.path.split(stl_file.lower())[1]
c=1
while newname in self.models:
newname=os.path.split(stl_file.lower())[1]
newname=newname+"(%d)"%c
c+=1
stl_path = os.path.join(os.path.split(name)[0:len(os.path.split(stl_file))-1])
stl_full_path = os.path.join(stl_path[0],str(stl_file))
self.load_stl_into_model(stl_full_path,stl_file,translate_list,rotate_list[2])
def load_stl(self,event,name):
if not(os.path.exists(name)): if not(os.path.exists(name)):
return return
path = os.path.split(name)[0] path = os.path.split(name)[0]
...@@ -171,11 +173,11 @@ class showstl(wx.Window): ...@@ -171,11 +173,11 @@ class showstl(wx.Window):
#print name #print name
if name.lower().endswith(".stl"): if name.lower().endswith(".stl"):
#Filter out the path, just show the STL filename. #Filter out the path, just show the STL filename.
self.load_stl(name,name) self.load_stl_into_model(name,name)
self.Refresh() self.Refresh()
#print time.time()-t #print time.time()-t
def load_stl(self,path,name,offset=[0,0,0],rotation=0): def load_stl_into_model(self,path,name,offset=[0,0,0],rotation=0):
newname=os.path.split(name.lower())[1] newname=os.path.split(name.lower())[1]
c=1 c=1
while newname in self.models: while newname in self.models:
......
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