From: spo Date: Fri, 24 Jul 2015 08:23:02 +0000 (+0300) Subject: Warning dialog before deletion shows directly dependent features and indirectly ones. X-Git-Tag: V_1.4.0_beta4~423 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6c5a66e84354a09ca460b5ec15b56cce6a9a696f;p=modules%2Fshaper.git Warning dialog before deletion shows directly dependent features and indirectly ones. --- diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 566329801..45398077f 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -174,7 +174,7 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature) //************************************************************** void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, - std::set& theRefFeatures) + std::set& theDirectRefFeatures, std::set& theIndirectRefFeatures) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (!aFeature.get()) @@ -187,7 +187,7 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP aLast = aRefFeatures.end(); for (; anIt != aLast; anIt++) { if (!isSubOfComposite(theSourceObject, *anIt)) - theRefFeatures.insert(*anIt); + theDirectRefFeatures.insert(*anIt); } // 2. find references in all documents if the document of the feature is @@ -242,19 +242,19 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP } } if (aHasReferenceToObject && !isSubOfComposite(theSourceObject, aFeature)) - theRefFeatures.insert(aFeature); + theDirectRefFeatures.insert(aFeature); } } } - // Run recursion. It is possible recusive dependency, like the folowing: plane, extrusion uses plane, + // 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 = theRefFeatures.begin(); - for (; aFeatureIt != theRefFeatures.end(); ++aFeatureIt) { - refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, aRecursiveRefFeatures); + std::set::const_iterator aFeatureIt = theDirectRefFeatures.begin(); + for (; aFeatureIt != theDirectRefFeatures.end(); ++aFeatureIt) { + refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, aRecursiveRefFeatures, aRecursiveRefFeatures); } - theRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); + theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); } } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 279e08560..b158a62c1 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -119,7 +119,8 @@ bool XGUI_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& */ void XGUI_EXPORT refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, - std::set& theRefFeatures); + std::set& theDirectRefFeatures, + std::set& theIndirectRefFeatures); }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 294452c6c..45248744d 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -85,6 +85,8 @@ #include #include +#include + #ifdef _DEBUG #include #include @@ -1126,32 +1128,42 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, #endif // 1. find all referenced features - std::set aRefFeatures; + std::set aDirectRefFeatures, aIndirectRefFeatures; foreach (ObjectPtr aDeletedObj, theList) { - XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aRefFeatures); + XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aDirectRefFeatures, aIndirectRefFeatures); + std::set aDifference; + std::set_difference(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end(), + aDirectRefFeatures.begin(), aDirectRefFeatures.end(), + std::inserter(aDifference, aDifference.begin())); + aIndirectRefFeatures = aDifference; } // 2. warn about the references remove, break the delete operation if the user chose it - if (theAskAboutDeleteReferences && !aRefFeatures.empty()) { - QStringList aRefNames; - std::set::const_iterator anIt = aRefFeatures.begin(), - aLast = aRefFeatures.end(); - for (; anIt != aLast; anIt++) { - aRefNames.append((*anIt)->name().c_str()); - } - QString aNames = aRefNames.join(", "); + if (theAskAboutDeleteReferences && !aDirectRefFeatures.empty()) { + QStringList aDirectRefNames; + foreach(const FeaturePtr& aFeature, aDirectRefFeatures) + aDirectRefNames.append(aFeature->name().c_str()); + QString aDirectNames = aDirectRefNames.join(", "); + + QStringList aIndirectRefNames; + foreach(const FeaturePtr& aFeature, aIndirectRefFeatures) + aIndirectRefNames.append(aFeature->name().c_str()); + QString aIndirectNames = aIndirectRefNames.join(", "); QMessageBox::StandardButton aRes = QMessageBox::warning( theParent, tr("Delete features"), QString(tr("Selected features are used in the following features: %1.\ -These features will be deleted also. Would you like to continue?")).arg(aNames), +These features will be deleted.\n%2Would you like to continue?")).arg(aDirectNames) + .arg(aIndirectNames.isEmpty() ? QString() : QString("Also these features will be deleted: %1.\n").arg(aIndirectNames)), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); if (aRes != QMessageBox::Yes) return false; } // 3. remove referenced features - std::set::const_iterator anIt = aRefFeatures.begin(), - aLast = aRefFeatures.end(); + std::set aFeaturesToDelete = aDirectRefFeatures; + aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end()); + std::set::const_iterator anIt = aFeaturesToDelete.begin(), + aLast = aFeaturesToDelete.end(); #ifdef DEBUG_DELETE QStringList anInfo; #endif