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