Salome HOME
Fix for the issue #743
[modules/shaper.git] / src / Model / Model_Objects.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Objects.cxx
4 // Created:     15 May 2015
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_Objects.h>
8 #include <Model_Data.h>
9 #include <Model_Document.h>
10 #include <Model_Events.h>
11 #include <Model_Session.h>
12 #include <Model_ResultPart.h>
13 #include <Model_ResultConstruction.h>
14 #include <Model_ResultBody.h>
15 #include <Model_ResultGroup.h>
16 #include <Model_ResultParameter.h>
17 #include <ModelAPI_Validator.h>
18 #include <ModelAPI_CompositeFeature.h>
19 #include <ModelAPI_Tools.h>
20
21 #include <Events_Loop.h>
22 #include <Events_Error.h>
23
24 #include <TDataStd_Integer.hxx>
25 #include <TDataStd_Comment.hxx>
26 #include <TDF_ChildIDIterator.hxx>
27 #include <TDataStd_ReferenceArray.hxx>
28 #include <TDataStd_HLabelArray1.hxx>
29 #include <TDataStd_Name.hxx>
30 #include <TDF_Reference.hxx>
31 #include <TDF_ChildIDIterator.hxx>
32 #include <TDF_LabelMapHasher.hxx>
33
34 static const int TAG_OBJECTS = 2;  // tag of the objects sub-tree (features, results)
35
36 // feature sub-labels
37 static const int TAG_FEATURE_ARGUMENTS = 1;  ///< where the arguments are located
38 static const int TAG_FEATURE_RESULTS = 2;  ///< where the results are located
39
40 ///
41 /// 0:1:2 - where features are located
42 /// 0:1:2:N:1 - data of the feature N
43 /// 0:1:2:N:2:K:1 - data of the K result of the feature N
44
45 Model_Objects::Model_Objects(TDF_Label theMainLab) : myMain(theMainLab)
46 {
47 }
48
49 void Model_Objects::setOwner(DocumentPtr theDoc)
50 {
51   myDoc = theDoc;
52   // update all fields and recreate features and result objects if needed
53   synchronizeFeatures(false, true, true);
54   myHistory.clear();
55 }
56
57 Model_Objects::~Model_Objects()
58 {
59   // delete all features of this document
60   Events_Loop* aLoop = Events_Loop::loop();
61   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeaturesIter(myFeatures);
62   for(; aFeaturesIter.More(); aFeaturesIter.Next()) {
63     FeaturePtr aFeature = aFeaturesIter.Value();
64     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
65     ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group());
66     ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
67     aFeature->eraseResults();
68     aFeature->erase();
69   }
70   myFeatures.Clear();
71   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
72   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
73
74 }
75
76 /// Appends to the array of references a new referenced label
77 static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced, TDF_Label& thePrevLab)
78 {
79   Handle(TDataStd_ReferenceArray) aRefs;
80   if (!theArrayLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
81     aRefs = TDataStd_ReferenceArray::Set(theArrayLab, 0, 0);
82     aRefs->SetValue(0, theReferenced);
83   } else {  // extend array by one more element
84     Handle(TDataStd_HLabelArray1) aNewArray = new TDataStd_HLabelArray1(aRefs->Lower(),
85                                                                         aRefs->Upper() + 1);
86     int aPassedPrev = 0; // prev feature is found and passed
87     if (thePrevLab.IsNull()) { // null means that inserted feature must be the first
88       aNewArray->SetValue(aRefs->Lower(), theReferenced);
89       aPassedPrev = 1;
90     }
91     for (int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
92       aNewArray->SetValue(a + aPassedPrev, aRefs->Value(a));
93       if (!aPassedPrev && aRefs->Value(a).IsEqual(thePrevLab)) {
94         aPassedPrev = 1;
95         aNewArray->SetValue(a + 1, theReferenced);
96       }
97     }
98     if (!aPassedPrev) // not found: unknown situation
99       aNewArray->SetValue(aRefs->Upper() + 1, theReferenced);
100     aRefs->SetInternalArray(aNewArray);
101   }
102 }
103
104 void Model_Objects::addFeature(FeaturePtr theFeature, const FeaturePtr theAfterThis)
105 {
106   if (!theFeature->isAction()) {  // do not add action to the data model
107     TDF_Label aFeaturesLab = featuresLabel();
108     TDF_Label aFeatureLab = aFeaturesLab.NewChild();
109     // store feature in the features array: before "initData" because in macro features
110     // in initData it creates new features, appeared later than this
111     TDF_Label aPrevFeateureLab;
112     if (theAfterThis.get()) { // searching for the previous feature label
113       std::shared_ptr<Model_Data> aPrevData = 
114         std::dynamic_pointer_cast<Model_Data>(theAfterThis->data());
115       if (aPrevData.get()) {
116         aPrevFeateureLab = aPrevData->label().Father();
117       }
118     }
119     AddToRefArray(aFeaturesLab, aFeatureLab, aPrevFeateureLab);
120
121     // keep the feature ID to restore document later correctly
122     TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str());
123     myFeatures.Bind(aFeatureLab, theFeature);
124     // must be after binding to the map because of "Box" macro feature that 
125     // creates other features in "initData"
126     initData(theFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
127     // event: feature is added
128     static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
129     ModelAPI_EventCreator::get()->sendUpdated(theFeature, anEvent);
130     theFeature->setDisabled(false); // by default created feature is enabled
131     updateHistory(ModelAPI_Feature::group());
132   } else { // make feature has not-null data anyway
133     theFeature->setData(Model_Data::invalidData());
134     theFeature->setDoc(myDoc);
135   }
136 }
137
138 /// Appends to the array of references a new referenced label.
139 /// If theIndex is not -1, removes element at this index, not theReferenced.
140 /// \returns the index of removed element
141 static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, 
142   const int theIndex = -1)
143 {
144   int aResult = -1;  // no returned
145   Handle(TDataStd_ReferenceArray) aRefs;
146   if (theArrayLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
147     if (aRefs->Length() == 1) {  // just erase an array
148       if ((theIndex == -1 && aRefs->Value(0) == theReferenced) || theIndex == 0) {
149         theArrayLab.ForgetAttribute(TDataStd_ReferenceArray::GetID());
150       }
151       aResult = 0;
152     } else {  // reduce the array
153       Handle(TDataStd_HLabelArray1) aNewArray = new TDataStd_HLabelArray1(aRefs->Lower(),
154                                                                           aRefs->Upper() - 1);
155       int aCount = aRefs->Lower();
156       for (int a = aCount; a <= aRefs->Upper(); a++, aCount++) {
157         if ((theIndex == -1 && aRefs->Value(a) == theReferenced) || theIndex == a) {
158           aCount--;
159           aResult = a;
160         } else {
161           aNewArray->SetValue(aCount, aRefs->Value(a));
162         }
163       }
164       aRefs->SetInternalArray(aNewArray);
165     }
166   }
167   return aResult;
168 }
169
170 void Model_Objects::refsToFeature(FeaturePtr theFeature,
171   std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs, const bool isSendError)
172 {
173   // check the feature: it must have no depended objects on it
174   // the dependencies can be in the feature results
175   std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
176   for(; aResIter != theFeature->results().cend(); aResIter++) {
177     ResultPtr aResult = (*aResIter);
178     std::shared_ptr<Model_Data> aData = 
179       std::dynamic_pointer_cast<Model_Data>(aResult->data());
180     if (aData.get() != NULL) {
181       const std::set<AttributePtr>& aRefs = aData->refsToMe();
182       std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
183       for(; aRefIt != aRefLast; aRefIt++) {
184         FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
185         if (aFeature.get() != NULL)
186           theRefs.insert(aFeature);
187       }
188     }
189   }
190   // the dependencies can be in the feature itself
191   std::shared_ptr<Model_Data> aData = 
192       std::dynamic_pointer_cast<Model_Data>(theFeature->data());
193   if (aData && !aData->refsToMe().empty()) {
194     const std::set<AttributePtr>& aRefs = aData->refsToMe();
195     std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
196     for(; aRefIt != aRefLast; aRefIt++) {
197       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
198       if (aFeature.get() != NULL)
199         theRefs.insert(aFeature);
200     }
201   }
202
203   if (!theRefs.empty() && isSendError) {
204     Events_Error::send(
205       "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
206   }
207 }
208
209 void Model_Objects::removeFeature(FeaturePtr theFeature)
210 {
211   std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theFeature->data());
212   if (aData && aData->isValid()) {
213     // checking that the sub-element of composite feature is removed: if yes, inform the owner
214     std::set<std::shared_ptr<ModelAPI_Feature> > aRefs;
215     refsToFeature(theFeature, aRefs, false);
216     std::set<std::shared_ptr<ModelAPI_Feature> >::iterator aRefIter = aRefs.begin();
217     for(; aRefIter != aRefs.end(); aRefIter++) {
218       std::shared_ptr<ModelAPI_CompositeFeature> aComposite = 
219         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aRefIter);
220       if (aComposite.get()) {
221         aComposite->removeFeature(theFeature);
222       }
223     }
224     // this must be before erase since theFeature erasing removes all information about
225     // the feature results and groups of results
226     // To reproduce: create sketch, extrusion, remove sketch => constructions tree is not updated
227     clearHistory(theFeature);
228     // erase fields
229     theFeature->erase();
230
231     TDF_Label aFeatureLabel = aData->label().Father();
232     if (myFeatures.IsBound(aFeatureLabel))
233       myFeatures.UnBind(aFeatureLabel);
234
235     static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
236     ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
237     // erase all attributes under the label of feature
238     aFeatureLabel.ForgetAllAttributes();
239     // remove it from the references array
240     RemoveFromRefArray(featuresLabel(), aFeatureLabel);
241     // event: feature is deleted
242     ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
243     // the redisplay signal should be flushed in order to erase the feature presentation in the viewer
244     Events_Loop::loop()->flush(EVENT_DISP);
245     updateHistory(ModelAPI_Feature::group());
246   }
247 }
248
249 void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
250 {
251   TDF_Label aFeaturesLab = featuresLabel();
252   Handle(TDataStd_ReferenceArray) aRefs;
253   if (!aFeaturesLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
254     return;
255   TDF_Label anAfterLab, aMovedLab = 
256     std::dynamic_pointer_cast<Model_Data>(theMoved->data())->label().Father();
257   if (theAfterThis.get())
258     anAfterLab = std::dynamic_pointer_cast<Model_Data>(theAfterThis->data())->label().Father();
259
260   Handle(TDataStd_HLabelArray1) aNewArray = 
261     new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper());
262   int aPassedMovedFrom = 0; // the prev feature location is found and passed
263   int aPassedMovedTo = 0; // the feature is added and this location is passed
264   if (!theAfterThis.get()) { // null means that inserted feature must be the first
265     aNewArray->SetValue(aRefs->Lower(), aMovedLab);
266     aPassedMovedTo = 1;
267   }
268   for (int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
269     if (aPassedMovedTo == 0 && aRefs->Value(a) == anAfterLab) { // add two
270       aPassedMovedTo++;
271       aNewArray->SetValue(a - aPassedMovedFrom, anAfterLab);
272       if (a + 1 - aPassedMovedFrom <= aRefs->Upper())
273         aNewArray->SetValue(a + 1 - aPassedMovedFrom, aMovedLab);
274     } else if (aPassedMovedFrom == 0 && aRefs->Value(a) == aMovedLab) { // skip
275       aPassedMovedFrom++;
276     } else { // just copy one
277       if (a - aPassedMovedFrom + aPassedMovedTo <= aRefs->Upper())
278         aNewArray->SetValue(a - aPassedMovedFrom + aPassedMovedTo, aRefs->Value(a));
279     }
280   }
281   if (!aPassedMovedFrom || !aPassedMovedTo) {// not found: unknown situation
282     if (!aPassedMovedFrom) {
283       static std::string aMovedFromError("The moved feature is not found");
284       Events_Error::send(aMovedFromError);
285     } else {
286       static std::string aMovedToError("The 'after' feature for movement is not found");
287       Events_Error::send(aMovedToError);
288     }
289     return;
290   }
291   // store the new array
292   aRefs->SetInternalArray(aNewArray);
293   // update the feature and the history
294   clearHistory(theMoved);
295   static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
296   ModelAPI_EventCreator::get()->sendUpdated(theMoved, EVENT_UPD);
297 }
298
299 void Model_Objects::clearHistory(ObjectPtr theObj)
300 {
301   if (theObj) {
302     const std::string aGroup = theObj->groupName();
303     std::map<std::string, std::vector<ObjectPtr> >::iterator aHIter = myHistory.find(aGroup);
304     if (aHIter != myHistory.end())
305       myHistory.erase(aHIter); // erase from map => this means that it is not synchronized
306     if (theObj->groupName() == ModelAPI_Feature::group()) { // clear results group of the feature
307       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
308       std::string aResultGroup = featureResultGroup(aFeature);
309       if (!aResultGroup.empty()) {
310         std::map<std::string, std::vector<ObjectPtr> >::iterator aHIter = 
311           myHistory.find(aResultGroup);
312         if (aHIter != myHistory.end())
313           myHistory.erase(aHIter); // erase from map => this means that it is not synchronized
314       }
315     }
316   }
317 }
318
319 void Model_Objects::createHistory(const std::string& theGroupID)
320 {
321   std::map<std::string, std::vector<ObjectPtr> >::iterator aHIter = myHistory.find(theGroupID);
322   if (aHIter == myHistory.end()) {
323     myHistory[theGroupID] = std::vector<ObjectPtr>();
324     std::vector<ObjectPtr>& aResult = myHistory[theGroupID];
325     // iterate the array of references and get feature by feature from the array
326     bool isFeature = theGroupID == ModelAPI_Feature::group();
327     Handle(TDataStd_ReferenceArray) aRefs;
328     if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
329       for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
330         FeaturePtr aFeature = feature(aRefs->Value(a));
331         if (aFeature.get()) {
332           // if feature is in sub-component, remove it from history: it is in sub-tree of sub-component
333           if (!ModelAPI_Tools::compositeOwner(aFeature).get()) {
334             if (isFeature) { // here may be also disabled features
335               if (aFeature->isInHistory()) {
336                 aResult.push_back(aFeature);
337               }
338             } else if (!aFeature->isDisabled()) { // iterate all results of not-disabled feature
339               const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
340               std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
341               for (; aRIter != aResults.cend(); aRIter++) {
342                 ResultPtr aRes = *aRIter;
343                 if (aRes->groupName() != theGroupID) break; // feature have only same group results
344                 if (!aRes->isDisabled() && aRes->isInHistory() && !aRes->isConcealed()) {
345                   aResult.push_back(*aRIter);
346                 }
347               }
348             }
349           }
350         }
351       }
352     }
353   }
354 }
355
356 void Model_Objects::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
357 {
358   clearHistory(theObject);
359 }
360
361 void Model_Objects::updateHistory(const std::string theGroup)
362 {
363   std::map<std::string, std::vector<ObjectPtr> >::iterator aHIter = myHistory.find(theGroup);
364   if (aHIter != myHistory.end())
365     myHistory.erase(aHIter); // erase from map => this means that it is not synchronized
366 }
367
368 FeaturePtr Model_Objects::feature(TDF_Label theLabel) const
369 {
370   if (myFeatures.IsBound(theLabel))
371     return myFeatures.Find(theLabel);
372   return FeaturePtr();  // not found
373 }
374
375 ObjectPtr Model_Objects::object(TDF_Label theLabel)
376 {
377   // try feature by label
378   FeaturePtr aFeature = feature(theLabel);
379   if (aFeature)
380     return feature(theLabel);
381   TDF_Label aFeatureLabel = theLabel.Father().Father();  // let's suppose it is result
382   aFeature = feature(aFeatureLabel);
383   if (aFeature) {
384     const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
385     std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
386     for (; aRIter != aResults.cend(); aRIter++) {
387       std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>(
388           (*aRIter)->data());
389       if (aResData->label().Father().IsEqual(theLabel))
390         return *aRIter;
391     }
392   }
393   return FeaturePtr();  // not found
394 }
395
396 ObjectPtr Model_Objects::object(const std::string& theGroupID, const int theIndex)
397 {
398   if (theIndex == -1)
399     return ObjectPtr();
400   createHistory(theGroupID);
401   return myHistory[theGroupID][theIndex];
402 }
403
404 std::shared_ptr<ModelAPI_Object> Model_Objects::objectByName(
405     const std::string& theGroupID, const std::string& theName)
406 {
407   createHistory(theGroupID);
408   std::vector<ObjectPtr>& allObjs = myHistory[theGroupID];
409   std::vector<ObjectPtr>::iterator anObjIter = allObjs.begin();
410   for(; anObjIter != allObjs.end(); anObjIter++) {
411     if ((*anObjIter)->data()->name() == theName)
412       return *anObjIter;
413   }
414   // not found
415   return ObjectPtr();
416 }
417
418 const int Model_Objects::index(std::shared_ptr<ModelAPI_Object> theObject)
419 {
420   std::string aGroup = theObject->groupName();
421   createHistory(aGroup);
422   std::vector<ObjectPtr>& allObjs = myHistory[aGroup];
423   std::vector<ObjectPtr>::iterator anObjIter = allObjs.begin(); // iterate to search object
424   for(int anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) {
425     if ((*anObjIter) == theObject)
426       return anIndex;
427   }
428   // not found
429   return -1;
430 }
431
432 int Model_Objects::size(const std::string& theGroupID)
433 {
434   createHistory(theGroupID);
435   return myHistory[theGroupID].size();
436 }
437
438 void Model_Objects::allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults)
439 {
440   // iterate the array of references and get feature by feature from the array
441   Handle(TDataStd_ReferenceArray) aRefs;
442   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
443     for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
444       FeaturePtr aFeature = feature(aRefs->Value(a));
445       if (aFeature.get()) {
446         const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
447         std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
448         for (; aRIter != aResults.cend(); aRIter++) {
449           ResultPtr aRes = *aRIter;
450           if (aRes->groupName() != theGroupID) break; // feature have only same group results
451           if (aRes->isInHistory() && !aRes->isConcealed()) {
452             theResults.push_back(*aRIter);
453           }
454         }
455       }
456     }
457   }
458 }
459
460
461 TDF_Label Model_Objects::featuresLabel() const
462 {
463   return myMain.FindChild(TAG_OBJECTS);
464 }
465
466 void Model_Objects::setUniqueName(FeaturePtr theFeature)
467 {
468   if (!theFeature->data()->name().empty())
469     return;  // not needed, name is already defined
470   std::string aName;  // result
471   // first count all features of such kind to start with index = count + 1
472   int aNumObjects = -1; // this feature is already in this map
473   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myFeatures);
474   for (; aFIter.More(); aFIter.Next()) {
475     if (aFIter.Value()->getKind() == theFeature->getKind())
476       aNumObjects++;
477   }
478   // generate candidate name
479   std::stringstream aNameStream;
480   aNameStream << theFeature->getKind() << "_" << aNumObjects + 1;
481   aName = aNameStream.str();
482   // check this is unique, if not, increase index by 1
483   for (aFIter.Initialize(myFeatures); aFIter.More();) {
484     FeaturePtr aFeature = aFIter.Value();
485     bool isSameName = aFeature->data()->name() == aName;
486     if (!isSameName) {  // check also results to avoid same results names (actual for Parts)
487       const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
488       std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
489       for (; aRIter != aResults.cend(); aRIter++) {
490         isSameName = (*aRIter)->data()->name() == aName;
491       }
492     }
493     if (isSameName) {
494       aNumObjects++;
495       std::stringstream aNameStream;
496       aNameStream << theFeature->getKind() << "_" << aNumObjects + 1;
497       aName = aNameStream.str();
498       // reinitialize iterator to make sure a new name is unique
499       aFIter.Initialize(myFeatures);
500     } else
501       aFIter.Next();
502   }
503   theFeature->data()->setName(aName);
504 }
505
506 void Model_Objects::initData(ObjectPtr theObj, TDF_Label theLab, const int theTag)
507 {
508   std::shared_ptr<Model_Data> aData(new Model_Data);
509   aData->setLabel(theLab.FindChild(theTag));
510   aData->setObject(theObj);
511   theObj->setDoc(myDoc);
512   theObj->setData(aData);
513   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
514   if (aFeature) {
515     setUniqueName(aFeature);  // must be before "initAttributes" because duplicate part uses name
516   }
517   theObj->initAttributes();
518 }
519
520 void Model_Objects::synchronizeFeatures(
521   const bool theMarkUpdated, const bool theUpdateReferences, const bool theFlush)
522 {
523   Model_Document* anOwner = std::dynamic_pointer_cast<Model_Document>(myDoc).get();
524   if (!anOwner) // this may happen on creation of document: nothing there, so nothing to synchronize
525     return;
526   // after all updates, sends a message that groups of features were created or updated
527   Events_Loop* aLoop = Events_Loop::loop();
528   static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
529   static Events_ID aCreateEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
530   static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
531   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
532   static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
533   static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
534   bool isActive = aLoop->activateFlushes(false);
535
536   // update all objects by checking are they on labels or not
537   std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
538   TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
539   for (; aLabIter.More(); aLabIter.Next()) {
540     TDF_Label aFeatureLabel = aLabIter.Value()->Label();
541     FeaturePtr aFeature;
542     if (!myFeatures.IsBound(aFeatureLabel)) {  // a new feature is inserted
543       // create a feature
544       aFeature = std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get())->createFeature(
545         TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
546         .ToCString(), anOwner);
547       if (!aFeature) {  // somethig is wrong, most probably, the opened document has invalid structure
548         Events_Error::send("Invalid type of object in the document");
549         aLabIter.Value()->Label().ForgetAllAttributes();
550         continue;
551       }
552       // this must be before "setData" to redo the sketch line correctly
553       myFeatures.Bind(aFeatureLabel, aFeature);
554       aNewFeatures.insert(aFeature);
555       initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
556       updateHistory(aFeature);
557       aFeature->setDisabled(false); // by default created feature is enabled (this allows to recreate the results before "setCurrent" is called)
558
559       // event: model is updated
560       ModelAPI_EventCreator::get()->sendUpdated(aFeature, aCreateEvent);
561     } else {  // nothing is changed, both iterators are incremented
562       aFeature = myFeatures.Find(aFeatureLabel);
563       aKeptFeatures.insert(aFeature);
564       if (theMarkUpdated) {
565         ModelAPI_EventCreator::get()->sendUpdated(aFeature, anUpdateEvent);
566       }
567     }
568   }
569
570   // check all features are checked: if not => it was removed
571   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myFeatures);
572   while (aFIter.More()) {
573     if (aKeptFeatures.find(aFIter.Value()) == aKeptFeatures.end()
574       && aNewFeatures.find(aFIter.Value()) == aNewFeatures.end()) {
575         FeaturePtr aFeature = aFIter.Value();
576         // event: model is updated
577         //if (aFeature->isInHistory()) {
578         ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group());
579         //}
580         // results of this feature must be redisplayed (hided)
581         // redisplay also removed feature (used for sketch and AISObject)
582         ModelAPI_EventCreator::get()->sendUpdated(aFeature, aRedispEvent);
583         updateHistory(aFeature);
584         aFeature->erase();
585         // unbind after the "erase" call: on abort sketch is removes sub-objects that corrupts aFIter
586         myFeatures.UnBind(aFIter.Key());
587         // reinitialize iterator because unbind may corrupt the previous order in the map
588         aFIter.Initialize(myFeatures);
589     } else
590       aFIter.Next();
591   }
592
593   if (theUpdateReferences) {
594     synchronizeBackRefs();
595   }
596   // update results of the features (after features created because they may be connected, like sketch and sub elements)
597   // After synchronisation of back references because sketch must be set in sub-elements before "execute" by updateResults
598   std::list<FeaturePtr> aComposites; // composites must be updated after their subs (issue 360)
599   TDF_ChildIDIterator aLabIter2(featuresLabel(), TDataStd_Comment::GetID());
600   for (; aLabIter2.More(); aLabIter2.Next()) {
601     TDF_Label aFeatureLabel = aLabIter2.Value()->Label();
602     if (myFeatures.IsBound(aFeatureLabel)) {  // a new feature is inserted
603       FeaturePtr aFeature = myFeatures.Find(aFeatureLabel);
604       if (std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature).get())
605         aComposites.push_back(aFeature);
606       updateResults(aFeature);
607     }
608   }
609   std::list<FeaturePtr>::iterator aComposite = aComposites.begin();
610   for(; aComposite != aComposites.end(); aComposite++) {
611     updateResults(*aComposite);
612   }
613
614   // the synchronize should be done after updateResults in order to correct back references of updated results
615   if (theUpdateReferences) {
616     synchronizeBackRefs();
617   }
618   if (theMarkUpdated) { // this means there is no control what was modified => remove history cash
619     myHistory.clear();
620   }
621
622   anOwner->executeFeatures() = false;
623   aLoop->activateFlushes(isActive);
624
625   if (theFlush) {
626     aLoop->flush(aCreateEvent);
627     aLoop->flush(aDeleteEvent);
628     aLoop->flush(anUpdateEvent);
629     aLoop->flush(aRedispEvent);
630     aLoop->flush(aToHideEvent);
631   }
632   anOwner->executeFeatures() = true;
633 }
634
635 void Model_Objects::synchronizeBackRefs()
636 {
637   // keeps the concealed flags of result to catch the change and create created/deleted events
638   std::list<std::pair<ResultPtr, bool> > aConcealed;
639   // first cycle: erase all data about back-references
640   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myFeatures);
641   for(; aFeatures.More(); aFeatures.Next()) {
642     FeaturePtr aFeature = aFeatures.Value();
643     std::shared_ptr<Model_Data> aFData = 
644       std::dynamic_pointer_cast<Model_Data>(aFeature->data());
645     if (aFData) {
646       aFData->eraseBackReferences();
647     }
648     const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
649     std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
650     for (; aRIter != aResults.cend(); aRIter++) {
651       std::shared_ptr<Model_Data> aResData = 
652         std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
653       if (aResData) {
654         aConcealed.push_back(std::pair<ResultPtr, bool>(*aRIter, (*aRIter)->isConcealed()));
655         aResData->eraseBackReferences();
656       }
657     }
658   }
659
660   // second cycle: set new back-references: only features may have reference, iterate only them
661   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
662   for(aFeatures.Initialize(myFeatures); aFeatures.More(); aFeatures.Next()) {
663     FeaturePtr aFeature = aFeatures.Value();
664     std::shared_ptr<Model_Data> aFData = 
665       std::dynamic_pointer_cast<Model_Data>(aFeature->data());
666     if (aFData) {
667       std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
668       aFData->referencesToObjects(aRefs);
669       std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator 
670         aRefsIter = aRefs.begin();
671       for(; aRefsIter != aRefs.end(); aRefsIter++) {
672         std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
673         for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
674           if (*aRefTo) {
675             std::shared_ptr<Model_Data> aRefData = 
676               std::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
677             aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
678             // update enable/disable status: the nested status must be equal to the composite
679             CompositeFeaturePtr aComp = 
680               std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
681             if (aComp.get()) {
682               FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(*aRefTo);
683               if (aReferenced.get()) {
684                 aReferenced->setDisabled(aComp->isDisabled());
685               }
686             }
687           }
688         }
689       }
690     }
691   }
692   std::list<std::pair<ResultPtr, bool> >::iterator aCIter = aConcealed.begin();
693   for(; aCIter != aConcealed.end(); aCIter++) {
694     if (aCIter->first->isConcealed() != aCIter->second) { // somethign is changed => produce event
695       if (aCIter->second) { // was concealed become not => creation event
696         static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
697         ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, anEvent);
698       } else { // was not concealed become concealed => delete event
699         ModelAPI_EventCreator::get()->sendDeleted(myDoc, aCIter->first->groupName());
700         // redisplay for the viewer (it must be disappeared also)
701         static Events_ID EVENT_DISP = 
702           Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
703         ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, EVENT_DISP);
704       }
705     }
706   }
707 }
708
709 TDF_Label Model_Objects::resultLabel(
710   const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex) 
711 {
712   const std::shared_ptr<Model_Data>& aData = 
713     std::dynamic_pointer_cast<Model_Data>(theFeatureData);
714   return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
715 }
716
717 void Model_Objects::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
718                                  std::shared_ptr<ModelAPI_Result> theResult,
719                                  const int theResultIndex)
720 {
721   theResult->setDoc(myDoc);
722   initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS);
723   if (theResult->data()->name().empty()) {  // if was not initialized, generate event and set a name
724     std::stringstream aNewName;
725     aNewName<<theFeatureData->name();
726     if (theResultIndex > 0) // if there are several results, add unique prefix starting from second
727       aNewName<<"_"<<theResultIndex + 1;
728     theResult->data()->setName(aNewName.str());
729   }
730 }
731
732 std::shared_ptr<ModelAPI_ResultConstruction> Model_Objects::createConstruction(
733     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
734 {
735   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
736   TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
737   ObjectPtr anOldObject = object(aLab);
738   std::shared_ptr<ModelAPI_ResultConstruction> aResult;
739   if (anOldObject) {
740     aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anOldObject);
741   }
742   if (!aResult) {
743     aResult = std::shared_ptr<ModelAPI_ResultConstruction>(new Model_ResultConstruction);
744     storeResult(theFeatureData, aResult, theIndex);
745   }
746   return aResult;
747 }
748
749 std::shared_ptr<ModelAPI_ResultBody> Model_Objects::createBody(
750     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
751 {
752   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
753   TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
754   ObjectPtr anOldObject = object(aLab);
755   std::shared_ptr<ModelAPI_ResultBody> aResult;
756   if (anOldObject) {
757     aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
758   }
759   if (!aResult) {
760     aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultBody);
761     storeResult(theFeatureData, aResult, theIndex);
762   }
763   return aResult;
764 }
765
766 std::shared_ptr<ModelAPI_ResultPart> Model_Objects::createPart(
767     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
768 {
769   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
770   TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
771   ObjectPtr anOldObject = object(aLab);
772   std::shared_ptr<ModelAPI_ResultPart> aResult;
773   if (anOldObject) {
774     aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anOldObject);
775   }
776   if (!aResult) {
777     aResult = std::shared_ptr<ModelAPI_ResultPart>(new Model_ResultPart);
778     storeResult(theFeatureData, aResult, theIndex);
779   }
780   return aResult;
781 }
782
783 std::shared_ptr<ModelAPI_ResultPart> Model_Objects::copyPart(
784     const std::shared_ptr<ModelAPI_Result>& theOldPart, 
785     const std::shared_ptr<ModelAPI_ResultPart>& theOrigin, const int theIndex)
786 {
787   std::shared_ptr<ModelAPI_ResultPart> aResult;
788   if (theOldPart.get()) {
789     aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theOldPart);
790   }
791   if (!aResult) {
792     aResult = std::shared_ptr<ModelAPI_ResultPart>(new Model_ResultPart);
793     aResult->setDoc(myDoc);
794     aResult->setData(theOrigin->data());
795   }
796   return aResult;
797 }
798
799 std::shared_ptr<ModelAPI_ResultGroup> Model_Objects::createGroup(
800     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
801 {
802   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
803   TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
804   ObjectPtr anOldObject = object(aLab);
805   std::shared_ptr<ModelAPI_ResultGroup> aResult;
806   if (anOldObject) {
807     aResult = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
808   }
809   if (!aResult) {
810     aResult = std::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
811     storeResult(theFeatureData, aResult, theIndex);
812   }
813   return aResult;
814 }
815
816 std::shared_ptr<ModelAPI_ResultParameter> Model_Objects::createParameter(
817       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
818 {
819   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
820   TDataStd_Comment::Set(aLab, ModelAPI_ResultParameter::group().c_str());
821   ObjectPtr anOldObject = object(aLab);
822   std::shared_ptr<ModelAPI_ResultParameter> aResult;
823   if (anOldObject) {
824     aResult = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(anOldObject);
825   }
826   if (!aResult) {
827     aResult = std::shared_ptr<ModelAPI_ResultParameter>(new Model_ResultParameter);
828     storeResult(theFeatureData, aResult, theIndex);
829   }
830   return aResult;
831 }
832
833 std::shared_ptr<ModelAPI_Feature> Model_Objects::feature(
834     const std::shared_ptr<ModelAPI_Result>& theResult)
835 {
836   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
837   if (aData) {
838     TDF_Label aFeatureLab = aData->label().Father().Father().Father();
839     return feature(aFeatureLab);
840   }
841   return FeaturePtr();
842 }
843
844 std::string Model_Objects::featureResultGroup(FeaturePtr theFeature)
845 {
846   if (theFeature->data()->isValid()) {
847     TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
848     if (aLabIter.More()) {
849       TDF_Label anArgLab = aLabIter.Value();
850       Handle(TDataStd_Comment) aGroup;
851       if (aLabIter.Value().FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
852         return TCollection_AsciiString(aGroup->Get()).ToCString();
853       }
854     }
855   }
856   static std::string anEmpty;
857   return anEmpty; // not found
858 }
859
860 void Model_Objects::updateResults(FeaturePtr theFeature)
861 {
862   // for not persistent is will be done by parametric updater automatically
863   //if (!theFeature->isPersistentResult()) return;
864   // check the existing results and remove them if there is nothing on the label
865   std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
866   while(aResIter != theFeature->results().cend()) {
867     ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(*aResIter);
868     if (aBody.get()) {
869       if (!aBody->data()->isValid()) { 
870         // found a disappeared result => remove it
871         theFeature->eraseResultFromList(aBody);
872         // start iterate from beginning because iterator is corrupted by removing
873         aResIter = theFeature->results().cbegin();
874         continue;
875       }
876     }
877     aResIter++;
878   }
879   // it may be on undo
880   if (!theFeature->data() || !theFeature->data()->isValid() || theFeature->isDisabled())
881     return;
882   // check that results are presented on all labels
883   int aResSize = theFeature->results().size();
884   TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
885   for(; aLabIter.More(); aLabIter.Next()) {
886     // here must be GUID of the feature
887     int aResIndex = aLabIter.Value().Tag() - 1;
888     ResultPtr aNewBody;
889     if (aResSize <= aResIndex) {
890       TDF_Label anArgLab = aLabIter.Value();
891       Handle(TDataStd_Comment) aGroup;
892       if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
893         if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
894           aNewBody = createBody(theFeature->data(), aResIndex);
895         } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
896           std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex); 
897           theFeature->setResult(aNewP, aResIndex);
898           if (!aNewP->partDoc().get())
899             theFeature->execute(); // create the part result: it is better to restore the previous result if it is possible
900           break;
901         } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
902           theFeature->execute(); // construction shapes are needed for sketch solver
903           break;
904         } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
905           aNewBody = createGroup(theFeature->data(), aResIndex);
906         } else if (aGroup->Get() == ModelAPI_ResultParameter::group().c_str()) {
907           theFeature->attributeChanged("expression"); // just produce a value
908           break;
909         } else {
910           Events_Error::send(std::string("Unknown type of result is found in the document:") +
911             TCollection_AsciiString(aGroup->Get()).ToCString());
912         }
913       }
914       if (aNewBody) {
915         theFeature->setResult(aNewBody, aResIndex);
916       }
917     }
918   }
919 }
920
921 ResultPtr Model_Objects::findByName(const std::string theName)
922 {
923   NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myFeatures);
924   for(; anObjIter.More(); anObjIter.Next()) {
925     FeaturePtr& aFeature = anObjIter.ChangeValue();
926     if (!aFeature.get() || aFeature->isDisabled()) // may be on close
927       continue;
928     const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
929     std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
930     for (; aRIter != aResults.cend(); aRIter++) {
931       ResultPtr aRes = *aRIter;
932       if (aRes.get() && aRes->data() && aRes->data()->isValid() && !aRes->isDisabled() &&
933           aRes->data()->name() == theName) {
934         return aRes;
935       }
936     }
937   }
938   // not found
939   return ResultPtr();
940 }
941
942 FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, const bool theReverse)
943 {
944   std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
945   if (aData && aData->isValid()) {
946     TDF_Label aFeatureLabel = aData->label().Father();
947     Handle(TDataStd_ReferenceArray) aRefs;
948     if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
949       for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) { // iterate all existing features
950         if (aRefs->Value(a).IsEqual(aFeatureLabel)) {
951           a += theReverse ? -1 : 1;
952           if (a >= aRefs->Lower() && a <= aRefs->Upper())
953             return feature(aRefs->Value(a));
954           break; // finish iiteration: it's last feature
955         }
956       }
957     }
958   }
959   return FeaturePtr(); // not found, last, or something is wrong
960 }
961
962 FeaturePtr Model_Objects::firstFeature()
963 {
964   Handle(TDataStd_ReferenceArray) aRefs;
965   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
966     return feature(aRefs->Value(aRefs->Lower()));
967   }
968   return FeaturePtr(); // no features at all
969 }
970
971 FeaturePtr Model_Objects::lastFeature()
972 {
973   Handle(TDataStd_ReferenceArray) aRefs;
974   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
975     return feature(aRefs->Value(aRefs->Upper()));
976   }
977   return FeaturePtr(); // no features at all
978 }
979
980 std::list<std::shared_ptr<ModelAPI_Feature> > Model_Objects::allFeatures()
981 {
982   std::list<std::shared_ptr<ModelAPI_Feature> > aResult;
983   Handle(TDataStd_ReferenceArray) aRefs;
984   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
985     for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
986       FeaturePtr aFeature = feature(aRefs->Value(a));
987       if (aFeature.get())
988         aResult.push_back(aFeature);
989     }
990   }
991   return aResult;
992 }
993
994 int Model_Objects::numInternalFeatures()
995 {
996   Handle(TDataStd_ReferenceArray) aRefs;
997   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
998     return aRefs->Upper() - aRefs->Lower() + 1;
999   }
1000   return 0; // invalid
1001 }
1002
1003 std::shared_ptr<ModelAPI_Feature> Model_Objects::internalFeature(const int theIndex)
1004 {
1005   Handle(TDataStd_ReferenceArray) aRefs;
1006   if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
1007     return feature(aRefs->Value(aRefs->Lower() + theIndex));
1008   }
1009   return FeaturePtr(); // invalid
1010 }
1011
1012 Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
1013 {
1014   return TDF_LabelMapHasher::HashCode(theLab, theUpper);
1015
1016 }
1017 Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2)
1018 {
1019   return TDF_LabelMapHasher::IsEqual(theLab1, theLab2);
1020 }