From 0fbdbb8dabb8e4969649b51455af31f27712fc38 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 18 Sep 2014 08:46:46 +0200 Subject: [PATCH] Fix a bug in TemplateProperty preventing new bool values to be set Add "isEnabled" flag BoolProperty to all renderables --- gui/luascriptexternalcontrol/CMakeLists.txt | 12 ------------ include/openspace/properties/templateproperty.h | 12 +++++++++++- include/openspace/properties/templateproperty.inl | 15 ++++++++++----- include/openspace/rendering/renderable.h | 10 ++++++++-- src/rendering/renderable.cpp | 9 +++++++-- src/scenegraph/scenegraph.cpp | 1 - src/scenegraph/scenegraphnode.cpp | 3 ++- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/gui/luascriptexternalcontrol/CMakeLists.txt b/gui/luascriptexternalcontrol/CMakeLists.txt index 44d82b517d..b4ff6d4784 100644 --- a/gui/luascriptexternalcontrol/CMakeLists.txt +++ b/gui/luascriptexternalcontrol/CMakeLists.txt @@ -3,20 +3,8 @@ cmake_minimum_required(VERSION 2.8.11) project(LuascriptExternalControl) set(CMAKE_INCLUDE_CURRENT_DIR ON) -#set(QT_PATH_OPTION "C:/Qt/5.1.0/5.1.0/msvc2012_64_opengl/lib" CACHE PATH "Path to Qt folder") -#set(QT_PATH_OPTION "C:\\Qt\\Qt5\\5.3\\msvc2013_64_opengl\\lib\\cmake\\Qt5Widgets") -#option(QT_PATH_OPTION "Path to the Qt5 folder" "C:/Qt/5.1.0/5.1.0/msvc2012_64_opengl/lib") -#message("Option: ${QT_PATH_OPTION}") - -#set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} ${QT_PATH_OPTION}") - -#set(CMAKE_PREFIX_PATH $ENV{QTDIR}) - -#message("Prefix: ${CMAKE_PREFIX_PATH}") - set(CMAKE_AUTOMOC ON) find_package(Qt5Widgets) find_package(Qt5Network) add_executable(LuascriptExternalControl WIN32 main.cpp mainwindow.cpp) -#qt5_use_modules(LuascriptExternalControl, Widgets) target_link_libraries(LuascriptExternalControl Qt5::Widgets Qt5::Network) \ No newline at end of file diff --git a/include/openspace/properties/templateproperty.h b/include/openspace/properties/templateproperty.h index 494eb46e9e..f2e511ab15 100644 --- a/include/openspace/properties/templateproperty.h +++ b/include/openspace/properties/templateproperty.h @@ -130,13 +130,23 @@ public: * was of the type T. It makes assignments such as * T v = property; possible by allowing implicit casts (even though, * internally, not casts are performed. This method is next to zero overhead). + * \return The internal representation of the Property */ operator T(); + /** + * This operator allows the TemplateProperty to be used almost transparently as if it + * was of the type T. It makes assignments such as + * T v = property; possible by allowing implicit casts (even though, + * internally, not casts are performed. This method is next to zero overhead). + * \return The internal representation of the Property + */ + operator T() const; + /** * The assignment operator allows the TemplateProperty's value to be set without using * the TemplateProperty::set method. It will be done internally by thos method and it - * allows assigments such as prop = T(1). + * allows assignments such as prop = T(1). * \param val The value that should be set. */ TemplateProperty& operator=(T val); diff --git a/include/openspace/properties/templateproperty.inl b/include/openspace/properties/templateproperty.inl index d2c333abcd..5459d644ef 100644 --- a/include/openspace/properties/templateproperty.inl +++ b/include/openspace/properties/templateproperty.inl @@ -131,6 +131,11 @@ TemplateProperty::operator T() { return _value; } +template +TemplateProperty::operator T() const { + return _value; +} + template TemplateProperty& TemplateProperty::operator=(T val) { setValue(val); @@ -162,9 +167,9 @@ boost::any TemplateProperty::get() const { template void TemplateProperty::set(boost::any value) { try { - T value = boost::any_cast(std::move(value)); - if (value != _value) { - _value = std::move(value); + T v = boost::any_cast(std::move(value)); + if (v != _value) { + _value = std::move(v); notifyListener(); } } @@ -183,9 +188,9 @@ template bool TemplateProperty::setLua(lua_State* state) { bool success; - T value = PropertyDelegate>::template fromLuaValue(state, success); + T thisValue = PropertyDelegate>::template fromLuaValue(state, success); if (success) - set(value); + set(boost::any(thisValue)); return success; } diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index a1959f72aa..91c001e5d7 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -25,12 +25,13 @@ #ifndef __RENDERABLE_H__ #define __RENDERABLE_H__ -// open space includes +#include + +#include #include #include #include #include -#include namespace openspace { @@ -51,9 +52,14 @@ public: virtual void render(const Camera* camera, const psc& thisPosition) = 0; virtual void update(); + bool isVisible() const; + protected: std::string findPath(const std::string& path); + private: + properties::BoolProperty _enabled; + PowerScaledScalar boundingSphere_; std::string _relativePath; }; diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index f62e26be7a..a81a6b1b33 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -59,9 +59,8 @@ Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary } Renderable::Renderable(const ghoul::Dictionary& dictionary) + : _enabled("enabled", "Is Enabled", true) { -// std::string name; -// dictionary.getValue(constants::scenegraphnode::keyName, name); setName("renderable"); // get path if available @@ -70,6 +69,8 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary) dictionary.getValue(constants::scenegraph::keyPathModule, _relativePath); _relativePath += "/"; } + + addProperty(_enabled); } Renderable::~Renderable() @@ -104,4 +105,8 @@ std::string Renderable::findPath(const std::string& path) { return ""; } +bool Renderable::isVisible() const { + return _enabled; +} + } // namespace openspace diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index a6ac8cf10e..750b32f94b 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -110,7 +110,6 @@ int property_setValue(lua_State* L) { return 0; } - //if (propertyValue.type() != prop->type()) { if (type != prop->typeLua()) LERROR("Property '" << uri << "' does not accept input of type '" << luaTypeToString(type) << "'. Requested type: '" diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index 5e349c782c..f033942988 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -269,7 +269,8 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) if (!_boundingSphereVisible) { return; } - if (_renderableVisible && _renderableToggle) { + + if (_renderableVisible && _renderableToggle && _renderable->isVisible()) { // LDEBUG("Render"); _renderable->render(camera, thisPosition); }