Skip to content

Commit

Permalink
replacement for PR 698
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 27, 2017
1 parent 9aac25b commit df1e264
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/App/PropertyContainerPy.xml
Expand Up @@ -8,7 +8,8 @@
Include="App/PropertyContainer.h"
Namespace="App"
FatherInclude="Base/PersistencePy.h"
FatherNamespace="Base">
FatherNamespace="Base"
DisableNotify="true">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>This is a Persistence class</UserDocu>
Expand Down
6 changes: 5 additions & 1 deletion src/Base/PyObjectBase.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions src/Base/PyObjectBase.h
Expand Up @@ -193,6 +193,12 @@ class BaseExport PyObjectBase : public PyObject
*/
Py_Header

enum Status {
Valid = 0,
Immutable = 1,
Notify = 2
};

protected:
/// destructor
virtual ~PyObjectBase();
Expand Down Expand Up @@ -274,21 +280,29 @@ class BaseExport PyObjectBase : public PyObject

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();
Expand Down
1 change: 1 addition & 0 deletions src/Tools/generateBase/generateMetaModel_Module.xsd
Expand Up @@ -69,6 +69,7 @@
<xs:attribute name="Delete" type="xs:boolean" use="optional" default="false"/>
<xs:attribute name="Reference" type="xs:boolean" use="optional"/>
<xs:attribute name="Initialization" type="xs:boolean" use="optional" default="false"/>
<xs:attribute name="DisableNotify" type="xs:boolean" use="optional" default="false"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
26 changes: 24 additions & 2 deletions 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!
Expand Down Expand Up @@ -219,8 +219,9 @@ def buildChildren(self, child_, nodeName_):

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
Expand Down Expand Up @@ -271,6 +272,8 @@ def getClassdeclarations(self): return self.ClassDeclarations
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
Expand Down Expand Up @@ -309,6 +312,8 @@ def export(self, outfile, level, name_='PythonExport'):
outfile.write('</%s>\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(), ))
Expand Down Expand Up @@ -351,6 +356,8 @@ def exportLiteralAttributes(self, outfile, level, name_):
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(),))
Expand Down Expand Up @@ -428,6 +435,13 @@ def build(self, node_):
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
Expand Down Expand Up @@ -1814,6 +1828,14 @@ def startElement(self, name, attrs):
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'):
Expand Down
4 changes: 3 additions & 1 deletion src/Tools/generateTemplates/templateClassPyExport.py
Expand Up @@ -621,10 +621,12 @@ class @self.export.Namespace@Export @self.export.Name@ : public @self.export.Fat
+ if (self.export.Reference):
pcObject->ref();
-
+ if (self.export.Initialization):
initialization();
-
+ if (self.export.DisableNotify):
this->setShouldNotify(false);
-
}
+ if not (self.export.Constructor):
Expand Down

0 comments on commit df1e264

Please sign in to comment.