Commit 2d0d08ea authored by lode_leroy's avatar lode_leroy

namespace cleanups

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@72 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2e72bc67
...@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter ...@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt from math import sqrt
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLU import * import OpenGL.GLU as GLU
from OpenGL.GLUT import * GL_enabled = True
except: except:
pass GL_enabled = False
class CylindricalCutter(BaseCutter): class CylindricalCutter(BaseCutter):
...@@ -26,15 +26,17 @@ class CylindricalCutter(BaseCutter): ...@@ -26,15 +26,17 @@ class CylindricalCutter(BaseCutter):
return "CylindricalCutter<%s,%s>" % (self.location,self.radius) return "CylindricalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self): def to_OpenGL(self):
glPushMatrix() if not GL_enabled:
glTranslate(self.center.x, self.center.y, self.center.z) return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_cylinder"): if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric() self._cylinder = GLU.gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10) GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
if not hasattr(self,"_disk"): if not hasattr(self,"_disk"):
self._disk = gluNewQuadric() self._disk = GLU.gluNewQuadric()
gluDisk(self._disk, 0, self.radius, 10, 10) GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
glPopMatrix() GL.glPopMatrix()
def moveto(self, location): def moveto(self, location):
BaseCutter.moveto(self, location) BaseCutter.moveto(self, location)
......
...@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter ...@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt from math import sqrt
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLU import * import OpenGL.GLU as GLU
from OpenGL.GLUT import * GL_enabled = True
except: except:
pass GL_enabled = False
class SphericalCutter(BaseCutter): class SphericalCutter(BaseCutter):
...@@ -26,15 +26,17 @@ class SphericalCutter(BaseCutter): ...@@ -26,15 +26,17 @@ class SphericalCutter(BaseCutter):
return "SphericalCutter<%s,%s>" % (self.location,self.radius) return "SphericalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self): def to_OpenGL(self):
glPushMatrix() if not GL_enabled:
glTranslate(self.center.x, self.center.y, self.center.z) return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_sphere"): if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric() self._sphere = GLU.gluNewQuadric()
gluSphere(self._sphere, self.radius, 10, 10) GLU.gluSphere(self._sphere, self.radius, 10, 10)
if not hasattr(self,"_cylinder"): if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric() self._cylinder = GLU.gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10) GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
glPopMatrix() GL.glPopMatrix()
def moveto(self, location): def moveto(self, location):
BaseCutter.moveto(self, location) BaseCutter.moveto(self, location)
......
...@@ -8,11 +8,12 @@ from pycam.Cutters.BaseCutter import BaseCutter ...@@ -8,11 +8,12 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt from math import sqrt
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLU import * import OpenGL.GLU as GLU
from OpenGL.GLUT import * import OpenGL.GLUT as GLUT
GL_enabled = True
except: except:
pass GL_enabled = False
class ToroidalCutter(BaseCutter): class ToroidalCutter(BaseCutter):
...@@ -30,19 +31,21 @@ class ToroidalCutter(BaseCutter): ...@@ -30,19 +31,21 @@ class ToroidalCutter(BaseCutter):
return "ToroidalCutter<%s,%f,R=%f,r=%f>" % (self.location,self.radius,self.majorradius,self.minorradius) return "ToroidalCutter<%s,%f,R=%f,r=%f>" % (self.location,self.radius,self.majorradius,self.minorradius)
def to_OpenGL(self): def to_OpenGL(self):
glPushMatrix() if not GL_enabled:
glTranslate(self.center.x, self.center.y, self.center.z) return
glutSolidTorus(self.minorradius, self.majorradius, 10, 20) GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
if not hasattr(self,"_cylinder"): if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric() self._cylinder = GLU.gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20) GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20)
glPopMatrix() GL.glPopMatrix()
glPushMatrix() GL.glPushMatrix()
glTranslate(self.location.x, self.location.y, self.location.z) GL.glTranslate(self.location.x, self.location.y, self.location.z)
if not hasattr(self,"_disk"): if not hasattr(self,"_disk"):
self._disk = gluNewQuadric() self._disk = GLU.gluNewQuadric()
gluDisk(self._disk, 0, self.majorradius, 20, 10) GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
glPopMatrix() GL.glPopMatrix()
def moveto(self, location): def moveto(self, location):
BaseCutter.moveto(self, location) BaseCutter.moveto(self, location)
......
list = [ "SimpleGCodeExporter", "SVGExporter" ] list = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter" ]
__all__ = list __all__ = list
...@@ -4,11 +4,10 @@ from Line import * ...@@ -4,11 +4,10 @@ from Line import *
from Triangle import * from Triangle import *
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLUT import * GL_enabled = True
from OpenGL.GLU import *
except: except:
pass GL_enabled = False
class Model: class Model:
id = 0 id = 0
...@@ -21,12 +20,12 @@ class Model: ...@@ -21,12 +20,12 @@ class Model:
def to_OpenGL(self): def to_OpenGL(self):
if True: if True:
glBegin(GL_TRIANGLES) GL.glBegin(GL.GL_TRIANGLES)
for t in self._triangles: for t in self._triangles:
glVertex3f(t.p1.x, t.p1.y, t.p1.z) GL.glVertex3f(t.p1.x, t.p1.y, t.p1.z)
glVertex3f(t.p2.x, t.p2.y, t.p2.z) GL.glVertex3f(t.p2.x, t.p2.y, t.p2.z)
glVertex3f(t.p3.x, t.p3.y, t.p3.z) GL.glVertex3f(t.p3.x, t.p3.y, t.p3.z)
glEnd() GL.glEnd()
else: else:
for t in self._triangles: for t in self._triangles:
t.to_OpenGL() t.to_OpenGL()
......
...@@ -3,15 +3,13 @@ from Plane import * ...@@ -3,15 +3,13 @@ from Plane import *
from utils import * from utils import *
from Line import * from Line import *
ORIENTATION_CCW = 2
ORIENTATION_CW = 3
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLU import * import OpenGL.GLU as GLU
from OpenGL.GLUT import * import OpenGL.GLUT as GLUT
GL_enabled = True
except: except:
pass GL_enabled = False
class Triangle: class Triangle:
id = 0 id = 0
...@@ -42,51 +40,53 @@ class Triangle: ...@@ -42,51 +40,53 @@ class Triangle:
return "triangle%d" % self.id return "triangle%d" % self.id
def to_OpenGL(self): def to_OpenGL(self):
glBegin(GL_TRIANGLES) if not GL_enabled:
glVertex3f(self.p1.x, self.p1.y, self.p1.z) return
glVertex3f(self.p2.x, self.p2.y, self.p2.z) GL.glBegin(GL.GL_TRIANGLES)
glVertex3f(self.p3.x, self.p3.y, self.p3.z) GL.glVertex3f(self.p1.x, self.p1.y, self.p1.z)
glEnd() GL.glVertex3f(self.p2.x, self.p2.y, self.p2.z)
GL.glVertex3f(self.p3.x, self.p3.y, self.p3.z)
GL.glEnd()
if False: # display surface normals if False: # display surface normals
n = self.normal() n = self.normal()
c = self.center() c = self.center()
d = 0.5 d = 0.5
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glVertex3f(c.x, c.y, c.z) GL.glVertex3f(c.x, c.y, c.z)
glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d) GL.glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
glEnd() GL.glEnd()
if False and hasattr(self, "_middle"): # display bounding sphere if False and hasattr(self, "_middle"): # display bounding sphere
glPushMatrix() GL.glPushMatrix()
glTranslate(self._middle.x, self._middle.y, self._middle.z) GL.glTranslate(self._middle.x, self._middle.y, self._middle.z)
if not hasattr(self,"_sphere"): if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric() self._sphere = GLU.gluNewQuadric()
gluSphere(self._sphere, self._radius, 10, 10) GLU.gluSphere(self._sphere, self._radius, 10, 10)
glPopMatrix() GL.glPopMatrix()
if True: # draw triangle id on triangle face if True: # draw triangle id on triangle face
glPushMatrix() GL.glPushMatrix()
cc = glGetFloatv(GL_CURRENT_COLOR) cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
c = self.center() c = self.center()
glTranslate(c.x,c.y,c.z) GL.glTranslate(c.x,c.y,c.z)
p12=self.p1.add(self.p2).mul(0.5) p12=self.p1.add(self.p2).mul(0.5)
p3_12=self.p3.sub(p12).normalize() p3_12=self.p3.sub(p12).normalize()
p2_1=self.p1.sub(self.p2).normalize() p2_1=self.p1.sub(self.p2).normalize()
pn=p2_1.cross(p3_12) pn=p2_1.cross(p3_12)
glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1)) GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
n = self.normal().mul(0.01) n = self.normal().mul(0.01)
glTranslatef(n.x,n.y,n.z) GL.glTranslatef(n.x,n.y,n.z)
glScalef(0.003,0.003,0.003) GL.glScalef(0.003,0.003,0.003)
w = 0 w = 0
for ch in str(self.id): for ch in str(self.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch)) w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0) GL.glTranslate(-w/2,0,0)
glColor4f(1,1,1,0) GL.glColor4f(1,1,1,0)
for ch in str(self.id): for ch in str(self.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch)) GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix() GL.glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3]) GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
if False: # draw point id on triangle face if False: # draw point id on triangle face
cc = glGetFloatv(GL_CURRENT_COLOR) cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
c = self.center() c = self.center()
p12=self.p1.add(self.p2).mul(0.5) p12=self.p1.add(self.p2).mul(0.5)
p3_12=self.p3.sub(p12).normalize() p3_12=self.p3.sub(p12).normalize()
...@@ -94,21 +94,21 @@ class Triangle: ...@@ -94,21 +94,21 @@ class Triangle:
pn=p2_1.cross(p3_12) pn=p2_1.cross(p3_12)
n = self.normal().mul(0.01) n = self.normal().mul(0.01)
for p in (self.p1,self.p2,self.p3): for p in (self.p1,self.p2,self.p3):
glPushMatrix() GL.glPushMatrix()
pp = p.sub(p.sub(c).mul(0.3)) pp = p.sub(p.sub(c).mul(0.3))
glTranslate(pp.x,pp.y,pp.z) GL.glTranslate(pp.x,pp.y,pp.z)
glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1)) GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
glTranslatef(n.x,n.y,n.z) GL.glTranslatef(n.x,n.y,n.z)
glScalef(0.001,0.001,0.001) GL.glScalef(0.001,0.001,0.001)
w = 0 w = 0
for ch in str(p.id): for ch in str(p.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch)) w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0) GL.glTranslate(-w/2,0,0)
glColor4f(0.5,1,0.5,0) GL.glColor4f(0.5,1,0.5,0)
for ch in str(p.id): for ch in str(p.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch)) GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix() GL.glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3]) GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
def normal(self): def normal(self):
if not hasattr(self, '_normal'): if not hasattr(self, '_normal'):
......
...@@ -4,11 +4,10 @@ import math ...@@ -4,11 +4,10 @@ import math
import pycam import pycam
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.GLUT import * GL_enabled = True
from OpenGL.GLU import *
except: except:
pass GL_enabled = False
class Node: class Node:
def __repr__(self): def __repr__(self):
...@@ -58,35 +57,37 @@ class kdtree: ...@@ -58,35 +57,37 @@ class kdtree:
return "(%s,%d:%g,%s)" % (self.lo,self.cutdim,self.cutval,self.hi) return "(%s,%d:%g,%s)" % (self.lo,self.cutdim,self.cutval,self.hi)
def to_OpenGL(self,minx,maxx,miny,maxy,minz,maxz): def to_OpenGL(self,minx,maxx,miny,maxy,minz,maxz):
if not GL_enabled:
return
if self.bucket: if self.bucket:
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glVertex3d(minx,miny,minz) GL.glVertex3d(minx,miny,minz)
glVertex3d(minx,miny,maxz) GL.glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,minz) GL.glVertex3d(minx,maxy,minz)
glVertex3d(minx,maxy,maxz) GL.glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,minz) GL.glVertex3d(maxx,miny,minz)
glVertex3d(maxx,miny,maxz) GL.glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,minz) GL.glVertex3d(maxx,maxy,minz)
glVertex3d(maxx,maxy,maxz) GL.glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz) GL.glVertex3d(minx,miny,minz)
glVertex3d(maxx,miny,minz) GL.glVertex3d(maxx,miny,minz)
glVertex3d(minx,maxy,minz) GL.glVertex3d(minx,maxy,minz)
glVertex3d(maxx,maxy,minz) GL.glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz) GL.glVertex3d(minx,miny,maxz)
glVertex3d(maxx,miny,maxz) GL.glVertex3d(maxx,miny,maxz)
glVertex3d(minx,maxy,maxz) GL.glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,maxy,maxz) GL.glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz) GL.glVertex3d(minx,miny,minz)
glVertex3d(minx,maxy,minz) GL.glVertex3d(minx,maxy,minz)
glVertex3d(maxx,miny,minz) GL.glVertex3d(maxx,miny,minz)
glVertex3d(maxx,maxy,minz) GL.glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz) GL.glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,maxz) GL.glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,maxz) GL.glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,maxz) GL.glVertex3d(maxx,maxy,maxz)
glEnd() GL.glEnd()
elif self.dim==6: elif self.dim==6:
if self.cutdim == 0 or self.cutdim == 2: if self.cutdim == 0 or self.cutdim == 2:
self.lo.to_OpenGL(minx,self.cutval,miny,maxy,minz,maxz) self.lo.to_OpenGL(minx,self.cutval,miny,maxy,minz,maxz)
......
#!/usr/bin/python #!/usr/bin/python
import sys import sys
sys.path.insert(0,'.') sys.path.insert(0,'.')
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from OpenGL.GL import * import OpenGL.GL as GL
from OpenGL.Tk import * import OpenGL.Tk as Tk
from OpenGL.GLUT import * import OpenGL.GLUT as GLUT
from OpenGL.GLU import *
import tkFileDialog import tkFileDialog
from pycam import * from pycam import *
...@@ -22,56 +20,56 @@ from pycam.Exporters import * ...@@ -22,56 +20,56 @@ from pycam.Exporters import *
# leave 10% margin around the model # leave 10% margin around the model
DEFAULT_MARGIN = 0.1 DEFAULT_MARGIN = 0.1
class OpenglWidget(Opengl): class OpenglWidget(Tk.Opengl):
def __init__(self, master=None, cnf={}, **kw): def __init__(self, master=None, cnf={}, **kw):
Opengl.__init__(self, master, kw) Tk.Opengl.__init__(self, master, kw)
glutInit() GLUT.glutInit()
glShadeModel(GL_FLAT) GL.glShadeModel(GL.GL_FLAT)
# glShadeModel(GL_SMOOTH) # GL.glShadeModel(GL.GL_SMOOTH)
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glMaterial(GL_FRONT_AND_BACK, GL_AMBIENT, (0.1, 0.1, 0.1, 1.0)) GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
glMaterial(GL_FRONT_AND_BACK, GL_SPECULAR, (0.1, 0.1, 0.1, 1.0)) GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, (0.1, 0.1, 0.1, 1.0))
glMaterial(GL_FRONT_AND_BACK, GL_SHININESS, (0.5)) GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, (0.5))
# glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL_LINE)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
def basic_lighting(self): def basic_lighting(self):
Opengl.basic_lighting(self) Tk.Opengl.basic_lighting(self)
# "Let There Be Light" # "Let There Be Light"
glPushMatrix() GL.glPushMatrix()
glLoadIdentity() GL.glLoadIdentity()
glLightfv(GL_LIGHT0, GL_AMBIENT, (0.5, 0.5, 0.5, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, (0.5, 0.5, 0.5, 1.0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
glLightfv(GL_LIGHT0, GL_SPECULAR, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, (1.0, 1.0, 1.0, 1.0))
glLightfv(GL_LIGHT0, GL_POSITION, (2, 2, +10, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (2, 2, +10, 1.0))
glEnable(GL_LIGHT0) GL.glEnable(GL.GL_LIGHT0)
glDisable(GL_LIGHTING) GL.glDisable(GL.GL_LIGHTING)
glPopMatrix() GL.glPopMatrix()
self.master.resetView() self.master.resetView()
class SimpleGui(Frame): class SimpleGui(Tk.Frame):
def draw_string(self, x, y, z, p, s, scale=.01): def draw_string(self, x, y, z, p, s, scale=.01):
glPushMatrix() GL.glPushMatrix()
glTranslatef(x,y,z) GL.glTranslatef(x,y,z)
if p == 'xy': if p == 'xy':
pass pass
elif p == 'yz': elif p == 'yz':
glRotatef(90, 0, 1, 0) GL.glRotatef(90, 0, 1, 0)
glRotatef(90, 0, 0, 1) GL.glRotatef(90, 0, 0, 1)
elif p == 'xz': elif p == 'xz':
glRotatef(90, 0, 1, 0) GL.glRotatef(90, 0, 1, 0)
glRotatef(90, 0, 0, 1) GL.glRotatef(90, 0, 0, 1)
glRotatef(-90, 0, 1, 0) GL.glRotatef(-90, 0, 1, 0)
glScalef(scale,scale,scale) GL.glScalef(scale,scale,scale)
for c in str(s): for c in str(s):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(c)) GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(c))
glPopMatrix() GL.glPopMatrix()
def Redraw(self, event=None): def Redraw(self, event=None):
# default scale and orientation # default scale and orientation
glTranslatef(0,0,-2) GL.glTranslatef(0,0,-2)
if self.Unit.get() == "mm": if self.Unit.get() == "mm":
size = 100 size = 100
...@@ -79,23 +77,23 @@ class SimpleGui(Frame): ...@@ -79,23 +77,23 @@ class SimpleGui(Frame):
size = 5 size = 5
# axes # axes
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glColor3f(1,0,0) GL.glColor3f(1,0,0)
glVertex3f(0,0,0) GL.glVertex3f(0,0,0)
glVertex3f(size,0,0) GL.glVertex3f(size,0,0)
glEnd() GL.glEnd()
self.draw_string(size,0,0,'xy',"X") self.draw_string(size,0,0,'xy',"X")
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glColor3f(0,1,0) GL.glColor3f(0,1,0)
glVertex3f(0,0,0) GL.glVertex3f(0,0,0)
glVertex3f(0,size,0) GL.glVertex3f(0,size,0)
glEnd() GL.glEnd()
self.draw_string(0,size,0,'yz',"Y") self.draw_string(0,size,0,'yz',"Y")
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glColor3f(0,0,1) GL.glColor3f(0,0,1)
glVertex3f(0,0,0) GL.glVertex3f(0,0,0)
glVertex3f(0,0,size) GL.glVertex3f(0,0,size)
glEnd() GL.glEnd()
self.draw_string(0,0,size,'xz',"Z") self.draw_string(0,0,size,'xz',"Z")
if True: if True:
...@@ -106,68 +104,68 @@ class SimpleGui(Frame): ...@@ -106,68 +104,68 @@ class SimpleGui(Frame):
maxy = float(self.MaxY.get()) maxy = float(self.MaxY.get())
minz = float(self.MinZ.get()) minz = float(self.MinZ.get())
maxz = float(self.MaxZ.get()) maxz = float(self.MaxZ.get())
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glColor3f(0.3,0.3,0.3) GL.glColor3f(0.3,0.3,0.3)
glVertex3f(minx,miny,minz) GL.glVertex3f(minx,miny,minz)
glVertex3f(maxx,miny,minz) GL.glVertex3f(maxx,miny,minz)
glVertex3f(minx,maxy,minz) GL.glVertex3f(minx,maxy,minz)
glVertex3f(maxx,maxy,minz) GL.glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz) GL.glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,maxz) GL.glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,maxz) GL.glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,maxz) GL.glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz) GL.glVertex3f(minx,miny,minz)
glVertex3f(minx,maxy,minz) GL.glVertex3f(minx,maxy,minz)
glVertex3f(maxx,miny,minz) GL.glVertex3f(maxx,miny,minz)
glVertex3f(maxx,maxy,minz) GL.glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz) GL.glVertex3f(minx,miny,maxz)
glVertex3f(minx,maxy,maxz) GL.glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,miny,maxz) GL.glVertex3f(maxx,miny,maxz)
glVertex3f(maxx,maxy,maxz) GL.glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz) GL.glVertex3f(minx,miny,minz)
glVertex3f(minx,miny,maxz) GL.glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,minz) GL.glVertex3f(maxx,miny,minz)
glVertex3f(maxx,miny,maxz) GL.glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,minz) GL.glVertex3f(minx,maxy,minz)
glVertex3f(minx,maxy,maxz) GL.glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,minz) GL.glVertex3f(maxx,maxy,minz)
glVertex3f(maxx,maxy,maxz) GL.glVertex3f(maxx,maxy,maxz)
glEnd() GL.glEnd()
if self.model: if self.model:
glColor3f(0.5,.5,1) GL.glColor3f(0.5,.5,1)
self.model.to_OpenGL() self.model.to_OpenGL()
if self.toolpath: if self.toolpath:
last = None last = None
for path in self.toolpath: for path in self.toolpath:
if last: if last:
glColor3f(.5,1,.5) GL.glColor3f(.5,1,.5)
glBegin(GL_LINES) GL.glBegin(GL.GL_LINES)
glVertex3f(last.x,last.y,last.z) GL.glVertex3f(last.x,last.y,last.z)
last = path.points[0] last = path.points[0]
glVertex3f(last.x,last.y,last.z) GL.glVertex3f(last.x,last.y,last.z)
glEnd() GL.glEnd()
glColor3f(1,.5,.5) GL.glColor3f(1,.5,.5)
glBegin(GL_LINE_STRIP) GL.glBegin(GL.GL_LINE_STRIP)
for point in path.points: for point in path.points:
glVertex3f(point.x,point.y,point.z) GL.glVertex3f(point.x,point.y,point.z)
glEnd() GL.glEnd()
last = path.points[-1] last = path.points[-1]
def browseOpen(self): def browseOpen(self):
...@@ -339,142 +337,142 @@ class SimpleGui(Frame): ...@@ -339,142 +337,142 @@ class SimpleGui(Frame):
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)
self.TopFrame = Frame(self).pack(side=TOP, expand=0, fill=X) self.TopFrame = Tk.Frame(self).pack(side=Tk.TOP, expand=0, fill=Tk.X)
self.InputFileFrame = Frame(self.TopFrame) self.InputFileFrame = Tk.Frame(self.TopFrame)
self.InputFileFrame.pack(side=TOP, anchor=W, expand=0, fill=X) self.InputFileFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Label(self.InputFileFrame, text="Input File: ").pack(side=LEFT, anchor=W) Tk.Label(self.InputFileFrame, text="Input File: ").pack(side=Tk.LEFT, anchor=Tk.W)
self.InputFileName = StringVar() self.InputFileName = Tk.StringVar()
Entry(self.InputFileFrame, textvariable=self.InputFileName).pack(side=LEFT, expand=1, fill=X) Tk.Entry(self.InputFileFrame, textvariable=self.InputFileName).pack(side=Tk.LEFT, expand=1, fill=Tk.X)
Button(self.InputFileFrame, text="Import...",command=self.browseOpen).pack(side=RIGHT) Tk.Button(self.InputFileFrame, text="Import...",command=self.browseOpen).pack(side=Tk.RIGHT)
self.CutterFrame = Frame(self.TopFrame) self.CutterFrame = Tk.Frame(self.TopFrame)
self.CutterFrame.pack(side=TOP, anchor=W) self.CutterFrame.pack(side=Tk.TOP, anchor=Tk.W)
Label(self.CutterFrame, text="Tool: ").pack(side=LEFT) Tk.Label(self.CutterFrame, text="Tool: ").pack(side=Tk.LEFT)
self.CutterName = StringVar() self.CutterName = Tk.StringVar()
self.CutterName.set(Cutters.list[0]) self.CutterName.set(Cutters.list[0])
for cutter in Cutters.list: for cutter in Cutters.list:
Radiobutton(self.CutterFrame, text=cutter, variable=self.CutterName, value=cutter).pack(side=LEFT) Tk.Radiobutton(self.CutterFrame, text=cutter, variable=self.CutterName, value=cutter).pack(side=Tk.LEFT)
self.PathGeneratorFrame = Frame(self.TopFrame) self.PathGeneratorFrame = Tk.Frame(self.TopFrame)
self.PathGeneratorFrame.pack(side=TOP, expand=0, anchor=W) self.PathGeneratorFrame.pack(side=Tk.TOP, expand=0, anchor=Tk.W)
Label(self.PathGeneratorFrame, text="PathGenerator: ").pack(side=LEFT) Tk.Label(self.PathGeneratorFrame, text="PathGenerator: ").pack(side=Tk.LEFT)
self.PathGeneratorName = StringVar() self.PathGeneratorName = Tk.StringVar()
self.PathGeneratorName.set(PathGenerators.list[0]) self.PathGeneratorName.set(PathGenerators.list[0])
for PathGenerator in PathGenerators.list: for PathGenerator in PathGenerators.list:
Radiobutton(self.PathGeneratorFrame, text=PathGenerator, variable=self.PathGeneratorName, value=PathGenerator).pack(side=LEFT) Tk.Radiobutton(self.PathGeneratorFrame, text=PathGenerator, variable=self.PathGeneratorName, value=PathGenerator).pack(side=Tk.LEFT)
self.PathProcessorFrame = Frame(self.TopFrame) self.PathProcessorFrame = Tk.Frame(self.TopFrame)
self.PathProcessorFrame.pack(side=TOP, expand=0, anchor=W) self.PathProcessorFrame.pack(side=Tk.TOP, expand=0, anchor=Tk.W)
Label(self.PathProcessorFrame, text="Postprocessor: ").pack(side=LEFT) Tk.Label(self.PathProcessorFrame, text="Postprocessor: ").pack(side=Tk.LEFT)
self.PathProcessorName = StringVar() self.PathProcessorName = Tk.StringVar()
self.PathProcessorName.set(PathProcessors.list[0]) self.PathProcessorName.set(PathProcessors.list[0])
for option in PathProcessors.list: for option in PathProcessors.list:
Radiobutton(self.PathProcessorFrame, text=option, variable=self.PathProcessorName, value=option).pack(side=LEFT) Tk.Radiobutton(self.PathProcessorFrame, text=option, variable=self.PathProcessorName, value=option).pack(side=Tk.LEFT)
self.ConfigurationFrame = Frame(self.TopFrame) self.ConfigurationFrame = Tk.Frame(self.TopFrame)
self.ConfigurationFrame.pack(side=TOP, anchor=W, expand=0, fill=X) self.ConfigurationFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Label(self.ConfigurationFrame, text="Tool Radius: ").pack(side=LEFT) Tk.Label(self.ConfigurationFrame, text="Tool Radius: ").pack(side=Tk.LEFT)
self.ToolRadius = StringVar() self.ToolRadius = Tk.StringVar()
self.ToolRadius.set("1.0") self.ToolRadius.set("1.0")
s = Spinbox(self.ConfigurationFrame, width=5, text='Radius', from_=0.1, to=5.0, increment=0.1, format="%2.1f") s = Tk.Spinbox(self.ConfigurationFrame, width=5, text='Radius', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s.pack(side=LEFT) s.pack(side=Tk.LEFT)
s["textvariable"] = self.ToolRadius s["textvariable"] = self.ToolRadius
Label(self.ConfigurationFrame, text="Torus Radius: ").pack(side=LEFT) Tk.Label(self.ConfigurationFrame, text="Torus Radius: ").pack(side=Tk.LEFT)
self.TorusRadius = StringVar() self.TorusRadius = Tk.StringVar()
self.TorusRadius.set("0.25") self.TorusRadius.set("0.25")
s = Spinbox(self.ConfigurationFrame, width=5, text='Toroid', from_=0.1, to=5.0, increment=0.1, format="%2.1f") s = Tk.Spinbox(self.ConfigurationFrame, width=5, text='Toroid', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s["textvariable"] = self.TorusRadius s["textvariable"] = self.TorusRadius
s.pack(side=LEFT) s.pack(side=Tk.LEFT)
Label(self.ConfigurationFrame, text="Unit: ").pack(side=LEFT) Tk.Label(self.ConfigurationFrame, text="Unit: ").pack(side=Tk.LEFT)
self.Unit = StringVar() self.Unit = Tk.StringVar()
self.Unit.set("mm") self.Unit.set("mm")
Radiobutton(self.ConfigurationFrame, text="mm", variable=self.Unit, value="mm", command=self.ogl.tkRedraw).pack(side=LEFT) Tk.Radiobutton(self.ConfigurationFrame, text="mm", variable=self.Unit, value="mm", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Radiobutton(self.ConfigurationFrame, text="in", variable=self.Unit, value="in", command=self.ogl.tkRedraw).pack(side=LEFT) Tk.Radiobutton(self.ConfigurationFrame, text="in", variable=self.Unit, value="in", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Label(self.ConfigurationFrame, text="Dir: ").pack(side=LEFT) Tk.Label(self.ConfigurationFrame, text="Dir: ").pack(side=Tk.LEFT)
self.Direction = StringVar() self.Direction = Tk.StringVar()
self.Direction.set("x") self.Direction.set("x")
Radiobutton(self.ConfigurationFrame, text="x", variable=self.Direction, value="x", command=self.ogl.tkRedraw).pack(side=LEFT) Tk.Radiobutton(self.ConfigurationFrame, text="x", variable=self.Direction, value="x", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Radiobutton(self.ConfigurationFrame, text="y", variable=self.Direction, value="y", command=self.ogl.tkRedraw).pack(side=LEFT) Tk.Radiobutton(self.ConfigurationFrame, text="y", variable=self.Direction, value="y", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Radiobutton(self.ConfigurationFrame, text="xy", variable=self.Direction, value="xy", command=self.ogl.tkRedraw).pack(side=LEFT) Tk.Radiobutton(self.ConfigurationFrame, text="xy", variable=self.Direction, value="xy", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
self.MinX = StringVar() self.MinX = Tk.StringVar()
self.MinX.set("-7") self.MinX.set("-7")
self.MinY = StringVar() self.MinY = Tk.StringVar()
self.MinY.set("-7") self.MinY.set("-7")
self.MinZ = StringVar() self.MinZ = Tk.StringVar()
self.MinZ.set("0") self.MinZ.set("0")
self.MaxX = StringVar() self.MaxX = Tk.StringVar()
self.MaxX.set("+7") self.MaxX.set("+7")
self.MaxY = StringVar() self.MaxY = Tk.StringVar()
self.MaxY.set("+7") self.MaxY.set("+7")
self.MaxZ = StringVar() self.MaxZ = Tk.StringVar()
self.MaxZ.set("+3") self.MaxZ.set("+3")
self.StockModelFrame = Frame(self.TopFrame) self.StockModelFrame = Tk.Frame(self.TopFrame)
self.StockModelFrame.pack(side=TOP, anchor=W, expand=0, fill=X) self.StockModelFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Label(self.StockModelFrame, text="Min X").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Min X").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MinX, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MinX, width=6).pack(side=Tk.LEFT)
Label(self.StockModelFrame, text="Min Y").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Min Y").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MinY, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MinY, width=6).pack(side=Tk.LEFT)
Label(self.StockModelFrame, text="Min Z").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Min Z").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MinZ, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MinZ, width=6).pack(side=Tk.LEFT)
Label(self.StockModelFrame, text="Max X").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Max X").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxX, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MaxX, width=6).pack(side=Tk.LEFT)
Label(self.StockModelFrame, text="Max Y").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Max Y").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxY, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MaxY, width=6).pack(side=Tk.LEFT)
Label(self.StockModelFrame, text="Max Z").pack(side=LEFT) Tk.Label(self.StockModelFrame, text="Max Z").pack(side=Tk.LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxZ, width=6).pack(side=LEFT) Tk.Entry(self.StockModelFrame, textvariable=self.MaxZ, width=6).pack(side=Tk.LEFT)
self.ConfigFrame = Frame(self.TopFrame) self.ConfigFrame = Tk.Frame(self.TopFrame)
self.ConfigFrame.pack(side=TOP, anchor=W, expand=0, fill=X) self.ConfigFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
self.Layers = StringVar() self.Layers = Tk.StringVar()
self.Layers.set("1") self.Layers.set("1")
Label(self.ConfigFrame, text="Layers").pack(side=LEFT) Tk.Label(self.ConfigFrame, text="Layers").pack(side=Tk.LEFT)
Entry(self.ConfigFrame, textvariable=self.Layers, width=6).pack(side=LEFT) Tk.Entry(self.ConfigFrame, textvariable=self.Layers, width=6).pack(side=Tk.LEFT)
self.Samples = StringVar() self.Samples = Tk.StringVar()
self.Samples.set("50") self.Samples.set("50")
Label(self.ConfigFrame, text="Samples").pack(side=LEFT) Tk.Label(self.ConfigFrame, text="Samples").pack(side=Tk.LEFT)
Entry(self.ConfigFrame, textvariable=self.Samples, width=6).pack(side=LEFT) Tk.Entry(self.ConfigFrame, textvariable=self.Samples, width=6).pack(side=Tk.LEFT)
self.Lines = StringVar() self.Lines = Tk.StringVar()
self.Lines.set("20") self.Lines.set("20")
Label(self.ConfigFrame, text="Lines").pack(side=LEFT) Tk.Label(self.ConfigFrame, text="Lines").pack(side=Tk.LEFT)
Entry(self.ConfigFrame, textvariable=self.Lines, width=6).pack(side=LEFT) Tk.Entry(self.ConfigFrame, textvariable=self.Lines, width=6).pack(side=Tk.LEFT)
Button(self.ConfigFrame, text="Generate Toolpath", command=self.generateToolpath).pack(side=RIGHT) Tk.Button(self.ConfigFrame, text="Generate Toolpath", command=self.generateToolpath).pack(side=Tk.RIGHT)
self.OutputFileFrame = Frame(self.TopFrame) self.OutputFileFrame = Tk.Frame(self.TopFrame)
self.OutputFileFrame.pack(side=TOP, anchor=W, expand=0, fill=X) self.OutputFileFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Label(self.OutputFileFrame, text= "Output File: ").pack(side=LEFT) Tk.Label(self.OutputFileFrame, text= "Output File: ").pack(side=Tk.LEFT)
self.OutputFileName = StringVar() self.OutputFileName = Tk.StringVar()
self.OutputFileField = Entry(self.OutputFileFrame, textvariable=self.OutputFileName).pack(side=LEFT, expand=1, fill=X) self.OutputFileField = Tk.Entry(self.OutputFileFrame, textvariable=self.OutputFileName).pack(side=Tk.LEFT, expand=1, fill=Tk.X)
self.FeedRate = StringVar() self.FeedRate = Tk.StringVar()
self.FeedRate.set("200") self.FeedRate.set("200")
Label(self.OutputFileFrame, text="FeedRate").pack(side=LEFT) Tk.Label(self.OutputFileFrame, text="FeedRate").pack(side=Tk.LEFT)
Entry(self.OutputFileFrame, textvariable=self.FeedRate, width=6).pack(side=LEFT) Tk.Entry(self.OutputFileFrame, textvariable=self.FeedRate, width=6).pack(side=Tk.LEFT)
self.Speed = StringVar() self.Speed = Tk.StringVar()
self.Speed.set("1000") self.Speed.set("1000")
Label(self.OutputFileFrame, text="Speed").pack(side=LEFT) Tk.Label(self.OutputFileFrame, text="Speed").pack(side=Tk.LEFT)
Entry(self.OutputFileFrame, textvariable=self.Speed, width=6).pack(side=LEFT) Tk.Entry(self.OutputFileFrame, textvariable=self.Speed, width=6).pack(side=Tk.LEFT)
self.OutputFileBrowse = Button(self.OutputFileFrame, text="Export...", command=self.browseSaveAs).pack(side=RIGHT) self.OutputFileBrowse = Tk.Button(self.OutputFileFrame, text="Export...", command=self.browseSaveAs).pack(side=Tk.RIGHT)
self.ViewFrame = Frame(self.TopFrame) self.ViewFrame = Tk.Frame(self.TopFrame)
self.ViewFrame.pack(side=TOP, anchor=W, expand=0) self.ViewFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0)
Label(self.ViewFrame, text="View: ").pack(side=LEFT) Tk.Label(self.ViewFrame, text="View: ").pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Reset", command=self.resetView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Reset", command=self.resetView).pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Front", command=self.frontView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Front", command=self.frontView).pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Back", command=self.backView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Back", command=self.backView).pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Left", command=self.leftView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Left", command=self.leftView).pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Right", command=self.rightView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Right", command=self.rightView).pack(side=Tk.LEFT)
Button(self.ViewFrame, text="Top", command=self.topView).pack(side=LEFT) Tk.Button(self.ViewFrame, text="Top", command=self.topView).pack(side=Tk.LEFT)
self.ogl.pack(side='bottom', expand=1, fill=BOTH) self.ogl.pack(side='bottom', expand=1, fill=Tk.BOTH)
self.ogl.set_background(0,0,0) self.ogl.set_background(0,0,0)
self.ogl.bind('<Button-2>',self.ogl.tkRecordMouse) self.ogl.bind('<Button-2>',self.ogl.tkRecordMouse)
self.ogl.bind('<B2-Motion>', self.ogl.tkTranslate) self.ogl.bind('<B2-Motion>', self.ogl.tkTranslate)
...@@ -484,10 +482,10 @@ class SimpleGui(Frame): ...@@ -484,10 +482,10 @@ class SimpleGui(Frame):
self.ogl.bind('<B3-Motion>', self.ogl.tkScale) self.ogl.bind('<B3-Motion>', self.ogl.tkScale)
self.ogl.redraw = self.Redraw self.ogl.redraw = self.Redraw
self.pack(expand=1, fill=BOTH) self.pack(expand=1, fill=Tk.BOTH)
def __init__(self, master=None): def __init__(self, master=None):
Frame.__init__(self, master) Tk.Frame.__init__(self, master)
self.model = None self.model = None
self.toolpath = None self.toolpath = None
self.createWidgets() self.createWidgets()
...@@ -517,49 +515,49 @@ class SimpleGui(Frame): ...@@ -517,49 +515,49 @@ class SimpleGui(Frame):
self.toolpath = pc.GenerateToolPath(x0,x1,y0,y1,z0,z1,dx,dy,dz) self.toolpath = pc.GenerateToolPath(x0,x1,y0,y1,z0,z1,dx,dy,dz)
def resetView(self): def resetView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
glRotatef(110,1.0,0.0,0.0) GL.glRotatef(110,1.0,0.0,0.0)
glRotatef(180,0.0,1.0,0.0) GL.glRotatef(180,0.0,1.0,0.0)
glRotatef(160,0.0,0.0,1.0) GL.glRotatef(160,0.0,0.0,1.0)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def frontView(self): def frontView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0) GL.glRotatef(-90,1.0,0,0)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def backView(self): def backView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0) GL.glRotatef(-90,1.0,0,0)
glRotatef(180,0,0,1.0) GL.glRotatef(180,0,0,1.0)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def leftView(self): def leftView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0) GL.glRotatef(-90,1.0,0,0)
glRotatef(90,0,0,1.0) GL.glRotatef(90,0,0,1.0)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def rightView(self): def rightView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0) GL.glRotatef(-90,1.0,0,0)
glRotatef(-90,0,0,1.0) GL.glRotatef(-90,0,0,1.0)
self.ogl.tkRedraw() self.ogl.tkRedraw()
def topView(self): def topView(self):
glMatrixMode(GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
glLoadIdentity() GL.glLoadIdentity()
glScalef(self.scale,self.scale,self.scale) GL.glScalef(self.scale,self.scale,self.scale)
self.ogl.tkRedraw() self.ogl.tkRedraw()
......
...@@ -3,9 +3,10 @@ from pycam.Geometry.Point import Point ...@@ -3,9 +3,10 @@ from pycam.Geometry.Point import Point
import ctypes import ctypes
try: try:
from OpenGL.GL import * import OpenGL.GL as GL
GL_enabled = True
except: except:
pass GL_enabled = False
EPSILON=1e-8 EPSILON=1e-8
...@@ -166,6 +167,7 @@ class ZBuffer: ...@@ -166,6 +167,7 @@ class ZBuffer:
self.changed = True self.changed = True
def to_OpenGL(self): def to_OpenGL(self):
if GL_enabled:
self.to_OpenGL_6() self.to_OpenGL_6()
self.changed = False self.changed = False
...@@ -177,17 +179,17 @@ class ZBuffer: ...@@ -177,17 +179,17 @@ class ZBuffer:
# the naive way (quads) # the naive way (quads)
def to_OpenGL_1(self): def to_OpenGL_1(self):
glBegin(GL_QUADS) GL.glBegin(GL.GL_QUADS)
for y in range(0,self.yres-1): for y in range(0,self.yres-1):
for x in range(0,self.xres-1): for x in range(0,self.xres-1):
n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z) n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2]) GL.glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z) GL.glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z) GL.glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z) GL.glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z) GL.glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
glEnd() GL.glEnd()
# use display lists (per quad) # use display lists (per quad)
def to_OpenGL_2(self): def to_OpenGL_2(self):
...@@ -199,23 +201,23 @@ class ZBuffer: ...@@ -199,23 +201,23 @@ class ZBuffer:
# print "z[%f][%f]=%f" % (self.y[y],self.x[x],self.buf[y][x]) # print "z[%f][%f]=%f" % (self.y[y],self.x[x],self.buf[y][x])
if self.buf[y+0][x+0].changed or self.buf[y+0][x+1].changed or self.buf[y+1][x+0].changed or self.buf[y+1][x+1].changed: if self.buf[y+0][x+0].changed or self.buf[y+0][x+1].changed or self.buf[y+1][x+0].changed or self.buf[y+1][x+1].changed:
if self.buf[y][x].list == -1: if self.buf[y][x].list == -1:
self.buf[y][x].list = glGenLists(1) self.buf[y][x].list = GL.glGenLists(1)
glNewList(self.buf[y][x].list, GL_COMPILE) GL.glNewList(self.buf[y][x].list, GL.GL_COMPILE)
glBegin(GL_QUADS) GL.glBegin(GL.GL_QUADS)
n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z) n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2]) GL.glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z) GL.glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z) GL.glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z) GL.glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z) GL.glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
glEnd() GL.glEnd()
glEndList() GL.glEndList()
for y in range(0,self.yres-1): for y in range(0,self.yres-1):
for x in range(0,self.xres-1): for x in range(0,self.xres-1):
self.buf[y][x].changed = False self.buf[y][x].changed = False
glCallList(self.buf[y][x].list) GL.glCallList(self.buf[y][x].list)
# use display list per cell (cell = group of quads) # use display list per cell (cell = group of quads)
def to_OpenGL_3(self): def to_OpenGL_3(self):
...@@ -244,43 +246,43 @@ class ZBuffer: ...@@ -244,43 +246,43 @@ class ZBuffer:
if changed: if changed:
if self.list[y][x] == -1: if self.list[y][x] == -1:
self.list[y][x] = glGenLists(1) self.list[y][x] = GL.glGenLists(1)
if False: if False:
glNewList(self.list[y][x], GL_COMPILE) GL.glNewList(self.list[y][x], GL.GL_COMPILE)
for yi in range(y0,y1-1): for yi in range(y0,y1-1):
glBegin(GL_TRIANGLES) GL.glBegin(GL.GL_TRIANGLES)
for xi in range(x0,x1-1): for xi in range(x0,x1-1):
n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z) n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z)
glNormal3f(n[0],n[1],n[2]) GL.glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z) GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z) GL.glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z) GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
n = self.normal(self.buf[y+1][x+1].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z) n = self.normal(self.buf[y+1][x+1].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2]) GL.glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z) GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z) GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z) GL.glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
self.buf[yi][xi].changed = False self.buf[yi][xi].changed = False
glEnd() GL.glEnd()
glEndList() GL.glEndList()
else: else:
glNewList(self.list[y][x], GL_COMPILE) GL.glNewList(self.list[y][x], GL.GL_COMPILE)
for yi in range(y0,y1-1): for yi in range(y0,y1-1):
glBegin(GL_QUADS) GL.glBegin(GL.GL_QUADS)
for xi in range(x0,x1-1): for xi in range(x0,x1-1):
n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z) n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z)
glNormal3f(n[0],n[1],n[2]) GL.glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z) GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z) GL.glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z) GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z) GL.glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
self.buf[yi][xi].changed = False self.buf[yi][xi].changed = False
glEnd() GL.glEnd()
glEndList() GL.glEndList()
glCallList(self.list[y][x]) GL.glCallList(self.list[y][x])
# use display list with vertex buffers per cell (cell = group of quads) # use display list with vertex buffers per cell (cell = group of quads)
def to_OpenGL_4(self): def to_OpenGL_4(self):
...@@ -319,12 +321,12 @@ class ZBuffer: ...@@ -319,12 +321,12 @@ class ZBuffer:
if changed: if changed:
# print "cell[",y,"][",x,"]=",self.cell[y][x].list # print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1: if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1) self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].array = (ctypes.c_float*3*((y1-y0)*(x1-x0)*2))() self.cell[y][x].array = (ctypes.c_float*3*((y1-y0)*(x1-x0)*2))()
glEnableClientState(GL_VERTEX_ARRAY) GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
glVertexPointerf(self.cell[y][x].array) GL.glVertexPointerf(self.cell[y][x].array)
glNewList(self.cell[y][x].list, GL_COMPILE) GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0 idx = 0
for yi in range(y0,y1-1): for yi in range(y0,y1-1):
lineidx = idx lineidx = idx
...@@ -338,10 +340,10 @@ class ZBuffer: ...@@ -338,10 +340,10 @@ class ZBuffer:
self.cell[y][x].array[idx+1][1] = self.y[yi+1] self.cell[y][x].array[idx+1][1] = self.y[yi+1]
self.cell[y][x].array[idx+1][2] = self.buf[yi+1][xi+0].z self.cell[y][x].array[idx+1][2] = self.buf[yi+1][xi+0].z
idx += 2 idx += 2
glDrawArrays(GL_QUAD_STRIP, lineidx, idx-lineidx+1) GL.glDrawArrays(GL.GL_QUAD_STRIP, lineidx, idx-lineidx+1)
glEndList() GL.glEndList()
glCallList(self.cell[y][x].list) GL.glCallList(self.cell[y][x].list)
# use display list with vertex and normal buffers per cell (cell = group of quads) # use display list with vertex and normal buffers per cell (cell = group of quads)
def to_OpenGL_5(self): def to_OpenGL_5(self):
...@@ -357,8 +359,8 @@ class ZBuffer: ...@@ -357,8 +359,8 @@ class ZBuffer:
num_cell_x = 1 num_cell_x = 1
dx = self.xres dx = self.xres
glEnableClientState(GL_VERTEX_ARRAY) GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY) GL.glEnableClientState(GL.GL_NORMAL_ARRAY)
for y in range(0,num_cell_y): for y in range(0,num_cell_y):
y0 = y*dy y0 = y*dy
...@@ -383,13 +385,13 @@ class ZBuffer: ...@@ -383,13 +385,13 @@ class ZBuffer:
if changed: if changed:
# print "cell[",y,"][",x,"]=",self.cell[y][x].list # print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1: if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1) self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))() self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))()
self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))() self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))()
glVertexPointerf(self.cell[y][x].vertex) GL.glVertexPointerf(self.cell[y][x].vertex)
glNormalPointerf(self.cell[y][x].normal) GL.glNormalPointerf(self.cell[y][x].normal)
glNewList(self.cell[y][x].list, GL_COMPILE) GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0 idx = 0
for yi in range(y0,y1-1): for yi in range(y0,y1-1):
lineidx = idx lineidx = idx
...@@ -424,13 +426,13 @@ class ZBuffer: ...@@ -424,13 +426,13 @@ class ZBuffer:
self.cell[y][x].normal[idx+3][2] = n[2] self.cell[y][x].normal[idx+3][2] = n[2]
idx += 4 idx += 4
glDrawArrays(GL_QUADS, lineidx, idx-lineidx+1) GL.glDrawArrays(GL.GL_QUADS, lineidx, idx-lineidx+1)
glEndList() GL.glEndList()
glCallList(self.cell[y][x].list) GL.glCallList(self.cell[y][x].list)
glDisableClientState(GL_VERTEX_ARRAY) GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY) GL.glDisableClientState(GL.GL_NORMAL_ARRAY)
# use display list with vertex and normal and index buffers per cell (cell = group of quads) # use display list with vertex and normal and index buffers per cell (cell = group of quads)
def to_OpenGL_6(self): def to_OpenGL_6(self):
...@@ -446,9 +448,9 @@ class ZBuffer: ...@@ -446,9 +448,9 @@ class ZBuffer:
num_cell_x = 1 num_cell_x = 1
dx = self.xres dx = self.xres
glEnableClientState(GL_INDEX_ARRAY) GL.glEnableClientState(GL.GL_INDEX_ARRAY)
glEnableClientState(GL_VERTEX_ARRAY) GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY) GL.glEnableClientState(GL.GL_NORMAL_ARRAY)
for y in range(0,num_cell_y): for y in range(0,num_cell_y):
y0 = y*dy y0 = y*dy
...@@ -473,15 +475,15 @@ class ZBuffer: ...@@ -473,15 +475,15 @@ class ZBuffer:
if changed: if changed:
#print "cell[",y,"][",x,"]=",self.cell[y][x].list #print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1: if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1) self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)))() self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)))()
self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)))() self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)))()
self.cell[y][x].index = (ctypes.c_ushort*(4*(y1-y0-1)*(x1-x0-1)))() self.cell[y][x].index = (ctypes.c_ushort*(4*(y1-y0-1)*(x1-x0-1)))()
glIndexPointers(self.cell[y][x].index) GL.glIndexPointers(self.cell[y][x].index)
glVertexPointerf(self.cell[y][x].vertex) GL.glVertexPointerf(self.cell[y][x].vertex)
glNormalPointerf(self.cell[y][x].normal) GL.glNormalPointerf(self.cell[y][x].normal)
glNewList(self.cell[y][x].list, GL_COMPILE) GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0 idx = 0
for yi in range(y0,y1): for yi in range(y0,y1):
for xi in range(x0,x1): for xi in range(x0,x1):
...@@ -510,11 +512,11 @@ class ZBuffer: ...@@ -510,11 +512,11 @@ class ZBuffer:
self.cell[y][x].index[idx+3] = (yi-y0+0)*(x1-x0) + (xi-x0+1) self.cell[y][x].index[idx+3] = (yi-y0+0)*(x1-x0) + (xi-x0+1)
idx += 4 idx += 4
glDrawElements(GL_QUADS, idx, GL_UNSIGNED_SHORT, self.cell[y][x].index) GL.glDrawElements(GL.GL_QUADS, idx, GL.GL_UNSIGNED_SHORT, self.cell[y][x].index)
glEndList() GL.glEndList()
glCallList(self.cell[y][x].list) GL.glCallList(self.cell[y][x].list)
glDisableClientState(GL_VERTEX_ARRAY) GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY) GL.glDisableClientState(GL.GL_NORMAL_ARRAY)
glDisableClientState(GL_INDEX_ARRAY) GL.glDisableClientState(GL.GL_INDEX_ARRAY)
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