From b8b2867a207bdfd520aed7d366dc64bd50ee1185 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Fri, 21 Apr 2023 15:48:09 -0400 Subject: [PATCH 01/11] Remove handlebars and refactor --- .../documentation/documentationengine.h | 22 --- .../documentation/documentationgenerator.h | 20 +-- src/documentation/documentationengine.cpp | 140 +----------------- src/documentation/documentationgenerator.cpp | 41 +++-- src/engine/openspaceengine.cpp | 37 ++--- src/interaction/keybindingmanager.cpp | 34 +---- src/properties/propertyowner.cpp | 45 ++---- src/scene/scenelicensewriter.cpp | 36 +---- src/scripting/scriptengine.cpp | 34 +---- src/util/factorymanager.cpp | 40 +---- 10 files changed, 81 insertions(+), 368 deletions(-) diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index ff922c0470..8336b39c21 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -71,14 +71,6 @@ public: */ void addDocumentation(Documentation documentation); - /* Adds the \p templates to the list of templates that are written to the - * documentation html file. - * \param templates Vector of templates to add. Most of the time this list - * will just contain one item, but some modules may wish to provide - * multiple templates for subtypes, etc - */ - void addHandlebarTemplates(std::vector templates); - /** * Returns a list of all registered Documentation%s. * @@ -97,17 +89,6 @@ public: */ static DocumentationEngine& ref(); - /** - * Generates the documentation html file. Generated file will have embeded - * in it: HandlebarJS Templates (from _handlebarTemplates) and json (from - * \p data) along with the base template and js/css files from the source - * directory ${WEB}/documentation - * - * \param path The path to add - * \param data The JSON data that is written to the documentation - */ - void writeDocumentationHtml(const std::string& path, std::string data); - std::string generateJson() const override; nlohmann::json generateJsonJson() const; @@ -116,12 +97,9 @@ private: /// The list of all Documentation%s that are stored by the DocumentationEngine std::vector _documentations; - /// The list of templates to render the documentation with. - std::vector _handlebarTemplates; static DocumentationEngine* _instance; }; - } // namespace openspace::documentation #define DocEng (openspace::documentation::DocumentationEngine::ref()) diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h index d16cd32d2d..dfe5e56b54 100644 --- a/include/openspace/documentation/documentationgenerator.h +++ b/include/openspace/documentation/documentationgenerator.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__ #define __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__ +#include #include #include @@ -46,35 +47,24 @@ namespace openspace { */ class DocumentationGenerator { public: - /// This struct contains a single Handlebar template, with the name and the filename - struct HandlebarTemplate { - std::string name; ///< The name of the Handlebar template defined in #filename - std::string filename; ///< The filename referenced in the #name - }; - + static const std::string NameTag; + static const std::string DataTag; /** * The constructor that is used to set the member variables later used in the * writeDocumentation method. * * \param name The name of the written documentation * \param jsonName The variable name of the value generated by the generateJson - * \param handlebarTemplates A list of Handlebar templates that is added to the - * documentation file * * \pre name must not be empty * \pre jsonName must not be empty - * \pre Each handlebarTemplates' `name` must not be empty * \pre javascriptFilename must not be empty */ - DocumentationGenerator(std::string name, std::string jsonName, - std::vector handlebarTemplates); + DocumentationGenerator(std::string name, std::string jsonName); /// Default constructor virtual ~DocumentationGenerator() = default; - //getter for handlebar templates - std::vector templatesToRegister(); - //getter for identifier std::string jsonName(); @@ -89,10 +79,10 @@ public: */ virtual std::string generateJson() const = 0; + void sortJson(nlohmann::json& json) const; private: const std::string _name; const std::string _jsonName; - const std::vector _handlebarTemplates; }; } // namespace openspace diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index b76591e559..c80149cb9d 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -58,10 +58,7 @@ DocumentationEngine::DuplicateDocumentationException::DuplicateDocumentationExce DocumentationEngine::DocumentationEngine() : DocumentationGenerator( "Top Level", - "toplevel", - { - { "toplevelTemplate", "${WEB}/documentation/toplevel.hbs" }, - } + "toplevel" ) {} @@ -180,142 +177,7 @@ void DocumentationEngine::addDocumentation(Documentation documentation) { } } -void DocumentationEngine::addHandlebarTemplates(std::vector templates) -{ - _handlebarTemplates.insert( - _handlebarTemplates.end(), - templates.begin(), templates.end() - ); -} - std::vector DocumentationEngine::documentations() const { return _documentations; } - -void DocumentationEngine::writeDocumentationHtml(const std::string& path, - std::string data) -{ - ZoneScoped; - - std::ifstream handlebarsInput; - handlebarsInput.exceptions(~std::ofstream::goodbit); - handlebarsInput.open(absPath(HandlebarsFilename)); - const std::string handlebarsContent = std::string( - std::istreambuf_iterator(handlebarsInput), - std::istreambuf_iterator() - ); - std::ifstream jsInput; - jsInput.exceptions(~std::ofstream::goodbit); - jsInput.open(absPath(JsFilename)); - const std::string jsContent = std::string( - std::istreambuf_iterator(jsInput), - std::istreambuf_iterator() - ); - - std::ifstream bootstrapInput; - bootstrapInput.exceptions(~std::ofstream::goodbit); - bootstrapInput.open(absPath(BootstrapFilename)); - const std::string bootstrapContent = std::string( - std::istreambuf_iterator(bootstrapInput), - std::istreambuf_iterator() - ); - - std::ifstream cssInput; - cssInput.exceptions(~std::ofstream::goodbit); - cssInput.open(absPath(CssFilename)); - const std::string cssContent = std::string( - std::istreambuf_iterator(cssInput), - std::istreambuf_iterator() - ); - - std::string filename = path + ("index.html"); - std::ofstream file; - file.exceptions(~std::ofstream::goodbit); - file.open(filename); - - // We probably should escape backslashes here? - file << "" << '\n' - << "" << '\n' - << " " << "" << '\n'; - - //write handlebar templates to htmlpage as script elements (as per hb) - for (const HandlebarTemplate& t : _handlebarTemplates) { - const char* Type = "text/x-handlebars-template"; - file << " " << '\n'; - } - - //write main template - file << " " << '\n'; - - //write scripte to register templates dynamically - file << " " << '\n'; - - - const std::string DataId = "data"; - - const std::string Version = - "[" + - std::to_string(OPENSPACE_VERSION_MAJOR) + "," + - std::to_string(OPENSPACE_VERSION_MINOR) + "," + - std::to_string(OPENSPACE_VERSION_PATCH) + - "]"; - - file - << " " << "" << '\n'; - - - file - << " " << "" << '\n' - << " " << "" << '\n' - << " " << "OpenSpace Documentation" << '\n' - << " " << "" << '\n' - << " " << "" << '\n' - << " " << "" << '\n' - << "" << '\n'; -} - - } // namespace openspace::documentation diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index ece31d9b2b..f79f13bf3a 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -32,30 +32,45 @@ namespace openspace { +const std::string DocumentationGenerator::DataTag = "Data"; +const std::string DocumentationGenerator::NameTag = "Name"; + DocumentationGenerator::DocumentationGenerator(std::string name, - std::string jsonName, - std::vector handlebarTemplates) + std::string jsonName) : _name(std::move(name)) , _jsonName(std::move(jsonName)) - , _handlebarTemplates(std::move(handlebarTemplates)) { ghoul_precondition(!_name.empty(), "name must not be empty"); ghoul_precondition(!_jsonName.empty(), "jsonName must not be empty"); - for (const HandlebarTemplate& t : _handlebarTemplates) { - (void)t; // Unused variable in Release mode - ghoul_precondition(!t.name.empty(), "name must not be empty"); - ghoul_precondition(!t.filename.empty(), "filename must not be empty"); - } } -std::vector -DocumentationGenerator::templatesToRegister() -{ - return _handlebarTemplates; -} std::string DocumentationGenerator::jsonName() { return _jsonName; } +void DocumentationGenerator::sortJson(nlohmann::json& json) const { + std::sort( + json.begin(), + json.end(), + [](const nlohmann::json& lhs, const nlohmann::json& rhs) { + std::string lhsString = lhs["Name"]; + std::string rhsString = rhs["Name"]; + std::transform( + lhsString.begin(), + lhsString.end(), + lhsString.begin(), + [](unsigned char c) { return std::tolower(c); } + ); + std::transform( + rhsString.begin(), + rhsString.end(), + rhsString.begin(), + [](unsigned char c) { return std::tolower(c); } + ); + + return rhsString > lhsString; + }); +} + } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 752b5e7e6a..cf2db1e7e6 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1047,36 +1047,17 @@ void OpenSpaceEngine::writeDocumentation() { &properties::PropertyOwner::generateJsonJson, _scene.get() ); - - - DocEng.addHandlebarTemplates(global::scriptEngine->templatesToRegister()); - DocEng.addHandlebarTemplates(FactoryManager::ref().templatesToRegister()); - DocEng.addHandlebarTemplates(DocEng.templatesToRegister()); - - nlohmann::json scripting; - scripting["Name"] = "Scripting API"; - scripting["Data"] = global::scriptEngine->generateJsonJson(); - - nlohmann::json factory; - factory["Name"] = "Asset Types"; - factory["Data"] = FactoryManager::ref().generateJsonJson(); - - nlohmann::json keybindings; - keybindings["Name"] = "Keybindings"; - keybindings["Keybindings"] = global::keybindingManager->generateJsonJson(); - SceneLicenseWriter writer; - nlohmann::json license; - license["Name"] = "Licenses"; - license["Data"] = writer.generateJsonJson(); - nlohmann::json sceneProperties; - sceneProperties["Name"] = "Settings"; - sceneProperties["Data"] = settings.get(); - - nlohmann::json sceneGraph; - sceneGraph["Name"] = "Scene"; - sceneGraph["Data"] = scene.get(); + nlohmann::json scripting = global::scriptEngine->generateJsonJson(); + nlohmann::json factory = FactoryManager::ref().generateJsonJson(); + nlohmann::json keybindings = global::keybindingManager->generateJsonJson(); + nlohmann::json license = writer.generateJsonJson(); + nlohmann::json sceneProperties = settings.get(); + nlohmann::json sceneGraph = scene.get(); + + sceneProperties[DocumentationGenerator::NameTag] = "Settings"; + sceneGraph[DocumentationGenerator::NameTag] = "Scene"; nlohmann::json documentation = { sceneGraph, sceneProperties, keybindings, license, scripting, factory diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 2c6881f310..e51f057dd1 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -38,37 +38,10 @@ namespace openspace::interaction { -void sortJson(nlohmann::json& json) { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - - return rhsString > lhsString; - }); -} - KeybindingManager::KeybindingManager() : DocumentationGenerator( "Keybindings", - "keybinding", - { - { "keybindingTemplate", "${WEB}/documentation/keybinding.hbs" } - } + "keybinding" ) {} @@ -177,7 +150,10 @@ nlohmann::json KeybindingManager::generateJsonJson() const { } sortJson(json); - return json; + nlohmann::json result; + result[NameTag] = "Keybindings"; + result["Keybindings"] = json; + return result; } scripting::LuaLibrary KeybindingManager::luaLibrary() { diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index a245bf62f1..c30dd4592b 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -41,30 +41,6 @@ namespace { constexpr std::string_view _loggerCat = "PropertyOwner"; - void sortJson(nlohmann::json& json) { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - - return rhsString > lhsString; - }); - } - nlohmann::json createJson(openspace::properties::PropertyOwner* owner) { ZoneScoped @@ -89,14 +65,12 @@ namespace { json["Properties"].push_back(propertyJson); } - sortJson(json["Properties"]); auto propertyOwners = owner->propertySubOwners(); for (properties::PropertyOwner* o : propertyOwners) { nlohmann::json propertyOwner; json["PropertyOwners"].push_back(createJson(o)); } - sortJson(json["PropertyOwners"]); return json; } @@ -107,12 +81,7 @@ namespace openspace::properties { PropertyOwner::PropertyOwner(PropertyOwnerInfo info) : DocumentationGenerator( "Property Owners", - "propertyOwners", - { - { "propertyOwnersTemplate","${WEB}/documentation/propertyowners.hbs" }, - { "propertyTemplate","${WEB}/documentation/property.hbs" }, - { "propertylistTemplate","${WEB}/documentation/propertylist.hbs" } - } + "propertyOwners" ) , _identifier(std::move(info.identifier)) , _guiName(std::move(info.guiName)) @@ -437,12 +406,20 @@ nlohmann::json PropertyOwner::generateJsonJson() const { std::vector subOwners = propertySubOwners(); for (PropertyOwner* owner : subOwners) { if (owner->identifier() != "Scene") { - json.push_back(createJson(owner)); + nlohmann::json jsonOwner = createJson(owner); + sortJson(jsonOwner["Properties"]); + sortJson(jsonOwner["PropertyOwners"]); + + json.push_back(jsonOwner); } } sortJson(json); - return json; + nlohmann::json result; + result[NameTag] = "PropertyOwner"; + result[DataTag] = json; + + return result; } } // namespace openspace::properties diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index b97c5f6113..e719753bf8 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -39,37 +39,10 @@ namespace openspace { SceneLicenseWriter::SceneLicenseWriter() : DocumentationGenerator( "Scene Licenses", - "sceneLicense", - { - { "sceneLicenseTemplate", "${WEB}/documentation/scenelicense.hbs" } - } + "sceneLicense" ) {} -void sortJson(nlohmann::json& json) { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - - return rhsString > lhsString; - }); -} - nlohmann::json SceneLicenseWriter::generateJsonJson() const { nlohmann::json json; @@ -144,7 +117,12 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { assetsJson["Licenses"].push_back(entry); } json.push_back(assetsJson); - return json; + + nlohmann::json result; + result[NameTag] = "Licenses"; + result[DataTag] = json; + + return result; } std::string SceneLicenseWriter::generateJson() const { diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 21f58ebaba..fbe2c9c595 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -81,29 +81,7 @@ namespace { return result; } - void sortJson(nlohmann::json& json) { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - return rhsString > lhsString; - }); - } nlohmann::json toJson(const openspace::scripting::LuaLibrary::Function& f) { using namespace openspace; @@ -216,10 +194,7 @@ namespace openspace::scripting { ScriptEngine::ScriptEngine() : DocumentationGenerator( "Script Documentation", - "scripting", - { - { "scriptingTemplate","${WEB}/documentation/scripting.hbs" }, - } + "scripting" ) { //tracy::LuaRegister(_state); @@ -600,7 +575,12 @@ nlohmann::json ScriptEngine::generateJsonJson() const { sortJson(json); } - return json; + + nlohmann::json result; + result[NameTag] = "Scripting API"; + result[DataTag] = json; + + return result; } void ScriptEngine::writeLog(const std::string& script) { diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 2502716654..fed2f0d6b3 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -42,30 +42,6 @@ namespace { using namespace openspace; using namespace openspace::documentation; -void sortJson(nlohmann::json& json) { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - - return rhsString > lhsString; - }); -} - nlohmann::json generateJsonDocumentation(const Documentation& d) { nlohmann::json json; @@ -113,7 +89,6 @@ nlohmann::json generateJsonDocumentation(const Documentation& d) { } json["Members"].push_back(entry); } - sortJson(json["Members"]); return json; } @@ -133,10 +108,7 @@ FactoryManager::FactoryNotFoundError::FactoryNotFoundError(std::string t) FactoryManager::FactoryManager() : DocumentationGenerator( "Factory Documentation", - "factory", - { - { "factoryTemplate", "${WEB}/documentation/factory.hbs" } - } + "factory" ) {} @@ -252,11 +224,15 @@ nlohmann::json FactoryManager::generateJsonJson() const { for (const Documentation& doc : docs) { leftovers["Classes"].push_back(generateJsonDocumentation(doc)); } - sortJson(leftovers["Classes"]); + sortJson(json["Classes"]["Members"]); json.push_back(leftovers); - sortJson(json); + // I did not check the output of this for correctness ---abock - return json; + nlohmann::json result; + result[NameTag] = "Asset Types"; + result[DataTag] = json; + + return result; } } // namespace openspace From 948fdd024bbeff37e7b2da18b27239d608fa8d87 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Tue, 25 Apr 2023 16:32:04 -0400 Subject: [PATCH 02/11] Remove generateJson function from the DocumentationGenerator and move sortJson function to json_helper --- .../documentation/documentationengine.h | 2 +- .../documentation/documentationgenerator.h | 1 - .../openspace/interaction/keybindingmanager.h | 2 +- include/openspace/properties/propertyowner.h | 2 +- include/openspace/scene/scenelicensewriter.h | 2 +- include/openspace/scripting/scriptengine.h | 2 +- include/openspace/util/factorymanager.h | 2 +- include/openspace/util/json_helper.h | 11 ++++++++ src/documentation/documentationgenerator.cpp | 23 ----------------- src/interaction/keybindingmanager.cpp | 2 +- src/properties/propertyowner.cpp | 6 ++--- src/scene/scenelicensewriter.cpp | 2 +- src/scripting/scriptengine.cpp | 4 +-- src/util/factorymanager.cpp | 4 +-- src/util/json_helper.cpp | 25 +++++++++++++++++++ 15 files changed, 51 insertions(+), 39 deletions(-) diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index 8336b39c21..1be6497f01 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -89,7 +89,7 @@ public: */ static DocumentationEngine& ref(); - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h index dfe5e56b54..3d6e2c7b66 100644 --- a/include/openspace/documentation/documentationgenerator.h +++ b/include/openspace/documentation/documentationgenerator.h @@ -79,7 +79,6 @@ public: */ virtual std::string generateJson() const = 0; - void sortJson(nlohmann::json& json) const; private: const std::string _name; const std::string _jsonName; diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index 405c77f88b..f036a9b3f6 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -55,7 +55,7 @@ public: void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; const std::multimap& keyBindings() const; diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 3628e69db2..6c4599613b 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -297,7 +297,7 @@ public: void removeTag(const std::string& tag); // Generate JSON for documentation - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; diff --git a/include/openspace/scene/scenelicensewriter.h b/include/openspace/scene/scenelicensewriter.h index a93a5aa9ab..9ed5af60c5 100644 --- a/include/openspace/scene/scenelicensewriter.h +++ b/include/openspace/scene/scenelicensewriter.h @@ -35,7 +35,7 @@ namespace openspace { class SceneLicenseWriter : public DocumentationGenerator { public: SceneLicenseWriter(); - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; }; diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 7239dd45e9..5d7602fbe8 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -95,7 +95,7 @@ public: std::vector allLuaFunctions() const; - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; private: diff --git a/include/openspace/util/factorymanager.h b/include/openspace/util/factorymanager.h index 932d3d3d6f..07a388f68a 100644 --- a/include/openspace/util/factorymanager.h +++ b/include/openspace/util/factorymanager.h @@ -109,7 +109,7 @@ public: template ghoul::TemplateFactory* factory() const; - std::string generateJson() const override; + std::string generateJson() const; nlohmann::json generateJsonJson() const; private: diff --git a/include/openspace/util/json_helper.h b/include/openspace/util/json_helper.h index 9cb285a817..b7909d1b9b 100644 --- a/include/openspace/util/json_helper.h +++ b/include/openspace/util/json_helper.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___JSON_HELPER___H__ #include +#include namespace openspace { @@ -65,6 +66,16 @@ std::string formatJsonNumber(double d); template std::string formatJson(T value); +/** + * Sort a json object that is an array of objects with the structure + * [ key = {}, key = {} ...]. Sorts it by the provided key + * + * \param json The json to sort + * \param key The key the json should be sorted by + * \return The sorted JSON + */ +void sortJson(nlohmann::json& json, const std::string& key); + } // namespace openspace #include "json_helper.inl" diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index f79f13bf3a..826f3a1b30 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -49,28 +49,5 @@ std::string DocumentationGenerator::jsonName() { return _jsonName; } -void DocumentationGenerator::sortJson(nlohmann::json& json) const { - std::sort( - json.begin(), - json.end(), - [](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs["Name"]; - std::string rhsString = rhs["Name"]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - - return rhsString > lhsString; - }); -} } // namespace openspace diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index e51f057dd1..498afeba94 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -148,7 +148,7 @@ nlohmann::json KeybindingManager::generateJsonJson() const { keybind["Action"] = p.second; json.push_back(std::move(keybind)); } - sortJson(json); + sortJson(json, "Name"); nlohmann::json result; result[NameTag] = "Keybindings"; diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index c30dd4592b..e019dc15ef 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -407,13 +407,13 @@ nlohmann::json PropertyOwner::generateJsonJson() const { for (PropertyOwner* owner : subOwners) { if (owner->identifier() != "Scene") { nlohmann::json jsonOwner = createJson(owner); - sortJson(jsonOwner["Properties"]); - sortJson(jsonOwner["PropertyOwners"]); + sortJson(jsonOwner["Properties"], "Name"); + sortJson(jsonOwner["PropertyOwners"], "Name"); json.push_back(jsonOwner); } } - sortJson(json); + sortJson(json, "Name"); nlohmann::json result; result[NameTag] = "PropertyOwner"; diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index e719753bf8..f9067692f8 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -113,7 +113,7 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { nlohmann::json entry; entry["Name"] = assetLicense.first; entry["Assets"] = assetLicense.second; - sortJson(entry["Assets"]); + sortJson(entry["Assets"], "Name"); assetsJson["Licenses"].push_back(entry); } json.push_back(assetsJson); diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index fbe2c9c595..1d559ee7fd 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -570,10 +570,10 @@ nlohmann::json ScriptEngine::generateJsonJson() const { for (const LuaLibrary::Function& f : l.documentations) { library["Functions"].push_back(toJson(f)); } - sortJson(library["Functions"]); + sortJson(library["Functions"], "Name"); json.push_back(library); - sortJson(json); + sortJson(json, "Name"); } nlohmann::json result; diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index fed2f0d6b3..c03c8e7d7d 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -213,7 +213,7 @@ nlohmann::json FactoryManager::generateJsonJson() const { factory["Classes"].push_back(documentation); } } - sortJson(factory["Classes"]); + sortJson(factory["Classes"], "Name"); json.push_back(factory); } // Add all leftover docs @@ -224,7 +224,7 @@ nlohmann::json FactoryManager::generateJsonJson() const { for (const Documentation& doc : docs) { leftovers["Classes"].push_back(generateJsonDocumentation(doc)); } - sortJson(json["Classes"]["Members"]); + sortJson(json["Classes"]["Members"], "Name"); json.push_back(leftovers); // I did not check the output of this for correctness ---abock diff --git a/src/util/json_helper.cpp b/src/util/json_helper.cpp index 1625e27da3..6ec2a6b81b 100644 --- a/src/util/json_helper.cpp +++ b/src/util/json_helper.cpp @@ -84,4 +84,29 @@ std::string formatJsonNumber(double d) { return std::to_string(d); } +void sortJson(nlohmann::json& json, const std::string& key) { + std::sort( + json.begin(), + json.end(), + [&key](const nlohmann::json& lhs, const nlohmann::json& rhs) { + std::string lhsString = lhs[key]; + std::string rhsString = rhs[key]; + std::transform( + lhsString.begin(), + lhsString.end(), + lhsString.begin(), + [](unsigned char c) { return std::tolower(c); } + ); + std::transform( + rhsString.begin(), + rhsString.end(), + rhsString.begin(), + [](unsigned char c) { return std::tolower(c); } + ); + + return rhsString > lhsString; + } + ); +} + } // namespace openspace From d267bc0dadd1b29a4533c95ef623f48cdc7f13ea Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Tue, 25 Apr 2023 16:44:10 -0400 Subject: [PATCH 03/11] Remove documentation generator --- .../documentation/documentationengine.h | 4 +- .../documentation/documentationgenerator.h | 89 ------------------- .../openspace/interaction/keybindingmanager.h | 4 +- include/openspace/mission/missionmanager.h | 1 - include/openspace/properties/propertyowner.h | 6 +- include/openspace/scene/scenelicensewriter.h | 4 +- include/openspace/scripting/scriptengine.h | 3 +- include/openspace/util/factorymanager.h | 4 +- src/CMakeLists.txt | 2 - src/documentation/documentationengine.cpp | 7 +- src/documentation/documentationgenerator.cpp | 24 ----- src/engine/openspaceengine.cpp | 4 +- src/interaction/keybindingmanager.cpp | 9 +- src/properties/propertyowner.cpp | 10 +-- src/scene/scenelicensewriter.cpp | 11 +-- src/scripting/scriptengine.cpp | 13 +-- src/util/factorymanager.cpp | 11 +-- 17 files changed, 24 insertions(+), 182 deletions(-) delete mode 100644 include/openspace/documentation/documentationgenerator.h diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index 1be6497f01..88ec3042c7 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -25,8 +25,6 @@ #ifndef __OPENSPACE_CORE___DOCUMENTATIONENGINE___H__ #define __OPENSPACE_CORE___DOCUMENTATIONENGINE___H__ -#include - #include #include #include @@ -38,7 +36,7 @@ namespace openspace::documentation { * produced in the application an write them out as a documentation file for human * consumption. */ -class DocumentationEngine : public DocumentationGenerator { +class DocumentationEngine { public: /** * This exception is thrown by the addDocumentation method if a provided Documentation diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h deleted file mode 100644 index 3d6e2c7b66..0000000000 --- a/include/openspace/documentation/documentationgenerator.h +++ /dev/null @@ -1,89 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2023 * - * * - * 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_CORE___DOCUMENTATIONGENERATOR___H__ -#define __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__ - -#include -#include -#include - -namespace openspace { - -/* - * This abstract class is used for instances when another class has the ability to - * generate a Handlebar generated documentation file that contains valuable information - * for the user. Instances of this are the DocumentationEngine results, the list of - * Property%s generated by the Scene, or the FactoryEngine results. The documentation is - * generated through the writeDocumentation method. - * - * The concrete subclass needs to overload the generateJson class that will return the - * Json that is parsed by Handlebar to generate the webpage. - * - * A list of Handlebar templates, the variable name for the result of the generateJson - * method, and the Javascript file that contains additional logic is passed in the - * constructor. - */ -class DocumentationGenerator { -public: - static const std::string NameTag; - static const std::string DataTag; - /** - * The constructor that is used to set the member variables later used in the - * writeDocumentation method. - * - * \param name The name of the written documentation - * \param jsonName The variable name of the value generated by the generateJson - * - * \pre name must not be empty - * \pre jsonName must not be empty - * \pre javascriptFilename must not be empty - */ - DocumentationGenerator(std::string name, std::string jsonName); - - /// Default constructor - virtual ~DocumentationGenerator() = default; - - //getter for identifier - std::string jsonName(); - - /** - * This abstract method is used by concrete subclasses to provide the actual data that - * is used in the documentation written by this DocumentationGenerator class. The JSON - * string returned by this function will be stored in the variable with the - * `jsonName` as passed in the constructor. - * - * \return A JSON script that is parsed and stored in the variable passed in the - * DocumentationGenerator constructor - */ - virtual std::string generateJson() const = 0; - -private: - const std::string _name; - const std::string _jsonName; -}; - -} // namespace openspace - -#endif // __OPENSPACE_CORE___DOCUMENTATIONGENERATOR___H__ diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index f036a9b3f6..55f0e3ae9e 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -25,8 +25,6 @@ #ifndef __OPENSPACE_CORE___KEYBINDINGMANAGER___H__ #define __OPENSPACE_CORE___KEYBINDINGMANAGER___H__ -#include - #include namespace openspace { @@ -38,7 +36,7 @@ namespace openspace::scripting { struct LuaLibrary; } namespace openspace::interaction { -class KeybindingManager : public DocumentationGenerator { +class KeybindingManager { public: KeybindingManager(); diff --git a/include/openspace/mission/missionmanager.h b/include/openspace/mission/missionmanager.h index 3918a4c29c..4942941853 100644 --- a/include/openspace/mission/missionmanager.h +++ b/include/openspace/mission/missionmanager.h @@ -25,7 +25,6 @@ #ifndef __OPENSPACE_CORE___MISSIONMANAGER___H__ #define __OPENSPACE_CORE___MISSIONMANAGER___H__ -#include #include #include diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 6c4599613b..81b199808b 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -25,8 +25,6 @@ #ifndef __OPENSPACE_CORE___PROPERTYOWNER___H__ #define __OPENSPACE_CORE___PROPERTYOWNER___H__ -#include - #include #include #include @@ -49,7 +47,7 @@ class Property; * (`.`), the first name before the separator will be used as a subOwner's name and the * search will proceed recursively. */ -class PropertyOwner : public DocumentationGenerator { +class PropertyOwner { public: /// The separator that is used while accessing the properties and/or sub-owners static constexpr char URISeparator = '.'; @@ -76,7 +74,7 @@ public: * The destructor will remove all Propertys and PropertyOwners it owns along with * itself. */ - virtual ~PropertyOwner() override; + virtual ~PropertyOwner(); /** * Sets the identifier for this PropertyOwner. If the PropertyOwner does not have an diff --git a/include/openspace/scene/scenelicensewriter.h b/include/openspace/scene/scenelicensewriter.h index 9ed5af60c5..0438d7c4d0 100644 --- a/include/openspace/scene/scenelicensewriter.h +++ b/include/openspace/scene/scenelicensewriter.h @@ -25,14 +25,12 @@ #ifndef __OPENSPACE_CORE___SCENELICENSEWRITER___H__ #define __OPENSPACE_CORE___SCENELICENSEWRITER___H__ -#include - #include #include namespace openspace { -class SceneLicenseWriter : public DocumentationGenerator { +class SceneLicenseWriter { public: SceneLicenseWriter(); std::string generateJson() const; diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 5d7602fbe8..11e3e54a1a 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -26,7 +26,6 @@ #define __OPENSPACE_CORE___SCRIPTENGINE___H__ #include -#include #include #include #include @@ -49,7 +48,7 @@ namespace openspace::scripting { * `openspace` namespace prefix in Lua. The same functions can be exposed to * other Lua states by passing them to the #initializeLuaState method. */ -class ScriptEngine : public Syncable, public DocumentationGenerator { +class ScriptEngine : public Syncable { public: using ScriptCallback = std::function; BooleanType(RemoteScripting); diff --git a/include/openspace/util/factorymanager.h b/include/openspace/util/factorymanager.h index 07a388f68a..bfb195341d 100644 --- a/include/openspace/util/factorymanager.h +++ b/include/openspace/util/factorymanager.h @@ -25,8 +25,6 @@ #ifndef __OPENSPACE_CORE___FACTORYMANAGER___H__ #define __OPENSPACE_CORE___FACTORYMANAGER___H__ -#include - #include #include #include @@ -39,7 +37,7 @@ namespace openspace { * them available through the #addFactory and #factory methods. Each * ghoul::TemplateFactory can only be added once and can be accessed by its type. */ -class FactoryManager : public DocumentationGenerator { +class FactoryManager { public: /// This exception is thrown if the ghoul::TemplateFactory could not be found in the /// #factory method diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a34c60fc2b..c54bb478af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,6 @@ set(OPENSPACE_SOURCE documentation/core_registration.cpp documentation/documentation.cpp documentation/documentationengine.cpp - documentation/documentationgenerator.cpp documentation/verifier.cpp engine/configuration.cpp engine/downloadmanager.cpp @@ -212,7 +211,6 @@ set(OPENSPACE_HEADER ${PROJECT_SOURCE_DIR}/include/openspace/documentation/core_registration.h ${PROJECT_SOURCE_DIR}/include/openspace/documentation/documentation.h ${PROJECT_SOURCE_DIR}/include/openspace/documentation/documentationengine.h - ${PROJECT_SOURCE_DIR}/include/openspace/documentation/documentationgenerator.h ${PROJECT_SOURCE_DIR}/include/openspace/documentation/verifier.h ${PROJECT_SOURCE_DIR}/include/openspace/documentation/verifier.inl ${PROJECT_SOURCE_DIR}/include/openspace/engine/configuration.h diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index c80149cb9d..d68286dcc4 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -55,12 +55,7 @@ DocumentationEngine::DuplicateDocumentationException::DuplicateDocumentationExce , documentation(std::move(doc)) {} -DocumentationEngine::DocumentationEngine() - : DocumentationGenerator( - "Top Level", - "toplevel" - ) -{} +DocumentationEngine::DocumentationEngine() {} void DocumentationEngine::initialize() { ghoul_assert(!isInitialized(), "DocumentationEngine is already initialized"); diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index 826f3a1b30..9b2bca2af2 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -22,32 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include - #include #include #include #include #include - -namespace openspace { - -const std::string DocumentationGenerator::DataTag = "Data"; -const std::string DocumentationGenerator::NameTag = "Name"; - -DocumentationGenerator::DocumentationGenerator(std::string name, - std::string jsonName) - : _name(std::move(name)) - , _jsonName(std::move(jsonName)) -{ - ghoul_precondition(!_name.empty(), "name must not be empty"); - ghoul_precondition(!_jsonName.empty(), "jsonName must not be empty"); -} - - -std::string DocumentationGenerator::jsonName() { - return _jsonName; -} - - -} // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index cf2db1e7e6..5804763566 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1056,8 +1056,8 @@ void OpenSpaceEngine::writeDocumentation() { nlohmann::json sceneProperties = settings.get(); nlohmann::json sceneGraph = scene.get(); - sceneProperties[DocumentationGenerator::NameTag] = "Settings"; - sceneGraph[DocumentationGenerator::NameTag] = "Scene"; + sceneProperties["Data"] = "Settings"; + sceneGraph["Name"] = "Scene"; nlohmann::json documentation = { sceneGraph, sceneProperties, keybindings, license, scripting, factory diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 498afeba94..6018d9d351 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -38,12 +38,7 @@ namespace openspace::interaction { -KeybindingManager::KeybindingManager() - : DocumentationGenerator( - "Keybindings", - "keybinding" - ) -{} +KeybindingManager::KeybindingManager() {} void KeybindingManager::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) { @@ -151,7 +146,7 @@ nlohmann::json KeybindingManager::generateJsonJson() const { sortJson(json, "Name"); nlohmann::json result; - result[NameTag] = "Keybindings"; + result["Name"] = "Keybindings"; result["Keybindings"] = json; return result; } diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index e019dc15ef..e743a0cd01 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -79,11 +79,7 @@ namespace { namespace openspace::properties { PropertyOwner::PropertyOwner(PropertyOwnerInfo info) - : DocumentationGenerator( - "Property Owners", - "propertyOwners" - ) - , _identifier(std::move(info.identifier)) + : _identifier(std::move(info.identifier)) , _guiName(std::move(info.guiName)) , _description(std::move(info.description)) { @@ -416,8 +412,8 @@ nlohmann::json PropertyOwner::generateJsonJson() const { sortJson(json, "Name"); nlohmann::json result; - result[NameTag] = "PropertyOwner"; - result[DataTag] = json; + result["Name"] = "PropertyOwner"; + result["Data"] = json; return result; } diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index f9067692f8..85ba365d45 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -36,12 +36,7 @@ namespace openspace { -SceneLicenseWriter::SceneLicenseWriter() - : DocumentationGenerator( - "Scene Licenses", - "sceneLicense" - ) -{} +SceneLicenseWriter::SceneLicenseWriter() {} nlohmann::json SceneLicenseWriter::generateJsonJson() const { nlohmann::json json; @@ -119,8 +114,8 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { json.push_back(assetsJson); nlohmann::json result; - result[NameTag] = "Licenses"; - result[DataTag] = json; + result["Name"] = "Licenses"; + result["Data"] = json; return result; } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 1d559ee7fd..ff48510f30 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -191,14 +191,7 @@ namespace { namespace openspace::scripting { -ScriptEngine::ScriptEngine() - : DocumentationGenerator( - "Script Documentation", - "scripting" - ) -{ - //tracy::LuaRegister(_state); -} +ScriptEngine::ScriptEngine() {} void ScriptEngine::initialize() { ZoneScoped; @@ -577,8 +570,8 @@ nlohmann::json ScriptEngine::generateJsonJson() const { } nlohmann::json result; - result[NameTag] = "Scripting API"; - result[DataTag] = json; + result["Name"] = "Scripting API"; + result["Data"] = json; return result; } diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index c03c8e7d7d..e63905a94a 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -105,12 +105,7 @@ FactoryManager::FactoryNotFoundError::FactoryNotFoundError(std::string t) ghoul_assert(!type.empty(), "Type must not be empty"); } -FactoryManager::FactoryManager() - : DocumentationGenerator( - "Factory Documentation", - "factory" - ) -{} +FactoryManager::FactoryManager() {} void FactoryManager::initialize() { ghoul_assert(!_manager, "Factory Manager must not have been initialized"); @@ -229,8 +224,8 @@ nlohmann::json FactoryManager::generateJsonJson() const { // I did not check the output of this for correctness ---abock nlohmann::json result; - result[NameTag] = "Asset Types"; - result[DataTag] = json; + result["Name"] = "Asset Types"; + result["Data"] = json; return result; } From 3ad2d35cb41b37c93d708df8b328509296dec8db Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Tue, 25 Apr 2023 17:40:19 -0400 Subject: [PATCH 04/11] Make all json keys lower case --- documentation | 2 +- src/engine/openspaceengine.cpp | 4 +- src/interaction/keybindingmanager.cpp | 10 ++-- src/properties/propertyowner.cpp | 12 ++--- src/scene/scenelicensewriter.cpp | 68 +++++++++++++-------------- src/scripting/scriptengine.cpp | 30 ++++++------ src/util/factorymanager.cpp | 34 +++++++------- 7 files changed, 80 insertions(+), 80 deletions(-) diff --git a/documentation b/documentation index da776dab64..c4e5cb78a9 160000 --- a/documentation +++ b/documentation @@ -1 +1 @@ -Subproject commit da776dab64b6a9eaf6b36a05e5b047b294cf7144 +Subproject commit c4e5cb78a926da417c4c0a3cbba779ffca35a447 diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 5804763566..e2b653aff7 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1056,8 +1056,8 @@ void OpenSpaceEngine::writeDocumentation() { nlohmann::json sceneProperties = settings.get(); nlohmann::json sceneGraph = scene.get(); - sceneProperties["Data"] = "Settings"; - sceneGraph["Name"] = "Scene"; + sceneProperties["data"] = "Settings"; + sceneGraph["name"] = "Scene"; nlohmann::json documentation = { sceneGraph, sceneProperties, keybindings, license, scripting, factory diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 6018d9d351..cd1a1c4119 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -139,15 +139,15 @@ nlohmann::json KeybindingManager::generateJsonJson() const { for (const std::pair& p : _keyLua) { nlohmann::json keybind; - keybind["Name"] = ghoul::to_string(p.first); - keybind["Action"] = p.second; + keybind["name"] = ghoul::to_string(p.first); + keybind["action"] = p.second; json.push_back(std::move(keybind)); } - sortJson(json, "Name"); + sortJson(json, "name"); nlohmann::json result; - result["Name"] = "Keybindings"; - result["Keybindings"] = json; + result["name"] = "keybindings"; + result["keybindings"] = json; return result; } diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index e743a0cd01..d7fdc84982 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -389,7 +389,7 @@ std::string PropertyOwner::generateJson() const { nlohmann::json json; std::vector subOwners = propertySubOwners(); for (PropertyOwner* owner : subOwners) { - json["Data"].push_back(createJson(owner)); + json["data"].push_back(createJson(owner)); } return json.dump(); @@ -403,17 +403,17 @@ nlohmann::json PropertyOwner::generateJsonJson() const { for (PropertyOwner* owner : subOwners) { if (owner->identifier() != "Scene") { nlohmann::json jsonOwner = createJson(owner); - sortJson(jsonOwner["Properties"], "Name"); - sortJson(jsonOwner["PropertyOwners"], "Name"); + sortJson(jsonOwner["properties"], "name"); + sortJson(jsonOwner["propertyOwners"], "name"); json.push_back(jsonOwner); } } - sortJson(json, "Name"); + sortJson(json, "name"); nlohmann::json result; - result["Name"] = "PropertyOwner"; - result["Data"] = json; + result["name"] = "propertyOwner"; + result["data"] = json; return result; } diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index 85ba365d45..c4bf514df0 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -57,14 +57,14 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { if (global::profile->meta.has_value()) { metaTotal++; nlohmann::json metaJson; - metaJson["Name"] = "Profile"; - metaJson["ProfileName"] = global::profile->meta->name.value_or(""); - metaJson["Version"] = global::profile->meta->version.value_or(""); - metaJson["Description"] = global::profile->meta->description.value_or(""); - metaJson["Author"] = global::profile->meta->author.value_or(""); - metaJson["Url"] = global::profile->meta->url.value_or(""); - metaJson["License"] = global::profile->meta->license.value_or(""); - metaJson["Type"] = "license"; + metaJson["name"] = "profile"; + metaJson["profileName"] = global::profile->meta->name.value_or(""); + metaJson["version"] = global::profile->meta->version.value_or(""); + metaJson["description"] = global::profile->meta->description.value_or(""); + metaJson["author"] = global::profile->meta->author.value_or(""); + metaJson["url"] = global::profile->meta->url.value_or(""); + metaJson["license"] = global::profile->meta->license.value_or(""); + metaJson["type"] = "license"; json.push_back(std::move(metaJson)); } @@ -74,48 +74,48 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { nlohmann::json assetJson; if (!meta.has_value()) { - assetJson["Name"] = ""; - assetJson["Version"] = ""; - assetJson["Description"] = ""; - assetJson["Author"] = ""; - assetJson["Url"] = ""; - assetJson["License"] = "No license"; - assetJson["Identifiers"] = ""; - assetJson["Path"] = asset->path().string(); + assetJson["name"] = ""; + assetJson["version"] = ""; + assetJson["description"] = ""; + assetJson["author"] = ""; + assetJson["url"] = ""; + assetJson["license"] = "No license"; + assetJson["identifiers"] = ""; + assetJson["path"] = asset->path().string(); - assetLicenses["No license"].push_back(assetJson); + assetLicenses["noLicense"].push_back(assetJson); } else { - std::string license = meta->license == "" ? "No license" : meta->license; - assetJson["Name"] = meta->name; - assetJson["Version"] = meta->version; - assetJson["Description"] = meta->description; - assetJson["Author"] = meta->author; - assetJson["Url"] = meta->url; - assetJson["License"] = license; - assetJson["Identifiers"] = meta->identifiers; - assetJson["Path"] = asset->path().string(); + std::string license = meta->license == "" ? "No License" : meta->license; + assetJson["name"] = meta->name; + assetJson["version"] = meta->version; + assetJson["description"] = meta->description; + assetJson["author"] = meta->author; + assetJson["url"] = meta->url; + assetJson["license"] = license; + assetJson["identifiers"] = meta->identifiers; + assetJson["path"] = asset->path().string(); assetLicenses[license].push_back(assetJson); } } nlohmann::json assetsJson; - assetsJson["Name"] = "Assets"; - assetsJson["Type"] = "Licenses"; + assetsJson["name"] = "assets"; + assetsJson["type"] = "licenses"; for (const std::pair& assetLicense : assetLicenses) { nlohmann::json entry; - entry["Name"] = assetLicense.first; - entry["Assets"] = assetLicense.second; - sortJson(entry["Assets"], "Name"); - assetsJson["Licenses"].push_back(entry); + entry["name"] = assetLicense.first; + entry["assets"] = assetLicense.second; + sortJson(entry["assets"], "name"); + assetsJson["licenses"].push_back(entry); } json.push_back(assetsJson); nlohmann::json result; - result["Name"] = "Licenses"; - result["Data"] = json; + result["name"] = "licenses"; + result["data"] = json; return result; } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index ff48510f30..50954e4034 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -87,20 +87,20 @@ namespace { using namespace openspace; using namespace openspace::scripting; nlohmann::json function; - function["Name"] = f.name; + function["name"] = f.name; nlohmann::json arguments = nlohmann::json::array(); for (const LuaLibrary::Function::Argument& arg : f.arguments) { nlohmann::json argument; - argument["Name"] = arg.name; - argument["Type"] = arg.type; - argument["Default Value"] = arg.defaultValue.value_or(""); + argument["name"] = arg.name; + argument["type"] = arg.type; + argument["defaultValue"] = arg.defaultValue.value_or(""); arguments.push_back(argument); } - function["Arguments"] = arguments; - function["Return Type"] = f.returnType; - function["Help"] = f.helpText; + function["arguments"] = arguments; + function["returnType"] = f.returnType; + function["help"] = f.helpText; return function; } @@ -553,25 +553,25 @@ nlohmann::json ScriptEngine::generateJsonJson() const { using namespace openspace::scripting; nlohmann::json library; - std::string libraryName = l.name.empty() ? "openspace" : "openspace." + l.name; - library["Name"] = libraryName; + std::string libraryName = l.name; + library["name"] = libraryName; for (const LuaLibrary::Function& f : l.functions) { - library["Functions"].push_back(toJson(f)); + library["functions"].push_back(toJson(f)); } for (const LuaLibrary::Function& f : l.documentations) { - library["Functions"].push_back(toJson(f)); + library["functions"].push_back(toJson(f)); } - sortJson(library["Functions"], "Name"); + sortJson(library["functions"], "name"); json.push_back(library); - sortJson(json, "Name"); + sortJson(json, "name"); } nlohmann::json result; - result["Name"] = "Scripting API"; - result["Data"] = json; + result["name"] = "scripting"; + result["data"] = json; return result; } diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index e63905a94a..89aec6aa44 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -163,8 +163,8 @@ nlohmann::json FactoryManager::generateJsonJson() const { for (const FactoryInfo& factoryInfo : _factories) { nlohmann::json factory; - factory["Name"] = factoryInfo.name; - factory["Identifier"] = "category" + factoryInfo.name; + factory["name"] = factoryInfo.name; + factory["identifier"] = "category" + factoryInfo.name; ghoul::TemplateFactoryBase* f = factoryInfo.factory.get(); // Add documentation about base class @@ -176,15 +176,15 @@ nlohmann::json FactoryManager::generateJsonJson() const { }); if (factoryDoc != docs.end()) { nlohmann::json documentation = generateJsonDocumentation(*factoryDoc); - factory["Classes"].push_back(documentation); + factory["classes"].push_back(documentation); // Remove documentation from list check at the end if all docs got put in docs.erase(factoryDoc); } else { nlohmann::json documentation; - documentation["Name"] = factoryInfo.name; - documentation["Identifier"] = factoryInfo.name; - factory["Classes"].push_back(documentation); + documentation["name"] = factoryInfo.name; + documentation["identifier"] = factoryInfo.name; + factory["classes"].push_back(documentation); } // Add documentation about derived classes @@ -198,34 +198,34 @@ nlohmann::json FactoryManager::generateJsonJson() const { }); if (found != docs.end()) { nlohmann::json documentation = generateJsonDocumentation(*found); - factory["Classes"].push_back(documentation); + factory["classes"].push_back(documentation); docs.erase(found); } else { nlohmann::json documentation; - documentation["Name"] = c; - documentation["Identifier"] = c; - factory["Classes"].push_back(documentation); + documentation["name"] = c; + documentation["identifier"] = c; + factory["classes"].push_back(documentation); } } - sortJson(factory["Classes"], "Name"); + sortJson(factory["classes"], "name"); json.push_back(factory); } // Add all leftover docs nlohmann::json leftovers; - leftovers["Name"] = "Other"; - leftovers["Identifier"] = "other"; + leftovers["name"] = "other"; + leftovers["identifier"] = "other"; for (const Documentation& doc : docs) { - leftovers["Classes"].push_back(generateJsonDocumentation(doc)); + leftovers["classes"].push_back(generateJsonDocumentation(doc)); } - sortJson(json["Classes"]["Members"], "Name"); + sortJson(json["classes"]["members"], "name"); json.push_back(leftovers); // I did not check the output of this for correctness ---abock nlohmann::json result; - result["Name"] = "Asset Types"; - result["Data"] = json; + result["name"] = "assetTypes"; + result["data"] = json; return result; } From a668f08f0321dc770692b8c0137ba5bf8c4b80cf Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 13:33:39 -0400 Subject: [PATCH 05/11] Make documentation file use camelCase for the keys --- src/engine/openspaceengine.cpp | 3 ++- src/interaction/keybindingmanager.cpp | 2 +- src/properties/propertyowner.cpp | 26 +++++++++--------- src/scene/scenelicensewriter.cpp | 8 +++--- src/util/factorymanager.cpp | 38 ++++++++++++++------------- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index e2b653aff7..910548f138 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1056,8 +1056,9 @@ void OpenSpaceEngine::writeDocumentation() { nlohmann::json sceneProperties = settings.get(); nlohmann::json sceneGraph = scene.get(); - sceneProperties["data"] = "Settings"; + sceneProperties["name"] = "Settings"; sceneGraph["name"] = "Scene"; + scripting["name"] = "Scripting API"; nlohmann::json documentation = { sceneGraph, sceneProperties, keybindings, license, scripting, factory diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index cd1a1c4119..2d7eb659a3 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -146,7 +146,7 @@ nlohmann::json KeybindingManager::generateJsonJson() const { sortJson(json, "name"); nlohmann::json result; - result["name"] = "keybindings"; + result["name"] = "Keybindings"; result["keybindings"] = json; return result; } diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index d7fdc84982..418a6607d3 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -46,30 +46,30 @@ namespace { using namespace openspace; nlohmann::json json; - json["Name"] = owner->identifier(); + json["name"] = owner->identifier(); - json["Description"] = owner->description(); - json["Properties"] = nlohmann::json::array(); - json["PropertyOwners"] = nlohmann::json::array(); - json["Type"] = owner->type(); - json["Tags"] = owner->tags(); + json["description"] = owner->description(); + json["properties"] = nlohmann::json::array(); + json["propertyOwners"] = nlohmann::json::array(); + json["type"] = owner->type(); + json["tags"] = owner->tags(); const std::vector& properties = owner->properties(); for (properties::Property* p : properties) { nlohmann::json propertyJson; - propertyJson["Name"] = p->identifier(); - propertyJson["Type"] = p->className(); - propertyJson["URI"] = p->fullyQualifiedIdentifier(); - propertyJson["Gui Name"] = p->guiName(); - propertyJson["Description"] = p->description(); + propertyJson["name"] = p->identifier(); + propertyJson["type"] = p->className(); + propertyJson["uri"] = p->fullyQualifiedIdentifier(); + propertyJson["guiName"] = p->guiName(); + propertyJson["description"] = p->description(); - json["Properties"].push_back(propertyJson); + json["properties"].push_back(propertyJson); } auto propertyOwners = owner->propertySubOwners(); for (properties::PropertyOwner* o : propertyOwners) { nlohmann::json propertyOwner; - json["PropertyOwners"].push_back(createJson(o)); + json["propertyOwners"].push_back(createJson(o)); } return json; diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index c4bf514df0..8ab0eb3136 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -57,7 +57,7 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { if (global::profile->meta.has_value()) { metaTotal++; nlohmann::json metaJson; - metaJson["name"] = "profile"; + metaJson["name"] = "Profile"; metaJson["profileName"] = global::profile->meta->name.value_or(""); metaJson["version"] = global::profile->meta->version.value_or(""); metaJson["description"] = global::profile->meta->description.value_or(""); @@ -101,8 +101,8 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { } nlohmann::json assetsJson; - assetsJson["name"] = "assets"; - assetsJson["type"] = "licenses"; + assetsJson["name"] = "Assets"; + assetsJson["type"] = "Licenses"; for (const std::pair& assetLicense : assetLicenses) { nlohmann::json entry; @@ -114,7 +114,7 @@ nlohmann::json SceneLicenseWriter::generateJsonJson() const { json.push_back(assetsJson); nlohmann::json result; - result["name"] = "licenses"; + result["name"] = "Licenses"; result["data"] = json; return result; diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 89aec6aa44..fe4f1a6eb9 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -45,16 +45,16 @@ using namespace openspace::documentation; nlohmann::json generateJsonDocumentation(const Documentation& d) { nlohmann::json json; - json["Name"] = d.name; - json["Identifier"] = d.id; - json["Members"] = nlohmann::json::array(); + json["name"] = d.name; + json["identifier"] = d.id; + json["members"] = nlohmann::json::array(); for (const DocumentationEntry& p : d.entries) { nlohmann::json entry; - entry["Name"] = p.key; - entry["Optional"] = p.optional.value; - entry["Type"] = p.verifier->type(); - entry["Documentation"] = p.documentation; + entry["name"] = p.key; + entry["optional"] = p.optional.value; + entry["type"] = p.verifier->type(); + entry["documentation"] = p.documentation; TableVerifier* tv = dynamic_cast(p.verifier.get()); ReferencingVerifier* rv = dynamic_cast(p.verifier.get()); @@ -68,27 +68,28 @@ nlohmann::json generateJsonDocumentation(const Documentation& d) { ); if (it == documentations.end()) { - entry["Reference"]["Found"] = false; + entry["reference"]["found"] = false; } else { nlohmann::json reference; - reference["Found"] = true; - reference["Name"] = it->name; - reference["Identifier"] = rv->identifier; + reference["found"] = true; + reference["name"] = it->name; + reference["identifier"] = rv->identifier; - entry["Reference"] = reference; + entry["reference"] = reference; } } else if (tv) { nlohmann::json json = generateJsonDocumentation(tv->documentations); // We have a TableVerifier, so we need to recurse - entry["Restrictions"] = json; + entry["restrictions"] = json; } else { - entry["Description"] = p.verifier->documentation(); + entry["description"] = p.verifier->documentation(); } - json["Members"].push_back(entry); + json["members"].push_back(entry); } + sortJson(json["members"], "name"); return json; } @@ -213,18 +214,19 @@ nlohmann::json FactoryManager::generateJsonJson() const { } // Add all leftover docs nlohmann::json leftovers; - leftovers["name"] = "other"; + leftovers["name"] = "Other"; leftovers["identifier"] = "other"; for (const Documentation& doc : docs) { leftovers["classes"].push_back(generateJsonDocumentation(doc)); } - sortJson(json["classes"]["members"], "name"); + sortJson(leftovers["classes"], "name"); json.push_back(leftovers); + sortJson(json, "name"); // I did not check the output of this for correctness ---abock nlohmann::json result; - result["name"] = "assetTypes"; + result["name"] = "Asset Types"; result["data"] = json; return result; From e0fc813525a71e0756e9d9ab27c0e7a1c1504b14 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 15:10:32 -0400 Subject: [PATCH 06/11] Update scripting documentation to be backwards compatible --- src/engine/openspaceengine.cpp | 9 +++++++-- src/scripting/scriptengine.cpp | 30 ++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 910548f138..ee5d487170 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1058,10 +1058,15 @@ void OpenSpaceEngine::writeDocumentation() { sceneProperties["name"] = "Settings"; sceneGraph["name"] = "Scene"; - scripting["name"] = "Scripting API"; + + // Add this here so that the generateJson function is the same as before to ensure + // backwards compatibility + nlohmann::json scriptingResult; + scriptingResult["name"] = "Scripting API"; + scriptingResult["data"] = scripting; nlohmann::json documentation = { - sceneGraph, sceneProperties, keybindings, license, scripting, factory + sceneGraph, sceneProperties, keybindings, license, scriptingResult, factory }; nlohmann::json result; diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 50954e4034..f38cbd731f 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -83,7 +83,9 @@ namespace { - nlohmann::json toJson(const openspace::scripting::LuaLibrary::Function& f) { + nlohmann::json toJson(const openspace::scripting::LuaLibrary::Function& f, + bool includeSourceLocation) + { using namespace openspace; using namespace openspace::scripting; nlohmann::json function; @@ -102,6 +104,13 @@ namespace { function["returnType"] = f.returnType; function["help"] = f.helpText; + if (includeSourceLocation) { + nlohmann::json sourceLocation; + sourceLocation["file"] = f.sourceLocation.file; + sourceLocation["line"] = f.sourceLocation.line; + function["sourceLocation"] = sourceLocation; + } + return function; } @@ -554,26 +563,27 @@ nlohmann::json ScriptEngine::generateJsonJson() const { nlohmann::json library; std::string libraryName = l.name; + // Keep the library key for backwards compatability + library["library"] = libraryName; library["name"] = libraryName; + std::string os = "openspace"; + library["fullName"] = libraryName.empty() ? os : os + "." + libraryName; for (const LuaLibrary::Function& f : l.functions) { - library["functions"].push_back(toJson(f)); + bool hasSourceLocation = true; + library["functions"].push_back(toJson(f, hasSourceLocation)); } for (const LuaLibrary::Function& f : l.documentations) { - library["functions"].push_back(toJson(f)); + bool hasSourceLocation = false; + library["functions"].push_back(toJson(f, hasSourceLocation)); } sortJson(library["functions"], "name"); json.push_back(library); - sortJson(json, "name"); + sortJson(json, "library"); } - - nlohmann::json result; - result["name"] = "scripting"; - result["data"] = json; - - return result; + return json; } void ScriptEngine::writeLog(const std::string& script) { From a88fb968274435247f19deca564ee12405a1b0b7 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 16:30:47 -0400 Subject: [PATCH 07/11] Sort properties --- src/properties/propertyowner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 418a6607d3..eb31b58e49 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -65,12 +65,14 @@ namespace { json["properties"].push_back(propertyJson); } + sortJson(json["properties"], "name"); auto propertyOwners = owner->propertySubOwners(); for (properties::PropertyOwner* o : propertyOwners) { nlohmann::json propertyOwner; json["propertyOwners"].push_back(createJson(o)); } + sortJson(json["propertyOwners"], "name"); return json; } @@ -403,8 +405,6 @@ nlohmann::json PropertyOwner::generateJsonJson() const { for (PropertyOwner* owner : subOwners) { if (owner->identifier() != "Scene") { nlohmann::json jsonOwner = createJson(owner); - sortJson(jsonOwner["properties"], "name"); - sortJson(jsonOwner["propertyOwners"], "name"); json.push_back(jsonOwner); } From 529ffc488cc60f85ef2f70533b320d62ad996527 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 16:39:07 -0400 Subject: [PATCH 08/11] Use the gui name as the name for properties --- src/properties/propertyowner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index eb31b58e49..59e0cb6de4 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -46,7 +46,7 @@ namespace { using namespace openspace; nlohmann::json json; - json["name"] = owner->identifier(); + json["name"] = !owner->guiName().empty() ? owner->guiName() : owner->identifier(); json["description"] = owner->description(); json["properties"] = nlohmann::json::array(); @@ -57,10 +57,11 @@ namespace { const std::vector& properties = owner->properties(); for (properties::Property* p : properties) { nlohmann::json propertyJson; - propertyJson["name"] = p->identifier(); + std::string name = !p->guiName().empty() ? p->guiName() : p->identifier(); + propertyJson["name"] = name; propertyJson["type"] = p->className(); propertyJson["uri"] = p->fullyQualifiedIdentifier(); - propertyJson["guiName"] = p->guiName(); + propertyJson["identifier"] = p->identifier(); propertyJson["description"] = p->description(); json["properties"].push_back(propertyJson); From 9a1e6b800227ed2c7855e7b61efdb436847b7f57 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 16:58:55 -0400 Subject: [PATCH 09/11] Remove old json functions --- .../openspace/interaction/keybindingmanager.h | 3 +- include/openspace/properties/propertyowner.h | 4 +- include/openspace/scene/scenelicensewriter.h | 2 +- include/openspace/scripting/scriptengine.h | 3 +- include/openspace/util/factorymanager.h | 3 +- .../server/src/topics/documentationtopic.cpp | 12 +- src/engine/openspaceengine.cpp | 12 +- src/interaction/keybindingmanager.cpp | 23 +--- src/properties/propertyowner.cpp | 14 +-- src/scene/scenelicensewriter.cpp | 2 +- src/scripting/scriptengine.cpp | 106 +----------------- src/util/factorymanager.cpp | 20 +--- 12 files changed, 21 insertions(+), 183 deletions(-) diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index 55f0e3ae9e..cca79962c6 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -53,8 +53,7 @@ public: void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); - std::string generateJson() const; - nlohmann::json generateJsonJson() const; + nlohmann::json generateJson() const; const std::multimap& keyBindings() const; diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 81b199808b..e803fa8930 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -295,9 +295,7 @@ public: void removeTag(const std::string& tag); // Generate JSON for documentation - std::string generateJson() const; - - nlohmann::json generateJsonJson() const; + nlohmann::json generateJson() const; protected: /// The unique identifier of this PropertyOwner diff --git a/include/openspace/scene/scenelicensewriter.h b/include/openspace/scene/scenelicensewriter.h index 0438d7c4d0..e534ded559 100644 --- a/include/openspace/scene/scenelicensewriter.h +++ b/include/openspace/scene/scenelicensewriter.h @@ -34,7 +34,7 @@ class SceneLicenseWriter { public: SceneLicenseWriter(); std::string generateJson() const; - nlohmann::json generateJsonJson() const; + nlohmann::json generateJsonGroupedByLicense() const; }; } // namespace openspace diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 11e3e54a1a..8221fee70a 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -94,8 +94,7 @@ public: std::vector allLuaFunctions() const; - std::string generateJson() const; - nlohmann::json generateJsonJson() const; + nlohmann::json generateJson() const; private: BooleanType(Replace); diff --git a/include/openspace/util/factorymanager.h b/include/openspace/util/factorymanager.h index bfb195341d..fcf8ef7eac 100644 --- a/include/openspace/util/factorymanager.h +++ b/include/openspace/util/factorymanager.h @@ -107,8 +107,7 @@ public: template ghoul::TemplateFactory* factory() const; - std::string generateJson() const; - nlohmann::json generateJsonJson() const; + nlohmann::json generateJson() const; private: /// Singleton member for the Factory Manager diff --git a/modules/server/src/topics/documentationtopic.cpp b/modules/server/src/topics/documentationtopic.cpp index 3cf8c74585..b385fb39f3 100644 --- a/modules/server/src/topics/documentationtopic.cpp +++ b/modules/server/src/topics/documentationtopic.cpp @@ -47,21 +47,19 @@ void DocumentationTopic::handleJson(const nlohmann::json& json) { // Do not parse generated json. Instead implement ability to get // ghoul::Dictionary objects from ScriptEngine, FactoryManager, and KeybindingManager. if (requestedType == "lua") { - response = json::parse(global::scriptEngine->generateJson()); + response = global::scriptEngine->generateJson(); } else if (requestedType == "factories") { - response = json::parse(FactoryManager::ref().generateJson()); + response = FactoryManager::ref().generateJson(); } else if (requestedType == "keyboard") { - response = json::parse(global::keybindingManager->generateJson()); + response = global::keybindingManager->generateJson(); } else if (requestedType == "asset") { - response = json::parse(global::keybindingManager->generateJson()); + response = global::keybindingManager->generateJson(); } else if (requestedType == "meta") { - std::string docs = SceneLicenseWriter().generateJson(); - nlohmann::json parsedDocs = json::parse(docs); - response = parsedDocs; + response = SceneLicenseWriter().generateJson(); } _connection->sendJson(wrappedPayload(response)); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ee5d487170..2d981448f7 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1039,20 +1039,20 @@ void OpenSpaceEngine::writeDocumentation() { // Start the async requests as soon as possible so they are finished when we need them std::future settings = std::async( - &properties::PropertyOwner::generateJsonJson, + &properties::PropertyOwner::generateJson, global::rootPropertyOwner ); std::future scene = std::async( - &properties::PropertyOwner::generateJsonJson, + &properties::PropertyOwner::generateJson, _scene.get() ); SceneLicenseWriter writer; - nlohmann::json scripting = global::scriptEngine->generateJsonJson(); - nlohmann::json factory = FactoryManager::ref().generateJsonJson(); - nlohmann::json keybindings = global::keybindingManager->generateJsonJson(); - nlohmann::json license = writer.generateJsonJson(); + nlohmann::json scripting = global::scriptEngine->generateJson(); + nlohmann::json factory = FactoryManager::ref().generateJson(); + nlohmann::json keybindings = global::keybindingManager->generateJson(); + nlohmann::json license = writer.generateJsonGroupedByLicense(); nlohmann::json sceneProperties = settings.get(); nlohmann::json sceneGraph = scene.get(); diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 2d7eb659a3..b086e3f524 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -111,28 +111,7 @@ const std::multimap& KeybindingManager::keyBinding return _keyLua; } -std::string KeybindingManager::generateJson() const { - ZoneScoped; - - std::stringstream json; - json << "["; - bool first = true; - for (const std::pair& p : _keyLua) { - if (!first) { - json << ","; - } - first = false; - json << "{"; - json << R"("key": ")" << ghoul::to_string(p.first) << "\","; - json << R"("action": ")" << p.second << "\""; - json << "}"; - } - json << "]"; - - return json.str(); -} - -nlohmann::json KeybindingManager::generateJsonJson() const { +nlohmann::json KeybindingManager::generateJson() const { ZoneScoped; nlohmann::json json; diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 59e0cb6de4..be1eacf9a8 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -386,19 +386,7 @@ void PropertyOwner::removeTag(const std::string& tag) { _tags.erase(std::remove(_tags.begin(), _tags.end(), tag), _tags.end()); } -std::string PropertyOwner::generateJson() const { - ZoneScoped; - - nlohmann::json json; - std::vector subOwners = propertySubOwners(); - for (PropertyOwner* owner : subOwners) { - json["data"].push_back(createJson(owner)); - } - - return json.dump(); -} - -nlohmann::json PropertyOwner::generateJsonJson() const { +nlohmann::json PropertyOwner::generateJson() const { ZoneScoped nlohmann::json json; diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index 8ab0eb3136..2c38c5b417 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -38,7 +38,7 @@ namespace openspace { SceneLicenseWriter::SceneLicenseWriter() {} -nlohmann::json SceneLicenseWriter::generateJsonJson() const { +nlohmann::json SceneLicenseWriter::generateJsonGroupedByLicense() const { nlohmann::json json; std::vector assets = diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index f38cbd731f..d70328d81b 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -81,8 +81,6 @@ namespace { return result; } - - nlohmann::json toJson(const openspace::scripting::LuaLibrary::Function& f, bool includeSourceLocation) { @@ -114,87 +112,6 @@ namespace { return function; } - void toJson(const openspace::scripting::LuaLibrary& library, std::stringstream& json) - { - constexpr std::string_view replStr = R"("{}": "{}", )"; - constexpr std::string_view replStr2 = R"("{}": "{}")"; - - using namespace openspace; - using namespace openspace::scripting; - - json << "{"; - json << fmt::format(replStr, "library", library.name); - json << "\"functions\": ["; - - for (const LuaLibrary::Function& f : library.functions) { - json << "{"; - json << fmt::format(replStr, "name", f.name); - json << "\"arguments\": ["; - for (const LuaLibrary::Function::Argument& arg : f.arguments) { - json << "{"; - json << fmt::format(replStr, "name", escapedJson(arg.name)); - json << fmt::format(replStr, "type", escapedJson(arg.type)); - json << fmt::format( - replStr2, "defaultValue", escapedJson(arg.defaultValue.value_or("")) - ); - json << "}"; - - if (&arg != &f.arguments.back()) { - json << ","; - } - } - json << "],"; - json << fmt::format(replStr, "returnType", escapedJson(f.returnType)); - json << fmt::format(replStr, "help", escapedJson(f.helpText)); - json << fmt::format( - "\"sourceLocation\": {{ \"file\": \"{}\", \"line\": {} }}", - escapedJson(f.sourceLocation.file), f.sourceLocation.line - ); - json << "}"; - if (&f != &library.functions.back() || !library.documentations.empty()) { - json << ","; - } - } - - - for (const LuaLibrary::Function& f : library.documentations) { - json << "{"; - json << fmt::format(replStr, "name", f.name); - json << "\"arguments\": ["; - for (const LuaLibrary::Function::Argument& arg : f.arguments) { - json << "{"; - json << fmt::format(replStr, "name", escapedJson(arg.name)); - json << fmt::format(replStr, "type", escapedJson(arg.type)); - json << fmt::format( - replStr2, "defaultValue", escapedJson(arg.defaultValue.value_or("")) - ); - json << "}"; - - if (&arg != &f.arguments.back()) { - json << ","; - } - } - json << "],"; - json << fmt::format(replStr, "returnType", escapedJson(f.returnType)); - json << fmt::format(replStr2, "help", escapedJson(f.helpText)); - json << "}"; - if (&f != &library.documentations.back()) { - json << ","; - } - } - - json << "],"; - - json << "\"subLibraries\": ["; - for (const LuaLibrary& sl : library.subLibraries) { - toJson(sl, json); - if (&sl != &library.subLibraries.back()) { - json << ","; - } - } - json << "]}"; - } - #include "scriptengine_codegen.cpp" } // namespace @@ -531,28 +448,7 @@ std::vector ScriptEngine::allLuaFunctions() const { return result; } -std::string ScriptEngine::generateJson() const { - ZoneScoped; - - // Create JSON - std::stringstream json; - json << "["; - - bool first = true; - for (const LuaLibrary& l : _registeredLibraries) { - if (!first) { - json << ","; - } - first = false; - - toJson(l, json); - } - json << "]"; - - return json.str(); -} - -nlohmann::json ScriptEngine::generateJsonJson() const { +nlohmann::json ScriptEngine::generateJson() const { ZoneScoped nlohmann::json json; diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index fe4f1a6eb9..3a25376388 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -140,25 +140,7 @@ FactoryManager& FactoryManager::ref() { return *_manager; } -std::string FactoryManager::generateJson() const { - nlohmann::json json; - - for (const FactoryInfo& factoryInfo : _factories) { - nlohmann::json factory; - factory["Name"] = factoryInfo.name; - - ghoul::TemplateFactoryBase* f = factoryInfo.factory.get(); - const std::vector& registeredClasses = f->registeredClasses(); - for (const std::string& c : registeredClasses) { - json["Classes"].push_back(c); - } - json["Data"].push_back(factory); - } - - return json.dump(); -} - -nlohmann::json FactoryManager::generateJsonJson() const { +nlohmann::json FactoryManager::generateJson() const { nlohmann::json json; std::vector docs = DocEng.documentations(); From d6ddd86a35671c5bbeef4e2f1e5c3fec76b50673 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 17:30:51 -0400 Subject: [PATCH 10/11] Rewrite asset json function to nlohmann::json --- include/openspace/scene/scenelicensewriter.h | 2 +- .../server/src/topics/documentationtopic.cpp | 2 +- src/scene/scenelicensewriter.cpp | 93 +++++-------------- 3 files changed, 25 insertions(+), 72 deletions(-) diff --git a/include/openspace/scene/scenelicensewriter.h b/include/openspace/scene/scenelicensewriter.h index e534ded559..4a183e3a1b 100644 --- a/include/openspace/scene/scenelicensewriter.h +++ b/include/openspace/scene/scenelicensewriter.h @@ -33,7 +33,7 @@ namespace openspace { class SceneLicenseWriter { public: SceneLicenseWriter(); - std::string generateJson() const; + nlohmann::json generateJsonList() const; nlohmann::json generateJsonGroupedByLicense() const; }; diff --git a/modules/server/src/topics/documentationtopic.cpp b/modules/server/src/topics/documentationtopic.cpp index b385fb39f3..3c2e0c16f0 100644 --- a/modules/server/src/topics/documentationtopic.cpp +++ b/modules/server/src/topics/documentationtopic.cpp @@ -59,7 +59,7 @@ void DocumentationTopic::handleJson(const nlohmann::json& json) { response = global::keybindingManager->generateJson(); } else if (requestedType == "meta") { - response = SceneLicenseWriter().generateJson(); + response = SceneLicenseWriter().generateJsonList(); } _connection->sendJson(wrappedPayload(response)); diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index 2c38c5b417..93b116a8f7 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -120,61 +120,23 @@ nlohmann::json SceneLicenseWriter::generateJsonGroupedByLicense() const { return result; } -std::string SceneLicenseWriter::generateJson() const { - ZoneScoped; +nlohmann::json SceneLicenseWriter::generateJsonList() const { + nlohmann::json json; - std::stringstream json; - json << "["; + if (global::profile->meta.has_value()) { + nlohmann::json profile; + profile["name"] = global::profile->meta->name.value_or(""); + profile["version"] = global::profile->meta->version.value_or(""); + profile["description"] = global::profile->meta->description.value_or(""); + profile["author"] = global::profile->meta->author.value_or(""); + profile["url"] = global::profile->meta->url.value_or(""); + profile["license"] = global::profile->meta->license.value_or(""); + json.push_back(profile); + } std::vector assets = global::openSpaceEngine->assetManager().allAssets(); - int metaTotal = 0; - int metaCount = 0; - for (const Asset* asset : assets) { - std::optional meta = asset->metaInformation(); - if (!meta.has_value()) { - continue; - } - metaTotal++; - } - - if (global::profile->meta.has_value()) { - metaTotal++; - constexpr std::string_view replStr = R"("{}": "{}", )"; - constexpr std::string_view replStr2 = R"("{}": "{}")"; - json << "{"; - json << fmt::format( - replStr, - "name", escapedJson(global::profile->meta->name.value_or("")) - ); - json << fmt::format( - replStr, - "version", escapedJson(global::profile->meta->version.value_or("")) - ); - json << fmt::format( - replStr, - "description", escapedJson(global::profile->meta->description.value_or("")) - ); - json << fmt::format( - replStr, - "author", escapedJson(global::profile->meta->author.value_or("")) - ); - json << fmt::format( - replStr, - "url", escapedJson(global::profile->meta->url.value_or("")) - ); - json << fmt::format( - replStr2, - "license", escapedJson(global::profile->meta->license.value_or("")) - ); - json << "}"; - - if (++metaCount != metaTotal) { - json << ","; - } - } - for (const Asset* asset : assets) { std::optional meta = asset->metaInformation(); @@ -182,27 +144,18 @@ std::string SceneLicenseWriter::generateJson() const { continue; } - constexpr std::string_view replStr = R"("{}": "{}", )"; - constexpr std::string_view replStr2 = R"("{}": "{}")"; - json << "{"; - json << fmt::format(replStr, "name", escapedJson(meta->name)); - json << fmt::format(replStr, "version", escapedJson(meta->version)); - json << fmt::format(replStr, "description", escapedJson(meta->description)); - json << fmt::format(replStr, "author", escapedJson(meta->author)); - json << fmt::format(replStr, "url", escapedJson(meta->url)); - json << fmt::format(replStr, "license", escapedJson(meta->license)); - json << fmt::format(replStr, "identifiers", escapedJson(meta->identifiers)); - json << fmt::format(replStr2, "path", escapedJson(asset->path().string())); - json << "}"; + nlohmann::json assetJson; + assetJson["name"] = meta->name; + assetJson["version"] = meta->version; + assetJson["description"] = meta->description; + assetJson["author"] = meta->author; + assetJson["url"] = meta->url; + assetJson["license"] = meta->license; + assetJson["identifiers"] = meta->identifiers; + assetJson["path"] = asset->path().string(); - metaCount++; - if (metaCount != metaTotal) { - json << ","; - } + json.push_back(assetJson); } - - json << "]"; - return json.str(); + return json; } - } // namespace openspace From ed34d5e4a6fdaaa799e716d8aa84c8bf7ed24aad Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 26 Apr 2023 17:36:01 -0400 Subject: [PATCH 11/11] Update documentation to new format (lower case keys and backwards compatible) --- documentation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation b/documentation index c4e5cb78a9..3917fa57e4 160000 --- a/documentation +++ b/documentation @@ -1 +1 @@ -Subproject commit c4e5cb78a926da417c4c0a3cbba779ffca35a447 +Subproject commit 3917fa57e47503e30e20d4059be9b54b729a5ea2