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