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_Desktop.h>
66 #include <SUIT_Study.h>
67 #include <SUIT_ViewManager.h>
70 #include <QApplication>
71 #include <QGraphicsSceneMouseEvent>
74 static int ViewManagerId = 0;
76 extern "C" HYDRO_EXPORT CAM_Module* createModule()
78 return new HYDROGUI_Module();
81 extern "C" HYDRO_EXPORT char* getModuleVersion()
83 return (char*)HYDRO_VERSION;
86 HYDROGUI_Module::HYDROGUI_Module()
87 : LightApp_Module( "HYDRO" ),
90 myIsUpdateEnabled( true )
94 HYDROGUI_Module::~HYDROGUI_Module()
98 int HYDROGUI_Module::getStudyId() const
100 LightApp_Application* anApp = getApp();
101 return anApp ? anApp->activeStudy()->id() : 0;
104 void HYDROGUI_Module::initialize( CAM_Application* theApp )
106 LightApp_Module::initialize( theApp );
109 createUndoRedoActions();
114 setMenuShown( false );
115 setToolShown( false );
117 myDisplayer = new HYDROGUI_Displayer( this );
118 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
121 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
123 bool aRes = LightApp_Module::activateModule( theStudy );
125 LightApp_Application* anApp = getApp();
126 SUIT_Desktop* aDesktop = anApp->desktop();
128 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
130 setMenuShown( true );
131 setToolShown( true );
133 #ifndef DISABLE_PYCONSOLE
134 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
135 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
140 updateCommandsStatus();
145 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
147 ViewManagerMapIterator anIter( myViewManagerMap );
148 while( anIter.hasNext() )
149 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
150 getApp()->removeViewManager( aViewManager );
151 myViewManagerMap.clear();
153 myObjectStateMap.clear();
156 // clear the data model's list of copying objects
157 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
159 setMenuShown( false );
160 setToolShown( false );
162 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
164 return LightApp_Module::deactivateModule( theStudy );
167 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
170 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
171 #ifndef DISABLE_PYCONSOLE
172 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
174 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
177 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
179 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
182 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
186 HYDROGUI_DataModel* aModel = getDataModel();
188 bool anIsObjectBrowser = theClient == "ObjectBrowser";
189 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
190 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
191 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView )
194 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
196 bool anIsSelectedDataObjects = false;
197 bool anIsVisibleInSelection = false;
198 bool anIsHiddenInSelection = false;
200 bool anIsImage = false;
201 bool anIsImportedImage = false;
202 bool anIsImageHasRefs = false;
203 bool anIsFusedImage = false;
204 bool anIsCutImage = false;
205 bool anIsSplittedImage = false;
206 bool anIsMustBeUpdatedImage = false;
207 bool anIsPolyline = false;
208 bool anIsCalculation = false;
209 bool anIsImmersibleZone = false;
210 bool anIsVisualState = false;
212 // check the selected data model objects
213 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
214 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
216 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
217 if( !anObject.IsNull() )
219 anIsSelectedDataObjects = true;
221 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
222 anIsVisibleInSelection |= aVisibility;
223 anIsHiddenInSelection |= !aVisibility;
225 if( anObject->GetKind() == KIND_IMAGE )
228 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
229 if( !anImage.IsNull() )
231 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
232 anIsImageHasRefs = anImage->HasReferences();
233 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
235 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
237 QString anOperatorName = anOperator->name();
238 if( anOperatorName == ImageComposer_FuseOperator::Type() )
239 anIsFusedImage = true;
240 else if( anOperatorName == ImageComposer_CutOperator::Type() )
242 else if( anOperatorName == ImageComposer_CropOperator::Type() )
243 anIsSplittedImage = true;
246 anIsMustBeUpdatedImage = anImage->IsMustBeUpdated();
249 else if( anObject->GetKind() == KIND_POLYLINE )
251 else if( anObject->GetKind() == KIND_CALCULATION )
252 anIsCalculation = true;
253 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
254 anIsImmersibleZone = true;
255 else if( anObject->GetKind() == KIND_VISUAL_STATE )
256 anIsVisualState = true;
260 // check the selected partitions
261 if( !anIsSelectedDataObjects && anIsObjectBrowser )
263 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
264 if( aSelectedPartition != KIND_UNKNOWN )
266 switch( aSelectedPartition )
269 theMenu->addAction( action( ImportImageId ) );
272 theMenu->addAction( action( CreatePolylineId ) );
274 case KIND_VISUAL_STATE:
275 theMenu->addAction( action( SaveVisualStateId ) );
277 case KIND_BATHYMETRY:
278 theMenu->addAction( action( ImportBathymetryId ) );
280 case KIND_CALCULATION:
281 theMenu->addAction( action( CreateCalculationId ) );
283 case KIND_IMMERSIBLE_ZONE:
284 theMenu->addAction( action( CreateImmersibleZoneId ) );
287 theMenu->addSeparator();
291 if( anIsSelectedDataObjects && anIsMustBeUpdatedImage )
293 theMenu->addAction( action( UpdateImageId ) );
294 theMenu->addSeparator();
297 if( anIsSelectedDataObjects && aSeq.Length() == 1 )
301 if( anIsImportedImage )
302 theMenu->addAction( action( EditImportedImageId ) );
303 else if( anIsImageHasRefs )
306 theMenu->addAction( action( EditFusedImageId ) );
307 else if( anIsCutImage )
308 theMenu->addAction( action( EditCutImageId ) );
309 else if( anIsSplittedImage )
310 theMenu->addAction( action( EditSplittedImageId ) );
313 theMenu->addAction( action( ObserveImageId ) );
314 theMenu->addAction( action( ExportImageId ) );
315 theMenu->addSeparator();
317 if( anIsImageHasRefs )
319 theMenu->addAction( action( RemoveImageRefsId ) );
320 theMenu->addSeparator();
323 theMenu->addAction( action( FuseImagesId ) );
324 theMenu->addAction( action( CutImagesId ) );
325 theMenu->addAction( action( SplitImageId ) );
326 theMenu->addSeparator();
328 else if( anIsPolyline )
330 theMenu->addAction( action( EditPolylineId ) );
331 theMenu->addSeparator();
333 else if( anIsCalculation )
335 theMenu->addAction( action( EditCalculationId ) );
336 theMenu->addSeparator();
338 else if( anIsImmersibleZone )
340 theMenu->addAction( action( EditImmersibleZoneId ) );
341 theMenu->addSeparator();
343 else if( anIsVisualState && anIsObjectBrowser )
345 theMenu->addAction( action( SaveVisualStateId ) );
346 theMenu->addAction( action( LoadVisualStateId ) );
347 theMenu->addSeparator();
351 if( anIsSelectedDataObjects )
353 theMenu->addAction( action( DeleteId ) );
354 theMenu->addSeparator();
357 if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsImmersibleZone ) )
359 if( anIsHiddenInSelection )
360 theMenu->addAction( action( ShowId ) );
361 theMenu->addAction( action( ShowOnlyId ) );
362 if( anIsVisibleInSelection )
363 theMenu->addAction( action( HideId ) );
364 theMenu->addSeparator();
367 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView )
369 theMenu->addAction( action( ShowAllId ) );
370 theMenu->addAction( action( HideAllId ) );
371 theMenu->addSeparator();
375 void HYDROGUI_Module::update( const int flags )
377 if( !isUpdateEnabled() )
380 QApplication::setOverrideCursor( Qt::WaitCursor );
382 // To prevent calling this method recursively
383 // from one of the methods called below
384 setUpdateEnabled( false );
386 // store selected objects
387 QStringList aSelectedEntries = storeSelection();
389 if( ( flags & UF_Viewer ) )
390 updateGV( flags & UF_GV_Init,
391 flags & UF_GV_Forced );
393 if( ( flags & UF_OCCViewer ) )
394 updateOCCViewer( flags & UF_OCC_Init,
395 flags & UF_OCC_Forced );
397 if( ( flags & UF_Model ) && getDataModel() && getApp() )
399 getDataModel()->update( getStudyId() );
401 // Temporary workaround to prevent breaking
402 // the selection in the object browser.
403 // Note: processEvents() should be called after updateGV(),
404 // otherwise the application crashes from time to time.
405 //RKV: qApp->processEvents();
406 getApp()->updateObjectBrowser( true );
409 // Object browser is currently updated by using UF_Model flag
410 //if( ( flags & UF_ObjBrowser ) && getApp() )
411 // getApp()->updateObjectBrowser( true );
413 if( ( flags & UF_Controls ) && getApp() )
414 getApp()->updateActions();
416 // restore selected objects
417 restoreSelection( aSelectedEntries );
419 setUpdateEnabled( true );
421 QApplication::restoreOverrideCursor();
424 void HYDROGUI_Module::updateCommandsStatus()
426 LightApp_Module::updateCommandsStatus();
428 updateUndoRedoControls();
430 action( CopyId )->setEnabled( getDataModel()->canCopy() );
431 action( PasteId )->setEnabled( getDataModel()->canPaste() );
434 void HYDROGUI_Module::selectionChanged()
436 LightApp_Module::selectionChanged();
437 updateCommandsStatus();
440 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
442 return (HYDROGUI_DataModel*)dataModel();
445 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
450 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
452 return myOCCDisplayer;
455 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
457 if( myViewManagerMap.contains( theId ) )
459 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
460 GraphicsView_ViewManager* aViewManager =
461 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
463 return aViewManager->getViewer();
468 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
470 if( myViewManagerMap.contains( theId ) )
472 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
473 OCCViewer_ViewManager* aViewManager =
474 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
476 return aViewManager->getOCCViewer();
481 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
483 ViewManagerMapIterator anIter( myViewManagerMap );
484 while( anIter.hasNext() )
486 int anId = anIter.next().key();
487 const ViewManagerInfo& anInfo = anIter.value();
488 if( anInfo.first == theViewManager )
494 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
496 int anId = getViewManagerId( theViewManager );
499 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
500 return anInfo.second;
505 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
506 const ViewManagerRole theRole )
508 int anId = getViewManagerId( theViewManager );
511 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
512 anInfo.second = theRole;
516 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
517 const Handle(HYDROData_Entity)& theObject ) const
519 if( theObject.IsNull() )
522 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
523 if( anIter1 != myObjectStateMap.end() )
525 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
526 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
527 if( anIter2 != aName2ObjectStateMap.end() )
529 const ObjectState& anObjectState = anIter2.value();
530 return anObjectState.Visibility;
536 void HYDROGUI_Module::setObjectVisible( const int theViewId,
537 const Handle(HYDROData_Entity)& theObject,
538 const bool theState )
540 if( !theObject.IsNull() )
542 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
543 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
544 anObjectState.Visibility = theState;
548 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
549 const Handle(HYDROData_Entity)& theObject ) const
551 HYDROGUI_Shape* aResShape = NULL;
552 if( theObject.IsNull() )
555 if ( myShapesMap.contains( theViewId ) )
557 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
558 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
560 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
571 void HYDROGUI_Module::setObjectShape( const int theViewId,
572 const Handle(HYDROData_Entity)& theObject,
573 HYDROGUI_Shape* theShape )
575 if( theObject.IsNull() )
578 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
579 aViewShapes.append( theShape );
582 void HYDROGUI_Module::removeObjectShape( const int theViewId,
583 const Handle(HYDROData_Entity)& theObject )
585 if ( !myShapesMap.contains( theViewId ) )
588 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
589 Handle(HYDROData_Entity) anObject;
590 for ( int i = 0; i < aViewShapes.length(); )
592 HYDROGUI_Shape* aShape = aViewShapes.at( i );
593 anObject = aShape->getObject();
594 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
597 aViewShapes.removeAt( i );
605 void HYDROGUI_Module::removeViewShapes( const int theViewId )
607 if ( !myShapesMap.contains( theViewId ) )
610 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
611 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
613 HYDROGUI_Shape* aShape = aViewShapes.at( i );
618 myShapesMap.remove( theViewId );
621 CAM_DataModel* HYDROGUI_Module::createDataModel()
623 return new HYDROGUI_DataModel( this );
626 void HYDROGUI_Module::customEvent( QEvent* e )
628 int aType = e->type();
629 if ( aType == NewViewEvent )
631 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
632 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
634 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
636 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
637 ViewManagerRole aRole = getViewManagerRole( aViewManager );
639 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
641 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
642 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
644 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
645 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
646 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
648 //ouv: temporarily commented
649 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
652 if( aRole != VMR_TransformImage )
655 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
661 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
663 QEvent::Type aType = theEvent->type();
664 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
666 if( aType == QEvent::Show )
668 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
669 e->setData( theObj );
670 QApplication::postEvent( this, e );
671 theObj->removeEventFilter( this );
674 return LightApp_Module::eventFilter( theObj, theEvent );
677 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
679 LightApp_Module::onViewManagerAdded( theViewManager );
681 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
683 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
684 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
686 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
688 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
689 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
692 createSelector( theViewManager ); // replace the default selector
694 ViewManagerInfo anInfo( theViewManager, VMR_General );
695 myViewManagerMap.insert( ViewManagerId++, anInfo );
698 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
700 LightApp_Module::onViewManagerRemoved( theViewManager );
702 createSelector( theViewManager ); // replace the default selector
704 int anId = getViewManagerId( theViewManager );
707 OCCViewer_ViewManager* anOCCViewManager =
708 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
709 if ( anOCCViewManager )
711 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
713 removeViewShapes( (size_t)anOCCViewer );
716 myViewManagerMap.remove( anId );
720 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
722 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
724 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
726 aViewFrame->installEventFilter( this );
728 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
730 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
731 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
734 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
736 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
738 aViewFrame->onTopView();
743 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
745 /* ouv: currently unused
746 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
748 SUIT_ViewManager* aViewManager = 0;
750 QObject* aParent = aViewPort;
751 while( aParent = aParent->parent() )
753 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
755 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
757 aViewManager = aViewer->getViewManager();
766 double aMouseX = theEvent->scenePos().x();
767 double aMouseY = theEvent->scenePos().y();
769 ViewManagerRole aRole = getViewManagerRole( aViewManager );
770 if( aRole == VMR_General )
772 int aXDeg = 0, aYDeg = 0;
773 int aXMin = 0, aYMin = 0;
774 double aXSec = 0, aYSec = 0;
775 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
776 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
778 QString aDegSymbol( QChar( 0x00B0 ) );
779 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
780 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
782 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
784 else if( aRole == VMR_TransformImage )
785 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
790 void HYDROGUI_Module::updateGV( const bool theIsInit,
791 const bool theIsForced )
793 if( !getDisplayer() )
796 QList<int> aViewManagerIdList;
798 // currently, all views are updated
799 ViewManagerMapIterator anIter( myViewManagerMap );
800 while( anIter.hasNext() )
802 GraphicsView_ViewManager* aViewManager =
803 dynamic_cast<GraphicsView_ViewManager*>( anIter.next().value().first );
807 int anId = anIter.key();
808 aViewManagerIdList.append( anId );
811 QListIterator<int> anIdIter( aViewManagerIdList );
812 while( anIdIter.hasNext() )
813 getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced );
816 void HYDROGUI_Module::updateOCCViewer( const bool theIsInit,
817 const bool theIsForced )
819 HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer();
820 if( !anOCCDisplayer )
823 QList<int> aViewManagerIdList;
825 // currently, all views are updated
826 ViewManagerMapIterator anIter( myViewManagerMap );
827 while( anIter.hasNext() )
829 OCCViewer_ViewManager* aViewManager =
830 ::qobject_cast<OCCViewer_ViewManager*>( anIter.next().value().first );
834 int anId = anIter.key();
835 aViewManagerIdList.append( anId );
838 QListIterator<int> anIdIter( aViewManagerIdList );
839 while( anIdIter.hasNext() )
840 anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced );
843 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
845 if( !theViewManager )
848 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
852 QString aViewType = theViewManager->getType();
853 if( aViewType != GraphicsView_Viewer::Type() &&
854 aViewType != OCCViewer_Viewer::Type())
857 QList<SUIT_Selector*> aSelectorList;
858 aSelectionMgr->selectors( aViewType, aSelectorList );
860 // disable all alien selectors
861 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
862 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
864 SUIT_Selector* aSelector = *anIter;
865 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
866 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
867 aSelector->setEnabled( false );
870 if ( aViewType == GraphicsView_Viewer::Type() )
872 GraphicsView_ViewManager* aViewManager =
873 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
875 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
877 else if ( aViewType == OCCViewer_Viewer::Type() )
879 OCCViewer_ViewManager* aViewManager =
880 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
882 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
886 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
888 bool aPrevState = myIsUpdateEnabled;
889 myIsUpdateEnabled = theState;
893 bool HYDROGUI_Module::isUpdateEnabled() const
895 return myIsUpdateEnabled;
898 QStringList HYDROGUI_Module::storeSelection() const
900 QStringList anEntryList;
901 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
903 SUIT_DataOwnerPtrList aList( true );
904 aSelectionMgr->selected( aList );
906 SUIT_DataOwnerPtrList::iterator anIter;
907 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
909 const LightApp_DataOwner* anOwner =
910 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
912 anEntryList.append( anOwner->entry() );
918 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
920 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
922 SUIT_DataOwnerPtrList aList( true );
923 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
924 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
925 aSelectionMgr->setSelected( aList );