Salome HOME
Implementation of the issue #1307. Also make connected parameters from different...
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintDistance.cpp
index e82568d3ef089f60cd569a3c5895a3bc565dab25..5bbcd791977b6d9736ec7ee7d50cfec2a4d7d8c4 100644 (file)
@@ -32,38 +32,32 @@ void SketchSolver_ConstraintDistance::getAttributes(
 
 void SketchSolver_ConstraintDistance::adjustConstraint()
 {
-  // Adjust point-line distance
-  if (getType() != CONSTRAINT_PT_LINE_DISTANCE)
+  ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front();
+
+  // Adjust point-point distance if the points are equal
+  if (getType() == CONSTRAINT_PT_PT_DISTANCE) {
+    const std::list<EntityWrapperPtr>& aSubs = aConstraint->entities();
+    if (aSubs.front()->isEqual(aSubs.back())) {
+      // Change X coordinate of second point to eliminate coincidence
+      ParameterWrapperPtr aX = aSubs.back()->parameters().front();
+      aX->setValue(aX->value() + 1.0);
+      myStorage->update(aX);
+    }
     return;
+  }
 
-  // Check the sign of distance is changed
-  ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front();
+  // Adjust point-line distance
   if (fabs(myPrevValue) == fabs(aConstraint->value())) {
+    // sign of distance is not changed
     aConstraint->setValue(myPrevValue);
     myStorage->addConstraint(myBaseConstraint, aConstraint);
     return;
   }
 
-  // Get constraint parameters and check the sign of constraint value
+  // Adjust the sign of constraint value
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
-  std::shared_ptr<GeomAPI_Pnt2d> aPoint;
-  std::shared_ptr<GeomAPI_Lin2d> aLine;
-  std::list<EntityWrapperPtr> aSubs = aConstraint->entities();
-  std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
-  for (; aSIt != aSubs.end(); ++aSIt) {
-    if ((*aSIt)->type() == ENTITY_POINT)
-      aPoint = aBuilder->point(*aSIt);
-    else if ((*aSIt)->type() == ENTITY_LINE)
-      aLine = aBuilder->line(*aSIt);
-  }
-
-  std::shared_ptr<GeomAPI_XY> aLineVec = aLine->direction()->xy();
-  std::shared_ptr<GeomAPI_XY> aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy());
-  if (aPtLineVec->cross(aLineVec) * aConstraint->value() < 0.0 || myIsNegative) {
-    aConstraint->setValue(aConstraint->value() * (-1.0));
-    myStorage->addConstraint(myBaseConstraint, aConstraint);
-    myIsNegative = true;
-  }
+  aBuilder->adjustConstraint(aConstraint);
+  myStorage->addConstraint(myBaseConstraint, aConstraint);
 }
 
 void SketchSolver_ConstraintDistance::update()