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