From: mpv Date: Tue, 4 Sep 2018 07:31:14 +0000 (+0300) Subject: Issue #2612 : Re-calculate model after modification of parameters X-Git-Tag: V9_2_0a1~68 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b9db2ce3280036d7af36a85ed580f9510ea7caf6;p=modules%2Fshaper.git Issue #2612 : Re-calculate model after modification of parameters Preparation for implementation: events and initial processing --- diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 05a9998d8..7ff05ab13 100755 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -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 "<name() @@ -232,6 +233,8 @@ void Model_Update::processEvent(const std::shared_ptr& 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 "<eventID().eventText()<& 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 aMsg = std::dynamic_pointer_cast(theMessage); @@ -325,7 +343,7 @@ void Model_Update::processEvent(const std::shared_ptr& 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::set > >:: @@ -337,7 +355,7 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag continue; } std::set >::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& 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& 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"< count of the processing periods during this update std::map, 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 diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index aa957fb72..ddef5a2d3 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -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";