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