From 157df5ff93fedee94c141a6a4bc4592776867db3 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 08:55:30 +0200 Subject: [PATCH 1/8] Clean-up: Include delta time steps in time topic --- modules/server/CMakeLists.txt | 2 - .../include/topics/deltatimestepstopic.h | 57 -------- modules/server/src/connection.cpp | 3 - .../server/src/topics/deltatimestepstopic.cpp | 127 ------------------ modules/server/src/topics/timetopic.cpp | 19 ++- 5 files changed, 18 insertions(+), 190 deletions(-) delete mode 100644 modules/server/include/topics/deltatimestepstopic.h delete mode 100644 modules/server/src/topics/deltatimestepstopic.cpp diff --git a/modules/server/CMakeLists.txt b/modules/server/CMakeLists.txt index 723fc24295..c39537163d 100644 --- a/modules/server/CMakeLists.txt +++ b/modules/server/CMakeLists.txt @@ -33,7 +33,6 @@ set(HEADER_FILES include/serverinterface.h include/topics/authorizationtopic.h include/topics/bouncetopic.h - include/topics/deltatimestepstopic.h include/topics/documentationtopic.h include/topics/flightcontrollertopic.h include/topics/getpropertytopic.h @@ -57,7 +56,6 @@ set(SOURCE_FILES src/serverinterface.cpp src/topics/authorizationtopic.cpp src/topics/bouncetopic.cpp - src/topics/deltatimestepstopic.cpp src/topics/documentationtopic.cpp src/topics/flightcontrollertopic.cpp src/topics/getpropertytopic.cpp diff --git a/modules/server/include/topics/deltatimestepstopic.h b/modules/server/include/topics/deltatimestepstopic.h deleted file mode 100644 index 6b06999151..0000000000 --- a/modules/server/include/topics/deltatimestepstopic.h +++ /dev/null @@ -1,57 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ -#define __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ - -#include -#include - -namespace openspace { - -class DeltaTimeStepsTopic : public Topic { -public: - DeltaTimeStepsTopic(); - virtual ~DeltaTimeStepsTopic(); - - void handleJson(const nlohmann::json& json) override; - bool isDone() const override; - -private: - const int UnsetOnChangeHandle = -1; - - bool dataHasChanged(); - void sendDeltaTimesData(); - - int _deltaTimeCallbackHandle = UnsetOnChangeHandle; - int _deltaTimesListCallbackHandle = UnsetOnChangeHandle; - bool _isDone = false; - - std::optional _lastNextDeltaTime = std::nullopt; - std::optional _lastPrevDeltaTime = std::nullopt; -}; - -} // namespace openspace - -#endif // __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index f45595788b..89cb02a96c 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -57,7 +56,6 @@ namespace { constexpr const char* VersionTopicKey = "version"; constexpr const char* AuthenticationTopicKey = "authorize"; - constexpr const char* DeltaTimeStepsTopicKey = "deltatimesteps"; constexpr const char* DocumentationTopicKey = "documentation"; constexpr const char* GetPropertyTopicKey = "get"; constexpr const char* LuaScriptTopicKey = "luascript"; @@ -97,7 +95,6 @@ Connection::Connection(std::unique_ptr s, ); _topicFactory.registerClass(DocumentationTopicKey); - _topicFactory.registerClass(DeltaTimeStepsTopicKey); _topicFactory.registerClass(GetPropertyTopicKey); _topicFactory.registerClass(LuaScriptTopicKey); _topicFactory.registerClass(SessionRecordingTopicKey); diff --git a/modules/server/src/topics/deltatimestepstopic.cpp b/modules/server/src/topics/deltatimestepstopic.cpp deleted file mode 100644 index 1399825f59..0000000000 --- a/modules/server/src/topics/deltatimestepstopic.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#include "modules/server/include/topics/deltatimestepstopic.h" - -#include -#include -#include -#include -#include -#include - -namespace { - constexpr const char* EventKey = "event"; - constexpr const char* SubscribeEvent = "start_subscription"; - constexpr const char* UnsubscribeEvent = "stop_subscription"; -} // namespace - -using nlohmann::json; - -namespace openspace { - -DeltaTimeStepsTopic::DeltaTimeStepsTopic() {} - -DeltaTimeStepsTopic::~DeltaTimeStepsTopic() { - if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) { - global::timeManager.removeDeltaTimeChangeCallback( - _deltaTimeCallbackHandle - ); - } - if (_deltaTimesListCallbackHandle != UnsetOnChangeHandle) { - global::timeManager.removeDeltaTimeStepsChangeCallback( - _deltaTimesListCallbackHandle - ); - } -} - -bool DeltaTimeStepsTopic::isDone() const { - return _isDone; -} - -bool DeltaTimeStepsTopic::dataHasChanged() { - std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - return (nextStep != _lastNextDeltaTime || prevStep != _lastPrevDeltaTime); -} - -void DeltaTimeStepsTopic::handleJson(const nlohmann::json& json) { - std::string event = json.at(EventKey).get(); - if (event == UnsubscribeEvent) { - _isDone = true; - return; - } - - sendDeltaTimesData(); - - if (event != SubscribeEvent) { - _isDone = true; - return; - } - - _deltaTimeCallbackHandle = global::timeManager.addDeltaTimeChangeCallback( - [this]() { - if (dataHasChanged()) { - sendDeltaTimesData(); - } - } - ); - - _deltaTimesListCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback( - [this]() { - if (dataHasChanged()) { - sendDeltaTimesData(); - } - } - ); -} - -void DeltaTimeStepsTopic::sendDeltaTimesData() { - std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - bool hasNext = nextStep.has_value(); - bool hasPrev = prevStep.has_value(); - - json deltaTimesListJson = { - { "hasNextStep", hasNext }, - { "hasPrevStep", hasPrev } - }; - - if (hasNext) { - deltaTimesListJson["nextStep"] = nextStep.value(); - } - - if (hasPrev) { - deltaTimesListJson["prevStep"] = prevStep.value(); - } - - _connection->sendJson(wrappedPayload(deltaTimesListJson)); - - _lastNextDeltaTime = nextStep; - _lastPrevDeltaTime = prevStep; -} - -} // namespace openspace diff --git a/modules/server/src/topics/timetopic.cpp b/modules/server/src/topics/timetopic.cpp index 789b9da924..e092a3bbaf 100644 --- a/modules/server/src/topics/timetopic.cpp +++ b/modules/server/src/topics/timetopic.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace { constexpr const char* EventKey = "event"; @@ -110,13 +111,29 @@ void TimeTopic::sendFullTimeData() { const double targetDeltaTime = global::timeManager.targetDeltaTime(); const bool isPaused = global::timeManager.isPaused(); - const json timeJson = { + std::optional nextStep = global::timeManager.nextDeltaTimeStep(); + std::optional prevStep = global::timeManager.previousDeltaTimeStep(); + + bool hasNext = nextStep.has_value(); + bool hasPrev = prevStep.has_value(); + + json timeJson = { { "time", currentTime }, { "deltaTime", deltaTime}, { "targetDeltaTime", targetDeltaTime}, { "isPaused", isPaused }, + { "hasNextStep", hasNext }, + { "hasPrevStep", hasPrev } }; + if (hasNext) { + timeJson["nextStep"] = nextStep.value(); + } + + if (hasPrev) { + timeJson["prevStep"] = prevStep.value(); + } + _connection->sendJson(wrappedPayload(timeJson)); _lastUpdateTime = std::chrono::system_clock::now(); _lastPauseState = isPaused; From 64b23e172abd37f8a6a1b22c29c6917fa700bdc9 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 10:11:58 +0200 Subject: [PATCH 2/8] Include delta time steps in time topic In case anyone wants to create a GUI that contains the delta time steps --- modules/server/include/topics/timetopic.h | 3 ++ modules/server/src/topics/timetopic.cpp | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/modules/server/include/topics/timetopic.h b/modules/server/include/topics/timetopic.h index 23b6c486c4..451b4c9ae9 100644 --- a/modules/server/include/topics/timetopic.h +++ b/modules/server/include/topics/timetopic.h @@ -43,14 +43,17 @@ private: void sendCurrentTime(); void sendFullTimeData(); + void sendDeltaTimeSteps(); int _timeCallbackHandle = UnsetOnChangeHandle; int _deltaTimeCallbackHandle = UnsetOnChangeHandle; + int _deltaTimeStepsCallbackHandle = UnsetOnChangeHandle; bool _isDone = false; std::chrono::system_clock::time_point _lastUpdateTime; bool _lastPauseState = false; double _lastTargetDeltaTime = 0.0; + std::vector _lastDeltaTimeSteps; }; } // namespace openspace diff --git a/modules/server/src/topics/timetopic.cpp b/modules/server/src/topics/timetopic.cpp index e092a3bbaf..9d2f21a94b 100644 --- a/modules/server/src/topics/timetopic.cpp +++ b/modules/server/src/topics/timetopic.cpp @@ -54,6 +54,9 @@ TimeTopic::~TimeTopic() { if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) { global::timeManager.removeDeltaTimeChangeCallback(_deltaTimeCallbackHandle); } + if (_deltaTimeStepsCallbackHandle != UnsetOnChangeHandle) { + global::timeManager.removeDeltaTimeStepsChangeCallback(_deltaTimeStepsCallbackHandle); + } } bool TimeTopic::isDone() const { @@ -68,6 +71,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) { } sendFullTimeData(); + sendDeltaTimeSteps(); if (event != SubscribeEvent) { _isDone = true; @@ -95,6 +99,15 @@ void TimeTopic::handleJson(const nlohmann::json& json) { sendFullTimeData(); } }); + + _deltaTimeStepsCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback( + [this]() { + const std::vector steps = global::timeManager.deltaTimeSteps(); + if (steps != _lastDeltaTimeSteps) { + sendDeltaTimeSteps(); + } + } + ); } void TimeTopic::sendCurrentTime() { @@ -140,4 +153,30 @@ void TimeTopic::sendFullTimeData() { _lastTargetDeltaTime = targetDeltaTime; } +void TimeTopic::sendDeltaTimeSteps() { + const std::vector steps = global::timeManager.deltaTimeSteps(); + const std::optional nextStep = global::timeManager.nextDeltaTimeStep(); + const std::optional prevStep = global::timeManager.previousDeltaTimeStep(); + + const bool hasNext = nextStep.has_value(); + const bool hasPrev = prevStep.has_value(); + + json deltaTimeStepsJson = { + { "deltaTimeSteps", steps }, + { "hasNextStep", hasNext }, + { "hasPrevStep", hasPrev } + }; + + if (hasNext) { + deltaTimeStepsJson["nextStep"] = nextStep.value(); + } + + if (hasPrev) { + deltaTimeStepsJson["prevStep"] = prevStep.value(); + } + + _connection->sendJson(wrappedPayload(deltaTimeStepsJson)); + _lastDeltaTimeSteps = steps; +} + } // namespace openspace From fe13ff7e48b5c9830d440d53afa5558e8c7497a7 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 10:42:41 +0200 Subject: [PATCH 3/8] Some cleanup --- modules/server/include/topics/timetopic.h | 2 + modules/server/src/topics/timetopic.cpp | 59 +++++++++++------------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/modules/server/include/topics/timetopic.h b/modules/server/include/topics/timetopic.h index 451b4c9ae9..2d66dc9f69 100644 --- a/modules/server/include/topics/timetopic.h +++ b/modules/server/include/topics/timetopic.h @@ -41,6 +41,8 @@ public: private: const int UnsetOnChangeHandle = -1; + nlohmann::json getNextPrevDeltaTimeStepJson(); + void sendCurrentTime(); void sendFullTimeData(); void sendDeltaTimeSteps(); diff --git a/modules/server/src/topics/timetopic.cpp b/modules/server/src/topics/timetopic.cpp index 9d2f21a94b..bfb3f2ea76 100644 --- a/modules/server/src/topics/timetopic.cpp +++ b/modules/server/src/topics/timetopic.cpp @@ -110,6 +110,28 @@ void TimeTopic::handleJson(const nlohmann::json& json) { ); } +json TimeTopic::getNextPrevDeltaTimeStepJson() { + const std::optional nextStep = global::timeManager.nextDeltaTimeStep(); + const std::optional prevStep = global::timeManager.previousDeltaTimeStep(); + const bool hasNext = nextStep.has_value(); + const bool hasPrev = prevStep.has_value(); + + json nextPrevJson = { + { "hasNextStep", hasNext }, + { "hasPrevStep", hasPrev } + }; + + if (hasNext) { + nextPrevJson["nextStep"] = nextStep.value(); + } + + if (hasPrev) { + nextPrevJson["prevStep"] = prevStep.value(); + } + + return nextPrevJson; +} + void TimeTopic::sendCurrentTime() { const json timeJson = { { "time", global::timeManager.time().ISO8601() } @@ -124,28 +146,15 @@ void TimeTopic::sendFullTimeData() { const double targetDeltaTime = global::timeManager.targetDeltaTime(); const bool isPaused = global::timeManager.isPaused(); - std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - bool hasNext = nextStep.has_value(); - bool hasPrev = prevStep.has_value(); - json timeJson = { { "time", currentTime }, { "deltaTime", deltaTime}, { "targetDeltaTime", targetDeltaTime}, - { "isPaused", isPaused }, - { "hasNextStep", hasNext }, - { "hasPrevStep", hasPrev } + { "isPaused", isPaused } }; - if (hasNext) { - timeJson["nextStep"] = nextStep.value(); - } - - if (hasPrev) { - timeJson["prevStep"] = prevStep.value(); - } + json nextPrevJson = getNextPrevDeltaTimeStepJson(); + timeJson.insert(nextPrevJson.begin(), nextPrevJson.end()); _connection->sendJson(wrappedPayload(timeJson)); _lastUpdateTime = std::chrono::system_clock::now(); @@ -155,25 +164,13 @@ void TimeTopic::sendFullTimeData() { void TimeTopic::sendDeltaTimeSteps() { const std::vector steps = global::timeManager.deltaTimeSteps(); - const std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - const std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - const bool hasNext = nextStep.has_value(); - const bool hasPrev = prevStep.has_value(); json deltaTimeStepsJson = { - { "deltaTimeSteps", steps }, - { "hasNextStep", hasNext }, - { "hasPrevStep", hasPrev } + { "deltaTimeSteps", steps } }; - if (hasNext) { - deltaTimeStepsJson["nextStep"] = nextStep.value(); - } - - if (hasPrev) { - deltaTimeStepsJson["prevStep"] = prevStep.value(); - } + json nextPrevJson = getNextPrevDeltaTimeStepJson(); + deltaTimeStepsJson.insert(nextPrevJson.begin(), nextPrevJson.end()); _connection->sendJson(wrappedPayload(deltaTimeStepsJson)); _lastDeltaTimeSteps = steps; From 63a61b3cbab409dbc89bcec7fd072cbade8a9b15 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 11:04:14 +0200 Subject: [PATCH 4/8] Tiny cleanup (const is good) --- modules/server/include/topics/timetopic.h | 2 +- modules/server/src/topics/timetopic.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/server/include/topics/timetopic.h b/modules/server/include/topics/timetopic.h index 2d66dc9f69..99493055cd 100644 --- a/modules/server/include/topics/timetopic.h +++ b/modules/server/include/topics/timetopic.h @@ -41,7 +41,7 @@ public: private: const int UnsetOnChangeHandle = -1; - nlohmann::json getNextPrevDeltaTimeStepJson(); + const nlohmann::json getNextPrevDeltaTimeStepJson(); void sendCurrentTime(); void sendFullTimeData(); diff --git a/modules/server/src/topics/timetopic.cpp b/modules/server/src/topics/timetopic.cpp index bfb3f2ea76..b5db345ef9 100644 --- a/modules/server/src/topics/timetopic.cpp +++ b/modules/server/src/topics/timetopic.cpp @@ -110,7 +110,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) { ); } -json TimeTopic::getNextPrevDeltaTimeStepJson() { +const json TimeTopic::getNextPrevDeltaTimeStepJson() { const std::optional nextStep = global::timeManager.nextDeltaTimeStep(); const std::optional prevStep = global::timeManager.previousDeltaTimeStep(); const bool hasNext = nextStep.has_value(); @@ -153,7 +153,7 @@ void TimeTopic::sendFullTimeData() { { "isPaused", isPaused } }; - json nextPrevJson = getNextPrevDeltaTimeStepJson(); + const json nextPrevJson = getNextPrevDeltaTimeStepJson(); timeJson.insert(nextPrevJson.begin(), nextPrevJson.end()); _connection->sendJson(wrappedPayload(timeJson)); @@ -163,13 +163,13 @@ void TimeTopic::sendFullTimeData() { } void TimeTopic::sendDeltaTimeSteps() { - const std::vector steps = global::timeManager.deltaTimeSteps(); + const std::vector& steps = global::timeManager.deltaTimeSteps(); json deltaTimeStepsJson = { { "deltaTimeSteps", steps } }; - json nextPrevJson = getNextPrevDeltaTimeStepJson(); + const json nextPrevJson = getNextPrevDeltaTimeStepJson(); deltaTimeStepsJson.insert(nextPrevJson.begin(), nextPrevJson.end()); _connection->sendJson(wrappedPayload(deltaTimeStepsJson)); From 19c110a4c245fdf3a02ded613fd81e03f3b57561 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 13:08:54 +0200 Subject: [PATCH 5/8] Update gui hash --- data/assets/util/webgui.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 27209f9080..ecdb0faae0 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "6673d083bf2629502ce7f809610509f29ad444b7" +local frontendHash = "e520f14d3fffc915b7b900f4fc6d888070f458c4" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ From d0508be631b7385dd2a55d465cd951fce4ea622d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 30 Aug 2020 22:00:13 +0200 Subject: [PATCH 6/8] First commit --- apps/OpenSpace/ext/sgct | 2 +- apps/OpenSpace/main.cpp | 11 +++++------ ext/ghoul | 2 +- include/openspace/util/screenlog.h | 4 ++-- modules/server/src/connection.cpp | 2 +- modules/sync/syncmodule.cpp | 4 ++-- src/engine/openspaceengine.cpp | 5 +---- src/rendering/luaconsole.cpp | 2 +- src/util/screenlog.cpp | 6 +++--- 9 files changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index b712e64848..76062e74a1 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit b712e6484894d70a60277bdcf719613b217954a7 +Subproject commit 76062e74a19e8b5238058ae81b0c2507ffadf0b2 diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 80e5ff01cb..3e96e60ef2 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -678,22 +678,21 @@ void mainDecodeFun(const std::vector& data, unsigned int) { -void mainLogCallback(Log::Level level, const char* message) { +void mainLogCallback(Log::Level level, std::string_view message) { ZoneScoped - std::string msg = message; switch (level) { case Log::Level::Debug: - LDEBUGC("SGCT", msg); + LDEBUGC("SGCT", message); break; case Log::Level::Info: - LINFOC("SGCT", msg); + LINFOC("SGCT", message); break; case Log::Level::Warning: - LWARNINGC("SGCT", msg); + LWARNINGC("SGCT", message); break; case Log::Level::Error: - LERRORC("SGCT", msg); + LERRORC("SGCT", message); break; } diff --git a/ext/ghoul b/ext/ghoul index bd812defd7..77ce270021 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit bd812defd787ad34119cfe7ecef2be71a7a1553e +Subproject commit 77ce2700218c3f21e6dfefb67553bd646058ff0a diff --git a/include/openspace/util/screenlog.h b/include/openspace/util/screenlog.h index c6ded67ff1..8c496ff57f 100644 --- a/include/openspace/util/screenlog.h +++ b/include/openspace/util/screenlog.h @@ -91,8 +91,8 @@ public: * \param category The category of the log message * \param message The actual log message that was transmitted */ - void log(ghoul::logging::LogLevel level, const std::string& category, - const std::string& message) override; + void log(ghoul::logging::LogLevel level, std::string_view category, + std::string_view message) override; /** * This method removes all the stored LogEntry%s that have expired, calculated by diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index 89cb02a96c..e845ad1d9d 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -85,7 +85,7 @@ Connection::Connection(std::unique_ptr s, AuthenticationTopicKey, [password](bool, const ghoul::Dictionary&, ghoul::MemoryPoolBase* pool) { if (pool) { - void* ptr = pool->alloc(sizeof(AuthorizationTopic)); + void* ptr = pool->allocate(sizeof(AuthorizationTopic)); return new (ptr) AuthorizationTopic(password); } else { diff --git a/modules/sync/syncmodule.cpp b/modules/sync/syncmodule.cpp index 582b7f2146..dc48ce9632 100644 --- a/modules/sync/syncmodule.cpp +++ b/modules/sync/syncmodule.cpp @@ -80,7 +80,7 @@ void SyncModule::internalInitialize(const ghoul::Dictionary& configuration) { "HttpSynchronization", [this](bool, const ghoul::Dictionary& dictionary, ghoul::MemoryPoolBase* pool) { if (pool) { - void* ptr = pool->alloc(sizeof(HttpSynchronization)); + void* ptr = pool->allocate(sizeof(HttpSynchronization)); return new (ptr) HttpSynchronization( dictionary, _synchronizationRoot, @@ -101,7 +101,7 @@ void SyncModule::internalInitialize(const ghoul::Dictionary& configuration) { "UrlSynchronization", [this](bool, const ghoul::Dictionary& dictionary, ghoul::MemoryPoolBase* pool) { if (pool) { - void* ptr = pool->alloc(sizeof(UrlSynchronization)); + void* ptr = pool->allocate(sizeof(UrlSynchronization)); return new (ptr) UrlSynchronization( dictionary, _synchronizationRoot diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index b3beab370e..a2f5d2ef89 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -994,10 +994,7 @@ void OpenSpaceEngine::loadFonts() { } try { - bool initSuccess = ghoul::fontrendering::FontRenderer::initialize(); - if (!initSuccess) { - LERROR("Error initializing default font renderer"); - } + ghoul::fontrendering::FontRenderer::initialize(); } catch (const ghoul::RuntimeError& err) { LERRORC(err.component, err.message); diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 20a302f976..97eee2f20e 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -687,7 +687,7 @@ void LuaConsole::render() { // Since the overflow is positive, at least one character needs to be removed. const size_t nCharsOverflow = static_cast(std::min( - std::max(1.f, overflow / _font->glyph('m')->width()), + std::max(1.f, overflow / _font->glyph('m')->width), static_cast(currentCommand.size()) )); diff --git a/src/util/screenlog.cpp b/src/util/screenlog.cpp index c5ff3f67e2..e5c865278b 100644 --- a/src/util/screenlog.cpp +++ b/src/util/screenlog.cpp @@ -48,15 +48,15 @@ void ScreenLog::removeExpiredEntries() { _entries.erase(rit, _entries.end() ); } -void ScreenLog::log(LogLevel level, const string& category, const string& message) { +void ScreenLog::log(LogLevel level, std::string_view category, std::string_view message) { std::lock_guard guard(_mutex); if (level >= _logLevel) { _entries.push_back({ level, std::chrono::steady_clock::now(), Log::timeString(), - category, - message + std::string(category), + std::string(message) }); } } From 7e06f310eb156479c374e80ee2fe173a34cddca4 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 1 Sep 2020 01:18:17 +0200 Subject: [PATCH 7/8] Update submodules Remove warnings and MSVC analyzer information messages --- apps/OpenSpace/ext/sgct | 2 +- ext/ghoul | 2 +- include/openspace/network/messagestructures.h | 169 ++++++------------ modules/server/src/connection.cpp | 2 +- .../src/topics/flightcontrollertopic.cpp | 2 - .../dashboard/dashboarditeminstruments.cpp | 1 - modules/webbrowser/include/cefhost.h | 9 + modules/webbrowser/src/cefhost.cpp | 1 - 8 files changed, 68 insertions(+), 120 deletions(-) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 76062e74a1..3d3835c38c 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 76062e74a19e8b5238058ae81b0c2507ffadf0b2 +Subproject commit 3d3835c38c8b87972f406ed44af1b5b2d48b1600 diff --git a/ext/ghoul b/ext/ghoul index 77ce270021..d18c7bb1fb 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 77ce2700218c3f21e6dfefb67553bd646058ff0a +Subproject commit d18c7bb1fb9ad05421f0b9ed7022ab0c214407ae diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index 06fe7841ee..e344a95255 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -40,18 +40,18 @@ enum class Type : uint32_t { }; struct CameraKeyframe { - CameraKeyframe() {} - CameraKeyframe(const std::vector &buffer) { + CameraKeyframe() = default; + CameraKeyframe(const std::vector& buffer) { deserialize(buffer); } glm::dvec3 _position = glm::dvec3(0.0); glm::dquat _rotation = glm::dquat(1.0, 0.0, 0.0, 0.0); - bool _followNodeRotation; + bool _followNodeRotation = false; std::string _focusNode; - float _scale; + float _scale = 0.f; - double _timestamp; + double _timestamp = 0.0; void serialize(std::vector &buffer) const { // Add position @@ -104,28 +104,28 @@ struct CameraKeyframe { ); }; - size_t deserialize(const std::vector &buffer, size_t offset = 0) { + size_t deserialize(const std::vector& buffer, size_t offset = 0) { int size = 0; // Position size = sizeof(_position); - memcpy(&_position, buffer.data() + offset, size); + std::memcpy(&_position, buffer.data() + offset, size); offset += size; // Orientation size = sizeof(_rotation); - memcpy(&_rotation, buffer.data() + offset, size); + std::memcpy(&_rotation, buffer.data() + offset, size); offset += size; // Follow focus node rotation? size = sizeof(_followNodeRotation); - memcpy(&_followNodeRotation, buffer.data() + offset, size); + std::memcpy(&_followNodeRotation, buffer.data() + offset, size); offset += size; // Focus node int nodeNameLength; size = sizeof(int); - memcpy(&nodeNameLength, buffer.data() + offset, size); + std::memcpy(&nodeNameLength, buffer.data() + offset, size); offset += size; size = nodeNameLength; _focusNode = std::string(buffer.data() + offset, buffer.data() + offset + size); @@ -133,29 +133,20 @@ struct CameraKeyframe { // Scale size = sizeof(_scale); - memcpy(&_scale, buffer.data() + offset, size); + std::memcpy(&_scale, buffer.data() + offset, size); offset += size; // Timestamp size = sizeof(_timestamp); - memcpy(&_timestamp, buffer.data() + offset, size); + std::memcpy(&_timestamp, buffer.data() + offset, size); offset += size; return offset; }; void write(std::ostream& out) const { - // Write position - out.write( - reinterpret_cast(&_position), - sizeof(_position) - ); - - // Write orientation - out.write( - reinterpret_cast(&_rotation), - sizeof(_rotation) - ); + out.write(reinterpret_cast(&_position), sizeof(_position)); + out.write(reinterpret_cast(&_rotation), sizeof(_rotation)); // Write follow focus node rotation? out.write( @@ -166,88 +157,58 @@ struct CameraKeyframe { int nodeNameLength = static_cast(_focusNode.size()); // Write focus node - out.write( - reinterpret_cast(&nodeNameLength), - sizeof(nodeNameLength) - ); - out.write( - _focusNode.c_str(), - _focusNode.size() - ); + out.write(reinterpret_cast(&nodeNameLength), sizeof(nodeNameLength)); + out.write(_focusNode.c_str(), _focusNode.size()); - //Write scale - out.write( - reinterpret_cast(&_scale), - sizeof(_scale) - ); + // Write scale + out.write(reinterpret_cast(&_scale), sizeof(_scale)); // Write timestamp - out.write( - reinterpret_cast(&_timestamp), - sizeof(_timestamp) - ); + out.write(reinterpret_cast(&_timestamp), sizeof(_timestamp)); }; void read(std::istream* in) { // Read position - in->read( - reinterpret_cast(&_position), - sizeof(_position) - ); + in->read(reinterpret_cast(&_position), sizeof(_position)); // Read orientation - in->read( - reinterpret_cast(&_rotation), - sizeof(_rotation) - ); + in->read(reinterpret_cast(&_rotation), sizeof(_rotation)); // Read follow focus node rotation unsigned char b; - in->read( - reinterpret_cast(&b), - sizeof(unsigned char) - ); + in->read(reinterpret_cast(&b), sizeof(unsigned char)); _followNodeRotation = (b == 1); // Read focus node int nodeNameLength = static_cast(_focusNode.size()); - in->read( - reinterpret_cast(&nodeNameLength), - sizeof(nodeNameLength) - ); - std::vector temp(nodeNameLength + 1); + in->read(reinterpret_cast(&nodeNameLength), sizeof(nodeNameLength)); + std::vector temp(static_cast(nodeNameLength) + 1); in->read(temp.data(), nodeNameLength); temp[nodeNameLength] = '\0'; _focusNode = temp.data(); // Read scale - in->read( - reinterpret_cast(&_scale), - sizeof(_scale) - ); + in->read(reinterpret_cast(&_scale), sizeof(_scale)); // Read timestamp - in->read( - reinterpret_cast(&_timestamp), - sizeof(_timestamp) - ); + in->read(reinterpret_cast(&_timestamp), sizeof(_timestamp)); }; }; struct TimeKeyframe { - TimeKeyframe() {} - TimeKeyframe(const std::vector &buffer) { + TimeKeyframe() = default; + TimeKeyframe(const std::vector& buffer) { deserialize(buffer); } - double _time; - double _dt; - bool _paused; - bool _requiresTimeJump; - double _timestamp; + double _time = 0.0; + double _dt = 0.0; + bool _paused = false; + bool _requiresTimeJump = false; + double _timestamp = 0.0; - void serialize(std::vector &buffer) const { + void serialize(std::vector& buffer) const { buffer.insert( buffer.end(), reinterpret_cast(this), @@ -255,37 +216,31 @@ struct TimeKeyframe { ); }; - size_t deserialize(const std::vector &buffer, size_t offset = 0){ + size_t deserialize(const std::vector& buffer, size_t offset = 0) { *this = *reinterpret_cast(buffer.data() + offset); offset += sizeof(TimeKeyframe); return offset; }; void write(std::ostream* out) const { - out->write( - reinterpret_cast(this), - sizeof(TimeKeyframe) - ); + out->write(reinterpret_cast(this), sizeof(TimeKeyframe)); }; void read(std::istream* in) { - in->read( - reinterpret_cast(this), - sizeof(TimeKeyframe) - ); + in->read(reinterpret_cast(this), sizeof(TimeKeyframe)); }; }; struct TimeTimeline { - TimeTimeline() {} - TimeTimeline(const std::vector &buffer) { + TimeTimeline() = default; + TimeTimeline(const std::vector& buffer) { deserialize(buffer); } bool _clear = true; std::vector _keyframes; - void serialize(std::vector &buffer) const { + void serialize(std::vector& buffer) const { buffer.insert( buffer.end(), reinterpret_cast(&_clear), @@ -298,77 +253,65 @@ struct TimeTimeline { reinterpret_cast(&nKeyframes), reinterpret_cast(&nKeyframes) + sizeof(int64_t) ); - for (const auto& k : _keyframes) { + for (const TimeKeyframe& k : _keyframes) { k.serialize(buffer); } }; - size_t deserialize(const std::vector &buffer, size_t offset = 0) { + size_t deserialize(const std::vector& buffer, size_t offset = 0) { int size = 0; size = sizeof(_clear); - memcpy(&_clear, buffer.data() + offset, size); + std::memcpy(&_clear, buffer.data() + offset, size); offset += size; int64_t nKeyframes = _keyframes.size(); size = sizeof(nKeyframes); - memcpy(&nKeyframes, buffer.data() + offset, size); + std::memcpy(&nKeyframes, buffer.data() + offset, size); offset += size; _keyframes.resize(nKeyframes); - for (auto& k : _keyframes) { + for (TimeKeyframe& k : _keyframes) { offset = k.deserialize(buffer, offset); } return offset; }; void write(std::ostream* out) const { - out->write( - reinterpret_cast(&_clear), - sizeof(bool) - ); + out->write(reinterpret_cast(&_clear), sizeof(bool)); int64_t nKeyframes = _keyframes.size(); - out->write( - reinterpret_cast(&nKeyframes), - sizeof(int64_t) - ); - for (const auto& k : _keyframes) { + out->write(reinterpret_cast(&nKeyframes), sizeof(int64_t)); + for (const TimeKeyframe& k : _keyframes) { k.write(out); } }; void read(std::istream* in) { - in->read( - reinterpret_cast(&_clear), - sizeof(bool) - ); + in->read(reinterpret_cast(&_clear), sizeof(bool)); int64_t nKeyframes = _keyframes.size(); - in->read( - reinterpret_cast(&nKeyframes), - sizeof(int64_t) - ); - for (auto& k : _keyframes) { + in->read(reinterpret_cast(&nKeyframes), sizeof(int64_t)); + for (TimeKeyframe& k : _keyframes) { k.read(in); } }; }; struct ScriptMessage { - ScriptMessage() {} - ScriptMessage(const std::vector &buffer) { + ScriptMessage() = default; + ScriptMessage(const std::vector& buffer) { deserialize(buffer); } std::string _script; - double _timestamp; + double _timestamp = 0.0; - void serialize(std::vector &buffer) const { + void serialize(std::vector& buffer) const { buffer.insert(buffer.end(), _script.begin(), _script.end()); }; - void deserialize(const std::vector &buffer) { + void deserialize(const std::vector& buffer) { _script.assign(buffer.begin(), buffer.end()); }; diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index e845ad1d9d..1b918297cc 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -139,7 +139,7 @@ void Connection::handleMessage(const std::string& message) { message.end(), sanitizedString.begin(), [](wchar_t c) { - return std::isprint(c, std::locale("")) ? c : ' '; + return std::isprint(c, std::locale("")) ? char(c) : ' '; } ); LERROR(fmt::format("Could not parse JSON: '{}'", sanitizedString)); diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index 3e2289c5a5..372c5c43ff 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -303,12 +303,10 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const { fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j) ); if (json.find(AimKey) == json.end()) { - const std::string j = json; LWARNING( fmt::format("Could not find {} key in JSON. JSON was:\n{}", AimKey, j) ); if (json.find(AnchorKey) == json.end()) { - const std::string j = json; LWARNING(fmt::format( "Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j )); diff --git a/modules/spacecraftinstruments/dashboard/dashboarditeminstruments.cpp b/modules/spacecraftinstruments/dashboard/dashboarditeminstruments.cpp index 84eda4956f..10f84cff4c 100644 --- a/modules/spacecraftinstruments/dashboard/dashboarditeminstruments.cpp +++ b/modules/spacecraftinstruments/dashboard/dashboarditeminstruments.cpp @@ -332,7 +332,6 @@ glm::vec2 DashboardItemInstruments::size() const { if (remaining > 0) { using FR = ghoul::fontrendering::FontRenderer; - FR& renderer = FR::defaultRenderer(); std::string progress = progressToStr(25, t); size = addToBoundingbox( diff --git a/modules/webbrowser/include/cefhost.h b/modules/webbrowser/include/cefhost.h index be15a79f50..3c739e4560 100644 --- a/modules/webbrowser/include/cefhost.h +++ b/modules/webbrowser/include/cefhost.h @@ -25,7 +25,16 @@ #ifndef __OPENSPACE_MODULE_WEBBROWSER___CEF_HOST___H__ #define __OPENSPACE_MODULE_WEBBROWSER___CEF_HOST___H__ +#ifdef WIN32 +#pragma warning(push) +#pragma warning(disable : 4100) +#endif // WIN32 + #include + +#ifdef WIN32 +#pragma warning(pop) +#endif // WIN32 #include struct CefSettingsTraits; diff --git a/modules/webbrowser/src/cefhost.cpp b/modules/webbrowser/src/cefhost.cpp index 21cb448e98..f53463b290 100644 --- a/modules/webbrowser/src/cefhost.cpp +++ b/modules/webbrowser/src/cefhost.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #ifdef __APPLE__ #include From 20d1e391cb5e351a01de331125b86c798d3a5ad4 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 1 Sep 2020 02:27:08 +0200 Subject: [PATCH 8/8] Adding a new ImGui component for explicitly adding GIBS layer --- .../globebrowsing/scripts/layer_support.lua | 10 +- modules/imgui/CMakeLists.txt | 2 + modules/imgui/include/gui.h | 5 +- modules/imgui/include/guigibscomponent.h | 42 ++++++ modules/imgui/src/guigibscomponent.cpp | 134 ++++++++++++++++++ 5 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 modules/imgui/include/guigibscomponent.h create mode 100644 modules/imgui/src/guigibscomponent.cpp diff --git a/modules/globebrowsing/scripts/layer_support.lua b/modules/globebrowsing/scripts/layer_support.lua index f52f8baea0..28b2447d00 100644 --- a/modules/globebrowsing/scripts/layer_support.lua +++ b/modules/globebrowsing/scripts/layer_support.lua @@ -1,11 +1,12 @@ openspace.globebrowsing.documentation = { { Name = "createTemporalGibsGdalXml", - Arguments = "string, string, string, string, string, string", + Arguments = "string, string, string, string, string, string, [string]", Documentation = "Creates an XML configuration for a temporal GIBS dataset." .. "Arguments are: Name, Start date, end date, time resolution, time format," .. - "resolution, file format. For all specifications, see " .. + "resolution, file format. The last parameter is the temporal format and " .. + "defaults to YYYY-MM-DD. For all specifications, see " .. "https://wiki.earthdata.nasa.gov/display/GIBS/GIBS+Available+Imagery+Products" .. "Usage:" .. "openspace.globebrowsing.addLayer(" .. @@ -115,13 +116,14 @@ openspace.globebrowsing.addGibsLayer = function(layer, resolution, format, start openspace.globebrowsing.addLayer('Earth', 'ColorLayers', { Identifier = layer, Type = "TemporalTileLayer", FilePath = xml }) end -openspace.globebrowsing.createTemporalGibsGdalXml = function (layerName, startDate, endDate, timeResolution, resolution, format) +openspace.globebrowsing.createTemporalGibsGdalXml = function (layerName, startDate, endDate, timeResolution, resolution, format, temporalFormat) + temporalFormat = temporalFormat or 'YYYY-MM-DD' temporalTemplate = "" .. "" .. startDate .. "" .. "" .. endDate .. "" .. "" .. timeResolution .. "" .. - "YYYY-MM-DD" .. + "" .. temporalFormat .. "" .. openspace.globebrowsing.createGibsGdalXml(layerName, "${OpenSpaceTimeId}", resolution, format) .. "" return temporalTemplate diff --git a/modules/imgui/CMakeLists.txt b/modules/imgui/CMakeLists.txt index 2809fbbffc..4ea3d8d0d8 100644 --- a/modules/imgui/CMakeLists.txt +++ b/modules/imgui/CMakeLists.txt @@ -31,6 +31,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/guiassetcomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guicomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guifilepathcomponent.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/guigibscomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guiglobebrowsingcomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guihelpcomponent.h ${CMAKE_CURRENT_SOURCE_DIR}/include/guijoystickcomponent.h @@ -51,6 +52,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/guiassetcomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guicomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guifilepathcomponent.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/guigibscomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guiglobebrowsingcomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guihelpcomponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/guijoystickcomponent.cpp diff --git a/modules/imgui/include/gui.h b/modules/imgui/include/gui.h index b9f959d7b6..0ec6ef76cd 100644 --- a/modules/imgui/include/gui.h +++ b/modules/imgui/include/gui.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,7 @@ namespace openspace::gui { namespace detail { constexpr int nComponents() { - const int nRegularComponents = 16; + const int nRegularComponents = 17; int totalComponents = nRegularComponents; #ifdef OPENSPACE_MODULE_ISWA_ENABLED @@ -105,6 +106,7 @@ public: GuiHelpComponent _help; GuiFilePathComponent _filePath; GuiAssetComponent _asset; + GuiGIBSComponent _gibs; GuiGlobeBrowsingComponent _globeBrowsing; GuiPropertyComponent _globalProperty; @@ -144,6 +146,7 @@ private: &_spaceTime, &_mission, &_parallel, + &_gibs, &_globeBrowsing, #ifdef OPENSPACE_MODULE_ISWA_ENABLED &_iswa, diff --git a/modules/imgui/include/guigibscomponent.h b/modules/imgui/include/guigibscomponent.h new file mode 100644 index 0000000000..4f5b13569b --- /dev/null +++ b/modules/imgui/include/guigibscomponent.h @@ -0,0 +1,42 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2020 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_IMGUI___GUIGIBSCOMPONENT___H__ +#define __OPENSPACE_MODULE_IMGUI___GUIGIBSCOMPONENT___H__ + +#include + +#include + +namespace openspace::gui { + +class GuiGIBSComponent : public GuiComponent { +public: + GuiGIBSComponent(); + void render() override; +}; + +} // namespace openspace::gui + +#endif // __OPENSPACE_MODULE_IMGUI___GUIGIBSCOMPONENT___H__ diff --git a/modules/imgui/src/guigibscomponent.cpp b/modules/imgui/src/guigibscomponent.cpp new file mode 100644 index 0000000000..acdde9ea70 --- /dev/null +++ b/modules/imgui/src/guigibscomponent.cpp @@ -0,0 +1,134 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2020 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#pragma optimize ("", off) +namespace { + const ImVec2 WindowSize = ImVec2(350, 500); +} // namespace + +namespace openspace::gui { + +GuiGIBSComponent::GuiGIBSComponent() + : GuiComponent("GIBS", "GIBS") +{} + +void GuiGIBSComponent::render() { + ImGui::SetNextWindowCollapsed(_isCollapsed); + bool e = _isEnabled; + ImGui::Begin("GIBS", &e, WindowSize, 0.5f); + _isEnabled = e; + _isCollapsed = ImGui::IsWindowCollapsed(); + + ImGui::Text("%s", "GIBS Layers"); + ImGui::Text("%s", "Find the information on the GIBS layer page at:"); + ImGui::Text( + "%s", + "https://wiki.earthdata.nasa.gov/display/GIBS/GIBS+Available+Imagery+Products" + ); + ImGui::Separator(); + + static std::array LayerBuffer; + ImGui::InputText("Layer Name", LayerBuffer.data(), LayerBuffer.size()); + + static std::array StartDateBuffer; + ImGui::InputText("Start Date", StartDateBuffer.data(), StartDateBuffer.size()); + + static std::array EndDateBuffer = { "Yesterday" }; + ImGui::InputText("End Date", EndDateBuffer.data(), EndDateBuffer.size()); + + static std::array TemporalResolutionBuffer = { "1d" }; + ImGui::InputText( + "Temporal Resolution", + TemporalResolutionBuffer.data(), + TemporalResolutionBuffer.size() + ); + + //static std::array TemporalFormatBuffer; + // @TODO Replace with dropdown menu + constexpr std::array TemporalFormats = { + // @FRAGILE: Synchronized with tileprovider.cpp `from_string` method + "YYYY-MM-DD", + "YYYY-MM-DDThh:mm:ssZ", + "YYYY-MM-DDThh_mm_ssZ", + "YYYYMMDD_hhmmss", + "YYYYMMDD_hhmm" + }; + static const char* currentTemporalFormat = "YYYY-MM-DD"; + if (ImGui::BeginCombo("##Temporal Format", currentTemporalFormat)) { + for (const char* f : TemporalFormats) { + bool isSelected = (f == currentTemporalFormat); + if (ImGui::Selectable(f, &isSelected)) { + currentTemporalFormat = f; + } + } + ImGui::EndCombo(); + } + + static std::array ImageResolutionBuffer = { "250m" }; + ImGui::InputText( + "Image Resolution", + ImageResolutionBuffer.data(), + ImageResolutionBuffer.size() + ); + + static std::array ImageFormatBuffer = { "png" }; + ImGui::InputText("Image Format", ImageFormatBuffer.data(), ImageFormatBuffer.size()); + + if (ImGui::Button("Add Layer")) { + std::string layer = std::string(LayerBuffer.data()); + std::string startDate = std::string(StartDateBuffer.data()); + std::string endDate = std::string(EndDateBuffer.data()); + std::string temporalRes = std::string(TemporalResolutionBuffer.data()); + std::string temporalFormat = std::string(currentTemporalFormat); + std::string imageRes = std::string(ImageResolutionBuffer.data()); + std::string imageFormat = std::string(ImageFormatBuffer.data()); + + std::string xmlFunc = fmt::format( + "openspace.globebrowsing.createTemporalGibsGdalXml(" + "'{}', '{}', '{}', '{}', '{}', '{}', '{}')", + layer, startDate, endDate, temporalRes, imageRes, imageFormat, temporalFormat + ); + + std::string script = fmt::format( + "openspace.globebrowsing.addLayer('Earth', 'ColorLayers', {{ " + "Identifier = '{}', Enabled = true, Type = 'TemporalTileLayer', " + "FilePath = {} }})", + layer, xmlFunc + ); + global::scriptEngine.queueScript( + script, + scripting::ScriptEngine::RemoteScripting::Yes + ); + } + + ImGui::End(); +} + +} // namespace openspace::gui