Salome HOME
Roll back the modification, not yet approved
[modules/shaper.git] / src / Model / Model_Update.cpp
index 244aa68678f78cc2ad1d0dbaa10869a6fafbfafe..fe86d7a28adceca6f28310204c29155bbf6ce631 100644 (file)
@@ -202,7 +202,7 @@ void Model_Update::iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeatu
         }
         // for the current breaked, set iteration to this feature precisely
         aBreaked->setCurrentBefore(theFeature);
-        myModification++;
+        //myModification++;
       }
       // the iterator that contains breaked is found, so, nothing else is needed
       return;
@@ -275,7 +275,7 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
     return;
 
   #ifdef DEB_UPDATE
-    //std::cout<<"Update Feature "<<theFeature->name()<<std::endl;
+    std::cout<<"Update Feature "<<theFeature->name()<<std::endl;
   #endif
   CompositeFeaturePtr aCompos = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
   // If automatice update is not needed and feature attributes were not updated right now,
@@ -298,7 +298,9 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
     if (!iterateUpdate(aCompos))
       return; // iteration was interrupted, so, interrupt the update of this feature (it will be done later)
     // reupdate arguments of composite feature: it may be changed during subs execution
-    if (theFeature->data()->execState() != ModelAPI_StateMustBeUpdated)
+
+    // issue 955: extrusion fuse sketch naming must be updated after the sketch update 
+    // so, comment this: if (theFeature->data()->execState() != ModelAPI_StateMustBeUpdated)
       updateArguments(theFeature);
   }
   // this checking must be after the composite feature sub-elements processing:
@@ -310,7 +312,13 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
   }
 
   // only the currently updated features are executed
-  bool aJustUpdated = myUpdated.find(theFeature) != myUpdated.end() && myUpdated[theFeature] == myModification;
+  bool aJustUpdated = myUpdated.find(theFeature) != myUpdated.end();
+  if (aJustUpdated) {
+    // if preview is not needed, the created feature was not updated before, so, myModification is not actual for this
+    if (theFeature->isPreviewNeeded()) {
+      aJustUpdated = myUpdated[theFeature] == myModification;
+    }
+  }
 
   if (myIsAutomatic && theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
     aJustUpdated = true;
@@ -350,6 +358,9 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
         #endif
         executeFeature(theFeature);
       } else {
+        #ifdef DEB_UPDATE
+          std::cout<<"Feature is not valid, erase results "<<theFeature->name()<<std::endl;
+        #endif
         theFeature->eraseResults();
         redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated
       }
@@ -380,6 +391,23 @@ void Model_Update::redisplayWithResults(FeaturePtr theFeature, const ModelAPI_Ex
       aRes->data()->setUpdateID(theFeature->data()->updateID());
     }
     ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
+    // iterate sub-bodies of compsolid
+    ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
+    if (aComp.get()) {
+      int aNumSub = aComp->numberOfSubs();
+      for(int a = 0; a < aNumSub; a++) {
+        ResultPtr aSub = aComp->subResult(a);
+        if (!aSub->isDisabled()) {// update state only for enabled results (Placement Result Part may make the original Part Result as invalid)
+          aSub->data()->execState(theState);
+          if (theState == ModelAPI_StateDone) // feature become "done", so execution changed results
+            myUpdated[aSub] = myModification;
+        }
+        if (theFeature->data()->updateID() > aSub->data()->updateID()) {
+          aSub->data()->setUpdateID(theFeature->data()->updateID());
+        }
+        ModelAPI_EventCreator::get()->sendUpdated(aSub, EVENT_DISP);
+      }
+    }
   }
   // to redisplay "presentable" feature (for ex. distance constraint)
   ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
@@ -566,7 +594,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
   // composite feature must be executed after sub-features execution
   if (aCompos) {
     // number of subs can be changed in execution: like fillet
-    for(int a = 0; a < aCompos->numberOfSubs(); a++) {
+    int aNumSubs = aCompos->numberOfSubs();
+    for(int a = 0; a < aNumSubs; a++) {
       FeaturePtr aSub = aCompos->subFeature(a);
       if (aSub.get() && aState == ModelAPI_StateDone) {
         if (isOlder(theFeature, aSub)) {
@@ -582,6 +611,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
           }
         }
       }
+      if (a == aNumSubs - 1) // in case number of subs is changed, just recheck before end
+        aNumSubs = aCompos->numberOfSubs();
     }
   }
 
@@ -654,7 +685,14 @@ void Model_Update::IterationItem::next()
           break;
       }
     } else if (mySub.get()) {
-      mySub = myObjects->nextFeature(mySub);
+      while(mySub.get()) {
+        mySub = myObjects->nextFeature(mySub);
+        CompositeFeaturePtr anOwner = ModelAPI_Tools::compositeOwner(mySub);
+        // skip sub-objects, that are subs not only for this: sketch elements relatively to PartSet
+        if (!anOwner.get()) {
+          break;
+        }
+      }
     }
   }
 }