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