Salome HOME
Attach second point of the Coincidence constraint to the first one.
authorazv <azv@opencascade.com>
Wed, 16 Sep 2015 11:30:37 +0000 (14:30 +0300)
committerazv <azv@opencascade.com>
Wed, 16 Sep 2015 11:31:05 +0000 (14:31 +0300)
Improve fixing of moved feature (issue #975)

src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
src/SketchSolver/SketchSolver_ConstraintMovement.cpp
src/SketchSolver/SketchSolver_ConstraintMovement.h

index 1bfa09e72119f7c9243d16e529221c9e1b9fb800..e1242606ea82f1f6c216f3f46da63f628175c105 100644 (file)
@@ -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]);
index 3cceeeaaa9b0ce4ef6e3fd33c78e7d17e0ca4c85..030274ac2dcc831be74167f26a689dcb20acb1ab 100644 (file)
@@ -2,8 +2,6 @@
 #include <SketchSolver_Error.h>
 #include <SketchSolver_Group.h>
 
-#include <GeomDataAPI_Point2D.h>
-
 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature)
   : SketchSolver_ConstraintRigid(theFeature)
 {
@@ -42,6 +40,7 @@ void SketchSolver_ConstraintMovement::getAttributes(
     std::vector<Slvs_hEntity>& 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<AttributePtr> aPoints =
         myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
      std::list<AttributePtr>::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<GeomDataAPI_Point2D> aPt =
           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*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<GeomDataAPI_Point2D> 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;
+}
index 0492f500693357f710c32fb3db285b85b36e093d..dd2b0df741368b380db0aa2459d789dc89cd649e 100644 (file)
@@ -10,6 +10,8 @@
 #include "SketchSolver.h"
 #include <SketchSolver_ConstraintRigid.h>
 
+#include <GeomDataAPI_Point2D.h>
+
 /** \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<Slvs_hEntity>& theAttributes, bool& theIsFullyMoved);
+
+private:
+  /// \brief Check the coordinates of point are differ than coordinates of correponding SolveSpace entity
+  bool isMoved(std::shared_ptr<GeomDataAPI_Point2D> thePoint, Slvs_hEntity theEntity);
 };
 
 #endif