rqt_ros_graph.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 # Author: Isaac Saito
34 
35 from __future__ import division
36 
37 from python_qt_binding.QtCore import Qt
38 import rospy
39 
40 
41 class RqtRosGraph(object):
42 
43  DELIM_GRN = '/'
44 
45  @staticmethod
46  def get_full_grn(model_index):
47  """
48  @deprecated: Not completed.
49 
50  Create full path format of GRN (Graph Resource Names, see
51  http://www.ros.org/wiki/Names). Build GRN by recursively transcending
52  parents & children of a given QModelIndex instance.
53 
54  A complete example of GRN: /wide_stereo/left/image_color/compressed
55 
56  Upon its very 1st call, the argument is the index where user clicks on
57  on the view object (here QTreeView is used but should work with other
58  View too. Not tested yet though). str_grn can be 0-length string.
59 
60  :type model_index: QModelIndex
61  :type str_grn: str
62  :param str_grn: This could be an incomplete or a complete GRN format.
63  :rtype: str
64  """
65 
66  children_grn_list = RqtRosGraph.get_lower_grn_dfs(model_index)
67  parent_data = model_index.data()
68  rospy.logdebug('parent_data={}'.format(parent_data))
69  if parent_data == None: # model_index is 1st-order node of a tree.
70  upper_grn = RqtRosGraph.get_upper_grn(model_index, '')
71  grn_list = []
72  for child_grn in children_grn_list:
73  grn_full = upper_grn + child_grn
74  rospy.logdebug('grn_full={} upper_grn={} child_grn={}'.format(
75  grn_full, upper_grn, child_grn))
76  grn_list.append(grn_full)
77  else:
78  grn_list = children_grn_list
79 
80  # Create a string where namespace is delimited by slash.
81  grn = ''
82  for s in grn_list:
83  grn += RqtRosGraph.DELIM_GRN + s
84 
85  return grn
86 
87  @staticmethod
88  def get_lower_grn_dfs(model_index, grn_prev=''):
89  """
90  Traverse all children treenodes and returns a list of "partial"
91  GRNs. Partial means that this method returns names under current level.
92 
93  Ex. Consider a tree like this:
94 
95  Root
96  |--TopitemA
97  | |--1
98  | |--2
99  | |--3
100  | |--4
101  | |--5
102  | |--6
103  | |--7
104  |--TopitemB
105 
106  Re-formatted in GRN (omitting root):
107 
108  TopitemA/1/2/3/4
109  TopitemA/1/2/3/5/6
110  TopitemA/1/2/3/5/7
111  TopitemB
112 
113  Might not be obvious from tree representation but there are 4 nodes as
114  GRN form suggests.
115 
116  (doc from here TBD)
117 
118  :type model_index: QModelIndex
119  :type grn_prev: str
120  :rtype: str[]
121  """
122  i_child = 0
123  list_grn_children_all = []
124  while True: # Loop per child.
125  grn_curr = grn_prev + RqtRosGraph.DELIM_GRN + \
126  str(model_index.data())
127  child_qmindex = model_index.child(i_child, 0)
128 
129  if (not child_qmindex.isValid()):
130  rospy.logdebug('!! DEADEND i_child=#{} grn_curr={}'.format(
131  i_child, grn_curr))
132  if i_child == 0:
133  # Only when the current node has no children, add current
134  # GRN to the returning list.
135  list_grn_children_all.append(grn_curr)
136  return list_grn_children_all
137 
138  rospy.logdebug('Child#{} grn_curr={}'.format(i_child, grn_curr))
139 
140  list_grn_children = RqtRosGraph.get_lower_grn_dfs(child_qmindex,
141  grn_curr)
142  for child_grn in list_grn_children:
143  child_grn = (grn_prev +
144  (RqtRosGraph.DELIM_GRN + grn_curr) +
145  (RqtRosGraph.DELIM_GRN + child_grn))
146 
147  list_grn_children_all = list_grn_children_all + list_grn_children
148  rospy.logdebug('111 lennodes={} list_grn_children={}'.format(
149  len(list_grn_children_all), list_grn_children))
150  rospy.logdebug('122 list_grn_children_all={}'.format(
151  list_grn_children_all))
152  i_child += 1
153  return list_grn_children_all
154 
155  @staticmethod
156  def get_upper_grn(model_index, str_grn):
157  if model_index.data(Qt.DisplayRole) == None:
158  return str_grn
159  str_grn = (RqtRosGraph.DELIM_GRN +
160  str(model_index.data(Qt.DisplayRole)) +
161  str_grn)
162  rospy.logdebug('get_full_grn_recur out str=%s', str_grn)
163  return RqtRosGraph.get_upper_grn(model_index.parent(), str_grn)
def get_lower_grn_dfs(model_index, grn_prev='')
def get_upper_grn(model_index, str_grn)


rqt_py_common
Author(s): Dorian Scholz , Isaac Saito, Dirk Thomas
autogenerated on Mon May 16 2022 02:49:40