Salome HOME
14b8836bc9c51054ee1c9f1ec13f4686e68d7acc
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Tool.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_Tool.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_DataObject.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Prs.h"
29
30 #include <HYDROData_Document.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_ImmersibleZone.h>
33 #include <HYDROData_Tool.h>
34
35 #include <GEOMBase.h>
36
37 #include <GraphicsView_Viewer.h>
38
39 #include <SalomeApp_Study.h>
40
41 #include <LightApp_Application.h>
42 #include <LightApp_DataOwner.h>
43 #include <LightApp_SelectionMgr.h>
44
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewFrame.h>
47
48 #include <QtxWorkstack.h>
49 #include <QtxActionToolMgr.h>
50
51 #include <STD_TabDesktop.h>
52
53 #include <SUIT_Session.h>
54 #include <SUIT_Study.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ViewWindow.h>
57
58 #include <SALOMEDSClient.hxx>
59
60 #include <QDir>
61 #include <QFileInfo>
62 #include <QDockWidget>
63 #include <QTextCodec>
64
65 // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1')
66 // encoding instead of default 'System'
67 #define USE_LATIN1_ENCODING
68
69 QString HYDROGUI_Tool::ToQString( const TCollection_AsciiString& src )
70 {
71 #ifdef USE_LATIN1_ENCODING
72   QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
73 #else
74   QTextCodec* codec = QTextCodec::codecForLocale();
75 #endif
76   QString res;
77   if ( !src.IsEmpty() )
78     res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) :
79       QString( (char*)src.ToCString() );
80   return res;
81 }
82
83 QString HYDROGUI_Tool::ToQString( const TCollection_ExtendedString& src )
84 {
85   return QString( (QChar*)src.ToExtString(), src.Length() );
86 }
87
88 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HAsciiString)& src )
89 {
90   if( src.IsNull() )
91     return QString();
92   else
93     return ToQString( src->String() );
94 }
95
96 QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HExtendedString)& src )
97 {
98   if( src.IsNull() )
99     return QString();
100   return ToQString( src->String() );
101 }
102
103 TCollection_AsciiString HYDROGUI_Tool::ToAsciiString( const QString& src )
104 {
105   TCollection_AsciiString res;
106   if( !src.isNull() )
107   {
108 #ifdef USE_LATIN1_ENCODING
109     QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1
110 #else
111     QTextCodec* codec = QTextCodec::codecForLocale();
112 #endif
113     if( codec )
114     {
115       QByteArray str = codec->fromUnicode( src );
116       res = TCollection_AsciiString( (Standard_CString)str.constData() );
117     }
118     else
119       res = TCollection_AsciiString( src.toLatin1().data() );
120   }
121   return res;
122 }
123
124 TCollection_ExtendedString HYDROGUI_Tool::ToExtString( const QString& src )
125 {
126   if( src.isEmpty() )
127     return TCollection_ExtendedString();
128
129   Standard_Integer len = src.length();
130   Standard_ExtString extStr = new Standard_ExtCharacter[ ( len + 1 ) * 2 ];
131   memcpy( (void*)extStr, src.unicode(), len * 2 );
132   ((short*)extStr)[ len ] = 0;
133
134   TCollection_ExtendedString trg( extStr );
135   delete [] extStr;
136   return trg;
137 }
138
139 Handle(TCollection_HAsciiString) HYDROGUI_Tool::ToHAsciiString( const QString& src )
140 {
141   return new TCollection_HAsciiString( ToAsciiString( src ) );
142 }
143
144 Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& src )
145 {
146   return new TCollection_HExtendedString( ToExtString( src ) );
147 }
148
149 int HYDROGUI_Tool::GetActiveStudyId()
150 {
151   if( SUIT_Session* aSession = SUIT_Session::session() )
152     if( SUIT_Application* anApp = aSession->activeApplication() )
153       if( SUIT_Study* aStudy = anApp->activeStudy() )
154         return aStudy->id();
155   return 0;
156 }
157
158 QString HYDROGUI_Tool::GetTempDir( const bool theToCreate )
159 {
160   QString aRes;
161
162   char* tmpdir = getenv ( "HYDRO_TMP_DIR" );
163   if ( tmpdir )
164   {
165     // try to create folder if it does not exist
166     QFileInfo fi( tmpdir );
167     if ( !fi.exists() && theToCreate )
168     {
169       if ( QDir().mkdir( tmpdir ) )
170         QFile::setPermissions( tmpdir, (QFile::Permissions)0x4FFFF );
171        QFileInfo fi( tmpdir );
172        if ( !fi.exists() || !fi.isWritable() )
173          tmpdir = 0;
174     }
175   }
176   if ( !tmpdir )
177     tmpdir = getenv ( "TEMP" );
178   if ( !tmpdir )
179     tmpdir = getenv ( "TMP" );
180   if ( !tmpdir )
181   {
182 #ifdef WNT
183     tmpdir = "C:\\";
184 #else
185     tmpdir = "/tmp";
186 #endif
187   }
188   aRes = tmpdir;
189   
190   QFileInfo fi( aRes );
191   if ( !fi.exists() || !fi.isWritable() )
192     aRes = QString::null;
193
194   return aRes;
195 }
196
197 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
198                                           SUIT_ViewManager* theViewManager )
199 {
200   if( theViewManager )
201     if( SUIT_ViewWindow* aViewWindow = theViewManager->getActiveView() )
202       if( STD_TabDesktop* aTabDesktop = dynamic_cast<STD_TabDesktop*>( theModule->getApp()->desktop() ) )
203         if( QtxWorkstack* aWorkstack = aTabDesktop->workstack() )
204           aWorkstack->setActiveWindow( aViewWindow );
205 }
206
207 void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule,
208                                       HYDROData_SequenceOfObjects& theSeq )
209 {
210   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
211   if( !aDocument.IsNull() )
212   {
213     HYDROData_Iterator anIterator( aDocument );
214     for( ; anIterator.More(); anIterator.Next() )
215     {
216       Handle(HYDROData_Entity) anObject = anIterator.Current();
217       if( !anObject.IsNull() && ( 
218         ( anObject->GetKind() == KIND_IMAGE ) ||
219         ( anObject->GetKind() == KIND_POLYLINEXY ) ||
220         ( anObject->GetKind() == KIND_POLYLINE ) ||
221         ( anObject->GetKind() == KIND_IMMERSIBLE_ZONE ) ||
222         ( anObject->GetKind() == KIND_REGION ) ||
223         ( anObject->GetKind() == KIND_BATHYMETRY ) ||
224         ( anObject->GetKind() == KIND_ZONE ) ||
225         ( anObject->GetKind() == KIND_OBSTACLE ) ||
226         ( anObject->GetKind() == KIND_PROFILE ) ||
227         ( anObject->GetKind() == KIND_STREAM ) ||
228         ( anObject->GetKind() == KIND_CHANNEL ) ||
229         ( anObject->GetKind() == KIND_DIGUE ) ) )
230       {
231         theSeq.Append( anObject );
232       }
233     }
234   }
235 }
236
237 HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Entity)& theObj,
238                                               const GraphicsView_ObjectList& theObjects )
239 {
240   if( !theObj.IsNull() )
241   {
242     GraphicsView_ObjectListIterator anIter( theObjects );
243     while( anIter.hasNext() )
244     {
245       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
246       {
247         Handle(HYDROData_Entity) anObj = aPrs->getObject();
248         if( IsEqual( anObj, theObj ) )
249           return aPrs;
250       }
251     }
252   }
253   return NULL;
254 }
255
256 GraphicsView_ObjectList HYDROGUI_Tool::GetPrsList( GraphicsView_ViewPort* theViewPort )
257 {
258   GraphicsView_ObjectList aList;
259   if( theViewPort )
260   {
261     GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() );
262     while( anIter.hasNext() )
263       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
264         aList.append( aPrs );
265   }
266   return aList;
267 }
268
269 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* theModule )
270 {
271   HYDROData_SequenceOfObjects aSeq;
272
273   HYDROGUI_DataModel* aModel = theModule->getDataModel();
274
275   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
276   SUIT_DataOwnerPtrList anOwners;
277   aSelectionMgr->selected( anOwners );
278
279   QStringList aCollectedNameList; // to avoid duplication
280   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
281   {
282     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
283     {
284       Handle(HYDROData_Entity) anObject = aModel->objectByEntry( anOwner->entry() );
285       if( !anObject.IsNull() )
286       {
287         QString aName = anObject->GetName();
288         if( !aCollectedNameList.contains( aName ) )
289         {
290           aSeq.Append( anObject );
291           aCollectedNameList.append( aName );
292         }
293       }
294     }
295   }
296   return aSeq;
297 }
298
299 Handle(HYDROData_Entity) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule )
300 {
301   HYDROData_SequenceOfObjects aSeq = GetSelectedObjects( theModule );
302   if( !aSeq.IsEmpty() )
303     return aSeq.First();
304   return NULL;
305 }
306
307 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetGeometryObjects( 
308   HYDROGUI_Module* theModule )
309 {
310   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
311
312   HYDROData_SequenceOfObjects aResSeq;
313
314   HYDROData_Iterator anIter( aDocument );
315   for ( ; anIter.More(); anIter.Next() )
316   {
317     Handle(HYDROData_Entity) anObj = anIter.Current();
318     if ( !HYDROData_Tool::IsGeometryObject( anObj ) )
319       continue;
320
321     aResSeq.Append( anObj );
322   }
323   
324   return aResSeq;
325 }
326
327 ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
328 {
329   HYDROGUI_DataModel* aModel = theModule->getDataModel();
330
331   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
332   SUIT_DataOwnerPtrList anOwners;
333   aSelectionMgr->selected( anOwners );
334
335   if( anOwners.size() != 1 )
336     return KIND_UNKNOWN;
337
338   if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( anOwners.first().operator->() ) )
339   {
340     QString anEntry = anOwner->entry();
341     QString aPrefix = HYDROGUI_DataObject::entryPrefix();
342     if( anEntry.left( aPrefix.length() ) == aPrefix )
343     {
344       anEntry.remove( aPrefix );
345       for( ObjectKind anObjectKind = KIND_UNKNOWN + 1; anObjectKind <= KIND_LAST; anObjectKind++ )
346         if( HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( anObjectKind ).toAscii() ) == anEntry )
347           return anObjectKind;
348     }
349   }
350   return KIND_UNKNOWN;
351 }
352
353 QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule )
354 {
355   QStringList anEntryList;
356
357   // Get active SalomeApp_Study
358   SalomeApp_Study* aStudy = NULL;
359   if ( theModule && theModule->getApp() ) {
360     aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
361   }
362   if ( !aStudy ) {
363     return anEntryList;
364   }
365
366   // Get selection
367   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
368   SUIT_DataOwnerPtrList anOwners;
369   aSelectionMgr->selected( anOwners );
370
371   // Check if the selected objects belong to GEOM and have a shape
372   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
373   {
374     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
375     {
376       QString anEntry = anOwner->entry();
377       _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID(qPrintable(anEntry)) );
378       if (aSObject) {
379          _PTR(SComponent) aSComponent = aSObject->GetFatherComponent();
380         if ( aSComponent && aSComponent->ComponentDataType() == "GEOM" ) {
381           GEOM::GEOM_Object_var aGeomObj = 
382             GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
383
384           if ( !aGeomObj->_is_nil() && aGeomObj->IsShape() ) {
385             anEntryList << anEntry;
386           }
387         }
388       }
389     }
390   }
391
392   return anEntryList;
393 }
394
395 Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
396                                                           const QString&   theName,
397                                                           const ObjectKind theObjectKind )
398 {
399   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
400   return HYDROData_Tool::FindObjectByName( aDocument, theName, theObjectKind );
401 }
402
403 HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module*   theModule,
404                                                                const QStringList& theNames,
405                                                                const ObjectKind   theObjectKind )
406 {
407   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
408   return HYDROData_Tool::FindObjectsByNames( aDocument, theNames, theObjectKind );
409 }
410
411 QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module*   theModule,
412                                            const QString&     thePrefix,
413                                            const QStringList& theUsedNames,
414                                            const bool         theIsTryToUsePurePrefix)
415 {
416   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
417   return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix );
418 }
419
420 size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule,
421                                        const QString&   theViewId )
422 {
423   size_t aViewId = 0;
424   SUIT_ViewManager* aViewMgr = theModule->getApp()->activeViewManager();
425   if( !aViewMgr || ( !theViewId.isEmpty() && aViewMgr->getType() != theViewId ) )
426     return aViewId;
427
428   if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
429     aViewId = (size_t)aViewer;
430   return aViewId;
431 }
432
433 size_t HYDROGUI_Tool::GetActiveGraphicsViewId( HYDROGUI_Module* theModule )
434 {
435   return GetActiveViewId( theModule, GraphicsView_Viewer::Type() );
436 }
437
438 size_t HYDROGUI_Tool::GetActiveOCCViewId( HYDROGUI_Module* theModule )
439 {
440   return GetActiveViewId( theModule, OCCViewer_Viewer::Type() );
441 }
442
443 QList<size_t> getViewIdList( HYDROGUI_Module* theModule,
444                              const QString&   theViewId )
445 {
446   QList<size_t> aList;
447   ViewManagerList aViewMgrs;
448   theModule->getApp()->viewManagers( theViewId, aViewMgrs );
449   QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
450   while( anIter.hasNext() )
451   {
452     if( SUIT_ViewManager* aViewMgr = anIter.next() )
453     {
454       if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
455         aList.append( (size_t)aViewer );
456     }
457   }
458   return aList;
459 }
460
461 QList<size_t> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
462 {
463   return getViewIdList( theModule, GraphicsView_Viewer::Type() );
464 }
465
466 QList<size_t> HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule )
467 {
468   return getViewIdList( theModule, OCCViewer_Viewer::Type() );
469 }
470
471 void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
472                                        const int theActionId,
473                                        const bool isShown )
474 {
475   if ( !theViewFrame )
476     return;
477
478   OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW );
479   if ( aView ) {
480     aView->toolMgr()->setShown( theActionId, isShown );
481     if ( theActionId == OCCViewer_ViewWindow::MaximizedId )
482       theViewFrame->onMaximizedView( aView, true );
483   }
484 }
485
486 void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule,
487                                        const int theActionId,
488                                        const bool isShown )
489 {
490   QList<size_t> aList;
491   ViewManagerList aViewMgrs;
492   theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs );
493   QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
494   while( anIter.hasNext() )
495   {
496     if( SUIT_ViewManager* aViewMgr = anIter.next() )
497     {
498       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>
499                                                            ( aViewMgr->getActiveView() );
500       if ( aViewFrame )
501         setOCCActionShown( aViewFrame, theActionId, isShown );
502     }
503   }
504 }
505
506 void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
507                                          HYDROData_SequenceOfObjects& theRefObjects,
508                                          QStringList& theRefNames )
509 {
510   if( theObj.IsNull() )
511     return;
512
513   HYDROData_SequenceOfObjects anAllRefObjects = theObj->GetAllReferenceObjects();
514   theRefObjects.Append( anAllRefObjects );
515
516   for( int i = 1, n = anAllRefObjects.Length(); i <= n; ++i )
517   {
518     Handle(HYDROData_Entity) aRefObj = theRefObjects.Value( i );
519     if( aRefObj.IsNull() || aRefObj->IsRemoved() )
520       continue;
521
522     QString aRefObjectName = aRefObj->GetName();
523     if( theRefNames.contains( aRefObjectName ) )
524       continue;
525
526     theRefObjects.Append( aRefObj );
527     theRefNames.append( aRefObjectName );
528
529     GetObjectReferences( aRefObj, theRefObjects, theRefNames );
530   }
531 }
532
533 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetObjectBackReferences( 
534   HYDROGUI_Module*                theModule,
535   const Handle(HYDROData_Entity)& theObj )
536 {
537   if( theObj.IsNull() )
538     return HYDROData_SequenceOfObjects();
539
540   QString anObjName = theObj->GetName();
541
542   QMap<QString,HYDROData_SequenceOfObjects> aMapOfBackRefs =
543     GetObjectsBackReferences( theModule, QStringList() << anObjName );
544
545   return aMapOfBackRefs[ anObjName ];
546 }
547
548 QMap<QString,HYDROData_SequenceOfObjects> HYDROGUI_Tool::GetObjectsBackReferences(
549   HYDROGUI_Module*   theModule, const QStringList& theObjectNames )
550 {
551   QMap<QString,HYDROData_SequenceOfObjects> aResMap;
552
553   if( theObjectNames.isEmpty() )
554     return aResMap;
555
556   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
557   if( aDocument.IsNull() )
558     return aResMap;
559
560   HYDROData_Iterator anIterator( aDocument );
561   for( ; anIterator.More(); anIterator.Next() )
562   {
563     Handle(HYDROData_Entity) anObject = anIterator.Current();
564     if( anObject.IsNull() || anObject->IsRemoved() )
565       continue;
566
567     QString anObjectName = anObject->GetName();
568     if ( theObjectNames.contains( anObjectName ) )
569       continue;
570
571     HYDROData_SequenceOfObjects aRefObjects = anObject->GetAllReferenceObjects();
572     for ( int i = 1, n = aRefObjects.Length(); i <= n; ++i )
573     {
574       Handle(HYDROData_Entity) aRefObject = aRefObjects.Value( i );
575       if( aRefObject.IsNull() || aRefObject->IsRemoved() )
576         continue;
577
578       QString aRefObjectName = aRefObject->GetName();
579       if ( !theObjectNames.contains( aRefObjectName ) )
580         continue;
581
582       aResMap[ aRefObjectName ].Append( anObject );
583     }
584   }
585
586   return aResMap;
587 }
588
589 QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid )
590 {
591   if ( !wid )
592     return 0;
593
594   QDockWidget* dock = 0;
595   QWidget* w = wid->parentWidget();
596   while ( w && !dock )
597   {
598     dock = ::qobject_cast<QDockWidget*>( w );
599     w = w->parentWidget();
600   }
601   return dock;
602 }
603
604 QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module*   theModule,
605                                             const QStringList& theZoneNames )
606 {
607   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
608   return GenerateFillingColor( aDocument, theZoneNames );
609 }
610
611 QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
612                                             const QStringList&                theZoneNames )
613 {
614   QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
615
616   int aCounter = 0;
617   int aR = 0, aG = 0, aB = 0;
618   QStringListIterator aZoneNameIter( theZoneNames );
619   while( aZoneNameIter.hasNext() )
620   {
621     const QString& aZoneName = aZoneNameIter.next();
622     Handle(HYDROData_ImmersibleZone) aRefZone = 
623       Handle(HYDROData_ImmersibleZone)::DownCast(
624         HYDROData_Tool::FindObjectByName( theDoc, aZoneName, KIND_IMMERSIBLE_ZONE ) );
625     if( !aRefZone.IsNull() )
626     {
627       QColor aRefColor = aRefZone->GetFillingColor();
628       aR += aRefColor.red();
629       aG += aRefColor.green();
630       aB += aRefColor.blue();
631       aCounter++;
632     }
633   }
634   
635   if( aCounter > 0 )
636   {
637     aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
638   }
639
640   return aFillingColor;
641 }
642
643 QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, 
644                                                      const ObjectKind theObjectKind )
645 {
646   QStringList aNames;
647
648   HYDROData_Iterator anIter( theDoc, theObjectKind );
649   for ( ; anIter.More(); anIter.Next() ) {
650     Handle(HYDROData_Entity) anObject = anIter.Current();
651     if( !anObject.IsNull() ) {
652       aNames.append( anObject->GetName() );
653     }
654   }
655
656   return aNames;
657 }
658
659 QString HYDROGUI_Tool::GetCoordinateString( const double theNumber )
660 {
661   return QString::number( theNumber, 'f', 2 );
662 }