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