From df1e2642d0f1b7e43f2f0e0f66159804bea58681 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Apr 2017 23:05:40 +0200 Subject: [PATCH] replacement for PR 698 --- src/App/PropertyContainerPy.xml | 3 ++- src/Base/PyObjectBase.cpp | 6 ++++- src/Base/PyObjectBase.h | 22 +++++++++++++--- .../generateBase/generateMetaModel_Module.xsd | 1 + .../generateBase/generateModel_Module.py | 26 +++++++++++++++++-- .../templateClassPyExport.py | 4 ++- 6 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/App/PropertyContainerPy.xml b/src/App/PropertyContainerPy.xml index daef8c3be7..cbf300ae46 100644 --- a/src/App/PropertyContainerPy.xml +++ b/src/App/PropertyContainerPy.xml @@ -8,7 +8,8 @@ Include="App/PropertyContainer.h" Namespace="App" FatherInclude="Base/PersistencePy.h" - FatherNamespace="Base"> + FatherNamespace="Base" + DisableNotify="true"> This is a Persistence class diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index b909f50d1b..bbf1887ca7 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -45,7 +45,8 @@ PyObjectBase::PyObjectBase(void* p,PyTypeObject *T) #ifdef FC_LOGPYOBJECTS Base::Console().Log("PyO+: %s (%p)\n",T->tp_name, this); #endif - StatusBits.set(0); // valid, the second bit is NOT set, i.e. it's mutable + StatusBits.set(Valid); // valid, the second bit is NOT set, i.e. it's mutable + StatusBits.set(Notify); } /// destructor @@ -325,6 +326,9 @@ void PyObjectBase::setAttributeOf(const char* attr, PyObject* par) void PyObjectBase::startNotify() { + if (!shouldNotify()) + return; + if (attrDict) { // This is the attribute name to the parent structure // which we search for in the dict diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index 467bd43d92..9d37b32dda 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -193,6 +193,12 @@ class BaseExport PyObjectBase : public PyObject */ Py_Header + enum Status { + Valid = 0, + Immutable = 1, + Notify = 2 + }; + protected: /// destructor virtual ~PyObjectBase(); @@ -274,21 +280,29 @@ public: void setInvalid() { // first bit is not set, i.e. invalid - StatusBits.reset(0); + StatusBits.reset(Valid); _pcTwinPointer = 0; } bool isValid() { - return StatusBits.test(0); + return StatusBits.test(Valid); } void setConst() { // second bit is set, i.e. immutable - StatusBits.set(1); + StatusBits.set(Immutable); } bool isConst() { - return StatusBits.test(1); + return StatusBits.test(Immutable); + } + + void setShouldNotify(bool on) { + StatusBits.set(Notify, on); + } + + bool shouldNotify() const { + return StatusBits.test(Notify); } void startNotify(); diff --git a/src/Tools/generateBase/generateMetaModel_Module.xsd b/src/Tools/generateBase/generateMetaModel_Module.xsd index b55b9ffc72..535807dc42 100644 --- a/src/Tools/generateBase/generateMetaModel_Module.xsd +++ b/src/Tools/generateBase/generateMetaModel_Module.xsd @@ -69,6 +69,7 @@ + diff --git a/src/Tools/generateBase/generateModel_Module.py b/src/Tools/generateBase/generateModel_Module.py index 22e74d4deb..972de2d47b 100644 --- a/src/Tools/generateBase/generateModel_Module.py +++ b/src/Tools/generateBase/generateModel_Module.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# Generated Thu Apr 27 15:48:35 2017 by generateDS.py. +# Generated Thu Apr 27 21:48:12 2017 by generateDS.py. # Update it with: python generateDS.py -o generateModel_Module.py generateMetaModel_Module.xsd # # WARNING! All changes made in this file will be lost! @@ -219,8 +219,9 @@ class GenerateModel: class PythonExport: subclass = None - def __init__(self, FatherNamespace='', RichCompare=0, Name='', Reference=0, FatherInclude='', Namespace='', Initialization=0, Father='', PythonName='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations=''): + def __init__(self, FatherNamespace='', DisableNotify=0, RichCompare=0, Name='', Reference=0, FatherInclude='', Namespace='', Initialization=0, Father='', PythonName='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations=''): self.FatherNamespace = FatherNamespace + self.DisableNotify = DisableNotify self.RichCompare = RichCompare self.Name = Name self.Reference = Reference @@ -271,6 +272,8 @@ class PythonExport: def setClassdeclarations(self, ClassDeclarations): self.ClassDeclarations = ClassDeclarations def getFathernamespace(self): return self.FatherNamespace def setFathernamespace(self, FatherNamespace): self.FatherNamespace = FatherNamespace + def getDisablenotify(self): return self.DisableNotify + def setDisablenotify(self, DisableNotify): self.DisableNotify = DisableNotify def getRichcompare(self): return self.RichCompare def setRichcompare(self, RichCompare): self.RichCompare = RichCompare def getName(self): return self.Name @@ -309,6 +312,8 @@ class PythonExport: outfile.write('\n' % name_) def exportAttributes(self, outfile, level, name_='PythonExport'): outfile.write(' FatherNamespace="%s"' % (self.getFathernamespace(), )) + if self.getDisablenotify() is not None: + outfile.write(' DisableNotify="%s"' % (self.getDisablenotify(), )) if self.getRichcompare() is not None: outfile.write(' RichCompare="%s"' % (self.getRichcompare(), )) outfile.write(' Name="%s"' % (self.getName(), )) @@ -351,6 +356,8 @@ class PythonExport: showIndent(outfile, level) outfile.write('FatherNamespace = "%s",\n' % (self.getFathernamespace(),)) showIndent(outfile, level) + outfile.write('DisableNotify = "%s",\n' % (self.getDisablenotify(),)) + showIndent(outfile, level) outfile.write('RichCompare = "%s",\n' % (self.getRichcompare(),)) showIndent(outfile, level) outfile.write('Name = "%s",\n' % (self.getName(),)) @@ -428,6 +435,13 @@ class PythonExport: def buildAttributes(self, attrs): if attrs.get('FatherNamespace'): self.FatherNamespace = attrs.get('FatherNamespace').value + if attrs.get('DisableNotify'): + if attrs.get('DisableNotify').value in ('true', '1'): + self.DisableNotify = 1 + elif attrs.get('DisableNotify').value in ('false', '0'): + self.DisableNotify = 0 + else: + raise ValueError('Bad boolean attribute (DisableNotify)') if attrs.get('RichCompare'): if attrs.get('RichCompare').value in ('true', '1'): self.RichCompare = 1 @@ -1814,6 +1828,14 @@ class SaxGeneratemodelHandler(handler.ContentHandler): val = attrs.get('FatherNamespace', None) if val is not None: obj.setFathernamespace(val) + val = attrs.get('DisableNotify', None) + if val is not None: + if val in ('true', '1'): + obj.setDisablenotify(1) + elif val in ('false', '0'): + obj.setDisablenotify(0) + else: + self.reportError('"DisableNotify" attribute must be boolean ("true", "1", "false", "0")') val = attrs.get('RichCompare', None) if val is not None: if val in ('true', '1'): diff --git a/src/Tools/generateTemplates/templateClassPyExport.py b/src/Tools/generateTemplates/templateClassPyExport.py index 7cfada9600..72705888ef 100644 --- a/src/Tools/generateTemplates/templateClassPyExport.py +++ b/src/Tools/generateTemplates/templateClassPyExport.py @@ -621,10 +621,12 @@ int @self.export.Name@::staticCallback_set@i.Name@ (PyObject *self, PyObject *va + if (self.export.Reference): pcObject->ref(); - - + if (self.export.Initialization): initialization(); - ++ if (self.export.DisableNotify): + this->setShouldNotify(false); +- } + if not (self.export.Constructor):