| 1 | #! /bin/env python |
|---|
| 2 | |
|---|
| 3 | ## Copyright 2005, 2006, 2007, 2008 Virginia Polytechnic Institute and State University |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of the OSSIE ALF Waveform Application Visualization Environment |
|---|
| 6 | ## |
|---|
| 7 | ## ALF is free software; you can redistribute it and/or modify |
|---|
| 8 | ## it under the terms of the GNU General Public License as published by |
|---|
| 9 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | ## (at your option) any later version. |
|---|
| 11 | ## |
|---|
| 12 | ## ALF is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 13 | ## WARRANTY; without even the implied warranty of |
|---|
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | ## GNU General Public License for more details. |
|---|
| 16 | ## |
|---|
| 17 | ## You should have received a copy of the GNU General Public License |
|---|
| 18 | ## along with OSSIE Waveform Developer; if not, write to the Free Software |
|---|
| 19 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import wx |
|---|
| 22 | from wx.lib import ogl |
|---|
| 23 | |
|---|
| 24 | try: # mac framework |
|---|
| 25 | from wavedev import ComponentClass as CC |
|---|
| 26 | from wavedev import WaveformClass |
|---|
| 27 | import CF, CF__POA |
|---|
| 28 | import customInterfaces |
|---|
| 29 | import standardInterfaces |
|---|
| 30 | import importResource |
|---|
| 31 | import importIDL |
|---|
| 32 | |
|---|
| 33 | except ImportError: # 0.6.2 |
|---|
| 34 | from WaveDev.wavedev import ComponentClass as CC |
|---|
| 35 | from WaveDev.wavedev import WaveformClass |
|---|
| 36 | import ossie.standardinterfaces.standardInterfaces as standardInterfaces |
|---|
| 37 | import ossie.custominterfaces.customInterfaces as customInterfaces |
|---|
| 38 | import ossie.cf.CF as CF |
|---|
| 39 | import ossie.cf.CF__POA as CF__POA |
|---|
| 40 | import WaveDev.wavedev.importResource as importResource |
|---|
| 41 | import WaveDev.wavedev.importIDL as importIDL |
|---|
| 42 | |
|---|
| 43 | from omniORB import CORBA, PortableServer |
|---|
| 44 | import CosNaming |
|---|
| 45 | import sys |
|---|
| 46 | import importWaveform |
|---|
| 47 | import ALFshapes, ALFtiming |
|---|
| 48 | |
|---|
| 49 | import xml.dom.minidom |
|---|
| 50 | from xml.dom.minidom import Node |
|---|
| 51 | |
|---|
| 52 | import os |
|---|
| 53 | import ALFutils |
|---|
| 54 | |
|---|
| 55 | import connectTool |
|---|
| 56 | import compform |
|---|
| 57 | import shutil |
|---|
| 58 | |
|---|
| 59 | import wx.lib.foldpanelbar as fpb |
|---|
| 60 | |
|---|
| 61 | #---------------------------------------------------------------------- |
|---|
| 62 | # Create unique IDs for menu items and toolbar items for associating |
|---|
| 63 | # events with a particular action |
|---|
| 64 | [wxID_TOOLBAR_TIMING_TOOL, wxID_TOOLBAR_REFRESH_TOOL, |
|---|
| 65 | wxID_TOOLBAR_TIMING_DISPLAY_TOOL, wxID_TOOLBAR_CONNECT_TOOL] = [ |
|---|
| 66 | wx.NewId() for x in range(4)] |
|---|
| 67 | |
|---|
| 68 | [wxID_NSBOX_POPUP_DISPLAY, wxID_NSBOX_POPUP_START, |
|---|
| 69 | wxID_NSBOX_POPUP_STOP, wxID_NSBOX_POPUP_UNINSTALL] = [ |
|---|
| 70 | wx.NewId() for x in range(4)] |
|---|
| 71 | |
|---|
| 72 | [wxID_INSTALLBOX_POPUP_INSTALL_START, wxID_COMPONENTSBOX_POPUP_INSTALL_START, |
|---|
| 73 | wxID_INSTALLBOX_POPUP_INSTALL, wxID_COMPONENTSBOX_POPUP_INSTALL] = [wx.NewId() for x in range(4)] |
|---|
| 74 | |
|---|
| 75 | #---------------------------------------------------------------------- |
|---|
| 76 | class alfApp(wx.App): |
|---|
| 77 | def OnInit(self): |
|---|
| 78 | self.main = alfFrame(None) |
|---|
| 79 | self.main.Show() |
|---|
| 80 | self.SetTopWindow(self.main) |
|---|
| 81 | return True |
|---|
| 82 | |
|---|
| 83 | #---------------------------------------------------------------------- |
|---|
| 84 | class alfFrame(wx.Frame): |
|---|
| 85 | def _init_ctrls(self, parent): |
|---|
| 86 | wx.Frame.__init__(self, id=-1, name='CompFrame', |
|---|
| 87 | parent=parent, pos=wx.DefaultPosition, size=wx.Size(1100, 770), |
|---|
| 88 | style=wx.DEFAULT_FRAME_STYLE, title=u'ALF - Waveform Debugger') |
|---|
| 89 | |
|---|
| 90 | # Initialize graphics |
|---|
| 91 | ogl.OGLInitialize() |
|---|
| 92 | ALFshapes.initializeColours() |
|---|
| 93 | |
|---|
| 94 | # Create the sash window and layout |
|---|
| 95 | self._leftWindow = wx.SashLayoutWindow(self, 101, wx.DefaultPosition, |
|---|
| 96 | wx.Size(240, 600), wx.NO_BORDER | wx.SW_3D | wx.CLIP_CHILDREN) |
|---|
| 97 | |
|---|
| 98 | self._leftWindow.SetDefaultSize(wx.Size(300, 400)) |
|---|
| 99 | self._leftWindow.SetOrientation(wx.LAYOUT_VERTICAL) |
|---|
| 100 | self._leftWindow.SetAlignment(wx.LAYOUT_LEFT) |
|---|
| 101 | self._leftWindow.SetSashVisible(wx.SASH_RIGHT, True) |
|---|
| 102 | self._leftWindow.SetExtraBorderSize(10) |
|---|
| 103 | |
|---|
| 104 | self.ID_WINDOW_TOP = 100 |
|---|
| 105 | self.ID_WINDOW_LEFT = 101 |
|---|
| 106 | self.ID_WINDOW_RIGHT = 102 |
|---|
| 107 | self.ID_WINDOW_BOTTOM = 103 |
|---|
| 108 | |
|---|
| 109 | self._leftWindow.Bind(wx.EVT_SASH_DRAGGED_RANGE, self.OnFoldPanelBarDrag, |
|---|
| 110 | id=100, id2=103) |
|---|
| 111 | self.Bind(wx.EVT_SIZE, self.OnFoldPanelSize) |
|---|
| 112 | |
|---|
| 113 | # Instantiate the main canvas |
|---|
| 114 | self.canvas = MainWindow(self, self) |
|---|
| 115 | |
|---|
| 116 | # Create the fold panel and add its windows |
|---|
| 117 | self._fpb_pnl = None |
|---|
| 118 | self.CreateFoldPanel() |
|---|
| 119 | |
|---|
| 120 | # Create the status and toolbars |
|---|
| 121 | self.CreateStatusBar(1, wx.ST_SIZEGRIP) |
|---|
| 122 | self.CreateToolBar() |
|---|
| 123 | |
|---|
| 124 | # Make a popup box for the Naming Service / Manage Waveforms functionality |
|---|
| 125 | self.nsBoxPopup = wx.Menu(title=u'') |
|---|
| 126 | self.init_nsBoxPopup_Items(self.nsBoxPopup) |
|---|
| 127 | |
|---|
| 128 | # Make a popup box for the Launch Waveforms functionality |
|---|
| 129 | self.installBoxPopup = wx.Menu(title=u'') |
|---|
| 130 | self.init_installBoxPopup_Items(self.installBoxPopup) |
|---|
| 131 | |
|---|
| 132 | # Make a popup box for the Launch Components asWaveforms functionality |
|---|
| 133 | self.componentsBoxPopup = wx.Menu(title=u'') |
|---|
| 134 | self.init_componentsBoxPopup_Items(self.componentsBoxPopup) |
|---|
| 135 | |
|---|
| 136 | self.setupToolbar() |
|---|
| 137 | |
|---|
| 138 | def __init__(self,parent): |
|---|
| 139 | self.active_wave = None |
|---|
| 140 | self.timing_display = None |
|---|
| 141 | self.tools = None |
|---|
| 142 | self.waveform_displays = {} |
|---|
| 143 | |
|---|
| 144 | self.compform_counter = 0 |
|---|
| 145 | |
|---|
| 146 | self._init_ctrls(parent) |
|---|
| 147 | self.Available_Ints = ALFutils.importStandardIdl(self) |
|---|
| 148 | self.rootContext = None |
|---|
| 149 | self.domMgr = None |
|---|
| 150 | self.init_CORBA() |
|---|
| 151 | |
|---|
| 152 | ALFutils.LoadConfiguration(self) |
|---|
| 153 | |
|---|
| 154 | self.waveformData = {} |
|---|
| 155 | self.tool_frames = [] |
|---|
| 156 | self.last_waveform_data_update = None |
|---|
| 157 | self.dasXML_list = [] |
|---|
| 158 | self.availableWaveforms = {} |
|---|
| 159 | self.availableComponents = {} |
|---|
| 160 | |
|---|
| 161 | if self.rootContext != None: |
|---|
| 162 | self.DisplayInstalledWaveforms() |
|---|
| 163 | self.DisplayAvailableWaveforms() |
|---|
| 164 | self.DisplayAvailableComponents() |
|---|
| 165 | |
|---|
| 166 | def init_CORBA(self): |
|---|
| 167 | """Initialize an orb and try to connect to the DomainManager""" |
|---|
| 168 | |
|---|
| 169 | orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) |
|---|
| 170 | obj = orb.resolve_initial_references("NameService") |
|---|
| 171 | try: |
|---|
| 172 | self.rootContext = obj._narrow(CosNaming.NamingContext) |
|---|
| 173 | except: |
|---|
| 174 | ts = "Failed to narrow the root naming context.\n" |
|---|
| 175 | ts += "Are the Naming Service and nodeBooter running?" |
|---|
| 176 | errorMsg(self, ts) |
|---|
| 177 | self.rootContext = None |
|---|
| 178 | self.domMgr = None |
|---|
| 179 | return |
|---|
| 180 | |
|---|
| 181 | if self.rootContext is None: |
|---|
| 182 | errorMsg(self,"Failed to narrow the root naming context") |
|---|
| 183 | self.domMgr = None |
|---|
| 184 | return |
|---|
| 185 | |
|---|
| 186 | name = [CosNaming.NameComponent("DomainName1",""), |
|---|
| 187 | CosNaming.NameComponent("DomainManager","")] |
|---|
| 188 | |
|---|
| 189 | try: |
|---|
| 190 | obj = self.rootContext.resolve(name) |
|---|
| 191 | except: |
|---|
| 192 | errorMsg(self,"DomainManger name not found") |
|---|
| 193 | self.domMgr = None |
|---|
| 194 | return |
|---|
| 195 | |
|---|
| 196 | self.domMgr = obj._narrow(CF.DomainManager) |
|---|
| 197 | |
|---|
| 198 | #--------------------------------------------------------------- |
|---|
| 199 | # Setup the display |
|---|
| 200 | #--------------------------------------------------------------- |
|---|
| 201 | def init_nsBoxPopup_Items(self, parent): |
|---|
| 202 | """Setup the popup menu for the Naming Service / Manage Waveforms box""" |
|---|
| 203 | |
|---|
| 204 | parent.Append(help='', id=wxID_NSBOX_POPUP_DISPLAY, kind=wx.ITEM_NORMAL, |
|---|
| 205 | text=u'Display') |
|---|
| 206 | self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupDisplayMenu, |
|---|
| 207 | id=wxID_NSBOX_POPUP_DISPLAY) |
|---|
| 208 | |
|---|
| 209 | parent.Append(help='', id=wxID_NSBOX_POPUP_START, kind=wx.ITEM_NORMAL, |
|---|
| 210 | text=u'Start') |
|---|
| 211 | self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupStartMenu, |
|---|
| 212 | id=wxID_NSBOX_POPUP_START) |
|---|
| 213 | |
|---|
| 214 | parent.Append(help='', id=wxID_NSBOX_POPUP_STOP, kind=wx.ITEM_NORMAL, |
|---|
| 215 | text=u'Stop') |
|---|
| 216 | self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupStopMenu, |
|---|
| 217 | id=wxID_NSBOX_POPUP_STOP) |
|---|
| 218 | |
|---|
| 219 | parent.Append(help='', id=wxID_NSBOX_POPUP_UNINSTALL, kind=wx.ITEM_NORMAL, |
|---|
| 220 | text=u'Uninstall') |
|---|
| 221 | self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupUninstallMenu, |
|---|
| 222 | id=wxID_NSBOX_POPUP_UNINSTALL) |
|---|
| 223 | |
|---|
| 224 | def init_installBoxPopup_Items(self, parent): |
|---|
| 225 | """Setup the popup menu for the Launch Waveforms box""" |
|---|
| 226 | |
|---|
| 227 | parent.Append(help='', id=wxID_INSTALLBOX_POPUP_INSTALL_START, |
|---|
| 228 | kind=wx.ITEM_NORMAL, text=u'Install and Start') |
|---|
| 229 | self.installBox.Bind(wx.EVT_MENU, self.OnInstallBoxPopupInstallStartMenu, |
|---|
| 230 | id=wxID_INSTALLBOX_POPUP_INSTALL_START) |
|---|
| 231 | |
|---|
| 232 | parent.Append(help='', id=wxID_INSTALLBOX_POPUP_INSTALL, |
|---|
| 233 | kind=wx.ITEM_NORMAL, text=u'Install') |
|---|
| 234 | self.installBox.Bind(wx.EVT_MENU, self.OnInstallBoxPopupInstallMenu, |
|---|
| 235 | id=wxID_INSTALLBOX_POPUP_INSTALL) |
|---|
| 236 | |
|---|
| 237 | def init_componentsBoxPopup_Items(self, parent): |
|---|
| 238 | """Setup the popup menu for the Launch Components as Waveforms box""" |
|---|
| 239 | |
|---|
| 240 | parent.Append(help='', id=wxID_COMPONENTSBOX_POPUP_INSTALL_START, |
|---|
| 241 | kind=wx.ITEM_NORMAL, text=u'Install and Start') |
|---|
| 242 | self.componentsBox.Bind(wx.EVT_MENU, self.OnComponentsBoxPopupInstallStartMenu, |
|---|
| 243 | id=wxID_COMPONENTSBOX_POPUP_INSTALL_START) |
|---|
| 244 | |
|---|
| 245 | parent.Append(help='', id=wxID_COMPONENTSBOX_POPUP_INSTALL, |
|---|
| 246 | kind=wx.ITEM_NORMAL, text=u'Install') |
|---|
| 247 | self.componentsBox.Bind(wx.EVT_MENU, self.OnComponentsBoxPopupInstallMenu, |
|---|
| 248 | id=wxID_COMPONENTSBOX_POPUP_INSTALL) |
|---|
| 249 | |
|---|
| 250 | def CreateFoldPanel(self): |
|---|
| 251 | self._fpb_pnl = fpb.FoldPanelBar(self._leftWindow, -1, wx.DefaultPosition, |
|---|
| 252 | wx.Size(-1,-1), fpb.FPB_DEFAULT_STYLE, 0) |
|---|
| 253 | |
|---|
| 254 | # Create the image list for the fold button icons |
|---|
| 255 | Images = wx.ImageList(16,16) |
|---|
| 256 | Images.Add(ALFutils.GetExpandedIconBitmap()) |
|---|
| 257 | Images.Add(ALFutils.GetCollapsedIconBitmap()) |
|---|
| 258 | |
|---|
| 259 | # Add the Launch Waveforms box |
|---|
| 260 | item = self._fpb_pnl.AddFoldPanel("Launch Waveform Applications", |
|---|
| 261 | collapsed=False, |
|---|
| 262 | foldIcons=Images) |
|---|
| 263 | self.installBox = wx.TreeCtrl(name=u'installBox', |
|---|
| 264 | parent=item, |
|---|
| 265 | size = wx.Size(-1,200), |
|---|
| 266 | style = wx.TR_HIDE_ROOT | |
|---|
| 267 | wx.TR_HAS_BUTTONS | |
|---|
| 268 | wx.SIMPLE_BORDER) |
|---|
| 269 | self._fpb_pnl.AddFoldPanelWindow(item, self.installBox, |
|---|
| 270 | fpb.FPB_ALIGN_WIDTH, 4) |
|---|
| 271 | self.installBox.Bind(wx.EVT_RIGHT_UP, self.OnInstallBoxRightUp) |
|---|
| 272 | self.installBox.Bind(wx.EVT_LEFT_DCLICK, self.OnInstallBoxLeftDclick) |
|---|
| 273 | |
|---|
| 274 | # Add the Launch Components as Waveforms box |
|---|
| 275 | item = self._fpb_pnl.AddFoldPanel("Launch Components as Applications", |
|---|
| 276 | collapsed=False, |
|---|
| 277 | foldIcons=Images) |
|---|
| 278 | self.componentsBox = wx.TreeCtrl(name=u'componentsBox', |
|---|
| 279 | parent=item, |
|---|
| 280 | size = wx.Size(-1,200), |
|---|
| 281 | style = wx.TR_HIDE_ROOT | |
|---|
| 282 | wx.TR_HAS_BUTTONS | |
|---|
| 283 | wx.SIMPLE_BORDER) |
|---|
| 284 | self._fpb_pnl.AddFoldPanelWindow(item, self.componentsBox, |
|---|
| 285 | fpb.FPB_ALIGN_WIDTH, 4) |
|---|
| 286 | self.componentsBox.Bind(wx.EVT_RIGHT_UP, self.OnComponentsBoxRightUp) |
|---|
| 287 | self.componentsBox.Bind(wx.EVT_LEFT_DCLICK, |
|---|
| 288 | self.OnComponentsBoxLeftDclick) |
|---|
| 289 | |
|---|
| 290 | # Add the Manage Waveforms box |
|---|
| 291 | item = self._fpb_pnl.AddFoldPanel("Manage Applications", |
|---|
| 292 | collapsed=False, |
|---|
| 293 | foldIcons=Images) |
|---|
| 294 | self.nsBox = wx.TreeCtrl(name=u'nsBox', parent=item, |
|---|
| 295 | size = wx.Size(-1,200), |
|---|
| 296 | style = wx.TR_HIDE_ROOT | |
|---|
| 297 | wx.TR_HAS_BUTTONS | |
|---|
| 298 | wx.SIMPLE_BORDER) |
|---|
| 299 | self.nsBox.Bind(wx.EVT_RIGHT_UP, self.OnNsBoxRightUp) |
|---|
| 300 | self.nsBox.Bind(wx.EVT_LEFT_DCLICK, self.OnNsBoxLeftDclick) |
|---|
| 301 | self._fpb_pnl.AddFoldPanelWindow(item, self.nsBox, |
|---|
| 302 | fpb.FPB_ALIGN_WIDTH, 4) |
|---|
| 303 | |
|---|
| 304 | self._leftWindow.SizeWindows() |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | def setupToolbar(self): |
|---|
| 308 | toolbar = self.GetToolBar() |
|---|
| 309 | tsize = (20,20) |
|---|
| 310 | test_bmp = wx.ArtProvider.GetBitmap(wx.ART_REDO, wx.ART_TOOLBAR, tsize) |
|---|
| 311 | toolbar.AddSimpleTool(wxID_TOOLBAR_REFRESH_TOOL,test_bmp,shortHelpString="Refresh") |
|---|
| 312 | toolbar.AddSeparator() |
|---|
| 313 | |
|---|
| 314 | root = __file__ |
|---|
| 315 | if os.path.islink (root): |
|---|
| 316 | root = os.path.realpath (root) |
|---|
| 317 | root = os.path.dirname (os.path.abspath (root)) |
|---|
| 318 | |
|---|
| 319 | time_img = wx.Image(root + '/images/timing.png',type=wx.BITMAP_TYPE_PNG) |
|---|
| 320 | time_img.Rescale(24,24) |
|---|
| 321 | time_bmp = wx.BitmapFromImage(time_img) |
|---|
| 322 | toolbar.AddCheckTool(wxID_TOOLBAR_TIMING_TOOL,time_bmp,shortHelp="Enable Timing") |
|---|
| 323 | self.timing_view_state = False |
|---|
| 324 | |
|---|
| 325 | time_img = wx.Image(root + '/images/timing_display.png',type=wx.BITMAP_TYPE_PNG) |
|---|
| 326 | time_img.Rescale(24,24) |
|---|
| 327 | time_bmp = wx.BitmapFromImage(time_img) |
|---|
| 328 | toolbar.AddCheckTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL,time_bmp,shortHelp="Toggle Timing Display") |
|---|
| 329 | |
|---|
| 330 | toolbar.AddSeparator() |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | connect_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) |
|---|
| 334 | toolbar.AddSimpleTool(wxID_TOOLBAR_CONNECT_TOOL,connect_bmp,shortHelpString="Connect Tool") |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | toolbar.Bind(wx.EVT_TOOL, self.OnToolBarClick) |
|---|
| 339 | |
|---|
| 340 | toolbar.Realize() |
|---|
| 341 | |
|---|
| 342 | # --------------------------------------------------- |
|---|
| 343 | # Event handling for toolbar |
|---|
| 344 | # --------------------------------------------------- |
|---|
| 345 | def OnToolBarClick(self,event): |
|---|
| 346 | tb = self.GetToolBar() |
|---|
| 347 | if event.GetId() == wxID_TOOLBAR_TIMING_TOOL: |
|---|
| 348 | if tb.GetToolState(wxID_TOOLBAR_TIMING_TOOL): |
|---|
| 349 | if self.active_wave == None: |
|---|
| 350 | errorMsg(self,"Please select and display a waveform first!") |
|---|
| 351 | tb.ToggleTool(wxID_TOOLBAR_TIMING_TOOL, False) |
|---|
| 352 | return |
|---|
| 353 | tb.EnableTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, True) |
|---|
| 354 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Disable Timing") |
|---|
| 355 | self.timing_display = ALFtiming.TimingDisplay(self.active_wave.naming_context, self) |
|---|
| 356 | else: |
|---|
| 357 | self.timing_display = None |
|---|
| 358 | tb.EnableTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, False) |
|---|
| 359 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Enable Timing") |
|---|
| 360 | self.refreshDisplay() |
|---|
| 361 | |
|---|
| 362 | if event.GetId() == wxID_TOOLBAR_TIMING_DISPLAY_TOOL: |
|---|
| 363 | if tb.GetToolState(wxID_TOOLBAR_TIMING_DISPLAY_TOOL): |
|---|
| 364 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Disable Timing Graphics") |
|---|
| 365 | self.timing_view_state = True |
|---|
| 366 | else: |
|---|
| 367 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Enable Timing Graphics") |
|---|
| 368 | self.timing_view_state = False |
|---|
| 369 | |
|---|
| 370 | elif event.GetId() == wxID_TOOLBAR_CONNECT_TOOL: |
|---|
| 371 | self.connect_frame = connectTool.create(self) |
|---|
| 372 | |
|---|
| 373 | # Refresh the display: Naming Service, Waveform List, and Canvas |
|---|
| 374 | elif event.GetId() == wxID_TOOLBAR_REFRESH_TOOL: |
|---|
| 375 | self.refreshDisplay(True) |
|---|
| 376 | self.DisplayInstalledWaveforms() |
|---|
| 377 | self.DisplayAvailableWaveforms() |
|---|
| 378 | self.DisplayAvailableComponents() |
|---|
| 379 | tb.ToggleTool(wxID_TOOLBAR_REFRESH_TOOL, False) |
|---|
| 380 | |
|---|
| 381 | def processTimingEvent(self, component_name, port_name, function_name, description, time_s, time_us, number_samples): |
|---|
| 382 | if self.active_wave == None or (self.active_wave.naming_context not in component_name): |
|---|
| 383 | errorMsg(self,"Cannot find waveform containing: " + component_name) |
|---|
| 384 | |
|---|
| 385 | cname = component_name[component_name.rfind('/')+1:] |
|---|
| 386 | if self.active_wave != None: |
|---|
| 387 | for comp in self.active_wave.components: |
|---|
| 388 | if comp.name == cname: |
|---|
| 389 | comp.shape.processTimingEvent(port_name, function_name, description, time_s, time_us, number_samples) |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | # --------------------------------------------------------- |
|---|
| 394 | # Event handling for the FoldPanel |
|---|
| 395 | # -------------------------------------------------------- |
|---|
| 396 | def OnFoldPanelSize(self, event): |
|---|
| 397 | wx.LayoutAlgorithm().LayoutWindow(self, self.canvas) |
|---|
| 398 | event.Skip() |
|---|
| 399 | |
|---|
| 400 | def OnFoldPanelBarDrag(self, event): |
|---|
| 401 | if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: |
|---|
| 402 | return |
|---|
| 403 | |
|---|
| 404 | if event.GetId() == self.ID_WINDOW_LEFT: |
|---|
| 405 | self._leftWindow.SetDefaultSize(wx.Size(event.GetDragRect().width, 400)) |
|---|
| 406 | |
|---|
| 407 | # Leaves bits of itself behind sometimes |
|---|
| 408 | wx.LayoutAlgorithm().LayoutWindow(self, self.canvas) |
|---|
| 409 | self.canvas.Refresh() |
|---|
| 410 | |
|---|
| 411 | event.Skip() |
|---|
| 412 | |
|---|
| 413 | # --------------------------------------------------------- |
|---|
| 414 | # Event handling for Naming Service / Manage Waveforms box |
|---|
| 415 | # -------------------------------------------------------- |
|---|
| 416 | def OnNsBoxRightUp(self, event): |
|---|
| 417 | self.nsBox.PopupMenu(self.nsBoxPopup) |
|---|
| 418 | event.Skip() |
|---|
| 419 | |
|---|
| 420 | def OnNsBoxLeftDclick(self, event): |
|---|
| 421 | self.DisplayWaveform() |
|---|
| 422 | event.Skip() |
|---|
| 423 | |
|---|
| 424 | def OnNsBoxPopupDisplayMenu(self, event): |
|---|
| 425 | self.DisplayWaveform() |
|---|
| 426 | event.Skip() |
|---|
| 427 | |
|---|
| 428 | def OnNsBoxPopupStartMenu(self, event): |
|---|
| 429 | self.StartApplication() |
|---|
| 430 | event.Skip() |
|---|
| 431 | |
|---|
| 432 | def OnNsBoxPopupStopMenu(self, event): |
|---|
| 433 | self.StopApplication() |
|---|
| 434 | event.Skip() |
|---|
| 435 | |
|---|
| 436 | def OnNsBoxPopupUninstallMenu(self, event): |
|---|
| 437 | self.UninstallWaveform() |
|---|
| 438 | event.Skip() |
|---|
| 439 | |
|---|
| 440 | def DisplayWaveform(self): |
|---|
| 441 | sn = self.nsBox.GetSelection() |
|---|
| 442 | if sn == self.nsBox.GetRootItem(): |
|---|
| 443 | errorMsg(self,'Please select a waveform!') |
|---|
| 444 | return |
|---|
| 445 | snPrnt = self.nsBox.GetItemParent(sn) |
|---|
| 446 | if snPrnt != self.nsBox.GetRootItem(): |
|---|
| 447 | errorMsg(self,'Please select a waveform!') |
|---|
| 448 | return |
|---|
| 449 | |
|---|
| 450 | wave_name = self.nsBox.GetItemText(sn) |
|---|
| 451 | app = self.nsBox.GetPyData(sn) |
|---|
| 452 | if app is None: |
|---|
| 453 | errorMsg(self,'No application associated with this entry!') |
|---|
| 454 | return |
|---|
| 455 | |
|---|
| 456 | # Check to see if a waveform is already active |
|---|
| 457 | if self.active_wave != None: |
|---|
| 458 | self.refreshDisplay(True) |
|---|
| 459 | |
|---|
| 460 | # Set item bold and all others set to plain text |
|---|
| 461 | troot = self.nsBox.GetRootItem() |
|---|
| 462 | if self.nsBox.GetChildrenCount(troot) <= 0: |
|---|
| 463 | return |
|---|
| 464 | cid1,cookie1 = self.nsBox.GetFirstChild(troot) |
|---|
| 465 | self.nsBox.SetItemBold(cid1, False) |
|---|
| 466 | for x in range(self.nsBox.GetChildrenCount(troot,recursively=False)-1): |
|---|
| 467 | cid2,cookie2 = self.nsBox.GetNextChild(troot,cookie1) |
|---|
| 468 | self.nsBox.SetItemBold(cid2, False) |
|---|
| 469 | cid1 = cid2 |
|---|
| 470 | cookie1 = cookie2 |
|---|
| 471 | |
|---|
| 472 | self.nsBox.SetItemBold(sn, True) |
|---|
| 473 | self.nsBox.SelectItem(sn, False) |
|---|
| 474 | |
|---|
| 475 | # Check to see if this waveform has previously been displayed |
|---|
| 476 | # If so, then update the display and return |
|---|
| 477 | if self.waveform_displays.has_key(wave_name): |
|---|
| 478 | # Clear the canvas and get ready to display the waveform |
|---|
| 479 | #print "already imported this waveform .... displaying..." |
|---|
| 480 | tmpdisplay = self.waveform_displays[wave_name] |
|---|
| 481 | # self.refreshDisplay(True) |
|---|
| 482 | self.active_wave = tmpdisplay.waveform |
|---|
| 483 | self.canvas.updateDisplay(tmpdisplay) |
|---|
| 484 | return |
|---|
| 485 | |
|---|
| 486 | sadfile = app._get_profile() |
|---|
| 487 | sadfile = sadfile.replace('//','') |
|---|
| 488 | wav_name = sadfile.replace('.sad.xml','') |
|---|
| 489 | sadpath = '/sdr/' + sadfile |
|---|
| 490 | |
|---|
| 491 | self.active_wave = importWaveform.getWaveform(sadpath, self, self.Available_Ints) |
|---|
| 492 | self.active_wave.naming_context = str(wave_name) |
|---|
| 493 | |
|---|
| 494 | tmpdisplay = self.AddWaveformShape(self.active_wave) |
|---|
| 495 | self.waveform_displays[wave_name] = tmpdisplay |
|---|
| 496 | |
|---|
| 497 | self.canvas.updateDisplay(tmpdisplay) |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | def DisplayInstalledWaveforms(self): |
|---|
| 501 | self.nsBox.DeleteAllItems() |
|---|
| 502 | nsRoot = self.nsBox.AddRoot("ns_root") |
|---|
| 503 | |
|---|
| 504 | if self.domMgr == None or self.rootContext == None: |
|---|
| 505 | return |
|---|
| 506 | |
|---|
| 507 | dom_obj = self.rootContext.resolve([CosNaming.NameComponent("DomainName1","")]) |
|---|
| 508 | dom_context = dom_obj._narrow(CosNaming.NamingContext) |
|---|
| 509 | if dom_context is None: |
|---|
| 510 | return |
|---|
| 511 | |
|---|
| 512 | appSeq = self.domMgr._get_applications() |
|---|
| 513 | members = dom_context.list(1000) |
|---|
| 514 | for m in members[0]: |
|---|
| 515 | wav_name = str(m.binding_name[0].id) |
|---|
| 516 | wav_obj = dom_context.resolve([CosNaming.NameComponent(wav_name,"")]) |
|---|
| 517 | wav_context = wav_obj._narrow(CosNaming.NamingContext) |
|---|
| 518 | if wav_context is None: |
|---|
| 519 | continue |
|---|
| 520 | |
|---|
| 521 | contextApp = None |
|---|
| 522 | foundApp = False |
|---|
| 523 | for app in appSeq: |
|---|
| 524 | compNameCon = app._get_componentNamingContexts() |
|---|
| 525 | for compElementType in compNameCon: |
|---|
| 526 | if wav_name in compElementType.elementId: |
|---|
| 527 | waveformApp = app |
|---|
| 528 | foundApp = True |
|---|
| 529 | #print compElementType.componentId + " " + compElementType.elementId |
|---|
| 530 | break |
|---|
| 531 | |
|---|
| 532 | if not foundApp: |
|---|
| 533 | print "Could not find associated application for: " + wav_name |
|---|
| 534 | continue |
|---|
| 535 | |
|---|
| 536 | t1 = self.nsBox.AppendItem(nsRoot,wav_name) |
|---|
| 537 | self.nsBox.SetPyData(t1,waveformApp) |
|---|
| 538 | |
|---|
| 539 | # Set item bold if it is the active waveform |
|---|
| 540 | if self.active_wave is not None: |
|---|
| 541 | if self.active_wave.naming_context == wav_name: |
|---|
| 542 | self.nsBox.SetItemBold(t1, True) |
|---|
| 543 | |
|---|
| 544 | self.nsBox.SortChildren(nsRoot) |
|---|
| 545 | |
|---|
| 546 | # --------------------------------------------------------- |
|---|
| 547 | # Event handling and control for Launch Waveforms box |
|---|
| 548 | # -------------------------------------------------------- |
|---|
| 549 | def DisplayAvailableWaveforms(self): |
|---|
| 550 | self.installBox.DeleteAllItems() |
|---|
| 551 | self.availableWaveforms.clear() |
|---|
| 552 | installRoot = self.installBox.AddRoot("install_root") |
|---|
| 553 | |
|---|
| 554 | for dirpath, dirnames, filenames in os.walk(self.installpath): |
|---|
| 555 | sad_file = None |
|---|
| 556 | das_file = None |
|---|
| 557 | for fname in filenames: |
|---|
| 558 | if fname.find(".sad.xml") != -1: |
|---|
| 559 | # make sure that the '.sad.xml' comes at the end of the file name |
|---|
| 560 | if fname[-8:] == ".sad.xml": |
|---|
| 561 | sad_file = fname |
|---|
| 562 | full_sad_file = dirpath + "/" + fname |
|---|
| 563 | if fname.find("_DAS.xml") != -1: |
|---|
| 564 | # make sure that the '_DAS.xml' comes at the end of the file name |
|---|
| 565 | if fname[-8:] == "_DAS.xml": |
|---|
| 566 | das_file = fname |
|---|
| 567 | full_das_file = dirpath + "/" + fname |
|---|
| 568 | if (sad_file == None and das_file != None) or (sad_file != None and das_file == None): |
|---|
| 569 | #errorMsg(self, "Could not find both a SAD file and a DAS in this directory:\n " + dirpath) |
|---|
| 570 | continue |
|---|
| 571 | |
|---|
| 572 | if sad_file == None or das_file == None: |
|---|
| 573 | continue |
|---|
| 574 | |
|---|
| 575 | wavename = sad_file[:-8] |
|---|
| 576 | if self.availableWaveforms.has_key(wavename): |
|---|
| 577 | errorMsg(self, "Conflicting waveform name: " + wavename) |
|---|
| 578 | continue |
|---|
| 579 | |
|---|
| 580 | self.availableWaveforms[wavename] = (sad_file, full_sad_file, das_file, full_das_file) |
|---|
| 581 | |
|---|
| 582 | # Populate the display at the Domain level |
|---|
| 583 | for waveform in self.availableWaveforms.keys(): |
|---|
| 584 | t1 = self.installBox.AppendItem(installRoot,waveform) |
|---|
| 585 | self.installBox.SetPyData(t1,self.availableWaveforms[waveform]) |
|---|
| 586 | self.installBox.SetItemBold(t1,False) |
|---|
| 587 | |
|---|
| 588 | self.installBox.SortChildren(installRoot) |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | # ----------------------------------------------------------------- |
|---|
| 592 | # Event handling and control for Launch Components as Waveforms box |
|---|
| 593 | # ----------------------------------------------------------------- |
|---|
| 594 | def DisplayAvailableComponents(self): |
|---|
| 595 | self.componentsBox.DeleteAllItems() |
|---|
| 596 | self.availableComponents.clear() |
|---|
| 597 | installRoot = self.componentsBox.AddRoot("install_root") |
|---|
| 598 | |
|---|
| 599 | for dirpath, dirnames, filenames in os.walk(self.installpath): |
|---|
| 600 | spd_file = None |
|---|
| 601 | for fname in filenames: |
|---|
| 602 | # skip the Domain Manager spd file |
|---|
| 603 | if fname.find("DomainManager") != -1: |
|---|
| 604 | continue |
|---|
| 605 | # skip the Device Manager spd file |
|---|
| 606 | if fname.find("DeviceManager") != -1: |
|---|
| 607 | continue |
|---|
| 608 | if fname.find(".spd.xml") != -1: |
|---|
| 609 | # make sure that the '.spd.xml' comes at the end |
|---|
| 610 | # of the file name |
|---|
| 611 | if fname[-8:] == ".spd.xml": |
|---|
| 612 | spd_file = fname |
|---|
| 613 | full_spd_file = dirpath + "/" |
|---|
| 614 | |
|---|
| 615 | # TODO: make sure all the xml and binary files are present |
|---|
| 616 | |
|---|
| 617 | if spd_file == None: |
|---|
| 618 | continue |
|---|
| 619 | |
|---|
| 620 | compname = spd_file[:-8] |
|---|
| 621 | compNameAndDir = full_spd_file |
|---|
| 622 | |
|---|
| 623 | if self.availableComponents.has_key(compname): |
|---|
| 624 | errorMsg(self, "Conflicting component name: " + compname) |
|---|
| 625 | continue |
|---|
| 626 | |
|---|
| 627 | self.availableComponents[compname] = (compname, compNameAndDir) |
|---|
| 628 | |
|---|
| 629 | # Populate the display at the Domain level |
|---|
| 630 | for component in self.availableComponents.keys(): |
|---|
| 631 | t1 = self.componentsBox.AppendItem(installRoot,component) |
|---|
| 632 | self.componentsBox.SetPyData(t1,self.availableComponents[component]) |
|---|
| 633 | self.componentsBox.SetItemBold(t1,False) |
|---|
| 634 | |
|---|
| 635 | self.componentsBox.SortChildren(installRoot) |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | def OnInstallBoxRightUp(self, event): |
|---|
| 639 | self.installBox.PopupMenu(self.installBoxPopup) |
|---|
| 640 | event.Skip() |
|---|
| 641 | |
|---|
| 642 | def OnInstallBoxPopupInstallMenu(self, event): |
|---|
| 643 | self.InstallWaveformFromBox(False) |
|---|
| 644 | event.Skip() |
|---|
| 645 | |
|---|
| 646 | def OnInstallBoxPopupInstallStartMenu(self, event): |
|---|
| 647 | self.InstallWaveformFromBox(True) |
|---|
| 648 | event.Skip() |
|---|
| 649 | |
|---|
| 650 | def OnInstallBoxLeftDclick(self, event): |
|---|
| 651 | self.InstallWaveformFromBox(True) |
|---|
| 652 | event.Skip() |
|---|
| 653 | |
|---|
| 654 | def OnComponentsBoxRightUp(self, event): |
|---|
| 655 | self.componentsBox.PopupMenu(self.componentsBoxPopup) |
|---|
| 656 | event.Skip() |
|---|
| 657 | |
|---|
| 658 | def OnComponentsBoxPopupInstallMenu(self, event): |
|---|
| 659 | ''' Install but do not start compform ''' |
|---|
| 660 | self.InstallCompform(False) |
|---|
| 661 | event.Skip() |
|---|
| 662 | |
|---|
| 663 | def OnComponentsBoxPopupInstallStartMenu(self, event): |
|---|
| 664 | ''' Install and start the selected compform ''' |
|---|
| 665 | self.InstallCompform(True) |
|---|
| 666 | event.Skip() |
|---|
| 667 | |
|---|
| 668 | def OnComponentsBoxLeftDclick(self, event): |
|---|
| 669 | ''' Install and start the selected compform ''' |
|---|
| 670 | self.InstallCompform(True) |
|---|
| 671 | event.Skip() |
|---|
| 672 | |
|---|
| 673 | def InstallWaveformFromBox(self, start_flag): |
|---|
| 674 | selection = self.installBox.GetSelection() |
|---|
| 675 | name_SAD, absolute_name_SAD, name_DAS, absolute_name_DAS = self.installBox.GetPyData(selection) |
|---|
| 676 | |
|---|
| 677 | self.InstallWaveform(name_SAD, absolute_name_SAD, |
|---|
| 678 | name_DAS, absolute_name_DAS, start_flag) |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | def InstallWaveform(self,name_SAD, absolute_name_SAD, |
|---|
| 682 | name_DAS, absolute_name_DAS, start_flag = True): |
|---|
| 683 | ''' Installs waveform application as an (SCA) application. By default |
|---|
| 684 | the (SCA) application will be started ''' |
|---|
| 685 | |
|---|
| 686 | sadxml = importResource.stripDoctype(absolute_name_SAD) |
|---|
| 687 | doc_sad = xml.dom.minidom.parse(absolute_name_SAD) |
|---|
| 688 | app_name = doc_sad.getElementsByTagName("softwareassembly")[0].getAttribute("name") |
|---|
| 689 | _appFacProps = [] |
|---|
| 690 | devMgrSeq = self.domMgr._get_deviceManagers() |
|---|
| 691 | available_dev_seq = [] |
|---|
| 692 | for devmgr in range(len(devMgrSeq)): |
|---|
| 693 | devMgr = devMgrSeq[devmgr] |
|---|
| 694 | curr_devSeq = devMgr._get_registeredDevices() |
|---|
| 695 | for dev in range(len(curr_devSeq)): |
|---|
| 696 | curr_dev = curr_devSeq[dev] |
|---|
| 697 | available_dev_seq.append(curr_dev._get_identifier()) |
|---|
| 698 | #print curr_dev._get_identifier() |
|---|
| 699 | |
|---|
| 700 | clean_SAD = absolute_name_SAD.split("/sdr") |
|---|
| 701 | name_SAD = clean_SAD[1] |
|---|
| 702 | self.domMgr.installApplication(name_SAD) |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | # Parse the device assignment sequence, ensure |
|---|
| 706 | doc_das = xml.dom.minidom.parse(absolute_name_DAS) |
|---|
| 707 | deviceassignmenttypeNodeList = doc_das.getElementsByTagName("deviceassignmenttype") |
|---|
| 708 | |
|---|
| 709 | for deviceassignmenttypeNode in deviceassignmenttypeNodeList: |
|---|
| 710 | # look for assigndeviceid nodes |
|---|
| 711 | assigndeviceidNodeList = deviceassignmenttypeNode.getElementsByTagName("assigndeviceid") |
|---|
| 712 | if len(assigndeviceidNodeList) == 0: |
|---|
| 713 | ts = "Could not find \"assigndeviceid\" tag\nAborting install" |
|---|
| 714 | errorMsg(self, ts) |
|---|
| 715 | return |
|---|
| 716 | |
|---|
| 717 | # get assigndeviceid tag value (DCE:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) |
|---|
| 718 | assigndeviceid = assigndeviceidNodeList[0].firstChild.data |
|---|
| 719 | |
|---|
| 720 | # ensure assigndeviceid is in list of available devices |
|---|
| 721 | if assigndeviceid not in available_dev_seq: |
|---|
| 722 | ts = "Could not find the required device: " + str(assigndeviceid) |
|---|
| 723 | ts += "\nAborting install" |
|---|
| 724 | errorMsg(self, ts) |
|---|
| 725 | return |
|---|
| 726 | |
|---|
| 727 | _devSeq = self.BuildDevSeq(absolute_name_DAS) |
|---|
| 728 | _applicationFactories = self.domMgr._get_applicationFactories() |
|---|
| 729 | |
|---|
| 730 | # attempt to match up the waveform application name to |
|---|
| 731 | # a application factory of the same name |
|---|
| 732 | app_factory_num = -1 |
|---|
| 733 | for app_num in range(len(_applicationFactories)): |
|---|
| 734 | if _applicationFactories[app_num]._get_name()==app_name: |
|---|
| 735 | app_factory_num = app_num |
|---|
| 736 | break |
|---|
| 737 | |
|---|
| 738 | if app_factory_num == -1: |
|---|
| 739 | print "Application factory not found" |
|---|
| 740 | sys.exit(-1) |
|---|
| 741 | |
|---|
| 742 | # use the application factor I found above to create an instance |
|---|
| 743 | # of an application |
|---|
| 744 | try: |
|---|
| 745 | app = _applicationFactories[app_factory_num].create(_applicationFactories[app_factory_num]._get_name(),_appFacProps,_devSeq) |
|---|
| 746 | except: |
|---|
| 747 | print "Unable to create application - make sure that all appropriate nodes are installed" |
|---|
| 748 | return(None) |
|---|
| 749 | |
|---|
| 750 | if start_flag: |
|---|
| 751 | # start the application |
|---|
| 752 | app.start() |
|---|
| 753 | |
|---|
| 754 | naming_context_list = app._get_componentNamingContexts() |
|---|
| 755 | naming_context = naming_context_list[0].elementId.split("/") |
|---|
| 756 | application_name = app._get_name() |
|---|
| 757 | waveform_name = naming_context[1] |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | # self.refreshDisplay() |
|---|
| 761 | self.DisplayInstalledWaveforms() |
|---|
| 762 | |
|---|
| 763 | return app |
|---|
| 764 | |
|---|
| 765 | def InstallCompform(self, start_flag = False): |
|---|
| 766 | ''' This method will take the component selected from the GUI |
|---|
| 767 | and create the necessary files to define a Waveform Application |
|---|
| 768 | consisting of a single instance of this component. The files will |
|---|
| 769 | then be passed to the InstallWaveform method which will create |
|---|
| 770 | an (SCA) application from the Waveform Application. ''' |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | print "WARNING: if your node's GPP UUID is not DCE:5ba336ee-aaaa-aaaa-aaaa-00123f573a7f this will not work...\n" |
|---|
| 774 | # get component name from the list |
|---|
| 775 | selection = self.componentsBox.GetSelection() |
|---|
| 776 | compName, compNameAndDir = self.componentsBox.GetPyData(selection) |
|---|
| 777 | |
|---|
| 778 | self.compform_counter = self.compform_counter + 1 |
|---|
| 779 | |
|---|
| 780 | tmp_dir_name = "/sdr/_tmp_alf_waveforms/" # this is where I put my temporary |
|---|
| 781 | # xml files |
|---|
| 782 | tmp_wave_name = "_" + compName + str(self.compform_counter) |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | #make the directory to put the XML |
|---|
| 786 | if os.path.exists(tmp_dir_name) == False: |
|---|
| 787 | try: |
|---|
| 788 | os.mkdir(tmp_dir_name) |
|---|
| 789 | except: |
|---|
| 790 | errorMsg(self,"Cannot create temporary directory in the waveform directory.\n" + |
|---|
| 791 | "You may need to change the temporary directory to one that you have write permissions to") |
|---|
| 792 | |
|---|
| 793 | #Ticket#272: loop into /sdr/_tmp_alf_waveforms/ directory and see if tmp waveforms exists already |
|---|
| 794 | #with the same name. If found, increment the counter and form a new name for the temp |
|---|
| 795 | #waveform. Repeat this until you find a new name. |
|---|
| 796 | while (os.path.exists(tmp_dir_name + tmp_wave_name) == True ): |
|---|
| 797 | print tmp_wave_name + " exists already...Regenerating new name " |
|---|
| 798 | self.compform_counter = self.compform_counter + 1 |
|---|
| 799 | tmp_wave_name = "_" + compName + str(self.compform_counter) |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | if os.path.exists(tmp_dir_name + tmp_wave_name) == False: |
|---|
| 803 | try: |
|---|
| 804 | os.mkdir(tmp_dir_name + tmp_wave_name) |
|---|
| 805 | except: |
|---|
| 806 | errorMsg(self,"Cannot create temporary directory in the waveform directory.\n" |
|---|
| 807 | "You may need to change the temporary directory to one that you have write permissions to") |
|---|
| 808 | return |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | # assumes that alf is in /sdr/tools |
|---|
| 812 | my_compform = compform.compform(compName, compNameAndDir, |
|---|
| 813 | tmp_dir_name, tmp_wave_name) |
|---|
| 814 | my_compform.create() |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | print "WARNING: tmp files generated in " + tmp_dir_name |
|---|
| 818 | |
|---|
| 819 | tmp_dir_name = tmp_dir_name + tmp_wave_name + "/" |
|---|
| 820 | self.InstallWaveform(tmp_wave_name + ".sad.xml", |
|---|
| 821 | tmp_dir_name + tmp_wave_name + ".sad.xml", |
|---|
| 822 | tmp_wave_name + "_DAS.xml", |
|---|
| 823 | tmp_dir_name + tmp_wave_name + "_DAS.xml", |
|---|
| 824 | start_flag) |
|---|
| 825 | |
|---|
| 826 | def StartApplication(self): |
|---|
| 827 | selection = self.nsBox.GetSelection() |
|---|
| 828 | app_ref = self.nsBox.GetPyData(selection) |
|---|
| 829 | app_ref.start() |
|---|
| 830 | self.DisplayInstalledWaveforms() |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | def StopApplication(self): |
|---|
| 834 | selection = self.nsBox.GetSelection() |
|---|
| 835 | app_ref = self.nsBox.GetPyData(selection) |
|---|
| 836 | app_ref.stop() |
|---|
| 837 | self.DisplayInstalledWaveforms() |
|---|
| 838 | |
|---|
| 839 | def UninstallWaveform(self): |
|---|
| 840 | selection = self.nsBox.GetSelection() |
|---|
| 841 | waveform_name = self.nsBox.GetItemText(selection) |
|---|
| 842 | if self.active_wave is not None: |
|---|
| 843 | if self.active_wave.naming_context == waveform_name: |
|---|
| 844 | self.refreshDisplay(True) |
|---|
| 845 | if self.waveform_displays.has_key(waveform_name): |
|---|
| 846 | # close any tool frames associated with waveform display |
|---|
| 847 | tmp_display = self.waveform_displays[waveform_name] |
|---|
| 848 | while len(tmp_display.tool_frames) > 0: |
|---|
| 849 | tf = tmp_display.tool_frames.pop() |
|---|
| 850 | tf.Close() |
|---|
| 851 | self.waveform_displays.pop(waveform_name) |
|---|
| 852 | app_ref = self.nsBox.GetPyData(selection) |
|---|
| 853 | # self.domMgr.uninstallApplication(app_ref._get_identifier()) # not sure if we need this or not |
|---|
| 854 | app_ref.releaseObject() |
|---|
| 855 | # self.refreshDisplay() |
|---|
| 856 | self.DisplayInstalledWaveforms() |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | def BuildDevSeq(self, dasXML): |
|---|
| 860 | doc_das = xml.dom.minidom.parse(dasXML) |
|---|
| 861 | |
|---|
| 862 | # create node list of "deviceassignmenttype" |
|---|
| 863 | deviceassignmenttypeNodeList = doc_das.getElementsByTagName("deviceassignmenttype") |
|---|
| 864 | |
|---|
| 865 | ds = [] |
|---|
| 866 | for n in deviceassignmenttypeNodeList: |
|---|
| 867 | componentid = n.getElementsByTagName("componentid")[0].firstChild.data |
|---|
| 868 | assigndeviceid = n.getElementsByTagName("assigndeviceid")[0].firstChild.data |
|---|
| 869 | ds.append(CF.DeviceAssignmentType(str(componentid),str(assigndeviceid))) |
|---|
| 870 | |
|---|
| 871 | return ds |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | #---------------------------------------------------------------------------- |
|---|
| 875 | # Waveform level controls and functions |
|---|
| 876 | #---------------------------------------------------------------------------- |
|---|
| 877 | def refreshDisplay(self, init = False): |
|---|
| 878 | # self.DisplayInstalledWaveforms() |
|---|
| 879 | |
|---|
| 880 | dc = wx.ClientDC(self.canvas) |
|---|
| 881 | self.canvas.PrepareDC(dc) |
|---|
| 882 | |
|---|
| 883 | if init: |
|---|
| 884 | if self.active_wave != None and self.timing_view_state: |
|---|
| 885 | for comp in self.active_wave.components: |
|---|
| 886 | for gauge in comp.shape.gauge_shapes: |
|---|
| 887 | gauge.gauge.Show(False) |
|---|
| 888 | |
|---|
| 889 | self.active_wave = None |
|---|
| 890 | self.timing_display = None |
|---|
| 891 | |
|---|
| 892 | self.canvas.diagram.RemoveAllShapes() |
|---|
| 893 | self.canvas.shapes = [] |
|---|
| 894 | |
|---|
| 895 | tb = self.GetToolBar() |
|---|
| 896 | tb.ToggleTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, False) |
|---|
| 897 | self.timing_view_state = False |
|---|
| 898 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Enable Timing Graphics") |
|---|
| 899 | tb.ToggleTool(wxID_TOOLBAR_TIMING_TOOL, False) |
|---|
| 900 | tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Enable Timing") |
|---|
| 901 | #self.canvas.diagram = ogl.Diagram() |
|---|
| 902 | #self.canvas.SetDiagram(self.canvas.diagram) |
|---|
| 903 | #self.canvas.diagram.SetCanvas(self.canvas) |
|---|
| 904 | |
|---|
| 905 | self.canvas.Refresh() |
|---|
| 906 | |
|---|
| 907 | def AddWaveformShape(self, waveform): |
|---|
| 908 | tmpdisplay = ALFshapes.WaveformShapes(waveform, self.canvas) |
|---|
| 909 | for comp in waveform.components: |
|---|
| 910 | tmpdisplay.AddComponentShape(comp) |
|---|
| 911 | tmpdisplay.ConnectComponents() |
|---|
| 912 | |
|---|
| 913 | return tmpdisplay |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | def updateWaveformData(self, data): |
|---|
| 917 | for d in data: |
|---|
| 918 | self.waveformData[d[0]] = d[1] |
|---|
| 919 | |
|---|
| 920 | self.last_waveform_data_update = self.waveformData.copy() |
|---|
| 921 | |
|---|
| 922 | for frame in self.tool_frames: |
|---|
| 923 | if hasattr(frame, 'updateWaveformData'): |
|---|
| 924 | frame.updateWaveformData(self.waveformData) |
|---|
| 925 | |
|---|
| 926 | def removeToolFrame(self, frame): |
|---|
| 927 | if frame not in self.tool_frames: |
|---|
| 928 | return |
|---|
| 929 | else: |
|---|
| 930 | index = self.tool_frames.index(frame) |
|---|
| 931 | del self.tool_frames[index] |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | #---------------------------------------------------------------------- |
|---|
| 936 | class MainWindow(ogl.ShapeCanvas): |
|---|
| 937 | def __init__(self, parent, frame): |
|---|
| 938 | ogl.ShapeCanvas.__init__(self, parent) |
|---|
| 939 | |
|---|
| 940 | maxWidth = 2100 |
|---|
| 941 | maxHeight = 1000 |
|---|
| 942 | self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20) |
|---|
| 943 | |
|---|
| 944 | self.frame = frame |
|---|
| 945 | self.SetBackgroundColour("LIGHT BLUE") #wxWHITE) |
|---|
| 946 | self.diagram = ogl.Diagram() |
|---|
| 947 | self.SetDiagram(self.diagram) |
|---|
| 948 | self.diagram.SetCanvas(self) |
|---|
| 949 | self.shapes = [] |
|---|
| 950 | |
|---|
| 951 | dsBrush = wx.Brush("WHEAT", wx.SOLID) |
|---|
| 952 | |
|---|
| 953 | def updateDisplay(self, waveformdisplay): |
|---|
| 954 | dc = wx.ClientDC(self) |
|---|
| 955 | self.PrepareDC(dc) |
|---|
| 956 | for compshape in waveformdisplay.shapes: |
|---|
| 957 | self.AddShape(compshape) |
|---|
| 958 | compshape.Show(True) |
|---|
| 959 | |
|---|
| 960 | self. diagram.Redraw(dc) |
|---|
| 961 | self.Refresh() |
|---|
| 962 | |
|---|
| 963 | def OnDestroy(self, evt): |
|---|
| 964 | # Do some cleanup |
|---|
| 965 | for shape in self.diagram.GetShapeList(): |
|---|
| 966 | if shape.GetParent() == None: |
|---|
| 967 | shape.SetCanvas(None) |
|---|
| 968 | shape.Destroy() |
|---|
| 969 | self.diagram.Destroy() |
|---|
| 970 | |
|---|
| 971 | |
|---|
| 972 | #---------------------------------------------------------------------- |
|---|
| 973 | |
|---|
| 974 | def errorMsg(self,msg): |
|---|
| 975 | dlg = wx.MessageDialog(self,msg,'Error', wx.OK | wx.ICON_INFORMATION) |
|---|
| 976 | try: |
|---|
| 977 | dlg.ShowModal() |
|---|
| 978 | finally: |
|---|
| 979 | dlg.Destroy() |
|---|
| 980 | return |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | def main(): |
|---|
| 984 | app = alfApp(0) |
|---|
| 985 | app.MainLoop() |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | # # If not profiling: |
|---|
| 989 | if __name__ == '__main__': |
|---|
| 990 | main() |
|---|
| 991 | |
|---|
| 992 | |
|---|
| 993 | ''' |
|---|
| 994 | # A script created by Drew Cormier for profiling |
|---|
| 995 | # code developed for his thesis |
|---|
| 996 | if __name__ == "__main__": |
|---|
| 997 | |
|---|
| 998 | import profile |
|---|
| 999 | import pstats |
|---|
| 1000 | |
|---|
| 1001 | # bias the profile to remove profiling overhead |
|---|
| 1002 | # note that the number being passed to |
|---|
| 1003 | # bias varies based on what system I am using |
|---|
| 1004 | # |
|---|
| 1005 | # Aquire this number for my linux machine using |
|---|
| 1006 | # >>> p.calibrate(10000000) |
|---|
| 1007 | profile.bias = 1.6989519401052302e-05 |
|---|
| 1008 | |
|---|
| 1009 | profile.run("main()", "alf_profile_1") |
|---|
| 1010 | |
|---|
| 1011 | my_stats = pstats.Stats("alf_profile_1") |
|---|
| 1012 | |
|---|
| 1013 | my_stats.sort_stats('cumulative') |
|---|
| 1014 | my_stats.print_stats(10) |
|---|
| 1015 | |
|---|
| 1016 | my_stats.sort_stats('time') |
|---|
| 1017 | my_stats.print_stats(10) |
|---|
| 1018 | ''' |
|---|
| 1019 | |
|---|
| 1020 | |
|---|
| 1021 | |
|---|
| 1022 | |
|---|
| 1023 | |
|---|
| 1024 | |
|---|
| 1025 | |
|---|