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