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