Skip to content

Commit

Permalink
Rviz config saving and loading fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mukhaaza committed Nov 16, 2023
1 parent cd2cb8d commit 95a4e6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "control/overlay_picker_tool.h"
#include "control/im_server.h"

#include <rviz/display_group.h>

namespace mrs_rviz_plugins{

class ControlTool : public rviz::SelectionTool{
Expand All @@ -39,6 +41,7 @@ class ControlTool : public rviz::SelectionTool{
void deactivate() override;
int processMouseEvent(rviz::ViewportMouseEvent& event) override;
int processKeyEvent(QKeyEvent* event, rviz::RenderPanel* panel) override;
rviz::InteractiveMarkerDisplay* findDisplay(rviz::Property* property);

protected:
// Check if the mouse has moved from one object to another,
Expand Down
29 changes: 26 additions & 3 deletions src/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,36 @@ void ControlTool::onInitialize(){
rviz::SelectionTool::onInitialize();
overlay_picker_tool->initialize(context_);

dis = new rviz::InteractiveMarkerDisplay();
dynamic_cast<rviz::VisualizationManager*>(context_)->addDisplay(dis, true);
dis = findDisplay(context_->getRootDisplayGroup());
if(dis == NULL){
dis = new rviz::InteractiveMarkerDisplay();
dynamic_cast<rviz::VisualizationManager*>(context_)->addDisplay(dis, true);
dis->setName(QString("Control Display"));
dis->setClassId("rviz/InteractiveMarkers");
}

dis->setName(QString("Control Display"));
dis->setTopic(QString("control/update"), QString("visualization_msgs/InteractiveMarkerUpdate"));
}

rviz::InteractiveMarkerDisplay* ControlTool::findDisplay(rviz::Property* property){
if(overlay_picker_tool->isPropertyType<rviz::DisplayGroup>(property)){
rviz::DisplayGroup* group_property = overlay_picker_tool->isPropertyType<rviz::DisplayGroup>(property);
for (int i = 0; i < group_property->numChildren(); i++) {
rviz::InteractiveMarkerDisplay* res = findDisplay(group_property->childAt(i));
if (res) {
return res;
}
}
}
else{
rviz::InteractiveMarkerDisplay* im_display = overlay_picker_tool->isPropertyType<rviz::InteractiveMarkerDisplay>(property);
if(im_display && im_display->getName() == "Control Display"){
return im_display;
}
}
return NULL;
}

void ControlTool::activate(){
rviz::SelectionTool::activate();
setStatus(DEFAULT_MODE_MESSAGE);
Expand Down

0 comments on commit 95a4e6b

Please sign in to comment.