Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintLength.cpp
1 #include <SketchSolver_ConstraintLength.h>
2 #include <SketchSolver_Group.h>
3 #include <SketchSolver_Error.h>
4
5
6 void SketchSolver_ConstraintLength::process()
7 {
8   cleanErrorMsg();
9   if (!myBaseConstraint || !myStorage || myGroup == 0) {
10     /// TODO: Put error message here
11     return;
12   }
13   if (!mySlvsConstraints.empty()) // some data is changed, update constraint
14     update(myBaseConstraint);
15
16   double aValue;
17   std::vector<Slvs_hEntity> anEntities;
18   getAttributes(aValue, anEntities);
19   if (!myErrorMsg.empty())
20     return;
21
22   // Check the entity is a line
23   Slvs_Entity aLine = myStorage->getEntity(anEntities[2]);
24   if (aLine.type != SLVS_E_LINE_SEGMENT){
25     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
26     return;
27   }
28
29   Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
30       getType(), myGroup->getWorkplaneId(), aValue,
31       aLine.point[0], aLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
32   aConstraint.h = myStorage->addConstraint(aConstraint);
33   mySlvsConstraints.push_back(aConstraint.h);
34   adjustConstraint();
35 }
36