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