From 74f4e27f43339ba7fafff42aba1a964814b354f3 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Fri, 23 Feb 2024 16:44:49 +0100 Subject: [PATCH] Move property owner json documentation to documentation engine --- .../documentation/documentationengine.h | 2 + src/documentation/documentationengine.cpp | 71 +++++++++++++++++-- src/properties/propertyowner.cpp | 58 --------------- 3 files changed, 68 insertions(+), 63 deletions(-) diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index 37af2cfa39..055836ed1d 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -91,6 +91,8 @@ public: nlohmann::json generateScriptEngineJson() const; nlohmann::json generateFactoryManagerJson() const; nlohmann::json generateKeybindingsJson() const; + nlohmann::json generatePropertyOwnerJson(properties::PropertyOwner* owner) const; + private: /// The list of all Documentation%s that are stored by the DocumentationEngine std::vector _documentations; diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index 43cedcdcb0..4272e9921e 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -103,6 +103,43 @@ nlohmann::json generateJsonDocumentation(const Documentation& d) { return json; } +nlohmann::json createPropertyJson(openspace::properties::PropertyOwner* owner) { + ZoneScoped; + + using namespace openspace; + nlohmann::json json; + json["name"] = !owner->guiName().empty() ? owner->guiName() : owner->identifier(); + + 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; + std::string name = !p->guiName().empty() ? p->guiName() : p->identifier(); + propertyJson["name"] = name; + propertyJson["type"] = p->className(); + propertyJson["uri"] = p->fullyQualifiedIdentifier(); + propertyJson["identifier"] = p->identifier(); + propertyJson["description"] = p->description(); + + 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(createPropertyJson(o)); + } + sortJson(json["propertyOwners"], "name"); + + return json; +} + nlohmann::json LuaFunctionToJson(const openspace::scripting::LuaLibrary::Function& f, bool includeSourceLocation) { @@ -302,6 +339,28 @@ nlohmann::json DocumentationEngine::generateKeybindingsJson() const { return result; } +nlohmann::json DocumentationEngine::generatePropertyOwnerJson( + properties::PropertyOwner* owner) const { + ZoneScoped; + + nlohmann::json json; + std::vector subOwners = owner->propertySubOwners(); + for (properties::PropertyOwner* owner : subOwners) { + if (owner->identifier() != "Scene") { + nlohmann::json jsonOwner = createPropertyJson(owner); + + json.push_back(jsonOwner); + } + } + sortJson(json, "name"); + + nlohmann::json result; + result["name"] = "propertyOwner"; + result["data"] = json; + + return result; +} + void DocumentationEngine::writeDocumentation() const { ZoneScoped; @@ -315,12 +374,14 @@ void DocumentationEngine::writeDocumentation() const { // Start the async requests as soon as possible so they are finished when we need them std::future settings = std::async( - &properties::PropertyOwner::generateJson, + &DocumentationEngine::generatePropertyOwnerJson, + this, global::rootPropertyOwner ); std::future sceneJson = std::async( - &properties::PropertyOwner::generateJson, + &DocumentationEngine::generatePropertyOwnerJson, + this, global::renderEngine->scene() ); @@ -328,7 +389,7 @@ void DocumentationEngine::writeDocumentation() const { nlohmann::json scripting = generateScriptEngineJson(); nlohmann::json factory = generateFactoryManagerJson(); - nlohmann::json keybindings = global::keybindingManager->generateJson(); + nlohmann::json keybindings = generateKeybindingsJson(); nlohmann::json license = writer.generateJsonGroupedByLicense(); nlohmann::json sceneProperties = settings.get(); nlohmann::json sceneGraph = sceneJson.get(); @@ -345,7 +406,8 @@ void DocumentationEngine::writeDocumentation() const { scriptingResult["data"] = scripting; nlohmann::json documentation = { - sceneGraph, sceneProperties, actions, events, keybindings, license, scriptingResult, factory + sceneGraph, sceneProperties, actions, events, keybindings, license, + scriptingResult, factory }; nlohmann::json result; @@ -356,7 +418,6 @@ void DocumentationEngine::writeDocumentation() const { out.close(); } - void DocumentationEngine::addDocumentation(Documentation documentation) { if (documentation.id.empty()) { _documentations.push_back(std::move(documentation)); diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 6478b7ec11..3ace8786c2 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -40,43 +40,6 @@ namespace { constexpr std::string_view _loggerCat = "PropertyOwner"; - - nlohmann::json createJson(openspace::properties::PropertyOwner* owner) { - ZoneScoped; - - using namespace openspace; - nlohmann::json json; - json["name"] = !owner->guiName().empty() ? owner->guiName() : owner->identifier(); - - 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; - std::string name = !p->guiName().empty() ? p->guiName() : p->identifier(); - propertyJson["name"] = name; - propertyJson["type"] = p->className(); - propertyJson["uri"] = p->fullyQualifiedIdentifier(); - propertyJson["identifier"] = p->identifier(); - propertyJson["description"] = p->description(); - - 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; - } } // namespace namespace openspace::properties { @@ -386,25 +349,4 @@ void PropertyOwner::removeTag(const std::string& tag) { _tags.erase(std::remove(_tags.begin(), _tags.end(), tag), _tags.end()); } -nlohmann::json PropertyOwner::generateJson() const { - ZoneScoped; - - nlohmann::json json; - std::vector subOwners = propertySubOwners(); - for (PropertyOwner* owner : subOwners) { - if (owner->identifier() != "Scene") { - nlohmann::json jsonOwner = createJson(owner); - - json.push_back(jsonOwner); - } - } - sortJson(json, "name"); - - nlohmann::json result; - result["name"] = "propertyOwner"; - result["data"] = json; - - return result; -} - } // namespace openspace::properties