From: azv Date: Thu, 16 Apr 2015 05:02:11 +0000 (+0300) Subject: Issue #447: Show message, if the constraint on the same objects is created twice X-Git-Tag: V_1.1.0~23^2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=77a5f82fddb078c5fb0d3d3fcba01249fca25b1e;p=modules%2Fshaper.git Issue #447: Show message, if the constraint on the same objects is created twice --- diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index d7049b111..5479601f9 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -408,7 +408,10 @@ bool SketchSolver_Group::resolveConstraints() int aResult = SLVS_RESULT_OKAY; try { - aResult = myConstrSolver.solve(); + if (myStorage->hasDuplicatedConstraint()) + aResult = SLVS_RESULT_INCONSISTENT; + else + aResult = myConstrSolver.solve(); } catch (...) { Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this); return false; diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 421696c17..857c634d4 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -29,7 +29,8 @@ SketchSolver_Storage::SketchSolver_Storage() myEntityMaxID(SLVS_E_UNKNOWN), myConstrMaxID(SLVS_C_UNKNOWN), myFixed(SLVS_E_UNKNOWN), - myNeedToResolve(false) + myNeedToResolve(false), + myDuplicatedConstraint(false) { } @@ -420,17 +421,15 @@ Slvs_hConstraint SketchSolver_Storage::addConstraint(const Slvs_Constraint& theC Slvs_Constraint aConstraint = theConstraint; - // Find a constraint with same type uses same arguments + // Find a constraint with same type uses same arguments to show user overconstraint situation std::vector::iterator aCIt = myConstraints.begin(); for (; aCIt != myConstraints.end(); aCIt++) { if (aConstraint.type != aCIt->type) continue; if (aConstraint.ptA == aCIt->ptA && aConstraint.ptB == aCIt->ptB && aConstraint.entityA == aCIt->entityA && aConstraint.entityB == aCIt->entityB && - aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) { - aConstraint.h = aCIt->h; - return updateConstraint(aConstraint); - } + aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) + myDuplicatedConstraint = true; } if (aConstraint.h > myConstrMaxID) @@ -484,6 +483,21 @@ bool SketchSolver_Storage::removeConstraint(const Slvs_hConstraint& theConstrain // remove temporary fixed point, if available if (myFixed == theConstraintID) myFixed = SLVS_E_UNKNOWN; + if (myDuplicatedConstraint) { + // Check the duplicated constraints are still available + myDuplicatedConstraint = false; + std::vector::const_iterator anIt1 = myConstraints.begin(); + std::vector::const_iterator anIt2 = myConstraints.begin(); + for (; anIt1 != myConstraints.end() && !myDuplicatedConstraint; anIt1++) + for (anIt2 = anIt1+1; anIt2 != myConstraints.end() && !myDuplicatedConstraint; anIt2++) { + if (anIt1->type != anIt2->type) + continue; + if (anIt1->ptA == anIt2->ptA && anIt1->ptB == anIt2->ptB && + anIt1->entityA == anIt2->entityA && anIt1->entityB == anIt2->entityB && + anIt1->entityC == anIt2->entityC && anIt1->entityD == anIt2->entityD) + myDuplicatedConstraint = true; + } + } } return aResult; } diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 80fce4563..fbd9acf64 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -115,6 +115,10 @@ public: bool isNeedToResolve() const { return myNeedToResolve; } + /// \brief Shows the storage has the same constraint twice + bool hasDuplicatedConstraint() const + { return myDuplicatedConstraint; } + /// \brief Changes the flag of group to be resolved void setNeedToResolve(bool theFlag) { myNeedToResolve = theFlag; } @@ -149,6 +153,7 @@ private: Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point bool myNeedToResolve; ///< parameters are changed and group needs to be resolved + bool myDuplicatedConstraint; ///< shows the storage has same constraint twice std::set myTemporaryConstraints; ///< list of transient constraints std::set myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)