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)
......
This diff is collapsed.
This diff is collapsed.
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