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();
143 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
144 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
149 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
151 ViewManagerMapIterator anIter( myViewManagerMap );
152 while( anIter.hasNext() )
153 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
154 getApp()->removeViewManager( aViewManager );
155 myViewManagerMap.clear();
157 myObjectStateMap.clear();
160 // clear the data model's list of copying objects
161 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
163 setMenuShown( false );
164 setToolShown( false );
166 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
168 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
169 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
171 return LightApp_Module::deactivateModule( theStudy );
174 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
177 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
178 #ifndef DISABLE_PYCONSOLE
179 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
181 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
184 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
186 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
189 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
193 HYDROGUI_DataModel* aModel = getDataModel();
195 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
196 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
197 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
198 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView )
201 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
203 bool anIsSelectedDataObjects = false;
204 bool anIsVisibleInSelection = false;
205 bool anIsHiddenInSelection = false;
207 bool anIsImage = false;
208 bool anIsImportedImage = false;
209 bool anIsImageHasRefs = false;
210 bool anIsFusedImage = false;
211 bool anIsCutImage = false;
212 bool anIsSplittedImage = false;
213 bool anIsMustBeUpdatedImage = false;
214 bool anIsPolyline = false;
215 bool anIsCalculation = false;
216 bool anIsImmersibleZone = false;
217 bool anIsVisualState = false;
218 bool anIsRegion = false;
219 bool anIsZone = false;
220 bool anIsObstacle = false;
222 // check the selected GEOM objects
223 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
224 theMenu->addAction( action( ImportGeomObjectId ) );
225 theMenu->addSeparator();
228 // check the selected data model objects
229 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
230 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
232 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
233 if( !anObject.IsNull() )
235 anIsSelectedDataObjects = true;
237 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
238 anIsVisibleInSelection |= aVisibility;
239 anIsHiddenInSelection |= !aVisibility;
241 if( anObject->GetKind() == KIND_IMAGE )
244 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
245 if( !anImage.IsNull() )
247 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
248 anIsImageHasRefs = anImage->HasReferences();
249 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
251 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
253 QString anOperatorName = anOperator->name();
254 if( anOperatorName == ImageComposer_FuseOperator::Type() )
255 anIsFusedImage = true;
256 else if( anOperatorName == ImageComposer_CutOperator::Type() )
258 else if( anOperatorName == ImageComposer_CropOperator::Type() )
259 anIsSplittedImage = true;
262 if ( anImage->IsMustBeUpdated() )
264 anIsMustBeUpdatedImage = true;
268 else if( anObject->GetKind() == KIND_POLYLINE )
270 else if( anObject->GetKind() == KIND_CALCULATION )
271 anIsCalculation = true;
272 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
273 anIsImmersibleZone = true;
274 else if( anObject->GetKind() == KIND_VISUAL_STATE )
275 anIsVisualState = true;
276 else if( anObject->GetKind() == KIND_REGION )
278 else if( anObject->GetKind() == KIND_ZONE )
280 else if( anObject->GetKind() == KIND_OBSTACLE )
285 // check the selected partitions
286 if( !anIsSelectedDataObjects && anIsObjectBrowser )
288 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
289 if( aSelectedPartition != KIND_UNKNOWN )
291 switch( aSelectedPartition )
294 theMenu->addAction( action( ImportImageId ) );
297 theMenu->addAction( action( CreatePolylineId ) );
299 case KIND_VISUAL_STATE:
300 theMenu->addAction( action( SaveVisualStateId ) );
302 case KIND_BATHYMETRY:
303 theMenu->addAction( action( ImportBathymetryId ) );
305 case KIND_CALCULATION:
306 theMenu->addAction( action( CreateCalculationId ) );
308 case KIND_IMMERSIBLE_ZONE:
309 theMenu->addAction( action( CreateImmersibleZoneId ) );
312 theMenu->addAction( action( ImportObstacleFromFileId ) );
313 theMenu->addAction( action( CreateBoxId ) );
314 theMenu->addAction( action( CreateCylinderId ) );
317 theMenu->addSeparator();
321 if( anIsSelectedDataObjects )
323 if ( anIsMustBeUpdatedImage )
325 theMenu->addAction( action( UpdateImageId ) );
326 theMenu->addSeparator();
329 if( aSeq.Length() == 1 )
333 if( anIsImportedImage )
334 theMenu->addAction( action( EditImportedImageId ) );
335 else if( anIsImageHasRefs )
338 theMenu->addAction( action( EditFusedImageId ) );
339 else if( anIsCutImage )
340 theMenu->addAction( action( EditCutImageId ) );
341 else if( anIsSplittedImage )
342 theMenu->addAction( action( EditSplittedImageId ) );
345 theMenu->addAction( action( ObserveImageId ) );
346 theMenu->addAction( action( ExportImageId ) );
347 theMenu->addSeparator();
349 if( anIsImageHasRefs )
351 theMenu->addAction( action( RemoveImageRefsId ) );
352 theMenu->addSeparator();
355 theMenu->addAction( action( FuseImagesId ) );
356 theMenu->addAction( action( CutImagesId ) );
357 theMenu->addAction( action( SplitImageId ) );
358 theMenu->addSeparator();
360 else if( anIsPolyline )
362 theMenu->addAction( action( EditPolylineId ) );
363 theMenu->addSeparator();
365 else if( anIsCalculation )
367 theMenu->addAction( action( EditCalculationId ) );
368 theMenu->addAction( action( ExportCalculationId ) );
369 theMenu->addSeparator();
371 else if( anIsImmersibleZone )
373 theMenu->addAction( action( EditImmersibleZoneId ) );
374 theMenu->addSeparator();
376 else if( anIsVisualState && anIsObjectBrowser )
378 theMenu->addAction( action( SaveVisualStateId ) );
379 theMenu->addAction( action( LoadVisualStateId ) );
380 theMenu->addSeparator();
384 theMenu->addAction( action( DeleteId ) );
385 theMenu->addSeparator();
387 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsObstacle )
389 if( anIsHiddenInSelection )
390 theMenu->addAction( action( ShowId ) );
391 theMenu->addAction( action( ShowOnlyId ) );
392 if( anIsVisibleInSelection )
393 theMenu->addAction( action( HideId ) );
394 theMenu->addSeparator();
398 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView )
400 theMenu->addAction( action( ShowAllId ) );
401 theMenu->addAction( action( HideAllId ) );
402 theMenu->addSeparator();
406 void HYDROGUI_Module::update( const int flags )
408 if( !isUpdateEnabled() )
411 QApplication::setOverrideCursor( Qt::WaitCursor );
413 // To prevent calling this method recursively
414 // from one of the methods called below
415 setUpdateEnabled( false );
417 // store selected objects
418 QStringList aSelectedEntries = storeSelection();
420 if( ( flags & UF_Viewer ) )
421 updateGV( flags & UF_GV_Init,
422 flags & UF_GV_Forced,
425 if( ( flags & UF_OCCViewer ) )
426 updateOCCViewer( flags & UF_OCC_Init,
427 flags & UF_OCC_Forced,
430 if( ( flags & UF_Model ) && getDataModel() && getApp() )
432 getDataModel()->update( getStudyId() );
434 // Temporary workaround to prevent breaking
435 // the selection in the object browser.
436 // Note: processEvents() should be called after updateGV(),
437 // otherwise the application crashes from time to time.
438 //RKV: qApp->processEvents();
439 getApp()->updateObjectBrowser( true );
442 // Object browser is currently updated by using UF_Model flag
443 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
444 getApp()->updateObjectBrowser( true );
446 if( ( flags & UF_Controls ) && getApp() )
447 getApp()->updateActions();
449 // restore selected objects
450 restoreSelection( aSelectedEntries );
452 setUpdateEnabled( true );
454 QApplication::restoreOverrideCursor();
457 void HYDROGUI_Module::updateCommandsStatus()
459 LightApp_Module::updateCommandsStatus();
461 updateUndoRedoControls();
463 action( CopyId )->setEnabled( getDataModel()->canCopy() );
464 action( PasteId )->setEnabled( getDataModel()->canPaste() );
467 void HYDROGUI_Module::selectionChanged()
469 LightApp_Module::selectionChanged();
470 updateCommandsStatus();
473 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
475 return (HYDROGUI_DataModel*)dataModel();
478 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
483 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
485 return myOCCDisplayer;
488 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
490 if( myViewManagerMap.contains( theId ) )
492 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
493 GraphicsView_ViewManager* aViewManager =
494 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
496 return aViewManager->getViewer();
501 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
503 if( myViewManagerMap.contains( theId ) )
505 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
506 OCCViewer_ViewManager* aViewManager =
507 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
509 return aViewManager->getOCCViewer();
514 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
516 ViewManagerMapIterator anIter( myViewManagerMap );
517 while( anIter.hasNext() )
519 int anId = anIter.next().key();
520 const ViewManagerInfo& anInfo = anIter.value();
521 if( anInfo.first == theViewManager )
527 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
529 int anId = getViewManagerId( theViewManager );
532 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
533 return anInfo.second;
538 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
539 const ViewManagerRole theRole )
541 int anId = getViewManagerId( theViewManager );
544 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
545 anInfo.second = theRole;
549 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
550 const Handle(HYDROData_Entity)& theObject ) const
552 if( theObject.IsNull() )
555 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
556 if( anIter1 != myObjectStateMap.end() )
558 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
559 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
560 if( anIter2 != aName2ObjectStateMap.end() )
562 const ObjectState& anObjectState = anIter2.value();
563 return anObjectState.Visibility;
569 void HYDROGUI_Module::setObjectVisible( const int theViewId,
570 const Handle(HYDROData_Entity)& theObject,
571 const bool theState )
573 if( !theObject.IsNull() )
575 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
576 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
577 anObjectState.Visibility = theState;
581 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
582 const Handle(HYDROData_Entity)& theObject ) const
584 HYDROGUI_Shape* aResShape = NULL;
585 if( theObject.IsNull() )
588 if ( myShapesMap.contains( theViewId ) )
590 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
591 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
593 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
604 void HYDROGUI_Module::setObjectShape( const int theViewId,
605 const Handle(HYDROData_Entity)& theObject,
606 HYDROGUI_Shape* theShape )
608 if( theObject.IsNull() )
611 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
612 aViewShapes.append( theShape );
615 void HYDROGUI_Module::removeObjectShape( const int theViewId,
616 const Handle(HYDROData_Entity)& theObject )
618 if ( !myShapesMap.contains( theViewId ) )
621 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
622 Handle(HYDROData_Entity) anObject;
623 for ( int i = 0; i < aViewShapes.length(); )
625 HYDROGUI_Shape* aShape = aViewShapes.at( i );
626 anObject = aShape->getObject();
627 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
630 aViewShapes.removeAt( i );
638 void HYDROGUI_Module::removeViewShapes( const int theViewId )
640 if ( !myShapesMap.contains( theViewId ) )
643 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
644 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
646 HYDROGUI_Shape* aShape = aViewShapes.at( i );
651 myShapesMap.remove( theViewId );
654 CAM_DataModel* HYDROGUI_Module::createDataModel()
656 return new HYDROGUI_DataModel( this );
659 void HYDROGUI_Module::customEvent( QEvent* e )
661 int aType = e->type();
662 if ( aType == NewViewEvent )
664 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
665 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
667 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
669 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
670 ViewManagerRole aRole = getViewManagerRole( aViewManager );
672 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
674 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
675 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
677 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
678 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
679 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
681 //ouv: temporarily commented
682 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
685 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
688 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
694 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
696 QEvent::Type aType = theEvent->type();
697 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
699 if( aType == QEvent::Show )
701 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
702 e->setData( theObj );
703 QApplication::postEvent( this, e );
704 theObj->removeEventFilter( this );
707 return LightApp_Module::eventFilter( theObj, theEvent );
710 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
712 LightApp_Module::onViewManagerAdded( theViewManager );
714 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
716 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
717 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
719 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
721 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
722 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
725 createSelector( theViewManager ); // replace the default selector
727 ViewManagerInfo anInfo( theViewManager, VMR_General );
728 myViewManagerMap.insert( ViewManagerId++, anInfo );
731 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
733 LightApp_Module::onViewManagerRemoved( theViewManager );
735 createSelector( theViewManager ); // replace the default selector
737 int anId = getViewManagerId( theViewManager );
740 OCCViewer_ViewManager* anOCCViewManager =
741 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
742 if ( anOCCViewManager )
744 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
746 removeViewShapes( (size_t)anOCCViewer );
749 myViewManagerMap.remove( anId );
753 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
755 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
757 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
759 aViewFrame->installEventFilter( this );
761 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
763 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
764 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
767 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
769 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
771 aViewFrame->onTopView();
776 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
778 /* ouv: currently unused
779 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
781 SUIT_ViewManager* aViewManager = 0;
783 QObject* aParent = aViewPort;
784 while( aParent = aParent->parent() )
786 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
788 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
790 aViewManager = aViewer->getViewManager();
799 double aMouseX = theEvent->scenePos().x();
800 double aMouseY = theEvent->scenePos().y();
802 ViewManagerRole aRole = getViewManagerRole( aViewManager );
803 if( aRole == VMR_General )
805 int aXDeg = 0, aYDeg = 0;
806 int aXMin = 0, aYMin = 0;
807 double aXSec = 0, aYSec = 0;
808 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
809 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
811 QString aDegSymbol( QChar( 0x00B0 ) );
812 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
813 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
815 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
817 else if( aRole == VMR_TransformImage )
818 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
823 void HYDROGUI_Module::updateGV( const bool theIsInit,
824 const bool theIsForced,
825 const bool theDoFitAll )
827 if( !getDisplayer() )
830 QList<int> aViewManagerIdList;
832 // currently, all views are updated
833 ViewManagerMapIterator anIter( myViewManagerMap );
834 while( anIter.hasNext() )
836 GraphicsView_ViewManager* aViewManager =
837 dynamic_cast<GraphicsView_ViewManager*>( anIter.next().value().first );
841 int anId = anIter.key();
842 aViewManagerIdList.append( anId );
845 QListIterator<int> anIdIter( aViewManagerIdList );
846 while( anIdIter.hasNext() )
847 getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
850 void HYDROGUI_Module::updateOCCViewer( const bool theIsInit,
851 const bool theIsForced,
852 const bool theDoFitAll )
854 HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer();
855 if( !anOCCDisplayer )
858 QList<int> aViewManagerIdList;
860 // currently, all views are updated
861 ViewManagerMapIterator anIter( myViewManagerMap );
862 while( anIter.hasNext() )
864 OCCViewer_ViewManager* aViewManager =
865 ::qobject_cast<OCCViewer_ViewManager*>( anIter.next().value().first );
869 int anId = anIter.key();
870 aViewManagerIdList.append( anId );
873 QListIterator<int> anIdIter( aViewManagerIdList );
874 while( anIdIter.hasNext() )
875 anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
878 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
880 if( !theViewManager )
883 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
887 QString aViewType = theViewManager->getType();
888 if( aViewType != GraphicsView_Viewer::Type() &&
889 aViewType != OCCViewer_Viewer::Type())
892 QList<SUIT_Selector*> aSelectorList;
893 aSelectionMgr->selectors( aViewType, aSelectorList );
895 // disable all alien selectors
896 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
897 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
899 SUIT_Selector* aSelector = *anIter;
900 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
901 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
902 aSelector->setEnabled( false );
905 if ( aViewType == GraphicsView_Viewer::Type() )
907 GraphicsView_ViewManager* aViewManager =
908 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
910 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
912 else if ( aViewType == OCCViewer_Viewer::Type() )
914 OCCViewer_ViewManager* aViewManager =
915 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
917 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
921 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
923 bool aPrevState = myIsUpdateEnabled;
924 myIsUpdateEnabled = theState;
928 bool HYDROGUI_Module::isUpdateEnabled() const
930 return myIsUpdateEnabled;
933 QStringList HYDROGUI_Module::storeSelection() const
935 QStringList anEntryList;
936 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
938 SUIT_DataOwnerPtrList aList( true );
939 aSelectionMgr->selected( aList );
941 SUIT_DataOwnerPtrList::iterator anIter;
942 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
944 const LightApp_DataOwner* anOwner =
945 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
947 anEntryList.append( anOwner->entry() );
953 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
955 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
957 SUIT_DataOwnerPtrList aList( true );
958 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
959 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
960 aSelectionMgr->setSelected( aList );