Fix a bug in TemplateProperty preventing new bool values to be set

Add "isEnabled" flag BoolProperty to all renderables
This commit is contained in:
Alexander Bock
2014-09-18 08:46:46 +02:00
parent 27901c1629
commit 0fbdbb8dab
7 changed files with 38 additions and 24 deletions
@@ -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)
@@ -130,13 +130,23 @@ public:
* was of the type <code>T</code>. It makes assignments such as
* <code>T v = property;</code> 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 <code>T</code>. It makes assignments such as
* <code>T v = property;</code> 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 <code>prop = T(1)</code>.
* allows assignments such as <code>prop = T(1)</code>.
* \param val The value that should be set.
*/
TemplateProperty<T>& operator=(T val);
@@ -131,6 +131,11 @@ TemplateProperty<T>::operator T() {
return _value;
}
template <typename T>
TemplateProperty<T>::operator T() const {
return _value;
}
template <typename T>
TemplateProperty<T>& TemplateProperty<T>::operator=(T val) {
setValue(val);
@@ -162,9 +167,9 @@ boost::any TemplateProperty<T>::get() const {
template <typename T>
void TemplateProperty<T>::set(boost::any value) {
try {
T value = boost::any_cast<T>(std::move(value));
if (value != _value) {
_value = std::move(value);
T v = boost::any_cast<T>(std::move(value));
if (v != _value) {
_value = std::move(v);
notifyListener();
}
}
@@ -183,9 +188,9 @@ template <typename T>
bool TemplateProperty<T>::setLua(lua_State* state)
{
bool success;
T value = PropertyDelegate<TemplateProperty<T>>::template fromLuaValue<T>(state, success);
T thisValue = PropertyDelegate<TemplateProperty<T>>::template fromLuaValue<T>(state, success);
if (success)
set(value);
set(boost::any(thisValue));
return success;
}
+8 -2
View File
@@ -25,12 +25,13 @@
#ifndef __RENDERABLE_H__
#define __RENDERABLE_H__
// open space includes
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/powerscaledscalar.h>
#include <openspace/util/camera.h>
#include <ghoul/misc/dictionary.h>
#include <openspace/properties/propertyowner.h>
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;
};
+7 -2
View File
@@ -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
-1
View File
@@ -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: '"
+2 -1
View File
@@ -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);
}