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,
14 const std::string& theType)
16 if (theType == GROUP()) {
17 std::list<SketchSolver_Constraint*>::iterator aPlaceToAdd = myObservers.end();
18 // point-point coincidence is placed first
19 if (theObserver->getType() == CONSTRAINT_PT_PT_COINCIDENT) {
20 for (aPlaceToAdd = myObservers.begin(); aPlaceToAdd != myObservers.end(); ++aPlaceToAdd)
21 if ((*aPlaceToAdd)->getType() != CONSTRAINT_PT_PT_COINCIDENT)
24 myObservers.insert(aPlaceToAdd, theObserver);
26 myNext->attach(theObserver, theType);
29 void PlaneGCSSolver_UpdateCoincidence::update(const FeaturePtr& theFeature)
31 if (theFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID() ||
32 theFeature->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
34 // notify listeners and stop procesing
35 std::list<SketchSolver_Constraint*>::iterator anIt = myObservers.begin();
36 for (; anIt != myObservers.end(); ++anIt)
37 (*anIt)->notify(theFeature, this);
39 myNext->update(theFeature);
42 bool PlaneGCSSolver_UpdateCoincidence::checkCoincidence(
43 const EntityWrapperPtr& theEntity1,
44 const EntityWrapperPtr& theEntity2)
46 bool isAccepted = true;
48 std::list<std::set<EntityWrapperPtr> >::iterator anIt = myCoincident.begin();
49 std::list<std::set<EntityWrapperPtr> >::iterator aFound1 = myCoincident.end();
50 std::list<std::set<EntityWrapperPtr> >::iterator aFound2 = myCoincident.end();
51 for (; anIt != myCoincident.end(); ++anIt) {
52 if (aFound1 == myCoincident.end() && anIt->find(theEntity1) != anIt->end())
54 if (aFound2 == myCoincident.end() && anIt->find(theEntity2) != anIt->end())
56 if (aFound1 != myCoincident.end() && aFound2 != myCoincident.end())
60 if (aFound1 == myCoincident.end() && aFound2 == myCoincident.end()) {
61 // new group of coincidence
62 std::set<EntityWrapperPtr> aNewCoinc;
63 aNewCoinc.insert(theEntity1);
64 aNewCoinc.insert(theEntity2);
65 myCoincident.push_back(aNewCoinc);
66 } else if (aFound1 == aFound2) // same group => already coincident
68 else if (aFound1 == myCoincident.end())
69 aFound2->insert(theEntity1);
70 else if (aFound2 == myCoincident.end())
71 aFound1->insert(theEntity2);
72 else { // merge two groups
73 aFound1->insert(aFound2->begin(), aFound2->end());
74 myCoincident.erase(aFound2);