1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PlaneGCSSolver_UpdateCoincidence.cpp
4 // Created: 17 Feb 2017
5 // Author: Artem ZHIDKOV
7 #include <PlaneGCSSolver_UpdateCoincidence.h>
8 #include <SketchSolver_Constraint.h>
10 #include <SketchPlugin_ConstraintCoincidence.h>
11 #include <SketchPlugin_ConstraintMiddle.h>
13 void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserver, const std::string& theType)
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)
23 myObservers.insert(aPlaceToAdd, theObserver);
25 myNext->attach(theObserver, theType);
28 void PlaneGCSSolver_UpdateCoincidence::update(const FeaturePtr& theFeature)
30 if (theFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID() ||
31 theFeature->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
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);
38 myNext->update(theFeature);
41 bool PlaneGCSSolver_UpdateCoincidence::checkCoincidence(
42 const EntityWrapperPtr& theEntity1,
43 const EntityWrapperPtr& theEntity2)
45 bool isAccepted = true;
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())
53 if (aFound2 == myCoincident.end() && anIt->find(theEntity2) != anIt->end())
55 if (aFound1 != myCoincident.end() && aFound2 != myCoincident.end())
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
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);