Salome HOME
Center presentation validation: check interactive object on NULL
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintAngle.cpp
index cfad93f19f9b119fc42e44d6d5294488570f55d1..39877af86d43b13cb45ef41a58d2bf44d494b519 100644 (file)
@@ -1,36 +1,41 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
 #include <SketchSolver_ConstraintAngle.h>
 
-#include <cmath>
+#include <ModelAPI_AttributeInteger.h>
+#include <SketchPlugin_ConstraintAngle.h>
 
 void SketchSolver_ConstraintAngle::getAttributes(
-    double& theValue, std::vector<Slvs_hEntity>& theAttributes)
+    EntityWrapperPtr& theValue, std::vector<EntityWrapperPtr>& theAttributes)
 {
   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
-
-  myAngle = theValue;
+  myType = myBaseConstraint->integer(SketchPlugin_ConstraintAngle::TYPE_ID())->value();
 }
 
 
 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;
-    }
+  int aType = myBaseConstraint->integer(SketchPlugin_ConstraintAngle::TYPE_ID())->value();
+  if (aType != myType) {
+    myType = aType;
+    myStorage->setNeedToResolve(true);
   }
-  double aDot = aLineDir[0][0] * aLineDir[1][0] + aLineDir[0][1] * aLineDir[1][1];
-
-  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);
 }