From 4b4154e06aba65daeab5178a0ac3998c8383318a Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 8 Dec 2014 19:24:24 +0300 Subject: [PATCH] Speed up the redraw of sketch with constraints moved by the point of the line --- src/Events/Events_Loop.cpp | 27 +++++++++++++++---- src/Events/Events_Loop.h | 5 ++++ src/Model/Model_Update.cpp | 2 +- .../SketchSolver_ConstraintManager.cpp | 14 ++++++++-- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 9447c376b..f9b9d0046 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -115,14 +115,18 @@ void Events_Loop::flush(const Events_ID& theID) { if (!myFlushActive) return; - std::map>::iterator aMyGroup = - myGroups.find(theID.eventText()); - if (aMyGroup != myGroups.end()) { // really sends - myFlushed.insert(theID.myID); + std::map >::iterator aMyGroup; + for(aMyGroup = myGroups.find(theID.eventText()); + aMyGroup != myGroups.end(); aMyGroup = myGroups.find(theID.eventText())) + { // really sends + bool aWasFlushed = myFlushed.find(theID.myID) != myFlushed.end(); + if (!aWasFlushed) + myFlushed.insert(theID.myID); std::shared_ptr aGroup = aMyGroup->second; myGroups.erase(aMyGroup); send(aGroup, false); - myFlushed.erase(myFlushed.find(theID.myID)); + if (!aWasFlushed) + myFlushed.erase(myFlushed.find(theID.myID)); } } @@ -147,3 +151,16 @@ void Events_Loop::autoFlush(const Events_ID& theID, const bool theAuto) else myFlushed.erase(myFlushed.find(theID.myID)); } + +bool Events_Loop::isFlushed(const Events_ID& theID) +{ + return myFlushed.find(theID.myID) != myFlushed.end(); +} + +void Events_Loop::setFlushed(const Events_ID& theID, const bool theValue) +{ + if (theValue) + myFlushed.insert(theID.myID); + else + myFlushed.erase(myFlushed.find(theID.myID)); +} diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index c8b7798c0..317c62d3b 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -72,6 +72,11 @@ class Events_Loop //! Enables flush without grouping for the given message EVENTS_EXPORT void autoFlush(const Events_ID& theID, const bool theAuto = true); + + //! Returns true if the evement is flushed right now + EVENTS_EXPORT bool isFlushed(const Events_ID& theID); + //! Sets the flag that the event is flished right now + EVENTS_EXPORT void setFlushed(const Events_ID& theID, const bool theValue); }; #endif diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 31c8b7565..3a70e463a 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -163,7 +163,7 @@ void Model_Update::updateInDoc(std::shared_ptr theDoc) void Model_Update::redisplayWithResults(FeaturePtr theFeature, const ModelAPI_ExecState theState) { - // maske updated and redisplay all results + // make updated and redisplay all results static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); const std::list >& aResults = theFeature->results(); std::list >::const_iterator aRIter = aResults.begin(); diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 3ba3fdda4..a69eb95bc 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -374,14 +374,24 @@ void SketchSolver_ConstraintManager::resolveConstraints() { myIsComputed = true; bool needToUpdate = false; + static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + // to avoid redisplay of each segment on update by solver one by one in the viewer + bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent); + if (isUpdateFlushed) { + Events_Loop::loop()->setFlushed(anUpdateEvent, false); + } + std::vector::iterator aGroupIter; for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) if ((*aGroupIter)->resolveConstraints()) needToUpdate = true; - // Features may be updated => send events + // Features may be updated => now send events, btu for all changed at once + if (isUpdateFlushed) { + Events_Loop::loop()->setFlushed(anUpdateEvent, true); + } if (needToUpdate) - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + Events_Loop::loop()->flush(anUpdateEvent); myIsComputed = false; } -- 2.30.2