]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
Salome HOME
Fix wrong DoF when split line with a point on it
[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 #include <PlaneGCSSolver_UpdateCoincidence.h>
7
8 void SketchSolver_ConstraintCoincidence::process()
9 {
10   cleanErrorMsg();
11   if (!myBaseConstraint || !myStorage) {
12     // Not enough parameters are assigned
13     return;
14   }
15
16   EntityWrapperPtr aValue;
17   std::vector<EntityWrapperPtr> anAttributes;
18   getAttributes(aValue, anAttributes);
19   if (!myErrorMsg.empty())
20     return;
21   if (anAttributes.empty()) {
22     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
23     return;
24   }
25
26   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
27   mySolverConstraint = aBuilder->createConstraint(
28       myBaseConstraint, getType(),
29       aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
30
31   myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
32   myStorage->notify(myBaseConstraint);
33 }
34
35 bool SketchSolver_ConstraintCoincidence::remove()
36 {
37   myInSolver = false;
38   return SketchSolver_Constraint::remove();
39 }
40
41 void SketchSolver_ConstraintCoincidence::getAttributes(
42     EntityWrapperPtr& theValue,
43     std::vector<EntityWrapperPtr>& theAttributes)
44 {
45   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
46   if (!myErrorMsg.empty() || !theAttributes[0]) {
47     theAttributes.clear();
48     return;
49   }
50
51   if (theAttributes[1])
52     myType = CONSTRAINT_PT_PT_COINCIDENT;
53   else if (theAttributes[2]) {
54     // check the type of entity (line or circle)
55     SketchSolver_EntityType anEntType = theAttributes[2]->type();
56     if (anEntType == ENTITY_LINE)
57       myType = CONSTRAINT_PT_ON_LINE;
58     else if (anEntType == ENTITY_CIRCLE || anEntType == ENTITY_ARC)
59       myType = CONSTRAINT_PT_ON_CIRCLE;
60     else
61       myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
62   } else
63     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
64 }
65
66 void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr&      theFeature,
67                                                 PlaneGCSSolver_Update* theUpdater)
68 {
69   PlaneGCSSolver_UpdateCoincidence* anUpdater =
70       static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
71   bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
72   if (isAccepted) {
73     if (!myInSolver) {
74       myInSolver = true;
75       myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
76     }
77   } else {
78     if (myInSolver) {
79       myInSolver = false;
80       myStorage->removeConstraint(myBaseConstraint);
81     }
82   }
83 }