Salome HOME
Receive DoF from the solver. Update test cases to check DoF.
[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 #include <PlaneGCSSolver_AttributeBuilder.h>
6
7 #include <ModelAPI_AttributeRefAttr.h>
8 #include <SketchPlugin_Line.h>
9
10 void SketchSolver_ConstraintEqual::getAttributes(
11     EntityWrapperPtr& theValue,
12     std::vector<EntityWrapperPtr>& theAttributes)
13 {
14   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
15   if (!myErrorMsg.empty() || !theAttributes[2] || !theAttributes[3]) {
16     theAttributes.clear();
17     return;
18   }
19
20   // Check the quantity of entities of each type
21   int aNbLines = 0;
22   int aNbArcs = 0;
23   int aNbCircs = 0;
24   bool isArcFirst = false; // in line-arc equivalence, the line should be first
25   std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
26   for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
27     SketchSolver_EntityType aType = (*anAttrIt)->type();
28     if (aType == ENTITY_LINE)
29       ++aNbLines;
30     else if (aType == ENTITY_CIRCLE)
31       ++aNbCircs;
32     else if (aType == ENTITY_ARC) {
33       ++aNbArcs;
34       isArcFirst = (aNbLines == 0);
35     }
36   }
37
38   if (aNbLines + aNbArcs + aNbCircs != 2 ||
39      (aNbLines == aNbCircs && aNbArcs == 0)) {
40     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
41     return;
42   }
43
44   switch (aNbLines) {
45   case 0:
46     myType = CONSTRAINT_EQUAL_RADIUS;
47     break;
48   case 1:
49     myType = CONSTRAINT_EQUAL_LINE_ARC;
50     if (isArcFirst) { // change the order of arc and line
51       EntityWrapperPtr aTmp = theAttributes[2];
52       theAttributes[2] = theAttributes[3];
53       theAttributes[3] = aTmp;
54     }
55     break;
56   default:
57     myType = CONSTRAINT_EQUAL_LINES;
58
59     AttributeRefAttrPtr aRefLine1 =
60         myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
61     FeaturePtr aLine1 = ModelAPI_Feature::feature(aRefLine1->object());
62     if (aLine1) {
63       PlaneGCSSolver_AttributeBuilder aBuilder(myStorage);
64       // store length of first line as a value for constraint
65       // (will be used to make equal lengths of lines)
66       theValue = aBuilder.createAttribute(aLine1->attribute(SketchPlugin_Line::LENGTH_ID()));
67     }
68     break;
69   }
70 }