topic.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 
00019 from airbus_docgen.digraph.digraph import *
00020 
00021 def getTopicTRModel(topic, msg, bgcolor=RgbColor.White, align = ALIGN.Left):
00022     
00023     model = TR()
00024     
00025     topic_td = TD()
00026     topic_td.setAttrib(TD.COLSPAN, 1)
00027     topic_td.setAttrib(TD.ALIGN, align)
00028     topic_td.setAttrib(TD.BGCOLOR, bgcolor)
00029     topic_td.setText(topic)
00030     model.addTD(topic_td)
00031     
00032     msg_td = TD()
00033     msg_td.setAttrib(TD.COLSPAN, 1)
00034     msg_td.setAttrib(TD.ALIGN, align)
00035     msg_td.setAttrib(TD.BGCOLOR, bgcolor)
00036     msg_td.setText(msg)
00037     model.addTD(msg_td)
00038     
00039     return model
00040 
00041 def getStandardTDModel(text, bgcolor=RgbColor.White, align = ALIGN.Left):
00042     
00043     model = TD()
00044     model.setAttrib(TD.COLSPAN, 1)
00045     model.setAttrib(TD.ALIGN, align)
00046     model.setAttrib(TD.BGCOLOR, bgcolor)
00047     model.setText(text)
00048     
00049     return model
00050 
00051 class _IoTopicsModel(NODE):
00052     
00053     def __init__(self, node_name, node_title):
00054         NODE.__init__(self, node_name)
00055         
00056         self._table = TABLE()
00057         self._table.setAttrib(TABLE.BORDER, 0)
00058         self._table.setAttrib(TABLE.CELLBORDER, 1)
00059         self._table.setAttrib(TABLE.CELLSPACING, 0)
00060         self._table.setAttrib(TABLE.BGCOLOR, RgbColor.White)
00061         
00062         title = TD()
00063         title.setAttrib(TD.ALIGN, ALIGN.Center)
00064         title.setAttrib(TD.BGCOLOR, RgbColor.LightSkyBlue)
00065         title.setAttrib(TD.COLSPAN, 2)
00066         title.setText(node_title)
00067         self._table.addTR(TR(title))
00068         
00069         header = getTopicTRModel("Topic name", "Message type", bgcolor=RgbColor.LightGray, align=ALIGN.Center)
00070         self._table.addTR(header)
00071         
00072     def addSubscriber(self, topic_name, msg):
00073         sub = getTopicTRModel(topic_name, msg)
00074         self._table.addTR(sub)
00075         
00076     def addPublisher(self, topic_name, msg):
00077         self.addSubscriber(topic_name, msg)
00078         
00079     def getNode(self):
00080         self.setHtml(self._table)
00081         return self
00082     
00083     def __str__(self):
00084         self.setHtml(self._table)
00085         return NODE.__str__(self)
00086     
00087 class SubscribersModel(_IoTopicsModel):
00088     def __init__(self):
00089         _IoTopicsModel.__init__(self, 'subscribers', "Subscribers list")
00090         
00091 class PublishersModel(_IoTopicsModel):
00092     def __init__(self):
00093         _IoTopicsModel.__init__(self, 'publishers', "Publishers list")
00094         
00095 # TFs Model
00096 
00097 if __name__ == '__main__':
00098 
00099     digraph = Digraph("digraph_test")
00100     digraph.setAttrib(Digraph.RANKDIR,'LR')
00101     
00102     nconf = NODE("node")
00103     nconf.setAttrib(NODE.SHAPE, SHAPE.Plaintext)
00104     
00105     subs = SubscribersModel()
00106     
00107     subs.addSubscriber("/vel1","geometry_msgs::Twist1")
00108     subs.addSubscriber("/vel2","geometry_msgs::Twist2")
00109     subs.addSubscriber("/vel3","geometry_msgs::Twist3")
00110     subs.addSubscriber("/vel4","geometry_msgs::Twist4")
00111     
00112     digraph.addNode(subs)
00113     
00114     pubs = PublishersModel()
00115     
00116     pubs.addSubscriber("/vel1","geometry_msgs::Twist1")
00117     pubs.addSubscriber("/vel2","geometry_msgs::Twist2")
00118     pubs.addSubscriber("/vel3","geometry_msgs::Twist3")
00119     pubs.addSubscriber("/vel4","geometry_msgs::Twist4")
00120     
00121     digraph.addNode(pubs)
00122     
00123     digraph.connect(subs,pubs)
00124     
00125     digraph.saveDot("/tmp/SubscribersModel.dot")
00126     digraph.dotToPng("/tmp/SubscribersModel.png")
00127 
00128     
00129     


airbus_docgen
Author(s): Matignon Martin
autogenerated on Thu Jun 6 2019 17:59:08