Show error message when trying to save navigation state to an invalid file path (closes #2508)

This commit is contained in:
Alexander Bock
2023-03-07 00:05:31 +01:00
parent a711591c09
commit 1aef976911
2 changed files with 14 additions and 8 deletions

View File

@@ -140,7 +140,7 @@ public:
NavigationState navigationState() const;
NavigationState navigationState(const SceneGraphNode& referenceFrame) const;
void saveNavigationState(const std::string& filepath,
void saveNavigationState(const std::filesystem::path& filepath,
const std::string& referenceFrameIdentifier);
void loadNavigationState(const std::string& filepath);

View File

@@ -442,9 +442,11 @@ NavigationState NavigationHandler::navigationState(
);
}
void NavigationHandler::saveNavigationState(const std::string& filepath,
void NavigationHandler::saveNavigationState(const std::filesystem::path& filepath,
const std::string& referenceFrameIdentifier)
{
ghoul_precondition(!filepath.empty(), "File path must not be empty");
NavigationState state;
if (!referenceFrameIdentifier.empty()) {
const SceneGraphNode* referenceFrame = sceneGraphNode(referenceFrameIdentifier);
@@ -461,14 +463,18 @@ void NavigationHandler::saveNavigationState(const std::string& filepath,
state = navigationState();
}
if (!filepath.empty()) {
std::filesystem::path absolutePath = absPath(filepath);
LINFO(fmt::format("Saving camera position: {}", absolutePath));
std::filesystem::path absolutePath = absPath(filepath);
LINFO(fmt::format("Saving camera position: {}", absolutePath));
std::ofstream ofs(absolutePath);
ofs << "return " << ghoul::formatLua(state.dictionary());
ofs.close();
std::ofstream ofs(absolutePath);
if (!ofs.good()) {
throw ghoul::RuntimeError(fmt::format(
"Error saving navigation state to {}", filepath
));
}
ofs << "return " << ghoul::formatLua(state.dictionary());
}
void NavigationHandler::loadNavigationState(const std::string& filepath) {