Salome HOME
Issue#1059: Consider operation state in selection validator
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
index b835629a7e37dbbb877aef8592f488b87741f4e0..fb0a8f2567dfa992722205900b0204dd9629a6a4 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Shape.h>
 
@@ -104,6 +105,23 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects)
   return aResult;
 }
 
+//******************************************************************
+bool canRename(QWidget* theParent, 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));
+      return false;
+    }
+  }
+
+  return true;
+}
+
 //******************************************************************
 bool allDocumentsActivated(QString& theNotActivatedNames)
 {
@@ -156,11 +174,16 @@ 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,
+                                 std::set<FeaturePtr>& 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<FeaturePtr> aRefFeatures;
@@ -169,7 +192,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
@@ -224,19 +247,20 @@ 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);
-  } 
-  theRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end());
+  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());
+  }
 }
 
 }