Salome HOME
First phase of SketchSolver refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintEqual.cpp
1 #include <SketchSolver_ConstraintEqual.h>
2 #include <SketchSolver_Error.h>
3
4 void SketchSolver_ConstraintEqual::getAttributes(
5     double& theValue,
6     std::vector<EntityWrapperPtr>& theAttributes)
7 {
8   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
9   if (!myErrorMsg.empty() || !theAttributes[2] || !theAttributes[3]) {
10     theAttributes.clear();
11     return;
12   }
13
14   // Check the quantity of entities of each type
15   int aNbLines = 0;
16   int aNbArcs = 0;
17   int aNbCircs = 0;
18   bool isArcFirst = false; // in line-arc equivalence, the line should be first
19   std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
20   for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
21     SketchSolver_EntityType aType = (*anAttrIt)->type();
22     if (aType == ENTITY_LINE)
23       ++aNbLines;
24     else if (aType == ENTITY_CIRCLE)
25       ++aNbCircs;
26     else if (aType == ENTITY_ARC) {
27       ++aNbArcs;
28       isArcFirst = (aNbLines == 0);
29     }
30   }
31
32   if (aNbLines + aNbArcs + aNbCircs != 2 ||
33      (aNbLines == aNbCircs && aNbArcs == 0)) {
34     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
35     return;
36   }
37
38   switch (aNbLines) {
39   case 0:
40     myType = CONSTRAINT_EQUAL_RADIUS;
41     break;
42   case 1:
43     myType = CONSTRAINT_EQUAL_LINE_ARC;
44     if (isArcFirst) { // change the order of arc and line
45       EntityWrapperPtr aTmp = theAttributes[2];
46       theAttributes[2] = theAttributes[3];
47       theAttributes[3] = aTmp;
48     }
49     break;
50   default:
51     myType = CONSTRAINT_EQUAL_LINES;
52     break;
53   }
54 }