From: azv Date: Wed, 22 Jun 2016 09:07:14 +0000 (+0300) Subject: Avoid too much recalculations of DoF while moving feature X-Git-Tag: V_2.4.0~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b074436fd3875330cd67cab7db2424a46a8c654;p=modules%2Fshaper.git Avoid too much recalculations of DoF while moving feature --- diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index a39aab6e6..285a55cbb 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -246,7 +246,7 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) return isUpdated; } -void SketchSolver_Group::moveFeature(FeaturePtr theFeature) +bool SketchSolver_Group::moveFeature(FeaturePtr theFeature) { BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); @@ -260,7 +260,7 @@ void SketchSolver_Group::moveFeature(FeaturePtr theFeature) // Then, create temporary Fixed constraint SolverConstraintPtr aConstraint = aBuilder->createMovementConstraint(theFeature); if (!aConstraint) - return; + return false; aConstraint->process(myStorage, getId(), getWorkplaneId()); if (aConstraint->error().empty()) setTemporary(aConstraint); @@ -279,6 +279,7 @@ void SketchSolver_Group::moveFeature(FeaturePtr theFeature) aFixedRadius->remove(); } } + return true; } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 89a14f490..ea22b03d0 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -81,8 +81,9 @@ class SketchSolver_Group /** \brief Updates the data corresponding the specified feature moved in GUI. * Additional Fixed constraints are created. * \param[in] theFeature the feature to be updated + * \return \c true, if the feature is moved */ - void moveFeature(FeaturePtr theFeature); + bool moveFeature(FeaturePtr theFeature); /** \brief Verifies the feature attributes are used in this group * \param[in] theFeature constraint or any other object for verification of interaction diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 350ef59ab..d430a9651 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -130,8 +130,9 @@ void SketchSolver_Manager::processEvent( for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { std::shared_ptr aSFeature = std::dynamic_pointer_cast(*aFeatIter); - if (aSFeature) { - moveEntity(aSFeature); + if (aSFeature && moveEntity(aSFeature)) { + // Want to avoid recalculation of DoF too frequently. + // So, set the flag when the feature is really moved. hasProperFeature = true; } } @@ -365,23 +366,22 @@ bool SketchSolver_Manager::changeFeature(std::shared_ptr t // Function: moveEntity // Purpose: update element moved on the sketch, which is used by constraints // ============================================================================ -void SketchSolver_Manager::moveEntity(std::shared_ptr theFeature) +bool SketchSolver_Manager::moveEntity(std::shared_ptr theFeature) { bool isMoved = false; std::list::iterator aGroupIt = myGroups.begin(); for (; aGroupIt != myGroups.end(); aGroupIt++) - if (!(*aGroupIt)->isEmpty() && (*aGroupIt)->isInteract(theFeature)) { - (*aGroupIt)->moveFeature(theFeature); - isMoved = true; - } + if (!(*aGroupIt)->isEmpty() && (*aGroupIt)->isInteract(theFeature)) + isMoved = (*aGroupIt)->moveFeature(theFeature) || isMoved; if (!isMoved && theFeature->getKind() == SketchPlugin_Arc::ID()) { // Workaround to move arc. // If the arc has not been constrained, we will push it into empty group and apply movement. for (aGroupIt = myGroups.begin(); aGroupIt != myGroups.end(); aGroupIt++) if ((*aGroupIt)->isEmpty()) - (*aGroupIt)->moveFeature(theFeature); + isMoved = (*aGroupIt)->moveFeature(theFeature) || isMoved; } + return isMoved; } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_Manager.h b/src/SketchSolver/SketchSolver_Manager.h index 0781129c0..c0866c558 100644 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@ -79,8 +79,9 @@ protected: /** \brief Updates entity which is moved in GUI * \param[in] theFeature entity to be updated + * \return \c true, if the entity has been moved */ - void moveEntity(std::shared_ptr theFeature); + bool moveEntity(std::shared_ptr theFeature); /** \brief Goes through the list of groups and solve the constraints * \param[in] theGroups list of groups to be resolved (if empty list, all groups are resolved)