]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2612 : Re-calculate model after modification of parameters
authormpv <mpv@opencascade.com>
Tue, 4 Sep 2018 07:31:14 +0000 (10:31 +0300)
committermpv <mpv@opencascade.com>
Tue, 4 Sep 2018 07:31:14 +0000 (10:31 +0300)
Preparation for implementation: events and initial processing

src/Model/Model_Update.cpp
src/Model/Model_Update.h
src/ModelAPI/ModelAPI_Events.h

index 05a9998d837bbb127b30c31ac007a0f779d66395..7ff05ab136af3cd2e33ba7b5d0374917eb066ada 100755 (executable)
@@ -80,6 +80,7 @@ Model_Update::Model_Update()
   myIsFinish = false;
   myIsProcessed = false;
   myIsPreviewBlocked = false;
+  myUpdateBlocked = false;
 }
 
 bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
@@ -105,7 +106,7 @@ bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
   }
 
   // update arguments for "apply button" state change
-  if ((!theFeature->isPreviewNeeded() && !myIsFinish) || myIsPreviewBlocked) {
+  if ((!theFeature->isPreviewNeeded() && !myIsFinish) || myIsPreviewBlocked || myUpdateBlocked) {
     if (theReason.get())
       myProcessOnFinish[theFeature].insert(theReason);
     else if (myProcessOnFinish.find(theFeature) == myProcessOnFinish.end())
@@ -135,7 +136,7 @@ bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
       aLoop->flush(kRedisplayEvent);
     }
 
-    if (!myIsPreviewBlocked)
+    if (!myIsPreviewBlocked && !myUpdateBlocked)
       return true;
   }
   if (myModified.find(theFeature) != myModified.end()) {
@@ -161,7 +162,7 @@ bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
       if (theReason.get())
         aNewSet.insert(theReason);
     }
-      myModified[theFeature] = aNewSet;
+    myModified[theFeature] = aNewSet;
 #ifdef DEB_UPDATE
     if (theReason.get()) {
       //std::cout<<"*** Add modified "<<theFeature->name()
@@ -232,6 +233,8 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   static const Events_ID kReorderEvent = aLoop->eventByName(EVENT_ORDER_UPDATED);
   static const Events_ID kRedisplayEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const Events_ID kUpdatedSel = aLoop->eventByName(EVENT_UPDATE_SELECTION);
+  static const Events_ID kAutomaticOff = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE);
+  static const Events_ID kAutomaticOn = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_ENABLE);
 
 #ifdef DEB_UPDATE
   std::cout<<"****** Event "<<theMessage->eventID().eventText()<<std::endl;
@@ -246,12 +249,27 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   }
   if (theMessage->eventID() == kPreviewRequestedEvent) {
     if (myIsPreviewBlocked) {
+      bool anUpdateState = myUpdateBlocked;
+      myUpdateBlocked = false;
       myIsPreviewBlocked = false;
       processFeatures();
       myIsPreviewBlocked = true;
+      myUpdateBlocked = anUpdateState;
     }
     return;
   }
+  if (theMessage->eventID() == kAutomaticOff) {
+    myUpdateBlocked = true;
+    return;
+  }
+  if (theMessage->eventID() == kAutomaticOn) {
+    myUpdateBlocked = false; // then process all modified features, even if preview is blocked
+    bool aPreviewBlockedState = myIsPreviewBlocked; // to update the selected arguments
+    myIsPreviewBlocked = false;
+    processFeatures();
+    myIsPreviewBlocked = myIsPreviewBlocked;
+    return;
+  }
   if (theMessage->eventID() == kUpdatedSel) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
