Salome HOME
18594018c4f38fe3c38f00aa468eae76d1d478d2
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintCoincidence.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include <SketchSolver_ConstraintCoincidence.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.h>
6
7 void SketchSolver_ConstraintCoincidence::getAttributes(
8     double& theValue,
9     std::vector<EntityWrapperPtr>& theAttributes)
10 {
11   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
12   if (!myErrorMsg.empty() || !theAttributes[0]) {
13     theAttributes.clear();
14     return;
15   }
16
17   if (theAttributes[1]) {
18     myType = CONSTRAINT_PT_PT_COINCIDENT;
19     if (myStorage->isFixed(theAttributes[1]) && !myStorage->isFixed(theAttributes[0])) {
20       // fixed point should go first
21       EntityWrapperPtr aTemp = theAttributes[0];
22       theAttributes[0] = theAttributes[1];
23       theAttributes[1] = aTemp;
24     }
25     // Set the slave (second) point the same as master (first) point.
26     // This will allow to skip adding point-point coincidence to the set of constraints
27     // and give us speed-up in solving the set of equations
28     myStorage->addCoincidentPoints(theAttributes[0], theAttributes[1]);
29   }
30   else if (theAttributes[2]) {
31     // check the type of entity (line or circle)
32     SketchSolver_EntityType anEntType = theAttributes[2]->type();
33     if (anEntType == ENTITY_LINE)
34       myType = CONSTRAINT_PT_ON_LINE;
35     else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
36       myType = CONSTRAINT_PT_ON_CIRCLE;
37     else
38       myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
39   } else
40     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
41 }