]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_Tools.cpp
Salome HOME
Delete key regression corrections: in previous implementation sketch entities did...
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
index fb0a8f2567dfa992722205900b0204dd9629a6a4..0b77c6c75cfb48c9a65acac5b5e8b0e93eb55905 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Tools.h>
+#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 
@@ -55,6 +56,18 @@ QString addSlash(const QString& path)
   return res;
 }
 
+//******************************************************************
+QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator)
+{
+  QStringList aObjectNames;
+  foreach (ObjectPtr aObj, theObjects) {
+    if (!aObj->data()->isValid())
+      continue;
+    aObjectNames << QString::fromStdString(aObj->data()->name());
+  }
+  return aObjectNames.join(", ");
+}
+
 //******************************************************************
 bool isModelObject(FeaturePtr theFeature)
 {
@@ -106,15 +119,16 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects)
 }
 
 //******************************************************************
-bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName)
+bool canRename(const ObjectPtr& theObject, const QString& theName)
 {
   if (std::dynamic_pointer_cast<ModelAPI_ResultParameter>(theObject).get()) {
     double aValue;
     ResultParameterPtr aParam;
     if (ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam)) {
-      QMessageBox::information(theParent, QObject::tr("Rename parameter"),
-          QString(QObject::tr("Selected parameter can not be renamed to: %1. \
-There is a parameter with the same name. Its value is: %2.")).arg(qPrintable(theName)).arg(aValue));
+      QString aErrMsg(QObject::tr("Selected parameter can not be renamed to: %1. \
+ There is a parameter with the same name. Its value is: %2.").arg(qPrintable(theName)).arg(aValue));
+      // We can not use here a dialog box for message - it will crash editing process in ObjectBrowser
+      Events_Error::send(aErrMsg.toStdString());
       return false;
     }
   }
@@ -172,11 +186,47 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
   return isSub;
 }
 
+//**************************************************************
+bool isSubOfComposite(const ObjectPtr& theObject)
+{
+  bool isSub = false;
+  std::set<FeaturePtr> aRefFeatures;
+  refsToFeatureInFeatureDocument(theObject, aRefFeatures);
+  std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
+                                       aLast = aRefFeatures.end();
+  for (; anIt != aLast && !isSub; anIt++) {
+    isSub = isSubOfComposite(theObject, *anIt);
+  }
+  return isSub;
+}
+
 //**************************************************************
 void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject,
+                                 const QObjectPtrList& theIgnoreList,
                                  std::set<FeaturePtr>& theDirectRefFeatures, 
                                  std::set<FeaturePtr>& theIndirectRefFeatures,
                                  std::set<FeaturePtr>& theAlreadyProcessed)
+{
+  refsDirectToFeatureInAllDocuments(theSourceObject, theObject, theIgnoreList, theDirectRefFeatures, 
+                                    theAlreadyProcessed);
+
+  // 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>::const_iterator aFeatureIt = theDirectRefFeatures.begin();
+  for (; aFeatureIt != theDirectRefFeatures.end(); ++aFeatureIt) {
+    std::set<FeaturePtr> aRecursiveRefFeatures;
+    refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, theIgnoreList,
+      aRecursiveRefFeatures, aRecursiveRefFeatures, theAlreadyProcessed);
+    theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end());
+  }
+
+}
+
+//**************************************************************
+void refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject,
+                                       const QObjectPtrList& theIgnoreList,
+                                       std::set<FeaturePtr>& theDirectRefFeatures, 
+                                       std::set<FeaturePtr>& theAlreadyProcessed)
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
   if (!aFeature.get())
@@ -186,12 +236,14 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP
   theAlreadyProcessed.insert(aFeature);
 
   // 1. find references in the current document
+
   std::set<FeaturePtr> aRefFeatures;
   refsToFeatureInFeatureDocument(theObject, aRefFeatures);
   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                        aLast = aRefFeatures.end();
   for (; anIt != aLast; anIt++) {
-    if (!isSubOfComposite(theSourceObject, *anIt))
+    // composite feature should not be deleted when the sub feature is to be deleted
+    if (!isSubOfComposite(theSourceObject, *anIt) && !theIgnoreList.contains(*anIt))
       theDirectRefFeatures.insert(*anIt);
   }
 
@@ -246,21 +298,12 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP
             }
           }
         }
-        if (aHasReferenceToObject && !isSubOfComposite(theSourceObject, aFeature))
+        if (aHasReferenceToObject && !isSubOfComposite(theSourceObject, aFeature) &&
+            !theIgnoreList.contains(aFeature))
           theDirectRefFeatures.insert(aFeature);
       }
     }
   }
-
-  // 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>::const_iterator aFeatureIt = theDirectRefFeatures.begin();
-  for (; aFeatureIt != theDirectRefFeatures.end(); ++aFeatureIt) {
-    std::set<FeaturePtr> aRecursiveRefFeatures;
-    refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, 
-      aRecursiveRefFeatures, aRecursiveRefFeatures, theAlreadyProcessed);
-    theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end());
-  }
 }
 
 }