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