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:
Zheng, Lei
2019-06-28 10:16:42 +08:00
committed by wmayer
parent 6731e83bf5
commit be6ec3fdfc
25 changed files with 1511 additions and 1579 deletions

View File

@@ -70,11 +70,9 @@ public:
ADD_PROPERTY(Proxy,(Py::Object()));
// cannot move this to the initializer list to avoid warning
imp = new FeaturePythonImp(this);
props = new DynamicProperty(this);
}
virtual ~FeaturePythonT() {
delete imp;
delete props;
}
/** @name methods override DocumentObject */
@@ -102,88 +100,6 @@ public:
//return "Gui::ViewProviderPythonFeature";
}
/** @name Access properties */
//@{
Property* addDynamicProperty(
const char* type, const char* name=0,
const char* group=0, const char* doc=0,
short attr=0, bool ro=false, bool hidden=false) {
return props->addDynamicProperty(type, name, group, doc, attr, ro, hidden);
}
virtual bool removeDynamicProperty(const char* name) {
FeatureT::onAboutToRemoveProperty(name);
return props->removeDynamicProperty(name);
}
std::vector<std::string> getDynamicPropertyNames() const {
return props->getDynamicPropertyNames();
}
Property *getDynamicPropertyByName(const char* name) const {
return props->getDynamicPropertyByName(name);
}
virtual void addDynamicProperties(const PropertyContainer* cont) {
return props->addDynamicProperties(cont);
}
/// get all properties of the class (including properties of the parent)
virtual void getPropertyList(std::vector<Property*> &List) const {
props->getPropertyList(List);
}
/// get all properties of the class (including parent)
void getPropertyMap(std::map<std::string,Property*> &Map) const {
props->getPropertyMap(Map);
}
/// find a property by its name
virtual Property *getPropertyByName(const char* name) const {
return props->getPropertyByName(name);
}
/// get the name of a property
virtual const char* getPropertyName(const Property* prop) const {
return props->getPropertyName(prop);
}
//@}
/** @name Property attributes */
//@{
/// get the Type of a Property
short getPropertyType(const Property* prop) const {
return props->getPropertyType(prop);
}
/// get the Type of a named Property
short getPropertyType(const char *name) const {
return props->getPropertyType(name);
}
/// get the Group of a Property
const char* getPropertyGroup(const Property* prop) const {
return props->getPropertyGroup(prop);
}
/// get the Group of a named Property
const char* getPropertyGroup(const char *name) const {
return props->getPropertyGroup(name);
}
/// get the Documentation of a Property
const char* getPropertyDocumentation(const Property* prop) const {
return props->getPropertyDocumentation(prop);
}
/// get the Group of a named Property
const char* getPropertyDocumentation(const char *name) const {
return props->getPropertyDocumentation(name);
}
//@}
/** @name Property serialization */
//@{
void Save (Base::Writer &writer) const {
const char* objname = this->getNameInDocument();
// if null then it's not part of the document
if (objname) {
writer.ObjectName = objname;
props->Save(writer);
}
}
void Restore(Base::XMLReader &reader) {
props->Restore(reader);
}
//@}
PyObject *getPyObject(void) {
if (FeatureT::PythonObject.is(Py::_None())) {
// ref counter is set to 1