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