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