From 5a9ebe552b6b5bc2c63abf05fb2235bb196f05f3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 24 Oct 2017 01:47:14 -0700 Subject: [PATCH] Add the ability to remove Tags --- include/openspace/properties/propertyowner.h | 12 +++++++-- src/engine/openspaceengine.cpp | 8 +++++- src/engine/openspaceengine_lua.inl | 26 +++++++++++++++++++- src/properties/propertyowner.cpp | 7 ++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index d74fe18199..061a77d8fe 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -224,12 +224,20 @@ public: std::vector tags() const; /** - * Adds a tag to the Property's list of assigned tags. Tags are useful for creating - * groups of Properties that can be used in batch operations. + * Adds a tag to the PropertyOwner's list of assigned tags. Tags are useful for + * creating oups of Properties that can be used in batch operations or to mark up + * PropertyOwners for other usages (such signalling to GUI applications). * \param tag The string that is to be assigned to the Property */ void addTag(std::string tag); + /** + * Removes a tag from this PropertyOwner. No error is reported if the tag does not + * exist + * @param tag The tag is that is to be removed from this PropertyOwner + */ + void removeTag(const std::string& tag); + private: /// The name of this PropertyOwner std::string _name; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index eef2fcbd66..f21c9dda8a 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1215,7 +1215,7 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, func(); } - if (_shutdown.inShutdown) { + if (isGuiWindow && _shutdown.inShutdown) { _renderEngine->renderShutdownInformation(_shutdown.timer, _shutdown.waitTime); } @@ -1388,6 +1388,12 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { &luascriptfunctions::addTag, "string, string", "Adds a tag (second argument) to a scene graph node (first argument)" + }, + { + "removeTag", + &luascriptfunctions::removeTag, + "string, string", + "Removes a tag (second argument) from a scene graph node (first argument)" } } }; diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 7fd89319e6..20a3185037 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -176,7 +176,31 @@ int addTag(lua_State* L) { return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str()); } - node->addTag(tag); + node->addTag(std::move(tag)); + + return 0; +} + +/** + * \ingroup LuaScripts + * removeTag(): + * Removes a tag from a SceneGraphNode + */ +int removeTag(lua_State* L) { + const int nArguments = lua_gettop(L); + if (nArguments != 2) { + return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments); + } + + const std::string uri = lua_tostring(L, -2); + const std::string tag = lua_tostring(L, -1); + + SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(uri); + if (!node) { + return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str()); + } + + node->removeTag(tag); return 0; } diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index c5cf1fc9cc..6568b7146c 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -282,4 +282,11 @@ void PropertyOwner::addTag(std::string tag) { _tags.push_back(std::move(tag)); } +void PropertyOwner::removeTag(const std::string& tag) { + _tags.erase( + std::remove(_tags.begin(), _tags.end(), tag), + _tags.end() + ); +} + } // namespace openspace::properties