]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #483: Fix the problem with distance constraint updating
authorazv <azv@opencascade.com>
Wed, 22 Apr 2015 08:40:40 +0000 (11:40 +0300)
committerazv <azv@opencascade.com>
Wed, 22 Apr 2015 08:40:40 +0000 (11:40 +0300)
src/SketchSolver/SketchSolver_ConstraintDistance.cpp
src/SketchSolver/SketchSolver_ConstraintDistance.h

index d256a25ed2848881b5e70aa4af1000ef00294065..f8898477f9ab859a1f3abf29b9e97b63d11498b9 100644 (file)
@@ -54,14 +54,28 @@ void SketchSolver_ConstraintDistance::process()
   aConstraint.h = myStorage->addConstraint(aConstraint);
   mySlvsConstraints.push_back(aConstraint.h);
 
+  myPrevValue = 0.0;
+  adjustConstraint();
+}
+
+void SketchSolver_ConstraintDistance::adjustConstraint()
+{
   // Adjust point-line distance
   if (getType() != SLVS_C_PT_LINE_DISTANCE)
     return;
 
+  // Check the sign of distance is changed
+  Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
+  if (fabs(myPrevValue) == fabs(aConstraint.valA)) {
+    aConstraint.valA = myPrevValue;
+    myStorage->updateConstraint(aConstraint);
+    return;
+  }
+
   // Get constraint parameters and check the sign of constraint value
   std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
   for (; aCIter != mySlvsConstraints.end(); aCIter++) {
-    Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter);
+    aConstraint = myStorage->getConstraint(*aCIter);
     Slvs_Entity aLine = myStorage->getEntity(aConstraint.entityA);
     // Obtain point and line coordinates
     Slvs_hEntity aPointID[3] = {aConstraint.ptA, aLine.point[0], aLine.point[1]};
@@ -81,3 +95,10 @@ void SketchSolver_ConstraintDistance::process()
     }
   }
 }
+
+void SketchSolver_ConstraintDistance::update(ConstraintPtr theConstraint)
+{
+  Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
+  myPrevValue = aConstraint.valA;
+  SketchSolver_Constraint::update(theConstraint);
+}
index ff594c10cfc7c13577b6ae9feebcb8feb947f780..ba1827208743f01e074cace7fcdf38680ea31b10 100644 (file)
@@ -21,6 +21,9 @@ public:
       SketchSolver_Constraint(theConstraint), myType(SLVS_C_UNKNOWN)
   {}
 
+  /// \brief Update constraint
+  virtual void update(ConstraintPtr theConstraint = ConstraintPtr());
+
   virtual int getType() const
   {return myType; }
 
@@ -28,8 +31,13 @@ protected:
   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
   virtual void process();
 
+  /// \brief This method is used in derived objects to check consistence of constraint.
+  ///        E.g. the distance between line and point may be signed.
+  virtual void adjustConstraint();
+
 private:
   int myType; ///< type of constraint (applicable: SLVS_C_PT_PT_DISTANCE, SLVS_C_PT_LINE_DISTANCE)
+  double myPrevValue; ///< previous value of distance (for correct calculation of a distance sign)
 };
 
 #endif