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:
@@ -672,20 +672,39 @@ PyObject* DocumentObjectPy::getPathsByOutList(PyObject *args)
|
||||
|
||||
PyObject *DocumentObjectPy::getCustomAttributes(const char* attr) const
|
||||
{
|
||||
// Dynamic proeprty is now directly supported in PropertyContainer. So we
|
||||
// can comment out here and let PropertyContainerPy handle it.
|
||||
#if 1
|
||||
(void)attr;
|
||||
#else
|
||||
// search for dynamic property
|
||||
Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr);
|
||||
if (prop)
|
||||
return prop->getPyObject();
|
||||
else
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
|
||||
{
|
||||
// The following code is practically the same as in PropertyContainerPy,
|
||||
// especially since now dynamic proeprty is directly supported in
|
||||
// PropertyContainer. So we can comment out here and let PropertyContainerPy
|
||||
// handle it.
|
||||
#if 1
|
||||
(void)attr;
|
||||
(void)obj;
|
||||
#else
|
||||
// explicitly search for dynamic property
|
||||
try {
|
||||
Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr);
|
||||
if (prop) {
|
||||
if(prop->testStatus(Property::Immutable)) {
|
||||
std::stringstream s;
|
||||
s << "'DocumentObject' attribute '" << attr << "' is read-only";
|
||||
throw Py::AttributeError(s.str());
|
||||
}
|
||||
prop->setPyObject(obj);
|
||||
return 1;
|
||||
}
|
||||
@@ -700,7 +719,9 @@ int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
|
||||
s << "Attribute (Name: " << attr << ") error: '" << exc.what() << "' ";
|
||||
throw Py::AttributeError(s.str());
|
||||
}
|
||||
catch (...) {
|
||||
catch (Py::AttributeError &) {
|
||||
throw;
|
||||
}catch (...) {
|
||||
std::stringstream s;
|
||||
s << "Unknown error in attribute " << attr;
|
||||
throw Py::AttributeError(s.str());
|
||||
@@ -710,8 +731,9 @@ int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
|
||||
Property *prop = getDocumentObjectPtr()->getPropertyByName(attr);
|
||||
if (prop) {
|
||||
// Read-only attributes must not be set over its Python interface
|
||||
short Type = getDocumentObjectPtr()->getPropertyType(prop);
|
||||
if (Type & Prop_ReadOnly) {
|
||||
if(prop->testStatus(Property::Immutable) ||
|
||||
(getDocumentObjectPtr()->getPropertyType(prop) & Prop_ReadOnly))
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "'DocumentObject' attribute '" << attr << "' is read-only";
|
||||
throw Py::AttributeError(s.str());
|
||||
@@ -727,6 +749,7 @@ int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user