Salome HOME
Make not-stable features lose the concealment ability
[modules/shaper.git] / src / Model / Model_Update.cpp
index 4b4ac45a22a937e84424f373e8627ff58795c573..21e38c5a49de0145a6f0cfa2f98f6c3e934e5f11 100644 (file)
@@ -54,9 +54,12 @@ Model_Update::Model_Update()
   aLoop->registerListener(this, kOpAbortEvent);
   static const Events_ID kOpStartEvent = aLoop->eventByName("StartOperation");
   aLoop->registerListener(this, kOpStartEvent);
+  static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
+  aLoop->registerListener(this, kStabilityEvent);
 
+  /* not needed now with history line
   Config_PropManager::registerProp("Model update", "automatic_rebuild", "Rebuild immediately",
-                                   Config_Prop::Boolean, "false");
+                                   Config_Prop::Boolean, "false");*/
   myIsAutomatic = true;
   //  Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
   myIsParamUpdated = false;
@@ -75,17 +78,21 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   static const Events_ID kOpFinishEvent = aLoop->eventByName("FinishOperation");
   static const Events_ID kOpAbortEvent = aLoop->eventByName("AbortOperation");
   static const Events_ID kOpStartEvent = aLoop->eventByName("StartOperation");
+  static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
 #ifdef DEB_UPDATE
   std::cout<<"****** Event "<<theMessage->eventID().eventText()<<std::endl;
 #endif
+  if (theMessage->eventID() == kStabilityEvent)
+    updateStability(theMessage->sender());
   if (theMessage->eventID() == kChangedEvent) { // automatic and manual rebuild flag is changed
-    bool aPropVal =
+    /*bool aPropVal =
       Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
     if (aPropVal != myIsAutomatic) { // something is changed
       // myIsAutomatic = aPropVal;
       if (myIsAutomatic) // higher level of automatization => to rebuild
         processOperation(false);
-    }
+    }*/
+    return;
   } else if (theMessage->eventID() == kRebuildEvent) { // the rebuild command
     processOperation(true);
   } else if (theMessage->eventID() == kCreatedEvent || theMessage->eventID() == kUpdatedEvent ||
@@ -202,7 +209,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;
@@ -216,6 +223,7 @@ void Model_Update::iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeatu
 
 void Model_Update::processOperation(const bool theTotalUpdate, const bool theFinish)
 {
+  /* cancel hardcode due to issue 948
   if (theFinish) {
     // the hardcode (DBC asked): hide the sketch referenced by extrusion on apply
     std::set<std::shared_ptr<ModelAPI_Object> >::iterator aFIter;
@@ -235,7 +243,7 @@ void Model_Update::processOperation(const bool theTotalUpdate, const bool theFin
         }
       }
     }
-  }
+  } */
   // perform update of everything if needed
   if (!myIsExecuted) {
     #ifdef DEB_UPDATE
@@ -271,11 +279,25 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
   // check all features this feature depended on (recursive call of updateFeature)
   static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
 
-  if (theFeature->isDisabled())
+  if (theFeature->isDisabled()) {
+    // possibly sub-elements are not disabled?
+    CompositeFeaturePtr aCompos = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+    if (aCompos)
+      iterateUpdate(aCompos);
     return;
+  }
+
+  // do not execute the composite that contains the current
+  bool isPostponedMain = false;
+  CompositeFeaturePtr aMain = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+  if (theFeature->getKind() == "ExtrusionSketch" && aMain.get()) {
+    CompositeFeaturePtr aCurrentOwner = 
+      ModelAPI_Tools::compositeOwner(theFeature->document()->currentFeature(false));
+    isPostponedMain = aCurrentOwner.get() && aMain->isSub(aCurrentOwner);
+  }
 
   #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 +320,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:
@@ -351,11 +375,16 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
     if (aJustUpdated) {
       ModelAPI_ExecState aState = theFeature->data()->execState();
       if (aFactory->validate(theFeature)) {
+        if (!isPostponedMain) {
+          #ifdef DEB_UPDATE
+            std::cout<<"Execute Feature "<<theFeature->name()<<std::endl;
+          #endif
+          executeFeature(theFeature);
+        }
+      } else {
         #ifdef DEB_UPDATE
-          std::cout<<"Execute Feature "<<theFeature->name()<<std::endl;
+          std::cout<<"Feature is not valid, erase results "<<theFeature->name()<<std::endl;
         #endif
-        executeFeature(theFeature);
-      } else {
         theFeature->eraseResults();
         redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated
       }
@@ -363,8 +392,10 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
   } else { // preview is not needed => make state Done
     if (theFeature->data()->execState() == ModelAPI_StateMustBeUpdated) {
       theFeature->data()->execState(ModelAPI_StateDone);
-      if (aJustUpdated) // store that it must be updated on finish
+      if (aJustUpdated) {// store that it must be updated on finish
         myUpdated[theFeature] = myModification;
+        aFactory->validate(theFeature); // need to be validated to update the "Apply" state if not previewed
+      }
     }
   }
 }
@@ -530,7 +561,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
             aState = ModelAPI_StateInvalidArgument;
         }
       } else if (aSel->isInvalid()) { // not needed to update, but invalid (stated previously)
-        aState = ModelAPI_StateInvalidArgument;
+        if (isObligatory)
+          aState = ModelAPI_StateInvalidArgument;
       }
     }
   }
@@ -556,7 +588,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
                 aState = ModelAPI_StateInvalidArgument;
             }
           } else if (aSelAttr->isInvalid()) {
-            aState = ModelAPI_StateInvalidArgument;
+            if (isObligatory)
+              aState = ModelAPI_StateInvalidArgument;
           }
         }
       }
@@ -641,6 +674,18 @@ void Model_Update::executeFeature(FeaturePtr theFeature)
   redisplayWithResults(theFeature, aState);
 }
 
+void Model_Update::updateStability(void* theSender)
+{
+  ModelAPI_Object* aSender = static_cast<ModelAPI_Object*>(theSender);
+  if (aSender && aSender->document()) {
+    Model_Objects* aDocObjects = 
+      std::dynamic_pointer_cast<Model_Document>(aSender->document())->objects();
+    if (aDocObjects) {
+      aDocObjects->synchronizeBackRefs();
+    }
+  }
+}
+
 ///////////////// Updated items iterator ////////////////////////
 Model_Update::IterationItem::IterationItem(std::shared_ptr<ModelAPI_CompositeFeature> theFeature)
 {
@@ -680,7 +725,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;
+        }
+      }
     }
   }
 }