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

Add service load_config_discard_changes #1710

Merged
10 changes: 7 additions & 3 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,17 @@ 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)
{
return false;
if (!prepareToExit())
FSund marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}
}

setWindowModified(false);
Expand Down
5 changes: 4 additions & 1 deletion src/rviz/visualization_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ 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 full path of the config file to load from.
* @param discard_changes Discard changes to current config
FSund marked this conversation as resolved.
Show resolved Hide resolved
* @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
15 changes: 15 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_discard_changes_service_ =
private_nh.advertiseService("load_config_discard_changes", &VisualizerApp::loadConfigDiscardChangesCallback, this);
FSund marked this conversation as resolved.
Show resolved Hide resolved
save_config_service_ =
private_nh.advertiseService("save_config", &VisualizerApp::saveConfigCallback, this);

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

bool VisualizerApp::loadConfigDiscardChangesCallback(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 loadConfigDiscardChangesCallback(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_discard_changes_service_;
ros::ServiceServer save_config_service_;
};

Expand Down