Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 from airbus_docgen import env
00019 from airbus_docgen.common import html
00020 from airbus_docgen.common.html import HtmlElement
00021
00022 from airbus_docgen.digraph.digraph import *
00023 from airbus_docgen.digraph.model.actionlib import ActionServerModel, ActionClientModel
00024 from airbus_docgen.digraph.model.topic import SubscribersModel, PublishersModel
00025
00026 class NodeInputOutput(HtmlElement):
00027
00028 def __init__(self):
00029 HtmlElement.__init__(self,
00030 tag=html.Sections.article,
00031 attrib={"class":"io-node"})
00032
00033 def _create_digraph(self, name):
00034
00035 digraph = Digraph("IoGraph")
00036 digraph.setAttrib(Digraph.NODESEP, 0.8)
00037 digraph.setAttrib(Digraph.RANKDIR, 'LR')
00038
00039 nconf = NODE("node")
00040 nconf.setAttrib(NODE.SHAPE, SHAPE.Plaintext)
00041 digraph.addNode(nconf)
00042
00043 pkg = NODE(name)
00044 pkg.setAttrib(NODE.SHAPE, SHAPE.Ellipse)
00045 pkg.setAttrib(NODE.STYLE, STYLE.FILLED)
00046 pkg.setAttrib(NODE.COLOR, RgbColor.CornflowerBlue)
00047 pkg.setAttrib(NODE.FONTSIZE, 22)
00048 digraph.addRootNode(pkg)
00049
00050 return digraph
00051
00052 def read(self, node_name, node_xml):
00053
00054 digraph = self._create_digraph(node_name)
00055
00056 for child in node_xml.find('io'):
00057 if child.tag == "topics":
00058 try:
00059 self._read_topics(child, digraph)
00060 except:
00061 continue
00062 elif child.tag == "actionlib":
00063 try:
00064 self._read_actionlibs(child, digraph)
00065 except:
00066 continue
00067 elif child.tag == "services":
00068 try:
00069 self._read_services(child, digraph)
00070 except:
00071 continue
00072 else:
00073 html.HTMLException("Unknown io tag '%s' from node %s !"%(child.tag, node_name), self)
00074
00075 digraph.saveDot(env.ROSDOC_DOT+"/io/%s.dot"%node_name)
00076 digraph.dotToPng(env.ROSDOC_DOT+"/io/%s.png"%node_name)
00077
00078 p = HtmlElement(html.Grouping.p)
00079 p.set("align","center")
00080 img = HtmlElement(html.EmbeddedContent.img)
00081 img.set("src","../dot/io/%s.png"%node_name)
00082
00083 p.append(img)
00084 self.append(p)
00085
00086 return True
00087
00088 def _read_topics(self, node, digraph):
00089
00090 if node is None or node.tag != "topics":
00091 html.HTMLException("Invalid topics container !", self)
00092 return
00093
00094 subs_dot_model = SubscribersModel()
00095 pubs_dot_model = PublishersModel()
00096 has_pub = False
00097 has_sub = False
00098
00099 for child in node:
00100 if child.tag == "publisher":
00101 pubs_dot_model.addPublisher(child.attrib["name"],
00102 child.attrib["msg"])
00103 has_pub=True
00104 elif child.tag == "subscriber":
00105 subs_dot_model.addSubscriber(child.attrib["name"],
00106 child.attrib["msg"])
00107 has_sub=True
00108 else:
00109 print "Unknown topics tag '%s' !"%child.tag
00110
00111 if has_pub is True:
00112 digraph.addNode(pubs_dot_model)
00113 digraph.connect(digraph.getRootNode(), pubs_dot_model)
00114
00115 if has_sub is True:
00116 digraph.addNode(subs_dot_model)
00117 digraph.connect(subs_dot_model, digraph.getRootNode())
00118
00119 def _read_actionlibs(self, node, digraph):
00120
00121 if node is None or node.tag != "actionlib":
00122 html.HTMLException("Invalid actionlib container !", self)
00123 return
00124
00125 for child in node:
00126 if child.tag == "client":
00127 try:
00128 ns = ActionClientModel(child.attrib["name"], child.attrib["action"])
00129 digraph.addNode(ns)
00130 digraph.connect(digraph.getRootNode(), ns, Edge(Edge.DIR, "both"))
00131 except:
00132 continue
00133 elif child.tag == "server":
00134 try:
00135 nc = ActionServerModel(child.attrib["name"], child.attrib["action"])
00136 digraph.addNode(nc)
00137 digraph.connect(nc, digraph.getRootNode(), Edge(Edge.DIR, "both"))
00138 except:
00139 continue
00140 else:
00141 print "Unknown actionlibs tag '%s' !"%child.tag
00142
00143 def _read_services(self, node, digraph):
00144
00145 if node is None or node.tag != "services":
00146 html.HTMLException("Invalid services container !", self)
00147 return
00148
00149 for child in node:
00150 if child.tag == "client":
00151 print "Service client : ",child.attrib
00152 elif child.tag == "server":
00153 print "Service server : ",child.attrib
00154 else:
00155 print "Unknown services tag '%s' !"%child.tag
00156