Beispiel #1
0
 def test_add_node_escape_name(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_node_to_graph(g, 'graph')
     self.assertEqual(1, len(g.get_nodes()))
     self.assertEqual('graph_', g.get_nodes()[0].get_name())
     self.assertEqual('graph_', g.get_nodes()[0].get_label())
Beispiel #2
0
    def _render_dotgraph(self, dotgraph):
        """
        Render the specified dotgraph on canvas

        :type dotgraph: pydot.Dot
        """

        # Only redraw when the graph differs from the previous one
        if self._prev_dotgraph == dotgraph:
            return
        else:
            self._prev_dotgraph = dotgraph

        self._scene.clear()

        if self._widget.highlight_connections_check_box.isChecked():
            highlight_level = 3
        else:
            highlight_level = 1

        # Generate qt items from dotcode
        dotcode = PydotFactory().create_dot(dotgraph)
        nodes, edges = DotToQtGenerator().dotcode_to_qt_items(
            dotcode, highlight_level, same_label_siblings=False)

        # Add generated items to scene
        for node_item in nodes:
            self._scene.addItem(nodes.get(node_item))
        for edge_items in edges:
            for edge_item in edges.get(edge_items):
                edge_item.add_to_scene(self._scene)

        self._scene.setSceneRect(self._scene.itemsBoundingRect())
Beispiel #3
0
def get_current_rqt_graph_to_dotcode():
    dotcode_generator = rqt_graph.dotcode.RosGraphDotcodeGenerator()

    # starting at line 229 of ros_graph.py
    ns_filter = '/'
    topic_filter = '/'
    graph_mode = 'node_topic_all'  # (Nodes/Topics(all))
    orientation = 'LR'
    namespace_cluster = 1

    accumulate_actions = True  # (Group: (Actions))
    hide_dead_end_topics = False  #True # (Dead sinks)
    hide_single_connection_topics = False  #True (Leaf Topics)
    quiet = True
    dotcode_factory = PydotFactory()

    graph = rosgraph.impl.graph.Graph()
    graph.set_master_stale(5.0)
    graph.set_node_stale(5.0)
    graph.update()

    dotcode = dotcode_generator.generate_dotcode(
        rosgraphinst=graph,
        ns_filter=ns_filter,
        topic_filter=topic_filter,
        graph_mode=graph_mode,
        hide_single_connection_topics=hide_single_connection_topics,
        hide_dead_end_topics=hide_dead_end_topics,
        cluster_namespaces_level=namespace_cluster,
        accumulate_actions=accumulate_actions,
        dotcode_factory=dotcode_factory,
        orientation=orientation,
        quiet=quiet)

    return dotcode
Beispiel #4
0
 def __init__(self, ros: Ros, parent=None):
     super(TopicGraphWidget, self).__init__(parent)
     self.ros_client = ros
     layout = QVBoxLayout()
     self._widget = QWidget()
     self._scene = QGraphicsScene()
     self._scene.setBackgroundBrush(Qt.white)
     self._graphics_view = InteractiveGraphicsView(self._widget)
     self._graphics_view.setScene(self._scene)
     self._graphics_view.setRenderHints(QPainter.Antialiasing
                                        | QPainter.HighQualityAntialiasing
                                        | QPainter.SmoothPixmapTransform
                                        | QPainter.TextAntialiasing)
     self._graphics_view.setResizeAnchor(QGraphicsView.AnchorViewCenter)
     layout.addWidget(self._graphics_view)
     self._refresh_button = QPushButton('加载数据')
     self._refresh_button.setFixedWidth(100)
     self._refresh_button.clicked.connect(self._draw_graph_view)
     btn_layout = QHBoxLayout()
     btn_layout.addWidget(self._refresh_button)
     layout.addLayout(btn_layout)
     self.setLayout(layout)
     self._current_dotcode = None
     self.dot_to_qt = DotToQtGenerator()
     self.dotcode_factory = PydotFactory()
     self.dotcode_generator = RosGraphDotcodeGenerator(self.ros_client)
     self._graph = graph.Graph(self.ros_client)
     self._graph.set_master_stale(5.0)
     self._graph.set_node_stale(5.0)
Beispiel #5
0
 def test_add_subgraph_escape_name(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_subgraph_to_graph(g, 'graph')
     self.assertEqual(1, len(g.get_subgraph_list()))
     self.assertEqual('cluster_graph_', g.get_subgraph_list()[0].get_name())
     self.assertEqual('graph_', g.get_subgraph_list()[0].get_label())
Beispiel #6
0
    def __init__(self, context):
        super(RosTfTree, self).__init__(context)
        self.initialized = False

        self.setObjectName('RosTfTree')

        self._current_dotcode = None

        self._widget = QWidget()

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        # generator builds rosgraph
        self.dotcode_generator = RosTfTreeDotcodeGenerator()
        self.tf2_buffer_ = tf2_ros.Buffer()
        self.tf2_listener_ = tf2_ros.TransformListener(self.tf2_buffer_)

        # dot_to_qt transforms into Qt elements using dot layout
        self.dot_to_qt = DotToQtGenerator()

        rp = rospkg.RosPack()
        ui_file = os.path.join(rp.get_path('rqt_tf_tree'), 'resource', 'RosTfTree.ui')
        loadUi(ui_file, self._widget, {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('RosTfTreeUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.refresh_graph_push_button.setIcon(QIcon.fromTheme('view-refresh'))
        self._widget.refresh_graph_push_button.pressed.connect(self._update_tf_graph)

        self._widget.highlight_connections_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.fit_in_view_push_button.setIcon(QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._widget.load_dot_push_button.setIcon(QIcon.fromTheme('document-open'))
        self._widget.load_dot_push_button.pressed.connect(self._load_dot)
        self._widget.save_dot_push_button.setIcon(QIcon.fromTheme('document-save-as'))
        self._widget.save_dot_push_button.pressed.connect(self._save_dot)
        self._widget.save_as_svg_push_button.setIcon(QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(QIcon.fromTheme('image-x-generic'))
        self._widget.save_as_image_push_button.pressed.connect(self._save_image)

        self._deferred_fit_in_view.connect(self._fit_in_view,
                                           Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()

        context.add_widget(self._widget)

        self._force_refresh = False
Beispiel #7
0
 def __init__(self):
     #Init the base class
     QtGui.QGraphicsScene.__init__(self)
     
     # dot_to_qt transforms into Qt elements using dot layout
     self._dot_to_qt = DotToQtGenerator()
     #The pydotfactory
     self._dot_factory = PydotFactory()
     self._graph = None      
     pass
Beispiel #8
0
 def test_add_edge(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_node_to_graph(g, 'foo')
     fac.add_node_to_graph(g, 'bar')
     fac.add_edge_to_graph(g, 'foo', 'bar')
     self.assertEqual(2, len(g.get_nodes()))
     self.assertEqual(1, len(g.get_edges()))
     self.assertEqual('foo', g.get_edges()[0].get_source())
     self.assertEqual('bar', g.get_edges()[0].get_destination())
Beispiel #9
0
    def __init__(self, context):
        self._context=context
        super(ConductorGraph, self).__init__(context)
        self.initialised=False
        self.setObjectName('Conductor Graph')
        self._current_dotcode=None
        self._node_items=None
        self._edge_items=None
        self._node_item_events={}
        self._edge_item_events={}
        self._client_info_list={}
        self._widget=QWidget()
        self.cur_selected_client_name = ""
        self.pre_selected_client_name = ""
            
        # factory builds generic dotcode items
        self.dotcode_factory=PydotFactory()
        # self.dotcode_factory=PygraphvizFactory()
        self.dotcode_generator=RosGraphDotcodeGenerator()
        self.dot_to_qt=DotToQtGenerator()
        
        self._graph=ConductorGraphInfo()
        self._graph._reg_event_callback(self._update_client_list)
        self._graph._reg_period_callback(self._set_network_statisics)
        
        rospack=rospkg.RosPack()
        ui_file=os.path.join(rospack.get_path('concert_conductor_graph'), 'ui', 'conductor_graph.ui')
        loadUi(ui_file, self._widget, {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('ConductorGraphUi')

        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))

        self._scene=QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        #self._widget.refresh_graph_push_button.setIcon(QIcon.fromTheme('view-refresh'))
        self._widget.refresh_graph_push_button.setIcon(QIcon.fromTheme('window-new'))
        self._widget.refresh_graph_push_button.pressed.connect(self._update_conductor_graph)

        self._widget.highlight_connections_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.fit_in_view_push_button.setIcon(QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._deferred_fit_in_view.connect(self._fit_in_view, Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()
        
        self._widget.tabWidget.currentChanged.connect(self._change_client_tab)
        self._client_list_update_signal.connect(self._update_conductor_graph)
        
        #rospy.Subscriber(concert_msgs.Strings.CONCERT_CLIENT_CHANGES, ConcertClients, self._update_client_list)
        
        context.add_widget(self._widget)
Beispiel #10
0
    def __init__(self, context):
        self._context = context
        super(ConductorGraph, self).__init__(context)
        self.initialised = False
        self.setObjectName('Conductor Graph')
        self._node_items = None
        self._edge_items = None
        self._node_item_events = {}
        self._edge_item_events = {}
        self._client_info_list = {}
        self._widget = QWidget()
        self.cur_selected_client_name = ""
        self.pre_selected_client_name = ""
        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory=PygraphvizFactory()
        self.dotcode_generator = ConductorGraphDotcodeGenerator()
        self.dot_to_qt = DotToQtGenerator()

        self._graph = ConductorGraphInfo(self._update_conductor_graph_relay,
                                         self._set_network_statisics)

        rospack = rospkg.RosPack()
        ui_file = os.path.join(rospack.get_path('concert_conductor_graph'),
                               'ui', 'conductor_graph.ui')
        loadUi(ui_file, self._widget,
               {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('ConductorGraphUi')

        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() +
                                        (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.highlight_connections_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.clusters_check_box.toggled.connect(
            self._redraw_graph_view)

        self.signal_deferred_fit_in_view.connect(self._fit_in_view,
                                                 Qt.QueuedConnection)
        self.signal_deferred_fit_in_view.emit()

        self._widget.tabWidget.currentChanged.connect(self._change_client_tab)
        self.signal_update_conductor_graph.connect(
            self._update_conductor_graph)

        context.add_widget(self._widget)
Beispiel #11
0
    def __init__(self, context):
        super(Ros2KnowledgeGraph, self).__init__(context)

        self._node = context.node
        self._logger = self._node.get_logger().get_child(
            'ros2_knowledge_graph_viewer.ros2_knowledge_graph.Ros2KnowledgeGraph'
        )
        self.setObjectName('Ros2KnowledgeGraph')

        self._ros2_knowledge_graph = Ros2KnowledgeGraphImpl()
        self._current_dotcode = None

        self._widget = QWidget()

        self.dotcode_factory = PydotFactory()
        self.dotcode_generator = Ros2KnowledgeGraphDotcodeGenerator()
        self.dot_to_qt = DotToQtGenerator()

        _, package_path = get_resource('packages',
                                       'ros2_knowledge_graph_viewer')
        ui_file = os.path.join(package_path, 'share',
                               'ros2_knowledge_graph_viewer', 'resource',
                               'Ros2KnowledgeGraph.ui')
        loadUi(ui_file, self._widget,
               {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('Ros2KnowledgeGraphUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() +
                                        (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.save_as_svg_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(
            QIcon.fromTheme('image'))
        self._widget.save_as_image_push_button.pressed.connect(
            self._save_image)

        self._update_ros2_knowledge_graph()
        self._deferred_fit_in_view.connect(self._fit_in_view,
                                           Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()

        context.add_widget(self._widget)

        self._updateTimer = QtCore.QTimer()
        self._updateTimer.timeout.connect(self.do_update)
        self._updateTimer.start(10)
 def test_create_dot(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_node_to_graph(g, 'foo')
     fac.add_node_to_graph(g, 'edge')
     fac.add_edge_to_graph(g, 'foo', 'edge')
     fac.add_subgraph_to_graph(g, 'foo')
     snippets = ['digraph graphname {\n\tgraph [rankdir=TB, ranksep="0.2", rank=same, compound=True];\n\tnode [label="\\N"];\n\tgraph [bb="', '"];\n\tsubgraph cluster_foo {\n\t\tgraph [',
                 '];\n\t}\n\tfoo [label=foo, shape=box, pos="',
                 'edge_ [label=edge_, shape=box, pos="',
                 'foo -> edge_',
                 '"];\n}\n']
     result = fac.create_dot(g)
     for sn in snippets:
         self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))
 def test_create_dot(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_node_to_graph(g, 'foo')
     fac.add_node_to_graph(g, 'edge')
     fac.add_edge_to_graph(g, 'foo', 'edge')
     fac.add_subgraph_to_graph(g, 'foo')
     snippets = [
         'digraph graphname {\n\tgraph [', 'rankdir=TB', 'compound=True',
         'rank=same', 'node [label="\\N"]',
         'subgraph cluster_foo {\n\t\tgraph [', 'foo\t [', 'label=foo',
         'shape=box', 'pos="', 'edge_\t [', 'label=edge_',
         'foo -> edge_\t [', '"];\n}\n'
     ]
     result = fac.create_dot(g)
     for sn in snippets:
         self.assertTrue(sn in result,
                         '%s \nmissing in\n %s' % (sn, result))
Beispiel #14
0
    def __init__(self, clusters=False):

        self._clusters = clusters
        self._dotcode_factory = PydotFactory()
        self._dotcode_generator = GraphDotcodeGenerator()
        self._pub_string = None

        self._graph = ConductorGraphInfo(
            change_callback=self._update_conductor_graph,
            periodic_callback=self._periodic_callback)

        while not self._graph.is_conductor and not rospy.is_shutdown():
            # self.loginfo("waits for conductor to be ready.")
            rospy.rostime.wallsleep(1)

        self._pub_string = rospy.Publisher(self._graph.namespace +
                                           '/graph/dot',
                                           std_msgs.String,
                                           queue_size=2)
Beispiel #15
0
 def test_create_dot(self):
     fac = PydotFactory()
     g = fac.get_graph()
     fac.add_node_to_graph(g, 'foo')
     fac.add_node_to_graph(g, 'edge')
     fac.add_edge_to_graph(g, 'foo', 'edge')
     fac.add_subgraph_to_graph(g, 'foo')
     snippets = [
         'digraph graphname { graph [', 'rankdir=TB', 'compound=True',
         'rank=same', 'node [label="\\N"]',
         'subgraph cluster_foo { graph [', 'foo [', 'label=foo',
         'shape=box', 'pos="', 'edge_ [', 'label=edge_', 'foo -> edge_ [',
         '"]; }'
     ]
     result = fac.create_dot(g)
     # get rid of version specific whitespaces
     result = re.sub('[\n\t ]+', ' ', result)
     for sn in snippets:
         self.assertTrue(sn in result,
                         '%s \nmissing in\n %s' % (sn, result))
Beispiel #16
0
    def __init__(self, dotFile, aboveDistance=1, belowDistance=1):
        """
        * dotFile -- is the path to the dot file to load
        * aboveDistance -- the default distance above the node to display
        * belowDistance -- the default distance below the node to display

        """
        self.__dotFile = dotFile
        self.__selectedNode = ""  # No node selected by default
        self.__aboveDistance = aboveDistance
        self.__belowDistance = belowDistance

        # Factory used to generate dot code
        self.__dotcodeFactory = PydotFactory()

        # List of all nodes in the graph (updated once file is loaded)
        self.__allNodes = None

        # List of graph nodes and edges to display
        self.nodes = []
        self.edges = []

        # Load the initial dot file
        self.__loadDotFile()
Beispiel #17
0
    def __init__(self, context):
        super(RosPackGraph, self).__init__(context)
        self.initialized = False
        self._current_dotcode = None
        self._update_thread = WorkerThread(self._update_thread_run,
                                           self._update_finished)
        self._nodes = {}
        self._edges = {}
        self._options = {}
        self._options_serialized = ''

        self.setObjectName('RosPackGraph')

        rospack = rospkg.RosPack()
        rosstack = rospkg.RosStack()

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        # generator builds rosgraph
        self.dotcode_generator = RosPackageGraphDotcodeGenerator(
            rospack, rosstack)
        # dot_to_qt transforms into Qt elements using dot layout
        self.dot_to_qt = DotToQtGenerator()

        self._widget = QWidget()
        rp = rospkg.RosPack()
        ui_file = os.path.join(rp.get_path('rqt_dep'), 'resource',
                               'RosPackGraph.ui')
        loadUi(ui_file, self._widget,
               {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('RosPackGraphUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() +
                                        (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.depth_combo_box.insertItem(0, self.tr('infinite'), -1)
        self._widget.depth_combo_box.insertItem(1, self.tr('1'), 2)
        self._widget.depth_combo_box.insertItem(2, self.tr('2'), 3)
        self._widget.depth_combo_box.insertItem(3, self.tr('3'), 4)
        self._widget.depth_combo_box.insertItem(4, self.tr('4'), 5)
        self._widget.depth_combo_box.currentIndexChanged.connect(
            self._refresh_rospackgraph)

        self._widget.directions_combo_box.insertItem(0, self.tr('depends'), 0)
        self._widget.directions_combo_box.insertItem(1, self.tr('depends_on'),
                                                     1)
        self._widget.directions_combo_box.insertItem(2, self.tr('both'), 2)
        self._widget.directions_combo_box.currentIndexChanged.connect(
            self._refresh_rospackgraph)

        self._widget.package_type_combo_box.insertItem(0, self.tr('wet & dry'),
                                                       3)
        self._widget.package_type_combo_box.insertItem(1, self.tr('wet only'),
                                                       2)
        self._widget.package_type_combo_box.insertItem(2, self.tr('dry only'),
                                                       1)
        self._widget.package_type_combo_box.currentIndexChanged.connect(
            self._refresh_rospackgraph)

        completionmodel = StackageCompletionModel(
            self._widget.filter_line_edit, rospack, rosstack)
        completer = RepeatedWordCompleter(completionmodel, self)
        completer.setCompletionMode(QCompleter.PopupCompletion)
        completer.setWrapAround(True)

        completer.setCaseSensitivity(Qt.CaseInsensitive)
        self._widget.filter_line_edit.editingFinished.connect(
            self._refresh_rospackgraph)
        self._widget.filter_line_edit.setCompleter(completer)
        self._widget.filter_line_edit.selectionChanged.connect(
            self._clear_filter)

        self._widget.with_stacks_check_box.clicked.connect(
            self._refresh_rospackgraph)
        self._widget.mark_check_box.clicked.connect(self._refresh_rospackgraph)
        self._widget.colorize_check_box.clicked.connect(
            self._refresh_rospackgraph)
        self._widget.hide_transitives_check_box.clicked.connect(
            self._refresh_rospackgraph)
        self._widget.show_system_check_box.clicked.connect(
            self._refresh_rospackgraph)

        self._widget.refresh_graph_push_button.setIcon(
            QIcon.fromTheme('view-refresh'))
        self._widget.refresh_graph_push_button.pressed.connect(
            self._update_rospackgraph)

        self._widget.highlight_connections_check_box.toggled.connect(
            self._refresh_rospackgraph)
        self._widget.auto_fit_graph_check_box.toggled.connect(
            self._refresh_rospackgraph)
        self._widget.fit_in_view_push_button.setIcon(
            QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._widget.load_dot_push_button.setIcon(
            QIcon.fromTheme('document-open'))
        self._widget.load_dot_push_button.pressed.connect(self._load_dot)
        self._widget.save_dot_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_dot_push_button.pressed.connect(self._save_dot)
        self._widget.save_as_svg_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(
            QIcon.fromTheme('image'))
        self._widget.save_as_image_push_button.pressed.connect(
            self._save_image)

        self._deferred_fit_in_view.connect(self._fit_in_view,
                                           Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()

        context.add_widget(self._widget)

        # If in either of following case, this turnes True
        # - 1st filtering key is already input by user
        # - filtering key is restored
        self._filtering_started = False
Beispiel #18
0
    def __init__(self, context):
        super(GatewayGraph, self).__init__(context)
        self.initialised = False
        self.setObjectName('Gateway Graph')
        self._current_dotcode = None

        self._widget = QWidget()

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        self.dotcode_generator = RosGraphDotcodeGenerator()
        self.dot_to_qt = DotToQtGenerator()
        self._graph = Graph()

        rospack = rospkg.RosPack()
        ui_file = os.path.join(rospack.get_path('rocon_gateway_graph'), 'ui',
                               'gateway_graph.ui')
        #ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui', 'gateway_graph.ui')
        loadUi(ui_file, self._widget,
               {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('GatewayGraphUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() +
                                        (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.refresh_graph_push_button.setIcon(
            QIcon.fromTheme('view-refresh'))
        self._widget.refresh_graph_push_button.pressed.connect(
            self._update_gateway_graph)

        self._widget.graph_type_combo_box.insertItem(0, self.tr('Gateways'),
                                                     GATEWAY_GATEWAY_GRAPH)
        self._widget.graph_type_combo_box.insertItem(
            1, self.tr('Pulled Connections'), GATEWAY_PULLED_GRAPH)
        self._widget.graph_type_combo_box.insertItem(
            2, self.tr('Flipped Connections'), GATEWAY_FLIPPED_GRAPH)
        self._widget.graph_type_combo_box.setCurrentIndex(0)
        self._widget.graph_type_combo_box.currentIndexChanged.connect(
            self._refresh_rosgraph)

        self.node_completionmodel = NamespaceCompletionModel(
            self._widget.filter_line_edit, False)
        completer = RepeatedWordCompleter(self.node_completionmodel, self)
        completer.setCompletionMode(QCompleter.PopupCompletion)
        completer.setWrapAround(True)
        completer.setCaseSensitivity(Qt.CaseInsensitive)
        self._widget.filter_line_edit.editingFinished.connect(
            self._refresh_rosgraph)
        self._widget.filter_line_edit.setCompleter(completer)
        self.topic_completionmodel = NamespaceCompletionModel(
            self._widget.topic_filter_line_edit, False)
        topic_completer = RepeatedWordCompleter(self.topic_completionmodel,
                                                self)
        topic_completer.setCompletionMode(QCompleter.PopupCompletion)
        topic_completer.setWrapAround(True)
        topic_completer.setCaseSensitivity(Qt.CaseInsensitive)
        self._widget.topic_filter_line_edit.editingFinished.connect(
            self._refresh_rosgraph)
        self._widget.topic_filter_line_edit.setCompleter(topic_completer)

        self._widget.namespace_cluster_check_box.clicked.connect(
            self._refresh_rosgraph)
        self._widget.watchlist_check_box.clicked.connect(
            self._refresh_rosgraph)
        self._widget.all_advertisements_check_box.clicked.connect(
            self._refresh_rosgraph)

        self._widget.highlight_connections_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.fit_in_view_push_button.setIcon(
            QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._widget.load_dot_push_button.setIcon(
            QIcon.fromTheme('document-open'))
        self._widget.load_dot_push_button.pressed.connect(self._load_dot)
        self._widget.save_dot_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_dot_push_button.pressed.connect(self._save_dot)
        self._widget.save_as_svg_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(
            QIcon.fromTheme('image'))
        self._widget.save_as_image_push_button.pressed.connect(
            self._save_image)

        self._update_gateway_graph()
        self._deferred_fit_in_view.connect(self._fit_in_view,
                                           Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()
        context.add_widget(self._widget)
Beispiel #19
0
 def test_get_graph(self):
     fac = PydotFactory()
     g = fac.get_graph()
     self.assertEqual('same', g.get_rank())
     self.assertEqual('digraph', g.get_graph_type())
#!/usr/bin/env python
#
# License: BSD
#   https://raw.github.com/robotics-in-concert/rocon_concert/license/LICENSE
###############################################################################
from concert_utilities.conductor_graph import ConductorStateDotcodeGenerator
from concert_conductor import StateTransitionTable
from qt_dotgraph.pydotfactory import PydotFactory

if __name__ == '__main__':

    dotcode_factory = PydotFactory()

    csdg = ConductorStateDotcodeGenerator(dotcode_factory)
    dotgraph = csdg.generate_dotgraph(StateTransitionTable)

    dotgraph.write_png('state_graph.png') 
Beispiel #21
0
def generate_dotcode_from_capability_info(spec_index, running_providers):
    dotcode_factory = PydotFactory()
    dotgraph = dotcode_factory.get_graph(rankdir="BT")
    interface_graphs = {}
    # Draw plain interfaces
    for name in spec_index.interfaces:
        providers = [
            k for k, v in spec_index.providers.items() if v.implements == name
        ]
        # Only create a subgraph if it has providers
        if providers:
            interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(
                dotgraph, str(name) + "_group", subgraphlabel='')
        # Draw box for interface
        graph = interface_graphs.get(name, dotgraph)
        dotcode_factory.add_node_to_graph(graph,
                                          nodename=str(name),
                                          shape="box")
    # Draw semantic interfaces
    for name, interface in spec_index.semantic_interfaces.items():
        providers = [
            k for k, v in spec_index.providers.items() if v.implements == name
        ]
        # Only create a subgraph if it has providers
        if providers:
            interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(
                dotgraph, str(name) + "_group", subgraphlabel='')
        graph = interface_graphs.get(name, dotgraph)
        # Draw box for semantic interface
        dotcode_factory.add_node_to_graph(graph,
                                          nodename=str(name),
                                          shape="box")
        # Make edge to interface it redefines, if it exists
        if interface.redefines in spec_index.interfaces:
            dotcode_factory.add_edge_to_graph(dotgraph,
                                              str(name),
                                              str(interface.redefines),
                                              label="redefines")
    # Draw providers
    interfaces = dict(spec_index.interfaces)
    interfaces.update(spec_index.semantic_interfaces)
    for name, provider in spec_index.providers.items():
        # Get subgraph of interface this provider implements
        graph = interface_graphs[provider.implements]
        # Get the default provider for the interface this provider implements
        default_provider = interfaces[provider.implements].default_provider
        provider_name = name
        # Add annotaion if this is the default provider
        if default_provider != 'unknown' and default_provider == name:
            provider_name += "  (default)"
        # If it is running, make it green
        if name in running_providers:
            dotcode_factory.add_node_to_graph(graph,
                                              nodename=str(name),
                                              nodelabel=str(provider_name),
                                              shape="ellipse",
                                              color="green")
        # Else no color
        else:
            dotcode_factory.add_node_to_graph(graph,
                                              nodename=str(name),
                                              nodelabel=str(provider_name),
                                              shape="ellipse")
        # Add edges to the interface, provider paris this provider depends on
        for dep, relationship in provider.dependencies.items():
            if relationship.preferred_provider is not None:
                dotcode_factory.add_edge_to_graph(
                    dotgraph,
                    str(name),
                    str(relationship.preferred_provider),
                    label="requires")
            elif spec_index.interfaces[
                    relationship.
                    capability_name].default_provider != 'unknown':
                dotcode_factory.add_edge_to_graph(
                    dotgraph,
                    str(name),
                    str(spec_index.interfaces[
                        relationship.capability_name].default_provider),
                    label="requires")
    return dotcode_factory.create_dot(dotgraph)
Beispiel #22
0
    def __init__(self, context):
        super(RosGraph, self).__init__(context)
        self.initialized = False
        self.setObjectName('RosGraph')

        self._graph = None
        self._current_dotcode = None

        self._widget = QWidget()

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        # generator builds rosgraph
        self.dotcode_generator = RosGraphDotcodeGenerator()
        # dot_to_qt transforms into Qt elements using dot layout
        self.dot_to_qt = DotToQtGenerator()

        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'RosGraph.ui')
        loadUi(ui_file, self._widget, {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('RosGraphUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._scene.setBackgroundBrush(Qt.white)
        self._widget.graphics_view.setScene(self._scene)

        self._widget.graph_type_combo_box.insertItem(0, self.tr('Nodes only'), NODE_NODE_GRAPH)
        self._widget.graph_type_combo_box.insertItem(1, self.tr('Nodes/Topics (active)'), NODE_TOPIC_GRAPH)
        self._widget.graph_type_combo_box.insertItem(2, self.tr('Nodes/Topics (all)'), NODE_TOPIC_ALL_GRAPH)
        self._widget.graph_type_combo_box.setCurrentIndex(0)
        self._widget.graph_type_combo_box.currentIndexChanged.connect(self._refresh_rosgraph)

        self.node_completionmodel = NamespaceCompletionModel(self._widget.filter_line_edit, False)
        completer = RepeatedWordCompleter(self.node_completionmodel, self)
        completer.setCompletionMode(QCompleter.PopupCompletion)
        completer.setWrapAround(True)
        completer.setCaseSensitivity(Qt.CaseInsensitive)
        self._widget.filter_line_edit.editingFinished.connect(self._refresh_rosgraph)
        self._widget.filter_line_edit.setCompleter(completer)

        self.topic_completionmodel = NamespaceCompletionModel(self._widget.topic_filter_line_edit, False)
        topic_completer = RepeatedWordCompleter(self.topic_completionmodel, self)
        topic_completer.setCompletionMode(QCompleter.PopupCompletion)
        topic_completer.setWrapAround(True)
        topic_completer.setCaseSensitivity(Qt.CaseInsensitive)
        self._widget.topic_filter_line_edit.editingFinished.connect(self._refresh_rosgraph)
        self._widget.topic_filter_line_edit.setCompleter(topic_completer)

        self._widget.namespace_cluster_check_box.clicked.connect(self._refresh_rosgraph)
        self._widget.actionlib_check_box.clicked.connect(self._refresh_rosgraph)
        self._widget.dead_sinks_check_box.clicked.connect(self._refresh_rosgraph)
        self._widget.leaf_topics_check_box.clicked.connect(self._refresh_rosgraph)
        self._widget.quiet_check_box.clicked.connect(self._refresh_rosgraph)

        self._widget.refresh_graph_push_button.setIcon(QIcon.fromTheme('view-refresh'))
        self._widget.refresh_graph_push_button.pressed.connect(self._update_rosgraph)

        self._widget.highlight_connections_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(self._redraw_graph_view)
        self._widget.fit_in_view_push_button.setIcon(QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._widget.load_dot_push_button.setIcon(QIcon.fromTheme('document-open'))
        self._widget.load_dot_push_button.pressed.connect(self._load_dot)
        self._widget.save_dot_push_button.setIcon(QIcon.fromTheme('document-save-as'))
        self._widget.save_dot_push_button.pressed.connect(self._save_dot)
        self._widget.save_as_svg_push_button.setIcon(QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(QIcon.fromTheme('image'))
        self._widget.save_as_image_push_button.pressed.connect(self._save_image)

        self._update_rosgraph()
        self._deferred_fit_in_view.connect(self._fit_in_view, Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()

        context.add_widget(self._widget)