From: azv Date: Wed, 9 Sep 2015 12:05:33 +0000 (+0300) Subject: SketchSolver performance improvement (issue #934) X-Git-Tag: V_1.4.0_beta4~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=137c6d606fc07aa3f7df13ce64623302edb59a93;p=modules%2Fshaper.git SketchSolver performance improvement (issue #934) --- diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp index d5b96bf33..3cceeeaaa 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp @@ -93,5 +93,19 @@ void SketchSolver_ConstraintMovement::getAttributes( theIsFullyMoved = false; } } + + // Leave only points which are used in constraints + if (myStorage->isUsedByConstraints(anEntityID)) + return; + std::vector::iterator anIt = theAttributes.begin(); + while (anIt != theAttributes.end()) { + if (myStorage->isUsedByConstraints(*anIt)) + ++anIt; + else { + int aShift = anIt - theAttributes.begin(); + theAttributes.erase(anIt); + anIt = theAttributes.begin() + aShift; + } + } } diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 6dce96f4c..c599c3fbb 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -59,7 +59,8 @@ Slvs_hParam SketchSolver_Storage::updateParameter(const Slvs_Param& theParam) // parameter already used, rewrite it int aPos = Search(theParam.h, myParameters); if (aPos >= 0 && aPos < (int)myParameters.size()) { - myNeedToResolve = myNeedToResolve || IsNotEqual(myParameters[aPos], theParam); + if (IsNotEqual(myParameters[aPos], theParam)) + myUpdatedParameters.insert(theParam.h); myParameters[aPos] = theParam; return theParam.h; } @@ -276,6 +277,21 @@ void SketchSolver_Storage::removeUnusedEntities() myNeedToResolve = true; } +bool SketchSolver_Storage::isUsedByConstraints(const Slvs_hEntity& theEntityID) const +{ + std::vector::const_iterator aCIt = myConstraints.begin(); + for (; aCIt != myConstraints.end(); ++aCIt) { + Slvs_hEntity aSubs[6] = { + aCIt->entityA, aCIt->entityB, + aCIt->entityC, aCIt->entityD, + aCIt->ptA, aCIt->ptB}; + for (int i = 0; i < 6; i++) + if (aSubs[i] != SLVS_E_UNKNOWN && aSubs[i] == theEntityID) + return true; + } + return false; +} + const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const { int aPos = Search(theEntityID, myEntities); @@ -1066,6 +1082,48 @@ bool SketchSolver_Storage::isUsedInEqual( return false; } +bool SketchSolver_Storage::isNeedToResolve() +{ + if (myConstraints.empty()) + return false; + + if (!myNeedToResolve) { + // Verify the updated parameters are used in constraints + std::set aPoints; + std::vector::const_iterator anEntIt = myEntities.begin(); + for (; anEntIt != myEntities.end(); ++anEntIt) { + for (int i = 0; i < 4 && anEntIt->param[i] != SLVS_E_UNKNOWN; ++i) + if (myUpdatedParameters.find(anEntIt->param[i]) != myUpdatedParameters.end()) { + aPoints.insert(anEntIt->h); + break; + } + } + std::set anEntities = aPoints; + for (anEntIt = myEntities.begin(); anEntIt != myEntities.end(); ++anEntIt) { + for (int i = 0; i < 4 && anEntIt->point[i] != SLVS_E_UNKNOWN; ++i) + if (aPoints.find(anEntIt->point[i]) != aPoints.end()) { + anEntities.insert(anEntIt->h); + break; + } + } + + std::vector::const_iterator aCIt = myConstraints.begin(); + for (; aCIt != myConstraints.end() && !myNeedToResolve; ++aCIt) { + Slvs_hEntity anAttrs[6] = + {aCIt->ptA, aCIt->ptB, aCIt->entityA, aCIt->entityB, aCIt->entityC, aCIt->entityD}; + for (int i = 0; i < 6; i++) + if (anAttrs[i] != SLVS_E_UNKNOWN && anEntities.find(anAttrs[i]) != anEntities.end()) { + myNeedToResolve = true; + break; + } + } + } + + myUpdatedParameters.clear(); + return myNeedToResolve; +} + + diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 2d1e1cd12..8e808e52b 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -67,6 +67,8 @@ public: Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied); /// \brief Copy one entity to another void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo); + /// \brief Check the entity is used in constraints + bool isUsedByConstraints(const Slvs_hEntity& theEntityID) const; /// \brief Verifies the current point or another coincident one is fixed /// \param[in] thePointID entity to be checked fixed @@ -121,8 +123,7 @@ public: { return (int)myTemporaryConstraints.size(); } /// \brief Shows the sketch should be resolved - bool isNeedToResolve() const - { return myNeedToResolve && !myConstraints.empty(); } + bool isNeedToResolve(); /// \brief Shows the storage has the same constraint twice bool hasDuplicatedConstraint() const @@ -203,6 +204,7 @@ private: std::set myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant) std::set myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant) std::set myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant) + std::set myUpdatedParameters; ///< list of just updated parameters (cleared when isNeedToResolve() called) }; typedef std::shared_ptr StoragePtr;