1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.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"
39 #include <HYDROData_Image.h>
40 #include <HYDROData_Lambert93.h>
42 #include <HYDROData_OperationsFactory.h>
44 #include <GraphicsView_ViewFrame.h>
45 #include <GraphicsView_ViewManager.h>
46 #include <GraphicsView_ViewPort.h>
47 #include <GraphicsView_Viewer.h>
49 #include <ImageComposer_CutOperator.h>
50 #include <ImageComposer_CropOperator.h>
51 #include <ImageComposer_FuseOperator.h>
53 #include <LightApp_Application.h>
54 #include <LightApp_DataOwner.h>
55 #include <LightApp_GVSelector.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <LightApp_UpdateFlags.h>
59 #include <OCCViewer_ViewFrame.h>
60 #include <OCCViewer_ViewManager.h>
61 #include <OCCViewer_ViewModel.h>
63 #include <SALOME_Event.h>
65 #include <SUIT_DataBrowser.h>
66 #include <SUIT_Desktop.h>
67 #include <SUIT_Study.h>
68 #include <SUIT_ViewManager.h>
71 #include <QApplication>
72 #include <QGraphicsSceneMouseEvent>
75 static int ViewManagerId = 0;
77 extern "C" HYDRO_EXPORT CAM_Module* createModule()
79 return new HYDROGUI_Module();
82 extern "C" HYDRO_EXPORT char* getModuleVersion()
84 return (char*)HYDRO_VERSION;
87 HYDROGUI_Module::HYDROGUI_Module()
88 : LightApp_Module( "HYDRO" ),
91 myIsUpdateEnabled( true )
95 HYDROGUI_Module::~HYDROGUI_Module()
99 int HYDROGUI_Module::getStudyId() const
101 LightApp_Application* anApp = getApp();
102 return anApp ? anApp->activeStudy()->id() : 0;
105 void HYDROGUI_Module::initialize( CAM_Application* theApp )
107 LightApp_Module::initialize( theApp );
110 createUndoRedoActions();
115 setMenuShown( false );
116 setToolShown( false );
118 myDisplayer = new HYDROGUI_Displayer( this );
119 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
122 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
124 bool aRes = LightApp_Module::activateModule( theStudy );
126 LightApp_Application* anApp = getApp();
127 SUIT_Desktop* aDesktop = anApp->desktop();
129 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
131 setMenuShown( true );
132 setToolShown( true );
134 #ifndef DISABLE_PYCONSOLE
135 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
136 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
141 updateCommandsStatus();
146 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
148 ViewManagerMapIterator anIter( myViewManagerMap );
149 while( anIter.hasNext() )
150 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
151 getApp()->removeViewManager( aViewManager );
152 myViewManagerMap.clear();
154 myObjectStateMap.clear();
157 // clear the data model's list of copying objects
158 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
160 setMenuShown( false );
161 setToolShown( false );
163 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
165 return LightApp_Module::deactivateModule( theStudy );
168 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
171 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
172 #ifndef DISABLE_PYCONSOLE
173 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
175 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
178 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
180 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
183 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
187 HYDROGUI_DataModel* aModel = getDataModel();
189 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
190 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
191 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
192 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView )
195 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
197 bool anIsSelectedDataObjects = false;
198 bool anIsVisibleInSelection = false;
199 bool anIsHiddenInSelection = false;
201 bool anIsImage = false;
202 bool anIsImportedImage = false;
203 bool anIsImageHasRefs = false;
204 bool anIsFusedImage = false;
205 bool anIsCutImage = false;
206 bool anIsSplittedImage = false;
207 bool anIsMustBeUpdatedImage = false;
208 bool anIsPolyline = false;
209 bool anIsCalculation = false;
210 bool anIsImmersibleZone = false;
211 bool anIsVisualState = false;
212 bool anIsRegion = false;
213 bool anIsZone = false;
215 // check the selected data model objects
216 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
217 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
219 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
220 if( !anObject.IsNull() )
222 anIsSelectedDataObjects = true;
224 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
225 anIsVisibleInSelection |= aVisibility;
226 anIsHiddenInSelection |= !aVisibility;
228 if( anObject->GetKind() == KIND_IMAGE )
231 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
232 if( !anImage.IsNull() )
234 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
235 anIsImageHasRefs = anImage->HasReferences();
236 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
238 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
240 QString anOperatorName = anOperator->name();
241 if( anOperatorName == ImageComposer_FuseOperator::Type() )
242 anIsFusedImage = true;
243 else if( anOperatorName == ImageComposer_CutOperator::Type() )
245 else if( anOperatorName == ImageComposer_CropOperator::Type() )
246 anIsSplittedImage = true;
249 if ( anImage->IsMustBeUpdated() )
251 anIsMustBeUpdatedImage = true;
255 else if( anObject->GetKind() == KIND_POLYLINE )
257 else if( anObject->GetKind() == KIND_CALCULATION )
258 anIsCalculation = true;
259 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
260 anIsImmersibleZone = true;
261 else if( anObject->GetKind() == KIND_VISUAL_STATE )
262 anIsVisualState = true;
263 else if( anObject->GetKind() == KIND_REGION )
265 else if( anObject->GetKind() == KIND_ZONE )
270 // check the selected partitions
271 if( !anIsSelectedDataObjects && anIsObjectBrowser )
273 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
274 if( aSelectedPartition != KIND_UNKNOWN )
276 switch( aSelectedPartition )
279 theMenu->addAction( action( ImportImageId ) );
282 theMenu->addAction( action( CreatePolylineId ) );
284 case KIND_VISUAL_STATE:
285 theMenu->addAction( action( SaveVisualStateId ) );
287 case KIND_BATHYMETRY:
288 theMenu->addAction( action( ImportBathymetryId ) );
290 case KIND_CALCULATION:
291 theMenu->addAction( action( CreateCalculationId ) );
293 case KIND_IMMERSIBLE_ZONE:
294 theMenu->addAction( action( CreateImmersibleZoneId ) );
297 theMenu->addSeparator();
301 if( anIsSelectedDataObjects )
303 if ( anIsMustBeUpdatedImage )
305 theMenu->addAction( action( UpdateImageId ) );
306 theMenu->addSeparator();
309 if( aSeq.Length() == 1 )
313 if( anIsImportedImage )
314 theMenu->addAction( action( EditImportedImageId ) );
315 else if( anIsImageHasRefs )
318 theMenu->addAction( action( EditFusedImageId ) );
319 else if( anIsCutImage )
320 theMenu->addAction( action( EditCutImageId ) );
321 else if( anIsSplittedImage )
322 theMenu->addAction( action( EditSplittedImageId ) );
325 theMenu->addAction( action( ObserveImageId ) );
326 theMenu->addAction( action( ExportImageId ) );
327 theMenu->addSeparator();
329 if( anIsImageHasRefs )
331 theMenu->addAction( action( RemoveImageRefsId ) );
332 theMenu->addSeparator();
335 theMenu->addAction( action( FuseImagesId ) );
336 theMenu->addAction( action( CutImagesId ) );
337 theMenu->addAction( action( SplitImageId ) );
338 theMenu->addSeparator();
340 else if( anIsPolyline )
342 theMenu->addAction( action( EditPolylineId ) );
343 theMenu->addSeparator();
345 else if( anIsCalculation )
347 theMenu->addAction( action( EditCalculationId ) );
348 theMenu->addSeparator();
350 else if( anIsImmersibleZone )
352 theMenu->addAction( action( EditImmersibleZoneId ) );
353 theMenu->addSeparator();
355 else if( anIsVisualState && anIsObjectBrowser )
357 theMenu->addAction( action( SaveVisualStateId ) );
358 theMenu->addAction( action( LoadVisualStateId ) );
359 theMenu->addSeparator();
363 theMenu->addAction( action( DeleteId ) );
364 theMenu->addSeparator();
366 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion )
368 if( anIsHiddenInSelection )
369 theMenu->addAction( action( ShowId ) );
370 theMenu->addAction( action( ShowOnlyId ) );
371 if( anIsVisibleInSelection )
372 theMenu->addAction( action( HideId ) );
373 theMenu->addSeparator();
377 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView )
379 theMenu->addAction( action( ShowAllId ) );
380 theMenu->addAction( action( HideAllId ) );
381 theMenu->addSeparator();
385 void HYDROGUI_Module::update( const int flags )
387 if( !isUpdateEnabled() )
390 QApplication::setOverrideCursor( Qt::WaitCursor );
392 // To prevent calling this method recursively
393 // from one of the methods called below
394 setUpdateEnabled( false );
396 // store selected objects
397 QStringList aSelectedEntries = storeSelection();
399 if( ( flags & UF_Viewer ) )
400 updateGV( flags & UF_GV_Init,
401 flags & UF_GV_Forced );
403 if( ( flags & UF_OCCViewer ) )
404 updateOCCViewer( flags & UF_OCC_Init,
405 flags & UF_OCC_Forced );
407 if( ( flags & UF_Model ) && getDataModel() && getApp() )
409 getDataModel()->update( getStudyId() );
411 // Temporary workaround to prevent breaking
412 // the selection in the object browser.
413 // Note: processEvents() should be called after updateGV(),
414 // otherwise the application crashes from time to time.
415 //RKV: qApp->processEvents();
416 getApp()->updateObjectBrowser( true );
419 // Object browser is currently updated by using UF_Model flag
420 //if( ( flags & UF_ObjBrowser ) && getApp() )
421 // getApp()->updateObjectBrowser( true );
423 if( ( flags & UF_Controls ) && getApp() )
424 getApp()->updateActions();
426 // restore selected objects
427 restoreSelection( aSelectedEntries );
429 setUpdateEnabled( true );
431 QApplication::restoreOverrideCursor();
434 void HYDROGUI_Module::updateCommandsStatus()
436 LightApp_Module::updateCommandsStatus();
438 updateUndoRedoControls();
440 action( CopyId )->setEnabled( getDataModel()->canCopy() );
441 action( PasteId )->setEnabled( getDataModel()->canPaste() );
444 void HYDROGUI_Module::selectionChanged()
446 LightApp_Module::selectionChanged();
447 updateCommandsStatus();
450 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
452 return (HYDROGUI_DataModel*)dataModel();
455 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
460 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
462 return myOCCDisplayer;
465 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
467 if( myViewManagerMap.contains( theId ) )
469 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
470 GraphicsView_ViewManager* aViewManager =
471 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
473 return aViewManager->getViewer();
478 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
480 if( myViewManagerMap.contains( theId ) )
482 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
483 OCCViewer_ViewManager* aViewManager =
484 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
486 return aViewManager->getOCCViewer();
491 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
493 ViewManagerMapIterator anIter( myViewManagerMap );
494 while( anIter.hasNext() )
496 int anId = anIter.next().key();
497 const ViewManagerInfo& anInfo = anIter.value();
498 if( anInfo.first == theViewManager )
504 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
506 int anId = getViewManagerId( theViewManager );
509 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
510 return anInfo.second;
515 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
516 const ViewManagerRole theRole )
518 int anId = getViewManagerId( theViewManager );
521 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
522 anInfo.second = theRole;
526 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
527 const Handle(HYDROData_Entity)& theObject ) const
529 if( theObject.IsNull() )
532 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
533 if( anIter1 != myObjectStateMap.end() )
535 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
536 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
537 if( anIter2 != aName2ObjectStateMap.end() )
539 const ObjectState& anObjectState = anIter2.value();
540 return anObjectState.Visibility;
546 void HYDROGUI_Module::setObjectVisible( const int theViewId,
547 const Handle(HYDROData_Entity)& theObject,
548 const bool theState )
550 if( !theObject.IsNull() )
552 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
553 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
554 anObjectState.Visibility = theState;
558 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
559 const Handle(HYDROData_Entity)& theObject ) const
561 HYDROGUI_Shape* aResShape = NULL;
562 if( theObject.IsNull() )
565 if ( myShapesMap.contains( theViewId ) )
567 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
568 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
570 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
581 void HYDROGUI_Module::setObjectShape( const int theViewId,
582 const Handle(HYDROData_Entity)& theObject,
583 HYDROGUI_Shape* theShape )
585 if( theObject.IsNull() )
588 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
589 aViewShapes.append( theShape );
592 void HYDROGUI_Module::removeObjectShape( const int theViewId,
593 const Handle(HYDROData_Entity)& theObject )
595 if ( !myShapesMap.contains( theViewId ) )
598 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
599 Handle(HYDROData_Entity) anObject;
600 for ( int i = 0; i < aViewShapes.length(); )
602 HYDROGUI_Shape* aShape = aViewShapes.at( i );
603 anObject = aShape->getObject();
604 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
607 aViewShapes.removeAt( i );
615 void HYDROGUI_Module::removeViewShapes( const int theViewId )
617 if ( !myShapesMap.contains( theViewId ) )
620 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
621 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
623 HYDROGUI_Shape* aShape = aViewShapes.at( i );
628 myShapesMap.remove( theViewId );
631 CAM_DataModel* HYDROGUI_Module::createDataModel()
633 return new HYDROGUI_DataModel( this );
636 void HYDROGUI_Module::customEvent( QEvent* e )
638 int aType = e->type();
639 if ( aType == NewViewEvent )
641 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
642 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
644 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
646 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
647 ViewManagerRole aRole = getViewManagerRole( aViewManager );
649 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
651 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
652 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
654 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
655 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
656 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
658 //ouv: temporarily commented
659 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
662 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
665 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
671 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
673 QEvent::Type aType = theEvent->type();
674 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
676 if( aType == QEvent::Show )
678 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
679 e->setData( theObj );
680 QApplication::postEvent( this, e );
681 theObj->removeEventFilter( this );
684 return LightApp_Module::eventFilter( theObj, theEvent );
687 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
689 LightApp_Module::onViewManagerAdded( theViewManager );
691 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
693 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
694 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
696 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
698 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
699 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
702 createSelector( theViewManager ); // replace the default selector
704 ViewManagerInfo anInfo( theViewManager, VMR_General );
705 myViewManagerMap.insert( ViewManagerId++, anInfo );
708 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
710 LightApp_Module::onViewManagerRemoved( theViewManager );
712 createSelector( theViewManager ); // replace the default selector
714 int anId = getViewManagerId( theViewManager );
717 OCCViewer_ViewManager* anOCCViewManager =
718 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
719 if ( anOCCViewManager )
721 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
723 removeViewShapes( (size_t)anOCCViewer );
726 myViewManagerMap.remove( anId );
730 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
732 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
734 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
736 aViewFrame->installEventFilter( this );
738 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
740 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
741 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
744 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
746 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
748 aViewFrame->onTopView();
753 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
755 /* ouv: currently unused
756 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
758 SUIT_ViewManager* aViewManager = 0;
760 QObject* aParent = aViewPort;
761 while( aParent = aParent->parent() )
763 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
765 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
767 aViewManager = aViewer->getViewManager();
776 double aMouseX = theEvent->scenePos().x();
777 double aMouseY = theEvent->scenePos().y();
779 ViewManagerRole aRole = getViewManagerRole( aViewManager );
780 if( aRole == VMR_General )
782 int aXDeg = 0, aYDeg = 0;
783 int aXMin = 0, aYMin = 0;
784 double aXSec = 0, aYSec = 0;
785 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
786 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
788 QString aDegSymbol( QChar( 0x00B0 ) );
789 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
790 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
792 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
794 else if( aRole == VMR_TransformImage )
795 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
800 void HYDROGUI_Module::updateGV( const bool theIsInit,
801 const bool theIsForced )
803 if( !getDisplayer() )
806 QList<int> aViewManagerIdList;
808 // currently, all views are updated
809 ViewManagerMapIterator anIter( myViewManagerMap );
810 while( anIter.hasNext() )
812 GraphicsView_ViewManager* aViewManager =
813 dynamic_cast<GraphicsView_ViewManager*>( anIter.next().value().first );
817 int anId = anIter.key();
818 aViewManagerIdList.append( anId );
821 QListIterator<int> anIdIter( aViewManagerIdList );
822 while( anIdIter.hasNext() )
823 getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced );
826 void HYDROGUI_Module::updateOCCViewer( const bool theIsInit,
827 const bool theIsForced )
829 HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer();
830 if( !anOCCDisplayer )
833 QList<int> aViewManagerIdList;
835 // currently, all views are updated
836 ViewManagerMapIterator anIter( myViewManagerMap );
837 while( anIter.hasNext() )
839 OCCViewer_ViewManager* aViewManager =
840 ::qobject_cast<OCCViewer_ViewManager*>( anIter.next().value().first );
844 int anId = anIter.key();
845 aViewManagerIdList.append( anId );
848 QListIterator<int> anIdIter( aViewManagerIdList );
849 while( anIdIter.hasNext() )
850 anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced );
853 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
855 if( !theViewManager )
858 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
862 QString aViewType = theViewManager->getType();
863 if( aViewType != GraphicsView_Viewer::Type() &&
864 aViewType != OCCViewer_Viewer::Type())
867 QList<SUIT_Selector*> aSelectorList;
868 aSelectionMgr->selectors( aViewType, aSelectorList );
870 // disable all alien selectors
871 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
872 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
874 SUIT_Selector* aSelector = *anIter;
875 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
876 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
877 aSelector->setEnabled( false );
880 if ( aViewType == GraphicsView_Viewer::Type() )
882 GraphicsView_ViewManager* aViewManager =
883 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
885 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
887 else if ( aViewType == OCCViewer_Viewer::Type() )
889 OCCViewer_ViewManager* aViewManager =
890 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
892 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
896 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
898 bool aPrevState = myIsUpdateEnabled;
899 myIsUpdateEnabled = theState;
903 bool HYDROGUI_Module::isUpdateEnabled() const
905 return myIsUpdateEnabled;
908 QStringList HYDROGUI_Module::storeSelection() const
910 QStringList anEntryList;
911 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
913 SUIT_DataOwnerPtrList aList( true );
914 aSelectionMgr->selected( aList );
916 SUIT_DataOwnerPtrList::iterator anIter;
917 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
919 const LightApp_DataOwner* anOwner =
920 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
922 anEntryList.append( anOwner->entry() );
928 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
930 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
932 SUIT_DataOwnerPtrList aList( true );
933 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
934 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
935 aSelectionMgr->setSelected( aList );