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