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