Salome HOME
Bug #226: children are not shown under Polyline 3D, Channel and Digue.
[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->addAction( action( BathymetryBoundsId ) );
518         theMenu->addSeparator();
519       }
520       else if( anIsPolyline )
521       {
522         theMenu->addAction( action( EditPolylineId ) );
523         theMenu->addSeparator();
524       }
525       else if( anIsPolyline3D )
526       {
527         theMenu->addAction( action( EditPolyline3DId ) );
528         theMenu->addSeparator();
529       }
530       else if( anIsProfile )
531       {
532         theMenu->addAction( action( EditProfileId ) );
533         theMenu->addAction( action( SelectedGeoreferencementId ) );
534         theMenu->addSeparator();
535       }
536       else if( anIsCalculation )
537       {
538         theMenu->addAction( action( EditCalculationId ) );
539         theMenu->addAction( action( ExportCalculationId ) );
540         theMenu->addSeparator();
541       }
542       else if( anIsImmersibleZone )
543       {
544         theMenu->addAction( action( EditImmersibleZoneId ) );
545         theMenu->addSeparator();
546       }
547       else if( anIsStream )
548       {
549         theMenu->addAction( action( EditStreamId ) );
550         theMenu->addSeparator();
551       }
552       else if( anIsChannel )
553       {
554         theMenu->addAction( action( EditChannelId ) );
555         theMenu->addSeparator();
556       }
557       else if( anIsDigue )
558       {
559         theMenu->addAction( action( EditDigueId ) );
560         theMenu->addSeparator();
561       }
562       else if( anIsVisualState && anIsObjectBrowser )
563       {
564         theMenu->addAction( action( SaveVisualStateId ) );
565         theMenu->addAction( action( LoadVisualStateId ) );
566         theMenu->addSeparator();
567       }
568
569       // Add set color action for geometrical objects
570       if ( anIsObjectCanBeColored )
571       {
572         theMenu->addAction( action( SetColorId ) );
573         theMenu->addSeparator();
574       }
575     } else if ( anAllAreProfiles ) {
576       theMenu->addAction( action( SelectedGeoreferencementId ) );
577       theMenu->addSeparator();
578     }
579
580     if( !anIsDummyObject3D )
581       theMenu->addAction( action( DeleteId ) );
582     theMenu->addSeparator();
583
584     if( anIsImage || anIsPolyline || anIsPolyline3D || 
585         anIsImmersibleZone || anIsZone || anIsRegion ||
586         anIsBathymetry || anIsObstacle || anIsStream ||
587         anIsChannel || anIsDigue || anIsDummyObject3D ||
588         anIsValidProfile || anIsGroup )
589     {
590       if( anIsHiddenInSelection )
591         theMenu->addAction( action( ShowId ) );
592       theMenu->addAction( action( ShowOnlyId ) );
593       if( anIsVisibleInSelection )
594         theMenu->addAction( action( HideId ) );
595       theMenu->addSeparator();
596     }
597   }
598
599   if ( anIsOCCView )
600   {
601     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
602     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
603     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
604       theMenu->addAction( action( DeleteId ) );
605   }
606
607   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
608   {
609     theMenu->addAction( action( ShowAllId ) );
610     theMenu->addAction( action( HideAllId ) );
611     theMenu->addSeparator();
612   }
613 }
614
615 void HYDROGUI_Module::update( const int flags )
616 {
617   if( !isUpdateEnabled() )
618     return;
619
620   QApplication::setOverrideCursor( Qt::WaitCursor );
621
622   // To prevent calling this method recursively
623   // from one of the methods called below
624   setUpdateEnabled( false );
625
626   // store selected objects
627   QStringList aSelectedEntries = storeSelection();
628
629   bool aDoFitAll = flags & UF_FitAll;
630   if( ( flags & UF_Viewer ) )
631     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
632
633   if( ( flags & UF_OCCViewer ) )
634     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
635
636   if( ( flags & UF_VTKViewer ) )
637     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
638
639   if( ( flags & UF_Model ) && getDataModel() && getApp() )
640   {
641     getDataModel()->update( getStudyId() );
642
643     // Temporary workaround to prevent breaking
644     // the selection in the object browser.
645     // Note: processEvents() should be called after updateGV(),
646     // otherwise the application crashes from time to time.
647     //RKV: qApp->processEvents(); 
648     getApp()->updateObjectBrowser( true );
649   }
650
651   // Object browser is currently updated by using UF_Model flag
652   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
653     getApp()->updateObjectBrowser( true );
654
655   if( ( flags & UF_Controls ) && getApp() )
656     getApp()->updateActions();
657
658   // restore selected objects
659   restoreSelection( aSelectedEntries );
660
661   setUpdateEnabled( true );
662
663   QApplication::restoreOverrideCursor();
664 }
665
666 void HYDROGUI_Module::updateCommandsStatus()
667 {
668   LightApp_Module::updateCommandsStatus();
669
670   updateUndoRedoControls();
671
672   action( CopyId )->setEnabled( getDataModel()->canCopy() );
673   action( PasteId )->setEnabled( getDataModel()->canPaste() );
674 }
675
676 void HYDROGUI_Module::selectionChanged()
677 {
678   LightApp_Module::selectionChanged();
679   updateCommandsStatus();
680 }
681
682 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
683 {
684   return (HYDROGUI_DataModel*)dataModel();
685 }
686
687 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
688 {
689   return myDisplayer;
690 }
691
692 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
693 {
694   return myOCCDisplayer;
695 }
696
697 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
698 {
699   return myVTKDisplayer;
700 }
701
702 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
703 {
704   if( myViewManagerMap.contains( theId ) )
705   {
706     return myViewManagerMap[ theId ].first;
707   }
708   return NULL;
709 }
710
711 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
712 {
713   if( myViewManagerMap.contains( theId ) )
714   {
715     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
716     GraphicsView_ViewManager* aViewManager =
717       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
718     if( aViewManager )
719       return aViewManager->getViewer();
720   }
721   return NULL;
722 }
723
724 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
725 {
726   if( myViewManagerMap.contains( theId ) )
727   {
728     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
729     OCCViewer_ViewManager* aViewManager =
730       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
731     if( aViewManager )
732       return aViewManager->getOCCViewer();
733   }
734   return NULL;
735 }
736
737 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
738 {
739   if( myViewManagerMap.contains( theId ) )
740   {
741     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
742     SVTK_ViewManager* aViewManager =
743       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
744     if( aViewManager )
745       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
746   }
747   return NULL;
748 }
749
750 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
751 {
752   ViewManagerMapIterator anIter( myViewManagerMap );
753   while( anIter.hasNext() )
754   {
755     int anId = anIter.next().key();
756     const ViewManagerInfo& anInfo = anIter.value();
757     if( anInfo.first == theViewManager )
758       return anId;
759   }
760   return -1;
761 }
762
763 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
764 {
765   int anId = getViewManagerId( theViewManager );
766   if( anId != -1 )
767   {
768     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
769     return anInfo.second;
770   }
771   return VMR_Unknown;
772 }
773
774 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
775                                           const ViewManagerRole theRole )
776 {
777   int anId = getViewManagerId( theViewManager );
778   if( anId != -1 )
779   {
780     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
781     anInfo.second = theRole;
782   }
783 }
784
785 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
786                                        const Handle(HYDROData_Entity)& theObject ) const
787 {
788   if( theObject.IsNull() )
789     return false;
790
791   ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
792   if( anIter1 != myObjectStateMap.end() )
793   {
794     const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
795     Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
796     if( anIter2 != aName2ObjectStateMap.end() )
797     {
798       const ObjectState& anObjectState = anIter2.value();
799       return anObjectState.Visibility;
800     }
801   }
802   return false;
803 }
804
805 void HYDROGUI_Module::setObjectVisible( const int theViewId,
806                                         const Handle(HYDROData_Entity)& theObject,
807                                         const bool theState )
808 {
809   if( !theObject.IsNull() )
810   {
811     Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
812     ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
813     anObjectState.Visibility = theState;
814   }
815 }
816
817 /////////////////// OCC SHAPES PROCESSING
818 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
819                                                  const Handle(HYDROData_Entity)& theObject ) const
820 {
821   HYDROGUI_Shape* aResShape = NULL;
822   if( theObject.IsNull() )
823     return aResShape;
824
825   if ( myShapesMap.contains( theViewId ) )
826   {
827     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
828     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
829     {
830       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
831         continue;
832
833       aResShape = aShape;
834       break;
835     }
836   }
837
838   return aResShape;
839 }
840
841 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
842                                       const Handle(HYDROData_Entity)& theObject,
843                                       HYDROGUI_Shape*                 theShape )
844 {
845   if( theObject.IsNull() )
846     return;
847
848   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
849   aViewShapes.append( theShape );
850 }
851
852 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
853                                          const Handle(HYDROData_Entity)& theObject )
854 {
855   if ( !myShapesMap.contains( theViewId ) )
856     return;
857
858   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
859   Handle(HYDROData_Entity) anObject;
860   for ( int i = 0; i < aViewShapes.length(); )
861   {
862     HYDROGUI_Shape* aShape = aViewShapes.at( i );
863     anObject = aShape->getObject();
864     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
865     {
866       delete aShape;
867       aViewShapes.removeAt( i );
868       continue;
869     }
870
871     ++i;
872   }
873 }
874
875 void HYDROGUI_Module::removeViewShapes( const int theViewId )
876 {
877   if ( !myShapesMap.contains( theViewId ) )
878     return;
879
880   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
881   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
882   {
883     HYDROGUI_Shape* aShape = aViewShapes.at( i );
884     if ( aShape )
885       delete aShape;
886   }
887
888   myShapesMap.remove( theViewId );
889 }
890 /////////////////// END OF OCC SHAPES PROCESSING
891
892 /////////////////// VTKPrs PROCESSING
893 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
894                                                  const Handle(HYDROData_Entity)& theObject ) const
895 {
896   HYDROGUI_VTKPrs* aResShape = NULL;
897   if( theObject.IsNull() )
898     return aResShape;
899
900   if ( myVTKPrsMap.contains( theViewId ) )
901   {
902     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
903     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
904     {
905       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
906         continue;
907
908       aResShape = aShape;
909       break;
910     }
911   }
912
913   return aResShape;
914 }
915
916 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
917                                        const Handle(HYDROData_Entity)& theObject,
918                                        HYDROGUI_VTKPrs*                 theShape )
919 {
920   if( theObject.IsNull() )
921     return;
922
923   if( theShape && theShape->needScalarBar() )
924   {
925     // Compute the new global Z range from the added presentation and the old global Z range.
926     double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
927     double* aRange = theShape->getInternalZRange();
928     bool anIsUpdate = false;
929     if ( aRange[0] < aGlobalRange[0] )
930     {
931       aGlobalRange[0] = aRange[0];
932       anIsUpdate = true;
933     }
934     if ( aRange[1] > aGlobalRange[1] )
935     {
936       aGlobalRange[1] = aRange[1];
937       anIsUpdate = true;
938     }
939
940     //if ( anIsUpdate )
941     //{
942       updateVTKZRange( theViewId, aGlobalRange );
943     //}
944   }
945
946   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
947   aViewShapes.append( theShape );
948 }
949
950 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
951                                           const Handle(HYDROData_Entity)& theObject )
952 {
953   if ( !myVTKPrsMap.contains( theViewId ) )
954     return;
955
956   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
957   Handle(HYDROData_Entity) anObject;
958   for ( int i = 0; i < aViewShapes.length(); )
959   {
960     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
961     anObject = aShape->getObject();
962     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
963     {
964       delete aShape;
965       aViewShapes.removeAt( i );
966       continue;
967     }
968
969     ++i;
970   }
971
972   // Invalidate global Z range
973   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
974   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
975 }
976
977 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
978 {
979   if ( !myVTKPrsMap.contains( theViewId ) )
980     return;
981
982   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
983   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
984   {
985     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
986     if ( aShape )
987       delete aShape;
988   }
989
990   myVTKPrsMap.remove( theViewId );
991 }
992
993 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
994 {
995   if ( myVTKPrsMap.contains( theViewId ) )
996   {
997     // For the given viewer id update all VTK presentations ...
998     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
999     HYDROGUI_VTKPrs* aShape;
1000     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1001     {
1002       aShape = aViewShapes.at( i );
1003       if ( aShape && aShape->needScalarBar() )
1004       {
1005         aShape->setZRange( theRange );
1006       }
1007     }
1008   }
1009   // ... and update the global color legend scalar bar.
1010   getVTKDisplayer()->SetZRange( theViewId, theRange );
1011 }
1012 /////////////////// END OF VTKPrs PROCESSING
1013
1014 CAM_DataModel* HYDROGUI_Module::createDataModel()
1015 {
1016   return new HYDROGUI_DataModel( this );
1017 }
1018
1019 void HYDROGUI_Module::customEvent( QEvent* e )
1020 {
1021   int aType = e->type();
1022   if ( aType == NewViewEvent )
1023   {
1024     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1025     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1026     {
1027       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1028       {
1029         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1030         ViewManagerRole aRole = getViewManagerRole( aViewManager );
1031
1032         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1033         {
1034           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1035             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1036
1037           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1038           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1039           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1040
1041           //ouv: temporarily commented
1042           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1043         }
1044
1045         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1046           update( UF_Viewer );
1047
1048         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1049       }
1050     }
1051   }
1052 }
1053
1054 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1055 {
1056   QEvent::Type aType = theEvent->type();
1057   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1058   {
1059     if( aType == QEvent::Show )
1060     {
1061       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1062       e->setData( theObj );
1063       QApplication::postEvent( this, e );
1064       theObj->removeEventFilter( this );
1065     }
1066   }
1067   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1068   {
1069     if( aType == QEvent::Leave )
1070     {
1071       SUIT_Desktop* aDesktop = getApp()->desktop();
1072       if ( aDesktop && aDesktop->statusBar() ) {
1073         aDesktop->statusBar()->clearMessage();
1074       }
1075     }
1076   }
1077
1078   return LightApp_Module::eventFilter( theObj, theEvent );
1079 }
1080
1081 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1082 {
1083   LightApp_Module::onViewManagerAdded( theViewManager );
1084
1085   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1086   { 
1087     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1088              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1089   }
1090   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1091   {
1092     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1093              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1094     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1095              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1096   }
1097
1098   createSelector( theViewManager ); // replace the default selector
1099
1100   ViewManagerInfo anInfo( theViewManager, VMR_General );
1101   myViewManagerMap.insert( ViewManagerId++, anInfo );
1102 }
1103
1104 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1105 {
1106   LightApp_Module::onViewManagerRemoved( theViewManager );
1107
1108   createSelector( theViewManager ); // replace the default selector
1109
1110   int anId = getViewManagerId( theViewManager );
1111   if( anId != -1 )
1112   {
1113     OCCViewer_ViewManager* anOCCViewManager =
1114       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1115     if ( anOCCViewManager )
1116     {
1117       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1118       if ( anOCCViewer )
1119         removeViewShapes( (size_t)anOCCViewer );
1120     }
1121
1122     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1123     {
1124       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1125       if ( aVTKViewer )
1126       {
1127         getVTKDisplayer()->EraseScalarBar( anId, true );
1128         removeViewShapes( (size_t)aVTKViewer );
1129       }
1130     }
1131
1132     myViewManagerMap.remove( anId );
1133   }
1134 }
1135
1136 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1137 {
1138   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1139   {
1140     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1141     {
1142       aViewFrame->installEventFilter( this );
1143
1144       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1145
1146       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1147                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1148     }
1149   }
1150   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1151   {
1152     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1153     {
1154       aViewFrame->onTopView();
1155
1156       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1157
1158       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1159       if ( aViewPort ) {
1160         aViewPort->installEventFilter( this );
1161       }
1162     }
1163   }
1164 }
1165
1166 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1167 {
1168   /* ouv: currently unused
1169   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1170   {
1171     SUIT_ViewManager* aViewManager = 0;
1172
1173     QObject* aParent = aViewPort;
1174     while( aParent = aParent->parent() )
1175     {
1176       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1177       {
1178         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1179         {
1180           aViewManager = aViewer->getViewManager();
1181           break;
1182         }
1183       }
1184     }
1185
1186     if( !aViewManager )
1187       return;
1188
1189     double aMouseX = theEvent->scenePos().x();
1190     double aMouseY = theEvent->scenePos().y();
1191
1192     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1193     if( aRole == VMR_General )
1194     {
1195       int aXDeg = 0, aYDeg = 0;
1196       int aXMin = 0, aYMin = 0;
1197       double aXSec = 0, aYSec = 0;
1198       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1199       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1200
1201       QString aDegSymbol( QChar( 0x00B0 ) );
1202       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1203       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1204
1205       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1206     }
1207     else if( aRole == VMR_TransformImage )
1208       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1209   }
1210   */
1211 }
1212
1213 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1214                                     const bool theIsInit, 
1215                                     const bool theIsForced, 
1216                                     const bool theDoFitAll )
1217 {
1218   QList<int> aViewManagerIdList;
1219
1220   // currently, all views are updated
1221   ViewManagerMapIterator anIter( myViewManagerMap );
1222   while( anIter.hasNext() )
1223   { 
1224     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1225
1226     if ( theDisplayer->IsApplicable( aViewManager ) )
1227     {
1228       int anId = anIter.key();
1229       aViewManagerIdList.append( anId );
1230     }
1231   }
1232
1233   QListIterator<int> anIdIter( aViewManagerIdList );
1234   while( anIdIter.hasNext() )
1235   {
1236     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1237   }
1238 }
1239
1240 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1241 {
1242   if( !theViewManager )
1243     return;
1244
1245   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1246   if( !aSelectionMgr )
1247     return;
1248
1249   QString aViewType = theViewManager->getType();
1250   if( aViewType != GraphicsView_Viewer::Type() &&
1251       aViewType != OCCViewer_Viewer::Type())
1252     return;
1253
1254   QList<SUIT_Selector*> aSelectorList;
1255   aSelectionMgr->selectors( aViewType, aSelectorList );
1256
1257   // disable all alien selectors
1258   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1259   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1260   {
1261     SUIT_Selector* aSelector = *anIter;
1262     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1263                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1264                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1265       aSelector->setEnabled( false );
1266   }
1267
1268   if ( aViewType == GraphicsView_Viewer::Type() )
1269   {
1270     GraphicsView_ViewManager* aViewManager =
1271       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1272     if( aViewManager )
1273       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1274   }
1275   else if ( aViewType == OCCViewer_Viewer::Type() )
1276   {
1277     OCCViewer_ViewManager* aViewManager =
1278       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1279     if( aViewManager )
1280       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1281   }
1282 }
1283
1284 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1285 {
1286   bool aPrevState = myIsUpdateEnabled;
1287   myIsUpdateEnabled = theState;
1288   return aPrevState;
1289 }
1290
1291 bool HYDROGUI_Module::isUpdateEnabled() const
1292 {
1293   return myIsUpdateEnabled;
1294 }
1295
1296 QStringList HYDROGUI_Module::storeSelection() const
1297 {
1298   QStringList anEntryList;
1299   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1300   {
1301     SUIT_DataOwnerPtrList aList( true );
1302     aSelectionMgr->selected( aList );
1303
1304     SUIT_DataOwnerPtrList::iterator anIter;
1305     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1306     {
1307       const LightApp_DataOwner* anOwner = 
1308         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1309       if( anOwner )
1310         anEntryList.append( anOwner->entry() );
1311     }
1312   }
1313   return anEntryList;
1314 }
1315
1316 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1317 {
1318   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1319   {
1320     SUIT_DataOwnerPtrList aList( true );
1321     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1322       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1323     aSelectionMgr->setSelected( aList );
1324   }
1325 }
1326
1327 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1328 {
1329   OCCViewer_ViewWindow* anOCCViewWindow = 
1330     dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1331   if ( !anOCCViewWindow ) {
1332     return;
1333   }
1334
1335   // Get the selected point coordinates
1336   OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1337   if ( !aViewPort ) {
1338     return;
1339   }
1340
1341   gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(), 
1342                                                 aViewPort->getView() );
1343
1344   // Show the coordinates in the status bar
1345   SUIT_Desktop* aDesktop = getApp()->desktop();
1346   if ( aDesktop && aDesktop->statusBar() ) {
1347     QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1348     QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1349     aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
1350   }
1351 }