App: Property related API changes
Property: * Extended property status bitset. Mirror most of PropertyType and allow dynamic change property type. * Cache property name and type to improve performance * Centralize property status change signalling * Change aboutToSetValue()/hasSetValue() to virtual * Add new API getFullName() to obtain full quanlified name of the property AtomicPropertyChangeInterface: * Allow calling aboutToSetValue()/hasSetValue() when actually changed PropertyLists: * Refactor implementation by an abstract class PropertyListBase and a template class PropertyListsT, to allow better code reuse. PropertyListT is derived from AtomicPropertyChangeInterface to allow more efficient change on individual elements. * All list type property now accept setting python value as a dictionary with index as key to set individual element of a list. * Add touch list for more efficient handling of value changes. The list contains the index of changed value. And empty touch list should be treated as the entire list is changed. PropertyContainerPy expose this functionality with getPropertyTouchList(). PropertyPersistentObject: * New property to allow dynamic creation of any FreeCAD object derived from Base::Persistence, and use it as a property. DynamicProperty: * Use boost multi_index_container for efficient property lookup while keeping order. * Modify to be allowed to use in PropertyContainer directly PropertyContainer: * Use boost multi_index_container for efficient property lookup while keeping order. * Allow adding/removing dynamic property on all property container * Modify Save/Restore() to persist property status, and better handle transient property which can now be dynamically enabled/disabled per object. * Add new API getFullName() to obtain full quanlified name of the property. Implemented by Document, DocumentObject, and also ViewProviderDocumentObject if future patch DocumentObject and FeaturePython are modified to accommondate the dynamic property changes. Removed get/setCustomAttribute() implementation from DocumentObjectPy, and rely on PropertyContainerPy for the implementation, because of the additional dynamic property support in property container. Gui::ViewProviderDocumentObject, which is derived from PropertyContainer, is also modified accordingly
This commit is contained in:
@@ -701,34 +701,9 @@ PropertyIntegerList::~PropertyIntegerList()
|
||||
|
||||
}
|
||||
|
||||
void PropertyIntegerList::setSize(int newSize)
|
||||
{
|
||||
_lValueList.resize(newSize);
|
||||
}
|
||||
|
||||
int PropertyIntegerList::getSize(void) const
|
||||
{
|
||||
return static_cast<int>(_lValueList.size());
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
void PropertyIntegerList::setValue(long lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(1);
|
||||
_lValueList[0]=lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyIntegerList::setValues(const std::vector<long>& values)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = values;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
PyObject *PropertyIntegerList::getPyObject(void)
|
||||
{
|
||||
PyObject* list = PyList_New(getSize());
|
||||
@@ -741,47 +716,17 @@ PyObject *PropertyIntegerList::getPyObject(void)
|
||||
return list;
|
||||
}
|
||||
|
||||
void PropertyIntegerList::setPyObject(PyObject *value)
|
||||
{
|
||||
if (PySequence_Check(value)) {
|
||||
Py_ssize_t nSize = PySequence_Size(value);
|
||||
std::vector<long> values;
|
||||
values.resize(nSize);
|
||||
|
||||
for (Py_ssize_t i=0; i<nSize;++i) {
|
||||
PyObject* item = PySequence_GetItem(value, i);
|
||||
long PropertyIntegerList::getPyValue(PyObject *item) const {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (!PyInt_Check(item)) {
|
||||
std::string error = std::string("type in list must be int, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
values[i] = PyInt_AsLong(item);
|
||||
if (PyInt_Check(item))
|
||||
return PyInt_AsLong(item);
|
||||
#else
|
||||
if (!PyLong_Check(item)) {
|
||||
std::string error = std::string("type in list must be int, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
values[i] = PyLong_AsLong(item);
|
||||
if (PyLong_Check(item))
|
||||
return PyLong_AsLong(item);
|
||||
#endif
|
||||
}
|
||||
|
||||
setValues(values);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(value)) {
|
||||
setValue(PyInt_AsLong(value));
|
||||
#else
|
||||
else if (PyLong_Check(value)) {
|
||||
setValue(PyLong_AsLong(value));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be int or a sequence of int, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
std::string error = std::string("type in list must be int, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
|
||||
void PropertyIntegerList::Save (Base::Writer &writer) const
|
||||
@@ -822,8 +767,6 @@ Property *PropertyIntegerList::Copy(void) const
|
||||
|
||||
void PropertyIntegerList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyIntegerList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
@@ -1251,31 +1194,6 @@ PropertyFloatList::~PropertyFloatList()
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
void PropertyFloatList::setSize(int newSize)
|
||||
{
|
||||
_lValueList.resize(newSize);
|
||||
}
|
||||
|
||||
int PropertyFloatList::getSize(void) const
|
||||
{
|
||||
return static_cast<int>(_lValueList.size());
|
||||
}
|
||||
|
||||
void PropertyFloatList::setValue(double lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(1);
|
||||
_lValueList[0]=lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyFloatList::setValues(const std::vector<double>& values)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = values;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
PyObject *PropertyFloatList::getPyObject(void)
|
||||
{
|
||||
PyObject* list = PyList_New(getSize());
|
||||
@@ -1284,39 +1202,19 @@ PyObject *PropertyFloatList::getPyObject(void)
|
||||
return list;
|
||||
}
|
||||
|
||||
void PropertyFloatList::setPyObject(PyObject *value)
|
||||
{
|
||||
if (PyList_Check(value)) {
|
||||
Py_ssize_t nSize = PyList_Size(value);
|
||||
std::vector<double> values;
|
||||
values.resize(nSize);
|
||||
|
||||
for (Py_ssize_t i=0; i<nSize;++i) {
|
||||
PyObject* item = PyList_GetItem(value, i);
|
||||
if (PyFloat_Check(item)) {
|
||||
values[i] = PyFloat_AsDouble(item);
|
||||
double PropertyFloatList::getPyValue(PyObject *item) const {
|
||||
if (PyFloat_Check(item)) {
|
||||
return PyFloat_AsDouble(item);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
} else if (PyLong_Check(item)) {
|
||||
values[i] = static_cast<double>(PyLong_AsLong(item));
|
||||
} else if (PyLong_Check(item)) {
|
||||
return static_cast<double>(PyLong_AsLong(item));
|
||||
#else
|
||||
} else if (PyInt_Check(item)) {
|
||||
values[i] = static_cast<double>(PyInt_AsLong(item));
|
||||
} else if (PyInt_Check(item)) {
|
||||
return static_cast<double>(PyInt_AsLong(item));
|
||||
#endif
|
||||
} else {
|
||||
std::string error = std::string("type in list must be float, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
setValues(values);
|
||||
}
|
||||
else if (PyFloat_Check(value)) {
|
||||
setValue(PyFloat_AsDouble(value));
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be float or list of float, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
} else {
|
||||
std::string error = std::string("type in list must be float, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
}
|
||||
@@ -1333,7 +1231,7 @@ void PropertyFloatList::Save (Base::Writer &writer) const
|
||||
}
|
||||
else {
|
||||
writer.Stream() << writer.ind() << "<FloatList file=\"" <<
|
||||
writer.addFile(getName(), this) << "\"/>" << std::endl;
|
||||
(getSize()?writer.addFile(getName(), this):"") << "\"/>" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1396,9 +1294,7 @@ Property *PropertyFloatList::Copy(void) const
|
||||
|
||||
void PropertyFloatList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyFloatList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
setValues(dynamic_cast<const PropertyFloatList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
unsigned int PropertyFloatList::getMemSize (void) const
|
||||
@@ -1679,37 +1575,13 @@ PropertyStringList::~PropertyStringList()
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
void PropertyStringList::setSize(int newSize)
|
||||
{
|
||||
_lValueList.resize(newSize);
|
||||
}
|
||||
|
||||
int PropertyStringList::getSize(void) const
|
||||
{
|
||||
return static_cast<int>(_lValueList.size());
|
||||
}
|
||||
|
||||
void PropertyStringList::setValue(const std::string& lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(1);
|
||||
_lValueList[0]=lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyStringList::setValues(const std::vector<std::string>& lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList=lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyStringList::setValues(const std::list<std::string>& lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(lValue.size());
|
||||
std::copy(lValue.begin(), lValue.end(), _lValueList.begin());
|
||||
hasSetValue();
|
||||
std::vector<std::string> vals;
|
||||
vals.reserve(lValue.size());
|
||||
for(const auto &v : lValue)
|
||||
vals.push_back(v);
|
||||
setValues(vals);
|
||||
}
|
||||
|
||||
PyObject *PropertyStringList::getPyObject(void)
|
||||
@@ -1728,60 +1600,28 @@ PyObject *PropertyStringList::getPyObject(void)
|
||||
return list;
|
||||
}
|
||||
|
||||
void PropertyStringList::setPyObject(PyObject *value)
|
||||
{
|
||||
#if PY_MAJOR_VERSION >=3
|
||||
if (PyBytes_Check(value)) {
|
||||
setValue(PyBytes_AsString(value));
|
||||
}
|
||||
#else
|
||||
if (PyString_Check(value)) {
|
||||
setValue(PyString_AsString(value));
|
||||
}
|
||||
#endif
|
||||
else if (PyUnicode_Check(value)) {
|
||||
std::string PropertyStringList::getPyValue(PyObject *item) const {
|
||||
std::string ret;
|
||||
if (PyUnicode_Check(item)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
setValue(PyUnicode_AsUTF8(value));
|
||||
}
|
||||
ret = PyUnicode_AsUTF8(item);
|
||||
#else
|
||||
PyObject* unicode = PyUnicode_AsUTF8String(value);
|
||||
setValue(PyString_AsString(unicode));
|
||||
PyObject* unicode = PyUnicode_AsUTF8String(item);
|
||||
ret = PyString_AsString(unicode);
|
||||
Py_DECREF(unicode);
|
||||
}
|
||||
} else if (PyString_Check(item)) {
|
||||
ret = PyString_AsString(item);
|
||||
#endif
|
||||
else if (PySequence_Check(value)) {
|
||||
Py_ssize_t nSize = PySequence_Size(value);
|
||||
std::vector<std::string> values;
|
||||
values.resize(nSize);
|
||||
|
||||
for (Py_ssize_t i=0; i<nSize;++i) {
|
||||
PyObject* item = PySequence_GetItem(value, i);
|
||||
if (PyUnicode_Check(item)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
values[i] = PyUnicode_AsUTF8(item);
|
||||
#else
|
||||
PyObject* unicode = PyUnicode_AsUTF8String(item);
|
||||
values[i] = PyString_AsString(unicode);
|
||||
Py_DECREF(unicode);
|
||||
}
|
||||
else if (PyString_Check(item)) {
|
||||
values[i] = PyString_AsString(item);
|
||||
} else if (PyBytes_Check(item)) {
|
||||
ret = PyBytes_AsString(item);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type in list must be str or unicode, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
setValues(values);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be str or unicode or list of str or list of unicodes, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
} else {
|
||||
std::string error = std::string("type in list must be str or unicode, not ");
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int PropertyStringList::getMemSize (void) const
|
||||
@@ -1832,9 +1672,7 @@ Property *PropertyStringList::Copy(void) const
|
||||
|
||||
void PropertyStringList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyStringList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
setValues(dynamic_cast<const PropertyStringList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
|
||||
@@ -1929,8 +1767,7 @@ void PropertyMap::setPyObject(PyObject *value)
|
||||
PyObject* unicode = PyUnicode_AsUTF8String(key);
|
||||
keyStr = PyString_AsString(unicode);
|
||||
Py_DECREF(unicode);
|
||||
}
|
||||
if (PyString_Check(key)) {
|
||||
}else if (PyString_Check(key)) {
|
||||
keyStr = PyString_AsString(key);
|
||||
#endif
|
||||
}
|
||||
@@ -2163,41 +2000,9 @@ 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());
|
||||
@@ -2226,53 +2031,28 @@ void PropertyBoolList::setPyObject(PyObject *value)
|
||||
Py_DECREF(unicode);
|
||||
boost::dynamic_bitset<> values(str);
|
||||
setValues(values);
|
||||
}
|
||||
if (PyString_Check(value)) {
|
||||
} else if (PyString_Check(value)) {
|
||||
str = PyString_AsString(value);
|
||||
#endif
|
||||
boost::dynamic_bitset<> values(str);
|
||||
setValues(values);
|
||||
}
|
||||
else if (PySequence_Check(value)) {
|
||||
Py_ssize_t nSize = PySequence_Size(value);
|
||||
boost::dynamic_bitset<> values(nSize);
|
||||
}else
|
||||
inherited::setPyObject(value);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
bool PropertyBoolList::getPyValue(PyObject *item) const {
|
||||
if (PyBool_Check(item)) {
|
||||
return (PyObject_IsTrue(item) ? true : false);
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(item)) {
|
||||
values[i] = (PyInt_AsLong(item) ? true : false);
|
||||
} else if (PyInt_Check(item)) {
|
||||
return (PyInt_AsLong(item) ? true : false);
|
||||
#else
|
||||
else if (PyLong_Check(item)) {
|
||||
values[i] = (PyLong_AsLong(item) ? true : false);
|
||||
} else if (PyLong_Check(item)) {
|
||||
return (PyLong_AsLong(item) ? true : false);
|
||||
#endif
|
||||
}
|
||||
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);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(value)) {
|
||||
setValue(PyInt_AsLong(value) ? true : false);
|
||||
#else
|
||||
else if (PyLong_Check(value)) {
|
||||
setValue(PyLong_AsLong(value) ? true : false);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be bool or a sequence of bool, not ");
|
||||
error += value->ob_type->tp_name;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@@ -2305,9 +2085,7 @@ Property *PropertyBoolList::Copy(void) const
|
||||
|
||||
void PropertyBoolList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyBoolList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
setValues(dynamic_cast<const PropertyBoolList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
unsigned int PropertyBoolList::getMemSize (void) const
|
||||
@@ -2487,31 +2265,6 @@ PropertyColorList::~PropertyColorList()
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
void PropertyColorList::setSize(int newSize)
|
||||
{
|
||||
_lValueList.resize(newSize);
|
||||
}
|
||||
|
||||
int PropertyColorList::getSize(void) const
|
||||
{
|
||||
return static_cast<int>(_lValueList.size());
|
||||
}
|
||||
|
||||
void PropertyColorList::setValue(const Color& lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(1);
|
||||
_lValueList[0]=lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyColorList::setValues (const std::vector<Color>& values)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList=values;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
PyObject *PropertyColorList::getPyObject(void)
|
||||
{
|
||||
PyObject* list = PyList_New(getSize());
|
||||
@@ -2534,43 +2287,17 @@ PyObject *PropertyColorList::getPyObject(void)
|
||||
return list;
|
||||
}
|
||||
|
||||
void PropertyColorList::setPyObject(PyObject *value)
|
||||
{
|
||||
if (PyList_Check(value)) {
|
||||
Py_ssize_t nSize = PyList_Size(value);
|
||||
std::vector<Color> values;
|
||||
values.resize(nSize);
|
||||
|
||||
for (Py_ssize_t i=0; i<nSize;++i) {
|
||||
PyObject* item = PyList_GetItem(value, i);
|
||||
PropertyColor col;
|
||||
col.setPyObject(item);
|
||||
values[i] = col.getValue();
|
||||
}
|
||||
|
||||
setValues(values);
|
||||
}
|
||||
else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) {
|
||||
PropertyColor col;
|
||||
col.setPyObject( value );
|
||||
setValue( col.getValue() );
|
||||
}
|
||||
else if (PyTuple_Check(value) && PyTuple_Size(value) == 4) {
|
||||
PropertyColor col;
|
||||
col.setPyObject( value );
|
||||
setValue( col.getValue() );
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("not allowed type, ");
|
||||
error += value->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
Color PropertyColorList::getPyValue(PyObject *item) const {
|
||||
PropertyColor col;
|
||||
col.setPyObject(item);
|
||||
return col.getValue();
|
||||
}
|
||||
|
||||
void PropertyColorList::Save (Base::Writer &writer) const
|
||||
{
|
||||
if (!writer.isForceXML()) {
|
||||
writer.Stream() << writer.ind() << "<ColorList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
|
||||
writer.Stream() << writer.ind() << "<ColorList file=\"" <<
|
||||
(getSize()?writer.addFile(getName(), this):"") << "\"/>" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2620,9 +2347,7 @@ Property *PropertyColorList::Copy(void) const
|
||||
|
||||
void PropertyColorList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyColorList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
setValues(dynamic_cast<const PropertyColorList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
unsigned int PropertyColorList::getMemSize (void) const
|
||||
@@ -2746,7 +2471,9 @@ void PropertyMaterial::Restore(Base::XMLReader &reader)
|
||||
|
||||
const char* PropertyMaterial::getEditorName(void) const
|
||||
{
|
||||
return "";// "Gui::PropertyEditor::PropertyMaterialItem";
|
||||
if(testStatus(MaterialEdit))
|
||||
return "Gui::PropertyEditor::PropertyMaterialItem";
|
||||
return "";
|
||||
}
|
||||
|
||||
Property *PropertyMaterial::Copy(void) const
|
||||
@@ -2785,31 +2512,6 @@ PropertyMaterialList::~PropertyMaterialList()
|
||||
//**************************************************************************
|
||||
// Base class implementer
|
||||
|
||||
void PropertyMaterialList::setSize(int newSize)
|
||||
{
|
||||
_lValueList.resize(newSize);
|
||||
}
|
||||
|
||||
int PropertyMaterialList::getSize(void) const
|
||||
{
|
||||
return static_cast<int>(_lValueList.size());
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setValue(const Material& lValue)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList.resize(1);
|
||||
_lValueList[0] = lValue;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setValues(const std::vector<Material>& values)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = values;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
PyObject *PropertyMaterialList::getPyObject(void)
|
||||
{
|
||||
Py::Tuple tuple(getSize());
|
||||
@@ -2821,24 +2523,9 @@ PyObject *PropertyMaterialList::getPyObject(void)
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
|
||||
void PropertyMaterialList::setPyObject(PyObject *value)
|
||||
{
|
||||
if (PyObject_TypeCheck(value, &(MaterialPy::Type))) {
|
||||
setValue(*static_cast<MaterialPy*>(value)->getMaterialPtr());
|
||||
}
|
||||
else if (PyList_Check(value) || PyTuple_Check(value)) {
|
||||
Py::Sequence list(value);
|
||||
std::vector<Material> materials;
|
||||
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(MaterialPy::Type))) {
|
||||
Material mat = *static_cast<MaterialPy*>((*it).ptr())->getMaterialPtr();
|
||||
materials.push_back(mat);
|
||||
}
|
||||
}
|
||||
|
||||
setValues(materials);
|
||||
}
|
||||
Material PropertyMaterialList::getPyValue(PyObject *value) const {
|
||||
if (PyObject_TypeCheck(value, &(MaterialPy::Type)))
|
||||
return *static_cast<MaterialPy*>(value)->getMaterialPtr();
|
||||
else {
|
||||
std::string error = std::string("type must be 'Material', not ");
|
||||
error += value->ob_type->tp_name;
|
||||
@@ -2849,7 +2536,8 @@ void PropertyMaterialList::setPyObject(PyObject *value)
|
||||
void PropertyMaterialList::Save(Base::Writer &writer) const
|
||||
{
|
||||
if (!writer.isForceXML()) {
|
||||
writer.Stream() << writer.ind() << "<MaterialList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
|
||||
writer.Stream() << writer.ind() << "<MaterialList file=\"" <<
|
||||
(getSize()?writer.addFile(getName(), this):"") << "\"/>" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2908,6 +2596,8 @@ void PropertyMaterialList::RestoreDocFile(Base::Reader &reader)
|
||||
|
||||
const char* PropertyMaterialList::getEditorName(void) const
|
||||
{
|
||||
if(testStatus(NoMaterialListEdit))
|
||||
return "";
|
||||
return "Gui::PropertyEditor::PropertyMaterialListItem";
|
||||
}
|
||||
|
||||
@@ -2920,12 +2610,86 @@ Property *PropertyMaterialList::Copy(void) const
|
||||
|
||||
void PropertyMaterialList::Paste(const Property &from)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_lValueList = dynamic_cast<const PropertyMaterialList&>(from)._lValueList;
|
||||
hasSetValue();
|
||||
setValues(dynamic_cast<const PropertyMaterialList&>(from)._lValueList);
|
||||
}
|
||||
|
||||
unsigned int PropertyMaterialList::getMemSize(void) const
|
||||
{
|
||||
return static_cast<unsigned int>(_lValueList.size() * sizeof(Material));
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// PropertyPersistentObject
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TYPESYSTEM_SOURCE(App::PropertyPersistentObject , App::PropertyString);
|
||||
|
||||
PyObject *PropertyPersistentObject::getPyObject(void){
|
||||
if(_pObject)
|
||||
return _pObject->getPyObject();
|
||||
return inherited::getPyObject();
|
||||
}
|
||||
|
||||
void PropertyPersistentObject::Save(Base::Writer &writer) const{
|
||||
inherited::Save(writer);
|
||||
#define ELEMENT_PERSISTENT_OBJ "PersistentObject"
|
||||
writer.Stream() << writer.ind() << "<" ELEMENT_PERSISTENT_OBJ ">" << std::endl;
|
||||
if(_pObject) {
|
||||
writer.incInd();
|
||||
_pObject->Save(writer);
|
||||
writer.decInd();
|
||||
}
|
||||
writer.Stream() << writer.ind() << "</" ELEMENT_PERSISTENT_OBJ ">" << std::endl;
|
||||
}
|
||||
|
||||
void PropertyPersistentObject::Restore(Base::XMLReader &reader){
|
||||
inherited::Restore(reader);
|
||||
reader.readElement(ELEMENT_PERSISTENT_OBJ);
|
||||
if(_pObject)
|
||||
_pObject->Restore(reader);
|
||||
reader.readEndElement(ELEMENT_PERSISTENT_OBJ);
|
||||
}
|
||||
|
||||
Property *PropertyPersistentObject::Copy(void) const{
|
||||
auto *p= new PropertyPersistentObject();
|
||||
p->_cValue = _cValue;
|
||||
p->_pObject = _pObject;
|
||||
return p;
|
||||
}
|
||||
|
||||
void PropertyPersistentObject::Paste(const Property &from){
|
||||
const auto &prop = dynamic_cast<const PropertyPersistentObject&>(from);
|
||||
if(_cValue!=prop._cValue || _pObject!=prop._pObject) {
|
||||
aboutToSetValue();
|
||||
_cValue = prop._cValue;
|
||||
_pObject = prop._pObject;
|
||||
hasSetValue();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int PropertyPersistentObject::getMemSize (void) const{
|
||||
auto size = inherited::getMemSize();
|
||||
if(_pObject)
|
||||
size += _pObject->getMemSize();
|
||||
return size;
|
||||
}
|
||||
|
||||
void PropertyPersistentObject::setValue(const char *type) {
|
||||
if(!type) type = "";
|
||||
if(type[0]) {
|
||||
Base::Type::importModule(type);
|
||||
Base::Type t = Base::Type::fromName(type);
|
||||
if(t.isBad())
|
||||
throw Base::TypeError("Invalid type");
|
||||
if(!t.isDerivedFrom(Persistence::getClassTypeId()))
|
||||
throw Base::TypeError("Type must be derived from Base::Persistence");
|
||||
if(_pObject && _pObject->getTypeId()==t)
|
||||
return;
|
||||
}
|
||||
aboutToSetValue();
|
||||
_pObject.reset();
|
||||
_cValue = type;
|
||||
if(type[0])
|
||||
_pObject.reset(static_cast<Base::Persistence*>(Base::Type::createInstanceByName(type)));
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user