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