diff --git a/include/openspace/events/event.h b/include/openspace/events/event.h index b5fa2d586f..7471b81b0d 100644 --- a/include/openspace/events/event.h +++ b/include/openspace/events/event.h @@ -77,6 +77,8 @@ struct Event { PointSpacecraft, RenderableEnabled, RenderableDisabled, + CameraPathStarted, + CameraPathFinished, Custom }; constexpr explicit Event(Type type_) : type(type_) {} @@ -520,6 +522,30 @@ struct EventRenderableDisabled : public Event { const tstring node; }; +/** + * This event is created when the a camera path is started + */ +struct EventCameraPathStarted : public Event { + static constexpr Type Type = Event::Type::CameraPathStarted; + + /** + * Creates an instance of an EventCameraPathStarted event. + */ + EventCameraPathStarted(); +}; + +/** + * This event is created when the a camera path is finished + */ +struct EventCameraPathFinished : public Event { + static constexpr Type Type = Event::Type::CameraPathFinished; + + /** + * Creates an instance of an EventCameraPathStarted event. + */ + EventCameraPathFinished(); +}; + /** * A custom event type that can be used in a pinch when no explicit event type is * available. This should only be used in special circumstances and it should be diff --git a/include/openspace/navigation/path.h b/include/openspace/navigation/path.h index 5ec915cae9..4c984dd10c 100644 --- a/include/openspace/navigation/path.h +++ b/include/openspace/navigation/path.h @@ -76,7 +76,7 @@ public: CameraPose traversePath(double dt, float speedScale = 1.f); /** - * Function that can be used to permaturely quit a path ,for example when skipping + * Function that can be used to permaturely quit a path, for example when skipping * to the end */ void quitPath(); diff --git a/src/events/event.cpp b/src/events/event.cpp index f16eae5759..c4a399822b 100644 --- a/src/events/event.cpp +++ b/src/events/event.cpp @@ -179,11 +179,6 @@ void log(int i, const EventPointSpacecraft& e) { )); } -void log(int i, const CustomEvent& e) { - ghoul_assert(e.type == CustomEvent::Type, "Wrong type"); - LINFO(fmt::format("[{}] CustomEvent: {} ({})", i, e.subtype, e.payload)); -} - void log(int i, const EventRenderableEnabled& e) { ghoul_assert(e.type == EventRenderableEnabled::Type, "Wrong type"); LINFO(fmt::format("[{}] EventRenderableEnabled: {}", i, e.node)); @@ -194,6 +189,20 @@ void log(int i, const EventRenderableDisabled& e) { LINFO(fmt::format("[{}] EventRenderableDisabled: {}", i, e.node)); } +void log(int i, const EventCameraPathStarted& e) { + ghoul_assert(e.type == EventCameraPathStarted::Type, "Wrong type"); + LINFO(fmt::format("[{}] EventCameraPathStarted", i)); +} + +void log(int i, const EventCameraPathFinished& e) { + ghoul_assert(e.type == EventCameraPathFinished::Type, "Wrong type"); + LINFO(fmt::format("[{}] EventCameraPathFinished", i)); +} + +void log(int i, const CustomEvent& e) { + ghoul_assert(e.type == CustomEvent::Type, "Wrong type"); + LINFO(fmt::format("[{}] CustomEvent: {} ({})", i, e.subtype, e.payload)); +} std::string_view toString(Event::Type type) { switch (type) { @@ -217,6 +226,8 @@ std::string_view toString(Event::Type type) { case Event::Type::PointSpacecraft: return "PointSpacecraft"; case Event::Type::RenderableEnabled: return "RenderableEnabled"; case Event::Type::RenderableDisabled: return "RenderableDisabled"; + case Event::Type::CameraPathStarted: return "CameraPathStarted"; + case Event::Type::CameraPathFinished: return "CameraPathFinished"; case Event::Type::Custom: return "Custom"; default: throw ghoul::MissingCaseException(); @@ -281,6 +292,12 @@ Event::Type fromString(std::string_view str) { else if (str == "RenderableDisabled") { return Event::Type::RenderableDisabled; } + else if (str == "CameraPathStarted") { + return Event::Type::CameraPathStarted; + } + else if (str == "CameraPathFinished") { + return Event::Type::CameraPathFinished; + } else if (str == "Custom") { return Event::Type::Custom; } @@ -534,6 +551,12 @@ void logAllEvents(const Event* e) { case Event::Type::RenderableDisabled: log(i, *static_cast(e)); break; + case Event::Type::CameraPathStarted: + log(i, *static_cast(e)); + break; + case Event::Type::CameraPathFinished: + log(i, *static_cast(e)); + break; case Event::Type::Custom: log(i, *static_cast(e)); break; @@ -662,6 +685,13 @@ EventRenderableDisabled::EventRenderableDisabled(const SceneGraphNode* node_) , node(temporaryString(node_->identifier())) {} +EventCameraPathStarted::EventCameraPathStarted() + : Event(Type) +{} + +EventCameraPathFinished::EventCameraPathFinished() + : Event(Type) +{} CustomEvent::CustomEvent(std::string_view subtype_, std::string_view payload_) : Event(Type) diff --git a/src/navigation/pathnavigator.cpp b/src/navigation/pathnavigator.cpp index b8a6bd2fbe..bcd04e8103 100644 --- a/src/navigation/pathnavigator.cpp +++ b/src/navigation/pathnavigator.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,6 @@ #include #include #include - #include "pathnavigator_lua.inl" namespace { @@ -300,7 +300,8 @@ void PathNavigator::startPath() { return; } - if (!global::openSpaceEngine->setMode(OpenSpaceEngine::Mode::CameraPath)) { + bool success = global::openSpaceEngine->setMode(OpenSpaceEngine::Mode::CameraPath); + if (!success) { LERROR("Could not start camera path"); return; // couldn't switch to camera path mode } @@ -323,6 +324,7 @@ void PathNavigator::startPath() { global::navigationHandler->orbitalNavigator().updateOnCameraInteraction(); global::navigationHandler->orbitalNavigator().resetVelocities(); + global::eventEngine->publishEvent(); } void PathNavigator::abortPath() { @@ -453,6 +455,8 @@ void PathNavigator::handlePathEnd() { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } + + global::eventEngine->publishEvent(); } void PathNavigator::findRelevantNodes() {