From 0bcd95416aaac6202fe0c07fbd9c77768d29feea Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 9 Mar 2014 17:10:11 +0100 Subject: [PATCH] + fixes #0001039: Add the property PropertyBoolList --- src/App/Application.cpp | 1 + src/App/FeatureTest.cpp | 1 + src/App/FeatureTest.h | 1 + src/App/PropertyStandard.cpp | 153 +++++++++++++++++++++++++++++++++++ src/App/PropertyStandard.h | 39 +++++++++ 5 files changed, 195 insertions(+) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index bb1094cfc..57ac5ebec 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1020,6 +1020,7 @@ void Application::initTypes(void) App ::PropertyContainer ::init(); App ::PropertyLists ::init(); App ::PropertyBool ::init(); + App ::PropertyBoolList ::init(); App ::PropertyFloat ::init(); App ::PropertyFloatList ::init(); App ::PropertyFloatConstraint ::init(); diff --git a/src/App/FeatureTest.cpp b/src/App/FeatureTest.cpp index 6a7692443..095ea8c4f 100644 --- a/src/App/FeatureTest.cpp +++ b/src/App/FeatureTest.cpp @@ -53,6 +53,7 @@ FeatureTest::FeatureTest() ADD_PROPERTY(Integer,(4711) ); ADD_PROPERTY(Float ,(47.11f) ); ADD_PROPERTY(Bool ,(true) ); + ADD_PROPERTY(BoolList,(false)); ADD_PROPERTY(String ,("4711")); ADD_PROPERTY(Path ,("c:\\temp")); ADD_PROPERTY(StringList ,("4711")); diff --git a/src/App/FeatureTest.h b/src/App/FeatureTest.h index 886047c39..b5316315d 100644 --- a/src/App/FeatureTest.h +++ b/src/App/FeatureTest.h @@ -48,6 +48,7 @@ public: App::PropertyInteger Integer; App::PropertyFloat Float; App::PropertyBool Bool; + App::PropertyBoolList BoolList; App::PropertyString String; App::PropertyPath Path; App::PropertyStringList StringList; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 38ba30adc..a463107d3 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1917,6 +1917,159 @@ void PropertyBool::Paste(const Property &from) hasSetValue(); } +//************************************************************************** +//************************************************************************** +// PropertyBoolList +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyBoolList , App::PropertyLists); + +//************************************************************************** +// Construction/Destruction + + +PropertyBoolList::PropertyBoolList() +{ + +} + +PropertyBoolList::~PropertyBoolList() +{ + +} + +void PropertyBoolList::setSize(int newSize) +{ + _lValueList.resize(newSize); +} + +int PropertyBoolList::getSize(void) const +{ + return static_cast(_lValueList.size()); +} + +//************************************************************************** +// Base class implementer + +void PropertyBoolList::setValue(bool lValue) +{ + aboutToSetValue(); + _lValueList.resize(1); + _lValueList[0]=lValue; + hasSetValue(); +} + +void PropertyBoolList::set1Value(const int idx, bool value) +{ + aboutToSetValue(); + _lValueList[idx]=value; + hasSetValue(); +} + +void PropertyBoolList::setValues(const boost::dynamic_bitset<>& values) +{ + aboutToSetValue(); + _lValueList = values; + hasSetValue(); +} + +PyObject *PropertyBoolList::getPyObject(void) +{ + PyObject* tuple = PyTuple_New(getSize()); + for(int i = 0;i values(str); + setValues(values); + } + else if (PySequence_Check(value)) { + Py_ssize_t nSize = PySequence_Size(value); + boost::dynamic_bitset<> values(nSize); + + for (Py_ssize_t i=0; iob_type->tp_name; + throw Base::TypeError(error); + } + } + + setValues(values); + } + else if (PyBool_Check(value)) { + setValue(PyObject_IsTrue(value) ? true : false); + } + else if (PyInt_Check(value)) { + setValue(PyInt_AsLong(value) ? true : false); + } + else { + std::string error = std::string("type must be bool or a sequence of bool, not "); + error += value->ob_type->tp_name; + throw Base::TypeError(error); + } +} + +void PropertyBoolList::Save (Base::Writer &writer) const +{ + writer.Stream() << writer.ind() << "" ; + writer.Stream() << std::endl; +} + +void PropertyBoolList::Restore(Base::XMLReader &reader) +{ + // read my Element + reader.readElement("BoolList"); + // get the value of my Attribute + string str = reader.getAttribute("value"); + boost::dynamic_bitset<> bitset(str); + setValues(bitset); +} + +Property *PropertyBoolList::Copy(void) const +{ + PropertyBoolList *p= new PropertyBoolList(); + p->_lValueList = _lValueList; + return p; +} + +void PropertyBoolList::Paste(const Property &from) +{ + aboutToSetValue(); + _lValueList = dynamic_cast(from)._lValueList; + hasSetValue(); +} + +unsigned int PropertyBoolList::getMemSize (void) const +{ + return static_cast(_lValueList.size()); +} + //************************************************************************** //************************************************************************** // PropertyColor diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index 340dc74e7..706fffe1b 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -746,6 +747,44 @@ private: bool _lValue; }; +/** Bool list properties + * + */ +class AppExport PropertyBoolList : public PropertyLists +{ + TYPESYSTEM_HEADER(); + +public: + PropertyBoolList(); + ~PropertyBoolList(); + + virtual void setSize(int newSize); + virtual int getSize(void) const; + + /** Sets the property + */ + void setValue(bool); + + /// index operator + void set1Value (const int idx, bool value); + void setValues (const boost::dynamic_bitset<>& values); + + const boost::dynamic_bitset<> &getValues(void) const{return _lValueList;} + + virtual PyObject *getPyObject(void); + virtual void setPyObject(PyObject *); + + virtual void Save (Base::Writer &writer) const; + virtual void Restore(Base::XMLReader &reader); + + virtual Property *Copy(void) const; + virtual void Paste(const Property &from); + virtual unsigned int getMemSize (void) const; + +private: + boost::dynamic_bitset<> _lValueList; +}; + /** Color properties * This is the father of all properties handling colors.