Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / Model / Model_Document.cpp
index 8ce08d8ee8442563d1a27a8b27a8ac60f483dcf1..ebc4de9d8871ea39ed8d1e4d6e4a0bf84057ee93 100755 (executable)
@@ -831,12 +831,37 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
   myObjs->removeFeature(theFeature);
 }
 
+// recursive function to check if theSub is a child of theMain composite feature
+// through all the hierarchy of parents
+static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
+  CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
+  if (!aParent.get())
+    return false;
+  if (aParent == theMain)
+    return true;
+  return isSub(theMain, aParent);
+}
+
+
 void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
 {
   bool aCurrentUp = theMoved == currentFeature(false);
   if (aCurrentUp) {
     setCurrentFeatureUp();
   }
+  // if user adds after high-level feature with nested, add it after all nested (otherwise the nested will be disabled)
+  CompositeFeaturePtr aCompositeAfter = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theAfterThis);
+  if (aCompositeAfter.get()) {
+    FeaturePtr aSub = aCompositeAfter;
+    do {
+      FeaturePtr aNext = myObjs->nextFeature(aSub);
+      if (!isSub(aCompositeAfter, aNext)) {
+        theAfterThis = aSub;
+        break;
+      }
+      aSub = aNext;
+    } while (aSub.get());
+  }
 
   myObjs->moveFeature(theMoved, theAfterThis);
   if (aCurrentUp) { // make the moved feature enabled or disabled due to the real status
@@ -921,17 +946,6 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theV
   return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
 }
 
-// recursive function to check if theSub is a child of theMain composite feature
-// through all the hierarchy of parents
-static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
-  CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
-  if (!aParent.get())
-    return false;
-  if (aParent == theMain)
-    return true;
-  return isSub(theMain, aParent);
-}
-
 void Model_Document::setCurrentFeature(
   std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theVisible)
 {