Salome HOME
Fix compilation error on Linux
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintCollinear.cpp
1 #include <SketchSolver_ConstraintCollinear.h>
2 #include <SketchSolver_Manager.h>
3
4 #include <SketchPlugin_Line.h>
5
6 SketchSolver_ConstraintCollinear::SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint)
7   : SketchSolver_Constraint(theConstraint)
8 {
9 }
10
11 void SketchSolver_ConstraintCollinear::notifyCoincidenceChanged(
12     EntityWrapperPtr theCoincAttr1,
13     EntityWrapperPtr theCoincAttr2)
14 {
15   bool used = true;
16
17   // obtain IDs of all boundary points of lines
18   EntityID aPointIDs[4];
19   for (int i = 0; i < 2; ++i) {
20     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
21         myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
22     if (!aRefAttr->object())
23       continue;
24     FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
25     AttributePtr aLinePt = aLine->attribute(SketchPlugin_Line::START_ID());
26     aPointIDs[2*i] = myStorage->entity(aLinePt)->id();
27     aLinePt = aLine->attribute(SketchPlugin_Line::END_ID());
28     aPointIDs[2*i + 1] = myStorage->entity(aLinePt)->id();
29   }
30
31   EntityWrapperPtr anAttrs[2] = {theCoincAttr1, theCoincAttr2};
32   for (int i = 0; i < 2 && used; ++i) {
33     if (anAttrs[i]->baseAttribute())
34       used = used && isUsed(anAttrs[i]->baseAttribute());
35     else
36       used = used && isUsed(anAttrs[i]->baseFeature());
37
38     if (!used) {
39       if (anAttrs[i]->type() == ENTITY_POINT) {
40         EntityID anID = anAttrs[i]->id();
41         for (int j = 0; j < 4; ++j)
42           if (anID == aPointIDs[j]) {
43             used = true;
44             break;
45           }
46       }
47     }
48   }
49
50   if (used) {
51     remove();
52     process();
53   }
54 }