From 99f199ad7e763263b6138eb79a9fb2a14674ce10 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 4 Jan 2020 17:22:52 +0800 Subject: [PATCH] App: fix pending object remove on recomputing --- src/App/Document.cpp | 18 +++++++++++++----- src/App/DocumentObject.h | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 270ae7991e..3db5e438c3 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -127,6 +127,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees. #include "Origin.h" #include "OriginGroupExtension.h" #include "Link.h" +#include "DocumentObserver.h" #include "GeoFeature.h" FC_LOG_LEVEL_INIT("App", true, true, true) @@ -174,6 +175,7 @@ struct DocumentP std::unordered_map objectMap; std::unordered_map objectIdMap; std::unordered_map partialLoadObjects; + std::vector pendingRemove; long lastObjectId; DocumentObject* activeObject; Transaction *activeUndoTransaction; @@ -3558,16 +3560,22 @@ int Document::recompute(const std::vector &objs, bool forc continue; obj->setStatus(ObjectStatus::PendingRecompute,false); obj->setStatus(ObjectStatus::Recompute2,false); - if(obj->testStatus(ObjectStatus::PendingRemove)) - obj->getDocument()->removeObject(obj->getNameInDocument()); } signalRecomputed(*this,topoSortedObjects); FC_TIME_LOG(t,"Recompute total"); - if (d->_RecomputeLog.size()) - Base::Console().Log("Recompute failed! Please check report view.\n"); + if(d->_RecomputeLog.size()) { + d->pendingRemove.clear(); + Base::Console().Error("Recompute failed! Please check report view.\n"); + } else { + for(auto &o : d->pendingRemove) { + auto obj = o.getObject(); + if(obj) + obj->getDocument()->removeObject(obj->getNameInDocument()); + } + } return objectCount; } @@ -4097,7 +4105,7 @@ void Document::removeObject(const char* sName) if (pos->second->testStatus(ObjectStatus::PendingRecompute)) { // TODO: shall we allow removal if there is active undo transaction? FC_LOG("pending remove of " << sName << " after recomputing document " << getName()); - pos->second->setStatus(ObjectStatus::PendingRemove,true); + d->pendingRemove.emplace_back(pos->second); return; } diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 75fd9642d8..eb9a949d0b 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -58,7 +58,6 @@ enum ObjectStatus { Recompute2 = 9, // set when the object is being recomputed in the second pass PartialObject = 10, PendingRecompute = 11, // set by Document, indicating the object is in recomputation queue - PendingRemove = 12, // set by Document, indicating the object is in pending for remove after recompute ObjImporting = 13, // Mark the object as importing NoTouch = 14, // no touch on any property change GeoExcluded = 15, // mark as a member but not claimed by GeoFeatureGroup