1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintMiddle.h>
5 #include <SketchSolver_Builder.h>
6 #include <SketchSolver_Manager.h>
8 #include <GeomAPI_XY.h>
10 SketchSolver_ConstraintMiddle::SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint)
11 : SketchSolver_Constraint(theConstraint)
15 void SketchSolver_ConstraintMiddle::notifyCoincidenceChanged(
16 EntityWrapperPtr theCoincAttr1,
17 EntityWrapperPtr theCoincAttr2)
19 // Check the coincidence between point and line has been changed
22 EntityWrapperPtr anEntities[2] = {theCoincAttr1, theCoincAttr2};
23 for (int i = 0; i < 2; ++i) {
24 if (anEntities[i]->type() == ENTITY_POINT)
25 aPoint = anEntities[i]->baseAttribute();
26 else if (anEntities[i]->type() == ENTITY_LINE)
27 aLine = anEntities[i]->baseFeature();
29 if (!aPoint || !aLine)
32 // Check the attributes of middle-point constraint are the same point and line
33 bool isSameAttr = true;
34 for (int i = 0; i < 2 && isSameAttr; ++i) {
35 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
36 myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
39 // It seems the Middle point constraint has been deleted, so keep it unchanged.
40 // It will be removed later.
43 if (aRefAttr->isObject()) {
44 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
45 isSameAttr = (aFeature == aLine);
47 isSameAttr = (aRefAttr->attr() == aPoint);