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

Tool: Propagate name changes to VisualizationFrame #1570

Conversation

jcmonteiro
Copy link
Contributor

Description

With this PR the tool parameters will be available when onInitialize is called. One can use this feature to solve #1138 by adding
an rviz::StringProperty, e.g. named Tool Name, and then use its value to rename the tool in onInitialize.

@rhaschke
Copy link
Contributor

I'm not sure about the purpose of this PR yet. Isn't it common practice to first initialize an object (display, panel, tool, ...) and later load its parameters? I don't like the idea of coupling the loading to the creation of a tool. Regarding #1138: I guess you can always call setName() on your tool, can't you?

@jcmonteiro
Copy link
Contributor Author

jcmonteiro commented Dec 17, 2020

Isn't it common practice to first initialize an object (display, panel, tool, ...) and later load its parameters?

Hmm.. I'm not quite sure. After all, the initialization might depend on the parameters. What would be the downside of having the parameters available in onInitialize?

Regarding #1138: I guess you can always call setName() on your tool, can't you?

Calling setName has no effect after onInitialize. At least it has no effect when called in activate. Besides, activate takes place only when the tool is clicked, so even if it worked there the name would only change to the correct one once the tool had been clicked.

@rhaschke
Copy link
Contributor

After all, the initialization might depend on the parameters.

It shouldn't. It's always possible to load a different config later. However, the initialization should always work.

Calling setName has no effect after onInitialize.

I don't see why this should be the case. Currently, setName() is called just shortly before initialize():

tool->setName(addSpaceToCamelCase(factory_->getClassName(class_id)));
tool->setIcon(factory_->getIcon(class_id));
tool->initialize(context_);

@jcmonteiro
Copy link
Contributor Author

It shouldn't. It's always possible to load a different config later. However, the initialization should always work.

I see... I did some more digging in the code and the issue is the following with setName and setIcon: they have no effect on the menu entries because they are created only once per tool in

void VisualizationFrame::addTool(Tool* tool)
{
QAction* action = new QAction(tool->getName(), toolbar_actions_);
action->setIcon(tool->getIcon());
action->setIconText(tool->getName());
action->setCheckable(true);
toolbar_->insertAction(add_tool_action_, action);
action_to_tool_map_[action] = tool;
tool_to_action_map_[tool] = action;
remove_tool_menu_->addAction(tool->getName());
}

From what you explained about the initialization, I believe that the proper solution to #1138 is to change the setName and setIcon methods so that they force a reload of the action and update the member variables action_to_tool_map_, tool_to_action_map_, toolbar_, and remove_tool_menu_ from VisualizationFrame. After doing so, calling setName or setIcon from an overloaded load method should do the trick. What do you think?

@rhaschke
Copy link
Contributor

That sounds reasonable. Would it be sufficient to change the name? I think, having the same icons for the same tool, would facilitate its identification. I suggest introducing a signal nameChanged(), such that the VisFrame is informed about name changes.

@jcmonteiro
Copy link
Contributor Author

Completely agree. I'll do it then.

@jcmonteiro jcmonteiro force-pushed the feature/tool/expose-parameter-on-initialization branch from 462d717 to c4f109e Compare December 17, 2020 15:29
@jcmonteiro
Copy link
Contributor Author

I've force-pushed the changes. Calling setName now updates the toolbar and this PR solves #1138.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution. In general, this looks good. Some minor remarks though.

src/rviz/tool.cpp Show resolved Hide resolved
src/rviz/tool.h Outdated Show resolved Hide resolved
src/rviz/visualization_frame.cpp Outdated Show resolved Hide resolved
src/rviz/visualization_frame.h Outdated Show resolved Hide resolved
@jcmonteiro jcmonteiro force-pushed the feature/tool/expose-parameter-on-initialization branch from c4f109e to a0446c9 Compare December 18, 2020 08:16
@jcmonteiro
Copy link
Contributor Author

Great suggestions! I've force-pushed again to meet them.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Two more nitpicks. Otherwise looks good. Thanks.

src/rviz/visualization_frame.cpp Outdated Show resolved Hide resolved
src/rviz/visualization_frame.h Outdated Show resolved Hide resolved
@jcmonteiro jcmonteiro force-pushed the feature/tool/expose-parameter-on-initialization branch from a0446c9 to a1ad870 Compare December 18, 2020 14:30
@jcmonteiro
Copy link
Contributor Author

Two more nitpicks. Otherwise looks good. Thanks.

That's completely understandable 👍. I've pushed the changes.

@rhaschke rhaschke merged commit f59a2ea into ros-visualization:melodic-devel Dec 18, 2020
@rhaschke rhaschke changed the title [tool] load parameters before initializing Tool: Propagate name changes to VisualizationFrame Dec 18, 2020
@rhaschke
Copy link
Contributor

Thanks a lot.

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

Successfully merging this pull request may close these issues.

2 participants