It's been a while since I did this (or even looked at the code), but I created a tool that I load/unload programmatically for a corresponding custom Display
. Something to be aware of is that the tool currently in use is system-wide, so loading/unloading needs to be handled appropriately.
In a Panel
, you can access the ToolManager
from the protected VisualizationManager
member:
ToolManager* toolManager = vis_manager_->tool_manager_;
See the ToolManager API for further functionality. Note that this is for Indigo; things may be different for other ROS versions.
Edit: given the ToolManager*
(I'll call it tMan
for brevity) and tool class name (tClassName
), loading is:
tMan->addTool(tClassName);
Assume you have a reference to a Tool* tool
; to make it the active tool:
tMan->setCurrentTool(tool);
That will take care of switching tools for you; unloading a tool is akin to removing it from the tool panel (which you likely don't need to do).
Note that actually bookkeeping the tools is a pain. As far as I know, you need to use the class name; something like:
Tool* curTool = tMan->getCurrentTool();
if (curTool && curTool->getClassId() == tClassName) {
...
}
But just doing tMan->setCurrentTool(tool)
will deactivate the old and activate the new. Hope that helps some.