Commit 317cf3d4 authored by lode_leroy's avatar lode_leroy

enable command line driven operation

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@30 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b8027f69
#!/usr/bin/python
import sys import sys
import os import os
...@@ -5,5 +6,29 @@ from pycam.Gui.SimpleGui import SimpleGui ...@@ -5,5 +6,29 @@ from pycam.Gui.SimpleGui import SimpleGui
from pycam.Importers.TestModel import TestModel from pycam.Importers.TestModel import TestModel
gui = SimpleGui() gui = SimpleGui()
gui.model = TestModel()
gui.mainloop() inputfile = None
outputfile = None
display = False
for arg in sys.argv[1:]:
if arg == "-gui":
display = True
elif arg[0] != '-':
if not inputfile:
inputfile = arg
elif not outputfile:
outputfile = arg
if not inputfile:
gui.model = TestModel()
gui.mainloop()
else:
gui.open(inputfile)
if display:
gui.mainloop()
else:
gui.generateToolpath()
if outputfile:
gui.save(outputfile)
...@@ -74,55 +74,56 @@ class SimpleGui(Frame): ...@@ -74,55 +74,56 @@ class SimpleGui(Frame):
glVertex3f(0,0,size) glVertex3f(0,0,size)
glEnd() glEnd()
# stock model if True:
minx = float(self.MinX.get()) # stock model
maxx = float(self.MaxX.get()) minx = float(self.MinX.get())
miny = float(self.MinY.get()) maxx = float(self.MaxX.get())
maxy = float(self.MaxY.get()) miny = float(self.MinY.get())
minz = float(self.MinZ.get()) maxy = float(self.MaxY.get())
maxz = float(self.MaxZ.get()) minz = float(self.MinZ.get())
glBegin(GL_LINES) maxz = float(self.MaxZ.get())
glColor3f(0.3,0.3,0.3) glBegin(GL_LINES)
glColor3f(0.3,0.3,0.3)
glVertex3f(minx,miny,minz) glVertex3f(minx,miny,minz)
glVertex3f(maxx,miny,minz) glVertex3f(maxx,miny,minz)
glVertex3f(minx,maxy,minz) glVertex3f(minx,maxy,minz)
glVertex3f(maxx,maxy,minz) glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz) glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,maxz) glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,maxz) glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,maxz) glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz) glVertex3f(minx,miny,minz)
glVertex3f(minx,maxy,minz) glVertex3f(minx,maxy,minz)
glVertex3f(maxx,miny,minz) glVertex3f(maxx,miny,minz)
glVertex3f(maxx,maxy,minz) glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz) glVertex3f(minx,miny,maxz)
glVertex3f(minx,maxy,maxz) glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,miny,maxz) glVertex3f(maxx,miny,maxz)
glVertex3f(maxx,maxy,maxz) glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz) glVertex3f(minx,miny,minz)
glVertex3f(minx,miny,maxz) glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,minz) glVertex3f(maxx,miny,minz)
glVertex3f(maxx,miny,maxz) glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,minz) glVertex3f(minx,maxy,minz)
glVertex3f(minx,maxy,maxz) glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,minz) glVertex3f(maxx,maxy,minz)
glVertex3f(maxx,maxy,maxz) glVertex3f(maxx,maxy,maxz)
glEnd() glEnd()
if self.model: if self.model:
glColor3f(0.5,.5,1) glColor3f(0.5,.5,1)
...@@ -147,6 +148,10 @@ class SimpleGui(Frame): ...@@ -147,6 +148,10 @@ class SimpleGui(Frame):
def browseOpen(self): def browseOpen(self):
filename = tkFileDialog.Open(self, filetypes=[("STL files", ".stl")]).show() filename = tkFileDialog.Open(self, filetypes=[("STL files", ".stl")]).show()
if filename:
self.open(filename)
def open(self, filename):
self.model = None self.model = None
if filename: if filename:
self.InputFileName.set(filename) self.InputFileName.set(filename)
...@@ -206,8 +211,8 @@ class SimpleGui(Frame): ...@@ -206,8 +211,8 @@ class SimpleGui(Frame):
maxx = float(self.MaxX.get())+offset maxx = float(self.MaxX.get())+offset
miny = float(self.MinY.get())-offset miny = float(self.MinY.get())-offset
maxy = float(self.MaxY.get())+offset maxy = float(self.MaxY.get())+offset
minz = float(self.MinZ.get())-offset minz = float(self.MinZ.get())
maxz = float(self.MaxZ.get())+offset maxz = float(self.MaxZ.get())
samples = float(self.Samples.get()) samples = float(self.Samples.get())
lines = float(self.Lines.get()) lines = float(self.Lines.get())
layers = float(self.Layers.get()) layers = float(self.Layers.get())
...@@ -261,22 +266,25 @@ class SimpleGui(Frame): ...@@ -261,22 +266,25 @@ class SimpleGui(Frame):
elif self.Direction.get() == "y": elif self.Direction.get() == "y":
self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dy, 0, dz) self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dy, 0, dz)
elif self.Direction.get() == "xy": elif self.Direction.get() == "xy":
self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dx, dy, dz) self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dy, dy, dz)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def browseSaveAs(self): def browseSaveAs(self):
filename = tkFileDialog.SaveAs(self, filetypes=[("GCODE files", ".nc .gc .ngc")]).show() filename = tkFileDialog.SaveAs(self, filetypes=[("GCODE files", ".nc .gc .ngc")]).show()
if filename: if filename:
self.OutputFileName.set(filename) save(self, filename)
if self.toolpath:
offset = float(self.ToolRadius.get())/2 def save(self, filename):
minx = float(self.MinX.get())-offset self.OutputFileName.set(filename)
maxx = float(self.MaxX.get())+offset if self.toolpath:
miny = float(self.MinY.get())-offset offset = float(self.ToolRadius.get())/2
maxy = float(self.MaxY.get())+offset minx = float(self.MinX.get())-offset
minz = float(self.MinZ.get())-offset maxx = float(self.MaxX.get())+offset
maxz = float(self.MaxZ.get())+offset miny = float(self.MinY.get())-offset
exporter = SimpleGCodeExporter.ExportPathList(filename, self.toolpath, self.Unit.get(), minx, miny, maxz, self.FeedRate.get(), self.Speed.get()) maxy = float(self.MaxY.get())+offset
minz = float(self.MinZ.get())-offset
maxz = float(self.MaxZ.get())+offset
exporter = SimpleGCodeExporter.ExportPathList(filename, self.toolpath, self.Unit.get(), minx, miny, maxz, self.FeedRate.get(), self.Speed.get())
def createWidgets(self): def createWidgets(self):
self.ogl = OpenglWidget(self, width=600, height=500, double=1) self.ogl = OpenglWidget(self, width=600, height=500, double=1)
......
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