Salome HOME
Fix compilation error on Linux
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMiddle.cpp
1 #include <SketchSolver_ConstraintMiddle.h>
2
3 #include <SketchSolver_Builder.h>
4 #include <SketchSolver_Manager.h>
5
6 #include <GeomAPI_XY.h>
7
8 SketchSolver_ConstraintMiddle::SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint)
9   : SketchSolver_Constraint(theConstraint)
10 {
11 }
12
13 void SketchSolver_ConstraintMiddle::notifyCoincidenceChanged(
14     EntityWrapperPtr theCoincAttr1,
15     EntityWrapperPtr theCoincAttr2)
16 {
17   // Check the coincidence between point and line has been changed
18   AttributePtr aPoint;
19   FeaturePtr aLine;
20   EntityWrapperPtr anEntities[2] = {theCoincAttr1, theCoincAttr2};
21   for (int i = 0; i < 2; ++i) {
22     if (anEntities[i]->type() == ENTITY_POINT)
23       aPoint = anEntities[i]->baseAttribute();
24     else if (anEntities[i]->type() == ENTITY_LINE)
25       aLine = anEntities[i]->baseFeature();
26   }
27   if (!aPoint || !aLine)
28     return;
29
30   // Check the attributes of middle-point constraint are the same point and line
31   bool isSameAttr = true;
32   for (int i = 0; i < 2 && isSameAttr; ++i) {
33     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
34         myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
35     if (aRefAttr->isObject()) {
36       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
37       isSameAttr = (aFeature == aLine);
38     } else
39       isSameAttr = (aRefAttr->attr() == aPoint);
40   }
41
42   if (isSameAttr) {
43     remove();
44     process();
45   }
46 }