pyNastran
0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
|
00001 ## GNU Lesser General Public License 00002 ## 00003 ## Program pyNastran - a python interface to NASTRAN files 00004 ## Copyright (C) 2011-2012 Steven Doyle, Al Danial 00005 ## 00006 ## Authors and copyright holders of pyNastran 00007 ## Steven Doyle <mesheb82@gmail.com> 00008 ## Al Danial <al.danial@gmail.com> 00009 ## 00010 ## This file is part of pyNastran. 00011 ## 00012 ## pyNastran is free software: you can redistribute it and/or modify 00013 ## it under the terms of the GNU Lesser General Public License as published by 00014 ## the Free Software Foundation, either version 3 of the License, or 00015 ## (at your option) any later version. 00016 ## 00017 ## pyNastran is distributed in the hope that it will be useful, 00018 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 ## GNU General Public License for more details. 00021 ## 00022 ## You should have received a copy of the GNU Lesser General Public License 00023 ## along with pyNastran. If not, see <http://www.gnu.org/licenses/>. 00024 ## 00025 import vtk 00026 00027 class MouseStyle(vtk.vtkInteractorStyleTrackballCamera): 00028 def __init__(self,ren,parent=None): 00029 self.AddObserver("MiddleButtonPressEvent",self.middleButtonPressEvent) 00030 self.AddObserver("MiddleButtonReleaseEvent",self.middleButtonReleaseEvent) 00031 self.pipeline = ren['pipeline'] 00032 self.cam = ren['camera'] 00033 00034 def Update(self): 00035 self.pipeline.widget.Modified() 00036 self.cam.Modified() 00037 self.cam.UpdateViewport(self.pipeline.rend) 00038 self.pipeline.renWin.Render() 00039 00040 def getActiveCamera(self): 00041 ren = self.pipeline.rend 00042 #print "type(ren) = ",ren 00043 #print "dir = ",'\n'.join(dir(ren)) 00044 camera = self.cam 00045 #camera = ren.getActiveCamera 00046 #print "type(camera) = ",camera 00047 return camera 00048 #return self.pipeline.rend.getActiveCamera() 00049 00050 #def leftButtonPressEvent(self,obj,event): 00051 # print "Left Button pressed" 00052 # self.LeftButtonDown() 00053 # return 00054 # 00055 #def rightButtonPressEvent(self,obj,event): 00056 # print "Right Button pressed" 00057 # self.OnRightButtonDown() 00058 # return 00059 00060 #def rightButtonReleaseEvent(self,obj,event): 00061 # print "Right Button released" 00062 # self.OnRightButtonUp() 00063 # return 00064 00065 def middleButtonPressEvent(self,obj,event): 00066 print "Middle Button pressed" 00067 self.OnMiddleButtonDown() 00068 return 00069 00070 def middleButtonReleaseEvent(self,obj,event): 00071 print "Middle Button released" 00072 self.OnMiddleButtonUp() 00073 return 00074 00075 def onChar(self,obj,event): 00076 rwi = obj 00077 key = rwi.GetKeySym() 00078 print "*Pressed %s" %(key) 00079 00080 #renderer = self.ren 00081 camera = self.getActiveCamera() 00082 #print "type(camera) = ",type(camera) 00083 if key=='m': # zooming in 00084 camera.Zoom(1.1) 00085 self.Update() 00086 elif key=='M': # zooming out 00087 camera.Zoom(0.9) 00088 self.Update() 00089 elif key=='d': # draw edges 00090 if self.pipeline.isEdges==False: 00091 return 00092 prop = self.pipeline.edgeActor.GetProperty() 00093 #print '\n'.join(dir(prop)) 00094 if self.pipeline.isEdges: 00095 #prop.SetLineWidth(0.0) 00096 prop.EdgeVisibilityOff() 00097 else: 00098 #prop.SetLineWidth(1.0) 00099 prop.EdgeVisibilityOn() 00100 #prop.Update() 00101 #prop.Modified() 00102 #prop.SetVisibility(False) 00103 self.pipeline.isEdges = not(self.pipeline.isEdges) 00104 self.pipeline.edgeMapper.Modified() 00105 self.pipeline.edgeMapper.Update() 00106 self.pipeline.edgeActor.Modified() 00107 00108 # Roll 00109 elif key=='o': # counter-clockwise 00110 camera.Roll(5.) 00111 self.Update() 00112 elif key=='O': # clockwise 00113 camera.Roll(-5.) 00114 self.Update() 00115 00116 # Yaw 00117 #elif key=='a': # counter-clockwise 00118 #camera.Yaw(5.) 00119 #self.Update() 00120 #elif key=='A': # clockwise 00121 #camera.Yaw(-5.) 00122 #self.Update() 00123 00124 # Elevation 00125 #elif key=='v': # counter-clockwise 00126 #camera.Elevation(5.) 00127 #self.Update() 00128 #elif key=='V': # clockwise 00129 #camera.Elevation(-5.) 00130 #self.Update() 00131 00132 # Pitch 00133 #elif key=='c': # counter-clockwise 00134 #camera.Pitch(5.) 00135 #self.Update() 00136 #elif key=='C': # clockwise 00137 #camera.Pitch(-5.) 00138 #self.Update() 00139 00140 elif key=='x': # set x-axis 00141 camera.SetFocalPoint(0.,0.,0.) 00142 camera.SetViewUp( 0.,0., 1.) 00143 camera.SetPosition(1.,0., 0.) 00144 self.pipeline.rend.ResetCamera() 00145 self.Update() 00146 elif key=='X': # set x-axis 00147 camera.SetFocalPoint(0.,0.,0.) 00148 camera.SetViewUp( 0.,0.,-1.) 00149 camera.SetPosition(-1.,0., 0.) 00150 self.pipeline.rend.ResetCamera() 00151 self.Update() 00152 00153 00154 elif key=='y': # set y-axis 00155 camera.SetFocalPoint(0.,0.,0.) 00156 camera.SetViewUp( 0.,0.,1.) 00157 camera.SetPosition( 0.,1.,0.) 00158 self.pipeline.rend.ResetCamera() 00159 self.Update() 00160 elif key=='Y': # set y-axis 00161 camera.SetFocalPoint(0., 0., 0.) 00162 camera.SetViewUp( 0., 0.,-1.) 00163 camera.SetPosition( 0.,-1., 0.) 00164 self.pipeline.rend.ResetCamera() 00165 self.Update() 00166 00167 elif key=='z': # set z-axis 00168 camera.SetFocalPoint(0.,0.,0.) 00169 camera.SetViewUp( 0.,1.,0.) 00170 camera.SetPosition( 0.,0.,1.) 00171 self.pipeline.rend.ResetCamera() 00172 self.Update() 00173 elif key=='Z': # set z-axis 00174 camera.SetFocalPoint(0.,0., 0.) 00175 camera.SetViewUp( 0., -1.,0.) 00176 camera.SetPosition( 0., 0.,-1.) 00177 self.pipeline.rend.ResetCamera() 00178 self.Update() 00179 00180 #elif key=='i': # picture taking doesnt work 00181 #self.pipeline.takePicture() 00182 00183 # Panning doesnt work 00184 #elif key=='Up': 00185 #p = camera.GetPosition() 00186 #print "p = ",p 00187 #f = camera.GetFocalPoint() 00188 #print "f = ",f 00189 #camera.SetFocalPoint() 00190 #camera.SetPosition(p[0],p[1],p[2]+1.) 00191 #camera.SetFocalPoint(f[0],f[1],f[2]+1.) 00192 #camera.Pan() 00193 #self.Update() 00194 #elif key=='Down': 00195 #p = camera.GetPosition() 00196 #print "p = ",p 00197 #f = camera.GetFocalPoint() 00198 #print "f = ",f 00199 #camera.SetFocalPoint() 00200 #camera.SetPosition(p[0],p[1],p[2]-1.) 00201 #camera.SetFocalPoint(f[0],f[1],f[2]-1.) 00202 #camera.Pan() 00203 #self.pipeline.rend.ResetCamera() 00204 #self.Update() 00205 00206