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