diff --git a/data/assets/dsn.scene b/data/assets/dsn.scene index 05d7f00247..4810fe48dc 100644 --- a/data/assets/dsn.scene +++ b/data/assets/dsn.scene @@ -21,7 +21,7 @@ asset.require('scene/solarsystem/dsn/stations') --Communication --assetHelper.requestAll(asset, 'scene/solarsystem/dsn') asset.require('scene/solarsystem/dsn/communicationlines/communicationlines') -asset.require('scene/solarsystem/dsn/spacecrafts') +asset.require('scene/solarsystem/dsn/testRADEC') -- Load default key bindings applicable to most scenes asset.require('util/default_keybindings') diff --git a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset b/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset index dfdec3d829..e40d0a2e73 100644 --- a/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset +++ b/data/assets/scene/solarsystem/dsn/communicationlines/communicationlines.asset @@ -8,7 +8,7 @@ local Signals = { Identifier = "Signals", Renderable = { Translation = { - Type = "RadecTranslation", + Type = "StaticTranslation", Position = {0.0, 0.0, 0.0} --no parent, sun center is 0, 0, 0 }, Type = "RenderableSignals", diff --git a/data/assets/scene/solarsystem/dsn/spacecrafts.asset b/data/assets/scene/solarsystem/dsn/testRADEC.asset similarity index 62% rename from data/assets/scene/solarsystem/dsn/spacecrafts.asset rename to data/assets/scene/solarsystem/dsn/testRADEC.asset index 5e60bcbf52..8ff043a70e 100644 --- a/data/assets/scene/solarsystem/dsn/spacecrafts.asset +++ b/data/assets/scene/solarsystem/dsn/testRADEC.asset @@ -1,4 +1,5 @@ local assetHelper = asset.require('util/asset_helper') +local dataFolder = openspace.absPath("../../../sync/http/dsn_data/1/positioning/VGR") local models = asset.syncedResource({ Name = "Dsn models", @@ -7,11 +8,13 @@ local models = asset.syncedResource({ Version = 1 }) -local testSpaceCraft = { - Identifier = "testSpaceCraft", +local testRADEC = { + Identifier = "testRADEC", Transform = { Translation = { - Type = "RadecTranslation" + Type = "RadecTranslation", + DataFolder = dataFolder, + DataFileType = "json" }, Scale = { Type = "StaticScale", @@ -28,9 +31,9 @@ local testSpaceCraft = { ColorTexture = models .. "/34m_dish/base_AO.png", }, GUI = { - Name = "testSpaceCraft", - Path = "/Solar System/testSpaceCraft" + Name = "testRADEC", + Path = "/Solar System/testRADEC" } } -assetHelper.registerSceneGraphNodesAndExport(asset, {testSpaceCraft}) \ No newline at end of file +assetHelper.registerSceneGraphNodesAndExport(asset, {testRADEC}) \ No newline at end of file diff --git a/modules/dsn/CMakeLists.txt b/modules/dsn/CMakeLists.txt index fd470dcc49..4ca8e1e4e0 100644 --- a/modules/dsn/CMakeLists.txt +++ b/modules/dsn/CMakeLists.txt @@ -28,6 +28,8 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesignals.h ${CMAKE_CURRENT_SOURCE_DIR}/translation/radectranslation.h ${CMAKE_CURRENT_SOURCE_DIR}/managers/signalmanager.h + ${CMAKE_CURRENT_SOURCE_DIR}/managers/radecmanager.h + ${CMAKE_CURRENT_SOURCE_DIR}/managers/jsonhelper.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -35,6 +37,8 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesignals.cpp ${CMAKE_CURRENT_SOURCE_DIR}/translation/radectranslation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/managers/signalmanager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/managers/radecmanager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/managers/jsonhelper.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/dsn/managers/jsonhelper.cpp b/modules/dsn/managers/jsonhelper.cpp new file mode 100644 index 0000000000..9db6157ead --- /dev/null +++ b/modules/dsn/managers/jsonhelper.cpp @@ -0,0 +1,136 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* 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 + +namespace openspace { + constexpr const char* _loggerCat = "JsonHelper"; + + JsonHelper::JsonHelper() + { + + } + + // Keys to get values from dictionary + constexpr const char* KeyDataFolder = "DataFolder"; + constexpr const char* KeyDataFileType = "DataFileType"; + + //Filetypes + const std::string dataFileTypeStringJson = "json"; + enum class DataFileType : int { + Json = 0, + Invalid + }; + + /** + * Extracts the general information (from the lua modfile) that is mandatory for the class + * to function; such as the file type and the location of the data files. + * Returns false if it fails to extract mandatory information! + */ + bool JsonHelper::checkFileNames(const char* identifier, std::unique_ptr &dictionary, std::vector &dataFiles) + { + DataFileType sourceFileType = DataFileType::Invalid; + + + // ------------------- EXTRACT MANDATORY VALUES FROM DICTIONARY ------------------- // + std::string dataFileTypeString; + if (!dictionary->getValue(KeyDataFileType, dataFileTypeString)) { + LERROR(fmt::format("{}: The field {} is missing", identifier, KeyDataFileType)); + } + std::transform( + dataFileTypeString.begin(), + dataFileTypeString.end(), + dataFileTypeString.begin(), + [](char c) { return static_cast(tolower(c)); } + ); + // Verify that the input type is correct + if (dataFileTypeString == dataFileTypeStringJson) { + sourceFileType = DataFileType::Json; + } + else { + LERROR(fmt::format( + "{}: {} is not a recognized {}", + identifier, dataFileTypeString, KeyDataFileType + )); + return false; + } + + std::string dataFolderPath; + if (!dictionary->getValue(KeyDataFolder, dataFolderPath)) { + LERROR(fmt::format("{}: The field {} is missing", identifier, KeyDataFolder)); + return false; + } + + // Ensure that the source folder exists and then extract + // the files with the same extension as + ghoul::filesystem::Directory dataFolder(dataFolderPath); + if (FileSys.directoryExists(dataFolder)) { + // Extract all file paths from the provided folder + dataFiles = dataFolder.readFiles( + ghoul::filesystem::Directory::Recursive::No, + ghoul::filesystem::Directory::Sort::Yes + ); + + // Remove all files that don't have as extension + dataFiles.erase( + std::remove_if( + dataFiles.begin(), + dataFiles.end(), + [dataFileTypeString](const std::string& str) { + const size_t extLength = dataFileTypeString.length(); + std::string sub = str.substr(str.length() - extLength, extLength); + std::transform( + sub.begin(), + sub.end(), + sub.begin(), + [](char c) { return static_cast(::tolower(c)); } + ); + return sub != dataFileTypeString; + }), + dataFiles.end() + ); + // Ensure that there are available and valid source files left + if (dataFiles.empty()) { + LERROR(fmt::format( + "{}: {} contains no {} files", + identifier, dataFolderPath, dataFileTypeString + )); + return false; + } + } + else { + LERROR(fmt::format( + "{}: {} is not a valid directory", + identifier, + dataFolderPath + )); + return false; + } + return true; + } + + +} + + diff --git a/modules/dsn/managers/jsonhelper.h b/modules/dsn/managers/jsonhelper.h new file mode 100644 index 0000000000..a6909a999c --- /dev/null +++ b/modules/dsn/managers/jsonhelper.h @@ -0,0 +1,46 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* 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_DSN___JSONHELPER___H__ +#define __OPENSPACE_MODULE_DSN___JSONHELPER___H__ + +#include +#include +#include +#include + + +namespace openspace { + + class JsonHelper { + + public: + JsonHelper(); + /* Extracts all the mandatory information we need from our asset files */ + static bool checkFileNames(const char* identifier, std::unique_ptr &dictionary, std::vector &dataFiles); + + }; +} + + +#endif diff --git a/modules/dsn/managers/radecmanager.cpp b/modules/dsn/managers/radecmanager.cpp new file mode 100644 index 0000000000..375bafc39f --- /dev/null +++ b/modules/dsn/managers/radecmanager.cpp @@ -0,0 +1,49 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* 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 + +namespace openspace { + constexpr const char* _loggerCat = "RadecManager"; + std::vector RadecManager::_dataFiles; + + RadecManager::RadecManager() + { + } + + bool RadecManager::extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr &dictionary){ + + JsonHelper::checkFileNames(identifier, dictionary, RadecManager::_dataFiles); + + + return true; + } + + static void jsonParser(int index) { + + } + +} + + diff --git a/modules/dsn/managers/radecmanager.h b/modules/dsn/managers/radecmanager.h new file mode 100644 index 0000000000..7c53d917d0 --- /dev/null +++ b/modules/dsn/managers/radecmanager.h @@ -0,0 +1,47 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* 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_DSN___RADECMANAGER___H__ +#define __OPENSPACE_MODULE_DSN___RADECMANAGER___H__ + +#include +#include +#include + + +namespace openspace { + + class RadecManager { + + public: + RadecManager(); + static void jsonParser(int index); + static std::vector _dataFiles; + static bool extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr &dictionary); + + + }; +} + + +#endif diff --git a/modules/dsn/managers/signalmanager.cpp b/modules/dsn/managers/signalmanager.cpp index f1ad789876..31de66e035 100644 --- a/modules/dsn/managers/signalmanager.cpp +++ b/modules/dsn/managers/signalmanager.cpp @@ -27,23 +27,11 @@ namespace openspace { constexpr const char* _loggerCat = "SignalManager"; - - // Keys to get values from dictionary - constexpr const char* KeyDataFolder = "DataFolder"; - constexpr const char* KeyDataFileType = "DataFileType"; struct SignalManager::SignalData SignalManager::_signalData; std::vector SignalManager::_fileStartTimes; std::vector SignalManager::_dataFiles; - //Filetypes - const std::string dataFileTypeStringJson = "json"; - - enum class DataFileType : int { - Json = 0, - Invalid - }; - /** * Extracts the general information (from the lua modfile) that is mandatory for the class * to function; such as the file type and the location of the data files. @@ -51,90 +39,18 @@ namespace openspace { */ bool SignalManager::extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr &dictionary) { - DataFileType sourceFileType = DataFileType::Invalid; - - // ------------------- EXTRACT MANDATORY VALUES FROM DICTIONARY ------------------- // - std::string dataFileTypeString; - if (!dictionary->getValue(KeyDataFileType, dataFileTypeString)) { - LERROR(fmt::format("{}: The field {} is missing", identifier, KeyDataFileType)); - } - std::transform( - dataFileTypeString.begin(), - dataFileTypeString.end(), - dataFileTypeString.begin(), - [](char c) { return static_cast(tolower(c)); } - ); - // Verify that the input type is correct - if (dataFileTypeString == dataFileTypeStringJson) { - sourceFileType = DataFileType::Json; - } - else { - LERROR(fmt::format( - "{}: {} is not a recognized {}", - identifier, dataFileTypeString, KeyDataFileType - )); - return false; - } - - std::string dataFolderPath; - if (!dictionary->getValue(KeyDataFolder, dataFolderPath)) { - LERROR(fmt::format("{}: The field {} is missing", identifier, KeyDataFolder)); - return false; - } + bool dataFilesSuccess = JsonHelper::checkFileNames(identifier, dictionary, _dataFiles); - // Ensure that the source folder exists and then extract - // the files with the same extension as - ghoul::filesystem::Directory dataFolder(dataFolderPath); - if (FileSys.directoryExists(dataFolder)) { - // Extract all file paths from the provided folder - _dataFiles = dataFolder.readFiles( - ghoul::filesystem::Directory::Recursive::No, - ghoul::filesystem::Directory::Sort::Yes - ); - - // Remove all files that don't have as extension - _dataFiles.erase( - std::remove_if( - _dataFiles.begin(), - _dataFiles.end(), - [dataFileTypeString](const std::string& str) { - const size_t extLength = dataFileTypeString.length(); - std::string sub = str.substr(str.length() - extLength, extLength); - std::transform( - sub.begin(), - sub.end(), - sub.begin(), - [](char c) { return static_cast(::tolower(c)); } - ); - return sub != dataFileTypeString; - }), - _dataFiles.end() - ); - // Ensure that there are available and valid source files left - if (_dataFiles.empty()) { - LERROR(fmt::format( - "{}: {} contains no {} files", - identifier, dataFolderPath, dataFileTypeString - )); - return false; - } - } - else { - LERROR(fmt::format( - "{}: {} is not a valid directory", - identifier, - dataFolderPath - )); - return false; - } extractTriggerTimesFromFileNames(_dataFiles); + SignalManager::jsonParser(0); - return SignalManager::jsonParser(0); + return dataFilesSuccess; } // Extract J2000 time from file names // Requires files to be named as such: 'YYYY-DDDT.json' void SignalManager::extractTriggerTimesFromFileNames(std::vector _dataFiles) { + // number of characters in filename (excluding '.json') constexpr const int FilenameSize = 9; // size(".json") diff --git a/modules/dsn/managers/signalmanager.h b/modules/dsn/managers/signalmanager.h index d24fca52a0..085125eb11 100644 --- a/modules/dsn/managers/signalmanager.h +++ b/modules/dsn/managers/signalmanager.h @@ -28,14 +28,10 @@ #include #include #include +#include #include -//#include -//#include -//#include -//#include -//#include #include #include @@ -51,7 +47,7 @@ namespace openspace { std::string direction; std::string startTime; std::string endTime; - }; + }; static struct SignalData { //filename is on the format of YYYY-DDDT (excluding '.json') diff --git a/modules/dsn/translation/radectranslation.cpp b/modules/dsn/translation/radectranslation.cpp index ad257771d9..6a13341751 100644 --- a/modules/dsn/translation/radectranslation.cpp +++ b/modules/dsn/translation/radectranslation.cpp @@ -36,6 +36,8 @@ namespace { namespace openspace { +constexpr const char* _loggerCat = "RadecTranslation"; + documentation::Documentation RadecTranslation::Documentation() { using namespace documentation; return { @@ -74,11 +76,16 @@ RadecTranslation::RadecTranslation() requireUpdate(); notifyObservers(); }); + + } RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary) : RadecTranslation() { + std::unique_ptr dictionaryPtr = std::make_unique(dictionary); + extractData(dictionaryPtr); + documentation::testSpecificationAndThrow( Documentation(), dictionary, @@ -86,7 +93,19 @@ RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary) ); } +void RadecTranslation::extractData(std::unique_ptr &dictionary){ + const char* _identifier = "testRADEC"; + + if (!RadecManager::extractMandatoryInfoFromDictionary(_identifier, dictionary)) { + LERROR(fmt::format("{}: Did not manage to extract data. (from RadecTranslation and RadecManager)", _identifier)); + } + else { + LDEBUG(fmt::format("{}: Successfully read data. (from RadecTranslation and RadecManager)", _identifier)); + } +} + glm::dvec3 RadecTranslation::convertRaDecRangeToCartesian() const{ + //Todo: stream data from file //Static data for voyager 1 double ra = 257.777029167736; //2018-246 diff --git a/modules/dsn/translation/radectranslation.h b/modules/dsn/translation/radectranslation.h index 97fe46ef2d..fa069f7be6 100644 --- a/modules/dsn/translation/radectranslation.h +++ b/modules/dsn/translation/radectranslation.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace openspace { @@ -41,6 +42,7 @@ namespace documentation { struct Documentation; } class RadecTranslation : public Translation { public: RadecTranslation(); + void extractData(std::unique_ptr &dictionary); RadecTranslation(const ghoul::Dictionary& dictionary); /* Converts the Ra Dec range coordinates into cartesian coordinates*/ glm::dvec3 convertRaDecRangeToCartesian() const;