]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx
Salome HOME
#19765 EDF 21730 - long time to load med file file with huge amount of groups
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_UseCaseBuilder.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : SALOMEDSImpl_UseCaseBuilder.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26
27 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
28 #include "SALOMEDSImpl_SObject.hxx"
29 #include "SALOMEDSImpl_SComponent.hxx"
30 #include "SALOMEDSImpl_Study.hxx"
31 #include "SALOMEDSImpl_Attributes.hxx"
32
33 #include "DF_ChildIterator.hxx"
34
35 #include <list>
36
37 #define USE_CASE_LABEL_TAG           2
38 #define USE_CASE_GUID                "AA43BB12-D9CD-11d6-945D-0050DA506788"
39
40 namespace {
41   // comparator to sort use case nodes in ascending order
42   struct AscSortSOs {
43     bool operator()( SALOMEDSImpl_SObject firstSO, SALOMEDSImpl_SObject secondSO ) const {
44       std::string firstName, secondName;
45       SALOMEDSImpl_SObject refSO;
46       firstSO.ReferencedObject(refSO) ?
47         firstName = refSO.GetName() :
48         firstName = firstSO.GetName();
49       secondSO.ReferencedObject(refSO) ?
50         secondName = refSO.GetName() :
51         secondName = secondSO.GetName();
52       return firstName < secondName;
53     }
54   };
55
56   // comparator to sort use case nodes in descending order
57   struct DescSortSOs {
58     bool operator()( SALOMEDSImpl_SObject firstSO, SALOMEDSImpl_SObject secondSO ) const {
59       std::string firstName, secondName;
60       SALOMEDSImpl_SObject refSO;
61       firstSO.ReferencedObject(refSO) ?
62         firstName = refSO.GetName() :
63         firstName = firstSO.GetName();
64       secondSO.ReferencedObject(refSO) ?
65         secondName = refSO.GetName() :
66         secondName = secondSO.GetName();
67       return firstName > secondName;
68     }
69   };
70 }
71
72 //============================================================================
73 /*! Function : constructor
74  *  Purpose  :
75  */
76 //============================================================================
77 SALOMEDSImpl_UseCaseBuilder::SALOMEDSImpl_UseCaseBuilder(DF_Document* theDocument)
78   :_doc(theDocument), _lastChild(0), _childIndex(-1)
79 {
80   if(!_doc) return;
81   
82   DF_Label aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); //Iterate all use cases
83   if(!(_root = (SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(std::string(USE_CASE_GUID)))) {
84     _root = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, std::string(USE_CASE_GUID));
85   }
86  
87   SALOMEDSImpl_AttributeReference* aRef = NULL;
88   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
89     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label());  
90   }  
91
92   if(!aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())) { 
93     SALOMEDSImpl_AttributeName::Set(aLabel, "Use cases"); 
94   }  
95 }
96
97 //============================================================================
98 /*! Function : destructor
99  *  Purpose  :
100  */
101 //============================================================================
102 SALOMEDSImpl_UseCaseBuilder::~SALOMEDSImpl_UseCaseBuilder()
103 {
104 }
105
106
107 //============================================================================
108 /*! Function : Append
109  *  Purpose  : 
110  */
111 //============================================================================
112 bool SALOMEDSImpl_UseCaseBuilder::Append(const SALOMEDSImpl_SObject& theObject)
113 {
114   if(!_root || !theObject) return false;
115
116   DF_Label aLabel = theObject.GetLabel();
117   if(aLabel.IsNull()) return false;
118
119   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
120   SALOMEDSImpl_AttributeTreeNode* aCurrentNode = NULL;
121   aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID());
122   aNode->Remove();
123
124   SALOMEDSImpl_AttributeReference* aRef;
125   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
126     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label());  
127   }  
128
129   DF_Label aCurrent = aRef->Get();
130   if(aCurrent.IsNull() || !(aCurrentNode=(SALOMEDSImpl_AttributeTreeNode*)aCurrent.FindAttribute(_root->ID())))
131     aCurrentNode = _root;
132
133   aCurrentNode->Append(aNode, &_childIndex);
134   _lastChild = aNode;
135
136   // Mantis issue 0020136: Drag&Drop in OB
137   SALOMEDSImpl_Study::GetStudyImpl(theObject.GetLabel())->addSO_Notification(theObject);
138
139   return true;
140 }
141
142 //============================================================================
143 /*! Function : Remove
144  *  Purpose  :
145  */
146 //============================================================================
147 bool SALOMEDSImpl_UseCaseBuilder::Remove(const SALOMEDSImpl_SObject& theObject)
148 {
149   if(!_root || !theObject) return false;
150
151   DF_Label aLabel = theObject.GetLabel();
152   if(aLabel.IsNull()) return false;
153
154   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
155   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false;
156
157   if ( _lastChild && aNode->GetFather() == _lastChild->GetFather() )
158     _lastChild = 0;
159
160   aNode->Remove();
161
162   std::vector<DF_Attribute*> aList;
163   aList.push_back(aNode);
164
165   SALOMEDSImpl_AttributeReference* aRef = NULL;
166   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
167     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label());
168   }
169
170   DF_Label aCurrent = aRef->Get();
171
172   SALOMEDSImpl_ChildNodeIterator aChildItr(aNode, true);
173   for(; aChildItr.More(); aChildItr.Next())
174     aList.push_back(aChildItr.Value());
175
176   for(int i = 0, len = aList.size(); i<len; i++) {
177     if(aList[i]->Label() ==  aCurrent) { //The current node is removed
178       aRef->Set(_root->Label()); //Reset the current node to the root
179     }
180     aList[i]->Label().ForgetAttribute(_root->ID());
181   }
182
183   return true;
184 }
185
186
187 //============================================================================
188 /*! Function : AppendTo
189  *  Purpose  :
190  */
191 //============================================================================
192 bool SALOMEDSImpl_UseCaseBuilder::AppendTo(const SALOMEDSImpl_SObject& theFather, 
193                                            const SALOMEDSImpl_SObject& theObject)
194 {
195   if(!_root || !theFather || !theObject) return false;
196
197   DF_Label aFatherLabel = theFather.GetLabel(), aLabel = theObject.GetLabel();
198   if(aFatherLabel == aLabel) return false;
199
200   SALOMEDSImpl_AttributeTreeNode *aFather = NULL, *aNode = NULL;
201   
202   if(aFatherLabel.IsNull()) return false;
203   if(!(aFather=(SALOMEDSImpl_AttributeTreeNode*)aFatherLabel.FindAttribute(_root->ID()))) return false;
204
205   if(aLabel.IsNull()) return false;
206   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) {
207     aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID());
208   }
209
210   if ( aNode == _lastChild && !_lastChild->HasNext() && _lastChild->GetFather() == aFather )
211     return true; // aNode is already the last child
212
213   aNode->Remove();
214
215   bool ret = true;
216   if ( _lastChild && _lastChild->GetFather() == aFather &&
217        !_lastChild->HasNext() ) // _lastChild is the last under aFather
218   {
219     _lastChild->InsertAfter( aNode );
220     _lastChild = aNode;
221     ++_childIndex;
222   }
223   else
224   {
225     ret = aFather->Append(aNode, &_childIndex);
226     _lastChild  = aNode;
227   }
228
229   // Mantis issue 0020136: Drag&Drop in OB
230   SALOMEDSImpl_Study::GetStudyImpl(theObject.GetLabel())->addSO_Notification(theObject);
231
232   return ret;
233 }
234
235 //============================================================================
236 /*! Function : GetIndexInFather
237  *  Purpose  :
238  */
239 //============================================================================
240 int SALOMEDSImpl_UseCaseBuilder::GetIndexInFather(const SALOMEDSImpl_SObject& theFather, 
241                                                   const SALOMEDSImpl_SObject& theObject)
242 {
243   int index = -1;
244   if(!_root || !theFather || !theObject) return index;
245
246   DF_Label aFatherLabel = theFather.GetLabel(), aLabel = theObject.GetLabel();
247   if(aFatherLabel == aLabel) return index;
248
249   SALOMEDSImpl_AttributeTreeNode *aFather = NULL, *aNode = NULL;
250   
251   if(aFatherLabel.IsNull()) return index;
252   if(!(aFather=(SALOMEDSImpl_AttributeTreeNode*)aFatherLabel.FindAttribute(_root->ID()))) return index;
253
254   if(aLabel.IsNull()) return index;
255   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) {
256     aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID());
257   }
258
259   if ( _lastChild && _lastChild->GetFather() == aFather )
260   {
261     if ( aNode == _lastChild )
262       index = _childIndex;
263     else if ( aNode == _lastChild->GetPrevious())
264       index = _childIndex - 1;
265     else if ( aNode == _lastChild->GetNext())
266     {
267       index = ++_childIndex;
268       _lastChild = aNode;
269     }
270   }
271
272   if ( index < 0 )
273   {
274     SALOMEDSImpl_AttributeTreeNode* Last = aFather->GetFirst();
275     for ( index = 0; Last && Last->HasNext(); ++index )
276     {
277       Last = Last->GetNext();
278       if ( aNode == Last )
279         break;
280     }
281     if ( Last != aNode )
282       index = -1;
283     else if ( !Last->HasNext() )
284     {
285       _lastChild = Last;
286       _childIndex = index;
287     }
288   }
289
290   return index;
291 }
292
293 //============================================================================
294 /*! Function : InsertBefore
295  *  Purpose  :
296  */
297 //============================================================================
298 bool SALOMEDSImpl_UseCaseBuilder::InsertBefore(const SALOMEDSImpl_SObject& theFirst,
299                                                const SALOMEDSImpl_SObject& theNext)
300 {
301   if(!_root || !theFirst || !theNext) return false;
302
303   DF_Label aFirstLabel = theFirst.GetLabel(), aLabel= theNext.GetLabel();
304   if(aFirstLabel == aLabel) return false;
305
306   SALOMEDSImpl_AttributeTreeNode *aFirstNode = NULL, *aNode = NULL;
307
308   if(aFirstLabel.IsNull()) return false;
309   if((aFirstNode=(SALOMEDSImpl_AttributeTreeNode*)aFirstLabel.FindAttribute(_root->ID()))) {
310     aFirstNode->Remove();
311     aFirstLabel.ForgetAttribute(aFirstNode->ID());
312   }
313
314   aFirstNode = SALOMEDSImpl_AttributeTreeNode::Set(aFirstLabel, _root->ID());
315
316   if(aLabel.IsNull()) return false;
317   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false;
318
319   aFirstNode->Remove();
320
321   bool ret = aNode->InsertBefore(aFirstNode);
322
323   if ( _lastChild && _lastChild->GetFather() == aNode->GetFather() )
324   {
325     if ( aNode == _lastChild )
326       ++_childIndex;
327     else
328       _lastChild = 0;
329   }
330
331   // Mantis issue 0020136: Drag&Drop in OB
332   SALOMEDSImpl_Study::GetStudyImpl(theFirst.GetLabel())->addSO_Notification(theFirst);
333
334   return ret;
335 }
336
337
338 //============================================================================
339 /*! Function : SetCurrentObject
340  *  Purpose  :
341  */
342 //============================================================================
343 bool SALOMEDSImpl_UseCaseBuilder::SetCurrentObject(const SALOMEDSImpl_SObject& theObject)
344 {
345   if(!_root || !theObject) return false;
346
347   DF_Label aLabel = theObject.GetLabel();
348   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
349   if(aLabel.IsNull()) return false;
350   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false;
351
352   SALOMEDSImpl_AttributeReference* aRef = NULL;
353   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
354     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), aNode->Label());  
355   }
356   
357   aRef->Set(aNode->Label());
358
359   return true;
360 }
361
362 //============================================================================
363 /*! Function : SetRootCurrent
364  *  Purpose  :
365  */
366 //============================================================================
367 bool SALOMEDSImpl_UseCaseBuilder::SetRootCurrent()
368 {
369   if(!_root) return false;
370    
371   SALOMEDSImpl_AttributeReference* aRef = NULL;
372   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) 
373     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label());  
374
375   aRef->Set(_root->Label());
376   return true;
377 }
378
379 //============================================================================
380 /*! Function : HasChildren
381  *  Purpose  :
382  */
383 //============================================================================
384 bool SALOMEDSImpl_UseCaseBuilder::HasChildren(const SALOMEDSImpl_SObject& theObject)
385 {
386   if(!_root) return false;
387
388   DF_Label aLabel;
389   if (!theObject) aLabel = _root->Label();
390   else 
391     aLabel = theObject.GetLabel(); 
392   if(aLabel.IsNull()) return false;
393
394   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
395   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false; 
396   
397   return (aNode->GetFirst());
398 }
399
400 //============================================================================
401 /*! Function : SortChildren
402  *  Purpose  :
403  */
404 //============================================================================
405 bool SALOMEDSImpl_UseCaseBuilder::SortChildren(const SALOMEDSImpl_SObject& theObject, bool theAscendingOrder)
406 {
407   if(!_root) return false;
408
409   DF_Label aLabel;
410   if (!theObject) aLabel = _root->Label();
411   else 
412     aLabel = theObject.GetLabel(); 
413   if(aLabel.IsNull()) return false;
414
415   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
416   if (!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false;
417
418   std::list<SALOMEDSImpl_SObject> aRefSOs;
419   std::list<SALOMEDSImpl_SObject> aNodeSOs;
420   for ( SALOMEDSImpl_AttributeTreeNode* aChildNode=aNode->GetFirst(); aChildNode; aChildNode=aChildNode->GetNext() ) {
421     if ( SALOMEDSImpl_SObject aSO = SALOMEDSImpl_Study::SObject( aChildNode->Label() ) ) {
422       if ( aChildNode->FindAttribute( SALOMEDSImpl_AttributeReference::GetID() ) )
423         aRefSOs.push_back( aSO );      
424       else
425         aNodeSOs.push_back( aSO );
426     }
427   }
428   if ( aRefSOs.empty() && aNodeSOs.empty() ) return false;
429
430   //sort items by names in ascending/descending order
431   _lastChild = 0;
432   std::list<SALOMEDSImpl_SObject>::iterator it;  
433   if ( !aRefSOs.empty() ) {
434     theAscendingOrder ? aRefSOs.sort( AscSortSOs() ) : aRefSOs.sort( DescSortSOs() );
435     for ( it = aRefSOs.begin(); it != aRefSOs.end(); ++it ) {
436       AppendTo( theObject, *it );
437     }
438   }  
439   if ( !aNodeSOs.empty() ) {
440     theAscendingOrder ? aNodeSOs.sort( AscSortSOs() ) : aNodeSOs.sort( DescSortSOs() );
441     for ( it = aNodeSOs.begin(); it != aNodeSOs.end(); ++it ) {
442       AppendTo( theObject, *it );
443     }
444   }
445
446   return true;
447 }
448
449 //============================================================================
450 /*! Function : GetFather
451  *  Purpose  :
452  */
453 //============================================================================
454 SALOMEDSImpl_SObject SALOMEDSImpl_UseCaseBuilder::GetFather(const SALOMEDSImpl_SObject& theObject)
455 {
456   SALOMEDSImpl_SObject so;
457   if (!_root || !theObject) return so;
458
459   DF_Label aLabel = theObject.GetLabel(); 
460   if (aLabel.IsNull()) return so;
461
462   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
463   if (!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return so; 
464
465   SALOMEDSImpl_AttributeTreeNode* aFatherNode = aNode->GetFather();
466   if (!aFatherNode) return so;
467
468   return aFatherNode->GetSObject();
469 }
470
471 //============================================================================
472 /*! Function : SetName
473  *  Purpose  :
474  */
475 //============================================================================
476 bool SALOMEDSImpl_UseCaseBuilder::SetName(const std::string& theName) {
477   if(!_root) return false;
478
479   SALOMEDSImpl_AttributeName* aNameAttrib = NULL;
480
481   if (!(aNameAttrib=(SALOMEDSImpl_AttributeName*)_root->FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
482     aNameAttrib = SALOMEDSImpl_AttributeName::Set(_root->Label(), theName);
483      
484   aNameAttrib->SetValue(theName);
485     
486   return true;
487 }
488
489
490 //============================================================================
491 /*! Function : GetCurrentObject
492  *  Purpose  :
493  */
494 //============================================================================
495 SALOMEDSImpl_SObject SALOMEDSImpl_UseCaseBuilder::GetCurrentObject()
496 {
497   SALOMEDSImpl_SObject so;
498   if(!_root) return so;
499
500   SALOMEDSImpl_AttributeReference* aRef = NULL;
501   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
502     aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label());  
503   }  
504   
505   DF_Label aCurrent = aRef->Get();  
506   if(aCurrent.IsNull()) return so;
507
508   return SALOMEDSImpl_Study::SObject(aCurrent);
509 }
510
511 //============================================================================
512 /*! Function : GetName
513  *  Purpose  :
514  */
515 //============================================================================
516 std::string SALOMEDSImpl_UseCaseBuilder::GetName() 
517 {
518   std::string aString;
519   if(!_root) return aString;
520   
521   SALOMEDSImpl_AttributeName* aName = NULL;
522   if (!(aName=(SALOMEDSImpl_AttributeName*)_root->FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) return aString;
523   return aName->Value();
524 }
525
526 //============================================================================ 
527 /*! Function :  IsUseCase
528  *  Purpose  :  
529  */ 
530 //============================================================================ 
531 bool SALOMEDSImpl_UseCaseBuilder::IsUseCase(const SALOMEDSImpl_SObject& theObject)
532 {
533   if(!theObject) return false;
534   DF_Label aFather, aLabel = theObject.GetLabel(); 
535   aFather = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG);
536   if(aLabel.Father() == aFather) return true;
537   return false;
538 }
539
540 //============================================================================ 
541 /*! Function :  IsUseCaseNode
542  *  Purpose  :  
543  */ 
544 //============================================================================ 
545 bool SALOMEDSImpl_UseCaseBuilder::IsUseCaseNode(const SALOMEDSImpl_SObject& theObject)
546 {
547   if(!_root) return false;
548
549   DF_Label aLabel;
550   if (!theObject) aLabel = _root->Label();
551   else 
552     aLabel = theObject.GetLabel(); 
553   if(aLabel.IsNull()) return false;
554
555   SALOMEDSImpl_AttributeTreeNode* aNode = NULL;
556   if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) return false; 
557   
558   return true;
559 }
560
561 //============================================================================ 
562 /*! Function : NewUseCase 
563  *  Purpose  :  
564  */ 
565 //============================================================================ 
566 SALOMEDSImpl_SObject SALOMEDSImpl_UseCaseBuilder::AddUseCase(const std::string& theName)
567 {
568   std::string aBasicGUID(USE_CASE_GUID);
569
570   //Create a use cases structure if it not exists 
571
572   SALOMEDSImpl_AttributeTreeNode *aFatherNode = NULL, *aNode = NULL;
573   SALOMEDSImpl_AttributeInteger* anInteger = NULL;
574   SALOMEDSImpl_AttributeReference* aRef = NULL;
575
576   DF_Label aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG);
577
578   if(!(aRef=(SALOMEDSImpl_AttributeReference*)_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
579     aRef = SALOMEDSImpl_AttributeReference::Set(aLabel, aLabel);
580   }
581  
582   if(!(aFatherNode=(SALOMEDSImpl_AttributeTreeNode*)aRef->Get().FindAttribute(aBasicGUID))) {
583     aFatherNode = SALOMEDSImpl_AttributeTreeNode::Set(aRef->Get(), aBasicGUID);
584   }
585
586   if(!(anInteger=(SALOMEDSImpl_AttributeInteger*)_root->FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
587     anInteger = SALOMEDSImpl_AttributeInteger::Set(aLabel, 0);
588   }    
589
590   //Create a new use case
591   anInteger->SetValue(anInteger->Value()+1);
592   DF_Label aChild = aLabel.FindChild(anInteger->Value());
593   aNode = SALOMEDSImpl_AttributeTreeNode::Set(aChild, aBasicGUID);
594   aNode->Remove();
595   aFatherNode->Append(aNode);
596   SALOMEDSImpl_AttributeName::Set(aChild, theName);
597
598   return SALOMEDSImpl_Study::SObject(aChild);
599 }
600
601 //============================================================================
602 /*! Function : GetUseCaseIterator
603  *  Purpose  : Creates a new UseCase iterator, if anObject is null all use cases are iterated 
604  */
605 //============================================================================
606 SALOMEDSImpl_UseCaseIterator
607 SALOMEDSImpl_UseCaseBuilder::GetUseCaseIterator(const SALOMEDSImpl_SObject& theObject) 
608 {
609   DF_Label aLabel;
610
611   if(theObject) {
612     aLabel = theObject.GetLabel(); //Iterate only sub tree in the use case
613   }
614   else {
615     aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); //Iterate all use cases
616   }
617
618   return SALOMEDSImpl_UseCaseIterator(aLabel, USE_CASE_GUID, false); 
619 }
620
621
622 SALOMEDSImpl_SObject SALOMEDSImpl_UseCaseBuilder::GetSObject(const std::string& theEntry)
623 {
624   DF_Label L = DF_Label::Label(_root->Label(), theEntry);
625   return SALOMEDSImpl_Study::SObject(L);    
626 }