From a7bd6319db7487ab582c12e778f52a5b04265f0b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 22 Feb 2015 22:05:25 +0100 Subject: [PATCH] Adding 'property' prefix to subowner methods in PropertyOwner Added function for writing documentation of properties --- include/openspace/gui/gui.h | 16 ------- include/openspace/properties/propertyowner.h | 6 +-- include/openspace/scenegraph/scenegraph.h | 2 + include/openspace/util/constants.h | 2 + openspace.cfg | 4 ++ src/properties/propertyowner.cpp | 12 +++--- src/scenegraph/scenegraph.cpp | 44 +++++++++++++++++++- 7 files changed, 60 insertions(+), 26 deletions(-) diff --git a/include/openspace/gui/gui.h b/include/openspace/gui/gui.h index 423f77a44d..02f255b53a 100644 --- a/include/openspace/gui/gui.h +++ b/include/openspace/gui/gui.h @@ -67,22 +67,6 @@ public: bool _isEnabled; bool _showHelp; - - //ghoul::SharedMemory* _performanceMemory; - //float _minMaxValues[2]; - - //std::set _boolProperties; - //std::set _intProperties; - //std::set _floatProperties; - //std::set _vec2Properties; - //std::set _vec3Properties; - //std::set _vec4Properties; - //std::set _stringProperties; - //std::set _optionProperty; - //std::set _selectionProperty; - //std::set _triggerProperty; - - //std::map> _propertiesByOwner; }; } // namespace gui diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 63842f4a55..4906d94915 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -123,7 +123,7 @@ public: * this PropertyOwner. * \return A list of all sub-owners this PropertyOwner has */ - const std::vector& subOwners() const; + const std::vector& propertySubOwners() const; /** * This method returns the direct sub-owner of this PropertyOwner with the provided @@ -134,7 +134,7 @@ public: * \param name The name of the sub-owner that should be returned * \return The PropertyOwner with the given name, or nullptr */ - PropertyOwner* subOwner(const std::string& name) const; + PropertyOwner* propertySubOwner(const std::string& name) const; /** * Returns true if this PropertyOwner owns a sub-owner with the provided @@ -143,7 +143,7 @@ public: * \return true if this PropertyOwner owns a sub-owner with the provided * name; returns false otherwise */ - bool hasSubOwner(const std::string& name) const; + bool hasPropertySubOwner(const std::string& name) const; /** * This method converts a provided groupID, used by the Propertys, into a diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h index 6a059cf625..093cae316b 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -110,6 +110,8 @@ public: private: bool loadSceneInternal(const std::string& sceneDescriptionFilePath); + void writePropertyDocumentation(const std::string& filename, const std::string& type); + std::string _focus; // actual scenegraph diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 611e7329cc..700906f60f 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -44,6 +44,8 @@ namespace configurationmanager { const std::string keyConfigSgct = "SGCTConfig"; const std::string keyLuaDocumentationType = "LuaDocumentationFile.Type"; const std::string keyLuaDocumentationFile = "LuaDocumentationFile.File"; + const std::string keyPropertyDocumentationType = "PropertyDocumentationFile.Type"; + const std::string keyPropertyDocumentationFile = "PropertyDocumentationFile.File"; const std::string keyConfigScene = "Scene"; const std::string keyEnableGui = "EnableGUI"; const std::string keyStartupScript = "StartupScripts"; diff --git a/openspace.cfg b/openspace.cfg index 37acb414d6..1372e7400f 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -38,6 +38,10 @@ return { Type = "text", File = "${BASE_PATH}/LuaScripting.txt" }, + PropertyDocumentationFile = { + Type = "text", + File = "${BASE_PATH}/Properties.txt" + }, SGCTConfig = "${SGCT}/single.xml", --SGCTConfig = "${SGCT}/single_fisheye.xml", --SGCTConfig = "${SGCT}/two_nodes.xml", diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index a266a12e33..0dd4c72422 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -96,7 +96,7 @@ Property* PropertyOwner::property(const std::string& id) const const std::string ownerName = id.substr(0, ownerSeparator); const std::string propertyName = id.substr(ownerSeparator + 1); - PropertyOwner* owner = subOwner(ownerName); + PropertyOwner* owner = propertySubOwner(ownerName); if (owner == nullptr) { return nullptr; } @@ -114,11 +114,11 @@ bool PropertyOwner::hasProperty(const std::string& id) const { return property(id) != nullptr; } -const std::vector& PropertyOwner::subOwners() const { +const std::vector& PropertyOwner::propertySubOwners() const { return _subOwners; } -PropertyOwner* PropertyOwner::subOwner(const std::string& name) const { +PropertyOwner* PropertyOwner::propertySubOwner(const std::string& name) const { assert(std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess)); // As the _subOwners list is sorted, getting the lower bound is sufficient @@ -134,8 +134,8 @@ PropertyOwner* PropertyOwner::subOwner(const std::string& name) const { return *it; } -bool PropertyOwner::hasSubOwner(const std::string& name) const { - return subOwner(name) != nullptr; +bool PropertyOwner::hasPropertySubOwner(const std::string& name) const { + return propertySubOwner(name) != nullptr; } void PropertyOwner::setPropertyGroupName(std::string groupID, std::string name) @@ -179,7 +179,7 @@ void PropertyOwner::addProperty(Property* prop) return; } else { // Otherwise we still have to look if there is a PropertyOwner with the same name - const bool hasOwner = hasSubOwner(prop->identifier()); + const bool hasOwner = hasPropertySubOwner(prop->identifier()); if (hasOwner) { LERROR("Property identifier '" << prop->identifier() << "' already names a" << "registed PropertyOwner"); diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index a1153ce28c..6e3dcb7271 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -480,10 +480,25 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) std::vector properties = node->propertiesRecursive(); for (properties::Property* p : properties) { OsEng.gui()->_property.registerProperty(p); - //OsEng.gui()->_property.registerProperty(p->description()); } } + // If a LuaDocumentationFile was specified, generate it now + using constants::configurationmanager::keyPropertyDocumentationType; + using constants::configurationmanager::keyPropertyDocumentationFile; + const bool hasType = OsEng.configurationManager()->hasKey(keyPropertyDocumentationType); + const bool hasFile = OsEng.configurationManager()->hasKey(keyPropertyDocumentationFile); + if (hasType && hasFile) { + std::string propertyDocumentationType; + OsEng.configurationManager()->getValue(keyPropertyDocumentationType, propertyDocumentationType); + std::string propertyDocumentationFile; + OsEng.configurationManager()->getValue(keyPropertyDocumentationFile, propertyDocumentationFile); + + propertyDocumentationFile = absPath(propertyDocumentationFile); + writePropertyDocumentation(propertyDocumentationFile, propertyDocumentationType); + } + + OsEng.runSettingsScripts(); return true; @@ -642,6 +657,33 @@ std::vector SceneGraph::allSceneGraphNodes() const { return _nodes; } +void SceneGraph::writePropertyDocumentation(const std::string& filename, const std::string& type) { + if (type == "text") { + LDEBUG("Writing documentation for properties"); + std::ofstream file(filename); + if (!file.good()) { + LERROR("Could not open file '" << filename << "' for writing property documentation"); + return; + } + + using properties::Property; + for (SceneGraphNode* node : _nodes) { + std::vector properties = node->propertiesRecursive(); + if (!properties.empty()) { + file << node->name() << std::endl; + + for (Property* p : properties) { + file << p->fullyQualifiedIdentifier() << ": " << p->guiName() << std::endl; + } + + file << std::endl; + } + } + } + else + LERROR("Undefined type '" << type << "' for Property documentation"); +} + scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() { return { "",