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>
41 #include <HYDROData_Tool.h>
43 #include <HYDROData_OperationsFactory.h>
45 #include <GraphicsView_ViewFrame.h>
46 #include <GraphicsView_ViewManager.h>
47 #include <GraphicsView_ViewPort.h>
48 #include <GraphicsView_Viewer.h>
50 #include <ImageComposer_CutOperator.h>
51 #include <ImageComposer_CropOperator.h>
52 #include <ImageComposer_FuseOperator.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_DataOwner.h>
56 #include <LightApp_GVSelector.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_UpdateFlags.h>
60 #include <OCCViewer_ViewFrame.h>
61 #include <OCCViewer_ViewManager.h>
62 #include <OCCViewer_ViewModel.h>
64 #include <SALOME_Event.h>
66 #include <SUIT_DataBrowser.h>
67 #include <SUIT_Desktop.h>
68 #include <SUIT_Study.h>
69 #include <SUIT_ViewManager.h>
72 #include <QApplication>
73 #include <QGraphicsSceneMouseEvent>
76 static int ViewManagerId = 0;
78 extern "C" HYDRO_EXPORT CAM_Module* createModule()
80 return new HYDROGUI_Module();
83 extern "C" HYDRO_EXPORT char* getModuleVersion()
85 return (char*)HYDRO_VERSION;
88 HYDROGUI_Module::HYDROGUI_Module()
89 : LightApp_Module( "HYDRO" ),
92 myIsUpdateEnabled( true )
96 HYDROGUI_Module::~HYDROGUI_Module()
100 int HYDROGUI_Module::getStudyId() const
102 LightApp_Application* anApp = getApp();
103 return anApp ? anApp->activeStudy()->id() : 0;
106 void HYDROGUI_Module::initialize( CAM_Application* theApp )
108 LightApp_Module::initialize( theApp );
111 createUndoRedoActions();
116 setMenuShown( false );
117 setToolShown( false );
119 myDisplayer = new HYDROGUI_Displayer( this );
120 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
123 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
125 bool aRes = LightApp_Module::activateModule( theStudy );
127 LightApp_Application* anApp = getApp();
128 SUIT_Desktop* aDesktop = anApp->desktop();
130 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
132 setMenuShown( true );
133 setToolShown( true );
135 #ifndef DISABLE_PYCONSOLE
136 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
137 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
142 updateCommandsStatus();
144 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
145 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
150 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
152 ViewManagerMapIterator anIter( myViewManagerMap );
153 while( anIter.hasNext() )
154 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
155 getApp()->removeViewManager( aViewManager );
156 myViewManagerMap.clear();
158 myObjectStateMap.clear();
161 // clear the data model's list of copying objects
162 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
164 setMenuShown( false );
165 setToolShown( false );
167 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
169 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
170 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
172 return LightApp_Module::deactivateModule( theStudy );
175 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
178 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
179 #ifndef DISABLE_PYCONSOLE
180 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
182 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
185 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
187 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
190 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
194 HYDROGUI_DataModel* aModel = getDataModel();
196 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
197 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
198 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
199 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView )
202 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
204 bool anIsSelectedDataObjects = false;
205 bool anIsVisibleInSelection = false;
206 bool anIsHiddenInSelection = false;
208 bool anIsImage = false;
209 bool anIsImportedImage = false;
210 bool anIsImageHasRefs = false;
211 bool anIsFusedImage = false;
212 bool anIsCutImage = false;
213 bool anIsSplittedImage = false;
214 bool anIsMustBeUpdatedImage = false;
215 bool anIsPolyline = false;
216 bool anIsCalculation = false;
217 bool anIsImmersibleZone = false;
218 bool anIsVisualState = false;
219 bool anIsRegion = false;
220 bool anIsZone = false;
221 bool anIsObstacle = false;
222 bool anIsGeomObject = false;
224 // check the selected GEOM objects
225 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
226 theMenu->addAction( action( ImportGeomObjectId ) );
227 theMenu->addSeparator();
230 // check the selected data model objects
231 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
232 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
234 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
235 if( !anObject.IsNull() )
237 anIsSelectedDataObjects = true;
239 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
240 anIsVisibleInSelection |= aVisibility;
241 anIsHiddenInSelection |= !aVisibility;
243 if( anObject->GetKind() == KIND_IMAGE )
246 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
247 if( !anImage.IsNull() )
249 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
250 anIsImageHasRefs = anImage->HasReferences();
251 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
253 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
255 QString anOperatorName = anOperator->name();
256 if( anOperatorName == ImageComposer_FuseOperator::Type() )
257 anIsFusedImage = true;
258 else if( anOperatorName == ImageComposer_CutOperator::Type() )
260 else if( anOperatorName == ImageComposer_CropOperator::Type() )
261 anIsSplittedImage = true;
264 if ( anImage->IsMustBeUpdated() )
266 anIsMustBeUpdatedImage = true;
270 else if( anObject->GetKind() == KIND_POLYLINE )
272 else if( anObject->GetKind() == KIND_CALCULATION )
273 anIsCalculation = true;
274 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
275 anIsImmersibleZone = true;
276 else if( anObject->GetKind() == KIND_VISUAL_STATE )
277 anIsVisualState = true;
278 else if( anObject->GetKind() == KIND_REGION )
280 else if( anObject->GetKind() == KIND_ZONE )
282 else if( anObject->GetKind() == KIND_OBSTACLE )
286 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
289 // check the selected partitions
290 if( !anIsSelectedDataObjects && anIsObjectBrowser )
292 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
293 if( aSelectedPartition != KIND_UNKNOWN )
295 switch( aSelectedPartition )
298 theMenu->addAction( action( ImportImageId ) );
301 theMenu->addAction( action( CreatePolylineId ) );
303 case KIND_VISUAL_STATE:
304 theMenu->addAction( action( SaveVisualStateId ) );
306 case KIND_BATHYMETRY:
307 theMenu->addAction( action( ImportBathymetryId ) );
309 case KIND_CALCULATION:
310 theMenu->addAction( action( CreateCalculationId ) );
312 case KIND_IMMERSIBLE_ZONE:
313 theMenu->addAction( action( CreateImmersibleZoneId ) );
316 theMenu->addAction( action( ImportObstacleFromFileId ) );
317 theMenu->addAction( action( CreateBoxId ) );
318 theMenu->addAction( action( CreateCylinderId ) );
321 theMenu->addSeparator();
325 if( anIsSelectedDataObjects )
327 if ( anIsMustBeUpdatedImage )
329 theMenu->addAction( action( UpdateImageId ) );
330 theMenu->addSeparator();
333 if( aSeq.Length() == 1 )
337 if( anIsImportedImage )
338 theMenu->addAction( action( EditImportedImageId ) );
339 else if( anIsImageHasRefs )
342 theMenu->addAction( action( EditFusedImageId ) );
343 else if( anIsCutImage )
344 theMenu->addAction( action( EditCutImageId ) );
345 else if( anIsSplittedImage )
346 theMenu->addAction( action( EditSplittedImageId ) );
349 theMenu->addAction( action( ObserveImageId ) );
350 theMenu->addAction( action( ExportImageId ) );
351 theMenu->addSeparator();
353 if( anIsImageHasRefs )
355 theMenu->addAction( action( RemoveImageRefsId ) );
356 theMenu->addSeparator();
359 theMenu->addAction( action( FuseImagesId ) );
360 theMenu->addAction( action( CutImagesId ) );
361 theMenu->addAction( action( SplitImageId ) );
362 theMenu->addSeparator();
364 else if( anIsPolyline )
366 theMenu->addAction( action( EditPolylineId ) );
367 theMenu->addSeparator();
369 else if( anIsCalculation )
371 theMenu->addAction( action( EditCalculationId ) );
372 theMenu->addAction( action( ExportCalculationId ) );
373 theMenu->addSeparator();
375 else if( anIsImmersibleZone )
377 theMenu->addAction( action( EditImmersibleZoneId ) );
378 theMenu->addSeparator();
380 else if( anIsVisualState && anIsObjectBrowser )
382 theMenu->addAction( action( SaveVisualStateId ) );
383 theMenu->addAction( action( LoadVisualStateId ) );
384 theMenu->addSeparator();
387 // Add set color action for geometrical objects
388 if ( anIsGeomObject )
390 theMenu->addAction( action( SetColorId ) );
391 theMenu->addSeparator();
395 theMenu->addAction( action( DeleteId ) );
396 theMenu->addSeparator();
398 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsObstacle )
400 if( anIsHiddenInSelection )
401 theMenu->addAction( action( ShowId ) );
402 theMenu->addAction( action( ShowOnlyId ) );
403 if( anIsVisibleInSelection )
404 theMenu->addAction( action( HideId ) );
405 theMenu->addSeparator();
409 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView )
411 theMenu->addAction( action( ShowAllId ) );
412 theMenu->addAction( action( HideAllId ) );
413 theMenu->addSeparator();
417 void HYDROGUI_Module::update( const int flags )
419 if( !isUpdateEnabled() )
422 QApplication::setOverrideCursor( Qt::WaitCursor );
424 // To prevent calling this method recursively
425 // from one of the methods called below
426 setUpdateEnabled( false );
428 // store selected objects
429 QStringList aSelectedEntries = storeSelection();
431 if( ( flags & UF_Viewer ) )
432 updateGV( flags & UF_GV_Init,
433 flags & UF_GV_Forced,
436 if( ( flags & UF_OCCViewer ) )
437 updateOCCViewer( flags & UF_OCC_Init,
438 flags & UF_OCC_Forced,
441 if( ( flags & UF_Model ) && getDataModel() && getApp() )
443 getDataModel()->update( getStudyId() );
445 // Temporary workaround to prevent breaking
446 // the selection in the object browser.
447 // Note: processEvents() should be called after updateGV(),
448 // otherwise the application crashes from time to time.
449 //RKV: qApp->processEvents();
450 getApp()->updateObjectBrowser( true );
453 // Object browser is currently updated by using UF_Model flag
454 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
455 getApp()->updateObjectBrowser( true );
457 if( ( flags & UF_Controls ) && getApp() )
458 getApp()->updateActions();
460 // restore selected objects
461 restoreSelection( aSelectedEntries );
463 setUpdateEnabled( true );
465 QApplication::restoreOverrideCursor();
468 void HYDROGUI_Module::updateCommandsStatus()
470 LightApp_Module::updateCommandsStatus();
472 updateUndoRedoControls();
474 action( CopyId )->setEnabled( getDataModel()->canCopy() );
475 action( PasteId )->setEnabled( getDataModel()->canPaste() );
478 void HYDROGUI_Module::selectionChanged()
480 LightApp_Module::selectionChanged();
481 updateCommandsStatus();
484 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
486 return (HYDROGUI_DataModel*)dataModel();
489 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
494 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
496 return myOCCDisplayer;
499 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
501 if( myViewManagerMap.contains( theId ) )
503 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
504 GraphicsView_ViewManager* aViewManager =
505 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
507 return aViewManager->getViewer();
512 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
514 if( myViewManagerMap.contains( theId ) )
516 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
517 OCCViewer_ViewManager* aViewManager =
518 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
520 return aViewManager->getOCCViewer();
525 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
527 ViewManagerMapIterator anIter( myViewManagerMap );
528 while( anIter.hasNext() )
530 int anId = anIter.next().key();
531 const ViewManagerInfo& anInfo = anIter.value();
532 if( anInfo.first == theViewManager )
538 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
540 int anId = getViewManagerId( theViewManager );
543 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
544 return anInfo.second;
549 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
550 const ViewManagerRole theRole )
552 int anId = getViewManagerId( theViewManager );
555 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
556 anInfo.second = theRole;
560 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
561 const Handle(HYDROData_Entity)& theObject ) const
563 if( theObject.IsNull() )
566 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
567 if( anIter1 != myObjectStateMap.end() )
569 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
570 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
571 if( anIter2 != aName2ObjectStateMap.end() )
573 const ObjectState& anObjectState = anIter2.value();
574 return anObjectState.Visibility;
580 void HYDROGUI_Module::setObjectVisible( const int theViewId,
581 const Handle(HYDROData_Entity)& theObject,
582 const bool theState )
584 if( !theObject.IsNull() )
586 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
587 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
588 anObjectState.Visibility = theState;
592 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
593 const Handle(HYDROData_Entity)& theObject ) const
595 HYDROGUI_Shape* aResShape = NULL;
596 if( theObject.IsNull() )
599 if ( myShapesMap.contains( theViewId ) )
601 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
602 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
604 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
615 void HYDROGUI_Module::setObjectShape( const int theViewId,
616 const Handle(HYDROData_Entity)& theObject,
617 HYDROGUI_Shape* theShape )
619 if( theObject.IsNull() )
622 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
623 aViewShapes.append( theShape );
626 void HYDROGUI_Module::removeObjectShape( const int theViewId,
627 const Handle(HYDROData_Entity)& theObject )
629 if ( !myShapesMap.contains( theViewId ) )
632 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
633 Handle(HYDROData_Entity) anObject;
634 for ( int i = 0; i < aViewShapes.length(); )
636 HYDROGUI_Shape* aShape = aViewShapes.at( i );
637 anObject = aShape->getObject();
638 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
641 aViewShapes.removeAt( i );
649 void HYDROGUI_Module::removeViewShapes( const int theViewId )
651 if ( !myShapesMap.contains( theViewId ) )
654 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
655 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
657 HYDROGUI_Shape* aShape = aViewShapes.at( i );
662 myShapesMap.remove( theViewId );
665 CAM_DataModel* HYDROGUI_Module::createDataModel()
667 return new HYDROGUI_DataModel( this );
670 void HYDROGUI_Module::customEvent( QEvent* e )
672 int aType = e->type();
673 if ( aType == NewViewEvent )
675 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
676 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
678 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
680 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
681 ViewManagerRole aRole = getViewManagerRole( aViewManager );
683 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
685 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
686 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
688 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
689 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
690 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
692 //ouv: temporarily commented
693 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
696 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
699 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
705 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
707 QEvent::Type aType = theEvent->type();
708 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
710 if( aType == QEvent::Show )
712 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
713 e->setData( theObj );
714 QApplication::postEvent( this, e );
715 theObj->removeEventFilter( this );
718 return LightApp_Module::eventFilter( theObj, theEvent );
721 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
723 LightApp_Module::onViewManagerAdded( theViewManager );
725 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
727 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
728 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
730 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
732 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
733 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
736 createSelector( theViewManager ); // replace the default selector
738 ViewManagerInfo anInfo( theViewManager, VMR_General );
739 myViewManagerMap.insert( ViewManagerId++, anInfo );
742 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
744 LightApp_Module::onViewManagerRemoved( theViewManager );
746 createSelector( theViewManager ); // replace the default selector
748 int anId = getViewManagerId( theViewManager );
751 OCCViewer_ViewManager* anOCCViewManager =
752 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
753 if ( anOCCViewManager )
755 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
757 removeViewShapes( (size_t)anOCCViewer );
760 myViewManagerMap.remove( anId );
764 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
766 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
768 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
770 aViewFrame->installEventFilter( this );
772 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
774 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
775 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
778 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
780 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
782 aViewFrame->onTopView();
787 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
789 /* ouv: currently unused
790 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
792 SUIT_ViewManager* aViewManager = 0;
794 QObject* aParent = aViewPort;
795 while( aParent = aParent->parent() )
797 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
799 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
801 aViewManager = aViewer->getViewManager();
810 double aMouseX = theEvent->scenePos().x();
811 double aMouseY = theEvent->scenePos().y();
813 ViewManagerRole aRole = getViewManagerRole( aViewManager );
814 if( aRole == VMR_General )
816 int aXDeg = 0, aYDeg = 0;
817 int aXMin = 0, aYMin = 0;
818 double aXSec = 0, aYSec = 0;
819 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
820 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
822 QString aDegSymbol( QChar( 0x00B0 ) );
823 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
824 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
826 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
828 else if( aRole == VMR_TransformImage )
829 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
834 void HYDROGUI_Module::updateGV( const bool theIsInit,
835 const bool theIsForced,
836 const bool theDoFitAll )
838 if( !getDisplayer() )
841 QList<int> aViewManagerIdList;
843 // currently, all views are updated
844 ViewManagerMapIterator anIter( myViewManagerMap );
845 while( anIter.hasNext() )
847 GraphicsView_ViewManager* aViewManager =
848 dynamic_cast<GraphicsView_ViewManager*>( anIter.next().value().first );
852 int anId = anIter.key();
853 aViewManagerIdList.append( anId );
856 QListIterator<int> anIdIter( aViewManagerIdList );
857 while( anIdIter.hasNext() )
858 getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
861 void HYDROGUI_Module::updateOCCViewer( const bool theIsInit,
862 const bool theIsForced,
863 const bool theDoFitAll )
865 HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer();
866 if( !anOCCDisplayer )
869 QList<int> aViewManagerIdList;
871 // currently, all views are updated
872 ViewManagerMapIterator anIter( myViewManagerMap );
873 while( anIter.hasNext() )
875 OCCViewer_ViewManager* aViewManager =
876 ::qobject_cast<OCCViewer_ViewManager*>( anIter.next().value().first );
880 int anId = anIter.key();
881 aViewManagerIdList.append( anId );
884 QListIterator<int> anIdIter( aViewManagerIdList );
885 while( anIdIter.hasNext() )
886 anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
889 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
891 if( !theViewManager )
894 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
898 QString aViewType = theViewManager->getType();
899 if( aViewType != GraphicsView_Viewer::Type() &&
900 aViewType != OCCViewer_Viewer::Type())
903 QList<SUIT_Selector*> aSelectorList;
904 aSelectionMgr->selectors( aViewType, aSelectorList );
906 // disable all alien selectors
907 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
908 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
910 SUIT_Selector* aSelector = *anIter;
911 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
912 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
913 aSelector->setEnabled( false );
916 if ( aViewType == GraphicsView_Viewer::Type() )
918 GraphicsView_ViewManager* aViewManager =
919 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
921 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
923 else if ( aViewType == OCCViewer_Viewer::Type() )
925 OCCViewer_ViewManager* aViewManager =
926 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
928 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
932 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
934 bool aPrevState = myIsUpdateEnabled;
935 myIsUpdateEnabled = theState;
939 bool HYDROGUI_Module::isUpdateEnabled() const
941 return myIsUpdateEnabled;
944 QStringList HYDROGUI_Module::storeSelection() const
946 QStringList anEntryList;
947 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
949 SUIT_DataOwnerPtrList aList( true );
950 aSelectionMgr->selected( aList );
952 SUIT_DataOwnerPtrList::iterator anIter;
953 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
955 const LightApp_DataOwner* anOwner =
956 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
958 anEntryList.append( anOwner->entry() );
964 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
966 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
968 SUIT_DataOwnerPtrList aList( true );
969 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
970 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
971 aSelectionMgr->setSelected( aList );