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