From: azv Date: Wed, 16 Sep 2015 11:30:37 +0000 (+0300) Subject: Attach second point of the Coincidence constraint to the first one. X-Git-Tag: V_1.4.0~58 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6fb5c9e4214f528d9836d6e6cd82d5e9ba978f7c;p=modules%2Fshaper.git Attach second point of the Coincidence constraint to the first one. Improve fixing of moved feature (issue #975) --- diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index 1bfa09e72..e1242606e 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -15,8 +15,20 @@ void SketchSolver_ConstraintCoincidence::getAttributes( if (!myErrorMsg.empty() || theAttributes[0] == SLVS_E_UNKNOWN) return; - if (theAttributes[1] != SLVS_E_UNKNOWN) + if (theAttributes[1] != SLVS_E_UNKNOWN) { myType = SLVS_C_POINTS_COINCIDENT; + + // set coordinates of slave (second) point equal to the master (first) point + Slvs_Entity aFirst = myStorage->getEntity(theAttributes[0]); + Slvs_Entity aSecond = myStorage->getEntity(theAttributes[1]); + for (int i = 0; i < 4; i++) + if (aFirst.param[i] != SLVS_E_UNKNOWN && aSecond.param[i] != SLVS_E_UNKNOWN) { + Slvs_Param aPar1 = myStorage->getParameter(aFirst.param[i]); + Slvs_Param aPar2 = myStorage->getParameter(aSecond.param[i]); + aPar2.val = aPar1.val; + myStorage->updateParameter(aPar2); + } + } else if (theAttributes[2] != SLVS_E_UNKNOWN) { // check the type of entity (line or circle) Slvs_Entity anEnt = myStorage->getEntity(theAttributes[2]); diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp index 3cceeeaaa..030274ac2 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp @@ -2,8 +2,6 @@ #include #include -#include - SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature) : SketchSolver_ConstraintRigid(theFeature) { @@ -42,6 +40,7 @@ void SketchSolver_ConstraintMovement::getAttributes( std::vector& theAttributes, bool& theIsFullyMoved) { + bool isComplexFeature = false; theValue = 0.0; theIsFullyMoved = true; int aType = SLVS_E_UNKNOWN; // type of created entity @@ -56,15 +55,17 @@ void SketchSolver_ConstraintMovement::getAttributes( // Check the entity is complex Slvs_Entity anEntity = myStorage->getEntity(anEntityID); - if (anEntity.point[0] != SLVS_E_UNKNOWN) { - for (int i = 0; i < 4 && anEntity.point[i]; i++) - theAttributes.push_back(anEntity.point[i]); - } else // simple entity + if (anEntity.point[0] != SLVS_E_UNKNOWN) + isComplexFeature = true; + else // simple entity theAttributes.push_back(anEntityID); } else { myFeatureMap[myBaseFeature] = anEntityID; + isComplexFeature = true; + } + if (isComplexFeature) { std::list aPoints = myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); std::list::iterator anIt = aPoints.begin(); @@ -72,16 +73,12 @@ void SketchSolver_ConstraintMovement::getAttributes( Slvs_hEntity anAttr = myGroup->getAttributeId(*anIt); // Check the attribute changes coordinates - Slvs_Entity anAttrEnt = myStorage->getEntity(anAttr); - double aDeltaX = myStorage->getParameter(anAttrEnt.param[0]).val; - double aDeltaY = myStorage->getParameter(anAttrEnt.param[1]).val; std::shared_ptr aPt = std::dynamic_pointer_cast(*anIt); - aDeltaX -= aPt->x(); - aDeltaY -= aPt->y(); - if (aDeltaX * aDeltaX + aDeltaY * aDeltaY >= tolerance * tolerance) { + if (isMoved(aPt, anAttr)) { theAttributes.push_back(anAttr); // update point coordinates + Slvs_Entity anAttrEnt = myStorage->getEntity(anAttr); double aNewPos[2] = {aPt->x(), aPt->y()}; for (int i = 0; i < 2; i++) { Slvs_Param aParam = myStorage->getParameter(anAttrEnt.param[i]); @@ -109,3 +106,13 @@ void SketchSolver_ConstraintMovement::getAttributes( } } +bool SketchSolver_ConstraintMovement::isMoved( + std::shared_ptr thePoint, Slvs_hEntity theEntity) +{ + Slvs_Entity anAttrEnt = myStorage->getEntity(theEntity); + double aDeltaX = myStorage->getParameter(anAttrEnt.param[0]).val; + double aDeltaY = myStorage->getParameter(anAttrEnt.param[1]).val; + aDeltaX -= thePoint->x(); + aDeltaY -= thePoint->y(); + return aDeltaX * aDeltaX + aDeltaY * aDeltaY >= tolerance * tolerance; +} diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.h b/src/SketchSolver/SketchSolver_ConstraintMovement.h index 0492f5006..dd2b0df74 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.h +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.h @@ -10,6 +10,8 @@ #include "SketchSolver.h" #include +#include + /** \class SketchSolver_ConstraintMovement * \ingroup Plugins * \brief Stores data of Rigid (Fixed) constraint for the moved feature only @@ -35,6 +37,10 @@ protected: /// \param[out] theAttributes list of attributes to be filled /// \param[out] theIsFullyMoved shows that the feature is moved, in other case only one point of the feature is shifted virtual void getAttributes(double& theValue, std::vector& theAttributes, bool& theIsFullyMoved); + +private: + /// \brief Check the coordinates of point are differ than coordinates of correponding SolveSpace entity + bool isMoved(std::shared_ptr thePoint, Slvs_hEntity theEntity); }; #endif