Salome HOME
Issue #2615 : EDF 2018-3 Sub-results states
[modules/shaper.git] / src / Model / Model_Objects.cpp
index 199b249c34ce234e396e11a4670ec7960bfe3fa7..70183795c0f94329fc2eb74310a998e5d7ed8e98 100644 (file)
@@ -378,6 +378,9 @@ void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
   if (theAfterThis.get())
     anAfterLab = std::dynamic_pointer_cast<Model_Data>(theAfterThis->data())->label().Father();
 
+  // check whether some folder refers to the moved feature by start or end: if yes, remove from it
+  removeFromFolder(std::list<FeaturePtr>(1, theMoved));
+
   Handle(TDataStd_HLabelArray1) aNewArray =
     new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper());
   int aPassedMovedFrom = 0; // the prev feature location is found and passed
@@ -576,7 +579,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
           if (aSub.get()) {
             std::shared_ptr<Model_Data> aSubData = std::dynamic_pointer_cast<Model_Data>(
               aSub->data());
-            if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) {
+            const TDF_Label& aSubLabVal = aSubLab.ChangeValue();
+            if (aSubData->label().Father().IsEqual(aSubLabVal)) {
               aCurrentResult = aSub;
               break;
             }
@@ -588,7 +592,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
         const std::list<ResultPtr>& aResults = aFeature->results();
         std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
         for(; aRIter != aResults.cend(); aRIter++) {
-          std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+          std::shared_ptr<Model_Data> aResData =
+            std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
           if (aResData->label().Father().IsEqual(aSubLab.ChangeValue())) {
             aCurrentResult = *aRIter;
             break;
@@ -682,8 +687,8 @@ std::shared_ptr<ModelAPI_Object> Model_Objects::parent(
   if (theChild.get()) {
     std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theChild->data());
     TDF_Label aLab = aData->label();
-    if (!aLab.IsNull() && aLab.Depth() > 1) {
-      ObjectPtr anObj = object(aLab.Father().Father());
+    if (!aLab.IsNull() && aLab.Depth() > 2) {
+      ObjectPtr anObj = object(aLab.Father().Father().Father());
       return anObj;
     }
   }
@@ -1180,23 +1185,28 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   std::string& theParentName) const
 {
   ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
-  if(aBodyRes) {
+  if (aBodyRes) {
+    // only for top-results (works for the cases when results are not yet added to the feature)
     FeaturePtr anOwner = ModelAPI_Feature::feature(theResult);
 
     // names of sub-solids in CompSolid should be default (for example,
     // result of boolean operation 'Boolean_1' is a CompSolid which is renamed to 'MyBOOL',
     // however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1', 'Boolean_1_2' etc.)
-    std::ostringstream aDefaultName;
-    aDefaultName << anOwner->name();
-    // compute default name of CompSolid (name of feature + index of CompSolid's result)
-    int aBodyResultIndex = 0;
-    const std::list<ResultPtr>& aResults = anOwner->results();
-    std::list<ResultPtr>::const_iterator anIt = aResults.begin();
-    for(; anIt != aResults.end(); ++anIt, ++aBodyResultIndex)
-      if(aBodyRes == *anIt)
-        break;
-    aDefaultName << "_" << (aBodyResultIndex + 1);
-    theParentName = aDefaultName.str();
+    if (std::dynamic_pointer_cast<Model_Data>(aBodyRes->data())->label().Depth() == 6) {
+      std::ostringstream aDefaultName;
+      // compute default name of CompSolid (name of feature + index of CompSolid's result)
+      int aBodyResultIndex = 0;
+      const std::list<ResultPtr>& aResults = anOwner->results();
+      std::list<ResultPtr>::const_iterator anIt = aResults.begin();
+      for (; anIt != aResults.end(); ++anIt, ++aBodyResultIndex)
+        if (aBodyRes == *anIt)
+          break;
+      aDefaultName << anOwner->name();
+      aDefaultName << "_" << (aBodyResultIndex + 1);
+      theParentName = aDefaultName.str();
+    } else { // just name of the parent result if it is deeper than just a sub-result
+      theParentName = aBodyRes->data()->name();
+    }
     return false;
   }
 
@@ -1888,6 +1898,15 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
       }
     }
   }
+  if (aResSize > 0) { // check there exist a body that must be updated
+    std::list<ResultPtr>::const_iterator aRes = theFeature->results().cbegin();
+    for (; aResSize && aRes != theFeature->results().cend(); aRes++, aResSize++) {
+      if ((*aRes)->data()->isValid() && (*aRes)->groupName() == ModelAPI_ResultBody::group()) {
+        ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
+        aBody->updateSubs(aBody->shape(), false);
+      }
+    }
+  }
 }
 
 ResultPtr Model_Objects::findByName(const std::string theName)