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
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
GL_enabled = True
except:
pass
GL_enabled = False
class CylindricalCutter(BaseCutter):
......@@ -26,15 +26,17 @@ class CylindricalCutter(BaseCutter):
return "CylindricalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not GL_enabled:
return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
if not hasattr(self,"_disk"):
self._disk = gluNewQuadric()
gluDisk(self._disk, 0, self.radius, 10, 10)
glPopMatrix()
self._disk = GLU.gluNewQuadric()
GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
......@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
GL_enabled = True
except:
pass
GL_enabled = False
class SphericalCutter(BaseCutter):
......@@ -26,15 +26,17 @@ class SphericalCutter(BaseCutter):
return "SphericalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not GL_enabled:
return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric()
gluSphere(self._sphere, self.radius, 10, 10)
self._sphere = GLU.gluNewQuadric()
GLU.gluSphere(self._sphere, self.radius, 10, 10)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
glPopMatrix()
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
......@@ -8,11 +8,12 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
import OpenGL.GLUT as GLUT
GL_enabled = True
except:
pass
GL_enabled = False
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)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
if not GL_enabled:
return
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"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20)
glPopMatrix()
glPushMatrix()
glTranslate(self.location.x, self.location.y, self.location.z)
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20)
GL.glPopMatrix()
GL.glPushMatrix()
GL.glTranslate(self.location.x, self.location.y, self.location.z)
if not hasattr(self,"_disk"):
self._disk = gluNewQuadric()
gluDisk(self._disk, 0, self.majorradius, 20, 10)
glPopMatrix()
self._disk = GLU.gluNewQuadric()
GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
list = [ "SimpleGCodeExporter", "SVGExporter" ]
list = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter" ]
__all__ = list
......@@ -4,11 +4,10 @@ from Line import *
from Triangle import *
try:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import OpenGL.GL as GL
GL_enabled = True
except:
pass
GL_enabled = False
class Model:
id = 0
......@@ -21,12 +20,12 @@ class Model:
def to_OpenGL(self):
if True:
glBegin(GL_TRIANGLES)
GL.glBegin(GL.GL_TRIANGLES)
for t in self._triangles:
glVertex3f(t.p1.x, t.p1.y, t.p1.z)
glVertex3f(t.p2.x, t.p2.y, t.p2.z)
glVertex3f(t.p3.x, t.p3.y, t.p3.z)
glEnd()
GL.glVertex3f(t.p1.x, t.p1.y, t.p1.z)
GL.glVertex3f(t.p2.x, t.p2.y, t.p2.z)
GL.glVertex3f(t.p3.x, t.p3.y, t.p3.z)
GL.glEnd()
else:
for t in self._triangles:
t.to_OpenGL()
......
......@@ -3,15 +3,13 @@ from Plane import *
from utils import *
from Line import *
ORIENTATION_CCW = 2
ORIENTATION_CW = 3
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
import OpenGL.GLUT as GLUT
GL_enabled = True
except:
pass
GL_enabled = False
class Triangle:
id = 0
......@@ -42,51 +40,53 @@ class Triangle:
return "triangle%d" % self.id
def to_OpenGL(self):
glBegin(GL_TRIANGLES)
glVertex3f(self.p1.x, self.p1.y, self.p1.z)
glVertex3f(self.p2.x, self.p2.y, self.p2.z)
glVertex3f(self.p3.x, self.p3.y, self.p3.z)
glEnd()
if not GL_enabled:
return
GL.glBegin(GL.GL_TRIANGLES)
GL.glVertex3f(self.p1.x, self.p1.y, self.p1.z)
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
n = self.normal()
c = self.center()
d = 0.5
glBegin(GL_LINES)
glVertex3f(c.x, c.y, c.z)
glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glVertex3f(c.x, c.y, c.z)
GL.glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
GL.glEnd()
if False and hasattr(self, "_middle"): # display bounding sphere
glPushMatrix()
glTranslate(self._middle.x, self._middle.y, self._middle.z)
GL.glPushMatrix()
GL.glTranslate(self._middle.x, self._middle.y, self._middle.z)
if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric()
gluSphere(self._sphere, self._radius, 10, 10)
glPopMatrix()
self._sphere = GLU.gluNewQuadric()
GLU.gluSphere(self._sphere, self._radius, 10, 10)
GL.glPopMatrix()
if True: # draw triangle id on triangle face
glPushMatrix()
cc = glGetFloatv(GL_CURRENT_COLOR)
GL.glPushMatrix()
cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
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)
p3_12=self.p3.sub(p12).normalize()
p2_1=self.p1.sub(self.p2).normalize()
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)
glTranslatef(n.x,n.y,n.z)
glScalef(0.003,0.003,0.003)
GL.glTranslatef(n.x,n.y,n.z)
GL.glScalef(0.003,0.003,0.003)
w = 0
for ch in str(self.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0)
glColor4f(1,1,1,0)
w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glTranslate(-w/2,0,0)
GL.glColor4f(1,1,1,0)
for ch in str(self.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3])
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glPopMatrix()
GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
if False: # draw point id on triangle face
cc = glGetFloatv(GL_CURRENT_COLOR)
cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
c = self.center()
p12=self.p1.add(self.p2).mul(0.5)
p3_12=self.p3.sub(p12).normalize()
......@@ -94,21 +94,21 @@ class Triangle:
pn=p2_1.cross(p3_12)
n = self.normal().mul(0.01)
for p in (self.p1,self.p2,self.p3):
glPushMatrix()
GL.glPushMatrix()
pp = p.sub(p.sub(c).mul(0.3))
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))
glTranslatef(n.x,n.y,n.z)
glScalef(0.001,0.001,0.001)
GL.glTranslate(pp.x,pp.y,pp.z)
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))
GL.glTranslatef(n.x,n.y,n.z)
GL.glScalef(0.001,0.001,0.001)
w = 0
for ch in str(p.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0)
glColor4f(0.5,1,0.5,0)
w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glTranslate(-w/2,0,0)
GL.glColor4f(0.5,1,0.5,0)
for ch in str(p.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3])
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glPopMatrix()
GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
def normal(self):
if not hasattr(self, '_normal'):
......
......@@ -4,11 +4,10 @@ import math
import pycam
try:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import OpenGL.GL as GL
GL_enabled = True
except:
pass
GL_enabled = False
class Node:
def __repr__(self):
......@@ -58,35 +57,37 @@ class kdtree:
return "(%s,%d:%g,%s)" % (self.lo,self.cutdim,self.cutval,self.hi)
def to_OpenGL(self,minx,maxx,miny,maxy,minz,maxz):
if not GL_enabled:
return
if self.bucket:
glBegin(GL_LINES)
glVertex3d(minx,miny,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,minz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,minz)
glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,minz)
glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz)
glVertex3d(maxx,miny,minz)
glVertex3d(minx,maxy,minz)
glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(maxx,miny,maxz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz)
glVertex3d(minx,maxy,minz)
glVertex3d(maxx,miny,minz)
glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,maxz)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glEnd()
elif self.dim==6:
if self.cutdim == 0 or self.cutdim == 2:
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