Salome HOME
Storing/restoring selection during the module update.
[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_Operations.h"
32 #include "HYDROGUI_PrsImage.h"
33 #include "HYDROGUI_Tool.h"
34 #include "HYDROGUI_UpdateFlags.h"
35
36 #include <HYDROData_Image.h>
37
38 #include <HYDROOperations_Factory.h>
39
40 #include <GraphicsView_ViewFrame.h>
41 #include <GraphicsView_ViewManager.h>
42 #include <GraphicsView_ViewPort.h>
43 #include <GraphicsView_Viewer.h>
44
45 #include <ImageComposer_CutOperator.h>
46 #include <ImageComposer_CropOperator.h>
47 #include <ImageComposer_FuseOperator.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_DataOwner.h>
51 #include <LightApp_GVSelector.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <LightApp_UpdateFlags.h>
54
55 #include <SALOME_Event.h>
56
57 #include <SUIT_Desktop.h>
58 #include <SUIT_Study.h>
59 #include <SUIT_ViewManager.h>
60
61 #include <QAction>
62 #include <QApplication>
63 #include <QGraphicsSceneMouseEvent>
64 #include <QMenu>
65
66 static int ViewManagerId = 0;
67
68 extern "C" HYDRO_EXPORT CAM_Module* createModule()
69 {
70   return new HYDROGUI_Module();
71 }
72
73 extern "C" HYDRO_EXPORT char* getModuleVersion()
74 {
75   return (char*)HYDRO_VERSION;
76 }
77
78 HYDROGUI_Module::HYDROGUI_Module()
79 : LightApp_Module( "HYDRO" ),
80   myDisplayer( 0 ),
81   myIsUpdateEnabled( true )
82 {
83 }
84
85 HYDROGUI_Module::~HYDROGUI_Module()
86 {
87 }
88
89 int HYDROGUI_Module::getStudyId() const
90 {
91   LightApp_Application* anApp = getApp();
92   return anApp ? anApp->activeStudy()->id() : 0;
93 }
94
95 void HYDROGUI_Module::initialize( CAM_Application* theApp )
96 {
97   LightApp_Module::initialize( theApp );
98
99   createActions();
100   createUndoRedoActions();
101   createMenus();
102   createPopups();
103   createToolbars();
104
105   setMenuShown( false );
106   setToolShown( false );
107
108   myDisplayer = new HYDROGUI_Displayer( this );
109 }
110
111 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
112 {
113   bool aRes = LightApp_Module::activateModule( theStudy );
114
115   LightApp_Application* anApp = getApp();
116   SUIT_Desktop* aDesktop = anApp->desktop();
117
118   getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
119
120   setMenuShown( true );
121   setToolShown( true );
122
123 #ifndef DISABLE_PYCONSOLE
124   aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), 
125                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
126 #endif
127
128   update( UF_All );
129
130   updateCommandsStatus();
131
132   return aRes;
133 }
134
135 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
136 {
137   ViewManagerMapIterator anIter( myViewManagerMap );
138   while( anIter.hasNext() )
139     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
140       getApp()->removeViewManager( aViewManager );
141   myViewManagerMap.clear();
142
143   myObjectStateMap.clear();
144
145   // clear the data model's list of copying objects
146   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
147
148   setMenuShown( false );
149   setToolShown( false );
150
151   getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
152
153   return LightApp_Module::deactivateModule( theStudy );
154 }
155
156 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
157 {
158   theMap.clear();
159   theMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
160 #ifndef DISABLE_PYCONSOLE
161   theMap.insert( LightApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
162 #endif
163   theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea   );
164 }
165
166 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
167 {
168   theTypesList << GraphicsView_Viewer::Type();
169 }
170
171 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
172                                         QMenu* theMenu,
173                                         QString& theTitle )
174 {
175   HYDROGUI_DataModel* aModel = getDataModel();
176
177   bool anIsObjectBrowser = theClient == "ObjectBrowser";
178   bool anIsGraphicsView = theClient == "GraphicsView";
179   if( !anIsObjectBrowser && !anIsGraphicsView )
180     return;
181
182   size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( this );
183
184   bool anIsSelectedDataObjects = false;
185   bool anIsVisibleInSelection = false;
186   bool anIsHiddenInSelection = false;
187
188   bool anIsImage = false;
189   bool anIsImportedImage = false;
190   bool anIsCompositeImage = false;
191   bool anIsFusedImage = false;
192   bool anIsCutImage = false;
193   bool anIsSplittedImage = false;
194   bool anIsMustBeUpdatedImage = false;
195   bool anIsPolyline = false;
196   bool anIsCalculation = false;
197   bool anIsZone = false;
198   bool anIsVisualState = false;
199
200   // check the selected data model objects
201   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
202   for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
203   {
204     Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
205     if( !anObject.IsNull() )
206     {
207       anIsSelectedDataObjects = true;
208
209       bool aVisibility = isObjectVisible( aViewId, anObject );
210       anIsVisibleInSelection |= aVisibility;
211       anIsHiddenInSelection |= !aVisibility;
212
213       if( anObject->GetKind() == KIND_IMAGE )
214       {
215         anIsImage = true;
216         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
217         if( !anImage.IsNull() )
218         {
219           anIsImportedImage = anImage->HasTrsfPoints() && !anImage->IsSelfSplitted();
220           anIsCompositeImage = anImage->NbReferences() > 0;
221           if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
222           {
223             if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
224             {
225               QString anOperatorName = anOperator->name();
226               if( anOperatorName == ImageComposer_FuseOperator::Type() )
227                 anIsFusedImage = true;
228               else if( anOperatorName == ImageComposer_CutOperator::Type() )
229                 anIsCutImage = true;
230               else if( anOperatorName == ImageComposer_CropOperator::Type() )
231                 anIsSplittedImage = true;
232             }
233           }
234           anIsMustBeUpdatedImage = anImage->MustBeUpdated();
235         }
236       }
237       else if( anObject->GetKind() == KIND_POLYLINE )
238         anIsPolyline = true;
239       else if( anObject->GetKind() == KIND_CALCULATION )
240         anIsCalculation = true;
241       else if( anObject->GetKind() == KIND_ZONE )
242         anIsZone = true;
243       else if( anObject->GetKind() == KIND_VISUAL_STATE )
244         anIsVisualState = true;
245     }
246   }
247
248   // check the selected partitions
249   if( !anIsSelectedDataObjects && anIsObjectBrowser )
250   {
251     ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
252     if( aSelectedPartition != KIND_UNKNOWN )
253     {
254       switch( aSelectedPartition )
255       {
256         case KIND_IMAGE:
257           theMenu->addAction( action( ImportImageId ) );
258           break;
259         case KIND_POLYLINE:
260           theMenu->addAction( action( CreatePolylineId ) );
261           break;
262         case KIND_VISUAL_STATE:
263           theMenu->addAction( action( SaveVisualStateId ) );
264           break;
265         case KIND_BATHYMETRY:
266           theMenu->addAction( action( ImportBathymetryId ) );
267           break;
268         case KIND_CALCULATION:
269           theMenu->addAction( action( CreateCalculationId ) );
270           break;
271         case KIND_ZONE:
272           theMenu->addAction( action( CreateZoneId ) );
273           break;
274       }
275       theMenu->addSeparator();
276     }
277   }
278
279   if( anIsSelectedDataObjects && anIsMustBeUpdatedImage )
280   {
281     theMenu->addAction( action( UpdateImageId ) );
282     theMenu->addSeparator();
283   }
284
285   if( anIsSelectedDataObjects && aSeq.Length() == 1 )
286   {
287     if( anIsImage )
288     {
289       if( anIsImportedImage )
290         theMenu->addAction( action( EditImportedImageId ) );
291       else if( anIsCompositeImage )
292       {
293         if( anIsFusedImage )
294           theMenu->addAction( action( EditFusedImageId ) );
295         else if( anIsCutImage )
296           theMenu->addAction( action( EditCutImageId ) );
297         else if( anIsSplittedImage )
298           theMenu->addAction( action( EditSplittedImageId ) );
299       }
300
301       theMenu->addAction( action( ObserveImageId ) );
302       theMenu->addAction( action( ExportImageId ) );
303       theMenu->addSeparator();
304
305       theMenu->addAction( action( FuseImagesId ) );
306       theMenu->addAction( action( CutImagesId ) );
307       theMenu->addAction( action( SplitImageId ) );
308       theMenu->addSeparator();
309     }
310     else if( anIsPolyline )
311     {
312       theMenu->addAction( action( EditPolylineId ) );
313       theMenu->addSeparator();
314     }
315     else if( anIsCalculation )
316     {
317       theMenu->addAction( action( EditCalculationId ) );
318       theMenu->addSeparator();
319     }
320     else if( anIsZone )
321     {
322       theMenu->addAction( action( EditZoneId ) );
323       theMenu->addSeparator();
324     }
325     else if( anIsVisualState && anIsObjectBrowser )
326     {
327       theMenu->addAction( action( SaveVisualStateId ) );
328       theMenu->addAction( action( LoadVisualStateId ) );
329       theMenu->addSeparator();
330     }
331   }
332
333   if( anIsSelectedDataObjects )
334   {
335     theMenu->addAction( action( DeleteId ) );
336     theMenu->addSeparator();
337   }
338
339   if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsZone ) )
340   {
341     if( anIsHiddenInSelection )
342       theMenu->addAction( action( ShowId ) );
343     theMenu->addAction( action( ShowOnlyId ) );
344     if( anIsVisibleInSelection )
345       theMenu->addAction( action( HideId ) );
346     theMenu->addSeparator();
347   }
348
349   if( anIsObjectBrowser || anIsGraphicsView )
350   {
351     theMenu->addAction( action( ShowAllId ) );
352     theMenu->addAction( action( HideAllId ) );
353     theMenu->addSeparator();
354   }
355 }
356
357 void HYDROGUI_Module::update( const int flags )
358 {
359   if( !isUpdateEnabled() )
360     return;
361
362   QApplication::setOverrideCursor( Qt::WaitCursor );
363
364   // To prevent calling this method recursively
365   // from one of the methods called below
366   setUpdateEnabled( false );
367
368   // store selected objects
369   QStringList aSelectedEntries = storeSelection();
370
371   if( ( flags & UF_Viewer ) )
372     updateGV( flags & UF_GV_Init,
373               flags & UF_GV_Forced );
374
375   if( ( flags & UF_Model ) && getDataModel() && getApp() )
376   {
377     getDataModel()->update( getStudyId() );
378
379     // Temporary workaround to prevent breaking
380     // the selection in the object browser.
381     // Note: processEvents() should be called after updateGV(),
382     // otherwise the application crashes from time to time.
383     qApp->processEvents(); 
384     getApp()->updateObjectBrowser( true );
385   }
386
387   // Object browser is currently updated by using UF_Model flag
388   //if( ( flags & UF_ObjBrowser ) && getApp() )
389   //  getApp()->updateObjectBrowser( true );
390
391   if( ( flags & UF_Controls ) && getApp() )
392     getApp()->updateActions();
393
394   // restore selected objects
395   restoreSelection( aSelectedEntries );
396
397   setUpdateEnabled( true );
398
399   QApplication::restoreOverrideCursor();
400 }
401
402 void HYDROGUI_Module::updateCommandsStatus()
403 {
404   LightApp_Module::updateCommandsStatus();
405
406   updateUndoRedoControls();
407
408   action( CopyId )->setEnabled( getDataModel()->canCopy() );
409   action( PasteId )->setEnabled( getDataModel()->canPaste() );
410 }
411
412 void HYDROGUI_Module::selectionChanged()
413 {
414   LightApp_Module::selectionChanged();
415   updateCommandsStatus();
416 }
417
418 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
419 {
420   return (HYDROGUI_DataModel*)dataModel();
421 }
422
423 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
424 {
425   return myDisplayer;
426 }
427
428 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
429 {
430   if( myViewManagerMap.contains( theId ) )
431   {
432     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
433     GraphicsView_ViewManager* aViewManager =
434       dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
435     if( aViewManager )
436       return aViewManager->getViewer();
437   }
438   return NULL;
439 }
440
441 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
442 {
443   ViewManagerMapIterator anIter( myViewManagerMap );
444   while( anIter.hasNext() )
445   {
446     int anId = anIter.next().key();
447     const ViewManagerInfo& anInfo = anIter.value();
448     if( anInfo.first == theViewManager )
449       return anId;
450   }
451   return -1;
452 }
453
454 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
455 {
456   int anId = getViewManagerId( theViewManager );
457   if( anId != -1 )
458   {
459     const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
460     return anInfo.second;
461   }
462   return VMR_Unknown;
463 }
464
465 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
466                                           const ViewManagerRole theRole )
467 {
468   int anId = getViewManagerId( theViewManager );
469   if( anId != -1 )
470   {
471     ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
472     anInfo.second = theRole;
473   }
474 }
475
476 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
477                                        const Handle(HYDROData_Object)& theObject )
478 {
479   if( theObject.IsNull() )
480     return false;
481
482   ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
483   if( anIter1 != myObjectStateMap.end() )
484   {
485     const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
486     Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
487     if( anIter2 != aName2ObjectStateMap.end() )
488     {
489       const ObjectState& anObjectState = anIter2.value();
490       return anObjectState.Visibility;
491     }
492   }
493   return false;
494 }
495
496 void HYDROGUI_Module::setObjectVisible( const int theViewId,
497                                         const Handle(HYDROData_Object)& theObject,
498                                         const bool theState )
499 {
500   if( !theObject.IsNull() )
501   {
502     Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
503     ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
504     anObjectState.Visibility = theState;
505   }
506 }
507
508 CAM_DataModel* HYDROGUI_Module::createDataModel()
509 {
510   return new HYDROGUI_DataModel( this );
511 }
512
513 void HYDROGUI_Module::customEvent( QEvent* e )
514 {
515   int aType = e->type();
516   if ( aType == NewViewEvent )
517   {
518     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
519     if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
520     {
521       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
522       {
523         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
524         {
525           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
526           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
527           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
528
529           //ouv: temporarily commented
530           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
531         }
532
533         SUIT_ViewManager* aViewManager = aViewer->getViewManager();
534         ViewManagerRole aRole = getViewManagerRole( aViewManager );
535         if( aRole != VMR_TransformImage )
536           update( UF_Viewer );
537
538         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
539       }
540     }
541   }
542 }
543
544 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
545 {
546   QEvent::Type aType = theEvent->type();
547   if( theObj->inherits( "GraphicsView_ViewFrame" ) )
548   {
549     if( aType == QEvent::Show )
550     {
551       SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
552       e->setData( theObj );
553       QApplication::postEvent( this, e );
554       theObj->removeEventFilter( this );
555     }
556   }
557   return LightApp_Module::eventFilter( theObj, theEvent );
558 }
559
560 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
561 {
562   LightApp_Module::onViewManagerAdded( theViewManager );
563
564   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
565   { 
566     createSelector( theViewManager ); // replace the default selector
567
568     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
569              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
570   }
571
572   ViewManagerInfo anInfo( theViewManager, VMR_General );
573   myViewManagerMap.insert( ViewManagerId++, anInfo );
574 }
575
576 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
577 {
578   LightApp_Module::onViewManagerRemoved( theViewManager );
579
580   createSelector( theViewManager ); // replace the default selector
581
582   int anId = getViewManagerId( theViewManager );
583   if( anId != -1 )
584     myViewManagerMap.remove( anId );
585 }
586
587 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
588 {
589   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
590   {
591     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
592     {
593       aViewFrame->installEventFilter( this );
594
595       GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
596
597       connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
598                this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
599       return;
600     }
601   }
602 }
603
604 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
605 {
606   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
607   {
608     SUIT_ViewManager* aViewManager = 0;
609
610     QObject* aParent = aViewPort;
611     while( aParent = aParent->parent() )
612     {
613       if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
614       {
615         if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
616         {
617           aViewManager = aViewer->getViewManager();
618           break;
619         }
620       }
621     }
622
623     if( !aViewManager )
624       return;
625
626     double aMouseX = theEvent->scenePos().x();
627     double aMouseY = theEvent->scenePos().y();
628
629     ViewManagerRole aRole = getViewManagerRole( aViewManager );
630     if( aRole == VMR_General )
631     {
632       int aXDeg = 0, aYDeg = 0;
633       int aXMin = 0, aYMin = 0;
634       double aXSec = 0, aYSec = 0;
635       HYDROGUI_Tool::DoubleToLambert( aMouseX, aXDeg, aXMin, aXSec );
636       HYDROGUI_Tool::DoubleToLambert( aMouseY, aYDeg, aYMin, aYSec );
637
638       QString aDegSymbol( QChar( 0x00B0 ) );
639       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
640       QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
641
642       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
643     }
644     else if( aRole == VMR_TransformImage )
645       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
646   }
647 }
648
649 void HYDROGUI_Module::updateGV( const bool theIsInit,
650                                 const bool theIsForced )
651 {
652   if( !getDisplayer() )
653     return;
654
655   QList<int> aViewManagerIdList;
656
657   // currently, all views are updated
658   ViewManagerMapIterator anIter( myViewManagerMap );
659   while( anIter.hasNext() )
660   {
661     int anId = anIter.next().key();
662     aViewManagerIdList.append( anId );
663   }
664
665   QListIterator<int> anIdIter( aViewManagerIdList );
666   while( anIdIter.hasNext() )
667     getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced );
668 }
669
670 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
671 {
672   if( !theViewManager )
673     return;
674
675   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
676   if( !aSelectionMgr )
677     return;
678
679   QString aViewType = theViewManager->getType();
680   if( aViewType != GraphicsView_Viewer::Type() )
681     return;
682
683   GraphicsView_ViewManager* aViewManager =
684     dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
685   if( !aViewManager )
686     return;
687
688   QList<SUIT_Selector*> aSelectorList;
689   aSelectionMgr->selectors( aViewType, aSelectorList );
690
691   // disable all alien selectors
692   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
693   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
694   {
695     SUIT_Selector* aSelector = *anIter;
696     if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
697       aSelector->setEnabled( false );
698   }
699
700   new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
701 }
702
703 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
704 {
705   bool aPrevState = myIsUpdateEnabled;
706   myIsUpdateEnabled = theState;
707   return aPrevState;
708 }
709
710 bool HYDROGUI_Module::isUpdateEnabled() const
711 {
712   return myIsUpdateEnabled;
713 }
714
715 QStringList HYDROGUI_Module::storeSelection() const
716 {
717   QStringList anEntryList;
718   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
719   {
720     SUIT_DataOwnerPtrList aList( true );
721     aSelectionMgr->selected( aList );
722
723     SUIT_DataOwnerPtrList::iterator anIter;
724     for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
725     {
726       const LightApp_DataOwner* anOwner = 
727         dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
728       if( anOwner )
729         anEntryList.append( anOwner->entry() );
730     }
731   }
732   return anEntryList;
733 }
734
735 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
736 {
737   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
738   {
739     SUIT_DataOwnerPtrList aList( true );
740     for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
741       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
742     aSelectionMgr->setSelected( aList );
743   }
744 }