Salome HOME
Chanel Create\Edit operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.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_Module.h"
24
25 #include "HYDROGUI.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_OCCDisplayer.h"
32 #include "HYDROGUI_OCCSelector.h"
33 #include "HYDROGUI_Operations.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_Shape.h"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
41 #include "HYDROGUI_PolylineOp.h"
42
43 #include <HYDROData_Image.h>
44 #include <HYDROData_Profile.h>
45 #include <HYDROData_Lambert93.h>
46 #include <HYDROData_Tool.h>
47
48 #include <HYDROData_OperationsFactory.h>
49
50 #include <GraphicsView_ViewFrame.h>
51 #include <GraphicsView_ViewManager.h>
52 #include <GraphicsView_ViewPort.h>
53 #include <GraphicsView_Viewer.h>
54
55 #include <ImageComposer_CutOperator.h>
56 #include <ImageComposer_CropOperator.h>
57 #include <ImageComposer_FuseOperator.h>
58
59 #include <LightApp_Application.h>
60 #include <LightApp_DataOwner.h>
61 #include <LightApp_GVSelector.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_UpdateFlags.h>
64
65 #include <OCCViewer_ViewFrame.h>
66 #include <OCCViewer_ViewManager.h>
67 #include <OCCViewer_ViewModel.h>
68
69 #include <SALOME_Event.h>
70
71 #include <SUIT_DataBrowser.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_Study.h>
74 #include <SUIT_ViewManager.h>
75
76 #include <SVTK_ViewManager.h>
77 #include <SVTK_ViewModel.h>
78 #include <SVTK_Selector.h>
79
80 #include <OCCViewer_ViewPort3d.h>
81
82 #include <GEOMUtils.hxx>
83
84 #include <QAction>
85 #include <QApplication>
86 #include <QGraphicsSceneMouseEvent>
87 #include <QMenu>
88 #include <QMouseEvent>
89 #include <QStatusBar>
90
91 static int ViewManagerId = 0;
92
93 extern "C" HYDRO_EXPORT CAM_Module* createModule()
94 {
95   return new HYDROGUI_Module();
96 }
97
98 extern "C" HYDRO_EXPORT char* getModuleVersion()
99 {
100   return (char*)HYDRO_VERSION;
101 }
102
103 HYDROGUI_Module::HYDROGUI_Module()
104 : LightApp_Module( "HYDRO" ),
105   myDisplayer( 0 ),
106   myOCCDisplayer( 0 ),
107   myIsUpdateEnabled( true )
108 {
109 }
110
111 HYDROGUI_Module::~HYDROGUI_Module()
112 {
113 }
114
115 int HYDROGUI_Module::getStudyId() const
116 {
117   LightApp_Application* anApp = getApp();
118   return anApp ? anApp->activeStudy()->id() : 0;
119 }
120
121 void HYDROGUI_Module::initialize( CAM_Application* theApp )
122 {
123   LightApp_Module::initialize( theApp );
124
125   createActions();
126   createUndoRedoActions();
127   createMenus();
128   createPopups();
129   createToolbars();
130
131   setMenuShown( false );
132   setToolShown( false );
133
134   myDisplayer = new HYDROGUI_Displayer( this );
135   myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
136   myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
137 }
138
139 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
140 {
141   bool aRes = LightApp_Module::activateModule( theStudy );
142
143   LightApp_Application* anApp = getApp();
144   SUIT_Desktop* aDesktop = anApp->desktop();
145
146   getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
147
148   setMenuShown( true );
149   setToolShown( true );
150
151 #ifndef DISABLE_PYCONSOLE
152   aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), 
153                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
154 #endif
155
156   update( UF_All );
157
158   updateCommandsStatus();
159
160   connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), 
161            this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
162
163   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
164
165   ViewManagerList anOCCViewManagers;
166   anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
167   foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
168     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
169              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
170     foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
171       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
172       if ( aViewFrame && aViewFrame->getViewPort() ) {
173         aViewFrame->getViewPort()->installEventFilter( this );
174       }
175     }
176   }
177
178   return aRes;
179 }
180
181 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
182 {
183   ViewManagerMapIterator anIter( myViewManagerMap );
184   while( anIter.hasNext() )
185     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
186       getApp()->removeViewManager( aViewManager );
187   myViewManagerMap.clear();
188
189   ViewManagerList anOCCViewManagers;
190   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
191   foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
192     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
193                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
194   }
195
196   myObjectStateMap.clear();
197   myShapesMap.clear();
198   myVTKPrsMap.clear();
199
200   // clear the data model's list of copying objects
201   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
202
203   setMenuShown( false );
204   setToolShown( false );
205
206   getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
207
208   disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), 
209               this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
210
211   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
212
213   return LightApp_Module::deactivateModule( theStudy );
214 }
215
216 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
217 {
218   theMap.clear();
219   theMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
220 #ifndef DISABLE_PYCONSOLE
221   theMap.insert( LightApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
222 #endif
223   theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea   );
224 }
225
226 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
227 {
228   theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
229 }
230
231 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
232                                         QMenu* theMenu,
233                                         QString& theTitle )
234 {
235   HYDROGUI_DataModel* aModel = getDataModel();
236
237   bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
238   bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
239   bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
240   bool anIsVTKView = theClient == SVTK_Viewer::Type();
241   if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
242     return;
243
244   size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
245
246   bool anIsSelectedDataObjects = false;
247   bool anIsVisibleInSelection = false;
248   bool anIsHiddenInSelection = false;
249
250   bool anIsImage = false;
251   bool anIsImportedImage = false;
252   bool anIsImageHasRefs = false;
253   bool anIsFusedImage = false;
254   bool anIsCutImage = false;
255   bool anIsSplittedImage = false;
256   bool anIsMustBeUpdatedImage = false;
257   bool anIsPolyline = false;
258   bool anIsPolyline3D = false;
259   bool anIsProfile = false;
260   bool anIsValidProfile = false;
261   bool anAllAreProfiles = false;
262   bool anIsBathymetry = false;
263   bool anIsCalculation = false;
264   bool anIsImmersibleZone = false;
265   bool anIsVisualState = false;
266   bool anIsRegion = false;
267   bool anIsZone = false;
268   bool anIsObstacle = false;
269   bool anIsStream = false;
270   bool anIsChannel = false;
271   bool anIsGeomObject = false;
272
273   // check the selected GEOM objects
274   if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
275     theMenu->addAction( action( ImportGeomObjectId ) );
276     theMenu->addSeparator();
277   }
278
279   // check the selected data model objects
280   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
281   int aNbOfSelectedProfiles = 0;
282   for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
283   {
284     Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
285     if( !anObject.IsNull() )
286     {
287       anIsSelectedDataObjects = true;
288
289       bool aVisibility = isObjectVisible( anActiveViewId, anObject );
290       anIsVisibleInSelection |= aVisibility;
291       anIsHiddenInSelection |= !aVisibility;
292
293       ObjectKind anObjectKind = anObject->GetKind();
294       if( anObjectKind == KIND_IMAGE )
295       {
296         anIsImage = true;
297         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
298         if( !anImage.IsNull() )
299         {
300           anIsImportedImage = anImage->HasLocalPoints();
301           anIsImageHasRefs = anImage->HasReferences();
302           if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
303           {
304             if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
305             {
306               QString anOperatorName = anOperator->name();
307               if( anOperatorName == ImageComposer_FuseOperator::Type() )
308                 anIsFusedImage = true;
309               else if( anOperatorName == ImageComposer_CutOperator::Type() )
310                 anIsCutImage = true;
311               else if( anOperatorName == ImageComposer_CropOperator::Type() )
312                 anIsSplittedImage = true;
313             }
314           }
315           if ( anImage->IsMustBeUpdated() )
316           {
317             anIsMustBeUpdatedImage = true;
318           }
319         }
320       }
321       else if( anObjectKind == KIND_POLYLINEXY )
322         anIsPolyline = true;
323       else if( anObjectKind == KIND_POLYLINE )
324         anIsPolyline3D = true;
325       else if( anObjectKind == KIND_PROFILE )
326       {
327         anIsProfile = true;
328         aNbOfSelectedProfiles++;
329
330         Handle(HYDROData_Profile) aProfile = 
331           Handle(HYDROData_Profile)::DownCast( anObject );
332         if( !aProfile.IsNull() && aProfile->IsValid() ) {
333           anIsValidProfile = true;
334         }
335       }
336       else if( anObjectKind == KIND_CALCULATION )
337         anIsCalculation = true;
338       else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
339         anIsImmersibleZone = true;
340       else if( anObjectKind == KIND_VISUAL_STATE )
341         anIsVisualState = true;
342       else if( anObjectKind == KIND_REGION )
343         anIsRegion = true;
344       else if( anObjectKind == KIND_ZONE )
345         anIsZone = true;
346       else if( anObjectKind == KIND_BATHYMETRY )
347         anIsBathymetry = true;
348       else if( anObjectKind == KIND_OBSTACLE )
349         anIsObstacle = true;
350       else if( anObjectKind == KIND_STREAM )
351         anIsStream = true;
352       else if( anObjectKind == KIND_CHANNEL )
353         anIsChannel = true;
354     }
355
356     anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
357   }
358
359   // Check if all selected objects are profiles
360   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
361                      ( aNbOfSelectedProfiles == aSeq.Length() );
362
363   // check the selected partitions
364   if( !anIsSelectedDataObjects && anIsObjectBrowser )
365   {
366     ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
367     if( aSelectedPartition != KIND_UNKNOWN )
368     {
369       switch( aSelectedPartition )
370       {
371         case KIND_IMAGE:
372           theMenu->addAction( action( ImportImageId ) );
373           break;
374         case KIND_BATHYMETRY:
375           theMenu->addAction( action( ImportBathymetryId ) );
376           break;
377         case KIND_ARTIFICIAL_OBJECT:
378           theMenu->addAction( action( CreateChannelId ) );
379           break;
380         case KIND_NATURAL_OBJECT:
381           theMenu->addAction( action( CreateImmersibleZoneId ) );
382           theMenu->addAction( action( CreateStreamId ) );
383           break;
384         case KIND_OBSTACLE:
385           theMenu->addAction( action( ImportObstacleFromFileId ) );
386           theMenu->addAction( action( CreateBoxId ) );
387           theMenu->addAction( action( CreateCylinderId ) );
388           break;
389         case KIND_CALCULATION:
390           theMenu->addAction( action( CreateCalculationId ) );
391           break;
392         case KIND_POLYLINEXY:
393           theMenu->addAction( action( CreatePolylineId ) );
394           break;
395         case KIND_POLYLINE:
396           theMenu->addAction( action( CreatePolyline3DId ) );
397           break;
398         case KIND_PROFILE:
399           theMenu->addAction( action( CreateProfileId ) );
400           theMenu->addAction( action( ImportProfilesId ) );
401           theMenu->addAction( action( AllGeoreferencementId ) );
402           break;
403         case KIND_VISUAL_STATE:
404           theMenu->addAction( action( SaveVisualStateId ) );
405           break;
406       }
407       theMenu->addSeparator();
408     }
409   }
410
411   if( anIsSelectedDataObjects )
412   {
413     if ( anIsMustBeUpdatedImage )
414     {
415       theMenu->addAction( action( UpdateImageId ) );
416       theMenu->addSeparator();
417     }
418
419     if( aSeq.Length() == 1 )
420     {
421       if( anIsImage )
422       {
423         if( anIsImportedImage )
424           theMenu->addAction( action( EditImportedImageId ) );
425         else if( anIsImageHasRefs )
426         {
427           if( anIsFusedImage )
428             theMenu->addAction( action( EditFusedImageId ) );
429           else if( anIsCutImage )
430             theMenu->addAction( action( EditCutImageId ) );
431           else if( anIsSplittedImage )
432             theMenu->addAction( action( EditSplittedImageId ) );
433         }
434
435         theMenu->addAction( action( ObserveImageId ) );
436         theMenu->addAction( action( ExportImageId ) );
437         theMenu->addSeparator();
438
439         if( anIsImageHasRefs )
440         {
441           theMenu->addAction( action( RemoveImageRefsId ) );
442           theMenu->addSeparator();
443         }
444
445         theMenu->addAction( action( FuseImagesId ) );
446         theMenu->addAction( action( CutImagesId ) );
447         theMenu->addAction( action( SplitImageId ) );
448         theMenu->addSeparator();
449       }
450       else if( anIsPolyline )
451       {
452         theMenu->addAction( action( EditPolylineId ) );
453         theMenu->addSeparator();
454       }
455       else if( anIsPolyline3D )
456       {
457         theMenu->addAction( action( EditPolyline3DId ) );
458         theMenu->addSeparator();
459       }
460       else if( anIsProfile )
461       {
462         theMenu->addAction( action( EditProfileId ) );
463         theMenu->addAction( action( SelectedGeoreferencementId ) );
464         theMenu->addSeparator();
465       }
466       else if( anIsCalculation )
467       {
468         theMenu->addAction( action( EditCalculationId ) );
469         theMenu->addAction( action( ExportCalculationId ) );
470         theMenu->addSeparator();
471       }
472       else if( anIsImmersibleZone )
473       {
474         theMenu->addAction( action( EditImmersibleZoneId ) );
475         theMenu->addSeparator();
476       }
477       else if( anIsStream )
478       {
479         theMenu->addAction( action( EditStreamId ) );
480         theMenu->addSeparator();
481       }
482       else if( anIsChannel )
483       {
484         theMenu->addAction( action( EditChannelId ) );
485         theMenu->addSeparator();
486       }
487       else if( anIsVisualState && anIsObjectBrowser )
488       {
489         theMenu->addAction( action( SaveVisualStateId ) );
490         theMenu->addAction( action( LoadVisualStateId ) );
491         theMenu->addSeparator();
492       }
493
494       // Add set color action for geometrical objects
495       if ( anIsGeomObject )
496       {
497         theMenu->addAction( action( SetColorId ) );
498         theMenu->addSeparator();
499       }
500     } else if ( anAllAreProfiles ) {
501       theMenu->addAction( action( SelectedGeoreferencementId ) );
502       theMenu->addSeparator();
503     }
504
505     theMenu->addAction( action( DeleteId ) );
506     theMenu->addSeparator();
507
508     if( anIsImage || anIsPolyline || anIsPolyline3D || 
509         anIsImmersibleZone || anIsZone || anIsRegion ||
510         anIsBathymetry || anIsObstacle || anIsStream ||
511         anIsChannel || anIsValidProfile )
512     {
513       if( anIsHiddenInSelection )
514         theMenu->addAction( action( ShowId ) );
515       theMenu->addAction( action( ShowOnlyId ) );
516       if( anIsVisibleInSelection )
517         theMenu->addAction( action( HideId ) );
518       theMenu->addSeparator();
519     }
520   }
521
522   if ( anIsOCCView )
523   {
524     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
525     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
526     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
527       theMenu->addAction( action( DeleteId ) );
528   }
529
530   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
531   {
532     theMenu->addAction( action( ShowAllId ) );
533     theMenu->addAction( action( HideAllId ) );
534     theMenu->addSeparator();
535   }
536 }
537
538 void HYDROGUI_Module::update( const int flags )
539 {
540   if( !isUpdateEnabled() )
541     return;
542
543   QApplication::setOverrideCursor( Qt::WaitCursor );
544
545   // To prevent calling this method recursively
546   // from one of the methods called below
547   setUpdateEnabled( false );
548
549   // store selected objects
550   QStringList aSelectedEntries = storeSelection();
551
552   bool aDoFitAll = flags & UF_FitAll;
553   if( ( flags & UF_Viewer ) )
554     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
555
556   if( ( flags & UF_OCCViewer ) )
557     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
558
559   if( ( flags & UF_VTKViewer ) )
560     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
561
562   if( ( flags & UF_Model ) && getDataModel() && getApp() )
563   {
564     getDataModel()->update( getStudyId() );
565
566     // Temporary workaround to prevent breaking
567     // the selection in the object browser.
568     // Note: processEvents() should be called after updateGV(),
569     // otherwise the application crashes from time to time.
570     //RKV: qApp->processEvents(); 
571     getApp()->updateObjectBrowser( true );
572   }
573
574   // Object browser is currently updated by using UF_Model flag
575   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
576     getApp()->updateObjectBrowser( true );
577
578   if( ( flags & UF_Controls ) && getApp() )
579     getApp()->updateActions();
580
581   // restore selected objects
582   restoreSelection( aSelectedEntries );
583
584   setUpdateEnabled( true );
585
586   QApplication::restoreOverrideCursor();
587 }
588
589 void HYDROGUI_Module::updateCommandsStatus()
590 {
591   LightApp_Module::updateCommandsStatus();
592
593   updateUndoRedoControls();
594
595   action( CopyId )->setEnabled( getDataModel()->canCopy() );
596   action( PasteId )->setEnabled( getDataModel()->canPaste() );
597 }
598
599 void HYDROGUI_Module::selectionChanged()
600 {
601   LightApp_Module::selectionChanged();
602   updateCommandsStatus();
603 }
604
605 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
606 {
607   return (HYDROGUI_DataModel*)dataModel();
608 }
609
610 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
611 {
612   return myDisplayer;
613 }
614
615 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
616 {
617   return myOCCDisplayer;
618 }
619
620 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
621 {
622   return myVTKDisplayer;
623 }
624
625 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
626 {
627   if( myViewManagerMap.contains( theId ) )
628   {
629     return myViewManagerMap[ theId ].first;
630   }
631   return NULL;
632 }
633
634 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
635 {
636   if( myViewManagerMap.contains( theId ) )
637   {
638     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
639     GraphicsView_ViewManager* aViewManager =
640       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
641     if( aViewManager )
642       return aViewManager->getViewer();
643   }
644   return NULL;
645 }
646
647 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
648 {
649   if( myViewManagerMap.contains( theId ) )
650   {
651     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
652     OCCViewer_ViewManager* aViewManager =
653       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
654     if( aViewManager )
655       return aViewManager->getOCCViewer();
656   }
657   return NULL;
658 }
659
660 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
661 {
662   if( myViewManagerMap.contains( theId ) )
663   {
664     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
665     SVTK_ViewManager* aViewManager =
666       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
667     if( aViewManager )
668       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
669   }
670   return NULL;
671 }
672
673 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
674 {
675   ViewManagerMapIterator anIter( myViewManagerMap );
676   while( anIter.hasNext() )
677   {
678     int anId = anIter.next().key();
679     const ViewManagerInfo& anInfo = anIter.value();
680     if( anInfo.first == theViewManager )
681       return anId;
682   }
683   return -1;
684 }
685
686 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
687 {
688   int anId = getViewManagerId( theViewManager );
689   if( anId != -1 )
690   {
691     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
692     return anInfo.second;
693   }
694   return VMR_Unknown;
695 }
696
697 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
698                                           const ViewManagerRole theRole )
699 {
700   int anId = getViewManagerId( theViewManager );
701   if( anId != -1 )
702   {
703     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
704     anInfo.second = theRole;
705   }
706 }
707
708 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
709                                        const Handle(HYDROData_Entity)& theObject ) const
710 {
711   if( theObject.IsNull() )
712     return false;
713
714   ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
715   if( anIter1 != myObjectStateMap.end() )
716   {
717     const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
718     Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
719     if( anIter2 != aName2ObjectStateMap.end() )
720     {
721       const ObjectState& anObjectState = anIter2.value();
722       return anObjectState.Visibility;
723     }
724   }
725   return false;
726 }
727
728 void HYDROGUI_Module::setObjectVisible( const int theViewId,
729                                         const Handle(HYDROData_Entity)& theObject,
730                                         const bool theState )
731 {
732   if( !theObject.IsNull() )
733   {
734     Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
735     ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
736     anObjectState.Visibility = theState;
737   }
738 }
739
740 /////////////////// OCC SHAPES PROCESSING
741 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
742                                                  const Handle(HYDROData_Entity)& theObject ) const
743 {
744   HYDROGUI_Shape* aResShape = NULL;
745   if( theObject.IsNull() )
746     return aResShape;
747
748   if ( myShapesMap.contains( theViewId ) )
749   {
750     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
751     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
752     {
753       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
754         continue;
755
756       aResShape = aShape;
757       break;
758     }
759   }
760
761   return aResShape;
762 }
763
764 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
765                                       const Handle(HYDROData_Entity)& theObject,
766                                       HYDROGUI_Shape*                 theShape )
767 {
768   if( theObject.IsNull() )
769     return;
770
771   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
772   aViewShapes.append( theShape );
773 }
774
775 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
776                                          const Handle(HYDROData_Entity)& theObject )
777 {
778   if ( !myShapesMap.contains( theViewId ) )
779     return;
780
781   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
782   Handle(HYDROData_Entity) anObject;
783   for ( int i = 0; i < aViewShapes.length(); )
784   {
785     HYDROGUI_Shape* aShape = aViewShapes.at( i );
786     anObject = aShape->getObject();
787     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
788     {
789       delete aShape;
790       aViewShapes.removeAt( i );
791       continue;
792     }
793
794     ++i;
795   }
796 }
797
798 void HYDROGUI_Module::removeViewShapes( const int theViewId )
799 {
800   if ( !myShapesMap.contains( theViewId ) )
801     return;
802
803   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
804   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
805   {
806     HYDROGUI_Shape* aShape = aViewShapes.at( i );
807     if ( aShape )
808       delete aShape;
809   }
810
811   myShapesMap.remove( theViewId );
812 }
813 /////////////////// END OF OCC SHAPES PROCESSING
814
815 /////////////////// VTKPrs PROCESSING
816 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
817                                                  const Handle(HYDROData_Entity)& theObject ) const
818 {
819   HYDROGUI_VTKPrs* aResShape = NULL;
820   if( theObject.IsNull() )
821     return aResShape;
822
823   if ( myVTKPrsMap.contains( theViewId ) )
824   {
825     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
826     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
827     {
828       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
829         continue;
830
831       aResShape = aShape;
832       break;
833     }
834   }
835
836   return aResShape;
837 }
838
839 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
840                                        const Handle(HYDROData_Entity)& theObject,
841                                        HYDROGUI_VTKPrs*                 theShape )
842 {
843   if( theObject.IsNull() )
844     return;
845
846   // Compute the new global Z range from the added presentation and the old global Z range.
847   double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
848   double* aRange = theShape->getInternalZRange();
849   bool anIsUpdate = false;
850   if ( aRange[0] < aGlobalRange[0] )
851   {
852     aGlobalRange[0] = aRange[0];
853     anIsUpdate = true;
854   }
855   if ( aRange[1] > aGlobalRange[1] )
856   {
857     aGlobalRange[1] = aRange[1];
858     anIsUpdate = true;
859   }
860
861   //if ( anIsUpdate )
862   //{
863     updateVTKZRange( theViewId, aGlobalRange );
864   //}
865
866   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
867   aViewShapes.append( theShape );
868 }
869
870 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
871                                           const Handle(HYDROData_Entity)& theObject )
872 {
873   if ( !myVTKPrsMap.contains( theViewId ) )
874     return;
875
876   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
877   Handle(HYDROData_Entity) anObject;
878   for ( int i = 0; i < aViewShapes.length(); )
879   {
880     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
881     anObject = aShape->getObject();
882     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
883     {
884       delete aShape;
885       aViewShapes.removeAt( i );
886       continue;
887     }
888
889     ++i;
890   }
891
892   // Invalidate global Z range
893   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
894   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
895 }
896
897 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
898 {
899   if ( !myVTKPrsMap.contains( theViewId ) )
900     return;
901
902   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
903   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
904   {
905     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
906     if ( aShape )
907       delete aShape;
908   }
909
910   myVTKPrsMap.remove( theViewId );
911 }
912
913 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
914 {
915   if ( myVTKPrsMap.contains( theViewId ) )
916   {
917     // For the given viewer id update all VTK presentations ...
918     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
919     HYDROGUI_VTKPrs* aShape;
920     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
921     {
922       aShape = aViewShapes.at( i );
923       if ( aShape )
924       {
925         aShape->setZRange( theRange );
926       }
927     }
928   }
929   // ... and update the global color legend scalar bar.
930   getVTKDisplayer()->SetZRange( theViewId, theRange );
931 }
932 /////////////////// END OF VTKPrs PROCESSING
933
934 CAM_DataModel* HYDROGUI_Module::createDataModel()
935 {
936   return new HYDROGUI_DataModel( this );
937 }
938
939 void HYDROGUI_Module::customEvent( QEvent* e )
940 {
941   int aType = e->type();
942   if ( aType == NewViewEvent )
943   {
944     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
945     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
946     {
947       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
948       {
949         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
950         ViewManagerRole aRole = getViewManagerRole( aViewManager );
951
952         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
953         {
954           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
955             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
956
957           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
958           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
959           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
960
961           //ouv: temporarily commented
962           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
963         }
964
965         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
966           update( UF_Viewer );
967
968         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
969       }
970     }
971   }
972 }
973
974 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
975 {
976   QEvent::Type aType = theEvent->type();
977   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
978   {
979     if( aType == QEvent::Show )
980     {
981       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
982       e->setData( theObj );
983       QApplication::postEvent( this, e );
984       theObj->removeEventFilter( this );
985     }
986   }
987   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
988   {
989     if( aType == QEvent::Leave )
990     {
991       SUIT_Desktop* aDesktop = getApp()->desktop();
992       if ( aDesktop && aDesktop->statusBar() ) {
993         aDesktop->statusBar()->clearMessage();
994       }
995     }
996   }
997
998   return LightApp_Module::eventFilter( theObj, theEvent );
999 }
1000
1001 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1002 {
1003   LightApp_Module::onViewManagerAdded( theViewManager );
1004
1005   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1006   { 
1007     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1008              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1009   }
1010   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1011   {
1012     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1013              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1014     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1015              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1016   }
1017
1018   createSelector( theViewManager ); // replace the default selector
1019
1020   ViewManagerInfo anInfo( theViewManager, VMR_General );
1021   myViewManagerMap.insert( ViewManagerId++, anInfo );
1022 }
1023
1024 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1025 {
1026   LightApp_Module::onViewManagerRemoved( theViewManager );
1027
1028   createSelector( theViewManager ); // replace the default selector
1029
1030   int anId = getViewManagerId( theViewManager );
1031   if( anId != -1 )
1032   {
1033     OCCViewer_ViewManager* anOCCViewManager =
1034       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1035     if ( anOCCViewManager )
1036     {
1037       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1038       if ( anOCCViewer )
1039         removeViewShapes( (size_t)anOCCViewer );
1040     }
1041
1042     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1043     {
1044       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1045       if ( aVTKViewer )
1046       {
1047         getVTKDisplayer()->DeleteScalarBar( anId );
1048         removeViewShapes( (size_t)aVTKViewer );
1049       }
1050     }
1051
1052     myViewManagerMap.remove( anId );
1053   }
1054 }
1055
1056 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1057 {
1058   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1059   {
1060     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1061     {
1062       aViewFrame->installEventFilter( this );
1063
1064       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1065
1066       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1067                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1068     }
1069   }
1070   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1071   {
1072     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1073     {
1074       aViewFrame->onTopView();
1075
1076       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1077
1078       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1079       if ( aViewPort ) {
1080         aViewPort->installEventFilter( this );
1081       }
1082     }
1083   }
1084 }
1085
1086 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1087 {
1088   /* ouv: currently unused
1089   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1090   {
1091     SUIT_ViewManager* aViewManager = 0;
1092
1093     QObject* aParent = aViewPort;
1094     while( aParent = aParent->parent() )
1095     {
1096       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1097       {
1098         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1099         {
1100           aViewManager = aViewer->getViewManager();
1101           break;
1102         }
1103       }
1104     }
1105
1106     if( !aViewManager )
1107       return;
1108
1109     double aMouseX = theEvent->scenePos().x();
1110     double aMouseY = theEvent->scenePos().y();
1111
1112     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1113     if( aRole == VMR_General )
1114     {
1115       int aXDeg = 0, aYDeg = 0;
1116       int aXMin = 0, aYMin = 0;
1117       double aXSec = 0, aYSec = 0;
1118       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1119       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1120
1121       QString aDegSymbol( QChar( 0x00B0 ) );
1122       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1123       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1124
1125       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1126     }
1127     else if( aRole == VMR_TransformImage )
1128       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1129   }
1130   */
1131 }
1132
1133 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1134                                     const bool theIsInit, 
1135                                     const bool theIsForced, 
1136                                     const bool theDoFitAll )
1137 {
1138   QList<int> aViewManagerIdList;
1139
1140   // currently, all views are updated
1141   ViewManagerMapIterator anIter( myViewManagerMap );
1142   while( anIter.hasNext() )
1143   { 
1144     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1145
1146     if ( theDisplayer->IsApplicable( aViewManager ) )
1147     {
1148       int anId = anIter.key();
1149       aViewManagerIdList.append( anId );
1150     }
1151   }
1152
1153   QListIterator<int> anIdIter( aViewManagerIdList );
1154   while( anIdIter.hasNext() )
1155   {
1156     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1157   }
1158 }
1159
1160 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1161 {
1162   if( !theViewManager )
1163     return;
1164
1165   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1166   if( !aSelectionMgr )
1167     return;
1168
1169   QString aViewType = theViewManager->getType();
1170   if( aViewType != GraphicsView_Viewer::Type() &&
1171       aViewType != OCCViewer_Viewer::Type())
1172     return;
1173
1174   QList<SUIT_Selector*> aSelectorList;
1175   aSelectionMgr->selectors( aViewType, aSelectorList );
1176
1177   // disable all alien selectors
1178   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1179   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1180   {
1181     SUIT_Selector* aSelector = *anIter;
1182     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1183                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1184                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1185       aSelector->setEnabled( false );
1186   }
1187
1188   if ( aViewType == GraphicsView_Viewer::Type() )
1189   {
1190     GraphicsView_ViewManager* aViewManager =
1191       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1192     if( aViewManager )
1193       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1194   }
1195   else if ( aViewType == OCCViewer_Viewer::Type() )
1196   {
1197     OCCViewer_ViewManager* aViewManager =
1198       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1199     if( aViewManager )
1200       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1201   }
1202 }
1203
1204 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1205 {
1206   bool aPrevState = myIsUpdateEnabled;
1207   myIsUpdateEnabled = theState;
1208   return aPrevState;
1209 }
1210
1211 bool HYDROGUI_Module::isUpdateEnabled() const
1212 {
1213   return myIsUpdateEnabled;
1214 }
1215
1216 QStringList HYDROGUI_Module::storeSelection() const
1217 {
1218   QStringList anEntryList;
1219   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1220   {
1221     SUIT_DataOwnerPtrList aList( true );
1222     aSelectionMgr->selected( aList );
1223
1224     SUIT_DataOwnerPtrList::iterator anIter;
1225     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1226     {
1227       const LightApp_DataOwner* anOwner = 
1228         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1229       if( anOwner )
1230         anEntryList.append( anOwner->entry() );
1231     }
1232   }
1233   return anEntryList;
1234 }
1235
1236 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1237 {
1238   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1239   {
1240     SUIT_DataOwnerPtrList aList( true );
1241     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1242       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1243     aSelectionMgr->setSelected( aList );
1244   }
1245 }
1246
1247 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1248 {
1249   OCCViewer_ViewWindow* anOCCViewWindow = 
1250     dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1251   if ( !anOCCViewWindow ) {
1252     return;
1253   }
1254
1255   // Get the selected point coordinates
1256   OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1257   if ( !aViewPort ) {
1258     return;
1259   }
1260
1261   gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(), 
1262                                                 aViewPort->getView() );
1263
1264   // Show the coordinates in the status bar
1265   SUIT_Desktop* aDesktop = getApp()->desktop();
1266   if ( aDesktop && aDesktop->statusBar() ) {
1267     QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1268     QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1269     aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
1270   }
1271 }