From: azv Date: Fri, 15 Aug 2014 13:37:42 +0000 (+0400) Subject: Issue #100: Unpredictable result of distance creation X-Git-Tag: V_0.4.4~105^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=81bf735c62faafde506ba94930f7e573573762c8;p=modules%2Fshaper.git Issue #100: Unpredictable result of distance creation Added verification of a sign of a point-line distance constraint --- diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 2640da058..0e5878091 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -148,6 +149,14 @@ bool SketchSolver_ConstraintGroup::isInteract( FeaturePtr aFeature = aDoc->feature(aRC); if (myEntityFeatMap.find(aFeature) != myEntityFeatMap.end()) return true; + // search attributes of a feature to be parameters of constraint + std::list< boost::shared_ptr > + aFeatAttrList = aFeature->data()->attributes(std::string()); + std::list< boost::shared_ptr >::const_iterator + aFAIter = aFeatAttrList.begin(); + for ( ; aFAIter != aFeatAttrList.end(); aFAIter++) + if (myEntityAttrMap.find(*aFAIter) != myEntityAttrMap.end()) + return true; } } @@ -155,6 +164,41 @@ bool SketchSolver_ConstraintGroup::isInteract( return false; } +// ============================================================================ +// Function: checkConstraintConsistence +// Class: SketchSolver_ConstraintGroup +// Purpose: verifies and changes parameters of the constraint +// ============================================================================ +void SketchSolver_ConstraintGroup::checkConstraintConsistence(Slvs_Constraint& theConstraint) +{ + if (theConstraint.type == SLVS_C_PT_LINE_DISTANCE) + { + // Get constraint parameters and check the sign of constraint value + + // point coordinates + int aPtPos = Search(theConstraint.ptA, myEntities); + int aPtParamPos = Search(myEntities[aPtPos].param[0], myParams); + boost::shared_ptr aPoint( + new GeomAPI_XY(myParams[aPtParamPos].val, myParams[aPtParamPos+1].val)); + + // line coordinates + int aLnPos = Search(theConstraint.entityA, myEntities); + aPtPos = Search(myEntities[aLnPos].point[0], myEntities); + aPtParamPos = Search(myEntities[aPtPos].param[0], myParams); + boost::shared_ptr aStart( + new GeomAPI_XY(-myParams[aPtParamPos].val, -myParams[aPtParamPos+1].val)); + aPtPos = Search(myEntities[aLnPos].point[1], myEntities); + aPtParamPos = Search(myEntities[aPtPos].param[0], myParams); + boost::shared_ptr aEnd( + new GeomAPI_XY(myParams[aPtParamPos].val, myParams[aPtParamPos+1].val)); + + aEnd = aEnd->added(aStart); + aPoint = aPoint->added(aStart); + if (aPoint->cross(aEnd) * theConstraint.valA < 0.0) + theConstraint.valA *= -1.0; + } +} + // ============================================================================ // Function: changeConstraint // Class: SketchSolver_ConstraintGroup @@ -260,7 +304,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint( aDistance, aConstrEnt[0], aConstrEnt[1], aConstrEnt[2], aConstrEnt[3]); myConstraints.push_back(aConstraint); myConstraintMap[theConstraint] = aConstraint.h; + int aConstrPos = Search(aConstraint.h, myConstraints); + aConstrIter = myConstraints.begin() + aConstrPos; } + + checkConstraintConsistence(*aConstrIter); return true; } diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index a648fc9b3..1ec223627 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -174,6 +174,12 @@ private: */ bool addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2); + /** \brief Verifies and changes parameters of constriant, + * e.g. sign of the distance between line and point + * \param[in,out] theConstraint SolveSpace constraint to be verified + */ + void checkConstraintConsistence(Slvs_Constraint& theConstraint); + private: // SolveSpace entities Slvs_hGroup myID; ///< the index of the group