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