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