Salome HOME
Debug of the sketch faces selection in external document
[modules/shaper.git] / src / Model / Model_Objects.cpp
index b3b21793043789b434d0c4b7a51e2f4123786290..9d89e5c64c37a4d9499513f7b80eb0f52840d0b6 100644 (file)
@@ -41,7 +41,6 @@
 #include <TDF_ChildIDIterator.hxx>
 #include <TDataStd_ReferenceArray.hxx>
 #include <TDataStd_HLabelArray1.hxx>
-#include <TDataStd_Name.hxx>
 #include <TDF_Reference.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDF_LabelMapHasher.hxx>
@@ -364,7 +363,7 @@ void Model_Objects::eraseAllFeatures()
   }
   kCreator->sendDeleted(myDoc, ModelAPI_Feature::group());
   myFeatures.Clear(); // just remove features without modification of DS
-  updateHistory(ModelAPI_Feature::group());
+  myHistory.clear();
 }
 
 void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
@@ -378,6 +377,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
@@ -1182,24 +1184,28 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   std::string& theParentName) const
 {
   ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
-  if (aBodyRes && std::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Depth() < 7) {
+  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;
   }
 
@@ -1833,8 +1839,6 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
     }
   }
 
-  // for not persistent is will be done by parametric updater automatically
-  //if (!theFeature->isPersistentResult()) return;
   // check the existing results and remove them if there is nothing on the label
   std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
   while(aResIter != theFeature->results().cend()) {
@@ -1874,7 +1878,11 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
             // create the part result: it is better to restore the previous result if it is possible
             theFeature->execute();
         } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
-          theFeature->execute(); // construction shapes are needed for sketch solver
+          ResultConstructionPtr aConstr = createConstruction(theFeature->data(), aResIndex);
+          if (!aConstr->updateShape())
+            theFeature->execute(); // not stored shape in the data structure, execute to have it
+          else
+            theFeature->setResult(aConstr, aResIndex); // result is ready without execution
         } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
           aNewBody = createGroup(theFeature->data(), aResIndex);
         } else if (aGroup->Get() == ModelAPI_ResultField::group().c_str()) {
@@ -1894,9 +1902,16 @@ 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());
+      if ((*aRes)->data()->isValid()) {
+        if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
+          ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
+          aBody->updateSubs(aBody->shape(), false);
+        } else if ((*aRes)->groupName() == ModelAPI_ResultConstruction::group()) {
+          // update the cashed myShape presented in construction
+          ResultConstructionPtr aConstr =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+          aConstr->updateShape();
+        }
       }
     }
   }
@@ -1978,11 +1993,12 @@ FeaturePtr Model_Objects::lastFeature()
 {
   Handle(TDataStd_ReferenceArray) aRefs;
   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
-    FeaturePtr aLast = feature(aRefs->Value(aRefs->Upper()));
+    // comment this because of #2674 - features are removed from array on deactivation of Part
+    /*FeaturePtr aLast = feature(aRefs->Value(aRefs->Upper()));
     if (!aLast.get() && aRefs->Length() != 0) { // erase the invalid feature from the array
       RemoveFromRefArray(featuresLabel(), aRefs->Value(aRefs->Upper()));
       return lastFeature(); // try once again, after the last was removed
-    }
+    }*/
     return feature(aRefs->Value(aRefs->Upper()));
   }
   return FeaturePtr(); // no features at all