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