diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index fe8f4a8c43..9b982c4324 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -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; } diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index 75217bd819..101fd4c5f0 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -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. diff --git a/src/rviz/visualizer_app.cpp b/src/rviz/visualizer_app.cpp index 6ad77d7b58..3f44283a76 100644 --- a/src/rviz/visualizer_app.cpp +++ b/src/rviz/visualizer_app.cpp @@ -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); @@ -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)); diff --git a/src/rviz/visualizer_app.h b/src/rviz/visualizer_app.h index aa68c2f7f1..3700435630 100644 --- a/src/rviz/visualizer_app.h +++ b/src/rviz/visualizer_app.h @@ -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_; @@ -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_; };