]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_Storage.cpp
Salome HOME
Minor updates in SketchSolver plugin
[modules/shaper.git] / src / SketchSolver / SketchSolver_Storage.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Storage.cpp
4 // Created: 30 Nov 2015
5 // Author:  Artem ZHIDKOV
6
7 #include <SketchSolver_Storage.h>
8 #include <SketchSolver_Manager.h>
9
10 #include <GeomDataAPI_Point2D.h>
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_AttributeRefList.h>
13 #include <SketchPlugin_Arc.h>
14 #include <SketchPlugin_Circle.h>
15
16
17 /// \brief Verify two vectors of constraints are equal.
18 ///        Vectors differ by the order of elements are equal.
19 static bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
20                     const std::list<ConstraintWrapperPtr>& theCVec2);
21
22
23 void SketchSolver_Storage::addConstraint(ConstraintPtr        theConstraint,
24                                          ConstraintWrapperPtr theSolverConstraint)
25 {
26   std::list<ConstraintWrapperPtr> aConstrList(1, theSolverConstraint);
27   addConstraint(theConstraint, aConstrList);
28 }
29
30 void SketchSolver_Storage::addConstraint(
31     ConstraintPtr                   theConstraint,
32     std::list<ConstraintWrapperPtr> theSolverConstraints)
33 {
34   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
35       aFound = myConstraintMap.find(theConstraint);
36   if (aFound == myConstraintMap.end() || !isEqual(aFound->second, theSolverConstraints))
37     setNeedToResolve(true);
38
39   // Do not add point-point coincidence, because it is already made by setting
40   // the same parameters for both points
41   if (!theSolverConstraints.empty() &&
42       theSolverConstraints.front()->type() != CONSTRAINT_PT_PT_COINCIDENT) {
43     std::list<ConstraintWrapperPtr>::iterator aCIt = theSolverConstraints.begin();
44     for (; aCIt != theSolverConstraints.end(); ++aCIt)
45       update(*aCIt);
46   }
47   myConstraintMap[theConstraint] = theSolverConstraints;
48   // block events if necessary
49   if (myEventsBlocked && theConstraint->data() && theConstraint->data()->isValid())
50     theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
51 }
52
53 void SketchSolver_Storage::addEntity(FeaturePtr       theFeature,
54                                      EntityWrapperPtr theSolverEntity)
55 {
56   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
57   if (aFound == myFeatureMap.end() || !aFound->second || !aFound->second->isEqual(theSolverEntity))
58     setNeedToResolve(true); // the entity is new or modified
59
60   myFeatureMap[theFeature] = theSolverEntity;
61   // block events if necessary
62   if (myEventsBlocked && theFeature->data() && theFeature->data()->isValid())
63     theFeature->data()->blockSendAttributeUpdated(myEventsBlocked);
64 }
65
66 void SketchSolver_Storage::addEntity(AttributePtr     theAttribute,
67                                      EntityWrapperPtr theSolverEntity)
68 {
69   std::map<AttributePtr, EntityWrapperPtr>::const_iterator aFound = myAttributeMap.find(theAttribute);
70   if (aFound == myAttributeMap.end() || !aFound->second || !aFound->second->isEqual(theSolverEntity))
71     setNeedToResolve(true); // the entity is new or modified
72
73   myAttributeMap[theAttribute] = theSolverEntity;
74   // block events if necessary
75   if (myEventsBlocked && theAttribute->owner() &&
76       theAttribute->owner()->data() && theAttribute->owner()->data()->isValid())
77     theAttribute->owner()->data()->blockSendAttributeUpdated(myEventsBlocked);
78 }
79
80
81 bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup)
82 {
83   bool isUpdated = false;
84   EntityWrapperPtr aRelated = entity(theFeature);
85   if (!aRelated) { // Feature is not exist, create it
86     std::list<EntityWrapperPtr> aSubs;
87     // Reserve the feature in the map of features (do not want to add several copies of it)
88     myFeatureMap[theFeature] = aRelated;
89     // Firstly, create/update its attributes
90     std::list<AttributePtr> anAttrs =
91         theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
92     std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
93     for (; anIt != anAttrs.end(); ++anIt) {
94       isUpdated = update(*anIt, theGroup) || isUpdated;
95       aSubs.push_back(entity(*anIt));
96     }
97     // If the feature is a circle, add its radius as a sub
98     if (theFeature->getKind() == SketchPlugin_Circle::ID()) {
99       AttributePtr aRadius = theFeature->attribute(SketchPlugin_Circle::RADIUS_ID());
100       isUpdated = update(aRadius, theGroup) || isUpdated;
101       aSubs.push_back(entity(aRadius));
102     }
103     // If the feature if circle or arc, we need to add normal of the sketch to the list of subs
104     if (theFeature->getKind() == SketchPlugin_Arc::ID() ||
105         theFeature->getKind() == SketchPlugin_Circle::ID()) {
106       EntityWrapperPtr aNormal = getNormal();
107       if (aNormal) aSubs.push_back(aNormal);
108     }
109     // Secondly, convert feature
110     BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
111     GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
112     aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
113     if (!aRelated)
114       return false;
115     addEntity(theFeature, aRelated);
116   } else if (theGroup != GID_UNKNOWN)
117     changeGroup(aRelated, theGroup);
118   return update(aRelated) || isUpdated;
119 }
120
121 bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup)
122 {
123   AttributePtr anAttribute = theAttribute;
124   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
125   if (aRefAttr) {
126     if (aRefAttr->isObject()) {
127       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
128       return update(aFeature, theGroup);
129     } else
130       anAttribute = aRefAttr->attr();
131   }
132
133   EntityWrapperPtr aRelated = entity(anAttribute);
134   if (!aRelated) { // Attribute is not exist, create it
135     BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
136     GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
137     aRelated = aBuilder->createAttribute(anAttribute, aGroup);
138     if (!aRelated)
139       return false;
140     addEntity(anAttribute, aRelated);
141   } else if (theGroup != GID_UNKNOWN)
142     changeGroup(aRelated, theGroup);
143   return update(aRelated);
144 }
145
146
147
148 const std::list<ConstraintWrapperPtr>& SketchSolver_Storage::constraint(
149     const ConstraintPtr& theConstraint) const
150 {
151   static std::list<ConstraintWrapperPtr> aDummy;
152
153   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr>>::const_iterator
154       aFound = myConstraintMap.find(theConstraint);
155   if (aFound != myConstraintMap.end())
156     return aFound->second;
157   return aDummy;
158 }
159
160 const EntityWrapperPtr& SketchSolver_Storage::entity(const FeaturePtr& theFeature) const
161 {
162   static EntityWrapperPtr aDummy;
163
164   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
165   if (aFound != myFeatureMap.end())
166     return aFound->second;
167   return aDummy;
168 }
169
170 const EntityWrapperPtr& SketchSolver_Storage::entity(const AttributePtr& theAttribute) const
171 {
172   static EntityWrapperPtr aDummy;
173
174   std::map<AttributePtr, EntityWrapperPtr>::const_iterator
175       aFound = myAttributeMap.find(theAttribute);
176   if (aFound != myAttributeMap.end())
177     return aFound->second;
178
179   AttributeRefAttrPtr aRefAttr =
180       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
181   if (aRefAttr) {
182     if (aRefAttr->isObject()) {
183       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
184       return entity(aFeature);
185     } else
186       return entity(aRefAttr->attr());
187   }
188   return aDummy;
189 }
190
191 bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint)
192 {
193   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::iterator
194       aFound = myConstraintMap.find(theConstraint);
195   if (aFound == myConstraintMap.end())
196     return true; // no constraint, already deleted
197
198   // Remove constraint
199   std::list<ConstraintWrapperPtr> aConstrList = aFound->second;
200   myConstraintMap.erase(aFound);
201   // Remove SolveSpace constraints
202   bool isFullyRemoved = true;
203   std::list<ConstraintWrapperPtr>::iterator anIt = aConstrList.begin();
204   while (anIt != aConstrList.end()) {
205     if (remove(*anIt)) {
206       std::list<ConstraintWrapperPtr>::iterator aRemoveIt = anIt++;
207       aConstrList.erase(aRemoveIt);
208     } else {
209       isFullyRemoved = false;
210       ++anIt;
211     }
212   }
213   if (!isFullyRemoved) {
214     // revert removed constraint
215     addConstraint(theConstraint, aConstrList);
216   }
217   return isFullyRemoved;
218 }
219
220 template <class ENT_TYPE>
221 static bool isUsed(ConstraintWrapperPtr theConstraint, ENT_TYPE theEntity)
222 {
223   std::list<EntityWrapperPtr>::const_iterator anEntIt = theConstraint->entities().begin();
224   for (; anEntIt != theConstraint->entities().end(); ++anEntIt)
225     if ((*anEntIt)->isBase(theEntity))
226       return true;
227   return false;
228 }
229
230 static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
231 {
232   std::list<EntityWrapperPtr>::const_iterator aSubIt = theFeature->subEntities().begin();
233   for (; aSubIt != theFeature->subEntities().end(); ++aSubIt)
234     if ((*aSubIt)->isBase(theSubEntity))
235       return true;
236   return false;
237 }
238
239 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
240 {
241   if (myFeatureMap.find(theFeature) != myFeatureMap.end())
242     return true;
243   // check constraints
244   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
245       aCIt = myConstraintMap.begin();
246   std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
247   for (; aCIt != myConstraintMap.end(); ++aCIt)
248     for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
249       if (::isUsed(*aCWIt, theFeature))
250         return true;
251   // check attributes
252   std::list<AttributePtr> anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
253   std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
254   for (; anIt != anAttrList.end(); ++anIt)
255     if (isUsed(*anIt))
256       return true;
257   return false;
258 }
259
260 bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
261 {
262   AttributePtr anAttribute = theAttribute;
263   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
264   if (aRefAttr) {
265     if (aRefAttr->isObject())
266       return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
267     else
268       anAttribute = aRefAttr->attr();
269   }
270
271   if (myAttributeMap.find(theAttribute) != myAttributeMap.end())
272     return true;
273   // check in constraints
274   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
275       aCIt = myConstraintMap.begin();
276   std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
277   for (; aCIt != myConstraintMap.end(); ++aCIt)
278     for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
279       if (::isUsed(*aCWIt, anAttribute))
280         return true;
281   // check in features
282   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
283   for (; aFIt != myFeatureMap.end(); ++aFIt)
284     if (::isUsed(aFIt->second, anAttribute))
285       return true;
286   return false;
287 }
288
289
290 bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature)
291 {
292   std::map<FeaturePtr, EntityWrapperPtr>::iterator aFound = myFeatureMap.find(theFeature);
293   if (aFound == myFeatureMap.end())
294     return false; // feature not found, nothing to delete
295
296   // Check the feature is not used by constraints
297   if (isUsed(theFeature))
298     return false; // the feature is used, don't remove it
299
300   // Remove feature
301   EntityWrapperPtr anEntity = aFound->second;
302   myFeatureMap.erase(aFound);
303   if (remove(anEntity))
304     return true;
305   // feature is not removed, revert operation
306   myFeatureMap[theFeature] = anEntity;
307   update(anEntity);
308   return false;
309 }
310
311 bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute)
312 {
313   std::map<AttributePtr, EntityWrapperPtr>::iterator aFound = myAttributeMap.find(theAttribute);
314   if (aFound == myAttributeMap.end())
315     return false; // attribute not found, nothing to delete
316
317   // Check the attribute is not used by constraints
318   if (isUsed(theAttribute))
319     return false; // the attribute is used, don't remove it
320   // Check the attribute is not used by other features
321   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
322   for (; aFIt != myFeatureMap.end(); ++aFIt)
323     if (::isUsed(aFIt->second, theAttribute)) // the attribute is used, don't remove it
324       return false;
325
326   // Remove attribute
327   EntityWrapperPtr anEntity = aFound->second;
328   myAttributeMap.erase(aFound);
329   if (remove(anEntity))
330     return true;
331   // attribute is not removed, revert operation
332   myAttributeMap[theAttribute] = anEntity;
333   update(anEntity);
334   return false;
335 }
336
337
338 bool SketchSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
339 {
340   bool isFullyRemoved = true;
341   std::list<EntityWrapperPtr>::const_iterator anIt = theConstraint->entities().begin();
342   for (; anIt != theConstraint->entities().end(); ++anIt) {
343     FeaturePtr aBaseFeature = (*anIt)->baseFeature();
344     if (aBaseFeature)
345       isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
346     else
347       isFullyRemoved = SketchSolver_Storage::removeEntity((*anIt)->baseAttribute()) && isFullyRemoved;
348   }
349   return isFullyRemoved;
350 }
351
352 bool SketchSolver_Storage::remove(EntityWrapperPtr theEntity)
353 {
354   bool isFullyRemoved = true;
355   std::list<EntityWrapperPtr>::const_iterator anEntIt = theEntity->subEntities().begin();
356   for (; anEntIt != theEntity->subEntities().end(); ++anEntIt) {
357     FeaturePtr aBaseFeature = (*anEntIt)->baseFeature();
358     if (aBaseFeature)
359       isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
360     else
361       isFullyRemoved = SketchSolver_Storage::removeEntity((*anEntIt)->baseAttribute()) && isFullyRemoved;
362   }
363
364   std::list<ParameterWrapperPtr>::const_iterator aParIt = theEntity->parameters().begin();
365   for (; aParIt != theEntity->parameters().end(); ++aParIt)
366     isFullyRemoved = remove(*aParIt) && isFullyRemoved;
367   return isFullyRemoved;
368 }
369
370
371 bool SketchSolver_Storage::isInteract(const FeaturePtr& theFeature) const
372 {
373   if (!theFeature)
374     return false;
375   if (myConstraintMap.empty())
376     return true; // empty storage interacts with each feature
377
378   ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
379   if (aConstraint) {
380     if (myConstraintMap.find(aConstraint) != myConstraintMap.end())
381       return true;
382   } else if (myFeatureMap.find(theFeature) != myFeatureMap.end())
383     return true;
384
385   std::list<AttributePtr> anAttrList = theFeature->data()->attributes(std::string());
386   std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
387   for (; anIt != anAttrList.end(); ++anIt)
388     if (isInteract(*anIt))
389       return true;
390
391   return false;
392 }
393
394 bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const
395 {
396   if (!theAttribute)
397     return false;
398
399   AttributeRefListPtr aRefList = 
400       std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
401   if (aRefList) {
402     std::list<ObjectPtr> anObjects = aRefList->list();
403     std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
404     for (; anObjIt != anObjects.end(); ++anObjIt) {
405       FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt);
406       if (isInteract(aFeature))
407         return true;
408     }
409     return false;
410   }
411
412   AttributeRefAttrPtr aRefAttr =
413       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
414   if (!aRefAttr)
415     return myAttributeMap.find(theAttribute) != myAttributeMap.end();
416   if (!aRefAttr->isObject())
417     return myAttributeMap.find(aRefAttr->attr()) != myAttributeMap.end();
418
419   FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
420   return isInteract(aFeature);
421 }
422
423 bool SketchSolver_Storage::isConsistent() const
424 {
425   // Check the constraints are valid
426   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
427       aCIter = myConstraintMap.begin();
428   for (; aCIter != myConstraintMap.end(); ++aCIter)
429     if (!aCIter->first->data() || !aCIter->first->data()->isValid())
430       return false;
431   // Check the features are valid
432   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
433   for (; aFIter != myFeatureMap.end(); aFIter++)
434     if (!aFIter->first->data() || !aFIter->first->data()->isValid())
435       return false;
436   return true;
437 }
438
439 bool SketchSolver_Storage::isFixed(EntityWrapperPtr theEntity) const
440 {
441   if (theEntity->group() != myGroupID)
442     return true;
443   // no need additional checking for entities differ than point
444   if (theEntity->type() != ENTITY_POINT)
445     return false;
446
447   CoincidentPointsMap::const_iterator anIt = myCoincidentPoints.begin();
448   for (; anIt != myCoincidentPoints.end(); ++anIt)
449     if (anIt->first == theEntity || anIt->second.find(theEntity) != anIt->second.end()) {
450       if (anIt->first->group() != myGroupID)
451         return true;
452       std::set<EntityWrapperPtr>::const_iterator anEntIt = anIt->second.begin();
453       for (; anEntIt != anIt->second.end(); ++anEntIt)
454         if ((*anEntIt)->group() != myGroupID)
455           return true;
456     }
457   return false;
458 }
459
460 void SketchSolver_Storage::removeInvalidEntities()
461 {
462   // Remove invalid constraints
463   std::list<ConstraintPtr> anInvalidConstraints;
464   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
465       aCIter = myConstraintMap.begin();
466   for (; aCIter != myConstraintMap.end(); ++aCIter)
467     if (!aCIter->first->data() || !aCIter->first->data()->isValid())
468       anInvalidConstraints.push_back(aCIter->first);
469   std::list<ConstraintPtr>::const_iterator anInvCIt = anInvalidConstraints.begin();
470   for (; anInvCIt != anInvalidConstraints.end(); ++anInvCIt)
471     removeConstraint(*anInvCIt);
472   // Remove invalid features
473   std::list<FeaturePtr> anInvalidFeatures;
474   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
475   for (; aFIter != myFeatureMap.end(); aFIter++)
476     if (!aFIter->first->data() || !aFIter->first->data()->isValid())
477       anInvalidFeatures.push_back(aFIter->first);
478   std::list<FeaturePtr>::const_iterator anInvFIt = anInvalidFeatures.begin();
479   for (; anInvFIt != anInvalidFeatures.end(); ++anInvFIt)
480     removeEntity(*anInvFIt);
481 }
482
483 EntityWrapperPtr SketchSolver_Storage::getNormal() const
484 {
485   EntityWrapperPtr aSketch = sketch();
486   if (!aSketch)
487     return aSketch;
488
489   // Find normal entity
490   const std::list<EntityWrapperPtr>& aSketchSubs = aSketch->subEntities();
491   std::list<EntityWrapperPtr>::const_iterator aSIt = aSketchSubs.begin();
492   for (; aSIt != aSketchSubs.end(); ++aSIt)
493     if ((*aSIt)->type() == ENTITY_NORMAL)
494       return *aSIt;
495   return EntityWrapperPtr();
496 }
497
498 const EntityWrapperPtr& SketchSolver_Storage::sketch() const
499 {
500   static EntityWrapperPtr aDummySketch;
501
502   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
503   for (; aFIt != myFeatureMap.end(); ++aFIt)
504     if (aFIt->second && aFIt->second->type() == ENTITY_SKETCH)
505       break;
506   if (aFIt == myFeatureMap.end())
507     return aDummySketch;
508   return aFIt->second;
509 }
510
511 void SketchSolver_Storage::setSketch(const EntityWrapperPtr& theSketch)
512 {
513   if (sketch())
514     return;
515   addEntity(FeaturePtr(), theSketch);
516 }
517
518 void SketchSolver_Storage::blockEvents(bool isBlocked)
519 {
520   if (isBlocked == myEventsBlocked)
521     return;
522
523   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
524       aCIter = myConstraintMap.begin();
525   for (; aCIter != myConstraintMap.end(); aCIter++)
526     if (aCIter->first->data() && aCIter->first->data()->isValid())
527       aCIter->first->data()->blockSendAttributeUpdated(isBlocked);
528
529   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
530   for (; aFIter != myFeatureMap.end(); aFIter++)
531     if (aFIter->first->data() && aFIter->first->data()->isValid())
532       aFIter->first->data()->blockSendAttributeUpdated(isBlocked);
533
534   std::map<AttributePtr, EntityWrapperPtr>::const_iterator anAtIter = myAttributeMap.begin();
535   for (; anAtIter != myAttributeMap.end(); anAtIter++)
536     if (anAtIter->first->owner() && anAtIter->first->owner()->data() &&
537         anAtIter->first->owner()->data()->isValid())
538       anAtIter->first->owner()->data()->blockSendAttributeUpdated(isBlocked);
539   myEventsBlocked = isBlocked;
540 }
541
542
543
544
545
546
547 // ==============   Auxiliary functions   ====================================
548 bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
549              const std::list<ConstraintWrapperPtr>& theCVec2)
550 {
551   if (theCVec1.size() != theCVec2.size())
552     return false;
553
554   std::list<bool> aChecked(theCVec2.size(), false);
555   std::list<ConstraintWrapperPtr>::const_iterator anIt1 = theCVec1.begin();
556   for (; anIt1 != theCVec1.end(); ++anIt1) {
557     std::list<ConstraintWrapperPtr>::const_iterator anIt2 = theCVec2.begin();
558     std::list<bool>::iterator aCheckIt = aChecked.begin();
559     while (aCheckIt != aChecked.end() && *aCheckIt) {
560       ++aCheckIt;
561       ++anIt2;
562     }
563     for (; anIt2 != theCVec2.end(); ++anIt2, ++aCheckIt)
564       if (!(*aCheckIt) && (*anIt1)->isEqual(*anIt2)) {
565         *aCheckIt = true;
566         break;
567       }
568     // the same constraint is not found
569     if (anIt2 == theCVec2.end())
570       return false;
571   }
572   return true;
573 }