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