+ fixes #0001039: Add the property PropertyBoolList
This commit is contained in:
parent
7430d7d11b
commit
0bcd95416a
|
@ -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();
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<int>(_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<getSize(); i++) {
|
||||
bool v = _lValueList[i];
|
||||
if (v) {
|
||||
Py_INCREF(Py_True);
|
||||
PyTuple_SetItem(tuple, i, Py_True);
|
||||
}
|
||||
else {
|
||||
Py_INCREF(Py_False);
|
||||
PyTuple_SetItem(tuple, i, Py_False);
|
||||
}
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
void PropertyBoolList::setPyObject(PyObject *value)
|
||||
{
|
||||
// string is also a sequence and must be be treated differently
|
||||
if (PyString_Check(value)) {
|
||||
std::string str = PyString_AsString(value);
|
||||
boost::dynamic_bitset<> 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; i<nSize;++i) {
|
||||
PyObject* item = PySequence_GetItem(value, i);
|
||||
if (PyBool_Check(item)) {
|
||||
values[i] = (PyObject_IsTrue(item) ? true : false);
|
||||
}
|
||||
else if (PyInt_Check(item)) {
|
||||
values[i] = (PyInt_AsLong(item) ? true : false);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type in list must be bool or int, not ");
|
||||
error += item->ob_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() << "<BoolList value=\"" ;
|
||||
std::string bitset;
|
||||
boost::to_string(_lValueList, bitset);
|
||||
writer.Stream() << bitset <<"\"/>" ;
|
||||
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<const PropertyBoolList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
unsigned int PropertyBoolList::getMemSize (void) const
|
||||
{
|
||||
return static_cast<unsigned int>(_lValueList.size());
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// PropertyColor
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <Base/Uuid.h>
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user