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