]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Module.cxx
Salome HOME
54d2a851049d52a4fdabb436b279281abcaf460e
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_Module.h"
20
21 #include "HYDROGUI.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_DataObject.h"
24 #include "HYDROGUI_Displayer.h"
25 #include "HYDROGUI_GVSelector.h"
26 #include "HYDROGUI_InputPanel.h"
27 #include "HYDROGUI_ObjSelector.h"
28 #include "HYDROGUI_OCCDisplayer.h"
29 #include "HYDROGUI_OCCSelector.h"
30 #include "HYDROGUI_Operations.h"
31 #include "HYDROGUI_PrsImage.h"
32 #include "HYDROGUI_Tool.h"
33 #include "HYDROGUI_Tool2.h"
34 #include "HYDROGUI_UpdateFlags.h"
35 #include "HYDROGUI_Shape.h"
36 #include "HYDROGUI_VTKPrs.h"
37 #include "HYDROGUI_VTKPrsDisplayer.h"
38 #include "HYDROGUI_AbstractDisplayer.h"
39 #include "HYDROGUI_PolylineOp.h"
40 #include "HYDROGUI_SetColorOp.h"
41 #include "HYDROGUI_ImportGeomObjectOp.h"
42 #include "HYDROGUI_ShowHideOp.h"
43 #include "HYDROGUI_Overview.h"
44 #include <HYDROGUI_ProfileDlg.h>
45 #include <HYDROData_Tool.h>
46 #include <HYDROData_Image.h>
47 #include <HYDROData_Stream.h>
48 #include <HYDROData_Profile.h>
49 #include <HYDROData_Lambert93.h>
50 #include <HYDROData_Polyline3D.h>
51 #include <HYDROData_StricklerTable.h>
52 #include <HYDROData_ArtificialObject.h>
53 #include <HYDROData_NaturalObject.h>
54
55 #include <HYDROData_OperationsFactory.h>
56
57 #include <CurveCreator_Utils.hxx>
58
59 #include <GraphicsView_ViewFrame.h>
60 #include <GraphicsView_ViewManager.h>
61 #include <GraphicsView_ViewPort.h>
62 #include <GraphicsView_Viewer.h>
63
64 #include <ImageComposer_CutOperator.h>
65 #include <ImageComposer_CropOperator.h>
66 #include <ImageComposer_FuseOperator.h>
67
68 #include <LightApp_Application.h>
69 #include <LightApp_DataOwner.h>
70 #include <LightApp_GVSelector.h>
71 #include <LightApp_SelectionMgr.h>
72 #include <LightApp_UpdateFlags.h>
73
74 #include <SalomeApp_Study.h>
75
76 #include <OCCViewer_ViewFrame.h>
77 #include <OCCViewer_ViewManager.h>
78 #include <OCCViewer_ViewModel.h>
79
80 #include <SALOME_Event.h>
81
82 #include <SUIT_DataBrowser.h>
83 #include <SUIT_DataObject.h>
84 #include <SUIT_ViewManager.h>
85 #include <SUIT_ResourceMgr.h>
86 #include <SUIT_Desktop.h>
87 #include <SUIT_Study.h>
88 #include <SUIT_Session.h>
89
90 #include <SVTK_ViewManager.h>
91 #include <SVTK_ViewModel.h>
92 #include <SVTK_ViewWindow.h>
93 #include <SVTK_Selector.h>
94
95 #include <OCCViewer_ViewPort3d.h>
96
97 #include <GEOMUtils.hxx>
98 #include <GeometryGUI.h>
99
100 #include <SALOMEDS_wrap.hxx>
101
102 #include <QAction>
103 #include <QApplication>
104 #include <QGraphicsSceneMouseEvent>
105 #include <QMenu>
106 #include <QMouseEvent>
107 #include <QStatusBar>
108 #include <QCursor>
109
110 static int ViewManagerId = 0;
111
112 extern "C" HYDRO_EXPORT CAM_Module* createModule()
113 {
114   return new HYDROGUI_Module();
115 }
116
117 extern "C" HYDRO_EXPORT char* getModuleVersion()
118 {
119   return (char*)HYDRO_VERSION;
120 }
121
122 HYDROGUI_Module::HYDROGUI_Module()
123 : LightApp_Module( "HYDRO" ),
124   myDisplayer( 0 ),
125   myOCCDisplayer( 0 ),
126   myIsUpdateEnabled( true ),
127   myOverview( 0 )
128 {
129 }
130
131 HYDROGUI_Module::~HYDROGUI_Module()
132 {
133 }
134
135 int HYDROGUI_Module::getStudyId() const
136 {
137   LightApp_Application* anApp = getApp();
138   return anApp ? anApp->activeStudy()->id() : 0;
139 }
140
141 void HYDROGUI_Module::initialize( CAM_Application* theApp )
142 {
143   LightApp_Module::initialize( theApp );
144
145   createActions();
146   createUndoRedoActions();
147   createMenus();
148   createPopups();
149   createToolbars();
150
151   setMenuShown( false );
152   setToolShown( false );
153
154   myDisplayer = new HYDROGUI_Displayer( this );
155   myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
156   myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
157 }
158
159 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
160 {
161   bool aRes = LightApp_Module::activateModule( theStudy );
162
163   LightApp_Application* anApp = getApp();
164   SUIT_Desktop* aDesktop = anApp->desktop();
165
166   getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
167
168   setMenuShown( true );
169   setToolShown( true );
170
171 #ifndef DISABLE_PYCONSOLE
172   aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), 
173                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
174 #endif
175
176   // Remove defunct view managers from the map.
177   // It's essential to do this before "update( UF_All )" call!
178   QList<int> anObsoleteIds;
179   ViewManagerList anAllViewManagers = anApp->viewManagers();
180   ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
181   ViewManagerMapIterator anIter( myViewManagerMap );
182   while( anIter.hasNext() ) {
183     int anId = anIter.next().key();
184     const ViewManagerInfo& anInfo = anIter.value();
185   
186     aHydroViewManagers << anInfo.first;
187
188     if ( !anAllViewManagers.contains( anInfo.first ) ) {
189       anObsoleteIds << anId;
190     }
191   }
192   foreach ( const int anId, anObsoleteIds ) {
193     myViewManagerMap.remove( anId );
194     myObjectStateMap.remove( anId );
195     myShapesMap.remove( anId );
196     myVTKPrsMap.remove( anId );
197   }
198   // Replace the default selector for all view managers.
199   // Add view managers created outside of HYDRO module to the map.
200   foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
201     createSelector( aViewManager ); // replace the default selector
202     if ( !aHydroViewManagers.contains( aViewManager ) ) {
203       ViewManagerInfo anInfo( aViewManager, VMR_General );
204       myViewManagerMap.insert( ViewManagerId++, anInfo );
205     }
206   }
207
208   update( UF_All );
209
210   updateCommandsStatus();
211
212   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
213
214   ViewManagerList anOCCViewManagers;
215   anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
216
217   foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
218   {
219     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
220              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
221     connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
222              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
223
224     OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
225     if( occ_mgr )
226     {
227       occ_mgr->setChainedOperations( true );//TODO: via preferences
228     }
229
230     foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
231     {
232       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
233       if ( aViewFrame && aViewFrame->getViewPort() )
234       {
235         aViewFrame->getViewPort()->installEventFilter( this );
236       }
237     }
238   }
239
240   preferencesChanged( "HYDRO", "zoom_shutoff" );
241
242   preferencesChanged( "HYDRO", "chained_panning" );
243
244   // Load GEOM data
245   SalomeApp_Study* aStudy = 
246     dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
247   if ( aStudy ) {
248     SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
249     GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
250     if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
251       SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
252       SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
253       if( !GEOM_var->_is_nil() ) {
254         aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
255       }
256     }
257   }
258
259
260 //  SUIT_DataBrowser* ob = getApp()->objectBrowser();
261 //  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
262 //  treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
263
264   return aRes;
265 }
266
267 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
268 {
269   /* Issues ## 68, 88.
270   ViewManagerMapIterator anIter( myViewManagerMap );
271   while( anIter.hasNext() )
272     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
273       getApp()->removeViewManager( aViewManager );
274   myViewManagerMap.clear();
275   */
276
277   ViewManagerList anOCCViewManagers;
278   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
279   foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
280   {
281     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
282                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
283
284     OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
285     if( occ_mgr )
286     {
287       occ_mgr->setChainedOperations( false );
288       setAutoZoom( occ_mgr, true );
289     }
290   }
291
292   /* Issues ## 68, 88.
293   myObjectStateMap.clear();
294   myShapesMap.clear();
295   myVTKPrsMap.clear();
296   */
297
298   // clear the status bar
299   SUIT_Desktop* aDesktop = getApp()->desktop();
300   if ( aDesktop && aDesktop->statusBar() ) {
301     aDesktop->statusBar()->clearMessage();
302   }
303
304   // clear the data model's list of copying objects
305   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
306
307   setMenuShown( false );
308   setToolShown( false );
309
310   getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
311
312   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
313
314   myActiveOperationMap.clear();
315
316   myViewManagerMap.clear();
317
318   return LightApp_Module::deactivateModule( theStudy );
319 }
320
321 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
322 {
323   static bool inWindows = false;
324   if( inWindows )
325     return;
326
327   theMap.clear();
328   theMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
329 #ifndef DISABLE_PYCONSOLE
330   theMap.insert( LightApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
331 #endif
332   theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea   );
333   theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
334
335   inWindows = true;
336   LightApp_Application* app = getApp();
337   if( app && app->getWindow( OverviewWindow )==0 )
338   {
339     const_cast<HYDROGUI_Module*>( this )->myOverview = 
340       new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
341     app->insertDockWindow( OverviewWindow, myOverview );
342     app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
343   }
344   inWindows = false;
345 }
346
347 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
348 {
349   theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
350 }
351
352 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
353                                         QMenu* theMenu,
354                                         QString& theTitle )
355 {
356   HYDROGUI_DataModel* aModel = getDataModel();
357
358   bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
359   bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
360   bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
361   bool anIsVTKView = theClient == SVTK_Viewer::Type();
362   if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
363     return;
364
365   size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
366
367   bool anIsSelectedDataObjects = false;
368   bool anIsVisibleInSelection = false;
369   bool anIsHiddenInSelection = false;
370
371   bool anIsImage = false;
372   bool anIsImportedImage = false;
373   bool anIsImageHasRefs = false;
374   bool anIsFusedImage = false;
375   bool anIsCutImage = false;
376   bool anIsSplitImage = false;
377   bool anIsMustObjectBeUpdated = false;
378   bool anIsPolyline = false;
379   bool anIsPolyline3D = false;
380   bool anIsProfile = false;
381   bool anIsValidProfile = false;
382   bool anAllAreProfiles = false;
383   bool anIsBathymetry = false;
384   bool anIsCalculation = false;
385   bool anIsImmersibleZone = false;
386   bool anIsVisualState = false;
387   bool anIsRegion = false;
388   bool anIsZone = false;
389   bool anIsObstacle = false;
390   bool anIsStricklerTable = false;
391   bool anIsLandCoverMap = false;
392   bool anIsStream = false;
393   bool anIsChannel = false;
394   bool anIsDigue = false;
395   bool anIsDummyObject3D = false;
396   bool anIsGroup = false;
397   bool anIsObjectCanBeColored = false;
398   bool isRoot = false;
399   bool isStreamHasBottom = false;
400
401   SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
402   SUIT_DataOwnerPtrList anOwners;
403   aSelectionMgr->selected( anOwners );
404   if( anIsObjectBrowser && anOwners.size()==1 )
405   {
406     QString anEntry = anOwners[0]->keyString();
407     LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
408     if( aStudy )
409       isRoot = aStudy->isComponent( anEntry );
410   }
411
412   // Check the selected GEOM objects (take into account the Object Browser only)
413   if ( anIsObjectBrowser ) {
414     QList<GEOM::shape_type> anObstacleTypes = 
415       HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
416     QList<GEOM::shape_type> aPolylineTypes = 
417       HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
418
419     bool isCanBeImportedAsObstacle = 
420       !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
421     bool isCanBeImportedAsPolyline = 
422       !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
423
424     // Add import as obstacle action
425     if ( isCanBeImportedAsObstacle ) {
426       theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
427     }
428     // Add import as polyline action
429     if ( isCanBeImportedAsPolyline ) {
430       theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
431     }
432     // Add separator
433     if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
434       theMenu->addSeparator();
435     }
436   }
437
438   // check the selected data model objects
439   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
440   int aNbOfSelectedProfiles = 0;
441   for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
442   {
443     Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
444     if( !anObject.IsNull() )
445     {
446       anIsSelectedDataObjects = true;
447
448       bool aVisibility = isObjectVisible( anActiveViewId, anObject );
449       anIsVisibleInSelection |= aVisibility;
450       anIsHiddenInSelection |= !aVisibility;
451
452       if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
453       {
454         anIsMustObjectBeUpdated = true;
455       }
456
457       ObjectKind anObjectKind = anObject->GetKind();
458       if( anObjectKind == KIND_IMAGE )
459       {
460         anIsImage = true;
461         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
462         if( !anImage.IsNull() )
463         {
464           anIsImportedImage = anImage->HasLocalPoints();
465           anIsImageHasRefs = anImage->HasReferences();
466           if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
467           {
468             if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
469             {
470               QString anOperatorName = anOperator->name();
471               if( anOperatorName == ImageComposer_FuseOperator::Type() )
472                 anIsFusedImage = true;
473               else if( anOperatorName == ImageComposer_CutOperator::Type() )
474                 anIsCutImage = true;
475               else if( anOperatorName == ImageComposer_CropOperator::Type() )
476                 anIsSplitImage = true;
477             }
478           }
479         }
480       }
481       else if( anObjectKind == KIND_POLYLINEXY )
482         anIsPolyline = true;
483       else if( anObjectKind == KIND_POLYLINE )
484         anIsPolyline3D = true;
485       else if( anObjectKind == KIND_PROFILE )
486       {
487         anIsProfile = true;
488         aNbOfSelectedProfiles++;
489
490         Handle(HYDROData_Profile) aProfile = 
491           Handle(HYDROData_Profile)::DownCast( anObject );
492         if( !aProfile.IsNull() && aProfile->IsValid() ) {
493           anIsValidProfile = true;
494         }
495       }
496       else if( anObjectKind == KIND_CALCULATION )
497         anIsCalculation = true;
498       else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
499         anIsImmersibleZone = true;
500       else if( anObjectKind == KIND_VISUAL_STATE )
501         anIsVisualState = true;
502       else if( anObjectKind == KIND_REGION )
503         anIsRegion = true;
504       else if( anObjectKind == KIND_ZONE )
505         anIsZone = true;
506       else if( anObjectKind == KIND_BATHYMETRY )
507         anIsBathymetry = true;
508       else if( anObjectKind == KIND_OBSTACLE )
509         anIsObstacle = true;
510       else if( anObjectKind == KIND_STRICKLER_TABLE )
511         anIsStricklerTable = true;
512       else if( anObjectKind == KIND_LAND_COVER_MAP )
513         anIsLandCoverMap = true;
514       else if( anObjectKind == KIND_STREAM )
515       {
516         anIsStream = true;
517         Handle(HYDROData_Stream) aStream = 
518           Handle(HYDROData_Stream)::DownCast( anObject );
519         if ( !aStream.IsNull() )
520           isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
521       }
522       else if( anObjectKind == KIND_CHANNEL )
523         anIsChannel = true;
524       else if( anObjectKind == KIND_DIGUE )
525         anIsDigue = true;
526       else if( anObjectKind == KIND_DUMMY_3D )
527         anIsDummyObject3D = true;
528       else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
529         anIsGroup = true;
530     }
531
532     if ( !anIsObjectCanBeColored )
533       anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
534   }
535
536   // Check if all selected objects are profiles
537   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
538     ( aNbOfSelectedProfiles == aSeq.Length() );
539
540   // check the selected partitions
541   if( !anIsSelectedDataObjects && anIsObjectBrowser )
542   {
543     ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
544     if( aSelectedPartition != KIND_UNKNOWN )
545     {
546       switch( aSelectedPartition )
547       {
548       case KIND_IMAGE:
549         theMenu->addAction( action( ImportImageId ) );
550         break;
551       case KIND_BATHYMETRY:
552         theMenu->addAction( action( ImportBathymetryId ) );
553         break;
554       case KIND_ARTIFICIAL_OBJECT:
555         theMenu->addAction( action( CreateChannelId ) );
556         theMenu->addAction( action( CreateDigueId ) );
557         break;
558       case KIND_NATURAL_OBJECT:
559         theMenu->addAction( action( CreateImmersibleZoneId ) );
560         theMenu->addAction( action( CreateStreamId ) );
561         break;
562       case KIND_OBSTACLE:
563         theMenu->addAction( action( ImportObstacleFromFileId ) );
564         theMenu->addAction( action( CreateBoxId ) );
565         theMenu->addAction( action( CreateCylinderId ) );
566         break;
567       case KIND_STRICKLER_TABLE:
568         theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
569         break;
570       case KIND_LAND_COVER_MAP:
571         theMenu->addAction( action( CreateLandCoverMapId ) ); 
572         theMenu->addAction( action( ImportLandCoverMapId ) ); 
573         break;
574       case KIND_CALCULATION:
575         theMenu->addAction( action( CreateCalculationId ) );
576         break;
577       case KIND_POLYLINEXY:
578         theMenu->addAction( action( ImportPolylineId ) );
579         theMenu->addAction( action( CreatePolylineId ) );
580         break;
581       case KIND_POLYLINE:
582         theMenu->addAction( action( CreatePolyline3DId ) );
583         break;
584       case KIND_PROFILE:
585         theMenu->addAction( action( CreateProfileId ) );
586         theMenu->addAction( action( ImportProfilesId ) );
587         theMenu->addAction( action( AllGeoreferencementId ) );
588         break;
589       case KIND_VISUAL_STATE:
590         theMenu->addAction( action( SaveVisualStateId ) );
591         break;
592       }
593       theMenu->addSeparator();
594     }
595     else
596     {
597       Handle(HYDROData_CalculationCase) aCalcCase;
598       QString outStr;
599       HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
600       if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
601         theMenu->addAction( action( RegenerateRegionColorsId ) );
602     }
603   }
604
605   if( anIsSelectedDataObjects )
606   {
607     if ( anIsMustObjectBeUpdated )
608     {
609       theMenu->addAction( action( UpdateObjectId ) );
610       theMenu->addSeparator();
611     }
612     else
613     {
614       theMenu->addAction( action( ForcedUpdateObjectId ) );
615       theMenu->addSeparator();
616     }
617
618
619     if( aSeq.Length() == 1 )
620     {
621       if( anIsImage )
622       {
623         if( anIsImportedImage )
624           theMenu->addAction( action( EditImportedImageId ) );
625         else if( anIsImageHasRefs )
626         {
627           if( anIsFusedImage )
628             theMenu->addAction( action( EditFusedImageId ) );
629           else if( anIsCutImage )
630             theMenu->addAction( action( EditCutImageId ) );
631           else if( anIsSplitImage )
632             theMenu->addAction( action( EditSplitImageId ) );
633         }
634
635         //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
636         theMenu->addAction( action( ExportImageId ) );
637         theMenu->addSeparator();
638
639         if( anIsImageHasRefs )
640         {
641           theMenu->addAction( action( RemoveImageRefsId ) );
642           theMenu->addSeparator();
643         }
644
645         theMenu->addAction( action( FuseImagesId ) );
646         theMenu->addAction( action( CutImagesId ) );
647         theMenu->addAction( action( SplitImageId ) );
648         theMenu->addSeparator();
649         theMenu->addAction( action( RecognizeContoursId ) );
650         theMenu->addSeparator();
651       }
652       else if( anIsBathymetry )
653       {
654         theMenu->addAction( action( EditImportedBathymetryId ) );
655         theMenu->addAction( action( BathymetryBoundsId ) );
656         theMenu->addSeparator();
657       }
658       else if( anIsPolyline )
659       {
660         theMenu->addAction( action( EditPolylineId ) );
661         theMenu->addSeparator();
662         theMenu->addAction( action( SplitPolylinesId ) );
663         theMenu->addAction( action( MergePolylinesId ) );
664         theMenu->addSeparator();
665         theMenu->addAction( action( ShowAttrPolylinesId ) );
666         theMenu->addSeparator();
667       }
668       else if( anIsPolyline3D )
669       {
670         theMenu->addAction( action( EditPolyline3DId ) );
671         theMenu->addSeparator();
672       }
673       else if( anIsProfile )
674       {
675         theMenu->addAction( action( EditProfileId ) );
676         theMenu->addAction( action( SelectedGeoreferencementId ) );
677         theMenu->addSeparator();
678       }
679       else if( anIsCalculation )
680       {
681         theMenu->addAction( action( EditCalculationId ) );
682         theMenu->addAction( action( ExportCalculationId ) );
683         theMenu->addSeparator();
684       }
685       else if( anIsImmersibleZone )
686       {
687         theMenu->addAction( action( EditImmersibleZoneId ) );
688         theMenu->addSeparator();
689       }
690       else if( anIsStream )
691       {
692         theMenu->addAction( action( EditStreamId ) );
693         if ( action( RiverBottomContextId ) )
694         {
695           theMenu->addAction( action( RiverBottomContextId ) );
696           action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
697         }
698         theMenu->addAction( action( ProfileInterpolateId ) );
699         theMenu->addSeparator();
700       }
701       else if( anIsChannel )
702       {
703         theMenu->addAction( action( EditChannelId ) );
704         theMenu->addSeparator();
705       }
706       else if( anIsDigue )
707       {
708         theMenu->addAction( action( EditDigueId ) );
709         theMenu->addSeparator();
710       }
711       else if( anIsObstacle )
712       {
713         theMenu->addAction( action( TranslateObstacleId ) );
714         theMenu->addSeparator();
715       }
716       else if( anIsStricklerTable )
717       {
718         theMenu->addAction( action( EditStricklerTableId ) );
719         theMenu->addAction( action( ExportStricklerTableFromFileId ) );
720         theMenu->addAction( action( DuplicateStricklerTableId ) );
721         theMenu->addSeparator();
722
723         Handle(HYDROData_StricklerTable) aTable = 
724           Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
725         QString aCurrentTable = 
726           HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
727         bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
728
729         if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
730           theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
731           theMenu->addSeparator();
732         }
733       }
734       else if( anIsLandCoverMap )
735       {
736         theMenu->addAction( action( AddLandCoverId ) );
737         theMenu->addAction( action( RemoveLandCoverId ) );
738         theMenu->addSeparator();
739         theMenu->addAction( action( SplitLandCoverId ) );
740         theMenu->addAction( action( MergeLandCoverId ) );
741         theMenu->addAction( action( ChangeLandCoverTypeId ) );
742         theMenu->addSeparator();
743         //
744         theMenu->addAction( action( ExportToShapeFileID ) );
745         theMenu->addSeparator();
746       }      
747       else if( anIsVisualState && anIsObjectBrowser )
748       {
749         theMenu->addAction( action( SaveVisualStateId ) );
750         theMenu->addAction( action( LoadVisualStateId ) );
751         theMenu->addSeparator();
752       }
753       else if (anIsZone)
754         theMenu->addAction( action( ZoneSetColorId ) );
755
756       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
757       {
758         theMenu->addAction( action( PolylineExtractionId ) );
759         theMenu->addSeparator();
760       }
761
762       // Add set color action for geometrical objects
763       if ( anIsObjectCanBeColored )
764       {
765         theMenu->addAction( action( SetColorId ) );
766         theMenu->addSeparator();
767       }
768
769       // Add transparency action for land cover map objects
770       if ( anIsLandCoverMap )
771       {
772         theMenu->addAction( action( SetTransparencyId ) );
773         theMenu->addSeparator();
774       }
775     } 
776     else if ( anAllAreProfiles )
777     {
778       theMenu->addAction( action( EditProfileId ) );
779       theMenu->addAction( action( SelectedGeoreferencementId ) );
780       theMenu->addSeparator();
781     }
782
783     bool isPoly = anIsPolyline || anIsPolyline3D;
784     if (isPoly  && !anIsLandCoverMap)
785       theMenu->addAction( action( ExportToShapeFileID ) );
786
787     // Add copy action
788     QAction* aCopyAction = action( CopyId );
789     if( aCopyAction && aCopyAction->isEnabled() ) {
790       theMenu->addAction( action( CopyId ) );
791       theMenu->addSeparator();
792     }
793
794     // Add delete action
795     if( !anIsDummyObject3D )
796       theMenu->addAction( action( DeleteId ) );
797
798     theMenu->addSeparator();
799
800     if( anIsImage || anIsPolyline || anIsPolyline3D || 
801       anIsImmersibleZone || anIsZone || anIsRegion ||
802       anIsBathymetry || anIsObstacle || anIsStream ||
803       anIsChannel || anIsDigue || anIsDummyObject3D ||
804       anIsValidProfile || anIsGroup || anIsLandCoverMap )
805     {
806       if( anIsHiddenInSelection )
807         theMenu->addAction( action( ShowId ) );
808       theMenu->addAction( action( ShowOnlyId ) );
809       if( anIsVisibleInSelection )
810         theMenu->addAction( action( HideId ) );
811       theMenu->addSeparator();
812     }
813   }
814
815   if ( anIsOCCView )
816   {
817     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
818     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
819     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
820       theMenu->addAction( action( DeleteId ) );
821
822     theMenu->addSeparator();
823     theMenu->addAction( action( SetZLevelId ) );
824     theMenu->addSeparator();
825
826     if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
827       theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
828       theMenu->addSeparator();
829     }
830   }
831
832   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
833   {
834     theMenu->addAction( action( ShowAllId ) );
835     theMenu->addAction( action( HideAllId ) );
836     theMenu->addSeparator();
837   }
838
839   if ( anIsOCCView || anIsVTKView )
840   {
841     theMenu->addSeparator();
842     theMenu->addAction( action( CopyViewerPositionId ) );
843   }
844
845   if( isRoot )
846     theMenu->addAction( action( EditLocalCSId ) );
847
848   if( anIsObjectBrowser && anOwners.size()==1 )
849   {
850     if( aSeq.Size() > 0 )
851     {
852       Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
853       Handle(HYDROData_Object) anObject;
854       Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
855       Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
856
857       if (!anAObject.IsNull())
858         anObject = anAObject;
859       if (!aNObject.IsNull())
860         anObject = aNObject;
861
862       if( !anObject.IsNull() )
863       {
864         theMenu->addSeparator();
865         bool IsSubmersible = anObject->IsSubmersible();
866         if (!IsSubmersible)
867         {
868           theMenu->addAction( action( SubmersibleId ) );
869           action( SubmersibleId )->setCheckable(true);
870           action( SubmersibleId )->setChecked(true);
871         }
872         else
873         {
874           theMenu->addAction( action( UnSubmersibleId ) );
875           action( UnSubmersibleId )->setCheckable(true);
876           action( UnSubmersibleId )->setChecked(true);
877         }
878       }
879     }
880   }
881
882   theMenu->addSeparator();
883   QAction* a = action( ShowHideArrows );
884   a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
885   theMenu->addAction( a );
886 }
887
888 void HYDROGUI_Module::createPreferences()
889 {
890   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
891   int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
892
893   int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
894                                     LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
895
896   // Set property cursor type
897   QList<QVariant> aCursorTypeIndicesList;
898   QList<QVariant> aCursorTypeIconsList;
899
900   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
901   for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
902     QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
903     QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
904     aCursorTypeIndicesList << i;
905     aCursorTypeIconsList << pixmap;
906   }
907
908   setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
909   setPreferenceProperty( typeOfCursor, "icons",   aCursorTypeIconsList );
910
911   int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
912   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
913                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
914
915   addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
916
917   addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
918
919   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
920   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
921                                             LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
922   setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
923   setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
924   setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
925   setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
926
927   int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
928   int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
929     LightApp_Preferences::Selector, "polyline", "arrow_type" );
930
931   QList<QVariant> arrow_types;
932   arrow_types.append( tr( "No" ) );
933   arrow_types.append( tr( "Triangle" ) );
934   arrow_types.append( tr( "Cone" ) );
935   setPreferenceProperty( polylineArrow, "strings", arrow_types );
936
937   QList<QVariant> indices;
938   indices.append( 0 );
939   indices.append( 1 );
940   indices.append( 2 );
941   setPreferenceProperty( polylineArrow, "indexes", indices );
942   setPreferenceProperty( polylineArrow, "ids", indices );
943
944   int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
945     LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
946 }
947
948 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
949 {
950     SUIT_ResourceMgr* resMgr = application()->resourceMgr();
951     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
952     {
953         
954         Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
955         if ( resMgr && !aDoc.IsNull() )
956             aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
957     }
958     else if( theSection == "polyline" )
959     {
960       int aType = -1;
961       int aSize = -1;
962       if( resMgr )
963       {
964         resMgr->value( "polyline", "arrow_type", aType );
965         resMgr->value( "polyline", "arrow_size", aSize );
966       }
967       //Update polylines
968       ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
969       for( ; it!=last; it++ )
970       {
971         int aViewerId = it.key();
972         OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
973         if( aMgr )
974           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
975       }
976     }
977     else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
978     {
979       bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
980       setAutoZoomToAllViewManagers(!aZoomShutoff);
981     }
982     else if (theSection == "HYDRO" && thePref == "chained_panning")
983     {
984       bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
985       if (!aChainedPan)
986         resetViewState();
987       ViewManagerList aViewManagers = getApp()->viewManagers();
988       foreach (SUIT_ViewManager* aVMgr, aViewManagers)
989       {
990         OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
991         if (anOCCViewMgr)
992           anOCCViewMgr->setChainedOperations( aChainedPan );
993       }
994       
995       QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
996       foreach (QDockWidget* qw, docW)
997       {
998         HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
999         if (pdlg)
1000           pdlg->viewManager()->setChainedOperations(aChainedPan);
1001       }
1002     }
1003     else
1004       LightApp_Module::preferencesChanged( theSection, thePref );
1005 }
1006
1007 QCursor HYDROGUI_Module::getPrefEditCursor() const
1008 {
1009   int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
1010   if ( aCursorType >= Qt::BlankCursor)
1011     aCursorType++;
1012   QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
1013   return aCursor;
1014 }
1015
1016 void HYDROGUI_Module::update( const int flags )
1017 {
1018   if ( !isUpdateEnabled() )
1019     return;
1020
1021   QApplication::setOverrideCursor( Qt::WaitCursor );
1022
1023   // To prevent calling this method recursively
1024   // from one of the methods called below
1025   setUpdateEnabled( false );
1026
1027   // store selected objects
1028   QStringList aSelectedEntries = storeSelection();
1029
1030   bool aDoFitAll = flags & UF_FitAll;
1031   if ( aDoFitAll )
1032   {
1033     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1034     aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1035   }
1036
1037   if( ( flags & UF_Viewer ) )
1038     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
1039
1040   if( ( flags & UF_OCCViewer ) )
1041     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
1042
1043   if( ( flags & UF_VTKViewer ) )
1044     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
1045
1046   if( ( flags & UF_Model ) && getDataModel() && getApp() )
1047   {
1048     getDataModel()->update( getStudyId() );
1049
1050     // Temporary workaround to prevent breaking
1051     // the selection in the object browser.
1052     // Note: processEvents() should be called after updateGV(),
1053     // otherwise the application crashes from time to time.
1054     //RKV: qApp->processEvents();
1055     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1056     bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1057     SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1058     if ( isResizeOnExpandItem && anObjectBrowser ) {
1059       anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280 
1060     }
1061     getApp()->updateObjectBrowser( true );
1062     if ( isResizeOnExpandItem && anObjectBrowser ) {
1063       anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280 
1064     }
1065   }
1066
1067   // Object browser is currently updated by using UF_Model flag
1068   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1069     getApp()->updateObjectBrowser( true );
1070
1071   if( ( flags & UF_Controls ) && getApp() )
1072     getApp()->updateActions();
1073
1074   // restore selected objects
1075   restoreSelection( aSelectedEntries );
1076
1077   setUpdateEnabled( true );
1078
1079   preferencesChanged( "HYDRO", "zoom_shutoff" );
1080
1081   preferencesChanged( "HYDRO", "chained_panning" );
1082
1083   QApplication::restoreOverrideCursor();
1084 }
1085
1086 void HYDROGUI_Module::updateCommandsStatus()
1087 {
1088   LightApp_Module::updateCommandsStatus();
1089
1090   updateUndoRedoControls();
1091
1092   action( CopyId )->setEnabled( getDataModel()->canCopy() );
1093   action( PasteId )->setEnabled( getDataModel()->canPaste() );
1094 }
1095
1096 void HYDROGUI_Module::selectionChanged()
1097 {
1098   LightApp_Module::selectionChanged();
1099   updateCommandsStatus();
1100 }
1101
1102 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1103 {
1104   return (HYDROGUI_DataModel*)dataModel();
1105 }
1106
1107 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1108 {
1109   return myDisplayer;
1110 }
1111
1112 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1113 {
1114   return myOCCDisplayer;
1115 }
1116
1117 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1118 {
1119   return myVTKDisplayer;
1120 }
1121
1122 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1123 {
1124   if( myViewManagerMap.contains( theId ) )
1125   {
1126     return myViewManagerMap[ theId ].first;
1127   }
1128   return NULL;
1129 }
1130
1131 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1132 {
1133   if( myViewManagerMap.contains( theId ) )
1134   {
1135     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1136     GraphicsView_ViewManager* aViewManager =
1137       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1138     if( aViewManager )
1139       return aViewManager->getViewer();
1140   }
1141   return NULL;
1142 }
1143
1144 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1145 {
1146   if( myViewManagerMap.contains( theId ) )
1147   {
1148     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1149     OCCViewer_ViewManager* aViewManager =
1150       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1151     if( aViewManager )
1152       return aViewManager->getOCCViewer();
1153   }
1154   return NULL;
1155 }
1156
1157 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1158 {
1159   if( myViewManagerMap.contains( theId ) )
1160   {
1161     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1162     SVTK_ViewManager* aViewManager =
1163       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1164     if( aViewManager )
1165       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1166   }
1167   return NULL;
1168 }
1169
1170 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1171 {
1172   ViewManagerMapIterator anIter( myViewManagerMap );
1173   while( anIter.hasNext() )
1174   {
1175     int anId = anIter.next().key();
1176     const ViewManagerInfo& anInfo = anIter.value();
1177     if( anInfo.first == theViewManager )
1178       return anId;
1179   }
1180   return -1;
1181 }
1182
1183 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1184 {
1185   int anId = getViewManagerId( theViewManager );
1186   if( anId != -1 )
1187   {
1188     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1189     return anInfo.second;
1190   }
1191   return VMR_Unknown;
1192 }
1193
1194 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1195                                           const ViewManagerRole theRole )
1196 {
1197   int anId = getViewManagerId( theViewManager );
1198   if( anId != -1 )
1199   {
1200     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1201     anInfo.second = theRole;
1202   }
1203 }
1204
1205 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1206                                        const Handle(HYDROData_Entity)& theObject ) const
1207 {
1208   if( theObject.IsNull() )
1209     return false;
1210
1211   if( theViewId < 0 )
1212   {
1213     //search in all
1214     foreach( int aViewId, myObjectStateMap.keys() )
1215     {
1216       if( isObjectVisible( aViewId, theObject ) )
1217         return true;
1218     }
1219     return false;
1220   }
1221
1222   ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1223   if( anIter1 != myObjectStateMap.end() )
1224   {
1225     const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1226     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1227
1228     Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1229     if( anIter2 != aEntry2ObjectStateMap.end() )
1230     {
1231       const ObjectState& anObjectState = anIter2.value();
1232       return anObjectState.Visibility;
1233     }
1234   }
1235   return false;
1236 }
1237
1238 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1239                                         const Handle(HYDROData_Entity)& theObject,
1240                                         const bool theState )
1241 {
1242   if( !theObject.IsNull() )
1243   {
1244     Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1245     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1246
1247     ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1248     anObjectState.Visibility = theState;
1249
1250     HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1251     if ( hydroObject )
1252     {
1253         SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1254         if ( treeModel )
1255         {
1256           QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1257           Qtx::VisibilityState visState = treeModel->visibilityState( id );
1258           if ( visState != Qtx::UnpresentableState )
1259             treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1260         }
1261     }
1262
1263     if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1264       setLandCoversScalarMapModeOff( theViewId );
1265     } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1266       getOCCDisplayer()->SetToUpdateColorScale();
1267     }
1268   }
1269 }
1270
1271 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1272                                      const bool theState )
1273 {
1274   if( !theObject.IsNull() )
1275   {
1276     // Process OCC shapes
1277     ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1278     while( aShapesMapIter != myShapesMap.end() )
1279     {
1280       const ListOfShapes& aShapesList = aShapesMapIter.value();
1281       foreach ( HYDROGUI_Shape* aShape, aShapesList )
1282       {
1283         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1284         {
1285           aShape->setIsToUpdate( theState );
1286         }
1287       }
1288       aShapesMapIter++;
1289     }
1290     // Process VTK shapes
1291     ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1292     while( aVTKPrsMapIter != myVTKPrsMap.end() )
1293     {
1294       const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1295       foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1296       {
1297         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1298         {
1299           aShape->setIsToUpdate( theState );
1300         }
1301       }
1302       aVTKPrsMapIter++;
1303     }
1304   }
1305 }
1306
1307 /////////////////// OCC SHAPES PROCESSING
1308 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
1309                                                          ObjectKind theKind ) const
1310 {
1311   QList<HYDROGUI_Shape*> aResult;
1312
1313   if ( myShapesMap.contains( theViewId ) )
1314   {
1315     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1316     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1317     {
1318       if( aShape && aShape->getObject()->GetKind()==theKind )
1319         aResult.append( aShape );
1320     }
1321   }
1322   return aResult;
1323 }
1324
1325 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
1326                                                  const Handle(HYDROData_Entity)& theObject ) const
1327 {
1328   HYDROGUI_Shape* aResShape = NULL;
1329   if( theObject.IsNull() )
1330     return aResShape;
1331
1332   if ( myShapesMap.contains( theViewId ) )
1333   {
1334     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1335     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1336     {
1337       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1338         continue;
1339
1340       aResShape = aShape;
1341       break;
1342     }
1343   }
1344
1345   return aResShape;
1346 }
1347
1348 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
1349                                       const Handle(HYDROData_Entity)& theObject,
1350                                       HYDROGUI_Shape*                 theShape )
1351 {
1352   if( theObject.IsNull() )
1353     return;
1354
1355   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1356   aViewShapes.append( theShape );
1357 }
1358
1359 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
1360                                          const Handle(HYDROData_Entity)& theObject )
1361 {
1362   if ( !myShapesMap.contains( theViewId ) )
1363     return;
1364
1365   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1366   Handle(HYDROData_Entity) anObject;
1367   for ( int i = 0; i < aViewShapes.length(); )
1368   {
1369     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1370     anObject = aShape->getObject();
1371     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1372     {
1373       delete aShape;
1374       aViewShapes.removeAt( i );
1375       continue;
1376     }
1377
1378     ++i;
1379   }
1380 }
1381
1382 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1383 {
1384   if ( !myShapesMap.contains( theViewId ) )
1385     return;
1386
1387   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1388   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1389   {
1390     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1391     if ( aShape )
1392       delete aShape;
1393   }
1394
1395   myShapesMap.remove( theViewId );
1396 }
1397 /////////////////// END OF OCC SHAPES PROCESSING
1398
1399 /////////////////// VTKPrs PROCESSING
1400 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
1401                                                  const Handle(HYDROData_Entity)& theObject ) const
1402 {
1403   HYDROGUI_VTKPrs* aResShape = NULL;
1404   if( theObject.IsNull() )
1405     return aResShape;
1406
1407   if ( myVTKPrsMap.contains( theViewId ) )
1408   {
1409     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1410     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1411     {
1412       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1413         continue;
1414
1415       aResShape = aShape;
1416       break;
1417     }
1418   }
1419
1420   return aResShape;
1421 }
1422
1423 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
1424                                        const Handle(HYDROData_Entity)& theObject,
1425                                        HYDROGUI_VTKPrs*                 theShape )
1426 {
1427   if( theObject.IsNull() )
1428     return;
1429
1430   if( theShape && theShape->needScalarBar() )
1431   {
1432     // Compute the new global Z range from the added presentation and the old global Z range.
1433     double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1434     double* aRange = theShape->getInternalZRange();
1435     bool anIsUpdate = false;
1436     if ( aRange[0] < aGlobalRange[0] )
1437     {
1438       aGlobalRange[0] = aRange[0];
1439       anIsUpdate = true;
1440     }
1441     if ( aRange[1] > aGlobalRange[1] )
1442     {
1443       aGlobalRange[1] = aRange[1];
1444       anIsUpdate = true;
1445     }
1446
1447     //if ( anIsUpdate )
1448     //{
1449       updateVTKZRange( theViewId, aGlobalRange );
1450     //}
1451   }
1452
1453   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1454   aViewShapes.append( theShape );
1455 }
1456
1457 void HYDROGUI_Module::removeObjectVTKPrs( const int      theViewId,
1458                                           const QString& theEntry )
1459 {
1460   if ( !myVTKPrsMap.contains( theViewId ) )
1461     return;
1462
1463   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1464   Handle(HYDROData_Entity) anObject;
1465   QString anEntryRef;
1466   for ( int i = 0; i < aViewShapes.length(); )
1467   {
1468     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1469     anObject = aShape->getObject();
1470     anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1471     if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1472     {
1473       delete aShape;
1474       aViewShapes.removeAt( i );
1475       continue;
1476     }
1477
1478     ++i;
1479   }
1480
1481   // Invalidate global Z range
1482   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1483   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1484 }
1485
1486 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
1487                                           const Handle(HYDROData_Entity)& theObject )
1488 {
1489   if ( !myVTKPrsMap.contains( theViewId ) )
1490     return;
1491
1492   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1493   Handle(HYDROData_Entity) anObject;
1494   for ( int i = 0; i < aViewShapes.length(); )
1495   {
1496     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1497     anObject = aShape->getObject();
1498     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1499     {
1500       delete aShape;
1501       aViewShapes.removeAt( i );
1502       continue;
1503     }
1504
1505     ++i;
1506   }
1507
1508   // Invalidate global Z range
1509   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1510   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1511 }
1512
1513 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1514 {
1515   if ( !myVTKPrsMap.contains( theViewId ) )
1516     return;
1517
1518   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1519   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1520   {
1521     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1522     if ( aShape )
1523       delete aShape;
1524   }
1525
1526   myVTKPrsMap.remove( theViewId );
1527 }
1528
1529 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1530 {
1531   if ( myVTKPrsMap.contains( theViewId ) )
1532   {
1533     // For the given viewer id update all VTK presentations ...
1534     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1535     HYDROGUI_VTKPrs* aShape;
1536     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1537     {
1538       aShape = aViewShapes.at( i );
1539       if ( aShape && aShape->needScalarBar() )
1540       {
1541         aShape->setZRange( theRange );
1542       }
1543     }
1544   }
1545   // ... and update the global color legend scalar bar.
1546   getVTKDisplayer()->SetZRange( theViewId, theRange );
1547 }
1548 /////////////////// END OF VTKPrs PROCESSING
1549
1550 void HYDROGUI_Module::clearCache()
1551 {
1552     myObjectStateMap.clear();
1553 }
1554
1555 CAM_DataModel* HYDROGUI_Module::createDataModel()
1556 {
1557   return new HYDROGUI_DataModel( this );
1558 }
1559
1560 void HYDROGUI_Module::customEvent( QEvent* e )
1561 {
1562   int aType = e->type();
1563   if ( aType == NewViewEvent )
1564   {
1565     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1566     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1567     {
1568       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1569       {
1570         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1571         ViewManagerRole aRole = getViewManagerRole( aViewManager );
1572
1573         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1574         {
1575           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1576             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1577
1578           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1579           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1580           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1581
1582           //ouv: temporarily commented
1583           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1584         }
1585
1586         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1587           update( UF_Viewer );
1588
1589         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1590       }
1591     }
1592   }
1593 }
1594
1595 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1596 {
1597   QEvent::Type aType = theEvent->type();
1598   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1599   {
1600     if( aType == QEvent::Show )
1601     {
1602       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1603       e->setData( theObj );
1604       QApplication::postEvent( this, e );
1605       theObj->removeEventFilter( this );
1606     }
1607   }
1608   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1609   {
1610     if( aType == QEvent::Leave )
1611     {
1612       SUIT_Desktop* aDesktop = getApp()->desktop();
1613       if ( aDesktop && aDesktop->statusBar() ) {
1614         aDesktop->statusBar()->clearMessage();
1615       }
1616     }
1617   }
1618   else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1619   {
1620     if( aType == QEvent::Leave )
1621     {
1622       SUIT_Desktop* aDesktop = getApp()->desktop();
1623       if ( aDesktop && aDesktop->statusBar() ) {
1624         aDesktop->statusBar()->clearMessage();
1625       }
1626     }
1627   }
1628
1629   return LightApp_Module::eventFilter( theObj, theEvent );
1630 }
1631
1632 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1633 {
1634   LightApp_Module::onViewManagerAdded( theViewManager );
1635
1636   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1637   { 
1638     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1639              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1640   }
1641   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1642   {
1643     OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1644     //mgr->setChainedOperations( true );
1645
1646     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1647              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1648     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1649              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1650     connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
1651              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1652   }
1653   else if( theViewManager->getType() == SVTK_Viewer::Type() )
1654   {
1655     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1656              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1657     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1658              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1659   }
1660
1661   createSelector( theViewManager ); // replace the default selector
1662
1663   ViewManagerInfo anInfo( theViewManager, VMR_General );
1664   myViewManagerMap.insert( ViewManagerId++, anInfo );
1665 }
1666
1667 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1668 {
1669   LightApp_Module::onViewManagerRemoved( theViewManager );
1670
1671   createSelector( theViewManager ); // replace the default selector
1672
1673   int anId = getViewManagerId( theViewManager );
1674   if( anId != -1 )
1675   {
1676     OCCViewer_ViewManager* anOCCViewManager =
1677       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1678     if ( anOCCViewManager )
1679     {
1680       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1681       if ( anOCCViewer ) {
1682         int aViewerId = (size_t)anOCCViewer;
1683         removeViewShapes( aViewerId );
1684         setLandCoversScalarMapModeOff( aViewerId );
1685       }
1686     }
1687
1688     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1689     {
1690       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1691       if ( aVTKViewer )
1692       {
1693         getVTKDisplayer()->EraseScalarBar( anId, true );
1694         removeViewShapes( (size_t)aVTKViewer );
1695       }
1696     }
1697
1698     myViewManagerMap.remove( anId );
1699   }
1700 }
1701
1702 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1703 {
1704   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1705   {
1706     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1707     {
1708       aViewFrame->installEventFilter( this );
1709
1710       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1711       aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1712
1713       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1714                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1715     }
1716   }
1717   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1718   {
1719     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1720     {
1721       aViewFrame->onTopView();
1722
1723       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1724       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1725       if ( aViewPort ) {
1726         aViewPort->installEventFilter( this );
1727       }
1728     }
1729   }
1730   else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1731   {
1732     if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1733     {
1734       aViewFrame->installEventFilter( this );
1735     }
1736   }
1737 }
1738
1739 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1740 {
1741   /* ouv: currently unused
1742   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1743   {
1744     SUIT_ViewManager* aViewManager = 0;
1745
1746     QObject* aParent = aViewPort;
1747     while( aParent = aParent->parent() )
1748     {
1749       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1750       {
1751         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1752         {
1753           aViewManager = aViewer->getViewManager();
1754           break;
1755         }
1756       }
1757     }
1758
1759     if( !aViewManager )
1760       return;
1761
1762     double aMouseX = theEvent->scenePos().x();
1763     double aMouseY = theEvent->scenePos().y();
1764
1765     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1766     if( aRole == VMR_General )
1767     {
1768       int aXDeg = 0, aYDeg = 0;
1769       int aXMin = 0, aYMin = 0;
1770       double aXSec = 0, aYSec = 0;
1771       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1772       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1773
1774       QString aDegSymbol( QChar( 0x00B0 ) );
1775       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1776       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1777
1778       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1779     }
1780     else if( aRole == VMR_TransformImage )
1781       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1782   }
1783   */
1784 }
1785
1786 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1787                                     const bool theIsInit, 
1788                                     const bool theIsForced, 
1789                                     const bool theDoFitAll )
1790 {
1791   QList<int> aViewManagerIdList;
1792
1793   // currently, all views are updated
1794   ViewManagerMapIterator anIter( myViewManagerMap );
1795   while( anIter.hasNext() )
1796   { 
1797     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1798
1799     if ( theDisplayer->IsApplicable( aViewManager ) )
1800     {
1801       int anId = anIter.key();
1802       aViewManagerIdList.append( anId );
1803     }
1804   }
1805
1806   QListIterator<int> anIdIter( aViewManagerIdList );
1807   while( anIdIter.hasNext() )
1808   {
1809     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1810     myOverview->setTopView();
1811   }
1812 }
1813
1814 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1815 {
1816   if( !theViewManager )
1817     return;
1818
1819   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1820   if( !aSelectionMgr )
1821     return;
1822
1823   QString aViewType = theViewManager->getType();
1824   if( aViewType != GraphicsView_Viewer::Type() &&
1825       aViewType != OCCViewer_Viewer::Type())
1826     return;
1827
1828   QList<SUIT_Selector*> aSelectorList;
1829   aSelectionMgr->selectors( aViewType, aSelectorList );
1830
1831   // disable all alien selectors
1832   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1833   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1834   {
1835     SUIT_Selector* aSelector = *anIter;
1836     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1837                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1838                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1839       aSelector->setEnabled( false );
1840   }
1841
1842   if ( aViewType == GraphicsView_Viewer::Type() )
1843   {
1844     GraphicsView_ViewManager* aViewManager =
1845       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1846     if( aViewManager )
1847       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1848   }
1849   else if ( aViewType == OCCViewer_Viewer::Type() )
1850   {
1851     OCCViewer_ViewManager* aViewManager =
1852       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1853     if( aViewManager )
1854       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1855   }
1856 }
1857
1858 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1859 {
1860   bool aPrevState = myIsUpdateEnabled;
1861   myIsUpdateEnabled = theState;
1862   return aPrevState;
1863 }
1864
1865 bool HYDROGUI_Module::isUpdateEnabled() const
1866 {
1867   return myIsUpdateEnabled;
1868 }
1869
1870 QStringList HYDROGUI_Module::storeSelection() const
1871 {
1872   QStringList anEntryList;
1873   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1874   {
1875     SUIT_DataOwnerPtrList aList( true );
1876     aSelectionMgr->selected( aList );
1877
1878     SUIT_DataOwnerPtrList::iterator anIter;
1879     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1880     {
1881       const LightApp_DataOwner* anOwner = 
1882         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1883       if( anOwner )
1884         anEntryList.append( anOwner->entry() );
1885     }
1886   }
1887   return anEntryList;
1888 }
1889
1890 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1891 {
1892   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1893   {
1894     SUIT_DataOwnerPtrList aList( true );
1895     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1896       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1897     aSelectionMgr->setSelected( aList );
1898   }
1899 }
1900
1901 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1902 {
1903   double X, Y, Z;
1904   bool doShow = false;
1905   HYDROGUI_Displayer* aDisplayer = getDisplayer();
1906   if ( aDisplayer )
1907     aDisplayer->SaveCursorViewPosition( theViewWindow );
1908     doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1909
1910   if ( doShow )
1911   {
1912     // Show the coordinates in the status bar
1913     SUIT_Desktop* aDesktop = getApp()->desktop();
1914     if ( aDesktop && aDesktop->statusBar() )
1915     {
1916       gp_Pnt aWPnt( X, Y, Z );
1917       int aStudyId = application()->activeStudy()->id();
1918       HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1919       double WX = aWPnt.X(), WY = aWPnt.Y();
1920
1921       QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1922       QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1923       QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1924       QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1925       QString aMsg = tr( "COORDINATES_INFO" );
1926       aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1927       aDesktop->statusBar()->showMessage( aMsg );
1928     }
1929   }
1930 }
1931
1932 /**
1933  * Returns stack of active operations;
1934  */
1935 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1936 {
1937   return myActiveOperationMap;
1938 }
1939
1940 /**
1941  * Returns the module active operation. If the active operation is show/hide,
1942  * the method returns the previous operation if it is.
1943  */
1944 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1945 {
1946   HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1947
1948   if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1949   {
1950     QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1951     aVIt.toBack();
1952     aVIt.previous(); // skip the top show/hide operation
1953     anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1954   }
1955
1956   return anOp;
1957 }
1958
1959 /*!
1960  * \brief Virtual public slot
1961  *
1962  * This method is called after the object inserted into data view to update their visibility state
1963  * This is default implementation
1964  */
1965 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1966 {
1967   if ( !isActiveModule() )
1968       return;
1969
1970   HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1971
1972   // change visibility of object
1973   if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1974       return;
1975
1976   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1977
1978   QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1979   Qtx::VisibilityState visState = treeModel->visibilityState( id );
1980   if ( visState == Qtx::UnpresentableState )
1981       return;
1982
1983   visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1984   treeModel->setVisibilityState( id, visState );
1985
1986   bool vis = visState == Qtx::ShownState;
1987   if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1988       return;
1989
1990   setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1991
1992   update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1993 }
1994
1995 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1996 {
1997   Handle(HYDROData_StricklerTable) aTable;
1998
1999   if ( myLandCoverColoringMap.contains( theViewId ) ) {
2000     aTable = myLandCoverColoringMap.value( theViewId );
2001   }
2002
2003   return aTable;
2004 }
2005
2006 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
2007                                                  const Handle(HYDROData_StricklerTable)& theTable )
2008 {
2009   if ( !theTable.IsNull() ) {
2010     myLandCoverColoringMap.insert( theViewId, theTable );
2011   }
2012 }
2013
2014 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
2015 {
2016   myLandCoverColoringMap.remove( theViewId );
2017 }
2018
2019 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
2020 {
2021   return myLandCoverColoringMap.contains( theViewId );
2022 }
2023
2024 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2025 {
2026   if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2027     return;
2028   }
2029
2030   if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2031     Handle(HYDROData_StricklerTable) aTable = 
2032       Handle(HYDROData_StricklerTable)::DownCast( theObject );
2033     QList<int> aViewIds;
2034     QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2035     while ( anIter.hasNext() ) {
2036       if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) == 
2037            HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2038         anIter.remove();
2039       }
2040     }
2041   }
2042 }
2043
2044 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2045 {
2046   if( !theMgr )
2047     return;
2048
2049   SUIT_ViewWindow* wnd = theMgr->getActiveView();
2050   OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2051   if( !occwnd )
2052     return;
2053
2054   myOverview->setMainView( occwnd );
2055 }
2056
2057 void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
2058 {
2059   ViewManagerList aViewManagers = getApp()->viewManagers();
2060   foreach (SUIT_ViewManager* aVMgr, aViewManagers)
2061     setAutoZoom(aVMgr, bAutoZoom);
2062 }
2063
2064 void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
2065 {
2066   if (!aVMgr)
2067     return;
2068   QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
2069   foreach (SUIT_ViewWindow* aView, aViews)
2070   {
2071     if (aView)
2072     {
2073       OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
2074       if (anOCCViewFrame)
2075       {
2076         anOCCViewFrame->setAutomaticZoom(bAutoZoom);
2077         for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
2078         {
2079           OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
2080           if (aV)
2081             aV->setAutomaticZoom(bAutoZoom);
2082         }
2083       }
2084       OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
2085       if (anOCCViewWindow)
2086         anOCCViewWindow->setAutomaticZoom(bAutoZoom);
2087     }
2088   }
2089 }
2090