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