From 5fc5ce318ac23df455d591747836c97b7d9baade Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Apr 2022 16:05:56 +0200 Subject: [PATCH] Set default values for starting time and start camera (closes #1981) --- include/openspace/util/time.h | 4 ++-- src/engine/openspaceengine.cpp | 8 +++++++- src/util/timemanager.cpp | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 624833e546..02f22e3fda 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -144,14 +144,14 @@ public: /** * Sets a relative time from profile. */ - void setTimeRelativeFromProfile(const std::string& setTime); + static void setTimeRelativeFromProfile(const std::string& setTime); /** * Sets an absolute time from profile. * \param setTime a string containing time to set, which must be a valid * ISO 8601-like date string of the format YYYY-MM-DDTHH:MN:SS */ - void setTimeAbsoluteFromProfile(const std::string& setTime); + static void setTimeAbsoluteFromProfile(const std::string& setTime); /** * Returns the Lua library that contains all Lua functions available to change the diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 1918a1bc68..365e22a358 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1659,8 +1659,14 @@ void OpenSpaceEngine::removeModeChangeCallback(CallbackHandle handle) { void setCameraFromProfile(const Profile& p) { if (!p.camera.has_value()) { - throw ghoul::RuntimeError("No 'camera' entry exists in the startup profile"); + // If the camera is not specified, we want to set it to a sensible default value + interaction::NavigationState nav; + nav.anchor = "Root"; + nav.referenceFrame = "Root"; + global::navigationHandler->setNavigationStateNextFrame(nav); + return; } + std::visit( overloaded{ [](const Profile::CameraNavState& navStateProfile) { diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index 1af38c1529..aa4f9867f7 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -896,24 +896,24 @@ bool TimeManager::isPlayingBackSessionRecording() const { } void TimeManager::setTimeFromProfile(const Profile& p) { - Time t; - if (p.time.has_value()) { switch (p.time.value().type) { - case Profile::Time::Type::Relative: - t.setTimeRelativeFromProfile(p.time.value().value); - break; + case Profile::Time::Type::Relative: + Time::setTimeRelativeFromProfile(p.time.value().value); + break; - case Profile::Time::Type::Absolute: - t.setTimeAbsoluteFromProfile(p.time.value().value); - break; + case Profile::Time::Type::Absolute: + Time::setTimeAbsoluteFromProfile(p.time.value().value); + break; - default: - throw ghoul::MissingCaseException(); + default: + throw ghoul::MissingCaseException(); } } else { - throw ghoul::RuntimeError("No 'time' entry exists in the startup profile"); + // No value was specified so we are using 'now' instead + std::string now = std::string(Time::now().UTC()); + Time::setTimeAbsoluteFromProfile(now); } }