Salome HOME
Refs #289 - Spline profile is represented in OCC view as polyline profile
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Module.h"
24
25 #include "HYDROGUI.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_Displayer.h"
29 #include "HYDROGUI_GVSelector.h"
30 #include "HYDROGUI_InputPanel.h"
31 #include "HYDROGUI_ObjSelector.h"
32 #include "HYDROGUI_OCCDisplayer.h"
33 #include "HYDROGUI_OCCSelector.h"
34 #include "HYDROGUI_Operations.h"
35 #include "HYDROGUI_PrsImage.h"
36 #include "HYDROGUI_Tool.h"
37 #include "HYDROGUI_UpdateFlags.h"
38 #include "HYDROGUI_Shape.h"
39 #include "HYDROGUI_VTKPrs.h"
40 #include "HYDROGUI_VTKPrsDisplayer.h"
41 #include "HYDROGUI_AbstractDisplayer.h"
42 #include "HYDROGUI_PolylineOp.h"
43 #include "HYDROGUI_SetColorOp.h"
44 #include "HYDROGUI_ImportGeomObjectOp.h"
45
46 #include <HYDROData_Image.h>
47 #include <HYDROData_Profile.h>
48 #include <HYDROData_Lambert93.h>
49 #include <HYDROData_Tool.h>
50
51 #include <HYDROData_OperationsFactory.h>
52
53 #include <CurveCreator_Utils.h>
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_Desktop.h>
80 #include <SUIT_Study.h>
81 #include <SUIT_ViewManager.h>
82 #include <SUIT_ResourceMgr.h>
83
84 #include <SVTK_ViewManager.h>
85 #include <SVTK_ViewModel.h>
86 #include <SVTK_ViewWindow.h>
87 #include <SVTK_Selector.h>
88
89 #include <OCCViewer_ViewPort3d.h>
90
91 #include <GEOMUtils.hxx>
92 #include <GeometryGUI.h>
93
94 #include <SALOMEDS_wrap.hxx>
95
96 #include <QAction>
97 #include <QApplication>
98 #include <QGraphicsSceneMouseEvent>
99 #include <QMenu>
100 #include <QMouseEvent>
101 #include <QStatusBar>
102 #include <QCursor>
103
104 static int ViewManagerId = 0;
105
106 extern "C" HYDRO_EXPORT CAM_Module* createModule()
107 {
108   return new HYDROGUI_Module();
109 }
110
111 extern "C" HYDRO_EXPORT char* getModuleVersion()
112 {
113   return (char*)HYDRO_VERSION;
114 }
115
116 HYDROGUI_Module::HYDROGUI_Module()
117 : LightApp_Module( "HYDRO" ),
118   myDisplayer( 0 ),
119   myOCCDisplayer( 0 ),
120   myIsUpdateEnabled( true )
121 {
122 }
123
124 HYDROGUI_Module::~HYDROGUI_Module()
125 {
126 }
127
128 int HYDROGUI_Module::getStudyId() const
129 {
130   LightApp_Application* anApp = getApp();
131   return anApp ? anApp->activeStudy()->id() : 0;
132 }
133
134 void HYDROGUI_Module::initialize( CAM_Application* theApp )
135 {
136   LightApp_Module::initialize( theApp );
137
138   createActions();
139   createUndoRedoActions();
140   createMenus();
141   createPopups();
142   createToolbars();
143
144   setMenuShown( false );
145   setToolShown( false );
146
147   myDisplayer = new HYDROGUI_Displayer( this );
148   myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
149   myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
150 }
151
152 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
153 {
154   bool aRes = LightApp_Module::activateModule( theStudy );
155
156   LightApp_Application* anApp = getApp();
157   SUIT_Desktop* aDesktop = anApp->desktop();
158
159   getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
160
161   setMenuShown( true );
162   setToolShown( true );
163
164 #ifndef DISABLE_PYCONSOLE
165   aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), 
166                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
167 #endif
168
169   // Remove defunct view managers from the map.
170   // It's essential to do this before "update( UF_All )" call!
171   QList<int> anObsoleteIds;
172   ViewManagerList anAllViewManagers = anApp->viewManagers();
173   ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
174   ViewManagerMapIterator anIter( myViewManagerMap );
175   while( anIter.hasNext() ) {
176     int anId = anIter.next().key();
177     const ViewManagerInfo& anInfo = anIter.value();
178   
179     aHydroViewManagers << anInfo.first;
180
181     if ( !anAllViewManagers.contains( anInfo.first ) ) {
182       anObsoleteIds << anId;
183     }
184   }
185   foreach ( const int anId, anObsoleteIds ) {
186     myViewManagerMap.remove( anId );
187     myObjectStateMap.remove( anId );
188     myObjectDisplayOrderMap.remove( anId );
189     myShapesMap.remove( anId );
190     myVTKPrsMap.remove( anId );
191   }
192   // Replace the default selector for all view managers.
193   // Add view managers created outside of HYDRO module to the map.
194   foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
195     createSelector( aViewManager ); // replace the default selector
196     if ( !aHydroViewManagers.contains( aViewManager ) ) {
197       ViewManagerInfo anInfo( aViewManager, VMR_General );
198       myViewManagerMap.insert( ViewManagerId++, anInfo );
199     }
200   }
201
202   update( UF_All );
203
204   updateCommandsStatus();
205
206   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
207
208   ViewManagerList anOCCViewManagers;
209   anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
210   foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
211     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
212              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
213     foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
214       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
215       if ( aViewFrame && aViewFrame->getViewPort() ) {
216         aViewFrame->getViewPort()->installEventFilter( this );
217       }
218     }
219   }
220
221   // Load GEOM data
222   SalomeApp_Study* aStudy = 
223     dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
224   if ( aStudy ) {
225     SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
226     GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
227     if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
228       SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
229       SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
230       if( !GEOM_var->_is_nil() ) {
231         aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
232       }
233     }
234   }
235
236   return aRes;
237 }
238
239 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
240 {
241   /* Issues ## 68, 88.
242   ViewManagerMapIterator anIter( myViewManagerMap );
243   while( anIter.hasNext() )
244     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
245       getApp()->removeViewManager( aViewManager );
246   myViewManagerMap.clear();
247   */
248
249   ViewManagerList anOCCViewManagers;
250   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
251   foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
252     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
253                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
254   }
255
256   /* Issues ## 68, 88.
257   myObjectStateMap.clear();
258   myShapesMap.clear();
259   myVTKPrsMap.clear();
260   */
261
262   // clear the data model's list of copying objects
263   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
264
265   setMenuShown( false );
266   setToolShown( false );
267
268   getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
269
270   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
271
272   return LightApp_Module::deactivateModule( theStudy );
273 }
274
275 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
276 {
277   theMap.clear();
278   theMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
279 #ifndef DISABLE_PYCONSOLE
280   theMap.insert( LightApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
281 #endif
282   theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea   );
283 }
284
285 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
286 {
287   theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
288 }
289
290 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
291                                         QMenu* theMenu,
292                                         QString& theTitle )
293 {
294   HYDROGUI_DataModel* aModel = getDataModel();
295
296   bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
297   bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
298   bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
299   bool anIsVTKView = theClient == SVTK_Viewer::Type();
300   if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
301     return;
302
303   size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
304
305   bool anIsSelectedDataObjects = false;
306   bool anIsVisibleInSelection = false;
307   bool anIsHiddenInSelection = false;
308
309   bool anIsImage = false;
310   bool anIsImportedImage = false;
311   bool anIsImageHasRefs = false;
312   bool anIsFusedImage = false;
313   bool anIsCutImage = false;
314   bool anIsSplittedImage = false;
315   bool anIsMustObjectBeUpdated = false;
316   bool anIsPolyline = false;
317   bool anIsPolyline3D = false;
318   bool anIsProfile = false;
319   bool anIsValidProfile = false;
320   bool anAllAreProfiles = false;
321   bool anIsBathymetry = false;
322   bool anIsCalculation = false;
323   bool anIsImmersibleZone = false;
324   bool anIsVisualState = false;
325   bool anIsRegion = false;
326   bool anIsZone = false;
327   bool anIsObstacle = false;
328   bool anIsStream = false;
329   bool anIsChannel = false;
330   bool anIsDigue = false;
331   bool anIsDummyObject3D = false;
332   bool anIsGroup = false;
333   bool anIsObjectCanBeColored = false;
334
335   // Check the selected GEOM objects (take into account the Object Browser only)
336   if ( anIsObjectBrowser ) {
337     QList<GEOM::shape_type> anObstacleTypes = 
338       HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
339     QList<GEOM::shape_type> aPolylineTypes = 
340       HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
341
342     bool isCanBeImportedAsObstacle = 
343       !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
344     bool isCanBeImportedAsPolyline = 
345       !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
346
347     // Add import as obstacle action
348     if ( isCanBeImportedAsObstacle ) {
349       theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
350     }
351     // Add import as polyline action
352     if ( isCanBeImportedAsPolyline ) {
353       theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
354     }
355     // Add separator
356     if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
357       theMenu->addSeparator();
358     }
359   }
360
361   // check the selected data model objects
362   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
363   int aNbOfSelectedProfiles = 0;
364   for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
365   {
366     Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
367     if( !anObject.IsNull() )
368     {
369       anIsSelectedDataObjects = true;
370
371       bool aVisibility = isObjectVisible( anActiveViewId, anObject );
372       anIsVisibleInSelection |= aVisibility;
373       anIsHiddenInSelection |= !aVisibility;
374
375       if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
376       {
377         anIsMustObjectBeUpdated = true;
378       }
379
380       ObjectKind anObjectKind = anObject->GetKind();
381       if( anObjectKind == KIND_IMAGE )
382       {
383         anIsImage = true;
384         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
385         if( !anImage.IsNull() )
386         {
387           anIsImportedImage = anImage->HasLocalPoints();
388           anIsImageHasRefs = anImage->HasReferences();
389           if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
390           {
391             if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
392             {
393               QString anOperatorName = anOperator->name();
394               if( anOperatorName == ImageComposer_FuseOperator::Type() )
395                 anIsFusedImage = true;
396               else if( anOperatorName == ImageComposer_CutOperator::Type() )
397                 anIsCutImage = true;
398               else if( anOperatorName == ImageComposer_CropOperator::Type() )
399                 anIsSplittedImage = true;
400             }
401           }
402         }
403       }
404       else if( anObjectKind == KIND_POLYLINEXY )
405         anIsPolyline = true;
406       else if( anObjectKind == KIND_POLYLINE )
407         anIsPolyline3D = true;
408       else if( anObjectKind == KIND_PROFILE )
409       {
410         anIsProfile = true;
411         aNbOfSelectedProfiles++;
412
413         Handle(HYDROData_Profile) aProfile = 
414           Handle(HYDROData_Profile)::DownCast( anObject );
415         if( !aProfile.IsNull() && aProfile->IsValid() ) {
416           anIsValidProfile = true;
417         }
418       }
419       else if( anObjectKind == KIND_CALCULATION )
420         anIsCalculation = true;
421       else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
422         anIsImmersibleZone = true;
423       else if( anObjectKind == KIND_VISUAL_STATE )
424         anIsVisualState = true;
425       else if( anObjectKind == KIND_REGION )
426         anIsRegion = true;
427       else if( anObjectKind == KIND_ZONE )
428         anIsZone = true;
429       else if( anObjectKind == KIND_BATHYMETRY )
430         anIsBathymetry = true;
431       else if( anObjectKind == KIND_OBSTACLE )
432         anIsObstacle = true;
433       else if( anObjectKind == KIND_STREAM )
434         anIsStream = true;
435       else if( anObjectKind == KIND_CHANNEL )
436         anIsChannel = true;
437       else if( anObjectKind == KIND_DIGUE )
438         anIsDigue = true;
439       else if( anObjectKind == KIND_DUMMY_3D )
440         anIsDummyObject3D = true;
441       else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
442         anIsGroup = true;
443     }
444
445     if ( !anIsObjectCanBeColored )
446       anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
447   }
448
449   // Check if all selected objects are profiles
450   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
451                      ( aNbOfSelectedProfiles == aSeq.Length() );
452
453   // check the selected partitions
454   if( !anIsSelectedDataObjects && anIsObjectBrowser )
455   {
456     ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
457     if( aSelectedPartition != KIND_UNKNOWN )
458     {
459       switch( aSelectedPartition )
460       {
461         case KIND_IMAGE:
462           theMenu->addAction( action( ImportImageId ) );
463           break;
464         case KIND_BATHYMETRY:
465           theMenu->addAction( action( ImportBathymetryId ) );
466           break;
467         case KIND_ARTIFICIAL_OBJECT:
468           theMenu->addAction( action( CreateChannelId ) );
469           theMenu->addAction( action( CreateDigueId ) );
470           break;
471         case KIND_NATURAL_OBJECT:
472           theMenu->addAction( action( CreateImmersibleZoneId ) );
473           theMenu->addAction( action( CreateStreamId ) );
474           break;
475         case KIND_OBSTACLE:
476           theMenu->addAction( action( ImportObstacleFromFileId ) );
477           theMenu->addAction( action( CreateBoxId ) );
478           theMenu->addAction( action( CreateCylinderId ) );
479           break;
480         case KIND_CALCULATION:
481           theMenu->addAction( action( CreateCalculationId ) );
482           break;
483         case KIND_POLYLINEXY:
484           theMenu->addAction( action( CreatePolylineId ) );
485           break;
486         case KIND_POLYLINE:
487           theMenu->addAction( action( CreatePolyline3DId ) );
488           break;
489         case KIND_PROFILE:
490           theMenu->addAction( action( CreateProfileId ) );
491           theMenu->addAction( action( ImportProfilesId ) );
492           theMenu->addAction( action( AllGeoreferencementId ) );
493           break;
494         case KIND_VISUAL_STATE:
495           theMenu->addAction( action( SaveVisualStateId ) );
496           break;
497       }
498       theMenu->addSeparator();
499     }
500   }
501
502   if( anIsSelectedDataObjects )
503   {
504     if ( anIsMustObjectBeUpdated )
505     {
506       theMenu->addAction( action( UpdateObjectId ) );
507       theMenu->addSeparator();
508     }
509     else
510     {
511       theMenu->addAction( action( ForcedUpdateObjectId ) );
512       theMenu->addSeparator();
513     }
514
515
516     if( aSeq.Length() == 1 )
517     {
518       if( anIsImage )
519       {
520         if( anIsImportedImage )
521           theMenu->addAction( action( EditImportedImageId ) );
522         else if( anIsImageHasRefs )
523         {
524           if( anIsFusedImage )
525             theMenu->addAction( action( EditFusedImageId ) );
526           else if( anIsCutImage )
527             theMenu->addAction( action( EditCutImageId ) );
528           else if( anIsSplittedImage )
529             theMenu->addAction( action( EditSplittedImageId ) );
530         }
531
532         //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
533         theMenu->addAction( action( ExportImageId ) );
534         theMenu->addSeparator();
535
536         if( anIsImageHasRefs )
537         {
538           theMenu->addAction( action( RemoveImageRefsId ) );
539           theMenu->addSeparator();
540         }
541
542         theMenu->addAction( action( FuseImagesId ) );
543         theMenu->addAction( action( CutImagesId ) );
544         theMenu->addAction( action( SplitImageId ) );
545         theMenu->addSeparator();
546       }
547       else if( anIsBathymetry )
548       {
549         theMenu->addAction( action( EditImportedBathymetryId ) );
550         theMenu->addAction( action( BathymetryBoundsId ) );
551         theMenu->addSeparator();
552       }
553       else if( anIsPolyline )
554       {
555         theMenu->addAction( action( EditPolylineId ) );
556         theMenu->addSeparator();
557       }
558       else if( anIsPolyline3D )
559       {
560         theMenu->addAction( action( EditPolyline3DId ) );
561         theMenu->addSeparator();
562       }
563       else if( anIsProfile )
564       {
565         theMenu->addAction( action( EditProfileId ) );
566         theMenu->addAction( action( SelectedGeoreferencementId ) );
567         theMenu->addSeparator();
568       }
569       else if( anIsCalculation )
570       {
571         theMenu->addAction( action( EditCalculationId ) );
572         theMenu->addAction( action( ExportCalculationId ) );
573         theMenu->addSeparator();
574       }
575       else if( anIsImmersibleZone )
576       {
577         theMenu->addAction( action( EditImmersibleZoneId ) );
578         theMenu->addSeparator();
579       }
580       else if( anIsStream )
581       {
582         theMenu->addAction( action( EditStreamId ) );
583         theMenu->addSeparator();
584       }
585       else if( anIsChannel )
586       {
587         theMenu->addAction( action( EditChannelId ) );
588         theMenu->addSeparator();
589       }
590       else if( anIsDigue )
591       {
592         theMenu->addAction( action( EditDigueId ) );
593         theMenu->addSeparator();
594       }
595       else if( anIsVisualState && anIsObjectBrowser )
596       {
597         theMenu->addAction( action( SaveVisualStateId ) );
598         theMenu->addAction( action( LoadVisualStateId ) );
599         theMenu->addSeparator();
600       }
601
602       // Add set color action for geometrical objects
603       if ( anIsObjectCanBeColored )
604       {
605         theMenu->addAction( action( SetColorId ) );
606         theMenu->addSeparator();
607       }
608     } else if ( anAllAreProfiles ) {
609       theMenu->addAction( action( SelectedGeoreferencementId ) );
610       theMenu->addSeparator();
611     }
612
613     // Add copy action
614     QAction* aCopyAction = action( CopyId );
615     if( aCopyAction && aCopyAction->isEnabled() ) {
616       theMenu->addAction( action( CopyId ) );
617       theMenu->addSeparator();
618     }
619
620     // Add delete action
621     if( !anIsDummyObject3D )
622       theMenu->addAction( action( DeleteId ) );
623
624     theMenu->addSeparator();
625
626     if( anIsImage || anIsPolyline || anIsPolyline3D || 
627         anIsImmersibleZone || anIsZone || anIsRegion ||
628         anIsBathymetry || anIsObstacle || anIsStream ||
629         anIsChannel || anIsDigue || anIsDummyObject3D ||
630         anIsValidProfile || anIsGroup )
631     {
632       if( anIsHiddenInSelection )
633         theMenu->addAction( action( ShowId ) );
634       theMenu->addAction( action( ShowOnlyId ) );
635       if( anIsVisibleInSelection )
636         theMenu->addAction( action( HideId ) );
637       theMenu->addSeparator();
638     }
639   }
640
641   if ( anIsOCCView )
642   {
643     SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
644     HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
645     if ( aPolylineOp && aPolylineOp->deleteEnabled() )
646       theMenu->addAction( action( DeleteId ) );
647   }
648
649   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
650   {
651     theMenu->addAction( action( ShowAllId ) );
652     theMenu->addAction( action( HideAllId ) );
653     theMenu->addSeparator();
654   }
655   if ( anIsOCCView || anIsVTKView ) {
656     theMenu->addSeparator();
657     theMenu->addAction( action( CopyViewerPositionId ) );
658   }
659 }
660
661 void HYDROGUI_Module::update( const int flags )
662 {
663   if( !isUpdateEnabled() )
664     return;
665
666   QApplication::setOverrideCursor( Qt::WaitCursor );
667
668   // To prevent calling this method recursively
669   // from one of the methods called below
670   setUpdateEnabled( false );
671
672   // store selected objects
673   QStringList aSelectedEntries = storeSelection();
674
675   bool aDoFitAll = flags & UF_FitAll;
676   if( ( flags & UF_Viewer ) )
677     updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); 
678
679   if( ( flags & UF_OCCViewer ) )
680     updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); 
681
682   if( ( flags & UF_VTKViewer ) )
683     updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); 
684
685   if( ( flags & UF_Model ) && getDataModel() && getApp() )
686   {
687     getDataModel()->update( getStudyId() );
688
689     // Temporary workaround to prevent breaking
690     // the selection in the object browser.
691     // Note: processEvents() should be called after updateGV(),
692     // otherwise the application crashes from time to time.
693     //RKV: qApp->processEvents();
694     SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
695     bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
696     SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
697     if ( isResizeOnExpandItem && anObjectBrowser ) {
698       anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280 
699     }
700     getApp()->updateObjectBrowser( true );
701     if ( isResizeOnExpandItem && anObjectBrowser ) {
702       anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280 
703     }
704   }
705
706   // Object browser is currently updated by using UF_Model flag
707   if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
708     getApp()->updateObjectBrowser( true );
709
710   if( ( flags & UF_Controls ) && getApp() )
711     getApp()->updateActions();
712
713   // restore selected objects
714   restoreSelection( aSelectedEntries );
715
716   setUpdateEnabled( true );
717
718   QApplication::restoreOverrideCursor();
719 }
720
721 void HYDROGUI_Module::updateCommandsStatus()
722 {
723   LightApp_Module::updateCommandsStatus();
724
725   updateUndoRedoControls();
726
727   action( CopyId )->setEnabled( getDataModel()->canCopy() );
728   action( PasteId )->setEnabled( getDataModel()->canPaste() );
729 }
730
731 void HYDROGUI_Module::selectionChanged()
732 {
733   LightApp_Module::selectionChanged();
734   updateCommandsStatus();
735 }
736
737 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
738 {
739   return (HYDROGUI_DataModel*)dataModel();
740 }
741
742 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
743 {
744   return myDisplayer;
745 }
746
747 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
748 {
749   return myOCCDisplayer;
750 }
751
752 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
753 {
754   return myVTKDisplayer;
755 }
756
757 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
758 {
759   if( myViewManagerMap.contains( theId ) )
760   {
761     return myViewManagerMap[ theId ].first;
762   }
763   return NULL;
764 }
765
766 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
767 {
768   if( myViewManagerMap.contains( theId ) )
769   {
770     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
771     GraphicsView_ViewManager* aViewManager =
772       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
773     if( aViewManager )
774       return aViewManager->getViewer();
775   }
776   return NULL;
777 }
778
779 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
780 {
781   if( myViewManagerMap.contains( theId ) )
782   {
783     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
784     OCCViewer_ViewManager* aViewManager =
785       ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
786     if( aViewManager )
787       return aViewManager->getOCCViewer();
788   }
789   return NULL;
790 }
791
792 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
793 {
794   if( myViewManagerMap.contains( theId ) )
795   {
796     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
797     SVTK_ViewManager* aViewManager =
798       ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
799     if( aViewManager )
800       return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
801   }
802   return NULL;
803 }
804
805 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
806 {
807   ViewManagerMapIterator anIter( myViewManagerMap );
808   while( anIter.hasNext() )
809   {
810     int anId = anIter.next().key();
811     const ViewManagerInfo& anInfo = anIter.value();
812     if( anInfo.first == theViewManager )
813       return anId;
814   }
815   return -1;
816 }
817
818 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
819 {
820   int anId = getViewManagerId( theViewManager );
821   if( anId != -1 )
822   {
823     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
824     return anInfo.second;
825   }
826   return VMR_Unknown;
827 }
828
829 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
830                                           const ViewManagerRole theRole )
831 {
832   int anId = getViewManagerId( theViewManager );
833   if( anId != -1 )
834   {
835     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
836     anInfo.second = theRole;
837   }
838 }
839
840 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
841                                        const Handle(HYDROData_Entity)& theObject ) const
842 {
843   if( theObject.IsNull() )
844     return false;
845
846   ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
847   if( anIter1 != myObjectStateMap.end() )
848   {
849     const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
850     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
851
852     Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
853     if( anIter2 != aEntry2ObjectStateMap.end() )
854     {
855       const ObjectState& anObjectState = anIter2.value();
856       return anObjectState.Visibility;
857     }
858   }
859   return false;
860 }
861
862 void HYDROGUI_Module::setObjectVisible( const int theViewId,
863                                         const Handle(HYDROData_Entity)& theObject,
864                                         const bool theState )
865 {
866   if( !theObject.IsNull() )
867   {
868     Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
869     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
870
871     ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
872     anObjectState.Visibility = theState;
873
874     // Remember the display order ( needed for Z layers assignment only )
875     QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
876     anObjectEntries.removeAll( anEntry );
877     if ( theState ) {
878       anObjectEntries.append( anEntry );
879     }
880   }
881 }
882
883 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
884                                      const bool theState )
885 {
886   if( !theObject.IsNull() )
887   {
888     // Process OCC shapes
889     ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
890     while( aShapesMapIter != myShapesMap.end() )
891     {
892       const ListOfShapes& aShapesList = aShapesMapIter.value();
893       foreach ( HYDROGUI_Shape* aShape, aShapesList )
894       {
895         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
896         {
897           aShape->setIsToUpdate( theState );
898         }
899       }
900       aShapesMapIter++;
901     }
902     // Process VTK shapes
903     ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
904     while( aVTKPrsMapIter != myVTKPrsMap.end() )
905     {
906       const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
907       foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
908       {
909         if ( aShape && IsEqual( aShape->getObject(), theObject ) )
910         {
911           aShape->setIsToUpdate( theState );
912         }
913       }
914       aVTKPrsMapIter++;
915     }
916   }
917 }
918
919 /////////////////// OCC SHAPES PROCESSING
920 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
921                                                  const Handle(HYDROData_Entity)& theObject ) const
922 {
923   HYDROGUI_Shape* aResShape = NULL;
924   if( theObject.IsNull() )
925     return aResShape;
926
927   if ( myShapesMap.contains( theViewId ) )
928   {
929     const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
930     foreach ( HYDROGUI_Shape* aShape, aViewShapes )
931     {
932       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
933         continue;
934
935       aResShape = aShape;
936       break;
937     }
938   }
939
940   return aResShape;
941 }
942
943 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
944                                       const Handle(HYDROData_Entity)& theObject,
945                                       HYDROGUI_Shape*                 theShape )
946 {
947   if( theObject.IsNull() )
948     return;
949
950   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
951   aViewShapes.append( theShape );
952 }
953
954 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
955                                          const Handle(HYDROData_Entity)& theObject )
956 {
957   if ( !myShapesMap.contains( theViewId ) )
958     return;
959
960   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
961   Handle(HYDROData_Entity) anObject;
962   for ( int i = 0; i < aViewShapes.length(); )
963   {
964     HYDROGUI_Shape* aShape = aViewShapes.at( i );
965     anObject = aShape->getObject();
966     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
967     {
968       delete aShape;
969       aViewShapes.removeAt( i );
970       continue;
971     }
972
973     ++i;
974   }
975 }
976
977 void HYDROGUI_Module::removeViewShapes( const int theViewId )
978 {
979   if ( !myShapesMap.contains( theViewId ) )
980     return;
981
982   const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
983   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
984   {
985     HYDROGUI_Shape* aShape = aViewShapes.at( i );
986     if ( aShape )
987       delete aShape;
988   }
989
990   myShapesMap.remove( theViewId );
991 }
992 /////////////////// END OF OCC SHAPES PROCESSING
993
994 /////////////////// VTKPrs PROCESSING
995 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int                       theViewId,
996                                                  const Handle(HYDROData_Entity)& theObject ) const
997 {
998   HYDROGUI_VTKPrs* aResShape = NULL;
999   if( theObject.IsNull() )
1000     return aResShape;
1001
1002   if ( myVTKPrsMap.contains( theViewId ) )
1003   {
1004     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1005     foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1006     {
1007       if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1008         continue;
1009
1010       aResShape = aShape;
1011       break;
1012     }
1013   }
1014
1015   return aResShape;
1016 }
1017
1018 void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId,
1019                                        const Handle(HYDROData_Entity)& theObject,
1020                                        HYDROGUI_VTKPrs*                 theShape )
1021 {
1022   if( theObject.IsNull() )
1023     return;
1024
1025   if( theShape && theShape->needScalarBar() )
1026   {
1027     // Compute the new global Z range from the added presentation and the old global Z range.
1028     double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1029     double* aRange = theShape->getInternalZRange();
1030     bool anIsUpdate = false;
1031     if ( aRange[0] < aGlobalRange[0] )
1032     {
1033       aGlobalRange[0] = aRange[0];
1034       anIsUpdate = true;
1035     }
1036     if ( aRange[1] > aGlobalRange[1] )
1037     {
1038       aGlobalRange[1] = aRange[1];
1039       anIsUpdate = true;
1040     }
1041
1042     //if ( anIsUpdate )
1043     //{
1044       updateVTKZRange( theViewId, aGlobalRange );
1045     //}
1046   }
1047
1048   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1049   aViewShapes.append( theShape );
1050 }
1051
1052 void HYDROGUI_Module::removeObjectVTKPrs( const int                       theViewId,
1053                                           const Handle(HYDROData_Entity)& theObject )
1054 {
1055   if ( !myVTKPrsMap.contains( theViewId ) )
1056     return;
1057
1058   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1059   Handle(HYDROData_Entity) anObject;
1060   for ( int i = 0; i < aViewShapes.length(); )
1061   {
1062     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1063     anObject = aShape->getObject();
1064     if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1065     {
1066       delete aShape;
1067       aViewShapes.removeAt( i );
1068       continue;
1069     }
1070
1071     ++i;
1072   }
1073
1074   // Invalidate global Z range
1075   double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1076   getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1077 }
1078
1079 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1080 {
1081   if ( !myVTKPrsMap.contains( theViewId ) )
1082     return;
1083
1084   const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1085   for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1086   {
1087     HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1088     if ( aShape )
1089       delete aShape;
1090   }
1091
1092   myVTKPrsMap.remove( theViewId );
1093 }
1094
1095 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1096 {
1097   if ( myVTKPrsMap.contains( theViewId ) )
1098   {
1099     // For the given viewer id update all VTK presentations ...
1100     const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1101     HYDROGUI_VTKPrs* aShape;
1102     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1103     {
1104       aShape = aViewShapes.at( i );
1105       if ( aShape && aShape->needScalarBar() )
1106       {
1107         aShape->setZRange( theRange );
1108       }
1109     }
1110   }
1111   // ... and update the global color legend scalar bar.
1112   getVTKDisplayer()->SetZRange( theViewId, theRange );
1113 }
1114 /////////////////// END OF VTKPrs PROCESSING
1115
1116 CAM_DataModel* HYDROGUI_Module::createDataModel()
1117 {
1118   return new HYDROGUI_DataModel( this );
1119 }
1120
1121 void HYDROGUI_Module::customEvent( QEvent* e )
1122 {
1123   int aType = e->type();
1124   if ( aType == NewViewEvent )
1125   {
1126     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1127     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1128     {
1129       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1130       {
1131         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1132         ViewManagerRole aRole = getViewManagerRole( aViewManager );
1133
1134         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1135         {
1136           if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1137             aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1138
1139           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1140           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1141           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1142
1143           //ouv: temporarily commented
1144           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1145         }
1146
1147         if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1148           update( UF_Viewer );
1149
1150         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1151       }
1152     }
1153   }
1154 }
1155
1156 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1157 {
1158   QEvent::Type aType = theEvent->type();
1159   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1160   {
1161     if( aType == QEvent::Show )
1162     {
1163       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1164       e->setData( theObj );
1165       QApplication::postEvent( this, e );
1166       theObj->removeEventFilter( this );
1167     }
1168   }
1169   else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1170   {
1171     if( aType == QEvent::Leave )
1172     {
1173       SUIT_Desktop* aDesktop = getApp()->desktop();
1174       if ( aDesktop && aDesktop->statusBar() ) {
1175         aDesktop->statusBar()->clearMessage();
1176       }
1177     }
1178   }
1179   else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1180   {
1181     if( aType == QEvent::Leave )
1182     {
1183       SUIT_Desktop* aDesktop = getApp()->desktop();
1184       if ( aDesktop && aDesktop->statusBar() ) {
1185         aDesktop->statusBar()->clearMessage();
1186       }
1187     }
1188   }
1189
1190   return LightApp_Module::eventFilter( theObj, theEvent );
1191 }
1192
1193 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1194 {
1195   LightApp_Module::onViewManagerAdded( theViewManager );
1196
1197   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1198   { 
1199     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1200              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1201   }
1202   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1203   {
1204     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1205              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1206     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1207              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1208   }
1209   else if( theViewManager->getType() == SVTK_Viewer::Type() )
1210   {
1211     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1212              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1213     connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1214              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1215   }
1216
1217   createSelector( theViewManager ); // replace the default selector
1218
1219   ViewManagerInfo anInfo( theViewManager, VMR_General );
1220   myViewManagerMap.insert( ViewManagerId++, anInfo );
1221 }
1222
1223 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1224 {
1225   LightApp_Module::onViewManagerRemoved( theViewManager );
1226
1227   createSelector( theViewManager ); // replace the default selector
1228
1229   int anId = getViewManagerId( theViewManager );
1230   if( anId != -1 )
1231   {
1232     OCCViewer_ViewManager* anOCCViewManager =
1233       ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1234     if ( anOCCViewManager )
1235     {
1236       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1237       if ( anOCCViewer )
1238         removeViewShapes( (size_t)anOCCViewer );
1239     }
1240
1241     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1242     {
1243       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1244       if ( aVTKViewer )
1245       {
1246         getVTKDisplayer()->EraseScalarBar( anId, true );
1247         removeViewShapes( (size_t)aVTKViewer );
1248       }
1249     }
1250
1251     myViewManagerMap.remove( anId );
1252   }
1253 }
1254
1255 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1256 {
1257   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1258   {
1259     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1260     {
1261       aViewFrame->installEventFilter( this );
1262
1263       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1264
1265       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1266                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1267     }
1268   }
1269   else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1270   {
1271     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1272     {
1273       aViewFrame->onTopView();
1274
1275       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1276
1277       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1278       if ( aViewPort ) {
1279         aViewPort->installEventFilter( this );
1280       }
1281     }
1282   }
1283   else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1284   {
1285     if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1286     {
1287       aViewFrame->installEventFilter( this );
1288     }
1289   }
1290 }
1291
1292 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1293 {
1294   /* ouv: currently unused
1295   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1296   {
1297     SUIT_ViewManager* aViewManager = 0;
1298
1299     QObject* aParent = aViewPort;
1300     while( aParent = aParent->parent() )
1301     {
1302       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1303       {
1304         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1305         {
1306           aViewManager = aViewer->getViewManager();
1307           break;
1308         }
1309       }
1310     }
1311
1312     if( !aViewManager )
1313       return;
1314
1315     double aMouseX = theEvent->scenePos().x();
1316     double aMouseY = theEvent->scenePos().y();
1317
1318     ViewManagerRole aRole = getViewManagerRole( aViewManager );
1319     if( aRole == VMR_General )
1320     {
1321       int aXDeg = 0, aYDeg = 0;
1322       int aXMin = 0, aYMin = 0;
1323       double aXSec = 0, aYSec = 0;
1324       HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1325       HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1326
1327       QString aDegSymbol( QChar( 0x00B0 ) );
1328       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1329       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1330
1331       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1332     }
1333     else if( aRole == VMR_TransformImage )
1334       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1335   }
1336   */
1337 }
1338
1339 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
1340                                     const bool theIsInit, 
1341                                     const bool theIsForced, 
1342                                     const bool theDoFitAll )
1343 {
1344   QList<int> aViewManagerIdList;
1345
1346   // currently, all views are updated
1347   ViewManagerMapIterator anIter( myViewManagerMap );
1348   while( anIter.hasNext() )
1349   { 
1350     SUIT_ViewManager* aViewManager = anIter.next().value().first;
1351
1352     if ( theDisplayer->IsApplicable( aViewManager ) )
1353     {
1354       int anId = anIter.key();
1355       aViewManagerIdList.append( anId );
1356     }
1357   }
1358
1359   QListIterator<int> anIdIter( aViewManagerIdList );
1360   while( anIdIter.hasNext() )
1361   {
1362     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1363   }
1364 }
1365
1366 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1367 {
1368   if( !theViewManager )
1369     return;
1370
1371   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1372   if( !aSelectionMgr )
1373     return;
1374
1375   QString aViewType = theViewManager->getType();
1376   if( aViewType != GraphicsView_Viewer::Type() &&
1377       aViewType != OCCViewer_Viewer::Type())
1378     return;
1379
1380   QList<SUIT_Selector*> aSelectorList;
1381   aSelectionMgr->selectors( aViewType, aSelectorList );
1382
1383   // disable all alien selectors
1384   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1385   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1386   {
1387     SUIT_Selector* aSelector = *anIter;
1388     if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1389                        !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1390                        !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1391       aSelector->setEnabled( false );
1392   }
1393
1394   if ( aViewType == GraphicsView_Viewer::Type() )
1395   {
1396     GraphicsView_ViewManager* aViewManager =
1397       ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1398     if( aViewManager )
1399       new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1400   }
1401   else if ( aViewType == OCCViewer_Viewer::Type() )
1402   {
1403     OCCViewer_ViewManager* aViewManager =
1404       ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1405     if( aViewManager )
1406       new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1407   }
1408 }
1409
1410 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1411 {
1412   bool aPrevState = myIsUpdateEnabled;
1413   myIsUpdateEnabled = theState;
1414   return aPrevState;
1415 }
1416
1417 bool HYDROGUI_Module::isUpdateEnabled() const
1418 {
1419   return myIsUpdateEnabled;
1420 }
1421
1422 QStringList HYDROGUI_Module::storeSelection() const
1423 {
1424   QStringList anEntryList;
1425   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1426   {
1427     SUIT_DataOwnerPtrList aList( true );
1428     aSelectionMgr->selected( aList );
1429
1430     SUIT_DataOwnerPtrList::iterator anIter;
1431     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1432     {
1433       const LightApp_DataOwner* anOwner = 
1434         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1435       if( anOwner )
1436         anEntryList.append( anOwner->entry() );
1437     }
1438   }
1439   return anEntryList;
1440 }
1441
1442 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1443 {
1444   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1445   {
1446     SUIT_DataOwnerPtrList aList( true );
1447     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1448       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1449     aSelectionMgr->setSelected( aList );
1450   }
1451 }
1452
1453 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1454 {
1455   double aX, aY, aZ;
1456   bool doShow = false;
1457   HYDROGUI_Displayer* aDisplayer = getDisplayer();
1458   if ( aDisplayer )
1459     aDisplayer->SaveCursorViewPosition( theViewWindow );
1460     doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ );
1461
1462   if ( doShow )
1463   {
1464     // Show the coordinates in the status bar
1465     SUIT_Desktop* aDesktop = getApp()->desktop();
1466     if ( aDesktop && aDesktop->statusBar() ) {
1467       QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX );
1468       QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY );
1469       aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aXStr ).arg( anYStr ) );
1470     }
1471   }
1472 }
1473
1474 /**
1475  * Get the object display order. Needed for Z layers assignment only.
1476  */
1477 int HYDROGUI_Module::getObjectDisplayOrder( 
1478   const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1479 {
1480   if( theObject.IsNull() )
1481     return -1;
1482
1483   QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1484   QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1485
1486   return anObjectEntries.indexOf( anEntry );
1487 }