From 56d6a202d640c79f9eabc49ffc59de9f2e65ac35 Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 9 Jul 2015 11:49:45 +0300 Subject: [PATCH] Issue #671 - Removing object used in feature creation with optional parameters. -- Add recursive search of references. --- src/XGUI/XGUI_Workshop.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 875b58e63..c694ae2b8 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1083,7 +1083,9 @@ void XGUI_Workshop::moveObjects() } //************************************************************** -std::set refFeatures(const ObjectPtr& theObject, bool checkAllDocuments = true) +std::set refFeatures(const ObjectPtr& theObject, + bool checkAllDocuments = true, + bool useRecursion = false) { std::set aRefFeatures; FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); @@ -1101,15 +1103,15 @@ std::set refFeatures(const ObjectPtr& theObject, bool checkAllDocume DocumentPtr aModuleDoc = aMgr->moduleDocument(); if (aFeatureDoc == aModuleDoc) { // the feature and results of the feature should be found in references - std::list aDeletedObjects; - aDeletedObjects.push_back(aFeature); + std::list aObjects; + aObjects.push_back(aFeature); typedef std::list > ResultsList; const ResultsList& aResults = aFeature->results(); ResultsList::const_iterator aRIter = aResults.begin(); for (; aRIter != aResults.cend(); aRIter++) { ResultPtr aRes = *aRIter; if (aRes.get()) - aDeletedObjects.push_back(aRes); + aObjects.push_back(aRes); } // get all opened documents; found features in the documents; // get a list of objects where a feature refers; @@ -1137,8 +1139,8 @@ std::set refFeatures(const ObjectPtr& theObject, bool checkAllDocume for(; aRef != aRefs.end() && !aHasReferenceToObjetc; aRef++) { std::list::iterator aRefObj = aRef->second.begin(); for(; aRefObj != aRef->second.end() && !aHasReferenceToObjetc; aRefObj++) { - std::list::const_iterator aObjIt = aDeletedObjects.begin(); - for(; aObjIt != aDeletedObjects.end() && !aHasReferenceToObjetc; aObjIt++) { + std::list::const_iterator aObjIt = aObjects.begin(); + for(; aObjIt != aObjects.end() && !aHasReferenceToObjetc; aObjIt++) { aHasReferenceToObjetc = *aObjIt == *aRefObj; } } @@ -1149,6 +1151,16 @@ std::set refFeatures(const ObjectPtr& theObject, bool checkAllDocume } } } + + // Run recursion + if (useRecursion) { + std::set::const_iterator aFeatureIt = aRefFeatures.begin(); + for (; aFeatureIt != aRefFeatures.end(); ++aFeatureIt) { + std::set aRecursiveRefFeatures = refFeatures(*aFeatureIt, checkAllDocuments, useRecursion); + aRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); + } + } + return aRefFeatures; } @@ -1171,7 +1183,7 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, // 1. find all referenced features std::set aRefFeatures; foreach (ObjectPtr aDeletedObj, theList) { - std::set aFeatures = refFeatures(aDeletedObj); + std::set aFeatures = refFeatures(aDeletedObj, true, true); aRefFeatures.insert(aFeatures.begin(), aFeatures.end()); } // 2. warn about the references remove, break the delete operation if the user chose it -- 2.39.2