]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Warning dialog before deletion shows directly dependent features and indirectly ones.
authorspo <sergey.pokhodenko@opencascade.com>
Fri, 24 Jul 2015 08:23:02 +0000 (11:23 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Thu, 6 Aug 2015 08:54:56 +0000 (11:54 +0300)
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_Workshop.cpp

index 5663298017804a0df23d6a3d9e61bfea31f51872..45398077f6f74fd50603f75f5d93ebc09db61055 100644 (file)
@@ -174,7 +174,7 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
 
 //**************************************************************
 void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject,
-                                 std::set<FeaturePtr>& theRefFeatures)
+                                 std::set<FeaturePtr>& theDirectRefFeatures, std::set<FeaturePtr>& 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<FeaturePtr> aRecursiveRefFeatures;
-  std::set<FeaturePtr>::const_iterator aFeatureIt = theRefFeatures.begin();
-  for (; aFeatureIt != theRefFeatures.end(); ++aFeatureIt) {
-    refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, aRecursiveRefFeatures);
+  std::set<FeaturePtr>::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());
 }
 
 }
index 279e08560b6e60116bd8abbabce9c8c37c1bb1e0..b158a62c1250e2d5af992e8d96e6eb5b24ecb52e 100644 (file)
@@ -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<FeaturePtr>& theRefFeatures);
+                                             std::set<FeaturePtr>& theDirectRefFeatures,
+                                             std::set<FeaturePtr>& theIndirectRefFeatures);
 };
 
 #endif
index 294452c6cc6465b6b73776bd0813170072958a6c..45248744d1f134b0ced22a7de26cd085055f59db 100644 (file)
@@ -85,6 +85,8 @@
 #include <QAction>
 #include <QDesktopWidget>
 
+#include <iterator>
+
 #ifdef _DEBUG
 #include <QDebug>
 #include <iostream>
@@ -1126,32 +1128,42 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
 #endif
 
   // 1. find all referenced features
-  std::set<FeaturePtr> aRefFeatures;
+  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
   foreach (ObjectPtr aDeletedObj, theList) {
-    XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aRefFeatures);
+    XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, aDirectRefFeatures, aIndirectRefFeatures);
+    std::set<FeaturePtr> 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<FeaturePtr>::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<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
-                                       aLast = aRefFeatures.end();
+  std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
+  aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
+  std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
+                                       aLast = aFeaturesToDelete.end();
 #ifdef DEBUG_DELETE
   QStringList anInfo;
 #endif