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 os 00026 import wx 00027 import vtk 00028 from vtk.wx.wxVTKRenderWindow import wxVTKRenderWindow 00029 00030 class pyWidget(wxVTKRenderWindow): 00031 def __init__(self,*args,**kwargs): 00032 wxVTKRenderWindow.__init__(self, *args, **kwargs) 00033 self.parent = args[0] 00034 self.dirname = "" 00035 self.OnChar = self.onChar2 00036 00037 def ResetCamera(self): 00038 self.Reset() 00039 00040 def GetCamera(self): 00041 return self._CurrentCamera 00042 00043 def onChar2(self,event): 00044 #print "onChar2 = ",event.GetKeyCode() 00045 camera = self.GetCamera() 00046 code = event.GetKeyCode() 00047 if code == ord('m'): # zooming in 00048 camera.Zoom(1.1) 00049 elif code == ord('M'): # zooming out 00050 camera.Zoom(0.9) 00051 00052 elif code == ord('o'): # counter-clockwise 00053 camera.Roll(5.) 00054 elif code == ord('O'): # clockwise 00055 camera.Roll(-5.) 00056 00057 # Yaw 00058 #elif code == ord('a'): # counter-clockwise 00059 #camera.Yaw(5.) 00060 #elif code == ord('A'): # clockwise 00061 #camera.Yaw(-5.) 00062 00063 # Elevation 00064 #elif code == ord('v'): # counter-clockwise 00065 #camera.Elevation(5.) 00066 #elif code == ord('V'): # clockwise 00067 #camera.Elevation(-5.) 00068 00069 # Pitch 00070 #elif code == ord('c'): # counter-clockwise 00071 #camera.Pitch(5.) 00072 #elif code == ord('C'): # clockwise 00073 #camera.Pitch(-5.) 00074 00075 elif code == ord('x'): # set x-axis 00076 camera.SetFocalPoint(0.,0., 0.) 00077 camera.SetViewUp( 0.,0., 1.) 00078 camera.SetPosition( 1.,0., 0.) 00079 self.ResetCamera() 00080 elif code == ord('X'): # set x-axis 00081 camera.SetFocalPoint(0.,0., 0.) 00082 camera.SetViewUp( 0.,0.,-1.) 00083 camera.SetPosition( -1.,0., 0.) 00084 self.ResetCamera() 00085 00086 elif code == ord('y'): # set y-axis 00087 camera.SetFocalPoint(0.,0.,0.) 00088 camera.SetViewUp( 0.,0.,1.) 00089 camera.SetPosition( 0.,1.,0.) 00090 self.ResetCamera() 00091 elif code == ord('Y'): # set y-axis 00092 camera.SetFocalPoint(0., 0., 0.) 00093 camera.SetViewUp( 0., 0.,-1.) 00094 camera.SetPosition( 0.,-1., 0.) 00095 self.ResetCamera() 00096 00097 elif code == ord('z'): # set z-axis 00098 camera.SetFocalPoint(0.,0.,0.) 00099 camera.SetViewUp( 0.,1.,0.) 00100 camera.SetPosition( 0.,0.,1.) 00101 self.ResetCamera() 00102 elif code == ord('Z'): # set z-axis 00103 camera.SetFocalPoint(0.,0., 0.) 00104 camera.SetViewUp( 0., -1.,0.) 00105 camera.SetPosition( 0., 0.,-1.) 00106 self.ResetCamera() 00107 00108 elif code == ord('i'): 00109 self.onTakePicture(event) 00110 00111 #elif code == ord('e'): # edges dont work right yet 00112 #self.parent.DisplayEdges(event) 00113 00114 elif code == ord('L'): 00115 self.parent.cycleResults() 00116 00117 elif code == ord('h'): 00118 self.ShowHideScalarBar() 00119 00120 self.Update() 00121 self.Render() 00122 ### 00123 00124 def ShowHideScalarBar(self): 00125 if self.parent.nCases==0: 00126 return 00127 isOn = self.parent.scalarBar.GetVisibility() 00128 if isOn: 00129 self.parent.scalarBar.VisibilityOff() 00130 self.parent.TurnTextOff() 00131 else: 00132 self.parent.scalarBar.VisibilityOn() 00133 self.parent.TurnTextOn() 00134 self.parent.scalarBar.Modified() 00135 00136 def onTakePicture(self,event): 00137 renderLarge = vtk.vtkRenderLargeImage() 00138 renderLarge.SetInput(self.getRenderer()) 00139 renderLarge.SetMagnification(4) 00140 00141 wildcard = "PNG (*.png)|*.png|" \ 00142 "JPEG (*.jpeg; *.jpeg; *.jpg; *.jfif)|*.jpg;*.jpeg;*.jpg;*.jfif|" \ 00143 "TIFF (*.tif; *.tiff)|*.tif;*.tiff|" \ 00144 "BMP (*.bmp)|*.bmp|" \ 00145 "PostScript (*.ps)|*.ps|" \ 00146 "All files (*.*)|*.*" 00147 00148 dlg = wx.FileDialog(None, "Choose a file", self.dirname, "", wildcard, wx.SAVE | wx.OVERWRITE_PROMPT) 00149 if dlg.ShowModal() == wx.ID_OK: 00150 fname = dlg.GetFilename() 00151 self.dirname = dlg.GetDirectory() 00152 fname = os.path.join(self.dirname,fname) 00153 00154 print "fname = ",fname 00155 00156 # We write out the image which causes the rendering to occur. If you 00157 # watch your screen you might see the pieces being rendered right 00158 # after one another. 00159 lfname = fname.lower() 00160 if lfname.endswith('.png'): 00161 writer = vtk.vtkPNGWriter() 00162 elif lfname.endswith('.jpeg'): 00163 writer = vtk.vtkJPEGWriter() 00164 elif lfname.endswith('.tiff'): 00165 writer = vtk.vtkTIFFWriter() 00166 elif lfname.endswith('.ps'): 00167 writer = vtk.vtkPostScriptWriter() 00168 else: 00169 writer = vtk.vtkPNGWriter() 00170 00171 writer.SetInputConnection(renderLarge.GetOutputPort()) 00172 writer.SetFileName(fname) 00173 writer.Write() 00174 dlg.Destroy() 00175 00176 def getRenderer(self): 00177 return self.GetCurrentRenderer()