From 9e56242a29b413aea515c580cfb17cc10ff63fbc Mon Sep 17 00:00:00 2001 From: jriegel Date: Wed, 7 Dec 2011 21:24:44 +0000 Subject: [PATCH] + fix bug #525 + update document undo/redo test cases git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5232 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/App/Document.cpp | 19 +++++++++++++++++++ src/App/Document.h | 4 +++- src/Mod/Test/Document.py | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 04ae89130..457bc8143 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -297,6 +297,16 @@ void Document::openTransaction(const char* name) } } +void Document::_checkTransaction(void) +{ + // if the undo is active but no transaction open, open one! + if (d->iUndoMode) + if (! d->activeUndoTransaction) + openTransaction(); + +} + + void Document::_clearRedos() { while (!mRedoTransactions.empty()) { @@ -410,6 +420,7 @@ void Document::onChanged(const Property* prop) void Document::onBeforeChangeProperty(const DocumentObject *Who, const Property *What) { + _checkTransaction(); if (d->activeUndoTransaction && !d->rollback) d->activeUndoTransaction->addObjectChange(Who,What); } @@ -1221,6 +1232,8 @@ bool Document::_recomputeFeature(DocumentObject* Feat) void Document::recomputeFeature(DocumentObject* Feat) { + _checkTransaction(); + // delete recompute log for( std::vector::iterator it=_RecomputeLog.begin();it!=_RecomputeLog.end();++it) delete *it; @@ -1287,6 +1300,8 @@ DocumentObject * Document::addObject(const char* sType, const char* pObjectName) void Document::_addObject(DocumentObject* pcObject, const char* pObjectName) { + _checkTransaction(); + d->objectMap[pObjectName] = pcObject; d->objectArray.push_back(pcObject); // cache the pointer to the name string in the Object (for performance of DocumentObject::getNameInDocument()) @@ -1308,6 +1323,8 @@ void Document::_addObject(DocumentObject* pcObject, const char* pObjectName) /// Remove an object out of the document void Document::remObject(const char* sName) { + _checkTransaction(); + std::map::iterator pos = d->objectMap.find(sName); // name not found? @@ -1365,6 +1382,8 @@ void Document::remObject(const char* sName) /// Remove an object out of the document (internal) void Document::_remObject(DocumentObject* pcObject) { + _checkTransaction(); + std::map::iterator pos = d->objectMap.find(pcObject->getNameInDocument()); if (d->activeObject == pcObject) diff --git a/src/App/Document.h b/src/App/Document.h index ea223e307..cca26ecdc 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -260,7 +260,9 @@ protected: void _remObject(DocumentObject* pcObject); void _addObject(DocumentObject* pcObject, const char* pObjectName); DocumentObject* _copyObject(DocumentObject* obj, std::map&, bool recursive=false); + DocumentObject*>&, bool rcursive=false); + /// checks if a valid transaction is open + void _checkTransaction(void); void breakDependency(DocumentObject* pcObject, bool clear); void onChanged(const Property* prop); diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index dd6392693..3d3189dba 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -244,6 +244,7 @@ class DocumentRecomputeCases(unittest.TestCase): class UndoRedoCases(unittest.TestCase): def setUp(self): self.Doc = FreeCAD.newDocument("UndoTest") + self.Doc.UndoMode = 0 self.Doc.addObject("App::FeatureTest","Base") self.Doc.addObject("App::FeatureTest","Del") self.Doc.getObject("Del").Integer = 2