Salome HOME
Update mechanism for calculation case and it child objects corrected.
[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       {
230         theSeq.Append( anObject );
231       }
232     }
233   }
234 }
235
236 HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Entity)& theObj,
237                                               const GraphicsView_ObjectList& theObjects )
238 {
239   if( !theObj.IsNull() )
240   {
241     GraphicsView_ObjectListIterator anIter( theObjects );
242     while( anIter.hasNext() )
243     {
244       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
245       {
246         Handle(HYDROData_Entity) anObj = aPrs->getObject();
247         if( IsEqual( anObj, theObj ) )
248           return aPrs;
249       }
250     }
251   }
252   return NULL;
253 }
254
255 GraphicsView_ObjectList HYDROGUI_Tool::GetPrsList( GraphicsView_ViewPort* theViewPort )
256 {
257   GraphicsView_ObjectList aList;
258   if( theViewPort )
259   {
260     GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() );
261     while( anIter.hasNext() )
262       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
263         aList.append( aPrs );
264   }
265   return aList;
266 }
267
268 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module* theModule )
269 {
270   HYDROData_SequenceOfObjects aSeq;
271
272   HYDROGUI_DataModel* aModel = theModule->getDataModel();
273
274   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
275   SUIT_DataOwnerPtrList anOwners;
276   aSelectionMgr->selected( anOwners );
277
278   QStringList aCollectedNameList; // to avoid duplication
279   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
280   {
281     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
282     {
283       Handle(HYDROData_Entity) anObject = aModel->objectByEntry( anOwner->entry() );
284       if( !anObject.IsNull() )
285       {
286         QString aName = anObject->GetName();
287         if( !aCollectedNameList.contains( aName ) )
288         {
289           aSeq.Append( anObject );
290           aCollectedNameList.append( aName );
291         }
292       }
293     }
294   }
295   return aSeq;
296 }
297
298 Handle(HYDROData_Entity) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theModule )
299 {
300   HYDROData_SequenceOfObjects aSeq = GetSelectedObjects( theModule );
301   if( !aSeq.IsEmpty() )
302     return aSeq.First();
303   return NULL;
304 }
305
306 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetGeometryObjects( 
307   HYDROGUI_Module* theModule )
308 {
309   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
310
311   HYDROData_SequenceOfObjects aResSeq;
312
313   HYDROData_Iterator anIter( aDocument );
314   for ( ; anIter.More(); anIter.Next() )
315   {
316     Handle(HYDROData_Entity) anObj = anIter.Current();
317     if ( !HYDROData_Tool::IsGeometryObject( anObj ) )
318       continue;
319
320     aResSeq.Append( anObj );
321   }
322   
323   return aResSeq;
324 }
325
326 ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
327 {
328   HYDROGUI_DataModel* aModel = theModule->getDataModel();
329
330   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
331   SUIT_DataOwnerPtrList anOwners;
332   aSelectionMgr->selected( anOwners );
333
334   if( anOwners.size() != 1 )
335     return KIND_UNKNOWN;
336
337   if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( anOwners.first().operator->() ) )
338   {
339     QString anEntry = anOwner->entry();
340     QString aPrefix = HYDROGUI_DataObject::entryPrefix();
341     if( anEntry.left( aPrefix.length() ) == aPrefix )
342     {
343       anEntry.remove( aPrefix );
344       for( ObjectKind anObjectKind = KIND_UNKNOWN + 1; anObjectKind <= KIND_LAST; anObjectKind++ )
345         if( HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( anObjectKind ).toAscii() ) == anEntry )
346           return anObjectKind;
347     }
348   }
349   return KIND_UNKNOWN;
350 }
351
352 QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule )
353 {
354   QStringList anEntryList;
355
356   // Get active SalomeApp_Study
357   SalomeApp_Study* aStudy = NULL;
358   if ( theModule && theModule->getApp() ) {
359     aStudy = dynamic_cast<SalomeApp_Study*>( theModule->getApp()->activeStudy() );
360   }
361   if ( !aStudy ) {
362     return anEntryList;
363   }
364
365   // Get selection
366   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
367   SUIT_DataOwnerPtrList anOwners;
368   aSelectionMgr->selected( anOwners );
369
370   // Check if the selected objects belong to GEOM and have a shape
371   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
372   {
373     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
374     {
375       QString anEntry = anOwner->entry();
376       _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID(qPrintable(anEntry)) );
377       if (aSObject) {
378          _PTR(SComponent) aSComponent = aSObject->GetFatherComponent();
379         if ( aSComponent && aSComponent->ComponentDataType() == "GEOM" ) {
380           GEOM::GEOM_Object_var aGeomObj = 
381             GEOMBase::GetObjectFromIOR( aSObject->GetIOR().c_str() );
382
383           if ( !aGeomObj->_is_nil() && aGeomObj->IsShape() ) {
384             anEntryList << anEntry;
385           }
386         }
387       }
388     }
389   }
390
391   return anEntryList;
392 }
393
394 Handle(HYDROData_Entity) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
395                                                           const QString&   theName,
396                                                           const ObjectKind theObjectKind )
397 {
398   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
399   return HYDROData_Tool::FindObjectByName( aDocument, theName, theObjectKind );
400 }
401
402 HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module*   theModule,
403                                                                const QStringList& theNames,
404                                                                const ObjectKind   theObjectKind )
405 {
406   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
407   return HYDROData_Tool::FindObjectsByNames( aDocument, theNames, theObjectKind );
408 }
409
410 QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module*   theModule,
411                                            const QString&     thePrefix,
412                                            const QStringList& theUsedNames,
413                                            const bool         theIsTryToUsePurePrefix)
414 {
415   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
416   return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix );
417 }
418
419 size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule,
420                                        const QString&   theViewId )
421 {
422   size_t aViewId = 0;
423   SUIT_ViewManager* aViewMgr = theModule->getApp()->activeViewManager();
424   if( !aViewMgr || ( !theViewId.isEmpty() && aViewMgr->getType() != theViewId ) )
425     return aViewId;
426
427   if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
428     aViewId = (size_t)aViewer;
429   return aViewId;
430 }
431
432 size_t HYDROGUI_Tool::GetActiveGraphicsViewId( HYDROGUI_Module* theModule )
433 {
434   return GetActiveViewId( theModule, GraphicsView_Viewer::Type() );
435 }
436
437 size_t HYDROGUI_Tool::GetActiveOCCViewId( HYDROGUI_Module* theModule )
438 {
439   return GetActiveViewId( theModule, OCCViewer_Viewer::Type() );
440 }
441
442 QList<size_t> getViewIdList( HYDROGUI_Module* theModule,
443                              const QString&   theViewId )
444 {
445   QList<size_t> aList;
446   ViewManagerList aViewMgrs;
447   theModule->getApp()->viewManagers( theViewId, aViewMgrs );
448   QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
449   while( anIter.hasNext() )
450   {
451     if( SUIT_ViewManager* aViewMgr = anIter.next() )
452     {
453       if( SUIT_ViewModel* aViewer = aViewMgr->getViewModel() )
454         aList.append( (size_t)aViewer );
455     }
456   }
457   return aList;
458 }
459
460 QList<size_t> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
461 {
462   return getViewIdList( theModule, GraphicsView_Viewer::Type() );
463 }
464
465 QList<size_t> HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule )
466 {
467   return getViewIdList( theModule, OCCViewer_Viewer::Type() );
468 }
469
470 void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
471                                        const int theActionId,
472                                        const bool isShown )
473 {
474   if ( !theViewFrame )
475     return;
476
477   OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW );
478   if ( aView ) {
479     aView->toolMgr()->setShown( theActionId, isShown );
480     if ( theActionId == OCCViewer_ViewWindow::MaximizedId )
481       theViewFrame->onMaximizedView( aView, true );
482   }
483 }
484
485 void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule,
486                                        const int theActionId,
487                                        const bool isShown )
488 {
489   QList<size_t> aList;
490   ViewManagerList aViewMgrs;
491   theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs );
492   QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
493   while( anIter.hasNext() )
494   {
495     if( SUIT_ViewManager* aViewMgr = anIter.next() )
496     {
497       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>
498                                                            ( aViewMgr->getActiveView() );
499       if ( aViewFrame )
500         setOCCActionShown( aViewFrame, theActionId, isShown );
501     }
502   }
503 }
504
505 void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
506                                          HYDROData_SequenceOfObjects& theRefObjects,
507                                          QStringList& theRefNames )
508 {
509   if( theObj.IsNull() )
510     return;
511
512   HYDROData_SequenceOfObjects anAllRefObjects = theObj->GetAllReferenceObjects();
513   theRefObjects.Append( anAllRefObjects );
514
515   for( int i = 1, n = anAllRefObjects.Length(); i <= n; ++i )
516   {
517     Handle(HYDROData_Entity) aRefObj = theRefObjects.Value( i );
518     if( aRefObj.IsNull() || aRefObj->IsRemoved() )
519       continue;
520
521     QString aRefObjectName = aRefObj->GetName();
522     if( theRefNames.contains( aRefObjectName ) )
523       continue;
524
525     theRefObjects.Append( aRefObj );
526     theRefNames.append( aRefObjectName );
527
528     GetObjectReferences( aRefObj, theRefObjects, theRefNames );
529   }
530 }
531
532 HYDROData_SequenceOfObjects HYDROGUI_Tool::GetObjectBackReferences( 
533   HYDROGUI_Module*                theModule,
534   const Handle(HYDROData_Entity)& theObj )
535 {
536   if( theObj.IsNull() )
537     return HYDROData_SequenceOfObjects();
538
539   QString anObjName = theObj->GetName();
540
541   QMap<QString,HYDROData_SequenceOfObjects> aMapOfBackRefs =
542     GetObjectsBackReferences( theModule, QStringList() << anObjName );
543
544   return aMapOfBackRefs[ anObjName ];
545 }
546
547 QMap<QString,HYDROData_SequenceOfObjects> HYDROGUI_Tool::GetObjectsBackReferences(
548   HYDROGUI_Module*   theModule, const QStringList& theObjectNames )
549 {
550   QMap<QString,HYDROData_SequenceOfObjects> aResMap;
551
552   if( theObjectNames.isEmpty() )
553     return aResMap;
554
555   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
556   if( aDocument.IsNull() )
557     return aResMap;
558
559   HYDROData_Iterator anIterator( aDocument );
560   for( ; anIterator.More(); anIterator.Next() )
561   {
562     Handle(HYDROData_Entity) anObject = anIterator.Current();
563     if( anObject.IsNull() || anObject->IsRemoved() )
564       continue;
565
566     QString anObjectName = anObject->GetName();
567     if ( theObjectNames.contains( anObjectName ) )
568       continue;
569
570     HYDROData_SequenceOfObjects aRefObjects = anObject->GetAllReferenceObjects();
571     for ( int i = 1, n = aRefObjects.Length(); i <= n; ++i )
572     {
573       Handle(HYDROData_Entity) aRefObject = aRefObjects.Value( i );
574       if( aRefObject.IsNull() || aRefObject->IsRemoved() )
575         continue;
576
577       QString aRefObjectName = aRefObject->GetName();
578       if ( !theObjectNames.contains( aRefObjectName ) )
579         continue;
580
581       aResMap[ aRefObjectName ].Append( anObject );
582     }
583   }
584
585   return aResMap;
586 }
587
588 QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid )
589 {
590   if ( !wid )
591     return 0;
592
593   QDockWidget* dock = 0;
594   QWidget* w = wid->parentWidget();
595   while ( w && !dock )
596   {
597     dock = ::qobject_cast<QDockWidget*>( w );
598     w = w->parentWidget();
599   }
600   return dock;
601 }
602
603 QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module*   theModule,
604                                             const QStringList& theZoneNames )
605 {
606   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
607   return GenerateFillingColor( aDocument, theZoneNames );
608 }
609
610 QColor HYDROGUI_Tool::GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
611                                             const QStringList&                theZoneNames )
612 {
613   QColor aFillingColor( HYDROData_ImmersibleZone::DefaultFillingColor() );
614
615   int aCounter = 0;
616   int aR = 0, aG = 0, aB = 0;
617   QStringListIterator aZoneNameIter( theZoneNames );
618   while( aZoneNameIter.hasNext() )
619   {
620     const QString& aZoneName = aZoneNameIter.next();
621     Handle(HYDROData_ImmersibleZone) aRefZone = 
622       Handle(HYDROData_ImmersibleZone)::DownCast(
623         HYDROData_Tool::FindObjectByName( theDoc, aZoneName, KIND_IMMERSIBLE_ZONE ) );
624     if( !aRefZone.IsNull() )
625     {
626       QColor aRefColor = aRefZone->GetFillingColor();
627       aR += aRefColor.red();
628       aG += aRefColor.green();
629       aB += aRefColor.blue();
630       aCounter++;
631     }
632   }
633   
634   if( aCounter > 0 )
635   {
636     aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
637   }
638
639   return aFillingColor;
640 }
641
642 QStringList HYDROGUI_Tool::FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, 
643                                                      const ObjectKind theObjectKind )
644 {
645   QStringList aNames;
646
647   HYDROData_Iterator anIter( theDoc, theObjectKind );
648   for ( ; anIter.More(); anIter.Next() ) {
649     Handle(HYDROData_Entity) anObject = anIter.Current();
650     if( !anObject.IsNull() ) {
651       aNames.append( anObject->GetName() );
652     }
653   }
654
655   return aNames;
656 }
657
658 QString HYDROGUI_Tool::GetCoordinateString( const double theNumber )
659 {
660   return QString::number( theNumber, 'f', 2 );
661 }