root/ossiedev/branches/jsnyder/ComponentProject/PythonSrc/MainFrameGlue.py @ 7246

Revision 7246, 7.7 KB (checked in by stedwar2, 5 years ago)

Added support for setting the installPath.

Line 
1import sys, os, copy
2import wavedev.importResource
3import wavedev.importNode
4import wavedev.WaveformClass
5import wavedev.PlatformClass
6import wavedev.ComponentClass
7import threading
8from edu.vt.ossie.jyinterface.interfaces import MainFrame
9
10class MainFrameTreeNode:
11    def __init__(self, name, contents):
12        self.name = name
13        self.contents = contents
14
15
16class RunInNewThread(threading.Thread):
17    def __init__(self, inCommand):
18        self.command = inCommand
19        threading.Thread.__init__(self)
20
21
22    def run(self):
23        os.system(self.command)
24
25
26
27class MainFrameGlue(MainFrame):
28    def __init__(self):
29        self.active_waveform = wavedev.WaveformClass.Waveform()
30        self.active_platform = wavedev.PlatformClass.Platform()
31        self.installPath = "/sdr/"
32
33
34    def loadResources(self):
35        self.Available_Components = []
36        self.Available_Devices = []
37        self.Available_Nodes = []
38        resList = []
39
40        # List possible resource directories (components and device)
41        baseComponentPath = self.installPath + 'xml/'
42        if os.path.isdir(baseComponentPath):
43            for r in os.listdir(baseComponentPath):
44                if r != 'dtd':  # ignore dtd directory
45                    resList.append( (baseComponentPath,r) )
46        else:
47            errorMsg(self,"No component resources could be found in: " + self.installPath)
48            return
49
50        # find the .scd.xml files for each resource
51       
52        for r in resList:
53            tmpResName = r[1]
54            tmpResPath = r[0] + r[1]
55            tmpComp = wavedev.importResource.getResource(tmpResPath,tmpResName,self)
56               
57            if tmpComp == None:
58                continue
59            if tmpComp.type == 'resource':
60                self.Available_Components.append(tmpComp)
61             
62            elif tmpComp.type == 'executabledevice':
63                self.Available_Devices.append(tmpComp)
64             
65            elif tmpComp.type == 'loadabledevice':
66                self.Available_Devices.append(tmpComp)
67               
68            elif tmpComp.type == 'device':
69                self.Available_Devices.append(tmpComp)
70               
71       
72        nodeList = []
73        if os.path.isdir(self.installPath + 'nodes'):
74            nodeList = os.listdir(self.installPath + 'nodes')
75            print nodeList
76        else:
77            errorMsg(self, "No nodes could be found in: " + self.installPath)
78       
79        # find the scd files for each node
80        for node_name in nodeList:
81
82            # check for existence of DomainManager XML files
83            nodes_root_path = self.installPath + os.path.sep + 'nodes' + os.path.sep + node_name + os.path.sep
84            if not os.path.exists(nodes_root_path + 'DeviceManager.dcd.xml'):
85                errorMsg(self, "Could not find DeviceManager.dcd.xml in: " + nodes_root_path)
86                continue
87            elif not os.path.exists(nodes_root_path + 'DeviceManager.prf.xml'):
88                errorMsg(self, "Could not find DeviceManager.prf.xml in: " + nodes_root_path)
89                continue
90            elif not os.path.exists(nodes_root_path + 'DeviceManager.scd.xml'):
91                errorMsg(self, "Could not find DeviceManager.scd.xml in: " + nodes_root_path)
92                continue
93            elif not os.path.exists(nodes_root_path + 'DeviceManager.spd.xml'):
94                errorMsg(self, "Could not find DeviceManager.spd.xml in: " + nodes_root_path)
95                continue
96
97            nodeName = node_name
98            nodePath = self.installPath + 'nodes/' + nodeName + '/'
99           
100            print "calling getNode(", nodePath, ",", nodeName, ")"
101            tmpNode = wavedev.importNode.getNode(nodePath,nodeName,self)
102           
103            if tmpNode == None:
104                print "WARNING: possibly an error reading node " + nodePath + "/" + nodeName
105                continue
106            self.Available_Nodes.append(tmpNode)
107        return [MainFrameTreeNode("Components", self.Available_Components),
108                MainFrameTreeNode("Devices", self.Available_Devices),
109                MainFrameTreeNode("Nodes", self.Available_Nodes)]
110
111
112    def getActiveWaveform(self):
113        return self.active_waveform
114
115
116    def getActivePlatform(self):
117        return self.active_platform
118
119
120    def getOssieInstallPath(self):
121        return self.installPath
122
123
124    def setOssieInstallPath(self, newInstallPath):
125        self.installPath = newInstallPath
126
127
128    def generateTestWaveform(self):
129        self.active_wave = wavedev.WaveformClass.Waveform()
130        int1 = wavedev.ComponentClass.Interface('complexShort')
131        op1 = wavedev.ComponentClass.Operation('pushPacket','void')
132        param1 = wavedev.ComponentClass.Param('I','PortTypes::ShortSequence','in')
133        param2 = wavedev.ComponentClass.Param('Q','PortTypes::ShortSequence','in')
134        op1.params.extend([param1,param2])
135        int1.operations.append(op1)
136
137        t2 = wavedev.ComponentClass.Component("Transmitter",AC=True)
138        p1 = wavedev.ComponentClass.Port('inPortTx1',copy.deepcopy(int1),'Provides')
139        p2 = wavedev.ComponentClass.Port('outPortTx1',copy.deepcopy(int1),'Uses')
140        t2.ports.append(p1); t2.ports.append(p2)
141        self.active_wave.components.append(t2)
142       
143        t3 = wavedev.ComponentClass.Component("Channel")
144        p1 = wavedev.ComponentClass.Port('inPortCh1',copy.deepcopy(int1),'Provides')
145        p2 = wavedev.ComponentClass.Port('inPortCh2',copy.deepcopy(int1),'Provides')
146        p3 = wavedev.ComponentClass.Port('inPortCh3',copy.deepcopy(int1),'Provides')
147        p4 = wavedev.ComponentClass.Port('outPortCh1',copy.deepcopy(int1),'Uses')
148        p5 = wavedev.ComponentClass.Port('outPortCh2',copy.deepcopy(int1),'Uses')
149        p6 = wavedev.ComponentClass.Port('outPortCh3',copy.deepcopy(int1),'Uses')
150        t3.ports.extend([p1,p2,p3,p4,p5,p6])
151        self.active_wave.components.append(t3)       
152       
153        t4 = wavedev.ComponentClass.Component("Receiver")
154        p1 = wavedev.ComponentClass.Port('inPortRx1',copy.deepcopy(int1),'Provides')
155        p2 = wavedev.ComponentClass.Port('outPortRx1',copy.deepcopy(int1),'Uses')
156        t4.ports.append(p1); t4.ports.append(p2)
157        self.active_wave.components.append(t4)       
158       
159        temp_dev = wavedev.ComponentClass.Component("GPP")
160        self.active_wave.devices.append(temp_dev)
161        return [MainFrameTreeNode("Sample Waveform", self.active_wave)]
162       
163    def displayDoxygen(self, referenceMaterials):
164        defaultHtml = 'index.html'
165        defaultPdf = 'refman.pdf'
166        docList = None
167       
168        docsPath = self.installPath + 'docs/' + referenceMaterials.name
169        print docsPath
170        RunInNewThread('evince ' + "/home/Ossie/Desktop/OSSIE_0.6.2_User_Guide.pdf").start()
171        if os.path.isdir(docsPath):
172            docList = os.listdir(docsPath)
173            if os.path.isfile(docsPath + '/' + defaultHtml):
174                webbrowser.open_new('file://' + docsPath + '/' + defaultHtml)
175            elif os.path.isfile(docsPath + '/' + defaultPdf):
176                #find more portable way to view pdf?
177                try:
178                    RunInNewThread('evince ' + docsPath + '/' + defaultPdf + ' &')
179                finally:
180                    errorMsg(self,'evince pdf viewer threw exception or not found')
181                #webbrowser.open('file://' + docsPath + '/' + defaultPdf, 1)
182            else:
183                errorMsg(self,'Neither index.html nor refman.pdf found in ' + docsPath + ': directory listing: ' + str(docList))
184        else:
185            errorMsg(self,'No directory for ' + referenceMaterials.name + ' could be found in: ' + self.installPath + 'docs')           
186            return
187
188
189    def errorMsg(self, message):
190        sys.stderr.write(message)
191       
Note: See TracBrowser for help on using the browser.