dotcode.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Open Source Robotics Foundation, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Open Source Robotics Foundation, Inc. nor
00017 #    the names of its contributors may be used to endorse or promote
00018 #    products derived from this software without specific prior
00019 #    written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 # Author: William Woodall <william@osrfoundation.org>
00035 
00036 """Provides functions to produce dotcode which represents the capability graph
00037 """
00038 
00039 from qt_dotgraph.pydotfactory import PydotFactory
00040 
00041 
00042 def generate_dotcode_from_capability_info(spec_index, running_providers):
00043     dotcode_factory = PydotFactory()
00044     dotgraph = dotcode_factory.get_graph(rankdir="BT")
00045     interface_graphs = {}
00046     # Draw plain interfaces
00047     for name in spec_index.interfaces:
00048         providers = [k for k, v in spec_index.providers.items() if v.implements == name]
00049         # Only create a subgraph if it has providers
00050         if providers:
00051             interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(dotgraph, str(name) + "_group", subgraphlabel='')
00052         # Draw box for interface
00053         graph = interface_graphs.get(name, dotgraph)
00054         dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box")
00055     # Draw semantic interfaces
00056     for name, interface in spec_index.semantic_interfaces.items():
00057         providers = [k for k, v in spec_index.providers.items() if v.implements == name]
00058         # Only create a subgraph if it has providers
00059         if providers:
00060             interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(dotgraph, str(name) + "_group", subgraphlabel='')
00061         graph = interface_graphs.get(name, dotgraph)
00062         # Draw box for semantic interface
00063         dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box")
00064         # Make edge to interface it redefines, if it exists
00065         if interface.redefines in spec_index.interfaces:
00066             dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(interface.redefines), label="redefines")
00067     # Draw providers
00068     interfaces = dict(spec_index.interfaces)
00069     interfaces.update(spec_index.semantic_interfaces)
00070     for name, provider in spec_index.providers.items():
00071         # Get subgraph of interface this provider implements
00072         graph = interface_graphs[provider.implements]
00073         # Get the default provider for the interface this provider implements
00074         default_provider = interfaces[provider.implements].default_provider
00075         provider_name = name
00076         # Add annotaion if this is the default provider
00077         if default_provider != 'unknown' and default_provider == name:
00078             provider_name += "  (default)"
00079         # If it is running, make it green
00080         if name in running_providers:
00081             dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse", color="green")
00082         # Else no color
00083         else:
00084             dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse")
00085         # Add edges to the interface, provider paris this provider depends on
00086         for dep, relationship in provider.dependencies.items():
00087             if relationship.preferred_provider is not None:
00088                 dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(relationship.preferred_provider), label="requires")
00089             elif spec_index.interfaces[relationship.capability_name].default_provider != 'unknown':
00090                 dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(spec_index.interfaces[relationship.capability_name].default_provider), label="requires")
00091     return dotcode_factory.create_dot(dotgraph)


rqt_capabilities
Author(s): William Woodall
autogenerated on Sat Jun 8 2019 18:40:50