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