]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintEqual.cpp
Salome HOME
SketchSolver library refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintEqual.cpp
1 #include <SketchSolver_ConstraintEqual.h>
2 #include <SketchSolver_Group.h>
3 #include <SketchSolver_Error.h>
4
5
6 void SketchSolver_ConstraintEqual::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 quantity of entities of each type
23   int aNbLines = 0;
24   int aNbArcs = 0;
25   int aNbCircs = 0;
26   std::vector<Slvs_hEntity>::iterator anEntIter = anEntities.begin();
27   for (; anEntIter != anEntities.end(); anEntIter++) {
28     Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
29     if (anEnt.type == SLVS_E_LINE_SEGMENT)
30       aNbLines++;
31     else if (anEnt.type == SLVS_E_CIRCLE)
32       aNbCircs++;
33     else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE)
34       aNbArcs++;
35   }
36
37   if (aNbLines + aNbArcs + aNbCircs != 2 ||
38       (aNbLines == aNbCircs && aNbArcs == 0)) {
39     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
40     return;
41   }
42
43   switch (aNbLines) {
44   case 0:
45     myType = SLVS_C_EQUAL_RADIUS;
46     break;
47   case 1:
48     myType = SLVS_C_EQUAL_LINE_ARC_LEN;
49     break;
50   default:
51     myType = SLVS_C_EQUAL_LENGTH_LINES;
52     break;
53   }
54
55   Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
56       getType(), myGroup->getWorkplaneId(), aValue,
57       anEntities[0], anEntities[1], anEntities[2], anEntities[3]);
58   aConstraint.h = myStorage->addConstraint(aConstraint);
59   mySlvsConstraints.push_back(aConstraint.h);
60   adjustConstraint();
61 }
62