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,
404 if( ( flags & UF_OCCViewer ) )
405 updateOCCViewer( flags & UF_OCC_Init,
406 flags & UF_OCC_Forced,
409 if( ( flags & UF_Model ) && getDataModel() && getApp() )
411 getDataModel()->update( getStudyId() );
413 // Temporary workaround to prevent breaking
414 // the selection in the object browser.
415 // Note: processEvents() should be called after updateGV(),
416 // otherwise the application crashes from time to time.
417 //RKV: qApp->processEvents();
418 getApp()->updateObjectBrowser( true );
421 // Object browser is currently updated by using UF_Model flag
422 //if( ( flags & UF_ObjBrowser ) && getApp() )
423 // getApp()->updateObjectBrowser( true );
425 if( ( flags & UF_Controls ) && getApp() )
426 getApp()->updateActions();
428 // restore selected objects
429 restoreSelection( aSelectedEntries );
431 setUpdateEnabled( true );
433 QApplication::restoreOverrideCursor();
436 void HYDROGUI_Module::updateCommandsStatus()
438 LightApp_Module::updateCommandsStatus();
440 updateUndoRedoControls();
442 action( CopyId )->setEnabled( getDataModel()->canCopy() );
443 action( PasteId )->setEnabled( getDataModel()->canPaste() );
446 void HYDROGUI_Module::selectionChanged()
448 LightApp_Module::selectionChanged();
449 updateCommandsStatus();
452 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
454 return (HYDROGUI_DataModel*)dataModel();
457 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
462 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
464 return myOCCDisplayer;
467 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
469 if( myViewManagerMap.contains( theId ) )
471 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
472 GraphicsView_ViewManager* aViewManager =
473 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
475 return aViewManager->getViewer();
480 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
482 if( myViewManagerMap.contains( theId ) )
484 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
485 OCCViewer_ViewManager* aViewManager =
486 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
488 return aViewManager->getOCCViewer();
493 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
495 ViewManagerMapIterator anIter( myViewManagerMap );
496 while( anIter.hasNext() )
498 int anId = anIter.next().key();
499 const ViewManagerInfo& anInfo = anIter.value();
500 if( anInfo.first == theViewManager )
506 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
508 int anId = getViewManagerId( theViewManager );
511 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
512 return anInfo.second;
517 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
518 const ViewManagerRole theRole )
520 int anId = getViewManagerId( theViewManager );
523 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
524 anInfo.second = theRole;
528 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
529 const Handle(HYDROData_Entity)& theObject ) const
531 if( theObject.IsNull() )
534 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
535 if( anIter1 != myObjectStateMap.end() )
537 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
538 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
539 if( anIter2 != aName2ObjectStateMap.end() )
541 const ObjectState& anObjectState = anIter2.value();
542 return anObjectState.Visibility;
548 void HYDROGUI_Module::setObjectVisible( const int theViewId,
549 const Handle(HYDROData_Entity)& theObject,
550 const bool theState )
552 if( !theObject.IsNull() )
554 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
555 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
556 anObjectState.Visibility = theState;
560 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
561 const Handle(HYDROData_Entity)& theObject ) const
563 HYDROGUI_Shape* aResShape = NULL;
564 if( theObject.IsNull() )
567 if ( myShapesMap.contains( theViewId ) )
569 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
570 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
572 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
583 void HYDROGUI_Module::setObjectShape( const int theViewId,
584 const Handle(HYDROData_Entity)& theObject,
585 HYDROGUI_Shape* theShape )
587 if( theObject.IsNull() )
590 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
591 aViewShapes.append( theShape );
594 void HYDROGUI_Module::removeObjectShape( const int theViewId,
595 const Handle(HYDROData_Entity)& theObject )
597 if ( !myShapesMap.contains( theViewId ) )
600 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
601 Handle(HYDROData_Entity) anObject;
602 for ( int i = 0; i < aViewShapes.length(); )
604 HYDROGUI_Shape* aShape = aViewShapes.at( i );
605 anObject = aShape->getObject();
606 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
609 aViewShapes.removeAt( i );
617 void HYDROGUI_Module::removeViewShapes( const int theViewId )
619 if ( !myShapesMap.contains( theViewId ) )
622 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
623 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
625 HYDROGUI_Shape* aShape = aViewShapes.at( i );
630 myShapesMap.remove( theViewId );
633 CAM_DataModel* HYDROGUI_Module::createDataModel()
635 return new HYDROGUI_DataModel( this );
638 void HYDROGUI_Module::customEvent( QEvent* e )
640 int aType = e->type();
641 if ( aType == NewViewEvent )
643 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
644 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
646 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
648 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
649 ViewManagerRole aRole = getViewManagerRole( aViewManager );
651 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
653 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
654 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
656 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
657 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
658 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
660 //ouv: temporarily commented
661 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
664 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
667 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
673 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
675 QEvent::Type aType = theEvent->type();
676 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
678 if( aType == QEvent::Show )
680 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
681 e->setData( theObj );
682 QApplication::postEvent( this, e );
683 theObj->removeEventFilter( this );
686 return LightApp_Module::eventFilter( theObj, theEvent );
689 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
691 LightApp_Module::onViewManagerAdded( theViewManager );
693 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
695 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
696 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
698 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
700 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
701 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
704 createSelector( theViewManager ); // replace the default selector
706 ViewManagerInfo anInfo( theViewManager, VMR_General );
707 myViewManagerMap.insert( ViewManagerId++, anInfo );
710 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
712 LightApp_Module::onViewManagerRemoved( theViewManager );
714 createSelector( theViewManager ); // replace the default selector
716 int anId = getViewManagerId( theViewManager );
719 OCCViewer_ViewManager* anOCCViewManager =
720 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
721 if ( anOCCViewManager )
723 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
725 removeViewShapes( (size_t)anOCCViewer );
728 myViewManagerMap.remove( anId );
732 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
734 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
736 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
738 aViewFrame->installEventFilter( this );
740 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
742 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
743 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
746 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
748 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
750 aViewFrame->onTopView();
755 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
757 /* ouv: currently unused
758 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
760 SUIT_ViewManager* aViewManager = 0;
762 QObject* aParent = aViewPort;
763 while( aParent = aParent->parent() )
765 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
767 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
769 aViewManager = aViewer->getViewManager();
778 double aMouseX = theEvent->scenePos().x();
779 double aMouseY = theEvent->scenePos().y();
781 ViewManagerRole aRole = getViewManagerRole( aViewManager );
782 if( aRole == VMR_General )
784 int aXDeg = 0, aYDeg = 0;
785 int aXMin = 0, aYMin = 0;
786 double aXSec = 0, aYSec = 0;
787 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
788 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
790 QString aDegSymbol( QChar( 0x00B0 ) );
791 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
792 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
794 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
796 else if( aRole == VMR_TransformImage )
797 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
802 void HYDROGUI_Module::updateGV( const bool theIsInit,
803 const bool theIsForced,
804 const bool theDoFitAll )
806 if( !getDisplayer() )
809 QList<int> aViewManagerIdList;
811 // currently, all views are updated
812 ViewManagerMapIterator anIter( myViewManagerMap );
813 while( anIter.hasNext() )
815 GraphicsView_ViewManager* aViewManager =
816 dynamic_cast<GraphicsView_ViewManager*>( anIter.next().value().first );
820 int anId = anIter.key();
821 aViewManagerIdList.append( anId );
824 QListIterator<int> anIdIter( aViewManagerIdList );
825 while( anIdIter.hasNext() )
826 getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
829 void HYDROGUI_Module::updateOCCViewer( const bool theIsInit,
830 const bool theIsForced,
831 const bool theDoFitAll )
833 HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer();
834 if( !anOCCDisplayer )
837 QList<int> aViewManagerIdList;
839 // currently, all views are updated
840 ViewManagerMapIterator anIter( myViewManagerMap );
841 while( anIter.hasNext() )
843 OCCViewer_ViewManager* aViewManager =
844 ::qobject_cast<OCCViewer_ViewManager*>( anIter.next().value().first );
848 int anId = anIter.key();
849 aViewManagerIdList.append( anId );
852 QListIterator<int> anIdIter( aViewManagerIdList );
853 while( anIdIter.hasNext() )
854 anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
857 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
859 if( !theViewManager )
862 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
866 QString aViewType = theViewManager->getType();
867 if( aViewType != GraphicsView_Viewer::Type() &&
868 aViewType != OCCViewer_Viewer::Type())
871 QList<SUIT_Selector*> aSelectorList;
872 aSelectionMgr->selectors( aViewType, aSelectorList );
874 // disable all alien selectors
875 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
876 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
878 SUIT_Selector* aSelector = *anIter;
879 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
880 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
881 aSelector->setEnabled( false );
884 if ( aViewType == GraphicsView_Viewer::Type() )
886 GraphicsView_ViewManager* aViewManager =
887 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
889 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
891 else if ( aViewType == OCCViewer_Viewer::Type() )
893 OCCViewer_ViewManager* aViewManager =
894 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
896 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
900 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
902 bool aPrevState = myIsUpdateEnabled;
903 myIsUpdateEnabled = theState;
907 bool HYDROGUI_Module::isUpdateEnabled() const
909 return myIsUpdateEnabled;
912 QStringList HYDROGUI_Module::storeSelection() const
914 QStringList anEntryList;
915 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
917 SUIT_DataOwnerPtrList aList( true );
918 aSelectionMgr->selected( aList );
920 SUIT_DataOwnerPtrList::iterator anIter;
921 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
923 const LightApp_DataOwner* anOwner =
924 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
926 anEntryList.append( anOwner->entry() );
932 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
934 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
936 SUIT_DataOwnerPtrList aList( true );
937 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
938 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
939 aSelectionMgr->setSelected( aList );