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