]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Module.cxx
Salome HOME
refs #1488
[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       }
666       else if( anIsPolyline3D )
667       {
668         theMenu->addAction( action( EditPolyline3DId ) );
669         theMenu->addSeparator();
670       }
671       else if( anIsProfile )
672       {
673         theMenu->addAction( action( EditProfileId ) );
674         theMenu->addAction( action( SelectedGeoreferencementId ) );
675         theMenu->addSeparator();
676       }
677       else if( anIsCalculation )
678       {
679         theMenu->addAction( action( EditCalculationId ) );
680         theMenu->addAction( action( ExportCalculationId ) );
681         theMenu->addSeparator();
682       }
683       else if( anIsImmersibleZone )
684       {
685         theMenu->addAction( action( EditImmersibleZoneId ) );
686         theMenu->addSeparator();
687       }
688       else if( anIsStream )
689       {
690         theMenu->addAction( action( EditStreamId ) );
691         if ( action( RiverBottomContextId ) )
692         {
693           theMenu->addAction( action( RiverBottomContextId ) );
694           action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
695         }
696         theMenu->addAction( action( ProfileInterpolateId ) );
697         theMenu->addSeparator();
698       }
699       else if( anIsChannel )
700       {
701         theMenu->addAction( action( EditChannelId ) );
702         theMenu->addSeparator();
703       }
704       else if( anIsDigue )
705       {
706         theMenu->addAction( action( EditDigueId ) );
707         theMenu->addSeparator();
708       }
709       else if( anIsObstacle )
710       {
711         theMenu->addAction( action( TranslateObstacleId ) );
712         theMenu->addSeparator();
713       }
714       else if( anIsStricklerTable )
715       {
716         theMenu->addAction( action( EditStricklerTableId ) );
717         theMenu->addAction( action( ExportStricklerTableFromFileId ) );
718         theMenu->addAction( action( DuplicateStricklerTableId ) );
719         theMenu->addSeparator();
720
721         Handle(HYDROData_StricklerTable) aTable = 
722           Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
723         QString aCurrentTable = 
724           HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
725         bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
726
727         if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
728           theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
729           theMenu->addSeparator();
730         }
731       }
732       else if( anIsLandCoverMap )
733       {
734         theMenu->addAction( action( AddLandCoverId ) );
735         theMenu->addAction( action( RemoveLandCoverId ) );
736         theMenu->addSeparator();
737         theMenu->addAction( action( SplitLandCoverId ) );
738         theMenu->addAction( action( MergeLandCoverId ) );
739         theMenu->addAction( action( ChangeLandCoverTypeId ) );
740         theMenu->addSeparator();
741         //
742         theMenu->addAction( action( ExportToShapeFileID ) );
743         theMenu->addSeparator();
744       }      
745       else if( anIsVisualState && anIsObjectBrowser )
746       {
747         theMenu->addAction( action( SaveVisualStateId ) );
748         theMenu->addAction( action( LoadVisualStateId ) );
749         theMenu->addSeparator();
750       }
751       else if (anIsZone)
752         theMenu->addAction( action( ZoneSetColorId ) );
753
754       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
755       {
756         theMenu->addAction( action( PolylineExtractionId ) );
757         theMenu->addSeparator();
758       }
759
760       // Add set color action for geometrical objects
761       if ( anIsObjectCanBeColored )
762       {
763         theMenu->addAction( action( SetColorId ) );
764         theMenu->addSeparator();
765       }
766
767       // Add transparency action for land cover map objects
768       if ( anIsLandCoverMap )
769       {
770         theMenu->addAction( action( SetTransparencyId ) );
771         theMenu->addSeparator();
772       }
773     } 
774     else if ( anAllAreProfiles )
775     {
776       theMenu->addAction( action( EditProfileId ) );
777       theMenu->addAction( action( SelectedGeoreferencementId ) );
778       theMenu->addSeparator();
779     }
780
781     bool isPoly = anIsPolyline || anIsPolyline3D;
782     if (isPoly  && !anIsLandCoverMap)
783       theMenu->addAction( action( ExportToShapeFileID ) );
784
785     // Add copy action
786     QAction* aCopyAction = action( CopyId );
787     if( aCopyAction && aCopyAction->isEnabled() ) {
788       theMenu->addAction( action( CopyId ) );
789       theMenu->addSeparator();
790     }
791
792     // Add delete action
793     if( !anIsDummyObject3D )
794       theMenu->addAction( action( DeleteId ) );
795
796     theMenu->addSeparator();
797
798     if( anIsImage || anIsPolyline || anIsPolyline3D || 
799       anIsImmersibleZone || anIsZone || anIsRegion ||
800       anIsBathymetry || anIsObstacle || anIsStream ||
801       anIsChannel || anIsDigue || anIsDummyObject3D ||
802       anIsValidProfile || anIsGroup || anIsLandCoverMap )
803     {
804       if( anIsHiddenInSelection )
805         theMenu->addAction( action( ShowId ) );
806       theMenu->addAction( action( ShowOnlyId ) );
807       if( anIsVisibleInSelection )
808         theMenu->addAction( action( HideId ) );
809       theMenu->addSeparator();
810     }
811   }
812
813   if ( anIsOCCView )
814   {
815     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
816     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
817     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
818       theMenu->addAction( action( DeleteId ) );
819
820     theMenu->addSeparator();
821     theMenu->addAction( action( SetZLevelId ) );
822     theMenu->addSeparator();
823
824     if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
825       theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
826       theMenu->addSeparator();
827     }
828   }
829
830   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
831   {
832     theMenu->addAction( action( ShowAllId ) );
833     theMenu->addAction( action( HideAllId ) );
834     theMenu->addSeparator();
835   }
836
837   if ( anIsOCCView || anIsVTKView )
838   {
839     theMenu->addSeparator();
840     theMenu->addAction( action( CopyViewerPositionId ) );
841   }
842
843   if( isRoot )
844     theMenu->addAction( action( EditLocalCSId ) );
845
846   if( anIsObjectBrowser && anOwners.size()==1 )
847   {
848     if( aSeq.Size() > 0 )
849     {
850       Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
851       Handle(HYDROData_Object) anObject;
852       Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
853       Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
854
855       if (!anAObject.IsNull())
856         anObject = anAObject;
857       if (!aNObject.IsNull())
858         anObject = aNObject;
859
860       if( !anObject.IsNull() )
861       {
862         theMenu->addSeparator();
863         bool IsSubmersible = anObject->IsSubmersible();
864         if (!IsSubmersible)
865         {
866           theMenu->addAction( action( SubmersibleId ) );
867           action( SubmersibleId )->setCheckable(true);
868           action( SubmersibleId )->setChecked(true);
869         }
870         else
871         {
872           theMenu->addAction( action( UnSubmersibleId ) );
873           action( UnSubmersibleId )->setCheckable(true);
874           action( UnSubmersibleId )->setChecked(true);
875         }
876       }
877     }
878   }
879
880   theMenu->addSeparator();
881   QAction* a = action( ShowHideArrows );
882   a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
883   theMenu->addAction( a );
884 }
885
886 void HYDROGUI_Module::createPreferences()
887 {
888   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
889   int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
890
891   int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
892                                     LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
893
894   // Set property cursor type
895   QList<QVariant> aCursorTypeIndicesList;
896   QList<QVariant> aCursorTypeIconsList;
897
898   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
899   for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
900     QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
901     QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
902     aCursorTypeIndicesList << i;
903     aCursorTypeIconsList << pixmap;
904   }
905
906   setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
907   setPreferenceProperty( typeOfCursor, "icons",   aCursorTypeIconsList );
908
909   int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
910   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
911                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
912
913   addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
914
915   addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
916
917   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
918   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
919                                             LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
920   setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
921   setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
922   setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
923   setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
924
925   int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
926   int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
927     LightApp_Preferences::Selector, "polyline", "arrow_type" );
928
929   QList<QVariant> arrow_types;
930   arrow_types.append( tr( "No" ) );
931   arrow_types.append( tr( "Triangle" ) );
932   arrow_types.append( tr( "Cone" ) );
933   setPreferenceProperty( polylineArrow, "strings", arrow_types );
934
935   QList<QVariant> indices;
936   indices.append( 0 );
937   indices.append( 1 );
938   indices.append( 2 );
939   setPreferenceProperty( polylineArrow, "indexes", indices );
940   setPreferenceProperty( polylineArrow, "ids", indices );
941
942   int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
943     LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
944 }
945
946 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
947 {
948     SUIT_ResourceMgr* resMgr = application()->resourceMgr();
949     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
950     {
951         
952         Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
953         if ( resMgr && !aDoc.IsNull() )
954             aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
955     }
956     else if( theSection == "polyline" )
957     {
958       int aType = -1;
959       int aSize = -1;
960       if( resMgr )
961       {
962         resMgr->value( "polyline", "arrow_type", aType );
963         resMgr->value( "polyline", "arrow_size", aSize );
964       }
965       //Update polylines
966       ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
967       for( ; it!=last; it++ )
968       {
969         int aViewerId = it.key();
970         OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
971         if( aMgr )
972           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
973       }
974     }
975     else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
976     {
977       bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
978       setAutoZoomToAllViewManagers(!aZoomShutoff);
979     }
980     else if (theSection == "HYDRO" && thePref == "chained_panning")
981     {
982       bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
983       if (!aChainedPan)
984         resetViewState();
985       ViewManagerList aViewManagers = getApp()->viewManagers();
986       foreach (SUIT_ViewManager* aVMgr, aViewManagers)
987       {
988         OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
989         if (anOCCViewMgr)
990           anOCCViewMgr->setChainedOperations( aChainedPan );
991       }
992       
993       QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
994       foreach (QDockWidget* qw, docW)
995       {
996         HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
997         if (pdlg)
998           pdlg->viewManager()->setChainedOperations(aChainedPan);
999       }
1000     }
1001     else
1002       LightApp_Module::preferencesChanged( theSection, thePref );
1003 }
1004
1005 QCursor HYDROGUI_Module::getPrefEditCursor() const
1006 {
1007   int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
1008   if ( aCursorType >= Qt::BlankCursor)
1009     aCursorType++;
1010   QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
1011   return aCursor;
1012 }
1013
1014 void HYDROGUI_Module::update( const int flags )
1015 {
1016   if ( !isUpdateEnabled() )
1017     return;
1018
1019   QApplication::setOverrideCursor( Qt::WaitCursor );
1020
1021   // To prevent calling this method recursively
1022   // from one of the methods called below
1023   setUpdateEnabled( false );
1024
1025   // store selected objects
1026   QStringList aSelectedEntries = storeSelection();
1027
1028   bool aDoFitAll = flags & UF_FitAll;
1029   if ( aDoFitAll )
1030   {
1031     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1032     aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1033   }
1034
1035   if( ( flags & UF_Viewer ) )
1036     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
1037
1038   if( ( flags & UF_OCCViewer ) )
1039     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
1040
1041   if( ( flags & UF_VTKViewer ) )
1042     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
1043
1044   if( ( flags & UF_Model ) && getDataModel() && getApp() )
1045   {
1046     getDataModel()->update( getStudyId() );
1047
1048     // Temporary workaround to prevent breaking
1049     // the selection in the object browser.
1050     // Note: processEvents() should be called after updateGV(),
1051     // otherwise the application crashes from time to time.
1052     //RKV: qApp->processEvents();
1053     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1054     bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1055     SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1056     if ( isResizeOnExpandItem && anObjectBrowser ) {
1057       anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280 
1058     }
1059     getApp()->updateObjectBrowser( true );
1060     if ( isResizeOnExpandItem && anObjectBrowser ) {
1061       anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280 
1062     }
1063   }
1064
1065   // Object browser is currently updated by using UF_Model flag
1066   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1067     getApp()->updateObjectBrowser( true );
1068
1069   if( ( flags & UF_Controls ) && getApp() )
1070     getApp()->updateActions();
1071
1072   // restore selected objects
1073   restoreSelection( aSelectedEntries );
1074
1075   setUpdateEnabled( true );
1076
1077   preferencesChanged( "HYDRO", "zoom_shutoff" );
1078
1079   preferencesChanged( "HYDRO", "chained_panning" );
1080
1081   QApplication::restoreOverrideCursor();
1082 }
1083
1084 void HYDROGUI_Module::updateCommandsStatus()
1085 {
1086   LightApp_Module::updateCommandsStatus();
1087
1088   updateUndoRedoControls();
1089
1090   action( CopyId )->setEnabled( getDataModel()->canCopy() );
1091   action( PasteId )->setEnabled( getDataModel()->canPaste() );
1092 }
1093
1094 void HYDROGUI_Module::selectionChanged()
1095 {
1096   LightApp_Module::selectionChanged();
1097   updateCommandsStatus();
1098 }
1099
1100 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1101 {
1102   return (HYDROGUI_DataModel*)dataModel();
1103 }
1104
1105 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1106 {
1107   return myDisplayer;
1108 }
1109
1110 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1111 {
1112   return myOCCDisplayer;
1113 }
1114
1115 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1116 {
1117   return myVTKDisplayer;
1118 }
1119
1120 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1121 {
1122   if( myViewManagerMap.contains( theId ) )
1123   {
1124     return myViewManagerMap[ theId ].first;
1125   }
1126   return NULL;
1127 }
1128
1129 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1130 {
1131   if( myViewManagerMap.contains( theId ) )
1132   {
1133     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1134     GraphicsView_ViewManager* aViewManager =
1135       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1136     if( aViewManager )
1137       return aViewManager->getViewer();
1138   }
1139   return NULL;
1140 }
1141
1142 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1143 {
1144   if( myViewManagerMap.contains( theId ) )
1145   {
1146     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1147     OCCViewer_ViewManager* aViewManager =
1148       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1149     if( aViewManager )
1150       return aViewManager->getOCCViewer();
1151   }
1152   return NULL;
1153 }
1154
1155 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1156 {
1157   if( myViewManagerMap.contains( theId ) )
1158   {
1159     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1160     SVTK_ViewManager* aViewManager =
1161       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1162     if( aViewManager )
1163       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1164   }
1165   return NULL;
1166 }
1167
1168 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1169 {
1170   ViewManagerMapIterator anIter( myViewManagerMap );
1171   while( anIter.hasNext() )
1172   {
1173     int anId = anIter.next().key();
1174     const ViewManagerInfo& anInfo = anIter.value();
1175     if( anInfo.first == theViewManager )
1176       return anId;
1177   }
1178   return -1;
1179 }
1180
1181 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1182 {
1183   int anId = getViewManagerId( theViewManager );
1184   if( anId != -1 )
1185   {
1186     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1187     return anInfo.second;
1188   }
1189   return VMR_Unknown;
1190 }
1191
1192 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1193                                           const ViewManagerRole theRole )
1194 {
1195   int anId = getViewManagerId( theViewManager );
1196   if( anId != -1 )
1197   {
1198     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1199     anInfo.second = theRole;
1200   }
1201 }
1202
1203 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1204                                        const Handle(HYDROData_Entity)& theObject ) const
1205 {
1206   if( theObject.IsNull() )
1207     return false;
1208
1209   if( theViewId < 0 )
1210   {
1211     //search in all
1212     foreach( int aViewId, myObjectStateMap.keys() )
1213     {
1214       if( isObjectVisible( aViewId, theObject ) )
1215         return true;
1216     }
1217     return false;
1218   }
1219
1220   ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1221   if( anIter1 != myObjectStateMap.end() )
1222   {
1223     const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1224     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1225
1226     Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1227     if( anIter2 != aEntry2ObjectStateMap.end() )
1228     {
1229       const ObjectState& anObjectState = anIter2.value();
1230       return anObjectState.Visibility;
1231     }
1232   }
1233   return false;
1234 }
1235
1236 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1237                                         const Handle(HYDROData_Entity)& theObject,
1238                                         const bool theState )
1239 {
1240   if( !theObject.IsNull() )
1241   {
1242     Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1243     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1244
1245     ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1246     anObjectState.Visibility = theState;
1247
1248     HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1249     if ( hydroObject )
1250     {
1251         SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1252         if ( treeModel )
1253         {
1254           QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1255           Qtx::VisibilityState visState = treeModel->visibilityState( id );
1256           if ( visState != Qtx::UnpresentableState )
1257             treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1258         }
1259     }
1260
1261     if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1262       setLandCoversScalarMapModeOff( theViewId );
1263     } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1264       getOCCDisplayer()->SetToUpdateColorScale();
1265     }
1266   }
1267 }
1268
1269 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1270                                      const bool theState )
1271 {
1272   if( !theObject.IsNull() )
1273   {
1274     // Process OCC shapes
1275     ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1276     while( aShapesMapIter != myShapesMap.end() )
1277     {
1278       const ListOfShapes& aShapesList = aShapesMapIter.value();
1279       foreach ( HYDROGUI_Shape* aShape, aShapesList )
1280       {
1281         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1282         {
1283           aShape->setIsToUpdate( theState );
1284         }
1285       }
1286       aShapesMapIter++;
1287     }
1288     // Process VTK shapes
1289     ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1290     while( aVTKPrsMapIter != myVTKPrsMap.end() )
1291     {
1292       const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1293       foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1294       {
1295         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1296         {
1297           aShape->setIsToUpdate( theState );
1298         }
1299       }
1300       aVTKPrsMapIter++;
1301     }
1302   }
1303 }
1304
1305 /////////////////// OCC SHAPES PROCESSING
1306 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
1307                                                          ObjectKind theKind ) const
1308 {
1309   QList<HYDROGUI_Shape*> aResult;
1310
1311   if ( myShapesMap.contains( theViewId ) )
1312   {
1313     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1314     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1315     {
1316       if( aShape && aShape->getObject()->GetKind()==theKind )
1317         aResult.append( aShape );
1318     }
1319   }
1320   return aResult;
1321 }
1322
1323 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
1324                                                  const Handle(HYDROData_Entity)& theObject ) const
1325 {
1326   HYDROGUI_Shape* aResShape = NULL;
1327   if( theObject.IsNull() )
1328     return aResShape;
1329
1330   if ( myShapesMap.contains( theViewId ) )
1331   {
1332     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1333     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1334     {
1335       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1336         continue;
1337
1338       aResShape = aShape;
1339       break;
1340     }
1341   }
1342
1343   return aResShape;
1344 }
1345
1346 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
1347                                       const Handle(HYDROData_Entity)& theObject,
1348                                       HYDROGUI_Shape*                 theShape )
1349 {
1350   if( theObject.IsNull() )
1351     return;
1352
1353   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1354   aViewShapes.append( theShape );
1355 }
1356
1357 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
1358                                          const Handle(HYDROData_Entity)& theObject )
1359 {
1360   if ( !myShapesMap.contains( theViewId ) )
1361     return;
1362
1363   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1364   Handle(HYDROData_Entity) anObject;
1365   for ( int i = 0; i < aViewShapes.length(); )
1366   {
1367     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1368     anObject = aShape->getObject();
1369     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1370     {
1371       delete aShape;
1372       aViewShapes.removeAt( i );
1373       continue;
1374     }
1375
1376     ++i;
1377   }
1378 }
1379
1380 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1381 {
1382   if ( !myShapesMap.contains( theViewId ) )
1383     return;
1384
1385   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1386   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1387   {
1388     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1389     if ( aShape )
1390       delete aShape;
1391   }
1392
1393   myShapesMap.remove( theViewId );
1394 }
1395 /////////////////// END OF OCC SHAPES PROCESSING
1396
1397 /////////////////// VTKPrs PROCESSING
1398 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
1399                                                  const Handle(HYDROData_Entity)& theObject ) const
1400 {
1401   HYDROGUI_VTKPrs* aResShape = NULL;
1402   if( theObject.IsNull() )
1403     return aResShape;
1404
1405   if ( myVTKPrsMap.contains( theViewId ) )
1406   {
1407     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1408     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1409     {
1410       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1411         continue;
1412
1413       aResShape = aShape;
1414       break;
1415     }
1416   }
1417
1418   return aResShape;
1419 }
1420
1421 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
1422                                        const Handle(HYDROData_Entity)& theObject,
1423                                        HYDROGUI_VTKPrs*                 theShape )
1424 {
1425   if( theObject.IsNull() )
1426     return;
1427
1428   if( theShape && theShape->needScalarBar() )
1429   {
1430     // Compute the new global Z range from the added presentation and the old global Z range.
1431     double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1432     double* aRange = theShape->getInternalZRange();
1433     bool anIsUpdate = false;
1434     if ( aRange[0] < aGlobalRange[0] )
1435     {
1436       aGlobalRange[0] = aRange[0];
1437       anIsUpdate = true;
1438     }
1439     if ( aRange[1] > aGlobalRange[1] )
1440     {
1441       aGlobalRange[1] = aRange[1];
1442       anIsUpdate = true;
1443     }
1444
1445     //if ( anIsUpdate )
1446     //{
1447       updateVTKZRange( theViewId, aGlobalRange );
1448     //}
1449   }
1450
1451   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1452   aViewShapes.append( theShape );
1453 }
1454
1455 void HYDROGUI_Module::removeObjectVTKPrs( const int      theViewId,
1456                                           const QString& theEntry )
1457 {
1458   if ( !myVTKPrsMap.contains( theViewId ) )
1459     return;
1460
1461   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1462   Handle(HYDROData_Entity) anObject;
1463   QString anEntryRef;
1464   for ( int i = 0; i < aViewShapes.length(); )
1465   {
1466     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1467     anObject = aShape->getObject();
1468     anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1469     if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1470     {
1471       delete aShape;
1472       aViewShapes.removeAt( i );
1473       continue;
1474     }
1475
1476     ++i;
1477   }
1478
1479   // Invalidate global Z range
1480   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1481   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1482 }
1483
1484 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
1485                                           const Handle(HYDROData_Entity)& theObject )
1486 {
1487   if ( !myVTKPrsMap.contains( theViewId ) )
1488     return;
1489
1490   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1491   Handle(HYDROData_Entity) anObject;
1492   for ( int i = 0; i < aViewShapes.length(); )
1493   {
1494     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1495     anObject = aShape->getObject();
1496     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1497     {
1498       delete aShape;
1499       aViewShapes.removeAt( i );
1500       continue;
1501     }
1502
1503     ++i;
1504   }
1505
1506   // Invalidate global Z range
1507   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1508   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1509 }
1510
1511 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1512 {
1513   if ( !myVTKPrsMap.contains( theViewId ) )
1514     return;
1515
1516   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1517   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1518   {
1519     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1520     if ( aShape )
1521       delete aShape;
1522   }
1523
1524   myVTKPrsMap.remove( theViewId );
1525 }
1526
1527 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1528 {
1529   if ( myVTKPrsMap.contains( theViewId ) )
1530   {
1531     // For the given viewer id update all VTK presentations ...
1532     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1533     HYDROGUI_VTKPrs* aShape;
1534     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1535     {
1536       aShape = aViewShapes.at( i );
1537       if ( aShape && aShape->needScalarBar() )
1538       {
1539         aShape->setZRange( theRange );
1540       }
1541     }
1542   }
1543   // ... and update the global color legend scalar bar.
1544   getVTKDisplayer()->SetZRange( theViewId, theRange );
1545 }
1546 /////////////////// END OF VTKPrs PROCESSING
1547
1548 void HYDROGUI_Module::clearCache()
1549 {
1550     myObjectStateMap.clear();
1551 }
1552
1553 CAM_DataModel* HYDROGUI_Module::createDataModel()
1554 {
1555   return new HYDROGUI_DataModel( this );
1556 }
1557
1558 void HYDROGUI_Module::customEvent( QEvent* e )
1559 {
1560   int aType = e->type();
1561   if ( aType == NewViewEvent )
1562   {
1563     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1564     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1565     {
1566       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1567       {
1568         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1569         ViewManagerRole aRole = getViewManagerRole( aViewManager );
1570
1571         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1572         {
1573           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1574             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1575
1576           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1577           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1578           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1579
1580           //ouv: temporarily commented
1581           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1582         }
1583
1584         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1585           update( UF_Viewer );
1586
1587         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1588       }
1589     }
1590   }
1591 }
1592
1593 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1594 {
1595   QEvent::Type aType = theEvent->type();
1596   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1597   {
1598     if( aType == QEvent::Show )
1599     {
1600       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1601       e->setData( theObj );
1602       QApplication::postEvent( this, e );
1603       theObj->removeEventFilter( this );
1604     }
1605   }
1606   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1607   {
1608     if( aType == QEvent::Leave )
1609     {
1610       SUIT_Desktop* aDesktop = getApp()->desktop();
1611       if ( aDesktop && aDesktop->statusBar() ) {
1612         aDesktop->statusBar()->clearMessage();
1613       }
1614     }
1615   }
1616   else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1617   {
1618     if( aType == QEvent::Leave )
1619     {
1620       SUIT_Desktop* aDesktop = getApp()->desktop();
1621       if ( aDesktop && aDesktop->statusBar() ) {
1622         aDesktop->statusBar()->clearMessage();
1623       }
1624     }
1625   }
1626
1627   return LightApp_Module::eventFilter( theObj, theEvent );
1628 }
1629
1630 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1631 {
1632   LightApp_Module::onViewManagerAdded( theViewManager );
1633
1634   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1635   { 
1636     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1637              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1638   }
1639   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1640   {
1641     OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1642     //mgr->setChainedOperations( true );
1643
1644     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1645              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1646     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1647              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1648     connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
1649              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1650   }
1651   else if( theViewManager->getType() == SVTK_Viewer::Type() )
1652   {
1653     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1654              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1655     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1656              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1657   }
1658
1659   createSelector( theViewManager ); // replace the default selector
1660
1661   ViewManagerInfo anInfo( theViewManager, VMR_General );
1662   myViewManagerMap.insert( ViewManagerId++, anInfo );
1663 }
1664
1665 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1666 {
1667   LightApp_Module::onViewManagerRemoved( theViewManager );
1668
1669   createSelector( theViewManager ); // replace the default selector
1670
1671   int anId = getViewManagerId( theViewManager );
1672   if( anId != -1 )
1673   {
1674     OCCViewer_ViewManager* anOCCViewManager =
1675       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1676     if ( anOCCViewManager )
1677     {
1678       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1679       if ( anOCCViewer ) {
1680         int aViewerId = (size_t)anOCCViewer;
1681         removeViewShapes( aViewerId );
1682         setLandCoversScalarMapModeOff( aViewerId );
1683       }
1684     }
1685
1686     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1687     {
1688       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1689       if ( aVTKViewer )
1690       {
1691         getVTKDisplayer()->EraseScalarBar( anId, true );
1692         removeViewShapes( (size_t)aVTKViewer );
1693       }
1694     }
1695
1696     myViewManagerMap.remove( anId );
1697   }
1698 }
1699
1700 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1701 {
1702   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1703   {
1704     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1705     {
1706       aViewFrame->installEventFilter( this );
1707
1708       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1709       aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1710
1711       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1712                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1713     }
1714   }
1715   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1716   {
1717     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1718     {
1719       aViewFrame->onTopView();
1720
1721       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1722       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1723       if ( aViewPort ) {
1724         aViewPort->installEventFilter( this );
1725       }
1726     }
1727   }
1728   else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1729   {
1730     if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1731     {
1732       aViewFrame->installEventFilter( this );
1733     }
1734   }
1735 }
1736
1737 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1738 {
1739   /* ouv: currently unused
1740   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1741   {
1742     SUIT_ViewManager* aViewManager = 0;
1743
1744     QObject* aParent = aViewPort;
1745     while( aParent = aParent->parent() )
1746     {
1747       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1748       {
1749         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1750         {
1751           aViewManager = aViewer->getViewManager();
1752           break;
1753         }
1754       }
1755     }
1756
1757     if( !aViewManager )
1758       return;
1759
1760     double aMouseX = theEvent->scenePos().x();
1761     double aMouseY = theEvent->scenePos().y();
1762
1763     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1764     if( aRole == VMR_General )
1765     {
1766       int aXDeg = 0, aYDeg = 0;
1767       int aXMin = 0, aYMin = 0;
1768       double aXSec = 0, aYSec = 0;
1769       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1770       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1771
1772       QString aDegSymbol( QChar( 0x00B0 ) );
1773       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1774       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1775
1776       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1777     }
1778     else if( aRole == VMR_TransformImage )
1779       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1780   }
1781   */
1782 }
1783
1784 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1785                                     const bool theIsInit, 
1786                                     const bool theIsForced, 
1787                                     const bool theDoFitAll )
1788 {
1789   QList<int> aViewManagerIdList;
1790
1791   // currently, all views are updated
1792   ViewManagerMapIterator anIter( myViewManagerMap );
1793   while( anIter.hasNext() )
1794   { 
1795     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1796
1797     if ( theDisplayer->IsApplicable( aViewManager ) )
1798     {
1799       int anId = anIter.key();
1800       aViewManagerIdList.append( anId );
1801     }
1802   }
1803
1804   QListIterator<int> anIdIter( aViewManagerIdList );
1805   while( anIdIter.hasNext() )
1806   {
1807     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1808     myOverview->setTopView();
1809   }
1810 }
1811
1812 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1813 {
1814   if( !theViewManager )
1815     return;
1816
1817   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1818   if( !aSelectionMgr )
1819     return;
1820
1821   QString aViewType = theViewManager->getType();
1822   if( aViewType != GraphicsView_Viewer::Type() &&
1823       aViewType != OCCViewer_Viewer::Type())
1824     return;
1825
1826   QList<SUIT_Selector*> aSelectorList;
1827   aSelectionMgr->selectors( aViewType, aSelectorList );
1828
1829   // disable all alien selectors
1830   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1831   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1832   {
1833     SUIT_Selector* aSelector = *anIter;
1834     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1835                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1836                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1837       aSelector->setEnabled( false );
1838   }
1839
1840   if ( aViewType == GraphicsView_Viewer::Type() )
1841   {
1842     GraphicsView_ViewManager* aViewManager =
1843       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1844     if( aViewManager )
1845       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1846   }
1847   else if ( aViewType == OCCViewer_Viewer::Type() )
1848   {
1849     OCCViewer_ViewManager* aViewManager =
1850       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1851     if( aViewManager )
1852       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1853   }
1854 }
1855
1856 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1857 {
1858   bool aPrevState = myIsUpdateEnabled;
1859   myIsUpdateEnabled = theState;
1860   return aPrevState;
1861 }
1862
1863 bool HYDROGUI_Module::isUpdateEnabled() const
1864 {
1865   return myIsUpdateEnabled;
1866 }
1867
1868 QStringList HYDROGUI_Module::storeSelection() const
1869 {
1870   QStringList anEntryList;
1871   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1872   {
1873     SUIT_DataOwnerPtrList aList( true );
1874     aSelectionMgr->selected( aList );
1875
1876     SUIT_DataOwnerPtrList::iterator anIter;
1877     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1878     {
1879       const LightApp_DataOwner* anOwner = 
1880         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1881       if( anOwner )
1882         anEntryList.append( anOwner->entry() );
1883     }
1884   }
1885   return anEntryList;
1886 }
1887
1888 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1889 {
1890   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1891   {
1892     SUIT_DataOwnerPtrList aList( true );
1893     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1894       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1895     aSelectionMgr->setSelected( aList );
1896   }
1897 }
1898
1899 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1900 {
1901   double X, Y, Z;
1902   bool doShow = false;
1903   HYDROGUI_Displayer* aDisplayer = getDisplayer();
1904   if ( aDisplayer )
1905     aDisplayer->SaveCursorViewPosition( theViewWindow );
1906     doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1907
1908   if ( doShow )
1909   {
1910     // Show the coordinates in the status bar
1911     SUIT_Desktop* aDesktop = getApp()->desktop();
1912     if ( aDesktop && aDesktop->statusBar() )
1913     {
1914       gp_Pnt aWPnt( X, Y, Z );
1915       int aStudyId = application()->activeStudy()->id();
1916       HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1917       double WX = aWPnt.X(), WY = aWPnt.Y();
1918
1919       QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1920       QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1921       QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1922       QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1923       QString aMsg = tr( "COORDINATES_INFO" );
1924       aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1925       aDesktop->statusBar()->showMessage( aMsg );
1926     }
1927   }
1928 }
1929
1930 /**
1931  * Returns stack of active operations;
1932  */
1933 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1934 {
1935   return myActiveOperationMap;
1936 }
1937
1938 /**
1939  * Returns the module active operation. If the active operation is show/hide,
1940  * the method returns the previous operation if it is.
1941  */
1942 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1943 {
1944   HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1945
1946   if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1947   {
1948     QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1949     aVIt.toBack();
1950     aVIt.previous(); // skip the top show/hide operation
1951     anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1952   }
1953
1954   return anOp;
1955 }
1956
1957 /*!
1958  * \brief Virtual public slot
1959  *
1960  * This method is called after the object inserted into data view to update their visibility state
1961  * This is default implementation
1962  */
1963 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1964 {
1965   if ( !isActiveModule() )
1966       return;
1967
1968   HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1969
1970   // change visibility of object
1971   if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1972       return;
1973
1974   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1975
1976   QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1977   Qtx::VisibilityState visState = treeModel->visibilityState( id );
1978   if ( visState == Qtx::UnpresentableState )
1979       return;
1980
1981   visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1982   treeModel->setVisibilityState( id, visState );
1983
1984   bool vis = visState == Qtx::ShownState;
1985   if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1986       return;
1987
1988   setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1989
1990   update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1991 }
1992
1993 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1994 {
1995   Handle(HYDROData_StricklerTable) aTable;
1996
1997   if ( myLandCoverColoringMap.contains( theViewId ) ) {
1998     aTable = myLandCoverColoringMap.value( theViewId );
1999   }
2000
2001   return aTable;
2002 }
2003
2004 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
2005                                                  const Handle(HYDROData_StricklerTable)& theTable )
2006 {
2007   if ( !theTable.IsNull() ) {
2008     myLandCoverColoringMap.insert( theViewId, theTable );
2009   }
2010 }
2011
2012 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
2013 {
2014   myLandCoverColoringMap.remove( theViewId );
2015 }
2016
2017 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
2018 {
2019   return myLandCoverColoringMap.contains( theViewId );
2020 }
2021
2022 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2023 {
2024   if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2025     return;
2026   }
2027
2028   if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2029     Handle(HYDROData_StricklerTable) aTable = 
2030       Handle(HYDROData_StricklerTable)::DownCast( theObject );
2031     QList<int> aViewIds;
2032     QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2033     while ( anIter.hasNext() ) {
2034       if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) == 
2035            HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2036         anIter.remove();
2037       }
2038     }
2039   }
2040 }
2041
2042 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2043 {
2044   if( !theMgr )
2045     return;
2046
2047   SUIT_ViewWindow* wnd = theMgr->getActiveView();
2048   OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2049   if( !occwnd )
2050     return;
2051
2052   myOverview->setMainView( occwnd );
2053 }
2054
2055 void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
2056 {
2057   ViewManagerList aViewManagers = getApp()->viewManagers();
2058   foreach (SUIT_ViewManager* aVMgr, aViewManagers)
2059     setAutoZoom(aVMgr, bAutoZoom);
2060 }
2061
2062 void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
2063 {
2064   if (!aVMgr)
2065     return;
2066   QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
2067   foreach (SUIT_ViewWindow* aView, aViews)
2068   {
2069     if (aView)
2070     {
2071       OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
2072       if (anOCCViewFrame)
2073       {
2074         anOCCViewFrame->setAutomaticZoom(bAutoZoom);
2075         for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
2076         {
2077           OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
2078           if (aV)
2079             aV->setAutomaticZoom(bAutoZoom);
2080         }
2081       }
2082       OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
2083       if (anOCCViewWindow)
2084         anOCCViewWindow->setAutomaticZoom(bAutoZoom);
2085     }
2086   }
2087 }
2088