From 724896cd03d18f3581a912a1ae261fa167a09f41 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 19 Dec 2014 14:56:35 +0300 Subject: [PATCH] Optimization of the movement: call move event for point 2d dragging: the solver will flush all updates after all elements are recomputed --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 8 +++++++- src/ModuleBase/ModuleBase_ModelWidget.h | 1 + src/PartSet/PartSet_Module.cpp | 2 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 3 ++- src/SketchSolver/SketchSolver_ConstraintManager.cpp | 13 ++++++++----- src/SketchSolver/SketchSolver_ConstraintManager.h | 3 ++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 5ca4cd03b..79b00dfe2 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -84,7 +84,6 @@ bool ModuleBase_ModelWidget::focusTo() return true; } - void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); @@ -92,6 +91,13 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); } +void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const +{ + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); + ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); + Events_Loop::loop()->flush(anEvent); +} + bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index e7a9f24c5..e2f234384 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -146,6 +146,7 @@ signals: } void updateObject(ObjectPtr theObj) const; + void moveObject(ObjectPtr theObj) const; protected: std::string myAttributeID; /// the attribute name of the model feature diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 146dfa692..4d84d8168 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -522,8 +522,8 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); } } + // after movement the solver will call the update event: optimization Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED)); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); } myDragDone = true; myCurX = aX; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 104c9cfb5..8079d4885 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -138,7 +138,8 @@ bool PartSet_WidgetPoint2D::storeValue() const double _Y = myYSpin->value(); #endif aPoint->setValue(myXSpin->value(), myYSpin->value()); - updateObject(myFeature); + // after movement the solver will call the update event: optimization + moveObject(myFeature); aPoint->setImmutable(isImmutable); that->blockSignals(isBlocked); diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index e54a41292..71f062c39 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -114,7 +114,7 @@ void SketchSolver_ConstraintManager::processEvent( } // Solve the set of constraints - resolveConstraints(); + resolveConstraints(isMovedEvt); // send update for movement in any case } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = std::dynamic_pointer_cast(theMessage); @@ -372,7 +372,7 @@ std::shared_ptr SketchSolver_ConstraintManager // Class: SketchSolver_Session // Purpose: change entities according to available constraints // ============================================================================ -void SketchSolver_ConstraintManager::resolveConstraints() +void SketchSolver_ConstraintManager::resolveConstraints(const bool theForceUpdate) { myIsComputed = true; bool needToUpdate = false; @@ -388,12 +388,15 @@ void SketchSolver_ConstraintManager::resolveConstraints() if ((*aGroupIter)->resolveConstraints()) needToUpdate = true; - // Features may be updated => now send events, btu for all changed at once + // Features may be updated => now send events, but for all changed at once if (isUpdateFlushed) { Events_Loop::loop()->setFlushed(anUpdateEvent, true); } - if (needToUpdate) - Events_Loop::loop()->flush(anUpdateEvent); + // Must be before flush because on "Updated" flush the results may be produced + // and the creation event is appeared with many new objects. If myIsComputed these + // events are missed in processEvents and some elements are not added. myIsComputed = false; + if (needToUpdate || theForceUpdate) + Events_Loop::loop()->flush(anUpdateEvent); } diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.h b/src/SketchSolver/SketchSolver_ConstraintManager.h index 164308356..4604a52b1 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.h +++ b/src/SketchSolver/SketchSolver_ConstraintManager.h @@ -82,8 +82,9 @@ class SketchSolver_ConstraintManager : public Events_Listener void updateEntity(std::shared_ptr theFeature); /** \brief Goes through the list of groups and solve the constraints + * \param theForceUpdate flushes the update event in any case: something changed or not */ - void resolveConstraints(); + void resolveConstraints(const bool theForceUpdate); private: /** \brief Searches list of groups which interact with specified feature -- 2.39.2