Skip to content

Commit

Permalink
Add service load_config_discarding_changes (#1710)
Browse files Browse the repository at this point in the history
... to allow loading a new config without saving existing changes
  • Loading branch information
FSund authored Feb 6, 2022
1 parent 62ba5cd commit 34d4aea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ void VisualizationFrame::loadDisplayConfig(const QString& qpath)
loadDisplayConfigHelper(actual_load_path.string());
}

bool VisualizationFrame::loadDisplayConfigHelper(const std::string& full_path)
bool VisualizationFrame::loadDisplayConfigHelper(const std::string& full_path, const bool discard_changes)
{
// Check if we have unsaved changes to the current config the same
// as we do during exit, with the same option to cancel.
if (!prepareToExit())
if (!discard_changes && !prepareToExit())
{
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/rviz/visualization_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ class RVIZ_EXPORT VisualizationFrame : public QMainWindow, public WindowManagerI
void loadDisplayConfig(const QString& path);

/** @brief Load display and other settings from the given full file path.
* @param full_path The (absolute) path to the config file to load
* @param discard_changes Flag indicating whether to discard any unsaved config changes
* @return True on success, False on failure. */
bool loadDisplayConfigHelper(const std::string& full_path);
bool loadDisplayConfigHelper(const std::string& full_path, const bool discard_changes = false);

/** @brief Save display and other settings to the given file.
* @param path The full path of the config file to save into.
Expand Down
16 changes: 16 additions & 0 deletions src/rviz/visualizer_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ bool VisualizerApp::init(int argc, char** argv)

load_config_service_ =
private_nh.advertiseService("load_config", &VisualizerApp::loadConfigCallback, this);
load_config_discarding_service_ = private_nh.advertiseService(
"load_config_discarding_changes", &VisualizerApp::loadConfigDiscardingCallback, this);
save_config_service_ =
private_nh.advertiseService("save_config", &VisualizerApp::saveConfigCallback, this);

Expand Down Expand Up @@ -277,6 +279,20 @@ bool VisualizerApp::loadConfigCallback(rviz::SendFilePathRequest& req, rviz::Sen
return true;
}

bool VisualizerApp::loadConfigDiscardingCallback(rviz::SendFilePathRequest& req,
rviz::SendFilePathResponse& res)
{
fs::path path = req.path.data;
if (fs::is_regular_file(path))
{
bool discard_changes = true;
res.success = frame_->loadDisplayConfigHelper(path.string(), discard_changes);
}
else
res.success = false;
return true;
}

bool VisualizerApp::saveConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res)
{
res.success = frame_->saveDisplayConfig(QString::fromStdString(req.path.data));
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/visualizer_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private Q_SLOTS:
private:
void startContinueChecker();
bool loadConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res);
bool loadConfigDiscardingCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res);
bool saveConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res);

QApplication* app_;
Expand All @@ -72,6 +73,7 @@ private Q_SLOTS:
ros::NodeHandlePtr nh_;
ros::ServiceServer reload_shaders_service_;
ros::ServiceServer load_config_service_;
ros::ServiceServer load_config_discarding_service_;
ros::ServiceServer save_config_service_;
};

Expand Down

0 comments on commit 34d4aea

Please sign in to comment.