Skip to content

Commit

Permalink
Merge branch 'master' into cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jaagut authored Jan 30, 2024
2 parents 8bf5c9c + 3a64080 commit 024352b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ def __init__(self, node: Node, debug_topic: str):
self._cached_dotgraph: Optional[pydot.Dot] = None

# Subscribe to the DSDs tree (latched)
dsd_tree_topic = f"{debug_topic}/dsd_tree"
self.tree_sub = self._node.create_subscription(
String,
f"{debug_topic}/dsd_tree",
dsd_tree_topic,
self._tree_callback,
qos_profile=QoSProfile(depth=10, durability=DurabilityPolicy.TRANSIENT_LOCAL),
)

self._node.get_logger().info(f"Subscribed to {debug_topic}/dsd_tree")
self._node.get_logger().info(f"Subscribed to {dsd_tree_topic}")

# Subscribe to the DSDs stack
self.stack_sub = self._node.create_subscription(String, f"{debug_topic}/dsd_stack", self._stack_callback, 10)
self._node.get_logger().info(f"Subscribed to {debug_topic}/dsd_stack")
dsd_stack_topic = f"{debug_topic}/dsd_stack"
self.stack_sub = self._node.create_subscription(String, dsd_stack_topic, self._stack_callback, 10)
self._node.get_logger().info(f"Subscribed to {dsd_stack_topic}")

def _tree_callback(self, msg):
self._node.get_logger().info("Received tree")
Expand Down Expand Up @@ -158,9 +159,13 @@ def param_string(params: dict) -> str:

# Sanity check
if stack_element is not None:
assert stack_element["type"] == tree_element["type"], "The stack and the tree do not match"
assert (
stack_element["type"] == tree_element["type"]
), f"The stack and the tree do not match (element type mismatch: {stack_element['type']} vs. {tree_element['type']})"
if stack_element["type"] != "sequence":
assert stack_element["name"] == tree_element["name"], "The stack and the tree do not match"
assert (
stack_element["name"] == tree_element["name"]
), f"The stack and the tree do not match (element name mismatch: {stack_element['name']} vs. {tree_element['name']})"

# Initialize parameters of the dot node we are going to create
dot_node_params = {
Expand Down Expand Up @@ -211,9 +216,13 @@ def _stack_to_dotgraph(
"""
# Sanity check
if stack_root is not None:
assert stack_root["type"] == subtree_root["type"], "The stack and the tree do not match"
assert (
stack_root["type"] == subtree_root["type"]
), f"The stack element type and the tree element type do not match ({stack_root['type']} vs. {subtree_root['type']})"
if stack_root["type"] != "sequence":
assert stack_root["name"] == subtree_root["name"], "The stack and the tree do not match"
assert (
stack_root["name"] == subtree_root["name"]
), f"The stack element name and the tree element name do not match ({stack_root['name']} vs. {subtree_root['name']})"

# Generate dot node for the root and mark it as active if it is on the stack
dot_node = DsdFollower._dot_node_from_tree_element(subtree_root, stack_root)
Expand All @@ -224,7 +233,7 @@ def _stack_to_dotgraph(
if "children" in subtree_root and (stack_root is not None or full_tree):
# Go through all children
for activating_result, child in subtree_root["children"].items():
# Get the root of the sub stack if this branch the one which is currently on the stack
# Get the root of the sub stack if this branch of the tree is the one which is currently on the stack
sub_stack_root = None
if (
stack_root is not None
Expand All @@ -244,7 +253,7 @@ def _append_debug_data_to_item(
self, parent_item: QStandardItem, debug_data: Union[dict, list, int, float, str, bool]
):
"""
Append an elements debug_data to a QStandardItem.
Appends debug_data of a given element and its children to a QStandardItem.
:type parent_item: python_qt_binding.QtGui.QStandardItem
:type debug_data: dict or list or int or float or str or bool
Expand Down Expand Up @@ -278,7 +287,7 @@ def to_dotgraph(self, full_tree: bool) -> pydot.Dot:
if self._cached_dotgraph is not None:
return self._cached_dotgraph

self._node.get_logger().info("Generating dotgraph")
self._node.get_logger().debug("Generating dotgraph")

# Check if we received any data yet
if self.stack is None or self.tree is None:
Expand Down Expand Up @@ -350,8 +359,9 @@ def to_q_item_model(self):

def destroy(self):
"""
Cleanup the subscriptions, to we don't receive any more data that we don't need (performance)
Also this allows the garbage collector to delete this object and prevent memory leaks
Cleanup the subscriptions, so we don't receive any more data that we don't need.
This improves the performance.
Also this allows the garbage collector to delete this object and prevent memory leaks.
"""
self._node.destroy_subscription(self.tree_sub)
self._node.destroy_subscription(self.stack_sub)
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ def wheel_event(event):
self._widget.auto_fit_graph_check_box.setChecked(False)
self._widget.graphics_view.__class__.wheelEvent(self._widget.graphics_view, event)

# Call it as well as the original wheelEvent
# Overwrite the original wheelEvent handler
self._widget.graphics_view.wheelEvent = wheel_event

# Add widget to the user interface

context.add_widget(self._widget)

# Start a timer that calls back every 100 ms
Expand Down

0 comments on commit 024352b

Please sign in to comment.