Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recursive subgraph parsing, box3d shape, graphics items now immediately parented #87

Merged
merged 7 commits into from
Nov 3, 2017

Conversation

EliteMasterEric
Copy link
Contributor

This commit includes several features:

  • Added recursive subgraph parsing for nodes and edges (required for namespace nesting in rqt_graph)
  • Added QGraphicsBox3dItem to render nodes as a 'box3d' dot shape. Group nodes (such as /action_topics in rqt_graph) should use this shape to represent that multiple nodes are being rendered as one.
  • Graphics items now immediately parented to provided scene to prevent a crash bug. Scene defaults to none for compatibility.

@dirk-thomas
Copy link
Contributor

With #72 being merged can you please update this PR to be based on the current default branch. Thank you.

@EliteMasterEric
Copy link
Contributor Author

@fmauch, it appears we implemented recursive subgraph parsing in parallel with each other. Since your implementation is a bit cleaner, I fixed my code to use yours, and both the unit test and my pull request for rqt_graph are functioning correctly with these changes.

I'd like for you and @dirk-thomas to look at my pull request as it is now and provide feedback as necessary.

return node_item

def addEdgeItem(self, edge, nodes, edges, highlight_level, same_label_siblings=False):
def addEdgeItem(self, edge, nodes, edges, highlight_level, scene=None, same_label_siblings=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the new keyword argument scene at the end of the signature. That will avoid breaking any code using the current signature without specifying the keyword explicitly.

Same below for dotcode_to_qt_items.

return nodes, edges

def parse_nodes(self, graph, highlight_level):
def parse_nodes(self, graph, highlight_level, scene):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the new argument be an optional keyword argument (for the same compatibility reason mentioned above).

All callers should pass the keyword argument by explicitly passing the keyword.

Same for parse_edges below.

@@ -127,6 +127,7 @@ def __init__(self, highlight_level, spline, label_center, label, from_node, to_n
self._arrow.setAcceptHoverEvents(True)

self._path = QGraphicsPathItem()
self._path = QGraphicsPathItem(parent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the line before be removed?

elif shape == 'box3d':
self._graphics_item = QGraphicsBox3dItem(bounding_box)
else:
#raise ValueError("Invalid shape '"+shape+"'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the commented code line.

self._graphics_item = QGraphicsBox3dItem(bounding_box)
else:
#raise ValueError("Invalid shape '"+shape+"'")
print("Invalid shape '"+shape+"', defaulting to ellipse")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use print("Invalid shape '%s', defaulting to ellipse" % shape).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also print the error message to stderr:

print('...', file=sys.stderr)

This will require the following at the top of the file:

from __future__ import print_function

import sys

painter.drawLine(self._bounding_box.topRight().x(),
self._bounding_box.topRight().y(),
self._bounding_box.topRight().x(),
self._bounding_box.bottomRight().y() - self._bounding_box.height() * 0.1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use four space indentation and a newline at the end of the file to match the code style of the existing code.

@EliteMasterEric
Copy link
Contributor Author

@dirk-thomas I have made the requested changes. I'll start work on splitting the related ros-visualization/rqt_graph#9

@dirk-thomas
Copy link
Contributor

dirk-thomas commented Oct 9, 2017

@mastereric This comment is still pending.

@EliteMasterEric
Copy link
Contributor Author

@dirk-thomas Sorry for the delay in resolving the issues in your comment. The changes have been completed, please review them when you have time.

Copy link
Contributor

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside a few nitpicks this looks good to be merged.

@@ -0,0 +1,44 @@
from python_qt_binding.QtCore import QRectF
from python_qt_binding.QtGui import QColor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import not used.

rectangle = QRectF(self._bounding_box.topLeft().x(),
self._bounding_box.topLeft().y() + self._bounding_box.height() * 0.1,
self._bounding_box.width() - self._bounding_box.height() * 0.1,
self._bounding_box.height() - self._bounding_box.height() * 0.1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation doesn't align with parenthesis.

"""Recursively searches all nodes inside the graph and all subgraphs."""
# let pydot imitate pygraphviz api
graph.nodes_iter = graph.get_node_list
graph.subgraphs_iter = graph.get_subgraph_list

nodes = {}
edges = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigned but never used?

@@ -75,6 +77,17 @@ def __init__(self, highlight_level, bounding_box, label, shape, color=None, pare

self.hovershape = None

def parse_shape(self, shape, bounding_box):
if shape == 'box' or shape == 'rect' or shape == 'rectangle':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead: if shape in ('box', 'rect', 'rectangle'):

Similar below.

@EliteMasterEric
Copy link
Contributor Author

Hey @dirk-thomas,
Thank you for the work you've done in reviewing this code! Having someone else look at a pull request is really helpful in finding the oversights and unused variables from older iterations of code.

I've posted revisions to your latest set of nitpicks, and hope this code can be merged soon. After that, I'll look into pushing these revisions to lunar-devel as well.

P.S. It was cool meeting you back at ROSCon 2017!

self._graphics_item = QGraphicsRectItem(bounding_box)
elif shape in ('ellipse', 'oval', 'circle'):
self._graphics_item = QGraphicsEllipseItem(bounding_box)
elif shape in ('box3d'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit tricky. With a single item in the parenthesis Python doesn't interpret that as a list. So share='box' would match. It needs to be: elif shape in ('box3d', ):. I will apply the change directly.

@dirk-thomas
Copy link
Contributor

I've posted revisions to your latest set of nitpicks, and hope this code can be merged soon.

I just committed a minor logic fix in 8180a48 Once CI has passed I will merge this. Thank you for your effort on this nice feature!

After that, I'll look into pushing these revisions to lunar-devel as well.

This repo doesn't have a Lunar-specific branch. Kinetic and Lunar are using the same code from the kinetic-devel branch. So once this is merged I can make a release into Kinetic and Lunar.

For the pending PR downstream you might want to make sure to add a minimum version for the dependency on qt_dotgraph. The upcoming release will be version 0.3.8. That will make sure that when users update the plugin requiring the changes here are also getting the latest version of qt_dotgraph.

P.S. It was cool meeting you back at ROSCon 2017!

It is always great to add a face to the GitHub username 😉

@dirk-thomas dirk-thomas merged commit 363d837 into ros-visualization:kinetic-devel Nov 3, 2017
@EliteMasterEric
Copy link
Contributor Author

After that, I'll look into pushing these revisions to lunar-devel as well.

Looks like I misread one of your comments; the changes here need to be backported (to a new branch ros-visualization/qt_gui_core:indigo-devel), not forward-ported, right?

@dirk-thomas
Copy link
Contributor

Oh right, since the plugin using this actually has a single branch across all ROS distros. The only downside is that we won't be able to specify a version dependency then since qt_dotgraph has different versions in Indigo and Kinetic.

@EliteMasterEric
Copy link
Contributor Author

Specifying a version dependency seems important, since the new version of rqt_graph depends on this new version of qt_gui_core.

Could we branch the current repo from where the last indigo version was made and create an indigo-devel branch? This makes sense; because indigo uses a different version of qt, it needs a different codebase. Kinetic and Lunar can stay together.

@dirk-thomas
Copy link
Contributor

The branch in this repo used for Indigo is groovy-devel. If you port this patch to that branch we can release new minor versions to make sure that both the release for Indigo as well as Kinetic and Lunar are higher than what was available before. If we rev Indigo from 0.2.32 to 0.4.0 we can actually use a version dependency >= 0.3.8 (which is the version from the Kinetic branch). That numbering is not very intuitive but should work.

As a next step it would be good if you create a branch from the groovy-devel branch, cherry-pick the change from this PR (363d837), and then add additional commits to it to make it work with Qt 4. That PR can then be merged and we can make a new Indigo release (with the weird version increment).

@EliteMasterEric
Copy link
Contributor Author

@dirk-thomas Sorry for the delay in this, I cherry picked my commit to the groovy-devel branch as a new pull request #108.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants