Move function from SceneLicenseWriter to DocumentationEngine and remove SceneLicenseWriter files

This commit is contained in:
Ylva Selling
2024-02-26 09:10:52 +01:00
parent 9c16bd689f
commit 3fdac4a6d0
8 changed files with 129 additions and 214 deletions
@@ -92,6 +92,8 @@ public:
nlohmann::json generateFactoryManagerJson() const;
nlohmann::json generateKeybindingsJson() const;
nlohmann::json generatePropertyOwnerJson(properties::PropertyOwner* owner) const;
nlohmann::json generateLicensesGroupedByLicense() const;
nlohmann::json generateLicenseList() const;
private:
/// The list of all Documentation%s that are stored by the DocumentationEngine
@@ -1,42 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2024 *
* *
* 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___SCENELICENSEWRITER___H__
#define __OPENSPACE_CORE___SCENELICENSEWRITER___H__
#include <openspace/json.h>
#include <vector>
namespace openspace {
class SceneLicenseWriter {
public:
SceneLicenseWriter();
nlohmann::json generateJsonList() const;
nlohmann::json generateJsonGroupedByLicense() const;
};
} // namespace openspace
#endif // __OPENSPACE_CORE___SCENELICENSEWRITER___H__
@@ -31,7 +31,6 @@
#include <openspace/documentation/documentationengine.h>
#include <openspace/util/factorymanager.h>
#include <openspace/interaction/keybindingmanager.h>
#include <openspace/scene/scenelicensewriter.h>
#include <ghoul/logging/logmanager.h>
using nlohmann::json;
@@ -59,7 +58,7 @@ void DocumentationTopic::handleJson(const nlohmann::json& json) {
// TODO: Add asset documentation here
}
else if (requestedType == "meta") {
response = SceneLicenseWriter().generateJsonList();
response = DocEng.generateLicenseList();
}
_connection->sendJson(wrappedPayload(response));
-2
View File
@@ -155,7 +155,6 @@ set(OPENSPACE_SOURCE
scene/scene.cpp
scene/scene_lua.inl
scene/sceneinitializer.cpp
scene/scenelicensewriter.cpp
scene/scenegraphnode.cpp
scene/timeframe.cpp
scene/translation.cpp
@@ -347,7 +346,6 @@ set(OPENSPACE_HEADER
${PROJECT_SOURCE_DIR}/include/openspace/scene/scale.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/scene.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/sceneinitializer.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/scenelicensewriter.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/scenegraphnode.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/timeframe.h
${PROJECT_SOURCE_DIR}/include/openspace/scene/translation.h
+126 -4
View File
@@ -27,6 +27,7 @@
#include <openspace/openspace.h>
#include <openspace/documentation/core_registration.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/configuration.h>
#include <openspace/events/eventengine.h>
@@ -34,8 +35,9 @@
#include <openspace/interaction/keybindingmanager.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/json.h>
#include <openspace/scene/asset.h>
#include <openspace/scene/assetmanager.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenelicensewriter.h>
#include <openspace/scripting/scriptscheduler.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/factorymanager.h>
@@ -241,6 +243,128 @@ nlohmann::json DocumentationEngine::generateScriptEngineJson() const {
return json;
}
nlohmann::json DocumentationEngine::generateLicensesGroupedByLicense() const {
nlohmann::json json;
std::vector<const Asset*> assets =
global::openSpaceEngine->assetManager().allAssets();
int metaTotal = 0;
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
if (!meta.has_value()) {
continue;
}
metaTotal++;
}
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";
json.push_back(std::move(metaJson));
}
std::map<std::string, nlohmann::json> assetLicenses;
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
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();
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();
assetLicenses[license].push_back(assetJson);
}
}
nlohmann::json assetsJson;
assetsJson["name"] = "Assets";
assetsJson["type"] = "Licenses";
using K = const std::string;
using V = nlohmann::json;
for (const std::pair<K, V>& assetLicense : assetLicenses) {
nlohmann::json 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;
return result;
}
nlohmann::json DocumentationEngine::generateLicenseList() const {
nlohmann::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<const Asset*> assets =
global::openSpaceEngine->assetManager().allAssets();
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
if (!meta.has_value()) {
continue;
}
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();
json.push_back(assetJson);
}
return json;
}
nlohmann::json DocumentationEngine::generateFactoryManagerJson() const {
nlohmann::json json;
@@ -385,12 +509,10 @@ void DocumentationEngine::writeDocumentation() const {
global::renderEngine->scene()
);
SceneLicenseWriter writer;
nlohmann::json scripting = generateScriptEngineJson();
nlohmann::json factory = generateFactoryManagerJson();
nlohmann::json keybindings = generateKeybindingsJson();
nlohmann::json license = writer.generateJsonGroupedByLicense();
nlohmann::json license = generateLicensesGroupedByLicense();
nlohmann::json sceneProperties = settings.get();
nlohmann::json sceneGraph = sceneJson.get();
nlohmann::json actions = global::actionManager->generateJson();
-1
View File
@@ -56,7 +56,6 @@
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/sceneinitializer.h>
#include <openspace/scene/scenelicensewriter.h>
#include <openspace/scripting/scriptscheduler.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/factorymanager.h>
-1
View File
@@ -38,7 +38,6 @@
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/profile.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/scenelicensewriter.h>
#include <openspace/scene/sceneinitializer.h>
#include <openspace/scripting/lualibrary.h>
#include <openspace/scripting/scriptengine.h>
-162
View File
@@ -1,162 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2024 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/scene/scenelicensewriter.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/asset.h>
#include <openspace/scene/assetmanager.h>
#include <openspace/scene/profile.h>
#include <openspace/util/json_helper.h>
#include <ghoul/fmt.h>
#include <ghoul/misc/profiling.h>
#include <sstream>
namespace openspace {
SceneLicenseWriter::SceneLicenseWriter() {}
nlohmann::json SceneLicenseWriter::generateJsonGroupedByLicense() const {
nlohmann::json json;
std::vector<const Asset*> assets =
global::openSpaceEngine->assetManager().allAssets();
int metaTotal = 0;
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
if (!meta.has_value()) {
continue;
}
metaTotal++;
}
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";
json.push_back(std::move(metaJson));
}
std::map<std::string, nlohmann::json> assetLicenses;
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
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();
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();
assetLicenses[license].push_back(assetJson);
}
}
nlohmann::json assetsJson;
assetsJson["name"] = "Assets";
assetsJson["type"] = "Licenses";
using K = const std::string;
using V = nlohmann::json;
for (const std::pair<K, V>& assetLicense : assetLicenses) {
nlohmann::json 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;
return result;
}
nlohmann::json SceneLicenseWriter::generateJsonList() const {
nlohmann::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<const Asset*> assets =
global::openSpaceEngine->assetManager().allAssets();
for (const Asset* asset : assets) {
std::optional<Asset::MetaInformation> meta = asset->metaInformation();
if (!meta.has_value()) {
continue;
}
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();
json.push_back(assetJson);
}
return json;
}
} // namespace openspace