root/ossiedev/branches/deepanns/tools/wavedash/src/WavedashController.py @ 9570

Revision 9570, 8.9 KB (checked in by deepanns, 4 years ago)

added compform support

Line 
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 Waveform Application Visualization Environment
6##
7## WaveDash 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## WaveDash 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 WaveDash; if not, write to the Free Software
19## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21import os
22import wx
23import sys
24import xml.dom.minidom as minidom
25from WavedashModel import WavedashModel
26import WaveformModel
27import PropertyWidgets
28from PropertyWidgets import WidgetContainer
29from WavedashView import WavedashView
30import WavedashUtils as utils
31
32SDR_DIR = '/sdr/'
33SDR_WAVEFORMS_DIR = SDR_DIR + 'waveforms/'
34COMP_WAVEFORMS_DIR = SDR_DIR + '_tmp_alf_waveforms'
35SAD_XML = '.sad.xml'
36DAS_XML = '_DAS.xml'
37PROPERTY_WIDGET_CONFIG_FILE = '/resources/widgetconf.xml'
38
39class Controller(wx.App):
40    def OnInit(self):
41        self.model = WavedashModel(self)
42        self.views = []
43        self.widgetContainer = None
44        self.CORBAutils = utils.WaveAppCORBA()
45        return True
46       
47    def buildModel(self):
48        """ This functions walks through the system directories in /sdr/, construct a
49        list of .sad.xml files and pass them to the model to build the waveforms.
50        Waveforms in turn build their components and each component in turn build their
51        properties """     
52       
53        #Find the list of SAD and DAS files for all waveforms in standard SDR root directory (/sdr/)
54        (sdrWformsSADList, sdrWformsDASList) = (self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML), self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML))
55        #Find the list of SAD and DAS files for component running as waveforms. Those waveforms are installed in /sdr/_tmp_alf_waveforms
56        (tmpWformsSADList, tmpWformsDASList) = (self.getFileList(COMP_WAVEFORMS_DIR, SAD_XML, quiet=True), self.getFileList(COMP_WAVEFORMS_DIR, DAS_XML, quiet=True))
57       
58        if (sdrWformsSADList is None or sdrWformsDASList is None):
59                print "buildModel(): Error in reading SAD/DAS files for SDR waveforms in " + SDR_DIR
60                sys.exit(-1)
61       
62        if (tmpWformsSADList is None or tmpWformsDASList is None):
63            #We need not exit if no temporary waveforms are not found in /sdr/_tmp_alf_waveforms
64            tmpWformsSADList = []
65            tmpWformsDASList = []
66           
67       
68        sadFileList = sdrWformsSADList + tmpWformsSADList
69        dasFileList = sdrWformsDASList + tmpWformsDASList
70             
71        self.model.buildWaveforms(sadFileList, dasFileList)
72       
73        #update the model with currently installed waveforms in framework
74        installedWformDict = self.CORBAutils.getApplications()
75        for wform in installedWformDict.keys():
76            wformName = wform[wform.find("::") + 2 :]
77            for instance in installedWformDict[wform]:
78                instanceName = instance[instance.find("::") + 2 :]
79                self.model.addInstanceWaveform(wformName, instanceName)
80   
81    def refresh(self):
82        #First, update the SDR waveforms installed
83        #model.buildWaveforms(..) will build a new object for every waveform if it is not there already
84        #in its list
85        #Find the list of SAD and DAS files for all waveforms in standard SDR root directory (/sdr/)
86        (sdrWformsSADList, sdrWformsDASList) = (self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML), self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML))
87        #Find the list of SAD and DAS files for component running as waveforms. Those waveforms are installed in /sdr/_tmp_alf_waveforms
88        (tmpWformsSADList, tmpWformsDASList) = (self.getFileList(COMP_WAVEFORMS_DIR, SAD_XML, quiet=True), self.getFileList(COMP_WAVEFORMS_DIR, DAS_XML, quiet = True))
89       
90        if (sdrWformsSADList is None or sdrWformsDASList is None):
91                print "buildModel(): Error in reading SAD/DAS files for SDR waveforms in " + SDR_DIR
92                sys.exit(-1)
93       
94        if (tmpWformsSADList is None or tmpWformsDASList is None):
95            #We need not exit if no temporary waveforms are not found in /sdr/_tmp_alf_waveforms
96            tmpWformsSADList = []
97            tmpWformsDASList = []
98       
99        sadFileList = sdrWformsSADList + tmpWformsSADList
100        dasFileList = sdrWformsDASList + tmpWformsDASList
101       
102        #sadFileList = self.getFileList(SDR_WAVEFORMS_DIR, SAD_XML) #list holding sad files of all the system waveforms           
103        #dasFileList = self.getFileList(SDR_WAVEFORMS_DIR, DAS_XML)
104        self.model.buildWaveforms(sadFileList, dasFileList)
105       
106        #get the new list of installed applications
107        installedWformDict = self.CORBAutils.getApplications()
108        self.model.refreshModel(installedWformDict)         
109       
110           
111    def createWidgetContainer(self):
112        root = __file__
113        if os.path.islink (root):
114            root = os.path.realpath (root)
115        root = os.path.dirname (os.path.abspath (root))
116
117        widgetsDom = minidom.parse(root + PROPERTY_WIDGET_CONFIG_FILE)#self.getDOM(PROPERTY_WIDGET_CONFIG_FILE)
118        self.widgetContainer = WidgetContainer(widgetsDom)
119       
120    def getFileList(self, dir, filetype, quiet=False):
121        fileList = []
122       
123        if not os.path.isdir(dir):
124                if not quiet:
125                    utils.showMessage("Directory " + dir + " does not exist.", utils.NON_FATAL)
126                return None
127                   
128        for dirpath, dirnames, filenames in os.walk(dir):
129            fileFound = False
130           
131            for fname in filenames:               
132                if fname.find('.swp') != -1: #skip the .swp files if any
133                    continue
134                if fname.find(filetype) != -1:
135                    # make sure that the '.sad.xml' comes at the end of the file name
136                    fileFound = True       
137                    if fname[-8:] == filetype:
138                        abs_file_path = dirpath + "/" + fname
139               
140                    #do not add duplicate entries to the list
141                    if (abs_file_path not in fileList):
142                        fileList.append(abs_file_path)
143               
144        if not fileFound:
145            if not quiet: #Ignore the error for _tmp_alf_waveforms.
146                utils.showMessage("Could not find " + filetype + " files in this directory:\n " + dirpath, utils.FATAL)
147            return None
148                               
149        return fileList
150   
151    def getDOM(self, xmlfile):
152        """ This method gets a file name as string and returns a DOM object built
153        using minidom
154        """
155        if xmlfile.find(SDR_DIR) == -1:
156            xmlfile = SDR_DIR + xmlfile
157           
158        dom = minidom.parse(xmlfile)
159        return dom
160   
161    def installWaveform(self, wformName, start):
162        wform = self.model.getWaveform(wformName, WaveformModel.SYSTEM_WAVEFORM)
163        if wform is None:
164            utils.showMessage ("Unable to install " + wformName, utils.FATAL)
165        else:
166            instance = self.CORBAutils.installWaveform(wform.sadFile, wform.dasFile, start)
167            if instance is not None:
168                instanceName = instance[instance.find("::") + 2 :]
169                self.model.addInstanceWaveform(wformName, instanceName, start)
170
171            else:
172                utils.showMessage("Unable to find applications", utils.NON_FATAL)
173   
174    def uninstallWaveform(self, wformName):
175        status = self.CORBAutils.uninstallWaveform(wformName)
176        return status
177   
178    def startWaveform(self, wformName):
179        status = self.CORBAutils.startWaveform(wformName)
180        return status
181   
182    def stopWaveform(self, wformName):
183        status = self.CORBAutils.stopWaveform(wformName)
184        return status
185   
186    def getDefaultWidget(self, property):
187        return self.widgetContainer.getDefaultWidget(property)
188   
189    def getWidgetByType(self, type):
190        return self.widgetContainer.getWidgetByType(type)
191   
192    def getOptionalWidgets(self, propertyType):
193        return self.widgetContainer.getOptionalWidgets(propertyType)
194   
195    def getWidgetContainer(self):
196        return self.widgetContainer
197   
198    def getUtilRef(self):
199        return self.CORBAutils
200
201def main():
202    ctrlr = Controller()
203    ctrlr.createWidgetContainer()
204       
205    frame = WavedashView(ctrlr, ctrlr.model)
206    frame.Show()
207    ctrlr.CORBAutils.init_CORBA()
208    ctrlr.buildModel()
209    ctrlr.MainLoop()
210       
211if __name__ == '__main__':
212    main()   
213   
Note: See TracBrowser for help on using the browser.