Salome HOME
Problem with moving fixed point
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintCoincidence.cpp
1 #include <SketchSolver_ConstraintCoincidence.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
4
5 void SketchSolver_ConstraintCoincidence::getAttributes(
6     double& theValue,
7     std::vector<EntityWrapperPtr>& theAttributes)
8 {
9   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
10   if (!myErrorMsg.empty() || !theAttributes[0]) {
11     theAttributes.clear();
12     return;
13   }
14
15   if (theAttributes[1]) {
16     myType = CONSTRAINT_PT_PT_COINCIDENT;
17     if (myStorage->isFixed(theAttributes[1]) && !myStorage->isFixed(theAttributes[0])) {
18       // fixed point should go first
19       EntityWrapperPtr aTemp = theAttributes[0];
20       theAttributes[0] = theAttributes[1];
21       theAttributes[1] = aTemp;
22     }
23     // Set the slave (second) point the same as master (first) point.
24     // This will allow to skip adding point-point coincidence to the set of constraints
25     // and give us speed-up in solving the set of equations
26     myStorage->addCoincidentPoints(theAttributes[0], theAttributes[1]);
27   }
28   else if (theAttributes[2]) {
29     // check the type of entity (line or circle)
30     SketchSolver_EntityType anEntType = theAttributes[2]->type();
31     if (anEntType == ENTITY_LINE)
32       myType = CONSTRAINT_PT_ON_LINE;
33     else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
34       myType = CONSTRAINT_PT_ON_CIRCLE;
35     else
36       myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
37   } else
38     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
39 }
40
41
42 static bool isBase(const std::list<ConstraintWrapperPtr>& theConstraints, AttributePtr theAttribute)
43 {
44   AttributePtr anAttribute = theAttribute;
45   FeaturePtr aFeature;
46   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
47   if (aRefAttr) {
48     if (aRefAttr->isObject())
49       aFeature = ModelAPI_Feature::feature(aRefAttr->object());
50     else
51       anAttribute = aRefAttr->attr();
52   }
53
54   std::list<ConstraintWrapperPtr>::const_iterator aCIt = theConstraints.begin();
55   for (; aCIt != theConstraints.end(); ++aCIt) {
56     std::list<EntityWrapperPtr> aSubs = (*aCIt)->entities();
57     std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
58     for (; aSIt != aSubs.end(); ++aSIt)
59       if ((aFeature && (*aSIt)->isBase(aFeature)) ||
60          (!aFeature && (*aSIt)->isBase(anAttribute)))
61         return true;
62   }
63   return false;
64 }