Salome HOME
Revert "First phase of SketchSolver 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   bool isArcFirst = false; // in line-arc equivalence, the line should be first
27   std::vector<Slvs_hEntity>::iterator anEntIter = anEntities.begin();
28   for (; anEntIter != anEntities.end(); anEntIter++) {
29     Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
30     if (anEnt.type == SLVS_E_LINE_SEGMENT)
31       aNbLines++;
32     else if (anEnt.type == SLVS_E_CIRCLE)
33       aNbCircs++;
34     else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE) {
35       aNbArcs++;
36       isArcFirst = (aNbLines == 0);
37     }
38   }
39
40   if (aNbLines + aNbArcs + aNbCircs != 2 ||
41       (aNbLines == aNbCircs && aNbArcs == 0)) {
42     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
43     return;
44   }
45
46   switch (aNbLines) {
47   case 0:
48     myType = SLVS_C_EQUAL_RADIUS;
49     break;
50   case 1:
51     myType = SLVS_C_EQUAL_LINE_ARC_LEN;
52     if (isArcFirst) { // change the order of arc and line
53       Slvs_hEntity aTmp = anEntities[2];
54       anEntities[2] = anEntities[3];
55       anEntities[3] = aTmp;
56     }
57     break;
58   default:
59     myType = SLVS_C_EQUAL_LENGTH_LINES;
60     break;
61   }
62
63   Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
64       getType(), myGroup->getWorkplaneId(), aValue,
65       anEntities[0], anEntities[1], anEntities[2], anEntities[3]);
66   aConstraint.h = myStorage->addConstraint(aConstraint);
67   mySlvsConstraints.push_back(aConstraint.h);
68   adjustConstraint();
69 }
70