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