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