Added pipes drawing to edges.py
authorDmitriy Morozov <dmitriy@mrzv.org>
Fri, 03 Jun 2011 12:56:27 -0700
changeset 15 30a851aa0675
parent 14 9e82d4394fc3
child 16 69f6b439b161
Added pipes drawing to edges.py
VEFViewer.py
edges.py
io.py
--- a/VEFViewer.py	Thu May 05 11:11:04 2011 -0700
+++ b/VEFViewer.py	Fri Jun 03 12:56:27 2011 -0700
@@ -16,7 +16,6 @@
                     ('e', 'edges',     [], 'files with edges'),
                     ('t', 'triangles', [], 'files with triangles')])
 def main(*args, **opts):
-    
     points    = opts['points']
     edges     = opts['edges']
     triangles = opts['triangles']
--- a/edges.py	Thu May 05 11:11:04 2011 -0700
+++ b/edges.py	Fri Jun 03 12:56:27 2011 -0700
@@ -1,6 +1,8 @@
 from        OpenGL.GL   import glGenLists, glNewList, GL_COMPILE, glEndList, glCallList, \
                                glBegin, glEnd, GL_LINES, glVertex3f, glColor3f, \
                                glEnable, glDisable, GL_LIGHTING
+from        OpenGL.GLE  import glePolyCylinder
+from        OpenGL.GLE  import *
 
 from        points      import Point, centerMinMax
 from        ViewerItem  import ViewerItem
@@ -16,13 +18,28 @@
 
         self.create_display_list()
         self.center, self.min, self.max = centerMinMax(self.vertices())
+        self.pipes = False
 
+    def createMenu(self):
+        menu = super(Edges, self).createMenu()
+        pipesAction = menu.addAction("Pipes")
+        pipesAction.setCheckable(True)
+        pipesAction.setChecked(self.pipes)
+        pipesAction.command = lambda: self.pipesCommand()
+        return menu
+
+    def pipesCommand(self):
+        self.pipes = not self.pipes
 
     def create_display_list(self):
         self.display_list = glGenLists(1)
         glNewList(self.display_list, GL_COMPILE)
         self.draw_edges()
         glEndList()
+        self.display_list_pipes = glGenLists(1)
+        glNewList(self.display_list_pipes, GL_COMPILE)
+        self.draw_pipes()
+        glEndList()
 
     def draw_edges(self):
         glBegin(GL_LINES)
@@ -31,11 +48,25 @@
             glVertex3f(v.x, v.y, v.z)
         glEnd()
 
+    def draw_pipes(self):
+        r,g,b,a = self.color.getRgb()
+        glColor3f(r,g,b)
+        for (u,v) in self.edges:
+            glePolyCylinder([(u.x, u.y, u.z),
+                             (u.x, u.y, u.z),
+                             (v.x,v.y,v.z),
+                             (v.x,v.y,v.z),],
+                            None,
+                            .5)
+
     def draw(self):
         if not self.visible: return
         r,g,b,a = self.color.getRgb()
         glColor3f(r,g,b)
-        glCallList(self.display_list)
+        if not self.pipes:
+            glCallList(self.display_list)
+        else:
+            glCallList(self.display_list_pipes)
 
     def vertices(self):
         for (u,v) in self.edges:
--- a/io.py	Thu May 05 11:11:04 2011 -0700
+++ b/io.py	Fri Jun 03 12:56:27 2011 -0700
@@ -7,4 +7,3 @@
             if len(block) == size:
                 yield block
                 block = []
-