pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
gui.py
Go to the documentation of this file.
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 #!/usr/bin/python
00026 # pylint: disable=C0103,C0111,W0612,R0904
00027 
00028 import os
00029 import wx
00030 #import vtk
00031 import sys
00032 #from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
00033 
00034 #import pyNastran
00035 import pyNastran.gui
00036 from pyNastran.gui.guiPanel import Pan
00037 ID_SAVEAS = 803
00038 ID_ABOUT = 3
00039 
00040 ID_PLOT = 200
00041 
00042 ID_SURFACE   = 901
00043 ID_WIREFRAME = 902
00044 ID_HIDDEN    = 903
00045 
00046 ID_CAMERA    = 910
00047 
00048 ID_BDF = 920
00049 ID_OP2 = 921
00050 ID_F06 = 922
00051 ID_CART3D = 923
00052 ID_LAWGS = 924
00053 ID_PANAIR = 925
00054 
00055 ID_EXPORT = 930
00056 
00057 
00058 pkgPath = pyNastran.gui.__path__[0]
00059 #print "pkgPath = |%r|" %(pkgPath)
00060 
00061 if '?' in pkgPath:
00062     iconPath = 'icons'
00063 else:
00064     iconPath = os.path.join(pkgPath,'icons')
00065 #print "iconPath = |%r|" %(iconPath)
00066 
00067 #------------------------------------------------------------------------------
00068 
00069 class AppFrame(wx.Frame) :
00070 
00071     def __init__(self,isEdges=False, isNodal=False, isCentroidal=False,
00072                  debug=False):
00073         
00074         wx.Frame.__init__(self, None, -1, size=wx.Size(800, 600),
00075                           title='pyNastran')
00076         self.bdfFileName = None
00077         self.isEdges = isEdges
00078         self.isNodal = isNodal
00079         self.isCentroidal = isCentroidal
00080         self.dirname = ''
00081         self.setupFrame()
00082 
00083     def setupFrame(self):
00084         """
00085         --------------------------------
00086         |        VERTICAL(VMAIN)       |
00087         |   -------------------------  |
00088         |   |                       |  |
00089         |   |        toolbar        |  |
00090         |   |                       |  |
00091         |   -------------------------  |
00092         |   |       HORIZ           |  |
00093         |   |         |  VERTICAL   |  |
00094         |   |         |             |  |
00095         |   |   GUI   |  sidewindow |  |
00096         |   |         |             |  |
00097         |   |         |             |  |
00098         |   |         |             |  |
00099         |   -------------------------  |
00100         |   |                       |  |
00101         |   |       statusbar       |  |
00102         |   |                       |  |
00103         |   -------------------------  |
00104         |                              |
00105         --------------------------------
00106         """
00107         # Must call before any event handler is referenced.
00108         self.eventsHandler = EventsHandler(self, isNodal=self.isNodal,
00109                                            isCentroidal=self.isCentroidal)
00110         
00111         self.frmPanel = Pan(self, isEdges=self.isEdges, isNodal=self.isNodal,
00112                             isCentroidal=self.isCentroidal, size=(100, 200))
00113 
00114         self.buildMenuBar()
00115         self.buildToolBar()
00116         self.buildStatusBar()
00117         
00118         self.SetMenuBar(self.menubar)
00119 
00120         self.frmPanel.bdfFileName = self.bdfFileName
00121         self.frmPanel.buildVTK(self.bdfFileName)
00122 
00123         windowName = self.frmPanel.getWindowName()
00124         self.SetTitle(windowName)
00125         #self.SetSize([600,600])
00126         #self.Centre()
00127 
00128         # Add them to sizer.
00129         hbox = wx.BoxSizer( wx.HORIZONTAL )
00130         hbox.Add( self.frmPanel.widget, 1, wx.EXPAND|wx.ALL, 1 )
00131 
00132         # Add buttons in their own sizer
00133         if 0:
00134             self.redBtn   = wx.Button(self.frmPanel, label='Red')
00135             self.greenBtn = wx.Button(self.frmPanel, label='Green')
00136             self.exitBtn  = wx.Button(self.frmPanel, label='Exit')
00137 
00138             vRight = wx.BoxSizer( wx.VERTICAL)
00139             vRight.AddStretchSpacer()
00140             vRight.Add(self.greenBtn, proportion=0, flag=wx.EXPAND|wx.ALL,
00141                        border=5)
00142             vRight.Add(self.exitBtn,  proportion=0, flag=wx.EXPAND|wx.ALL,
00143                        border=5)
00144             vRight.Add(self.redBtn,   proportion=0, flag=wx.EXPAND|wx.ALL,
00145                        border=5)
00146             vRight.AddStretchSpacer()
00147             hbox.Add(vRight, 1, wx.EXPAND)
00148 
00149         if 0:
00150             tree = self.buildTree(self.frmPanel)
00151             vRight = wx.BoxSizer(wx.VERTICAL)
00152             vRight.AddStretchSpacer()
00153             vRight.Add(tree, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
00154             vRight.AddStretchSpacer()
00155             hbox.Add(vRight, 1, wx.EXPAND)
00156 
00157 
00158         # best guess at tree
00159         if 0:
00160             #self.tree  = wx.Button( self.frmPanel, label='Tree' )
00161 
00162             vRight = wx.BoxSizer(wx.VERTICAL)
00163 
00164             scroll = wx.ScrolledWindow(self, -1)
00165             panelRight = wx.Panel(scroll, -1)
00166 
00167             panelRight = wx.Panel(self, wx.EXPAND)
00168             tree = self.buildTree(panelRight)
00169             vRight.Add(tree, flag=wx.EXPAND|wx.ALL)
00170             #vRight.Add(tree, 1, wx.EXPAND)
00171             #hbox.Add(panel1, 1, wx.EXPAND)
00172             
00173             vRight.Add(scroll, 1, wx.EXPAND | wx.ALL)
00174             #panelRight.SetSizer(vRight)
00175             panelRight.Layout()
00176 
00177             
00178 
00179             hbox.Add( vRight, 1, wx.EXPAND)
00180             #hbox.Add(panelRight, 1, wx.EXPAND | wx.ALL)
00181 
00182             # SetSizer both sizers in the most senior control that has sizers in it.
00183             self.vMain = wx.BoxSizer(wx.VERTICAL | wx.EXPAND)
00184             self.vMain.Add(hbox, 1, wx.EXPAND, 5)
00185 
00186         #self.vMain.AddStretchSpacer()
00187         #self.vMain.Add(self.frmPanel.widget, 0, wx.EXPAND)
00188         #self.vMain.Add(self.toolbar1, 0, wx.EXPAND)
00189         #self.vMain.AddStretchSpacer()
00190         #self.vMain.Add(hbox, 0, wx.EXPAND|wx.ALL, 5)
00191         self.frmPanel.SetSizer(hbox)
00192         #self.frmPanel.SetSizer(self.vMain)
00193         self.frmPanel.Layout()
00194         #self.toolbar1.Realize()
00195 
00196         
00197         events = self.eventsHandler
00198         # Bind Controls
00199         #self.Bind(wx.EVT_RIGHT_DOWN, events.OnRightDown)
00200         
00201         # Bind View Menu
00202         self.Bind(wx.EVT_MENU, self.frmPanel.widget.onTakePicture, id=ID_CAMERA)
00203         self.Bind(wx.EVT_MENU, self.frmPanel.onSetToWireframe,     id=ID_WIREFRAME)
00204         self.Bind(wx.EVT_MENU, self.frmPanel.onSetToSurface,       id=ID_SURFACE)
00205 
00206         #self.Bind(wx.EVT_MENU, self.frmPanel.onSetToFlatShading,    self.flatShading)
00207         #self.Bind(wx.EVT_MENU, self.frmPanel.onSetToGouraudShading, self.gouraudShading)
00208         #self.Bind(wx.EVT_MENU, self.frmPanel.onSetToPhongShading,   self.phongShading)
00209 
00210         self.Bind(wx.EVT_MENU, events.onBackgroundColor, self.bkgColorView)
00211         #self.Bind(wx.EVT_MENU, events.onToggleStatusBar, self.showStatusBar)
00212         #self.Bind(wx.EVT_MENU, events.onToggleToolBar, self.showToolBar)
00213         
00214         # Bind Help Menu
00215         self.Bind(wx.EVT_MENU, events.onAbout, id=ID_ABOUT)
00216     #end __init__
00217 
00218     def buildTree(self, panel1):
00219         tree = wx.TreeCtrl(self, 1, wx.DefaultPosition, (-1, -1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
00220         root = tree.AddRoot('Programmer')
00221         OS   = tree.AppendItem(root, 'Operating Systems')
00222         tree.AppendItem(OS, 'Linux')
00223         tree.AppendItem(OS, 'FreeBSD')
00224         tree.AppendItem(OS, 'OpenBSD')
00225         tree.AppendItem(OS, 'NetBSD')
00226         tree.AppendItem(OS, 'Solaris')
00227         pl = tree.AppendItem(root, 'Programming Languages')
00228         cl = tree.AppendItem(pl, 'Compiled languages')
00229         sl = tree.AppendItem(pl, 'Scripting languages')
00230         tree.AppendItem(cl, 'Java')
00231         tree.AppendItem(cl, 'C++')
00232         tree.AppendItem(cl, 'C')
00233         tree.AppendItem(cl, 'Pascal')
00234         tree.AppendItem(sl, 'Python')
00235         tree.AppendItem(sl, 'Ruby')
00236         tree.AppendItem(sl, 'Tcl')
00237         tree.AppendItem(sl, 'PHP')
00238 
00239         tk = tree.AppendItem(root, 'Toolkits')
00240         tree.AppendItem(tk, 'Qt')
00241         tree.AppendItem(tk, 'MFC')
00242         tree.AppendItem(tk, 'wxPython')
00243         tree.AppendItem(tk, 'GTK+')
00244         tree.AppendItem(tk, 'Swing')
00245         #self.Bind(wx.EVT_MENU, self.frmPanel.SetToWireframe, id=ID_WIREFRAME)
00246         #tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=1)
00247         return tree
00248 
00249     def OnSelChanged(self, event):
00250         item =  event.GetItem()
00251         self.display.SetLabel(tree.GetItemText(item))
00252 
00253     def UpdateWindowName(self, bdfFileName):
00254         self.bdfFileName = bdfFileName
00255         self.frmPanel.bdfFileName = bdfFileName
00256         windowName = self.frmPanel.getWindowName()
00257         self.SetTitle(windowName)
00258     
00259     def buildStatusBar(self):
00260         self.statusbar = self.CreateStatusBar()
00261         self.statusbar.SetStatusText('Ready')
00262 
00263     def buildToolBar(self):
00264         events = self.eventsHandler
00265 
00266         #toolbar1.AddSeparator()
00267         #toolbar1.AddSeparator()
00268         #tnew  = toolbar1.AddLabelTool(wx.ID_ANY,  '', wx.Bitmap(os.path.join(iconPath,'new.png')))
00269         #tsave = toolbar1.AddLabelTool(ID_SAVEAS,  '', wx.Bitmap(os.path.join(iconPath,'tsave.png')))
00270         #tundo = toolbar1.AddLabelTool(wx.ID_UNDO, '', wx.Bitmap(os.path.join(iconPath,'tundo.png')))
00271         #tredo = toolbar1.AddLabelTool(wx.ID_REDO, '', wx.Bitmap(os.path.join(iconPath,'tredo.png')))
00272 
00273         # toolbar at top - toggles
00274         toolbar1 = self.CreateToolBar()
00275         #toolbar.AddLabelTool(self.id, '', bitmap, wx.NullBitmap, self.kind, 
00276         #                     shortHelp=wx.MenuItem.GetLabelFromText(self.menuText),
00277         #             longHelp=self.helpText)
00278 
00279         topen     = toolbar1.AddLabelTool(ID_BDF,       '', wx.Bitmap(os.path.join(iconPath,'topen.png')),      longHelp='Loads a BDF')
00280         wireframe = toolbar1.AddLabelTool(ID_WIREFRAME, '', wx.Bitmap(os.path.join(iconPath,'twireframe.png')), longHelp='Set to Wireframe Model')
00281         surface   = toolbar1.AddLabelTool(ID_SURFACE,   '', wx.Bitmap(os.path.join(iconPath,'tsolid.png')),     longHelp='Set to Surface/Solid Model')
00282         camera    = toolbar1.AddLabelTool(ID_CAMERA,    '', wx.Bitmap(os.path.join(iconPath,'tcamera.png')),    longHelp='Take a Screenshot')
00283         etool     = toolbar1.AddLabelTool(wx.ID_EXIT,   '', wx.Bitmap(os.path.join(iconPath,'texit.png')),      longHelp='Exit pyNastran GUI')
00284         #toolbar1.EnableTool(wx.ID_REDO, False)
00285         toolbar1.Realize()
00286 
00287         self.toolbar1 = toolbar1
00288 
00289 
00290         # Bind File Menu
00291         self.Bind(wx.EVT_TOOL, events.onLoadBDF,    id=ID_BDF)
00292         self.Bind(wx.EVT_TOOL, events.onLoadOP2,    id=ID_OP2)
00293         self.Bind(wx.EVT_TOOL, events.onLoadCart3d, id=ID_CART3D)
00294         self.Bind(wx.EVT_TOOL, events.onLoadLaWGS,  id=ID_LAWGS)
00295         self.Bind(wx.EVT_TOOL, events.onLoadPanair, id=ID_PANAIR)
00296         #self.Bind(wx.EVT_TOOL, events.onExport,     id=ID_EXPORT)
00297 
00298         self.Bind(wx.EVT_MENU, events.onExit,     id=wx.ID_EXIT)
00299        #self.Bind(wx.EVT_TOOL, events.onExit,     id=wx.ID_EXIT)
00300 
00301         self.Bind(wx.EVT_MENU, self.frmPanel.onSetToWireframe, id=ID_WIREFRAME)
00302         self.Bind(wx.EVT_MENU, self.frmPanel.onSetToSurface,   id=ID_SURFACE)
00303         self.Bind(wx.EVT_MENU, self.frmPanel.onSetToSurface,   id=ID_CAMERA)
00304 
00305 
00306         #self.Bind(wx.EVT_TOOL, events.onSaveAsFile, id=ID_SAVEAS)
00307         #self.Bind(wx.EVT_TOOL, events.onUndo, tundo)
00308         #self.Bind(wx.EVT_TOOL, events.onRedo, tredo)
00309 
00310     def buildMenuBar(self):
00311         events = self.eventsHandler
00312 
00313         menubar = wx.MenuBar()
00314         # --------- File Menu -------------------------------------------------
00315         fileMenu = wx.Menu()
00316         #fileMenu.Append(wx.ID_NEW,  '&New','does nothing')
00317         loadBDF    = fileMenu.Append(ID_BDF,
00318                                      'Load &BDF',
00319                                      'Loads a BDF Input File')
00320         loadOP2    = fileMenu.Append(ID_OP2,
00321                                      'Load O&P2',
00322                                      'Loads an OP2 Results File')
00323         loadCart3d = fileMenu.Append(ID_CART3D,
00324                                      'Load &Cart3D',
00325                                      'Loads a Cart3D Input/Results File')
00326         loadLaWGS  = fileMenu.Append(ID_LAWGS,
00327                                      'Load &LaWGS',
00328                                      'Loads an LaWGS File')
00329         loadPanair = fileMenu.Append(ID_PANAIR,
00330                                      'Load &Panair',
00331                                      'Loads a Panair Input File')
00332         #export     = fileMenu.Append(ID_EXPORT,'Export to...', 'Export the Model to Another Format')
00333         #print "topen = ",os.path.join(iconPath,'topen.png')
00334         sys.stdout.flush()
00335         assert os.path.exists(os.path.join(iconPath,'topen.png'))
00336         loadBDF.SetBitmap(   wx.Image(os.path.join(iconPath,'topen.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap())
00337 
00338         #fileMenu.Append(wx.ID_RES, 'Load OP2 &Results','Loads a OP2 - does nothing')
00339         #fileMenu.Append(wx.ID_SAVE, '&Save','does nothing')
00340         fileMenu.AppendSeparator()
00341 
00342         
00343         # dummy import submenu
00344         #imp = wx.Menu()
00345         #imp.Append(wx.ID_ANY, 'Import newsfeed list...')
00346         #imp.Append(wx.ID_ANY, 'Import bookmarks...')
00347         #imp.Append(wx.ID_ANY, 'Import mail...')
00348 
00349         #fileMenu.AppendMenu(wx.ID_ANY, 'I&mport', imp)
00350         exitButton = wx.MenuItem(fileMenu,
00351                                  wx.ID_EXIT, 'Exit','Exits pyNastran')
00352         exitButton.SetBitmap(wx.Image(os.path.join(iconPath,'texit.png'),
00353                                       wx.BITMAP_TYPE_PNG).ConvertToBitmap())
00354         fileMenu.AppendItem(exitButton)
00355 
00356         # --------- View Menu -------------------------------------------------
00357         # status bar at bottom - toggles
00358         viewMenu = wx.Menu()
00359         camera    = viewMenu.Append(ID_CAMERA,
00360                                     'Take a Screenshot',
00361                                     'Take a Screenshot')
00362         viewMenu.AppendSeparator()
00363         wireframe = viewMenu.Append(ID_WIREFRAME,
00364                                     'Wireframe Model',
00365                                     'Show Model as a Wireframe Model')
00366         surface   = viewMenu.Append(ID_SURFACE,
00367                                     'Surface Model',
00368                                     'Show Model as a Surface Model')
00369         #viewMenu.AppendSeparator()
00370 
00371         #self.flatShading    = viewMenu.Append(wx.ID_ANY, 'Flat Shading',           'Flat Shading')
00372         #self.gouraudShading = viewMenu.Append(wx.ID_ANY, 'Mid (Gouraud) Shading',  'Mid (Gouraud) Shading')
00373         #self.phongShading   = viewMenu.Append(wx.ID_ANY, 'Smooth (Phong) Shading', 'Smooth (Phong) Shading')
00374 
00375         # view images
00376         wireframe.SetBitmap(wx.Image(os.path.join(iconPath,'twireframe.png'),
00377                                      wx.BITMAP_TYPE_PNG).ConvertToBitmap())
00378         surface.SetBitmap(  wx.Image(os.path.join(iconPath,'tsolid.png'),
00379                                      wx.BITMAP_TYPE_PNG).ConvertToBitmap())
00380         camera.SetBitmap(   wx.Image(os.path.join(iconPath,'tcamera.png'),
00381                                      wx.BITMAP_TYPE_PNG).ConvertToBitmap())
00382 
00383         #wireframe = toolbar1.AddLabelTool(ID_WIREFRAME, 'Set to Wireframe Model', wx.Bitmap(os.path.join(iconPath,'twireframe.png')))
00384         #surface   = toolbar1.AddLabelTool(ID_SURFACE,   'Set to Surface Model',   wx.Bitmap(os.path.join(iconPath,'tsolid.png')))
00385         #camera    = toolbar1.AddLabelTool(ID_CAMERA,    'Take a Screenshot',      wx.Bitmap(os.path.join(iconPath,'tcamera.png')))
00386 
00387 
00388         viewMenu.AppendSeparator()
00389         self.bkgColorView  = viewMenu.Append(wx.ID_ANY,
00390                                              'Change Background Color',
00391                                              'Change Background Color')
00392         #self.showStatusBar = viewMenu.Append(wx.ID_ANY, 'Show statusbar', 'Show Statusbar', kind=wx.ITEM_CHECK)
00393         #self.showToolBar   = viewMenu.Append(wx.ID_ANY, 'Show toolbar',   'Show Toolbar',   kind=wx.ITEM_CHECK)
00394         #viewMenu.Check(self.showStatusBar.GetId(), True)
00395         #viewMenu.Check(self.showToolBar.GetId(),   True)
00396 
00397         # --------- Plot Menu -------------------------------------------------
00398         #plotMenu = wx.Menu()
00399         #plot = plotMenu.Append(ID_PLOT, '&Plot Data','Plot Data')
00400         #self.Bind(wx.EVT_MENU, self.onPlot, id=ID_PLOT)
00401         
00402 
00403         # --------- Help / About Menu -----------------------------------------
00404         # help/about menu
00405         helpMenu = wx.Menu()
00406         helpMenu.Append(ID_ABOUT, '&About', 'About pyNastran')
00407 
00408         # menu bar
00409         menubar.Append(fileMenu, '&File')
00410         #menubar.Append(plotMenu, '&Plot')
00411         menubar.Append(viewMenu, '&View')
00412         menubar.Append(helpMenu, '&Help')
00413         self.menubar = menubar
00414 
00415     def onPlot(self, event):
00416         #e = Example(self)
00417         e = TestFrame(self)
00418         e.Show()
00419 #end AppFrame class
00420 
00421 #------------------------------------------------------------------------------
00422 
00423 class TestFrame(wx.Frame):
00424     def __init__(self, parent):
00425         wx.Frame.__init__(self, parent, -1, "GridBagSizer Test")
00426         sizer = wx.GridBagSizer(hgap=5, vgap=5)
00427         
00428         
00429         labels = "1 2 3 4 5 6 7 8 9 0".split()
00430         for col in xrange(3):
00431             for row in xrange(3):
00432                 bw = wx.Button(self, label=labels[row*3 + col])
00433                 sizer.Add(bw, pos=(row, col))
00434 
00435         bw = wx.Button(self, label="span 3 rows")
00436         sizer.Add(bw, pos=(0, 3), span=(3, 1), flag=wx.EXPAND)
00437 
00438         bw = wx.Button(self, label="span all columns")
00439         sizer.Add(bw, pos=(3, 0), span=(1, 4), flag=wx.EXPAND)
00440 
00441         sizer.AddGrowableCol(3)
00442         sizer.AddGrowableRow(3)
00443 
00444         self.SetSizer(sizer)
00445         self.Fit()
00446 
00447 class Example(wx.Frame):
00448     
00449     def __init__(self, *args, **kwargs):
00450         super(Example, self).__init__(*args, **kwargs) 
00451             
00452         self.InitUI()
00453         
00454     def InitUI(self):    
00455 
00456         menubar = wx.MenuBar()
00457         fileMenu = wx.Menu()
00458         fitem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
00459         menubar.Append(fileMenu, '&File')
00460         self.SetMenuBar(menubar)
00461         
00462         self.Bind(wx.EVT_MENU, self.OnQuit, fitem)
00463 
00464         self.SetSize((300, 200))
00465         self.SetTitle('Simple menu')
00466         self.Centre()
00467         self.Show(True)
00468         
00469     def onQuit(self, e):
00470         self.Close()
00471 
00472 class EventsHandler(object) :
00473 
00474     def __init__(self, parent, isNodal=False, isCentroidal=True):
00475         self.parent = parent
00476         self.isNodal = isNodal
00477         self.isCentroidal = isCentroidal
00478 
00479     # File Menu
00480     def onLoadBDF(self, event):
00481         """ Open a file"""
00482         #print "OnOpen..."
00483 
00484         wildcard = "Nastran BDF (*.bdf; *.dat; *.nas)|*.bdf;*.dat;*.nas|" \
00485          "All files (*.*)|*.*"
00486 
00487         Title = 'Choose a Nastran Input Deck to Load'
00488         loadFunction = self.parent.frmPanel.loadNastranGeometry
00489         self.createLoadFileDialog(wildcard, Title, loadFunction,
00490                                   updateWindowName=True)
00491 
00492     def onLoadOP2(self, event):
00493         """ Open a file"""
00494         #print "OnOpen..."
00495 
00496         if 0:
00497             bdf = self.parent.bdfFileName
00498             bdfBase = os.path.basename(bdf)
00499             #dirname = os.path.dirname(bdf)
00500             (op2name, op2) = os.path.splitext(bdfBase)
00501             op2 = os.path.join(self.parent.dirname, op2name+'.op2')
00502             
00503             self.parent.op2FileName = op2
00504             if os.path.exists(op2):
00505                 self.parent.frmPanel.loadNastranResults(op2)
00506                 self.parent.frmPanel.Update()
00507             return
00508         
00509         wildcard = "Nastran OP2 (*.op2)|*.op2|" \
00510          "All files (*.*)|*.*"
00511 
00512         Title = 'Choose a Nastran Output File to Load (OP2 only)'
00513         loadFunction = self.parent.frmPanel.loadNastranResults
00514         self.createLoadFileDialog(wildcard, Title, loadFunction)
00515 
00516     def onLoadCart3d(self, event):
00517         """ Open a file"""
00518         #print "OnOpen..."
00519 
00520         #wildcard = "Cart3d (*.i.tri;*.a.tri)|(*.i.triq;*.a.triq)|" \
00521         # "All files (*.*)|*.*"
00522 
00523         wildcard = "Cart3d (*.i.tri; *.a.tri; *.triq)|*.i.tri;*.a.tri;*.triq|" \
00524          "All files (*.*)|*.*"
00525         #wildcard = "Cart3d (*.tri;)|(*.triq;)|" \
00526         # "All files (*.*)|*.*"
00527         
00528         Title = 'Choose a Cart3d Input File to Load'
00529         loadFunction = self.parent.frmPanel.loadCart3dGeometry
00530         #fname = r'C:\Users\steve\Desktop\pyNastran\pyNastran\converters\cart3d\Cart3d_35000_0.825_10_0_0_0_0.i.triq'
00531         #dirname = ''
00532         #loadFunction(fname,dirname)
00533         self.createLoadFileDialog(wildcard, Title, loadFunction,
00534                                   updateWindowName=True)
00535 
00536     def onLoadLaWGS(self, event):
00537         """ Open a file"""
00538         wildcard = "LaWGS (*.wgs)|*.wgs|" \
00539          "All files (*.*)|*.*"
00540 
00541         Title = 'Choose a LaWGS File to Load'
00542         loadFunction = self.parent.frmPanel.loadLaWGSGeometry
00543         #fname = r'C:\Users\steve\Desktop\pyNastran\pyNastran\converters\cart3d\Cart3d_35000_0.825_10_0_0_0_0.i.triq'
00544         #dirname = ''
00545         #loadFunction(fname,dirname)
00546         self.createLoadFileDialog(wildcard, Title, loadFunction,
00547                                   updateWindowName=True)
00548 
00549     def onLoadPanair(self, event):
00550         """ Open a file"""
00551         wildcard = "Panair (*.inp)|*.inp|" \
00552          "All files (*.*)|*.*"
00553 
00554         Title = 'Choose a Panair Input File to Load'
00555         loadFunction = self.parent.frmPanel.loadPanairGeometry
00556         #fname = r'C:\Users\steve\Desktop\pyNastran\pyNastran\converters\cart3d\Cart3d_35000_0.825_10_0_0_0_0.i.triq'
00557         #dirname = ''
00558         #loadFunction(fname,dirname)
00559         self.createLoadFileDialog(wildcard, Title, loadFunction,
00560                                   updateWindowName=True)
00561 
00562     def createLoadFileDialog(self, wildcard, Title, loadFunction,
00563                              updateWindowName=False):
00564         dlg = wx.FileDialog(None, Title, self.parent.dirname, "",
00565                             wildcard, wx.OPEN)
00566         if dlg.ShowModal() == wx.ID_OK:
00567             fileName            = dlg.GetFilename()
00568             self.parent.dirname = dlg.GetDirectory()
00569             fname = os.path.join(self.parent.dirname, fileName)
00570             print("fname = ", fname)
00571             if updateWindowName:
00572                 self.parent.UpdateWindowName(fileName)
00573             #self.parent.frmPanel.loadCart3dGeometry(fname,self.parent.dirname)
00574             loadFunction(fname, self.parent.dirname,
00575                          self.isNodal, self.isCentroidal)
00576             self.parent.frmPanel.Update()
00577         dlg.Destroy()
00578 
00579     def onExport(self):
00580         if self.modelType == 'nastran':
00581             pass
00582 
00583         if self.modelType == 'cart3d':
00584             exportToNastran(self, fname, points, elements, regions)
00585 
00586         wildcard = ("Nastran OP2 (*.op2)|*.op2|"
00587                     "All files (*.*)|*.*")
00588 
00589         Title = 'Choose a Nastran Output File to Load (OP2 only)'
00590         loadFunction = self.parent.frmPanel.loadNastranResults
00591         self.createLoadFileDialog(wildcard, Title, loadFunction)
00592         
00593     def onExit(self, event):
00594         self.parent.Destroy()
00595 
00596     # View Menu
00597     def onBackgroundColor(self, event):
00598         dlg = wx.ColourDialog(self.parent)
00599         dlg.GetColourData().SetChooseFull(True)
00600         if dlg.ShowModal() == wx.ID_OK:
00601             data = dlg.GetColourData()
00602             #print 'You selected: %s\n' % str(data.GetColour().Get())
00603             dlg.Destroy()
00604             self.SetColor(data.GetColour().Get())
00605             return
00606         dlg.Destroy()
00607 
00608     def SetColor(self, bkgColor):
00609         """
00610         @warning if the model is not loaded and the color is not "clicked"
00611         on, then rend will return None
00612         """
00613         rend = self.parent.frmPanel.widget.GetCurrentRenderer()
00614         if not rend: # rend doesnt exist at first
00615             print 'Try again to change the color (you didnt "click" on the color; one time bug)'
00616             return
00617             rend = self.parent.frmPanel.widget.GetCurrentRenderer()
00618 
00619         ## bkgColor range from 0 to 255
00620         ## color ranges from 0 to 1
00621         color = [bkgColor[0]/255., bkgColor[1]/255., bkgColor[2]/255.]
00622         rend.SetBackground(color)
00623         self.parent.frmPanel.widget.Render()
00624 
00625     def onToggleStatusBar(self, e):
00626         if self.parent.showStatusBar.IsChecked():
00627             self.parent.statusbar.Show()
00628         else:
00629             self.parent.statusbar.Hide()
00630 
00631     def onToggleToolBar(self, e):
00632         if self.parent.showToolBar.IsChecked():
00633             self.parent.toolbar1.Show()
00634         else:
00635             self.parent.toolbar1.Hide()
00636 
00637     # Help Menu
00638     def onAbout(self, event):
00639         about = [
00640             'pyNastran v%s' %(pyNastran.__version__),
00641             'Copyright %s; Steven Doyle 2011-2012\n' %(pyNastran.__license__),
00642             '%s' %(pyNastran.__website__),
00643             '',
00644             'Mouse',
00645               'Left Click - Rotate',
00646               'Middle Click - Pan/Recenter Rotation Point',
00647               'Shift + Left Click - Pan/Recenter Rotation Point',
00648               'Right Mouse - Zoom',
00649             '',
00650             'Keyboard Controls',
00651               'X/x - snap to x axis',
00652               'Y/y - snap to y axis',
00653               'Z/z - snap to z axis',
00654               '',
00655               'h   - show/hide legend & info',
00656               'i   - take a screenshot (image)',
00657               'L   - cycle op2 results',
00658               'm/M - scale up/scale down by 1.1 times',
00659               'o/O - rotate counter-clockwise/clockwise 5 degrees',
00660               's   - surface',
00661               'w   - wireframe',
00662               ]
00663         
00664         # not done
00665               #'',
00666               #'left arrow  - pan left',
00667               #'right arrow - pan right',
00668               #'up arrow    - pan up',
00669               #'down arrow  - pan down',
00670               #'',
00671               #'e  - show/hide edges',
00672               #'f   fly to rotation point',
00673               #'p   project point',
00674 
00675         dlg = wx.MessageDialog(None, '\n'.join(about), 'About',
00676                  wx.OK | wx.ICON_INFORMATION)
00677         dlg.ShowModal()
00678         dlg.Destroy()
00679 
00680 #end Events class
00681 
00682 #------------------------------------------------------------------------------
00683 def runArgParse():
00684     import argparse
00685 
00686     ver = str(pyNastran.__version__)
00687     parser = argparse.ArgumentParser(description='Tests to see if an OP2 will work with pyNastran.', add_help=True) # version=ver)
00688     #parser.add_argument('op2FileName', metavar='op2FileName', type=str, nargs=1,
00689     #                   help='path to OP2 file')
00690 
00691     group = parser.add_mutually_exclusive_group()
00692     group.add_argument( '-q', '--quiet', dest='quiet', action='store_true',
00693                        help='prints debug messages (default=True)')
00694 
00695     group2 = parser.add_mutually_exclusive_group()
00696     group2.add_argument('-e', '--edges', dest='edges', action='store_true',
00697                         help='shows element edges as black lines')
00698     #group2.add_argument('-w','--writeBDF', dest='writeBDF', action='store_true', help='Writes the bdf to fem.bdf.out')
00699 
00700     group3 = parser.add_mutually_exclusive_group()
00701     group3.add_argument('-n', '--nodalResults',      dest='isNodal',
00702                         action='store_true', help='plots nodal results')
00703     group3.add_argument('-c', '--centroidalResults', dest='isNodal',
00704                         action='store_false', help='plots centroidal results')
00705 
00706     parser.add_argument('-v', '--version', action='version', version=ver)
00707     
00708     if len(sys.argv) == 1:
00709         parser.print_help()
00710         sys.exit()
00711     args = parser.parse_args()
00712     #print "op2FileName = ", args.op2FileName[0]
00713     #print "debug       = ", not(args.quiet)
00714 
00715     debug = not(args.quiet)
00716     edges = args.edges
00717     isNodal = args.isNodal
00718     #writeBDF    = args.writeBDF
00719     #op2FileName = args.op2FileName[0]
00720 
00721     return (edges, isNodal, debug)
00722 
00723 def main():
00724     isEdges = False
00725     isNodal = True
00726     #isCentroidal = True
00727     debug   = True
00728     if sys.version_info < (2, 6):
00729         print("requires Python 2.6+ to use command line arguments...")
00730     else:
00731         if len(sys.argv) > 1:
00732             (isEdges, isNodal, debug) = runArgParse()
00733     isCentroidal = not(isNodal)
00734 
00735     isNodal = True
00736     isCentroidal = True
00737 
00738     app = wx.App(redirect=False)
00739     appFrm = AppFrame(isEdges, isNodal, isCentroidal, debug)
00740     #appFrm.Show()
00741     print("launching gui")
00742     app.MainLoop()
00743 
00744 #end class
00745 
00746 #==============================================================================
00747 
00748 if __name__ == '__main__' :
00749     main()
 All Classes Namespaces Files Functions Variables