From 7244aa3984b1d326f2c79e004b6d29de13ba1667 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 29 Mar 2017 15:30:26 +0300 Subject: [PATCH] Resolve constraint only when all events have been processed by the PlaneGCSSolver --- src/Events/Events_Loop.cpp | 6 +++ src/SketchSolver/SketchSolver_Manager.cpp | 46 +++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 013e0a02d..181f588a2 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -171,6 +171,7 @@ void Events_Loop::flush(const Events_ID& theID) { if (!myFlushActive) return; + bool hasEventsToFlush = !myGroups.empty(); std::map >::iterator aMyGroup; for(aMyGroup = myGroups.find(theID.eventText()); aMyGroup != myGroups.end(); aMyGroup = myGroups.find(theID.eventText())) @@ -206,6 +207,11 @@ void Events_Loop::flush(const Events_ID& theID) } } } + if (hasEventsToFlush && myGroups.empty()) { // no more messages left in the queue, so, finalize the sketch processing + static Events_ID anID = Events_Loop::eventByName("SketchPrepared"); + std::shared_ptr aMsg(new Events_Message(anID, this)); + Events_Loop::loop()->send(aMsg, false); + } } void Events_Loop::eraseMessages(const Events_ID& theID) diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 5571e2927..ec2f8d77b 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -74,13 +74,17 @@ bool SketchSolver_Manager::groupMessages() void SketchSolver_Manager::processEvent( const std::shared_ptr& theMessage) { + bool needToResolve = false; + bool isUpdateFlushed = false; + bool isMovedEvt = false; + static const Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); static const Events_ID aSketchPreparedEvent = Events_Loop::eventByName(EVENT_SKETCH_PREPARED); // sketch is prepared for resolve: all the needed events // are collected and must be processed by the solver if (theMessage->eventID() == aSketchPreparedEvent) { flushGrouped(anUpdateEvent); - return; + needToResolve = true; } if (myIsComputed) @@ -94,9 +98,9 @@ void SketchSolver_Manager::processEvent( std::dynamic_pointer_cast(theMessage); std::set aFeatures = anUpdateMsg->objects(); - bool isUpdateFlushed = stopSendUpdate(); + isUpdateFlushed = stopSendUpdate(); - bool isMovedEvt = theMessage->eventID() + isMovedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED); // Shows that the message has at least one feature applicable for solver @@ -113,25 +117,8 @@ void SketchSolver_Manager::processEvent( hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature; } - if (isMovedEvt && !hasProperFeature) { - // in this iteration it will compute nothing, so, no problem with recursion - // it is important that solver flushes signal updated after processing move signal as there - // is optimization that relies on this update, might be found by key "optimization" - myIsComputed = false; - } - - // Solve the set of constraints - bool needToUpdate = resolveConstraints(); - - // Features may be updated => now send events, but for all changed at once - if (isUpdateFlushed) - allowSendUpdate(); - - myIsComputed = false; - - // send update for movement in any case - if (needToUpdate || isMovedEvt) - Events_Loop::loop()->flush(anUpdateEvent); + if (isMovedEvt && hasProperFeature) + needToResolve = true; } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = @@ -158,11 +145,22 @@ void SketchSolver_Manager::processEvent( (*aGroupIter)->repairConsistency(); ++aGroupIter; } - - resolveConstraints(); } myIsComputed = false; } + + // resolve constraints if needed + bool needToUpdate = needToResolve && resolveConstraints(); + + // Features may be updated => now send events, but for all changed at once + if (isUpdateFlushed) + allowSendUpdate(); + + myIsComputed = false; + + // send update for movement in any case + if (needToUpdate || isMovedEvt) + Events_Loop::loop()->flush(anUpdateEvent); } // ============================================================================ -- 2.39.2