--- a/PyVEFViewer.py Mon Mar 21 13:28:23 2011 -0700
+++ b/PyVEFViewer.py Tue Mar 22 14:17:09 2011 -0700
@@ -1,6 +1,7 @@
from PyQGLViewer import *
from PyQt4 import QtGui, QtCore
import OpenGL.GL as ogl
+from os.path import splitext; ext = lambda fn: splitext(fn)[1]
from points import Points, centerMinMax, reduceCMM
from edges import Edges
@@ -46,6 +47,14 @@
item.toggleVisible()
self.updateGL()
+ def keyPressEvent(self, e):
+ if e.key() == QtCore.Qt.Key_O:
+ filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
+ self.read_from_extension(str(filename))
+ self.normalize_view()
+ else:
+ super(VEFViewer, self).keyPressEvent(e)
+
def init(self):
# ogl.glMaterialf(ogl.GL_FRONT_AND_BACK, ogl.GL_SHININESS, 50.0)
# specular_color = [ 0.8, 0.8, 0.8, 1.0 ]
@@ -78,6 +87,18 @@
for tri in triangles:
self.model_list.addItem(Triangles(tri, self.model_list))
+ def read_from_extension(self, fn):
+ if ext(fn) == '.vrt' or ext(fn) == '.pts':
+ self.read_points([fn])
+ elif ext(fn) == '.edg':
+ self.read_edges([fn])
+ elif ext(fn) == '.stl':
+ self.read_triangles([fn])
+ else:
+ return False
+
+ return True
+
def set_list(self, model_list):
self.model_list = model_list
self.model_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
@@ -90,6 +111,8 @@
self.setSceneBoundingBox(Vec(self.min.x, self.min.y, self.min.z), \
Vec(self.max.x, self.max.y, self.max.z))
self.setSceneCenter(Vec(self.center.x, self.center.y, self.center.z))
+
+ def show_entire_scene(self):
self.camera().showEntireScene()
def scene_parameters(self):
--- a/VEFViewer.py Mon Mar 21 13:28:23 2011 -0700
+++ b/VEFViewer.py Tue Mar 22 14:17:09 2011 -0700
@@ -3,7 +3,6 @@
import ui_PyVEFViewer as ui
from opster import command, dispatch
from sys import exit
-from os.path import splitext; ext = lambda fn: splitext(fn)[1]
class VEFViewerWindow(ui.QtGui.QWidget):
def __init__(self, parent = None):
@@ -22,18 +21,6 @@
edges = opts['edges']
triangles = opts['triangles']
- # Guess types from extensions
- for fn in args:
- if ext(fn) == '.vrt' or ext(fn) == '.pts':
- points.append(fn)
- elif ext(fn) == '.edg':
- edges.append(fn)
- elif ext(fn) == '.stl':
- triangles.append(fn)
- else:
- print "Cannot guess type from extension:", fn
- exit(1)
-
qapp = ui.QtGui.QApplication([])
win = VEFViewerWindow()
win.show()
@@ -42,7 +29,13 @@
win.ui.viewer.read_points(points)
win.ui.viewer.read_edges(edges)
win.ui.viewer.read_triangles(triangles)
+ # Guess types from extensions
+ for fn in args:
+ if not win.ui.viewer.read_from_extension(fn):
+ print "Cannot guess type from extension:", fn
+ exit(1)
win.ui.viewer.normalize_view()
+ win.ui.viewer.show_entire_scene()
qapp.exec_()