From: mpv Date: Thu, 17 Sep 2015 13:09:05 +0000 (+0300) Subject: Fix for hang up (and crash after) on remove of all features in the complicated model... X-Git-Tag: V_1.4.0~34 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dd95011fbb229596148cdbec3f091ac59866790c;p=modules%2Fshaper.git Fix for hang up (and crash after) on remove of all features in the complicated model (model_with_parameters2.hdf) --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index a657f75ef..e2a002640 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -746,7 +746,7 @@ std::shared_ptr Model_Document::currentFeature(const bool theV } void Model_Document::setCurrentFeature(std::shared_ptr theCurrent, - const bool theVisible) + const bool theVisible, const bool theFlushUpdates) { // blocks the flush signals to avoid each objects visualization in the viewer // they should not be shown once after all modifications are performed @@ -841,9 +841,11 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr // unblock the flush signals and up them after this aLoop->activateFlushes(isActive); - aLoop->flush(aCreateEvent); - aLoop->flush(aRedispEvent); - aLoop->flush(aDeleteEvent); + if (theFlushUpdates) { + aLoop->flush(aCreateEvent); + aLoop->flush(aRedispEvent); + aLoop->flush(aDeleteEvent); + } } void Model_Document::setCurrentFeatureUp() @@ -853,7 +855,8 @@ void Model_Document::setCurrentFeatureUp() FeaturePtr aCurrent = currentFeature(false); if (aCurrent.get()) { // if not, do nothing because null is the upper FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true); - setCurrentFeature(aPrev, false); + // do not flush: it is called only on remove, it will be flushed in the end of transaction + setCurrentFeature(aPrev, false, false); } } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index ad28e74d4..a3f28a20f 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -135,7 +135,7 @@ class Model_Document : public ModelAPI_Document //! \param theCurrent the selected feature as current: blow it everythin become disabled //! \param theVisible use visible features only: flag is true for Object Browser functionality MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr theCurrent, - const bool theVisible); + const bool theVisible, const bool theFlushUpdates = true); //! Makes the current feature one feature upper MODEL_EXPORT virtual void setCurrentFeatureUp(); diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 03a740af2..0f4ccc330 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -103,8 +103,9 @@ public: //! will be appended after this one. //! \param theCurrent the selected feature as current: blow it everythin become disabled //! \param theVisible use visible features only: flag is true for Object Browser functionality + //! \param theFlushUpdates if it is true (default) it flashes creation/redisplay/delete messages virtual void setCurrentFeature(std::shared_ptr theCurrent, - const bool theVisible) = 0; + const bool theVisible, const bool theFlushUpdates = true) = 0; //! Makes the current feature one feature upper virtual void setCurrentFeatureUp() = 0; diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 45398077f..fb0a8f256 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -174,11 +174,16 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature) //************************************************************** void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, - std::set& theDirectRefFeatures, std::set& theIndirectRefFeatures) + std::set& theDirectRefFeatures, + std::set& theIndirectRefFeatures, + std::set& theAlreadyProcessed) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (!aFeature.get()) return; + if (theAlreadyProcessed.find(aFeature) != theAlreadyProcessed.end()) + return; + theAlreadyProcessed.insert(aFeature); // 1. find references in the current document std::set aRefFeatures; @@ -249,12 +254,13 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP // Run recursion. It is possible recursive dependency, like the following: plane, extrusion uses plane, // axis is built on extrusion. Delete of a plane should check the dependency from the axis also. - std::set aRecursiveRefFeatures; std::set::const_iterator aFeatureIt = theDirectRefFeatures.begin(); for (; aFeatureIt != theDirectRefFeatures.end(); ++aFeatureIt) { - refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, aRecursiveRefFeatures, aRecursiveRefFeatures); - } - theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); + std::set aRecursiveRefFeatures; + refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, + aRecursiveRefFeatures, aRecursiveRefFeatures, theAlreadyProcessed); + theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); + } } } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index b158a62c1..178b8b2a4 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -115,12 +115,14 @@ bool XGUI_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& which has the object as a sub object. \param theSourceObject an object, which references are searched \param theObject an intermediate recursive object, should be set in the source object + \param theAlreadyProcessed set of processed elements, used for optimization (do not reanalyse processed) \return a boolean value */ void XGUI_EXPORT refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, std::set& theDirectRefFeatures, - std::set& theIndirectRefFeatures); + std::set& theIndirectRefFeatures, + std::set& theAlreadyProcessed); }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index f6ee0f99d..971502814 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1211,7 +1211,9 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, // 1. find all referenced features std::set aDirectRefFeatures, aIndirectRefFeatures; foreach (ObjectPtr aDeletedObj, theList) { - XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aDirectRefFeatures, aIndirectRefFeatures); + std::set alreadyProcessed; + XGUI_Tools::refsToFeatureInAllDocuments( + aDeletedObj, aDeletedObj, aDirectRefFeatures, aIndirectRefFeatures, alreadyProcessed); std::set aDifference; std::set_difference(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end(), aDirectRefFeatures.begin(), aDirectRefFeatures.end(),