Salome HOME
81ad9fa08755b9f788dd910c46f02633b4c3bd1b
[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( HYDROData_Entity::Geom_All ) )
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           theMenu->addAction( action( ImportLandCoverId ) ); 
523           break;
524         case KIND_CALCULATION:
525           theMenu->addAction( action( CreateCalculationId ) );
526           break;
527         case KIND_POLYLINEXY:
528           theMenu->addAction( action( ImportPolylineId ) );
529           theMenu->addAction( action( CreatePolylineId ) );
530           break;
531         case KIND_POLYLINE:
532           theMenu->addAction( action( CreatePolyline3DId ) );
533           break;
534         case KIND_PROFILE:
535           theMenu->addAction( action( CreateProfileId ) );
536           theMenu->addAction( action( ImportProfilesId ) );
537           theMenu->addAction( action( AllGeoreferencementId ) );
538           break;
539         case KIND_VISUAL_STATE:
540           theMenu->addAction( action( SaveVisualStateId ) );
541           break;
542       }
543       theMenu->addSeparator();
544     }
545   }
546
547   if( anIsSelectedDataObjects )
548   {
549     if ( anIsMustObjectBeUpdated )
550     {
551       theMenu->addAction( action( UpdateObjectId ) );
552       theMenu->addSeparator();
553     }
554     else
555     {
556       theMenu->addAction( action( ForcedUpdateObjectId ) );
557       theMenu->addSeparator();
558     }
559
560
561     if( aSeq.Length() == 1 )
562     {
563       if( anIsImage )
564       {
565         if( anIsImportedImage )
566           theMenu->addAction( action( EditImportedImageId ) );
567         else if( anIsImageHasRefs )
568         {
569           if( anIsFusedImage )
570             theMenu->addAction( action( EditFusedImageId ) );
571           else if( anIsCutImage )
572             theMenu->addAction( action( EditCutImageId ) );
573           else if( anIsSplittedImage )
574             theMenu->addAction( action( EditSplittedImageId ) );
575         }
576
577         //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
578         theMenu->addAction( action( ExportImageId ) );
579         theMenu->addSeparator();
580
581         if( anIsImageHasRefs )
582         {
583           theMenu->addAction( action( RemoveImageRefsId ) );
584           theMenu->addSeparator();
585         }
586
587         theMenu->addAction( action( FuseImagesId ) );
588         theMenu->addAction( action( CutImagesId ) );
589         theMenu->addAction( action( SplitImageId ) );
590         theMenu->addSeparator();
591         theMenu->addAction( action( RecognizeContoursId ) );
592         theMenu->addSeparator();
593       }
594       else if( anIsBathymetry )
595       {
596         theMenu->addAction( action( EditImportedBathymetryId ) );
597         theMenu->addAction( action( BathymetryBoundsId ) );
598         theMenu->addSeparator();
599       }
600       else if( anIsPolyline )
601       {
602         theMenu->addAction( action( EditPolylineId ) );
603         theMenu->addSeparator();
604         theMenu->addAction( action( SplitPolylinesId ) );
605         theMenu->addAction( action( MergePolylinesId ) );
606         theMenu->addSeparator();
607       }
608       else if( anIsPolyline3D )
609       {
610         theMenu->addAction( action( EditPolyline3DId ) );
611         theMenu->addSeparator();
612       }
613       else if( anIsProfile )
614       {
615         theMenu->addAction( action( EditProfileId ) );
616         theMenu->addAction( action( SelectedGeoreferencementId ) );
617         theMenu->addSeparator();
618       }
619       else if( anIsCalculation )
620       {
621         theMenu->addAction( action( EditCalculationId ) );
622         theMenu->addAction( action( ExportCalculationId ) );
623         theMenu->addSeparator();
624       }
625       else if( anIsImmersibleZone )
626       {
627         theMenu->addAction( action( EditImmersibleZoneId ) );
628         theMenu->addSeparator();
629       }
630       else if( anIsStream )
631       {
632         theMenu->addAction( action( EditStreamId ) );
633         if ( action( RiverBottomContextId ) )
634         {
635             theMenu->addAction( action( RiverBottomContextId ) );
636             action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
637         }
638         theMenu->addAction( action( ProfileInterpolateId ) );
639         theMenu->addSeparator();
640       }
641       else if( anIsChannel )
642       {
643         theMenu->addAction( action( EditChannelId ) );
644         theMenu->addSeparator();
645       }
646       else if( anIsDigue )
647       {
648         theMenu->addAction( action( EditDigueId ) );
649         theMenu->addSeparator();
650       }
651       else if( anIsObstacle )
652       {
653         theMenu->addAction( action( TranslateObstacleId ) );
654         theMenu->addSeparator();
655       }
656       else if( anIsStricklerTable )
657       {
658         theMenu->addAction( action( EditStricklerTableId ) );
659         theMenu->addAction( action( ExportStricklerTableFromFileId ) );
660         theMenu->addAction( action( DuplicateStricklerTableId ) );
661         theMenu->addSeparator();
662
663         Handle(HYDROData_StricklerTable) aTable = 
664           Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
665         QString aCurrentTable = 
666           HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
667         bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
668
669         if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER ).isEmpty() ) {
670           theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
671           theMenu->addSeparator();
672         }
673       }
674       else if( anIsLandCover )
675       {
676         theMenu->addAction( action( EditLandCoverId ) );
677         theMenu->addSeparator();
678       }      
679       else if( anIsVisualState && anIsObjectBrowser )
680       {
681         theMenu->addAction( action( SaveVisualStateId ) );
682         theMenu->addAction( action( LoadVisualStateId ) );
683         theMenu->addSeparator();
684       }
685
686       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
687       {
688         theMenu->addAction( action( PolylineExtractionId ) );
689         theMenu->addSeparator();
690       }
691
692       // Add set color action for geometrical objects
693       if ( anIsObjectCanBeColored )
694       {
695         theMenu->addAction( action( SetColorId ) );
696         theMenu->addSeparator();
697       }
698     } else if ( anAllAreProfiles ) {
699       theMenu->addAction( action( SelectedGeoreferencementId ) );
700       theMenu->addSeparator();
701     }
702
703     bool anIsPoly = anIsPolyline || anIsPolyline3D;
704     if ((anIsPoly && !anIsLandCover) || (!anIsPoly && anIsLandCover))
705       theMenu->addAction( action( ExportToShapeFileID ) );
706
707     // Add copy action
708     QAction* aCopyAction = action( CopyId );
709     if( aCopyAction && aCopyAction->isEnabled() ) {
710       theMenu->addAction( action( CopyId ) );
711       theMenu->addSeparator();
712     }
713
714     // Add delete action
715     if( !anIsDummyObject3D )
716       theMenu->addAction( action( DeleteId ) );
717
718     theMenu->addSeparator();
719
720     if( anIsImage || anIsPolyline || anIsPolyline3D || 
721         anIsImmersibleZone || anIsZone || anIsRegion ||
722         anIsBathymetry || anIsObstacle || anIsStream ||
723         anIsChannel || anIsDigue || anIsDummyObject3D ||
724         anIsValidProfile || anIsGroup || anIsLandCover )
725     {
726       if( anIsHiddenInSelection )
727         theMenu->addAction( action( ShowId ) );
728       theMenu->addAction( action( ShowOnlyId ) );
729       if( anIsVisibleInSelection )
730         theMenu->addAction( action( HideId ) );
731       theMenu->addSeparator();
732     }
733   }
734
735   if ( anIsOCCView )
736   {
737     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
738     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
739     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
740       theMenu->addAction( action( DeleteId ) );
741
742     theMenu->addSeparator();
743     theMenu->addAction( action( SetZLevelId ) );
744     theMenu->addSeparator();
745
746     if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
747       theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
748       theMenu->addSeparator();
749     }
750   }
751
752   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
753   {
754     theMenu->addAction( action( ShowAllId ) );
755     theMenu->addAction( action( HideAllId ) );
756     theMenu->addSeparator();
757   }
758   
759   if ( anIsOCCView || anIsVTKView )
760   {
761     theMenu->addSeparator();
762     theMenu->addAction( action( CopyViewerPositionId ) );
763   }
764
765   if( isRoot )
766     theMenu->addAction( action( EditLocalCSId ) );
767
768   if( anIsObjectBrowser && anOwners.size()==1 )
769   {
770     if( aSeq.Size() > 0 )
771     {
772       Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
773       if( !anObject.IsNull() )
774       {
775         theMenu->addSeparator();
776         theMenu->addAction( action( SubmersibleId ) );
777         action( SubmersibleId )->setCheckable( true );
778         action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
779       }
780     }
781   }
782 }
783
784 void HYDROGUI_Module::createPreferences()
785 {
786   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
787   int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
788
789   int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
790                                     LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
791
792   // Set property cursor type
793   QList<QVariant> aCursorTypeIndicesList;
794   QList<QVariant> aCursorTypeIconsList;
795
796   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
797   for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
798     QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
799     QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
800     aCursorTypeIndicesList << i;
801     aCursorTypeIconsList << pixmap;
802   }
803
804   setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
805   setPreferenceProperty( typeOfCursor, "icons",   aCursorTypeIconsList );
806
807   int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
808   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
809                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
810
811   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
812   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
813                                             LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
814   setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
815   setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
816   setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
817   setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
818 }
819
820 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
821 {
822     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
823     {
824         SUIT_ResourceMgr* resMgr = application()->resourceMgr();
825         Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
826         if ( resMgr && !aDoc.IsNull() )
827             aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
828     }
829     else
830         LightApp_Module::preferencesChanged( theSection, thePref );
831 }
832
833 QCursor HYDROGUI_Module::getPrefEditCursor() const
834 {
835   int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
836   if ( aCursorType >= Qt::BlankCursor)
837     aCursorType++;
838   QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
839   return aCursor;
840 }
841
842 void HYDROGUI_Module::update( const int flags )
843 {
844   if ( !isUpdateEnabled() )
845     return;
846
847   QApplication::setOverrideCursor( Qt::WaitCursor );
848
849   // To prevent calling this method recursively
850   // from one of the methods called below
851   setUpdateEnabled( false );
852
853   // store selected objects
854   QStringList aSelectedEntries = storeSelection();
855
856   bool aDoFitAll = flags & UF_FitAll;
857   if ( aDoFitAll )
858   {
859     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
860     aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
861   }
862
863   if( ( flags & UF_Viewer ) )
864     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
865
866   if( ( flags & UF_OCCViewer ) )
867     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
868
869   if( ( flags & UF_VTKViewer ) )
870     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
871
872   if( ( flags & UF_Model ) && getDataModel() && getApp() )
873   {
874     getDataModel()->update( getStudyId() );
875
876     // Temporary workaround to prevent breaking
877     // the selection in the object browser.
878     // Note: processEvents() should be called after updateGV(),
879     // otherwise the application crashes from time to time.
880     //RKV: qApp->processEvents();
881     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
882     bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
883     SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
884     if ( isResizeOnExpandItem && anObjectBrowser ) {
885       anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280 
886     }
887     getApp()->updateObjectBrowser( true );
888     if ( isResizeOnExpandItem && anObjectBrowser ) {
889       anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280 
890     }
891   }
892
893   // Object browser is currently updated by using UF_Model flag
894   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
895     getApp()->updateObjectBrowser( true );
896
897   if( ( flags & UF_Controls ) && getApp() )
898     getApp()->updateActions();
899
900   // restore selected objects
901   restoreSelection( aSelectedEntries );
902
903   setUpdateEnabled( true );
904
905   QApplication::restoreOverrideCursor();
906 }
907
908 void HYDROGUI_Module::updateCommandsStatus()
909 {
910   LightApp_Module::updateCommandsStatus();
911
912   updateUndoRedoControls();
913
914   action( CopyId )->setEnabled( getDataModel()->canCopy() );
915   action( PasteId )->setEnabled( getDataModel()->canPaste() );
916 }
917
918 void HYDROGUI_Module::selectionChanged()
919 {
920   LightApp_Module::selectionChanged();
921   updateCommandsStatus();
922 }
923
924 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
925 {
926   return (HYDROGUI_DataModel*)dataModel();
927 }
928
929 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
930 {
931   return myDisplayer;
932 }
933
934 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
935 {
936   return myOCCDisplayer;
937 }
938
939 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
940 {
941   return myVTKDisplayer;
942 }
943
944 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
945 {
946   if( myViewManagerMap.contains( theId ) )
947   {
948     return myViewManagerMap[ theId ].first;
949   }
950   return NULL;
951 }
952
953 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
954 {
955   if( myViewManagerMap.contains( theId ) )
956   {
957     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
958     GraphicsView_ViewManager* aViewManager =
959       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
960     if( aViewManager )
961       return aViewManager->getViewer();
962   }
963   return NULL;
964 }
965
966 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
967 {
968   if( myViewManagerMap.contains( theId ) )
969   {
970     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
971     OCCViewer_ViewManager* aViewManager =
972       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
973     if( aViewManager )
974       return aViewManager->getOCCViewer();
975   }
976   return NULL;
977 }
978
979 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
980 {
981   if( myViewManagerMap.contains( theId ) )
982   {
983     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
984     SVTK_ViewManager* aViewManager =
985       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
986     if( aViewManager )
987       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
988   }
989   return NULL;
990 }
991
992 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
993 {
994   ViewManagerMapIterator anIter( myViewManagerMap );
995   while( anIter.hasNext() )
996   {
997     int anId = anIter.next().key();
998     const ViewManagerInfo& anInfo = anIter.value();
999     if( anInfo.first == theViewManager )
1000       return anId;
1001   }
1002   return -1;
1003 }
1004
1005 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1006 {
1007   int anId = getViewManagerId( theViewManager );
1008   if( anId != -1 )
1009   {
1010     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1011     return anInfo.second;
1012   }
1013   return VMR_Unknown;
1014 }
1015
1016 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1017                                           const ViewManagerRole theRole )
1018 {
1019   int anId = getViewManagerId( theViewManager );
1020   if( anId != -1 )
1021   {
1022     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1023     anInfo.second = theRole;
1024   }
1025 }
1026
1027 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1028                                        const Handle(HYDROData_Entity)& theObject ) const
1029 {
1030   if( theObject.IsNull() )
1031     return false;
1032
1033   if( theViewId < 0 )
1034   {
1035     //search in all
1036     foreach( int aViewId, myObjectStateMap.keys() )
1037     {
1038       if( isObjectVisible( aViewId, theObject ) )
1039         return true;
1040     }
1041     return false;
1042   }
1043
1044   ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1045   if( anIter1 != myObjectStateMap.end() )
1046   {
1047     const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1048     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1049
1050     Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1051     if( anIter2 != aEntry2ObjectStateMap.end() )
1052     {
1053       const ObjectState& anObjectState = anIter2.value();
1054       return anObjectState.Visibility;
1055     }
1056   }
1057   return false;
1058 }
1059
1060 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1061                                         const Handle(HYDROData_Entity)& theObject,
1062                                         const bool theState )
1063 {
1064   if( !theObject.IsNull() )
1065   {
1066     Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1067     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1068
1069     ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1070     anObjectState.Visibility = theState;
1071
1072     HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1073     if ( hydroObject )
1074     {
1075         SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1076         QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1077         Qtx::VisibilityState visState = treeModel->visibilityState( id );
1078         if ( visState != Qtx::UnpresentableState )
1079             treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1080     }
1081
1082     if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1083       setLandCoversScalarMapModeOff( theViewId );
1084     } else if ( theObject->GetKind() == KIND_LAND_COVER && theState ) {
1085       getOCCDisplayer()->SetToUpdateColorScale();
1086     }
1087   }
1088 }
1089
1090 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1091                                      const bool theState )
1092 {
1093   if( !theObject.IsNull() )
1094   {
1095     // Process OCC shapes
1096     ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1097     while( aShapesMapIter != myShapesMap.end() )
1098     {
1099       const ListOfShapes& aShapesList = aShapesMapIter.value();
1100       foreach ( HYDROGUI_Shape* aShape, aShapesList )
1101       {
1102         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1103         {
1104           aShape->setIsToUpdate( theState );
1105         }
1106       }
1107       aShapesMapIter++;
1108     }
1109     // Process VTK shapes
1110     ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1111     while( aVTKPrsMapIter != myVTKPrsMap.end() )
1112     {
1113       const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1114       foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1115       {
1116         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1117         {
1118           aShape->setIsToUpdate( theState );
1119         }
1120       }
1121       aVTKPrsMapIter++;
1122     }
1123   }
1124 }
1125
1126 /////////////////// OCC SHAPES PROCESSING
1127 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int  theViewId,
1128                                                          ObjectKind theKind ) const
1129 {
1130   QList<HYDROGUI_Shape*> aResult;
1131
1132   if ( myShapesMap.contains( theViewId ) )
1133   {
1134     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1135     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1136     {
1137       if( aShape && aShape->getObject()->GetKind()==theKind )
1138         aResult.append( aShape );
1139     }
1140   }
1141   return aResult;
1142 }
1143
1144 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
1145                                                  const Handle(HYDROData_Entity)& theObject ) const
1146 {
1147   HYDROGUI_Shape* aResShape = NULL;
1148   if( theObject.IsNull() )
1149     return aResShape;
1150
1151   if ( myShapesMap.contains( theViewId ) )
1152   {
1153     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1154     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1155     {
1156       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1157         continue;
1158
1159       aResShape = aShape;
1160       break;
1161     }
1162   }
1163
1164   return aResShape;
1165 }
1166
1167 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
1168                                       const Handle(HYDROData_Entity)& theObject,
1169                                       HYDROGUI_Shape*                 theShape )
1170 {
1171   if( theObject.IsNull() )
1172     return;
1173
1174   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1175   aViewShapes.append( theShape );
1176 }
1177
1178 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
1179                                          const Handle(HYDROData_Entity)& theObject )
1180 {
1181   if ( !myShapesMap.contains( theViewId ) )
1182     return;
1183
1184   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1185   Handle(HYDROData_Entity) anObject;
1186   for ( int i = 0; i < aViewShapes.length(); )
1187   {
1188     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1189     anObject = aShape->getObject();
1190     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1191     {
1192       delete aShape;
1193       aViewShapes.removeAt( i );
1194       continue;
1195     }
1196
1197     ++i;
1198   }
1199 }
1200
1201 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1202 {
1203   if ( !myShapesMap.contains( theViewId ) )
1204     return;
1205
1206   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1207   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1208   {
1209     HYDROGUI_Shape* aShape = aViewShapes.at( i );
1210     if ( aShape )
1211       delete aShape;
1212   }
1213
1214   myShapesMap.remove( theViewId );
1215 }
1216 /////////////////// END OF OCC SHAPES PROCESSING
1217
1218 /////////////////// VTKPrs PROCESSING
1219 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
1220                                                  const Handle(HYDROData_Entity)& theObject ) const
1221 {
1222   HYDROGUI_VTKPrs* aResShape = NULL;
1223   if( theObject.IsNull() )
1224     return aResShape;
1225
1226   if ( myVTKPrsMap.contains( theViewId ) )
1227   {
1228     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1229     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1230     {
1231       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1232         continue;
1233
1234       aResShape = aShape;
1235       break;
1236     }
1237   }
1238
1239   return aResShape;
1240 }
1241
1242 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
1243                                        const Handle(HYDROData_Entity)& theObject,
1244                                        HYDROGUI_VTKPrs*                 theShape )
1245 {
1246   if( theObject.IsNull() )
1247     return;
1248
1249   if( theShape && theShape->needScalarBar() )
1250   {
1251     // Compute the new global Z range from the added presentation and the old global Z range.
1252     double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1253     double* aRange = theShape->getInternalZRange();
1254     bool anIsUpdate = false;
1255     if ( aRange[0] < aGlobalRange[0] )
1256     {
1257       aGlobalRange[0] = aRange[0];
1258       anIsUpdate = true;
1259     }
1260     if ( aRange[1] > aGlobalRange[1] )
1261     {
1262       aGlobalRange[1] = aRange[1];
1263       anIsUpdate = true;
1264     }
1265
1266     //if ( anIsUpdate )
1267     //{
1268       updateVTKZRange( theViewId, aGlobalRange );
1269     //}
1270   }
1271
1272   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1273   aViewShapes.append( theShape );
1274 }
1275
1276 void HYDROGUI_Module::removeObjectVTKPrs( const int      theViewId,
1277                                           const QString& theEntry )
1278 {
1279   if ( !myVTKPrsMap.contains( theViewId ) )
1280     return;
1281
1282   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1283   Handle(HYDROData_Entity) anObject;
1284   QString anEntryRef;
1285   for ( int i = 0; i < aViewShapes.length(); )
1286   {
1287     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1288     anObject = aShape->getObject();
1289     anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1290     if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1291     {
1292       delete aShape;
1293       aViewShapes.removeAt( i );
1294       continue;
1295     }
1296
1297     ++i;
1298   }
1299
1300   // Invalidate global Z range
1301   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1302   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1303 }
1304
1305 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
1306                                           const Handle(HYDROData_Entity)& theObject )
1307 {
1308   if ( !myVTKPrsMap.contains( theViewId ) )
1309     return;
1310
1311   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1312   Handle(HYDROData_Entity) anObject;
1313   for ( int i = 0; i < aViewShapes.length(); )
1314   {
1315     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1316     anObject = aShape->getObject();
1317     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1318     {
1319       delete aShape;
1320       aViewShapes.removeAt( i );
1321       continue;
1322     }
1323
1324     ++i;
1325   }
1326
1327   // Invalidate global Z range
1328   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1329   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1330 }
1331
1332 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1333 {
1334   if ( !myVTKPrsMap.contains( theViewId ) )
1335     return;
1336
1337   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1338   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1339   {
1340     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1341     if ( aShape )
1342       delete aShape;
1343   }
1344
1345   myVTKPrsMap.remove( theViewId );
1346 }
1347
1348 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1349 {
1350   if ( myVTKPrsMap.contains( theViewId ) )
1351   {
1352     // For the given viewer id update all VTK presentations ...
1353     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1354     HYDROGUI_VTKPrs* aShape;
1355     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1356     {
1357       aShape = aViewShapes.at( i );
1358       if ( aShape && aShape->needScalarBar() )
1359       {
1360         aShape->setZRange( theRange );
1361       }
1362     }
1363   }
1364   // ... and update the global color legend scalar bar.
1365   getVTKDisplayer()->SetZRange( theViewId, theRange );
1366 }
1367 /////////////////// END OF VTKPrs PROCESSING
1368
1369 void HYDROGUI_Module::clearCache()
1370 {
1371     myObjectStateMap.clear();
1372 }
1373
1374 CAM_DataModel* HYDROGUI_Module::createDataModel()
1375 {
1376   return new HYDROGUI_DataModel( this );
1377 }
1378
1379 void HYDROGUI_Module::customEvent( QEvent* e )
1380 {
1381   int aType = e->type();
1382   if ( aType == NewViewEvent )
1383   {
1384     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1385     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1386     {
1387       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1388       {
1389         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1390         ViewManagerRole aRole = getViewManagerRole( aViewManager );
1391
1392         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1393         {
1394           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1395             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1396
1397           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1398           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1399           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1400
1401           //ouv: temporarily commented
1402           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1403         }
1404
1405         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1406           update( UF_Viewer );
1407
1408         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1409       }
1410     }
1411   }
1412 }
1413
1414 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1415 {
1416   QEvent::Type aType = theEvent->type();
1417   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1418   {
1419     if( aType == QEvent::Show )
1420     {
1421       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1422       e->setData( theObj );
1423       QApplication::postEvent( this, e );
1424       theObj->removeEventFilter( this );
1425     }
1426   }
1427   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1428   {
1429     if( aType == QEvent::Leave )
1430     {
1431       SUIT_Desktop* aDesktop = getApp()->desktop();
1432       if ( aDesktop && aDesktop->statusBar() ) {
1433         aDesktop->statusBar()->clearMessage();
1434       }
1435     }
1436   }
1437   else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1438   {
1439     if( aType == QEvent::Leave )
1440     {
1441       SUIT_Desktop* aDesktop = getApp()->desktop();
1442       if ( aDesktop && aDesktop->statusBar() ) {
1443         aDesktop->statusBar()->clearMessage();
1444       }
1445     }
1446   }
1447
1448   return LightApp_Module::eventFilter( theObj, theEvent );
1449 }
1450
1451 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1452 {
1453   LightApp_Module::onViewManagerAdded( theViewManager );
1454
1455   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1456   { 
1457     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1458              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1459   }
1460   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1461   {
1462     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1463              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1464     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1465              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1466   }
1467   else if( theViewManager->getType() == SVTK_Viewer::Type() )
1468   {
1469     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1470              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1471     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1472              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1473   }
1474
1475   createSelector( theViewManager ); // replace the default selector
1476
1477   ViewManagerInfo anInfo( theViewManager, VMR_General );
1478   myViewManagerMap.insert( ViewManagerId++, anInfo );
1479 }
1480
1481 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1482 {
1483   LightApp_Module::onViewManagerRemoved( theViewManager );
1484
1485   createSelector( theViewManager ); // replace the default selector
1486
1487   int anId = getViewManagerId( theViewManager );
1488   if( anId != -1 )
1489   {
1490     OCCViewer_ViewManager* anOCCViewManager =
1491       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1492     if ( anOCCViewManager )
1493     {
1494       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1495       if ( anOCCViewer ) {
1496         int aViewerId = (size_t)anOCCViewer;
1497         removeViewShapes( aViewerId );
1498         setLandCoversScalarMapModeOff( aViewerId );
1499       }
1500     }
1501
1502     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1503     {
1504       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1505       if ( aVTKViewer )
1506       {
1507         getVTKDisplayer()->EraseScalarBar( anId, true );
1508         removeViewShapes( (size_t)aVTKViewer );
1509       }
1510     }
1511
1512     myViewManagerMap.remove( anId );
1513   }
1514 }
1515
1516 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1517 {
1518   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1519   {
1520     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1521     {
1522       aViewFrame->installEventFilter( this );
1523
1524       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1525
1526       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1527                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1528     }
1529   }
1530   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1531   {
1532     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1533     {
1534       aViewFrame->onTopView();
1535
1536       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1537
1538       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1539       if ( aViewPort ) {
1540         aViewPort->installEventFilter( this );
1541       }
1542     }
1543   }
1544   else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1545   {
1546     if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1547     {
1548       aViewFrame->installEventFilter( this );
1549     }
1550   }
1551 }
1552
1553 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1554 {
1555   /* ouv: currently unused
1556   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1557   {
1558     SUIT_ViewManager* aViewManager = 0;
1559
1560     QObject* aParent = aViewPort;
1561     while( aParent = aParent->parent() )
1562     {
1563       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1564       {
1565         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1566         {
1567           aViewManager = aViewer->getViewManager();
1568           break;
1569         }
1570       }
1571     }
1572
1573     if( !aViewManager )
1574       return;
1575
1576     double aMouseX = theEvent->scenePos().x();
1577     double aMouseY = theEvent->scenePos().y();
1578
1579     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1580     if( aRole == VMR_General )
1581     {
1582       int aXDeg = 0, aYDeg = 0;
1583       int aXMin = 0, aYMin = 0;
1584       double aXSec = 0, aYSec = 0;
1585       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1586       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1587
1588       QString aDegSymbol( QChar( 0x00B0 ) );
1589       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1590       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1591
1592       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1593     }
1594     else if( aRole == VMR_TransformImage )
1595       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1596   }
1597   */
1598 }
1599
1600 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1601                                     const bool theIsInit, 
1602                                     const bool theIsForced, 
1603                                     const bool theDoFitAll )
1604 {
1605   QList<int> aViewManagerIdList;
1606
1607   // currently, all views are updated
1608   ViewManagerMapIterator anIter( myViewManagerMap );
1609   while( anIter.hasNext() )
1610   { 
1611     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1612
1613     if ( theDisplayer->IsApplicable( aViewManager ) )
1614     {
1615       int anId = anIter.key();
1616       aViewManagerIdList.append( anId );
1617     }
1618   }
1619
1620   QListIterator<int> anIdIter( aViewManagerIdList );
1621   while( anIdIter.hasNext() )
1622   {
1623     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1624   }
1625 }
1626
1627 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1628 {
1629   if( !theViewManager )
1630     return;
1631
1632   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1633   if( !aSelectionMgr )
1634     return;
1635
1636   QString aViewType = theViewManager->getType();
1637   if( aViewType != GraphicsView_Viewer::Type() &&
1638       aViewType != OCCViewer_Viewer::Type())
1639     return;
1640
1641   QList<SUIT_Selector*> aSelectorList;
1642   aSelectionMgr->selectors( aViewType, aSelectorList );
1643
1644   // disable all alien selectors
1645   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1646   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1647   {
1648     SUIT_Selector* aSelector = *anIter;
1649     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1650                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1651                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1652       aSelector->setEnabled( false );
1653   }
1654
1655   if ( aViewType == GraphicsView_Viewer::Type() )
1656   {
1657     GraphicsView_ViewManager* aViewManager =
1658       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1659     if( aViewManager )
1660       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1661   }
1662   else if ( aViewType == OCCViewer_Viewer::Type() )
1663   {
1664     OCCViewer_ViewManager* aViewManager =
1665       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1666     if( aViewManager )
1667       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1668   }
1669 }
1670
1671 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1672 {
1673   bool aPrevState = myIsUpdateEnabled;
1674   myIsUpdateEnabled = theState;
1675   return aPrevState;
1676 }
1677
1678 bool HYDROGUI_Module::isUpdateEnabled() const
1679 {
1680   return myIsUpdateEnabled;
1681 }
1682
1683 QStringList HYDROGUI_Module::storeSelection() const
1684 {
1685   QStringList anEntryList;
1686   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1687   {
1688     SUIT_DataOwnerPtrList aList( true );
1689     aSelectionMgr->selected( aList );
1690
1691     SUIT_DataOwnerPtrList::iterator anIter;
1692     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1693     {
1694       const LightApp_DataOwner* anOwner = 
1695         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1696       if( anOwner )
1697         anEntryList.append( anOwner->entry() );
1698     }
1699   }
1700   return anEntryList;
1701 }
1702
1703 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1704 {
1705   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1706   {
1707     SUIT_DataOwnerPtrList aList( true );
1708     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1709       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1710     aSelectionMgr->setSelected( aList );
1711   }
1712 }
1713
1714 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1715 {
1716   double X, Y, Z;
1717   bool doShow = false;
1718   HYDROGUI_Displayer* aDisplayer = getDisplayer();
1719   if ( aDisplayer )
1720     aDisplayer->SaveCursorViewPosition( theViewWindow );
1721     doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1722
1723   if ( doShow )
1724   {
1725     // Show the coordinates in the status bar
1726     SUIT_Desktop* aDesktop = getApp()->desktop();
1727     if ( aDesktop && aDesktop->statusBar() )
1728     {
1729       gp_Pnt aWPnt( X, Y, Z );
1730       int aStudyId = application()->activeStudy()->id();
1731       HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1732       double WX = aWPnt.X(), WY = aWPnt.Y();
1733
1734       QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1735       QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1736       QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1737       QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1738       QString aMsg = tr( "COORDINATES_INFO" );
1739       aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1740       aDesktop->statusBar()->showMessage( aMsg );
1741     }
1742   }
1743 }
1744
1745 /**
1746  * Returns stack of active operations;
1747  */
1748 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1749 {
1750   return myActiveOperationMap;
1751 }
1752
1753 /**
1754  * Returns the module active operation. If the active operation is show/hide,
1755  * the method returns the previous operation if it is.
1756  */
1757 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1758 {
1759   HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1760
1761   if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1762   {
1763     QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1764     aVIt.toBack();
1765     aVIt.previous(); // skip the top show/hide operation
1766     anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1767   }
1768
1769   return anOp;
1770 }
1771
1772 /*!
1773  * \brief Virtual public slot
1774  *
1775  * This method is called after the object inserted into data view to update their visibility state
1776  * This is default implementation
1777  */
1778 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1779 {
1780   if ( !isActiveModule() )
1781       return;
1782
1783   HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1784
1785   // change visibility of object
1786   if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1787       return;
1788
1789   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1790
1791   QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1792   Qtx::VisibilityState visState = treeModel->visibilityState( id );
1793   if ( visState == Qtx::UnpresentableState )
1794       return;
1795
1796   visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1797   treeModel->setVisibilityState( id, visState );
1798
1799   bool vis = visState == Qtx::ShownState;
1800   if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1801       return;
1802
1803   setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1804
1805   update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1806 }
1807
1808 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1809 {
1810   Handle(HYDROData_StricklerTable) aTable;
1811
1812   if ( myLandCoverColoringMap.contains( theViewId ) ) {
1813     aTable = myLandCoverColoringMap.value( theViewId );
1814   }
1815
1816   return aTable;
1817 }
1818
1819 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1820                                                  const Handle(HYDROData_StricklerTable)& theTable )
1821 {
1822   if ( !theTable.IsNull() ) {
1823     myLandCoverColoringMap.insert( theViewId, theTable );
1824   }
1825 }
1826
1827 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1828 {
1829   myLandCoverColoringMap.remove( theViewId );
1830 }
1831
1832 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1833 {
1834   return myLandCoverColoringMap.contains( theViewId );
1835 }
1836
1837 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1838 {
1839   if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1840     return;
1841   }
1842
1843   if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1844     Handle(HYDROData_StricklerTable) aTable = 
1845       Handle(HYDROData_StricklerTable)::DownCast( theObject );
1846     QList<int> aViewIds;
1847     QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1848     while ( anIter.hasNext() ) {
1849       if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) == 
1850            HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
1851         anIter.remove();
1852       }
1853     }
1854   }
1855 }