2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 21 from visualstates.generators.pythonrosgenerator
import PythonRosGenerator
26 SUBSCRIBE =
'Subscribe' 42 topicNames = map(
lambda x: x[
'name'], self.
topics)
43 if topicName
in topicNames:
51 if topic[
'opType'] == RosConfig.PUBLISH:
52 newTopic[
'methodname'] = topic[
'methodname']
53 elif topic[
'opType'] == RosConfig.SUBSCRIBE:
54 newTopic[
'variablename'] = topic[
'variablename']
55 newTopic[
'name'] = topic[
'name']
56 newTopic[
'type'] = topic[
'type']
57 newTopic[
'opType'] = topic[
'opType']
58 self.topics.append(newTopic)
62 if topic
not in self.
topics:
67 return max(map(
lambda x: x[
'id'], self.
topics)) + 1
72 """Dependencies coming as strings""" 74 dependStrs = dependencies.split(
'\n')
75 for dStr
in dependStrs:
76 if len(dStr.strip()) > 0:
77 self.buildDependencies.append(dStr.strip())
83 """Dependencies coming as List""" 84 for dep
in dependencies:
86 self.buildDependencies.append(dep)
92 """Dependencies coming as List""" 93 for dep
in dependencies:
95 self.runDependencies.append(dep)
98 cfgElement = doc.createElement(
'config')
100 bDependencies = doc.createElement(
'buildDependencies')
102 dependElement = doc.createElement(
'dependency')
103 dependElement.appendChild(doc.createTextNode(bDepend))
104 bDependencies.appendChild(dependElement)
105 cfgElement.appendChild(bDependencies)
107 rDependencies = doc.createElement(
'runDependencies')
109 dElement = doc.createElement(
'dependency')
110 dElement.appendChild(doc.createTextNode(rDepend))
111 rDependencies.appendChild(dElement)
112 cfgElement.appendChild(rDependencies)
114 tElements = doc.createElement(
'topics')
116 tElement = doc.createElement(
'topic')
117 tElement.setAttribute(
'id', str(t[
'id']))
118 if t[
'opType'] == RosConfig.PUBLISH:
119 methodElement = doc.createElement(
'methodname')
120 methodElement.appendChild(doc.createTextNode(t[
'methodname']))
121 tElement.appendChild(methodElement)
122 elif t[
'opType'] == RosConfig.SUBSCRIBE:
123 varElement = doc.createElement(
'variablename')
124 varElement.appendChild(doc.createTextNode(t[
'variablename']))
125 tElement.appendChild(varElement)
126 nameElement = doc.createElement(
'name')
127 nameElement.appendChild(doc.createTextNode(t[
'name']))
128 tElement.appendChild(nameElement)
129 typeElement = doc.createElement(
'type')
130 typeElement.appendChild(doc.createTextNode(t[
'type']))
131 tElement.appendChild(typeElement)
132 opElement = doc.createElement(
'opType')
133 opElement.appendChild(doc.createTextNode(t[
'opType']))
134 tElement.appendChild(opElement)
136 tElements.appendChild(tElement)
138 cfgElement.appendChild(tElements)
144 bDependencies = node.getElementsByTagName(
'buildDependencies')[0]
145 for bDependency
in bDependencies.getElementsByTagName(
'dependency'):
146 if len(bDependency.childNodes) > 0:
147 self.buildDependencies.append(bDependency.childNodes[0].nodeValue)
151 rDependencies = node.getElementsByTagName(
'runDependencies')[0]
152 for rDependency
in rDependencies.getElementsByTagName(
'dependency'):
153 if len(rDependency.childNodes) > 0:
154 self.runDependencies.append(rDependency.childNodes[0].nodeValue)
158 tElements = node.getElementsByTagName(
'topics')[0]
159 for t
in tElements.getElementsByTagName(
'topic'):
161 topic[
'id'] = int(t.getAttribute(
'id'))
162 topic[
'name'] = t.getElementsByTagName(
'name')[0].childNodes[0].nodeValue
163 topic[
'type'] = t.getElementsByTagName(
'type')[0].childNodes[0].nodeValue
164 topic[
'opType'] = t.getElementsByTagName(
'opType')[0].childNodes[0].nodeValue
165 if topic[
'opType'] == RosConfig.PUBLISH:
166 methodnames = t.getElementsByTagName(
'methodname')
167 if len(methodnames) > 0:
168 topic[
'methodname'] = methodnames[0].childNodes[0].nodeValue
170 topic[
'methodname'] = self.
getVarName(topic[
'name'])
171 elif topic[
'opType'] == RosConfig.SUBSCRIBE:
172 varnames = t.getElementsByTagName(
'variablename')
173 if len(varnames) > 0:
174 topic[
'variablename'] = varnames[0].childNodes[0].nodeValue
176 topic[
'variablename'] = self.
getVarName(topic[
'name'])
178 self.topics.append(topic)
181 varName = varName.replace(
'/',
'_')
182 if varName[0] ==
'_':
183 varName = varName[1:]
def updateTopics(self, topics)
def updateRunDependencies(self, dependencies)
def setBuildDependencies(self, dependencies)
def getRunDependencies(self)
def updateBuildDependencies(self, dependencies)
def getBuildDependencies(self)
def addTopic(self, id, topic)
def updateROSConfig(self, newConfig)
def isTopicByName(self, topicName)
def createNode(self, doc)
def getVarName(self, varName)