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