Salome HOME
8196df50b23e9ef69649682a880defa81670a9f3
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
1 // Copyright (C) 2007-2013  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.
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 #include "HYDROGUI_DataModel.h"
24
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28
29 #include <HYDROData_Bathymetry.h>
30 #include <HYDROData_CalculationCase.h>
31 #include <HYDROData_Document.h>
32 #include <HYDROData_Image.h>
33 #include <HYDROData_ImmersibleZone.h>
34 #include <HYDROData_Iterator.h>
35 #include <HYDROData_Polyline.h>
36 #include <HYDROData_VisualState.h>
37 #include <HYDROData_Region.h>
38 #include <HYDROData_Zone.h>
39
40 #include <CAM_Application.h>
41 #include <CAM_DataObject.h>
42 #include <CAM_Module.h>
43 #include <CAM_Study.h>
44
45 #include <LightApp_Application.h>
46 #include <LightApp_DataObject.h>
47 #include <LightApp_Study.h>
48
49 #include <SUIT_DataObject.h>
50 #include <SUIT_DataBrowser.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Study.h>
53 #include <SUIT_Tools.h>
54
55 #include <HYDROData_Document.h>
56
57 #include <TDF_Delta.hxx>
58 #include <TDF_ListIteratorOfDeltaList.hxx>
59
60 #include <QApplication>
61 #include <QDir>
62
63 static HYDROData_SequenceOfObjects myCopyingObjects;
64
65 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
66 : LightApp_DataModel( theModule )
67 {
68   update( module()->application()->activeStudy()->id() );
69 }
70
71 HYDROGUI_DataModel::~HYDROGUI_DataModel()
72 {
73 }
74
75 bool HYDROGUI_DataModel::open( const QString& theURL,
76                                CAM_Study* theStudy,
77                                QStringList theFileList )
78 {
79   LightApp_DataModel::open( theURL, theStudy, theFileList );
80   const int aStudyId = theStudy->id();
81
82   Data_DocError res = DocError_UnknownProblem;
83   if( theFileList.count() == 2 )
84   {
85     QString aTmpDir = theFileList[0];
86     QString aFileName = theFileList[1];
87
88     myStudyURL = theURL;
89     QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName;
90
91     try
92     {
93       res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId );
94     }
95     catch(...)
96     {
97       res = DocError_UnknownProblem;
98     }
99     if( res != DocError_OK )
100     {
101       module()->application()->putInfo( tr( "LOAD_ERROR" ) );
102       return false;
103     }
104   }
105
106   // if the document open was successful, the data model update happens
107   // in the set mode of the module
108   if( res == DocError_OK )
109     update( aStudyId );
110
111   return true;
112 }
113
114 bool HYDROGUI_DataModel::save( QStringList& theFileList )
115 {
116   if( !module()->application()->activeStudy() )
117     return false;
118   
119   LightApp_DataModel::save( theFileList );
120
121   QString aTmpDir;
122   QString aFileName;
123   SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
124   bool isMultiFile = false;
125   if( resMgr )
126     isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
127
128   // save data to temporary files
129   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy() );
130   aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str();
131   aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
132
133   QString aFullPath = aTmpDir + aFileName;
134   Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
135   if( res != DocError_OK )
136   {
137     module()->application()->putInfo( tr( "SAVE_ERROR" ) );
138     return false;
139   }
140
141   theFileList.append( aTmpDir );
142   theFileList.append( aFileName );
143
144   return true;
145 }
146
147 bool HYDROGUI_DataModel::saveAs( const QString& theURL,
148                                  CAM_Study*,
149                                  QStringList& theFileList )
150 {
151   myStudyURL = theURL;
152   return save( theFileList );
153 }
154
155 bool HYDROGUI_DataModel::close()
156 {
157   return true;
158 }
159
160 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
161                                      CAM_Study*     theStudy,
162                                      bool           isMultiFile,
163                                      QStringList&   theListOfFiles )
164 {
165   LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
166
167   int aStudyId = theStudy->id();
168
169   LightApp_Study* aStudy = ::qobject_cast<LightApp_Study*>( theStudy );
170   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
171   if ( aDocument.IsNull() || !aStudy )
172     return false;
173
174   QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str();
175   aFileToExport += QString( QDir::separator() ) + "HYDRO.py";
176
177   bool aRes = aDocument->DumpToPython( aFileToExport );
178
179   if ( aRes )
180   {
181     theListOfFiles.append( aFileToExport );
182   }
183
184   return aRes;
185 }
186
187 bool HYDROGUI_DataModel::isModified() const
188 {
189   return getDocument()->IsModified();
190 }
191
192 bool HYDROGUI_DataModel::isSaved() const
193 {
194   return true;
195 }
196
197 void HYDROGUI_DataModel::update( const int theStudyId )
198 {
199   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
200   if( !anApp )
201     return;
202
203   SUIT_DataObject* aStudyRoot = anApp->activeStudy()->root();
204   if( !aStudyRoot )
205     return;
206
207   // create root object if not exist
208   CAM_DataObject* aRootObj = root();
209   if( !aRootObj )
210     aRootObj = createRootModuleObject( aStudyRoot );
211
212   if( !aRootObj )
213     return;
214
215   DataObjectList aList;
216   aRootObj->children( aList );
217   QListIterator<SUIT_DataObject*> anIter( aList );
218   while( anIter.hasNext() )
219     removeChild( aRootObj, anIter.next() );
220
221   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
222   if( aDocument.IsNull() )
223     return;
224
225   LightApp_DataObject* anImageRootObj = createObject( aRootObj, partitionName( KIND_IMAGE ) );
226
227   HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
228   for( ; anIterator.More(); anIterator.Next() )
229   {
230     Handle(HYDROData_Image) anImageObj =
231       Handle(HYDROData_Image)::DownCast( anIterator.Current() );
232     if( !anImageObj.IsNull() )
233       createObject( anImageRootObj, anImageObj );
234   }
235
236   LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) );
237
238   anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
239   for( ; anIterator.More(); anIterator.Next() )
240   {
241     Handle(HYDROData_Bathymetry) aBathymetryObj =
242       Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );
243     if( !aBathymetryObj.IsNull() )
244       createObject( aBathymetryRootObj, aBathymetryObj );
245   }
246
247   LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) );
248
249   anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
250   for( ; anIterator.More(); anIterator.Next() )
251   {
252     Handle(HYDROData_Polyline) aPolylineObj =
253       Handle(HYDROData_Polyline)::DownCast( anIterator.Current() );
254     if( !aPolylineObj.IsNull() )
255       createObject( aPolylineRootObj, aPolylineObj );
256   }
257
258   LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_IMMERSIBLE_ZONE ) );
259
260   anIterator = HYDROData_Iterator( aDocument, KIND_IMMERSIBLE_ZONE );
261   for( ; anIterator.More(); anIterator.Next() )
262   {
263     Handle(HYDROData_ImmersibleZone) aZoneObj =
264       Handle(HYDROData_ImmersibleZone)::DownCast( anIterator.Current() );
265     if( !aZoneObj.IsNull() )
266       createObject( aZonesRootObj, aZoneObj );
267   }
268
269   LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) );
270
271   anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION );
272   for( ; anIterator.More(); anIterator.Next() )
273   {
274     Handle(HYDROData_CalculationCase) aCalculObj =
275       Handle(HYDROData_CalculationCase)::DownCast( anIterator.Current() );
276     if( !aCalculObj.IsNull() )
277       createObject( aCalculRootObj, aCalculObj );
278   }
279
280   LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) );
281
282   anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
283   for( ; anIterator.More(); anIterator.Next() )
284   {
285     Handle(HYDROData_VisualState) aVisualStateObj =
286       Handle(HYDROData_VisualState)::DownCast( anIterator.Current() );
287     if( !aVisualStateObj.IsNull() )
288       createObject( aVisualStateRootObj, aVisualStateObj );
289   }
290
291   if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
292   {
293     anObjectBrowser->setAutoOpenLevel( 3 );
294     anObjectBrowser->openLevels();
295   }
296 }
297
298 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
299 {
300   return NULL; // to do if necessary
301 }
302
303 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
304 {
305   return NULL; // to do if necessary
306 }
307
308 SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
309 {
310   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
311   return anApp ? anApp->findObject( theEntry ) : 0;
312 }
313
314 void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
315                                  LightApp_Study* theStudy )
316 {
317   if( !theStudy )
318     theStudy = dynamic_cast<LightApp_Study*>( module()->application()->activeStudy()) ;
319   if( theStudy )
320     update( theStudy->id() );
321 }
322
323 CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent )
324 {
325   CAM_DataObject* aRootObj = createModuleObject( theParent );
326   setRoot( aRootObj );
327   return aRootObj;
328 }
329
330 void HYDROGUI_DataModel::updateModel()
331 {
332   HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
333   if( aModule )
334     update( aModule->getStudyId() );
335 }
336
337 Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
338                                                             const ObjectKind theObjectKind )
339 {
340   QString anEntry = theEntry;
341   if( anEntry.indexOf( "_" ) != -1 ) // reference object
342     anEntry = anEntry.section( "_", -1 );
343
344   Handle(HYDROData_Document) aDocument = getDocument();
345   if( !aDocument.IsNull() )
346   {
347     HYDROData_Iterator anIterator( aDocument, theObjectKind );
348     for( ; anIterator.More(); anIterator.Next() )
349     {
350       Handle(HYDROData_Entity) anObject = anIterator.Current();
351       if( !anObject.IsNull() )
352       {
353         QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
354         if( anEntryRef == anEntry )
355           return anObject;
356       }
357     }
358   }
359   return NULL;
360 }
361
362 bool HYDROGUI_DataModel::canUndo() const
363 {
364   return getDocument()->CanUndo();
365 }
366
367 bool HYDROGUI_DataModel::canRedo() const
368 {
369   return getDocument()->CanRedo();
370 }
371
372 QStringList HYDROGUI_DataModel::undoNames() const
373 {
374   QStringList aNames;
375   for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
376     aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
377   return aNames;
378 }
379
380 QStringList HYDROGUI_DataModel::redoNames() const
381 {
382   QStringList aNames;
383   for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
384     aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
385   return aNames;
386 }
387
388 void HYDROGUI_DataModel::clearUndos()
389 {
390   getDocument()->ClearUndos();
391 }
392
393 void HYDROGUI_DataModel::clearRedos()
394 {
395   getDocument()->ClearRedos();
396 }
397
398 bool HYDROGUI_DataModel::undo()
399 {
400   try 
401   {
402     getDocument()->Undo();
403   }
404   catch ( Standard_Failure )
405   {
406     return false;
407   }
408   return true;
409 }
410
411 bool HYDROGUI_DataModel::redo()
412 {
413   try 
414   {
415     getDocument()->Redo();
416   }
417   catch ( Standard_Failure )
418   {
419     return false;
420   }
421   return true;
422 }
423
424 bool HYDROGUI_DataModel::canCopy()
425 {
426   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
427   if( aSeq.Length() != 1 )
428     return false;
429
430   Handle(HYDROData_Entity) anObject = aSeq.First();
431   if( anObject.IsNull() )
432     return false;
433
434   ObjectKind aKind = anObject->GetKind();
435   if( aKind == KIND_IMAGE ||
436       aKind == KIND_POLYLINE ||
437       aKind == KIND_CALCULATION )
438     return true;
439
440   return false;
441 }
442
443 bool HYDROGUI_DataModel::canPaste()
444 {
445   for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
446   {
447     Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
448     if( !anObject.IsNull() && !anObject->IsRemoved() )
449       return true;
450   }
451   return false;
452 }
453
454 bool HYDROGUI_DataModel::copy()
455 {
456   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
457   changeCopyingObjects( aSeq );
458   return true;
459 }
460
461 bool HYDROGUI_DataModel::paste()
462 {
463   bool anIsChanged = false;
464   for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
465   {
466     Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
467     if( !anObject.IsNull() && !anObject->IsRemoved() )
468     {
469       ObjectKind aKind = anObject->GetKind();
470       Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
471       if( !aClone.IsNull() )
472       {
473         anObject->CopyTo( aClone );
474         anIsChanged = true;
475
476         // generate a new unique name for the clone object:
477         // case 1: Image_1 -> Image_2
478         // case 2: ImageObj -> ImageObj_1
479         QString aName = aClone->GetName();
480         QString aPrefix = aName;
481         if( aName.contains( '_' ) ) // case 1
482         {
483           QString aSuffix = aName.section( '_', -1 );
484           bool anIsInteger = false;
485           aSuffix.toInt( &anIsInteger );
486           if( anIsInteger )
487             aPrefix = aName.section( '_', 0, -2 );
488         }
489         else // case 2
490           aPrefix = aName;
491         aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
492         aClone->SetName( aName );
493       }
494     }
495   }
496   return anIsChanged;
497 }
498
499 void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
500 {
501   myCopyingObjects.Assign( theSeq );
502 }
503
504 QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
505 {
506   switch( theObjectKind )
507   {
508     case KIND_IMAGE:           return "IMAGES";
509     case KIND_POLYLINE:        return "POLYLINES";
510     case KIND_VISUAL_STATE:    return "VISUAL_STATES";
511     case KIND_BATHYMETRY:      return "BATHYMETRIES";
512     case KIND_CALCULATION:     return "CALCULATION_CASES";
513     case KIND_IMMERSIBLE_ZONE: return "IMMERSIBLE_ZONES";
514     default: break;
515   }
516   return QString();
517 }
518
519 Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
520 {
521   int aStudyId = module()->application()->activeStudy()->id();
522   return HYDROData_Document::Document( aStudyId );
523 }
524
525 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*         theParent,
526                                                        Handle(HYDROData_Entity) theModelObject,
527                                                        const QString&           theParentEntry,
528                                                        const bool               theIsBuildTree )
529 {
530   HYDROGUI_DataObject* aResObj = 
531     new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
532   
533   if ( theIsBuildTree )
534   {
535     buildObjectTree( theParent, aResObj, theParentEntry );
536   }
537
538   return aResObj;
539 }
540
541 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
542                                                        const QString&   theName,
543                                                        const QString&   theParentEntry )
544 {
545   return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
546 }
547
548 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
549                                           SUIT_DataObject* theObject,
550                                           const QString&   theParentEntry )
551 {
552   HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
553   if ( !aGuiObj )
554     return;
555
556   Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject();
557   if ( aDataObj.IsNull() )
558     return;
559
560   ObjectKind anObjectKind = aDataObj->GetKind();
561
562   if ( anObjectKind == KIND_IMAGE )
563   {
564     Handle(HYDROData_Image) anImageObj =
565       Handle(HYDROData_Image)::DownCast( aDataObj );
566     for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
567     {
568       Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex );
569       if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
570         createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
571     }
572   }
573   else if ( anObjectKind == KIND_IMMERSIBLE_ZONE )
574   {
575     Handle(HYDROData_ImmersibleZone) aZoneObj =
576       Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj );
577
578     LightApp_DataObject* aPolylineSect = 
579       createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
580
581     Handle(HYDROData_Polyline) aPolyline = aZoneObj->GetPolyline();
582     if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
583       createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
584
585     LightApp_DataObject* aBathSect = 
586       createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() );
587
588     Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry();
589     if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() )
590       createObject( aBathSect, aBathymetry, aGuiObj->entry(), false );
591   }
592   else if ( anObjectKind == KIND_CALCULATION )
593   {
594     Handle(HYDROData_CalculationCase) aCaseObj =
595       Handle(HYDROData_CalculationCase)::DownCast( aDataObj );
596
597     LightApp_DataObject* aCaseRegionsSect = 
598       createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() );
599
600     HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions();
601     HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
602     for ( ; anIter.More(); anIter.Next() )
603     {
604       Handle(HYDROData_Region) aCaseRegion =
605         Handle(HYDROData_Region)::DownCast( anIter.Value() );
606       if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
607         createObject( aCaseRegionsSect, aCaseRegion, aGuiObj->entry(), true );
608     }
609   }
610   else if ( anObjectKind == KIND_REGION )
611   {
612     Handle(HYDROData_Region) aRegionObj =
613       Handle(HYDROData_Region)::DownCast( aDataObj );
614
615     HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones();
616     HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones );
617     for ( ; anIter.More(); anIter.Next() )
618     {
619       Handle(HYDROData_Zone) aRegionZone =
620         Handle(HYDROData_Zone)::DownCast( anIter.Value() );
621       if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
622         createObject( aGuiObj, aRegionZone, aGuiObj->entry(), true );
623     }
624   }
625 }
626
627 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
628                                       SUIT_DataObject* theChild )
629 {
630   SUIT_DataObject* aSubChild = theChild->firstChild();
631   for( ; aSubChild; aSubChild = aSubChild->nextBrother() )
632     removeChild( theChild, aSubChild );
633   theParent->removeChild( theChild );
634 }
635
636 SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* theFather,
637                                                       const QString& theName )
638 {
639   SUIT_DataObject* aChild = theFather->firstChild();
640   while( aChild )
641   {
642     if( aChild->name() == theName )
643       return aChild; // found
644     aChild = aChild->nextBrother();
645   }
646   return NULL; // not found
647 }