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