]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintEqual.cpp
Salome HOME
SketchSolver Refactoring: Eliminate SolveSpace as a sketch solver.
[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 #include <ModelAPI_AttributeRefAttr.h>
7 #include <SketchPlugin_Line.h>
8
9 void SketchSolver_ConstraintEqual::getAttributes(
10     EntityWrapperPtr& theValue,
11     std::vector<EntityWrapperPtr>& theAttributes)
12 {
13   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
14   if (!myErrorMsg.empty() || !theAttributes[2] || !theAttributes[3]) {
15     theAttributes.clear();
16     return;
17   }
18
19   // Check the quantity of entities of each type
20   int aNbLines = 0;
21   int aNbArcs = 0;
22   int aNbCircs = 0;
23   bool isArcFirst = false; // in line-arc equivalence, the line should be first
24   std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
25   for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
26     SketchSolver_EntityType aType = (*anAttrIt)->type();
27     if (aType == ENTITY_LINE)
28       ++aNbLines;
29     else if (aType == ENTITY_CIRCLE)
30       ++aNbCircs;
31     else if (aType == ENTITY_ARC) {
32       ++aNbArcs;
33       isArcFirst = (aNbLines == 0);
34     }
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 = CONSTRAINT_EQUAL_RADIUS;
46     break;
47   case 1:
48     myType = CONSTRAINT_EQUAL_LINE_ARC;
49     if (isArcFirst) { // change the order of arc and line
50       EntityWrapperPtr aTmp = theAttributes[2];
51       theAttributes[2] = theAttributes[3];
52       theAttributes[3] = aTmp;
53     }
54     break;
55   default:
56     myType = CONSTRAINT_EQUAL_LINES;
57
58     AttributeRefAttrPtr aRefLine1 =
59         myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
60     FeaturePtr aLine1 = ModelAPI_Feature::feature(aRefLine1->object());
61     if (aLine1) {
62       // store length of first line as a value for constraint
63       // (will be used to make equal lengths of lines)
64       theValue = myStorage->entity(aLine1->attribute(SketchPlugin_Line::LENGTH_ID()));
65     }
66     break;
67   }
68 }