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:
@@ -529,27 +529,44 @@ void DocumentObject::setDocument(App::Document* doc)
|
||||
onSettingDocument();
|
||||
}
|
||||
|
||||
void DocumentObject::onAboutToRemoveProperty(const char* name)
|
||||
bool DocumentObject::removeDynamicProperty(const char* name)
|
||||
{
|
||||
if (_pDoc) {
|
||||
_pDoc->removePropertyOfObject(this, name);
|
||||
if (!_pDoc)
|
||||
return false;
|
||||
|
||||
Property* prop = getDynamicPropertyByName(name);
|
||||
if (prop) {
|
||||
auto expressions = ExpressionEngine.getExpressions();
|
||||
std::vector<App::ObjectIdentifier> removeExpr;
|
||||
Property* prop = getDynamicPropertyByName(name);
|
||||
if(!prop || prop->testStatus(App::Property::LockDynamic))
|
||||
return false;
|
||||
|
||||
for (auto it : expressions) {
|
||||
if (it.first.getProperty() == prop) {
|
||||
removeExpr.push_back(it.first);
|
||||
}
|
||||
}
|
||||
if(prop->isDerivedFrom(PropertyLinkBase::getClassTypeId()))
|
||||
clearOutListCache();
|
||||
|
||||
for (auto it : removeExpr) {
|
||||
ExpressionEngine.setValue(it, boost::shared_ptr<Expression>());
|
||||
}
|
||||
_pDoc->addOrRemovePropertyOfObject(this, prop, false);
|
||||
|
||||
auto expressions = ExpressionEngine.getExpressions();
|
||||
std::vector<App::ObjectIdentifier> removeExpr;
|
||||
|
||||
for (auto it : expressions) {
|
||||
if (it.first.getProperty() == prop) {
|
||||
removeExpr.push_back(it.first);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it : removeExpr) {
|
||||
ExpressionEngine.setValue(it, boost::shared_ptr<Expression>());
|
||||
}
|
||||
|
||||
return TransactionalObject::removeDynamicProperty(name);
|
||||
}
|
||||
|
||||
App::Property* DocumentObject::addDynamicProperty(
|
||||
const char* type, const char* name, const char* group, const char* doc,
|
||||
short attr, bool ro, bool hidden)
|
||||
{
|
||||
auto prop = TransactionalObject::addDynamicProperty(type,name,group,doc,attr,ro,hidden);
|
||||
if(prop && _pDoc)
|
||||
_pDoc->addOrRemovePropertyOfObject(this, prop, true);
|
||||
return prop;
|
||||
}
|
||||
|
||||
void DocumentObject::onBeforeChange(const Property* prop)
|
||||
@@ -580,8 +597,14 @@ void DocumentObject::onChanged(const Property* prop)
|
||||
_pDoc->signalRelabelObject(*this);
|
||||
|
||||
// set object touched if it is an input property
|
||||
if (!(prop->getType() & Prop_Output)) {
|
||||
StatusBits.set(ObjectStatus::Touch);
|
||||
if (!testStatus(ObjectStatus::NoTouch)
|
||||
&& !(prop->getType() & Prop_Output)
|
||||
&& !prop->testStatus(Property::Output))
|
||||
{
|
||||
if(!StatusBits.test(ObjectStatus::Touch)) {
|
||||
FC_TRACE("touch '" << getFullName() << "' on change of '" << prop->getName() << "'");
|
||||
StatusBits.set(ObjectStatus::Touch);
|
||||
}
|
||||
// must execute on document recompute
|
||||
if (!(prop->getType() & Prop_NoRecompute))
|
||||
StatusBits.set(ObjectStatus::Enforce);
|
||||
@@ -1008,3 +1031,9 @@ bool DocumentObject::redirectSubName(std::ostringstream &, DocumentObject *, Doc
|
||||
return false;
|
||||
}
|
||||
|
||||
void DocumentObject::onPropertyStatusChanged(const Property &prop, unsigned long oldStatus) {
|
||||
(void)oldStatus;
|
||||
if(!Document::isAnyRestoring() && getNameInDocument() && getDocument())
|
||||
getDocument()->signalChangePropertyEditor(*getDocument(),prop);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user