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