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