@@ -325,7 +343,7 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
       theMessage->eventID() == kOpStartEvent) {
     myIsPreviewBlocked = false;
 
-    if (theMessage->eventID() == kOpFinishEvent) {
+    if (theMessage->eventID() == kOpFinishEvent && !myUpdateBlocked) {// if update is blocked, skip
       myIsFinish = true;
       // add features that wait for finish as modified
       std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >::
@@ -337,7 +355,7 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
             continue;
           }
           std::set<std::shared_ptr<ModelAPI_Feature> >::iterator aReasons;
-          for(aReasons = aFeature->second.begin(); aReasons != aFeature->second.end(); aReasons++) {
+          for(aReasons = aFeature->second.begin(); aReasons != aFeature->second.end(); aReasons++){
             addModified(aFeature->first, *aReasons);
           }
         }
@@ -345,21 +363,23 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
       myIsFinish = false;
     }
     // processed features must be only on finish, so clear anyway (to avoid reimport on load)
-    myProcessOnFinish.clear();
+    if (!myUpdateBlocked) {
+      myProcessOnFinish.clear();
 
-    // #2156: current must be sketch, left after the macro execution
-    DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
-    FeaturePtr aCurrent;
-    if (anActiveDoc.get())
-      aCurrent = anActiveDoc->currentFeature(false);
+      // #2156: current must be sketch, left after the macro execution
+      DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
+      FeaturePtr aCurrent;
+      if (anActiveDoc.get())
+        aCurrent = anActiveDoc->currentFeature(false);
 
-    if (!(theMessage->eventID() == kOpStartEvent)) {
-      processFeatures(false);
-    }
+      if (!(theMessage->eventID() == kOpStartEvent)) {
+        processFeatures(false);
+      }
 
-    if (anActiveDoc.get() && aCurrent.get() && aCurrent->data()->isValid()) {
-      if (anActiveDoc->currentFeature(false) != aCurrent)
-        anActiveDoc->setCurrentFeature(aCurrent, false); // #2156 make the current feature back
+      if (anActiveDoc.get() && aCurrent.get() && aCurrent->data()->isValid()) {
+        if (anActiveDoc->currentFeature(false) != aCurrent)
+          anActiveDoc->setCurrentFeature(aCurrent, false); // #2156 make the current feature back
+      }
     }
 
 
@@ -403,7 +423,7 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
 void Model_Update::processFeatures(const bool theFlushRedisplay)
 {
    // perform update of everything if it is not performed right now or any preview is blocked
-  if (!myIsProcessed && !myIsPreviewBlocked) {
+  if (!myIsProcessed && !myIsPreviewBlocked && !myUpdateBlocked) {
     myIsProcessed = true;
     #ifdef DEB_UPDATE
       std::cout<<"****** Start processing"<<std::endl;
index 9a6ecc711bb27da78d47103aaec41dab8d9a67e9..9ca9045450b8b16ae19f63833e4b8038ee925017 100644 (file)
@@ -62,9 +62,10 @@ class Model_Update : public Events_Listener
     myProcessOnFinish;
   /// to avoid infinitive cycling: feature -> count of the processing periods during this update
   std::map<std::shared_ptr<ModelAPI_Feature>, int > myProcessed;
-  /// if preview in hte property panel is blocked and
-  /// any update is postponed until the end of operation
+  /// if preview in the property panel is blocked any update is postponed until end of operation
   bool myIsPreviewBlocked;
+  /// disables any update if it is true, even on start/finish operation, undo, etc.
+  bool myUpdateBlocked;
 
  public:
   /// Is called only once, on startup of the application
index aa957fb723caabfbb3c68e86ba37be75159fdc57..ddef5a2d328221689f787381f81ba17adf83d93a 100644 (file)
@@ -79,6 +79,10 @@ static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresenta
 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
 /// To preview the current feature in the viewer (to compute the result)
 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
+/// To block automatic recomputation of any feature (by the GUI button press)
+static const char * EVENT_AUTOMATIC_RECOMPUTATION_DISABLE = "DisableAutomaticRecomputation";
+/// To unblock block automatic recomputation (default state: the GUI button unpressed)
+static const char * EVENT_AUTOMATIC_RECOMPUTATION_ENABLE = "EnableAutomaticRecomputation";
 
 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
 static const char * EVENT_SOLVER_FAILED = "SolverFailed";