]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp
Salome HOME
SketchSolver Refactoring: Eliminate SolveSpace as a sketch solver.
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_UpdateCoincidence.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_UpdateCoincidence.cpp
4 // Created: 17 Feb 2017
5 // Author:  Artem ZHIDKOV
6
7 #include <PlaneGCSSolver_UpdateCoincidence.h>
8 #include <SketchSolver_Constraint.h>
9
10 #include <SketchPlugin_ConstraintCoincidence.h>
11 #include <SketchPlugin_ConstraintMiddle.h>
12
13 void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserver, const std::string& theType)
14 {
15   if (theType == GROUP()) {
16     std::list<SketchSolver_Constraint*>::iterator aPlaceToAdd = myObservers.end();
17     // point-point coincidence is placed first
18     if (theObserver->getType() == CONSTRAINT_PT_PT_COINCIDENT) {
19       for (aPlaceToAdd = myObservers.begin(); aPlaceToAdd != myObservers.end(); ++aPlaceToAdd)
20         if ((*aPlaceToAdd)->getType() != CONSTRAINT_PT_PT_COINCIDENT)
21           break;
22     }
23     myObservers.insert(aPlaceToAdd, theObserver);
24   } else
25     myNext->attach(theObserver, theType);
26 }
27
28 void PlaneGCSSolver_UpdateCoincidence::update(const FeaturePtr& theFeature)
29 {
30   if (theFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID() ||
31       theFeature->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
32     myCoincident.clear();
33     // notify listeners and stop procesing
34     std::list<SketchSolver_Constraint*>::iterator anIt = myObservers.begin();
35     for (; anIt != myObservers.end(); ++anIt)
36       (*anIt)->notify(theFeature, this);
37   } else
38     myNext->update(theFeature);
39 }
40
41 bool PlaneGCSSolver_UpdateCoincidence::checkCoincidence(
42     const EntityWrapperPtr& theEntity1,
43     const EntityWrapperPtr& theEntity2)
44 {
45   bool isAccepted = true;
46
47   std::list<std::set<EntityWrapperPtr> >::iterator anIt = myCoincident.begin();
48   std::list<std::set<EntityWrapperPtr> >::iterator aFound1 = myCoincident.end();
49   std::list<std::set<EntityWrapperPtr> >::iterator aFound2 = myCoincident.end();
50   for (; anIt != myCoincident.end(); ++anIt) {
51     if (aFound1 == myCoincident.end() && anIt->find(theEntity1) != anIt->end())
52       aFound1 = anIt;
53     if (aFound2 == myCoincident.end() && anIt->find(theEntity2) != anIt->end())
54       aFound2 = anIt;
55     if (aFound1 != myCoincident.end() && aFound2 != myCoincident.end())
56       break;
57   }
58
59   if (aFound1 == myCoincident.end() && aFound2 == myCoincident.end()) {
60     // new group of coincidence
61     std::set<EntityWrapperPtr> aNewCoinc;
62     aNewCoinc.insert(theEntity1);
63     aNewCoinc.insert(theEntity2);
64     myCoincident.push_back(aNewCoinc);
65   } else if (aFound1 == aFound2) // same group => already coincident
66     isAccepted = false;
67   else if (aFound1 == myCoincident.end())
68     aFound2->insert(theEntity1);
69   else if (aFound2 == myCoincident.end())
70     aFound1->insert(theEntity2);
71   else { // merge two groups
72     aFound1->insert(aFound2->begin(), aFound2->end());
73     myCoincident.erase(aFound2);
74   }
75
76   return isAccepted;
77 }