Salome HOME
Pipe validator fix
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintAngle.cpp
index cfad93f19f9b119fc42e44d6d5294488570f55d1..6138e3062cf3cb2f0b00ca4d6935a7edd35900b2 100644 (file)
@@ -1,9 +1,15 @@
 #include <SketchSolver_ConstraintAngle.h>
+#include <SketchSolver_Manager.h>
+
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_XY.h>
 
 #include <cmath>
 
 void SketchSolver_ConstraintAngle::getAttributes(
-    double& theValue, std::vector<Slvs_hEntity>& theAttributes)
+    double& theValue, std::vector<EntityWrapperPtr>& theAttributes)
 {
   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
 
@@ -13,24 +19,13 @@ void SketchSolver_ConstraintAngle::getAttributes(
 
 void SketchSolver_ConstraintAngle::adjustConstraint()
 {
-  Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
-
-  double aLineDir[2][2] = { {0.0, 0.0}, {0.0, 0.0} };
-  Slvs_hEntity anEnt[2] = {aConstraint.entityA, aConstraint.entityB};
-  for (int i = 0; i < 2; i++) {
-    const Slvs_Entity& aLine = myStorage->getEntity(anEnt[i]);
-    double aCoef = -1.0;
-    for (int j = 0; j < 2; j++, aCoef += 2.0) {
-      const Slvs_Entity& aPoint = myStorage->getEntity(aLine.point[j]);
-      for (int k = 0; k < 2; k++)
-        aLineDir[i][k] += aCoef * myStorage->getParameter(aPoint.param[k]).val;
-    }
-  }
-  double aDot = aLineDir[0][0] * aLineDir[1][0] + aLineDir[0][1] * aLineDir[1][1];
+  static const double aTol = 1000. * tolerance;
+  BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
 
-  aConstraint.other = aDot * (90.0 - fabs(aConstraint.valA)) < 0.0;
-  if ((90.0 - fabs(aConstraint.valA)) * (90.0 - fabs(myAngle)) < 0.0)
-    aConstraint.other = !aConstraint.other;
-  myAngle = aConstraint.valA;
-  myStorage->updateConstraint(aConstraint);
+  ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front();
+  //if (fabs(myAngle - aConstraint->value()) < aTol)
+  //  return;
+  myAngle = aConstraint->value();
+  aBuilder->adjustConstraint(aConstraint);
+  myStorage->addConstraint(myBaseConstraint, aConstraint);
 }