RtmParser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # @file RtmParser.py
5 # @brief rtc-link XML connection list file parser
6 # @date $Date: 2005-05-12 09:06:19 $
7 # @author Tsuyoshi Tanabe, Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2004-2005
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id: RtmParser.py 775 2008-07-28 16:14:45Z n-ando $
17 #
18 
19 import sys,os
20 import string
21 from omniORB import CORBA
22 from xml.dom.minidom import parse
23 from xml.dom.minidom import getDOMImplementation
24 
25 import RtmDtdValidator
26 
27 #
28 #
29 #
30 class RtmParser :
31 # def serializeDOM(self, target, node) :
32 
33 # XMLファイルの出力: DOMツリー → XML
34  def dump2file(self, outfilename=None) :
35  if outfilename:
36  self.outfilename = outfilename
37  if self.outfilename :
38  print "outfilename:",self.outfilename
39  self.outfile = open(self.outfilename, "w")
40  self.outfile.write(self.cur_node.toxml())
41  self.outfile.write("\n")
42  self.outfile.close()
43  else :
44  none
45  return 1
46 
47  def dump2cout(self) :
48  print(self.cur_node.toxml())
49  return 1
50 
51 # root node の取得 ?
52  def get_root(self) :
53  return self.the_root_node
54 
55  def get_cur_node(self) :
56  return self.cur_node
57 
58  def set_cur_node(self, nd) :
59  self.cur_node = nd
60  return 1
61 
62  def reset_node(self) :
63  self.cur_node = self.the_root_node
64  return 1
65 
66  def getChildNodes(self) :
67  self.node_list = self.cur_node.childNodes
68  return self.node_list
69 
70  def getTaggedNodes(self, tg) :
71  self.node_list = self.cur_node.getElementsByTagName(tg)
72  return self.node_list
73 
74  def getText(self, nodes=None) :
75  if nodes == None:
76  nodes = self.cur_node.childNodes
77  rc = ''
78  for node in nodes:
79  if node.nodeType == node.TEXT_NODE:
80  rc = rc + node.data
81  return rc
82 
83  def replaceText(self, txt) :
84  tmp_node = self.dom.createTextNode(txt)
85  self.cur_node.childNodes = [tmp_node]
86  return 1
87 
88  def getTaggedText(self, tg) :
89  nodes = self.cur_node.getElementsByTagName(tg)[0]
90 # tmp_root = nodes[0]
91 # nodes = tmp_root.childNodes
92  rc = self.getText(nodes.childNodes)
93  return rc
94 
95 # child element の更新(replace)
96  def replaceTaggedText(self, tg, txt) :
97  nodes = self.cur_node.getElementsByTagName(tg)
98  tmp_root = nodes[0]
99  tmp_node = self.dom.createTextNode(txt)
100  tmp_root.childNodes = [tmp_node]
101  return 1
102 
103 # child node の削除(remove)
104  def removeChildNode(self, nd):
105  self.cur_node.removeChild(nd)
106 
107 # element,text を子ノードとして追加 def appendChildTaggedText(self, tg, txt): tmp_elem = self.dom.createElement(tg) tmp_txt = self.dom.createTextNode(txt) tmp_elem.appendChild(tmp_txt) self.cur_node.appendChild(tmp_elem) return tmp_elem # elementを子ノードとして追加 def appendChildTagged(self, tg): tmp_elem = self.dom.createElement(tg) self.cur_node.appendChild(tmp_elem) return tmp_elem # # for C access # def set_tmplist(self, lst) : self.tmp_node_list = lst return 1 def elt_tmp(self, idx) : return self.tmp_node_list[idx]; # # for C access (end) # def getComponentNode(self, comp_key): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") tmp = '' tmp1 = '' tmp2 = '' tmp3 = '' tmp4 = '' tmp5 = '' ret = None for comp_node in comp_list: tmp1 = comp_node.getElementsByTagName("host_name")[0] tmp1 = self.getText(tmp.childNodes) tmp2 = comp_node.getElementsByTagName("manager_name")[0] tmp2 = self.getText(tmp.childNodes) tmp3 = comp_node.getElementsByTagName("category")[0] tmp3 = self.getText(tmp.childNodes) tmp4 = comp_node.getElementsByTagName("module_name")[0] tmp4 = self.getText(tmp.childNodes) tmp5 = comp_node.getElementsByTagName("component_name")[0] tmp5 = self.getText(tmp.childNodes) tmp = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5 if tmp == comp_key: break if tmp1 == '' or tmp2 == '' or tmp3 == '' or tmp4 == '' or tmp5 == '': # tmp1 == '.*' or tmp2 == '.*' or tmp3 == '.*' or tmp4 == '.*' or tmp5 == '.*' : print "Component Name is not an" print self.infilename else: self.cur_node = comp_node ret = self.cur_node return ret def getComponentNames(self): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") ret = [] save_node = self.get_cur_node() for comp_node in comp_list: self.set_cur_node(comp_node) tmp = self.getTaggedText("component_name") ret.append(tmp) self.set_cur_node(save_node) return ret def getComponentKeys(self): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") ret = [] save_node = self.get_cur_node() for comp_node in comp_list: self.set_cur_node(comp_node) tmp = self.getTaggedText("component_name") tmp1 = self.getTaggedText("host_name") tmp2 = self.getTaggedText("manager_name") tmp3 = self.getTaggedText("category") tmp4 = self.getTaggedText("module_name") tmp5 = self.getTaggedText("component_name") nam = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5 ret.append(nam) self.set_cur_node(save_node) return ret # XMLファイルの読込み: XML → DOMツリー → ディクショナリ def readXML(self, in_name): self.infilename = in_name self.dom = parse(self.infilename) self.the_root_node = self.dom self.reset_node() dict = {} dict['rtc'] = {} dict['line'] = [] rtc_list = self.getTaggedNodes('rtc_list')[0] self.set_cur_node(rtc_list) comp_list = self.getChildNodes() for comp_node in comp_list: self.set_cur_node(comp_node) name = self.getTaggedText('name') name_elem = self.getTaggedNodes('name')[0] x = string.atof(name_elem.getAttribute('x')) y = string.atof(name_elem.getAttribute('y')) rot = name_elem.getAttribute('rot') # print "Comp name:",name," x=",x," y=",y dict['rtc'][name] = {} dict['rtc'][name]['x'] = x dict['rtc'][name]['y'] = y dict['rtc'][name]['rot'] = rot self.reset_node() line_list = self.getTaggedNodes('line_list')[0] self.set_cur_node(line_list) lines = self.getChildNodes() for line_node in lines: self.set_cur_node(line_node) pos = self.getTaggedText('pos') inp_comp = self.getTaggedText('inp-comp') inp_name = self.getTaggedText('inp-name') outp_comp = self.getTaggedText('outp-comp') outp_name = self.getTaggedText('outp-name') tmp = {} tmp['pos'] = pos tmp['in-comp'] = inp_comp tmp['in-name'] = inp_name tmp['out-comp'] = outp_comp tmp['out-name'] = outp_name dict['line'].append(tmp) return dict def writeXML(self, filename, dict): #XML document create impl = getDOMImplementation() doc = impl.createDocument(None, "rt_system", None) top_elem = doc.documentElement # LF = doc.createTextNode('\n') # top_elem.appendChild(LF) #XML node append #component block comp_list = dict['rtc'].keys() elemRtcList = doc.createElement("rtc_list") top_elem.appendChild(elemRtcList) for comp_name in comp_list: elem = doc.createElement("rt_component") elemRtcList.appendChild(elem) elemName = doc.createElement("name") elem.appendChild(elemName) child = doc.createTextNode(comp_name) elemName.appendChild(child) elemName.setAttribute('x','%f'%dict['rtc'][comp_name]['x']) elemName.setAttribute('y','%f'%dict['rtc'][comp_name]['y']) elemName.setAttribute('rot',dict['rtc'][comp_name]['rot']) elemLineList = doc.createElement("line_list") top_elem.appendChild(elemLineList) line_list = dict['line'] for line in line_list: elem = doc.createElement("line") elemLineList.appendChild(elem) str = '' for pos in line['pos']: str += '%f,%f,'%(pos[0],pos[1]) # str[-1] = '' elemPos = doc.createElement("pos") elem.appendChild(elemPos) child = doc.createTextNode(str) elemPos.appendChild(child) elemInComp = doc.createElement("inp-comp") elemInName = doc.createElement("inp-name") elem.appendChild(elemInComp) elem.appendChild(elemInName) child = doc.createTextNode(line['in-comp']) elemInComp.appendChild(child) child = doc.createTextNode(line['in-name']) elemInName.appendChild(child) elemOutComp = doc.createElement("outp-comp") elemOutName = doc.createElement("outp-name") elem.appendChild(elemOutComp) elem.appendChild(elemOutName) child = doc.createTextNode(line['out-comp']) elemOutComp.appendChild(child) child = doc.createTextNode(line['out-name']) elemOutName.appendChild(child) #dump to file outfile = open(filename, "w") doc.writexml(outfile) outfile.close() doc.unlink() def __init__(self) : self.infilename = None self.outfilename = None #----------------------------------------------------------------------
108  def appendChildTaggedText(self, tg, txt):
109  tmp_elem = self.dom.createElement(tg)
110  tmp_txt = self.dom.createTextNode(txt)
111  tmp_elem.appendChild(tmp_txt)
112  self.cur_node.appendChild(tmp_elem)
113  return tmp_elem
114 
115 # elementを子ノードとして追加 def appendChildTagged(self, tg): tmp_elem = self.dom.createElement(tg) self.cur_node.appendChild(tmp_elem) return tmp_elem # # for C access # def set_tmplist(self, lst) : self.tmp_node_list = lst return 1 def elt_tmp(self, idx) : return self.tmp_node_list[idx]; # # for C access (end) # def getComponentNode(self, comp_key): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") tmp = '' tmp1 = '' tmp2 = '' tmp3 = '' tmp4 = '' tmp5 = '' ret = None for comp_node in comp_list: tmp1 = comp_node.getElementsByTagName("host_name")[0] tmp1 = self.getText(tmp.childNodes) tmp2 = comp_node.getElementsByTagName("manager_name")[0] tmp2 = self.getText(tmp.childNodes) tmp3 = comp_node.getElementsByTagName("category")[0] tmp3 = self.getText(tmp.childNodes) tmp4 = comp_node.getElementsByTagName("module_name")[0] tmp4 = self.getText(tmp.childNodes) tmp5 = comp_node.getElementsByTagName("component_name")[0] tmp5 = self.getText(tmp.childNodes) tmp = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5 if tmp == comp_key: break if tmp1 == '' or tmp2 == '' or tmp3 == '' or tmp4 == '' or tmp5 == '': # tmp1 == '.*' or tmp2 == '.*' or tmp3 == '.*' or tmp4 == '.*' or tmp5 == '.*' : print "Component Name is not an" print self.infilename else: self.cur_node = comp_node ret = self.cur_node return ret def getComponentNames(self): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") ret = [] save_node = self.get_cur_node() for comp_node in comp_list: self.set_cur_node(comp_node) tmp = self.getTaggedText("component_name") ret.append(tmp) self.set_cur_node(save_node) return ret def getComponentKeys(self): # search for compornent node list comp_list = self.the_root_node.getElementsByTagName("rt_component") ret = [] save_node = self.get_cur_node() for comp_node in comp_list: self.set_cur_node(comp_node) tmp = self.getTaggedText("component_name") tmp1 = self.getTaggedText("host_name") tmp2 = self.getTaggedText("manager_name") tmp3 = self.getTaggedText("category") tmp4 = self.getTaggedText("module_name") tmp5 = self.getTaggedText("component_name") nam = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5 ret.append(nam) self.set_cur_node(save_node) return ret # XMLファイルの読込み: XML → DOMツリー → ディクショナリ def readXML(self, in_name): self.infilename = in_name self.dom = parse(self.infilename) self.the_root_node = self.dom self.reset_node() dict = {} dict['rtc'] = {} dict['line'] = [] rtc_list = self.getTaggedNodes('rtc_list')[0] self.set_cur_node(rtc_list) comp_list = self.getChildNodes() for comp_node in comp_list: self.set_cur_node(comp_node) name = self.getTaggedText('name') name_elem = self.getTaggedNodes('name')[0] x = string.atof(name_elem.getAttribute('x')) y = string.atof(name_elem.getAttribute('y')) rot = name_elem.getAttribute('rot') # print "Comp name:",name," x=",x," y=",y dict['rtc'][name] = {} dict['rtc'][name]['x'] = x dict['rtc'][name]['y'] = y dict['rtc'][name]['rot'] = rot self.reset_node() line_list = self.getTaggedNodes('line_list')[0] self.set_cur_node(line_list) lines = self.getChildNodes() for line_node in lines: self.set_cur_node(line_node) pos = self.getTaggedText('pos') inp_comp = self.getTaggedText('inp-comp') inp_name = self.getTaggedText('inp-name') outp_comp = self.getTaggedText('outp-comp') outp_name = self.getTaggedText('outp-name') tmp = {} tmp['pos'] = pos tmp['in-comp'] = inp_comp tmp['in-name'] = inp_name tmp['out-comp'] = outp_comp tmp['out-name'] = outp_name dict['line'].append(tmp) return dict def writeXML(self, filename, dict): #XML document create impl = getDOMImplementation() doc = impl.createDocument(None, "rt_system", None) top_elem = doc.documentElement # LF = doc.createTextNode('\n') # top_elem.appendChild(LF) #XML node append #component block comp_list = dict['rtc'].keys() elemRtcList = doc.createElement("rtc_list") top_elem.appendChild(elemRtcList) for comp_name in comp_list: elem = doc.createElement("rt_component") elemRtcList.appendChild(elem) elemName = doc.createElement("name") elem.appendChild(elemName) child = doc.createTextNode(comp_name) elemName.appendChild(child) elemName.setAttribute('x','%f'%dict['rtc'][comp_name]['x']) elemName.setAttribute('y','%f'%dict['rtc'][comp_name]['y']) elemName.setAttribute('rot',dict['rtc'][comp_name]['rot']) elemLineList = doc.createElement("line_list") top_elem.appendChild(elemLineList) line_list = dict['line'] for line in line_list: elem = doc.createElement("line") elemLineList.appendChild(elem) str = '' for pos in line['pos']: str += '%f,%f,'%(pos[0],pos[1]) # str[-1] = '' elemPos = doc.createElement("pos") elem.appendChild(elemPos) child = doc.createTextNode(str) elemPos.appendChild(child) elemInComp = doc.createElement("inp-comp") elemInName = doc.createElement("inp-name") elem.appendChild(elemInComp) elem.appendChild(elemInName) child = doc.createTextNode(line['in-comp']) elemInComp.appendChild(child) child = doc.createTextNode(line['in-name']) elemInName.appendChild(child) elemOutComp = doc.createElement("outp-comp") elemOutName = doc.createElement("outp-name") elem.appendChild(elemOutComp) elem.appendChild(elemOutName) child = doc.createTextNode(line['out-comp']) elemOutComp.appendChild(child) child = doc.createTextNode(line['out-name']) elemOutName.appendChild(child) #dump to file outfile = open(filename, "w") doc.writexml(outfile) outfile.close() doc.unlink() def __init__(self) : self.infilename = None self.outfilename = None #----------------------------------------------------------------------
116  def appendChildTagged(self, tg):
117  tmp_elem = self.dom.createElement(tg)
118  self.cur_node.appendChild(tmp_elem)
119  return tmp_elem
120 
121 #
122 # for C access
123 #
124  def set_tmplist(self, lst) :
125  self.tmp_node_list = lst
126  return 1
127 
128  def elt_tmp(self, idx) :
129  return self.tmp_node_list[idx];
130 #
131 # for C access (end)
132 #
133 
134  def getComponentNode(self, comp_key):
135  # search for compornent node list
136  comp_list = self.the_root_node.getElementsByTagName("rt_component")
137  tmp = ''
138  tmp1 = ''
139  tmp2 = ''
140  tmp3 = ''
141  tmp4 = ''
142  tmp5 = ''
143  ret = None
144  for comp_node in comp_list:
145 
146  tmp1 = comp_node.getElementsByTagName("host_name")[0]
147  tmp1 = self.getText(tmp.childNodes)
148  tmp2 = comp_node.getElementsByTagName("manager_name")[0]
149  tmp2 = self.getText(tmp.childNodes)
150  tmp3 = comp_node.getElementsByTagName("category")[0]
151  tmp3 = self.getText(tmp.childNodes)
152  tmp4 = comp_node.getElementsByTagName("module_name")[0]
153  tmp4 = self.getText(tmp.childNodes)
154  tmp5 = comp_node.getElementsByTagName("component_name")[0]
155  tmp5 = self.getText(tmp.childNodes)
156 
157  tmp = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5
158 
159  if tmp == comp_key:
160  break
161 
162  if tmp1 == '' or tmp2 == '' or tmp3 == '' or tmp4 == '' or tmp5 == '':
163 # tmp1 == '.*' or tmp2 == '.*' or tmp3 == '.*' or tmp4 == '.*' or tmp5 == '.*' :
164  print "Component Name is not an"
165  print self.infilename
166  else:
167  self.cur_node = comp_node
168  ret = self.cur_node
169  return ret
170 
171  def getComponentNames(self):
172  # search for compornent node list
173  comp_list = self.the_root_node.getElementsByTagName("rt_component")
174  ret = []
175  save_node = self.get_cur_node()
176  for comp_node in comp_list:
177  self.set_cur_node(comp_node)
178  tmp = self.getTaggedText("component_name")
179  ret.append(tmp)
180  self.set_cur_node(save_node)
181  return ret
182 
183  def getComponentKeys(self):
184  # search for compornent node list
185  comp_list = self.the_root_node.getElementsByTagName("rt_component")
186  ret = []
187  save_node = self.get_cur_node()
188  for comp_node in comp_list:
189  self.set_cur_node(comp_node)
190  tmp = self.getTaggedText("component_name")
191 
192  tmp1 = self.getTaggedText("host_name")
193  tmp2 = self.getTaggedText("manager_name")
194  tmp3 = self.getTaggedText("category")
195  tmp4 = self.getTaggedText("module_name")
196  tmp5 = self.getTaggedText("component_name")
197  nam = tmp1 + "/" + tmp2 + "/" + tmp3 + "/" + tmp4 + "/" + tmp5
198 
199  ret.append(nam)
200  self.set_cur_node(save_node)
201  return ret
202 
203 
204 # XMLファイルの読込み: XML → DOMツリー → ディクショナリ def readXML(self, in_name): self.infilename = in_name self.dom = parse(self.infilename) self.the_root_node = self.dom self.reset_node() dict = {} dict['rtc'] = {} dict['line'] = [] rtc_list = self.getTaggedNodes('rtc_list')[0] self.set_cur_node(rtc_list) comp_list = self.getChildNodes() for comp_node in comp_list: self.set_cur_node(comp_node) name = self.getTaggedText('name') name_elem = self.getTaggedNodes('name')[0] x = string.atof(name_elem.getAttribute('x')) y = string.atof(name_elem.getAttribute('y')) rot = name_elem.getAttribute('rot') # print "Comp name:",name," x=",x," y=",y dict['rtc'][name] = {} dict['rtc'][name]['x'] = x dict['rtc'][name]['y'] = y dict['rtc'][name]['rot'] = rot self.reset_node() line_list = self.getTaggedNodes('line_list')[0] self.set_cur_node(line_list) lines = self.getChildNodes() for line_node in lines: self.set_cur_node(line_node) pos = self.getTaggedText('pos') inp_comp = self.getTaggedText('inp-comp') inp_name = self.getTaggedText('inp-name') outp_comp = self.getTaggedText('outp-comp') outp_name = self.getTaggedText('outp-name') tmp = {} tmp['pos'] = pos tmp['in-comp'] = inp_comp tmp['in-name'] = inp_name tmp['out-comp'] = outp_comp tmp['out-name'] = outp_name dict['line'].append(tmp) return dict def writeXML(self, filename, dict): #XML document create impl = getDOMImplementation() doc = impl.createDocument(None, "rt_system", None) top_elem = doc.documentElement # LF = doc.createTextNode('\n') # top_elem.appendChild(LF) #XML node append #component block comp_list = dict['rtc'].keys() elemRtcList = doc.createElement("rtc_list") top_elem.appendChild(elemRtcList) for comp_name in comp_list: elem = doc.createElement("rt_component") elemRtcList.appendChild(elem) elemName = doc.createElement("name") elem.appendChild(elemName) child = doc.createTextNode(comp_name) elemName.appendChild(child) elemName.setAttribute('x','%f'%dict['rtc'][comp_name]['x']) elemName.setAttribute('y','%f'%dict['rtc'][comp_name]['y']) elemName.setAttribute('rot',dict['rtc'][comp_name]['rot']) elemLineList = doc.createElement("line_list") top_elem.appendChild(elemLineList) line_list = dict['line'] for line in line_list: elem = doc.createElement("line") elemLineList.appendChild(elem) str = '' for pos in line['pos']: str += '%f,%f,'%(pos[0],pos[1]) # str[-1] = '' elemPos = doc.createElement("pos") elem.appendChild(elemPos) child = doc.createTextNode(str) elemPos.appendChild(child) elemInComp = doc.createElement("inp-comp") elemInName = doc.createElement("inp-name") elem.appendChild(elemInComp) elem.appendChild(elemInName) child = doc.createTextNode(line['in-comp']) elemInComp.appendChild(child) child = doc.createTextNode(line['in-name']) elemInName.appendChild(child) elemOutComp = doc.createElement("outp-comp") elemOutName = doc.createElement("outp-name") elem.appendChild(elemOutComp) elem.appendChild(elemOutName) child = doc.createTextNode(line['out-comp']) elemOutComp.appendChild(child) child = doc.createTextNode(line['out-name']) elemOutName.appendChild(child) #dump to file outfile = open(filename, "w") doc.writexml(outfile) outfile.close() doc.unlink() def __init__(self) : self.infilename = None self.outfilename = None #----------------------------------------------------------------------
205  def readXML(self, in_name):
206 
207  self.infilename = in_name
208 
209  self.dom = parse(self.infilename)
210  self.the_root_node = self.dom
211  self.reset_node()
212 
213  dict = {}
214  dict['rtc'] = {}
215  dict['line'] = []
216  rtc_list = self.getTaggedNodes('rtc_list')[0]
217  self.set_cur_node(rtc_list)
218  comp_list = self.getChildNodes()
219  for comp_node in comp_list:
220  self.set_cur_node(comp_node)
221  name = self.getTaggedText('name')
222  name_elem = self.getTaggedNodes('name')[0]
223  x = string.atof(name_elem.getAttribute('x'))
224  y = string.atof(name_elem.getAttribute('y'))
225  rot = name_elem.getAttribute('rot')
226 # print "Comp name:",name," x=",x," y=",y
227  dict['rtc'][name] = {}
228  dict['rtc'][name]['x'] = x
229  dict['rtc'][name]['y'] = y
230  dict['rtc'][name]['rot'] = rot
231 
232  self.reset_node()
233  line_list = self.getTaggedNodes('line_list')[0]
234  self.set_cur_node(line_list)
235  lines = self.getChildNodes()
236  for line_node in lines:
237  self.set_cur_node(line_node)
238  pos = self.getTaggedText('pos')
239  inp_comp = self.getTaggedText('inp-comp')
240  inp_name = self.getTaggedText('inp-name')
241  outp_comp = self.getTaggedText('outp-comp')
242  outp_name = self.getTaggedText('outp-name')
243  tmp = {}
244  tmp['pos'] = pos
245  tmp['in-comp'] = inp_comp
246  tmp['in-name'] = inp_name
247  tmp['out-comp'] = outp_comp
248  tmp['out-name'] = outp_name
249  dict['line'].append(tmp)
250 
251  return dict
252 
253 
254  def writeXML(self, filename, dict):
255  #XML document create
256  impl = getDOMImplementation()
257  doc = impl.createDocument(None, "rt_system", None)
258  top_elem = doc.documentElement
259 # LF = doc.createTextNode('\n')
260 # top_elem.appendChild(LF)
261 
262  #XML node append
263  #component block
264  comp_list = dict['rtc'].keys()
265  elemRtcList = doc.createElement("rtc_list")
266  top_elem.appendChild(elemRtcList)
267  for comp_name in comp_list:
268  elem = doc.createElement("rt_component")
269  elemRtcList.appendChild(elem)
270  elemName = doc.createElement("name")
271  elem.appendChild(elemName)
272  child = doc.createTextNode(comp_name)
273  elemName.appendChild(child)
274  elemName.setAttribute('x','%f'%dict['rtc'][comp_name]['x'])
275  elemName.setAttribute('y','%f'%dict['rtc'][comp_name]['y'])
276  elemName.setAttribute('rot',dict['rtc'][comp_name]['rot'])
277 
278  elemLineList = doc.createElement("line_list")
279  top_elem.appendChild(elemLineList)
280  line_list = dict['line']
281  for line in line_list:
282  elem = doc.createElement("line")
283  elemLineList.appendChild(elem)
284  str = ''
285  for pos in line['pos']:
286  str += '%f,%f,'%(pos[0],pos[1])
287 # str[-1] = ''
288  elemPos = doc.createElement("pos")
289  elem.appendChild(elemPos)
290  child = doc.createTextNode(str)
291  elemPos.appendChild(child)
292 
293  elemInComp = doc.createElement("inp-comp")
294  elemInName = doc.createElement("inp-name")
295  elem.appendChild(elemInComp)
296  elem.appendChild(elemInName)
297  child = doc.createTextNode(line['in-comp'])
298  elemInComp.appendChild(child)
299  child = doc.createTextNode(line['in-name'])
300  elemInName.appendChild(child)
301 
302  elemOutComp = doc.createElement("outp-comp")
303  elemOutName = doc.createElement("outp-name")
304  elem.appendChild(elemOutComp)
305  elem.appendChild(elemOutName)
306  child = doc.createTextNode(line['out-comp'])
307  elemOutComp.appendChild(child)
308  child = doc.createTextNode(line['out-name'])
309  elemOutName.appendChild(child)
310 
311 
312  #dump to file
313  outfile = open(filename, "w")
314  doc.writexml(outfile)
315  outfile.close()
316 
317  doc.unlink()
318 
319  def __init__(self) :
320  self.infilename = None
321  self.outfilename = None
322 #----------------------------------------------------------------------
def dump2cout(self)
Definition: RtmParser.py:47
def dump2file(self, outfilename=None)
Definition: RtmParser.py:34
def readXML(self, in_name)
Definition: RtmParser.py:205
def get_cur_node(self)
Definition: RtmParser.py:55
def getComponentKeys(self)
Definition: RtmParser.py:183
def getComponentNames(self)
Definition: RtmParser.py:171
def reset_node(self)
Definition: RtmParser.py:62
def __init__(self)
Definition: RtmParser.py:319
def getComponentNode(self, comp_key)
Definition: RtmParser.py:134
def getChildNodes(self)
Definition: RtmParser.py:66
def appendChildTagged(self, tg)
Definition: RtmParser.py:116
def appendChildTaggedText(self, tg, txt)
Definition: RtmParser.py:108
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
Definition: NVUtil.cpp:354
def set_cur_node(self, nd)
Definition: RtmParser.py:58
def getTaggedText(self, tg)
Definition: RtmParser.py:88
def get_root(self)
Definition: RtmParser.py:52
def removeChildNode(self, nd)
Definition: RtmParser.py:104
def writeXML(self, filename, dict)
Definition: RtmParser.py:254
def getText(self, nodes=None)
Definition: RtmParser.py:74
def elt_tmp(self, idx)
Definition: RtmParser.py:128
def replaceText(self, txt)
Definition: RtmParser.py:83
def set_tmplist(self, lst)
Definition: RtmParser.py:124
def replaceTaggedText(self, tg, txt)
Definition: RtmParser.py:96
def getTaggedNodes(self, tg)
Definition: RtmParser.py:70


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:55