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