mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Show error message when trying to save navigation state to an invalid file path (closes #2508)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user