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"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
42 #include <HYDROData_Image.h>
43 #include <HYDROData_Lambert93.h>
44 #include <HYDROData_Tool.h>
46 #include <HYDROData_OperationsFactory.h>
48 #include <GraphicsView_ViewFrame.h>
49 #include <GraphicsView_ViewManager.h>
50 #include <GraphicsView_ViewPort.h>
51 #include <GraphicsView_Viewer.h>
53 #include <ImageComposer_CutOperator.h>
54 #include <ImageComposer_CropOperator.h>
55 #include <ImageComposer_FuseOperator.h>
57 #include <LightApp_Application.h>
58 #include <LightApp_DataOwner.h>
59 #include <LightApp_GVSelector.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_UpdateFlags.h>
63 #include <OCCViewer_ViewFrame.h>
64 #include <OCCViewer_ViewManager.h>
65 #include <OCCViewer_ViewModel.h>
67 #include <SALOME_Event.h>
69 #include <SUIT_DataBrowser.h>
70 #include <SUIT_Desktop.h>
71 #include <SUIT_Study.h>
72 #include <SUIT_ViewManager.h>
74 #include <SVTK_ViewManager.h>
75 #include <SVTK_ViewModel.h>
76 #include <SVTK_Selector.h>
79 #include <QApplication>
80 #include <QGraphicsSceneMouseEvent>
83 static int ViewManagerId = 0;
85 extern "C" HYDRO_EXPORT CAM_Module* createModule()
87 return new HYDROGUI_Module();
90 extern "C" HYDRO_EXPORT char* getModuleVersion()
92 return (char*)HYDRO_VERSION;
95 HYDROGUI_Module::HYDROGUI_Module()
96 : LightApp_Module( "HYDRO" ),
99 myIsUpdateEnabled( true )
103 HYDROGUI_Module::~HYDROGUI_Module()
107 int HYDROGUI_Module::getStudyId() const
109 LightApp_Application* anApp = getApp();
110 return anApp ? anApp->activeStudy()->id() : 0;
113 void HYDROGUI_Module::initialize( CAM_Application* theApp )
115 LightApp_Module::initialize( theApp );
118 createUndoRedoActions();
123 setMenuShown( false );
124 setToolShown( false );
126 myDisplayer = new HYDROGUI_Displayer( this );
127 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
128 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
131 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
133 bool aRes = LightApp_Module::activateModule( theStudy );
135 LightApp_Application* anApp = getApp();
136 SUIT_Desktop* aDesktop = anApp->desktop();
138 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
140 setMenuShown( true );
141 setToolShown( true );
143 #ifndef DISABLE_PYCONSOLE
144 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
145 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
150 updateCommandsStatus();
152 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
153 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
158 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
160 ViewManagerMapIterator anIter( myViewManagerMap );
161 while( anIter.hasNext() )
162 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
163 getApp()->removeViewManager( aViewManager );
164 myViewManagerMap.clear();
166 myObjectStateMap.clear();
169 // clear the data model's list of copying objects
170 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
172 setMenuShown( false );
173 setToolShown( false );
175 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
177 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
178 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
180 return LightApp_Module::deactivateModule( theStudy );
183 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
186 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
187 #ifndef DISABLE_PYCONSOLE
188 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
190 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
193 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
195 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
198 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
202 HYDROGUI_DataModel* aModel = getDataModel();
204 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
205 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
206 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
207 bool anIsVTKView = theClient == SVTK_Viewer::Type();
208 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
211 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
213 bool anIsSelectedDataObjects = false;
214 bool anIsVisibleInSelection = false;
215 bool anIsHiddenInSelection = false;
217 bool anIsImage = false;
218 bool anIsImportedImage = false;
219 bool anIsImageHasRefs = false;
220 bool anIsFusedImage = false;
221 bool anIsCutImage = false;
222 bool anIsSplittedImage = false;
223 bool anIsMustBeUpdatedImage = false;
224 bool anIsPolyline = false;
225 bool anIsBathymetry = false;
226 bool anIsCalculation = false;
227 bool anIsImmersibleZone = false;
228 bool anIsVisualState = false;
229 bool anIsRegion = false;
230 bool anIsZone = false;
231 bool anIsObstacle = false;
232 bool anIsGeomObject = false;
234 // check the selected GEOM objects
235 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
236 theMenu->addAction( action( ImportGeomObjectId ) );
237 theMenu->addSeparator();
240 // check the selected data model objects
241 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
242 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
244 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
245 if( !anObject.IsNull() )
247 anIsSelectedDataObjects = true;
249 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
250 anIsVisibleInSelection |= aVisibility;
251 anIsHiddenInSelection |= !aVisibility;
253 if( anObject->GetKind() == KIND_IMAGE )
256 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
257 if( !anImage.IsNull() )
259 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
260 anIsImageHasRefs = anImage->HasReferences();
261 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
263 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
265 QString anOperatorName = anOperator->name();
266 if( anOperatorName == ImageComposer_FuseOperator::Type() )
267 anIsFusedImage = true;
268 else if( anOperatorName == ImageComposer_CutOperator::Type() )
270 else if( anOperatorName == ImageComposer_CropOperator::Type() )
271 anIsSplittedImage = true;
274 if ( anImage->IsMustBeUpdated() )
276 anIsMustBeUpdatedImage = true;
280 else if( anObject->GetKind() == KIND_POLYLINE )
282 else if( anObject->GetKind() == KIND_CALCULATION )
283 anIsCalculation = true;
284 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
285 anIsImmersibleZone = true;
286 else if( anObject->GetKind() == KIND_VISUAL_STATE )
287 anIsVisualState = true;
288 else if( anObject->GetKind() == KIND_REGION )
290 else if( anObject->GetKind() == KIND_ZONE )
292 else if( anObject->GetKind() == KIND_BATHYMETRY )
293 anIsBathymetry = true;
294 else if( anObject->GetKind() == KIND_OBSTACLE )
298 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
301 // check the selected partitions
302 if( !anIsSelectedDataObjects && anIsObjectBrowser )
304 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
305 if( aSelectedPartition != KIND_UNKNOWN )
307 switch( aSelectedPartition )
310 theMenu->addAction( action( ImportImageId ) );
313 theMenu->addAction( action( CreatePolylineId ) );
315 case KIND_VISUAL_STATE:
316 theMenu->addAction( action( SaveVisualStateId ) );
318 case KIND_BATHYMETRY:
319 theMenu->addAction( action( ImportBathymetryId ) );
321 case KIND_CALCULATION:
322 theMenu->addAction( action( CreateCalculationId ) );
324 case KIND_IMMERSIBLE_ZONE:
325 theMenu->addAction( action( CreateImmersibleZoneId ) );
328 theMenu->addAction( action( ImportObstacleFromFileId ) );
329 theMenu->addAction( action( CreateBoxId ) );
330 theMenu->addAction( action( CreateCylinderId ) );
333 theMenu->addSeparator();
337 if( anIsSelectedDataObjects )
339 if ( anIsMustBeUpdatedImage )
341 theMenu->addAction( action( UpdateImageId ) );
342 theMenu->addSeparator();
345 if( aSeq.Length() == 1 )
349 if( anIsImportedImage )
350 theMenu->addAction( action( EditImportedImageId ) );
351 else if( anIsImageHasRefs )
354 theMenu->addAction( action( EditFusedImageId ) );
355 else if( anIsCutImage )
356 theMenu->addAction( action( EditCutImageId ) );
357 else if( anIsSplittedImage )
358 theMenu->addAction( action( EditSplittedImageId ) );
361 theMenu->addAction( action( ObserveImageId ) );
362 theMenu->addAction( action( ExportImageId ) );
363 theMenu->addSeparator();
365 if( anIsImageHasRefs )
367 theMenu->addAction( action( RemoveImageRefsId ) );
368 theMenu->addSeparator();
371 theMenu->addAction( action( FuseImagesId ) );
372 theMenu->addAction( action( CutImagesId ) );
373 theMenu->addAction( action( SplitImageId ) );
374 theMenu->addSeparator();
376 else if( anIsPolyline )
378 theMenu->addAction( action( EditPolylineId ) );
379 theMenu->addSeparator();
381 else if( anIsCalculation )
383 theMenu->addAction( action( EditCalculationId ) );
384 theMenu->addAction( action( ExportCalculationId ) );
385 theMenu->addSeparator();
387 else if( anIsImmersibleZone )
389 theMenu->addAction( action( EditImmersibleZoneId ) );
390 theMenu->addSeparator();
392 else if( anIsVisualState && anIsObjectBrowser )
394 theMenu->addAction( action( SaveVisualStateId ) );
395 theMenu->addAction( action( LoadVisualStateId ) );
396 theMenu->addSeparator();
399 // Add set color action for geometrical objects
400 if ( anIsGeomObject )
402 theMenu->addAction( action( SetColorId ) );
403 theMenu->addSeparator();
407 theMenu->addAction( action( DeleteId ) );
408 theMenu->addSeparator();
410 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
412 if( anIsHiddenInSelection )
413 theMenu->addAction( action( ShowId ) );
414 theMenu->addAction( action( ShowOnlyId ) );
415 if( anIsVisibleInSelection )
416 theMenu->addAction( action( HideId ) );
417 theMenu->addSeparator();
421 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
423 theMenu->addAction( action( ShowAllId ) );
424 theMenu->addAction( action( HideAllId ) );
425 theMenu->addSeparator();
429 void HYDROGUI_Module::update( const int flags )
431 if( !isUpdateEnabled() )
434 QApplication::setOverrideCursor( Qt::WaitCursor );
436 // To prevent calling this method recursively
437 // from one of the methods called below
438 setUpdateEnabled( false );
440 // store selected objects
441 QStringList aSelectedEntries = storeSelection();
443 bool aDoFitAll = flags & UF_FitAll;
444 if( ( flags & UF_Viewer ) )
445 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
447 if( ( flags & UF_OCCViewer ) )
448 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
450 if( ( flags & UF_VTKViewer ) )
451 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
453 if( ( flags & UF_Model ) && getDataModel() && getApp() )
455 getDataModel()->update( getStudyId() );
457 // Temporary workaround to prevent breaking
458 // the selection in the object browser.
459 // Note: processEvents() should be called after updateGV(),
460 // otherwise the application crashes from time to time.
461 //RKV: qApp->processEvents();
462 getApp()->updateObjectBrowser( true );
465 // Object browser is currently updated by using UF_Model flag
466 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
467 getApp()->updateObjectBrowser( true );
469 if( ( flags & UF_Controls ) && getApp() )
470 getApp()->updateActions();
472 // restore selected objects
473 restoreSelection( aSelectedEntries );
475 setUpdateEnabled( true );
477 QApplication::restoreOverrideCursor();
480 void HYDROGUI_Module::updateCommandsStatus()
482 LightApp_Module::updateCommandsStatus();
484 updateUndoRedoControls();
486 action( CopyId )->setEnabled( getDataModel()->canCopy() );
487 action( PasteId )->setEnabled( getDataModel()->canPaste() );
490 void HYDROGUI_Module::selectionChanged()
492 LightApp_Module::selectionChanged();
493 updateCommandsStatus();
496 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
498 return (HYDROGUI_DataModel*)dataModel();
501 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
506 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
508 return myOCCDisplayer;
511 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
513 return myVTKDisplayer;
516 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
518 if( myViewManagerMap.contains( theId ) )
520 return myViewManagerMap[ theId ].first;
525 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
527 if( myViewManagerMap.contains( theId ) )
529 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
530 GraphicsView_ViewManager* aViewManager =
531 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
533 return aViewManager->getViewer();
538 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
540 if( myViewManagerMap.contains( theId ) )
542 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
543 OCCViewer_ViewManager* aViewManager =
544 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
546 return aViewManager->getOCCViewer();
551 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
553 if( myViewManagerMap.contains( theId ) )
555 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
556 SVTK_ViewManager* aViewManager =
557 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
559 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
564 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
566 ViewManagerMapIterator anIter( myViewManagerMap );
567 while( anIter.hasNext() )
569 int anId = anIter.next().key();
570 const ViewManagerInfo& anInfo = anIter.value();
571 if( anInfo.first == theViewManager )
577 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
579 int anId = getViewManagerId( theViewManager );
582 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
583 return anInfo.second;
588 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
589 const ViewManagerRole theRole )
591 int anId = getViewManagerId( theViewManager );
594 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
595 anInfo.second = theRole;
599 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
600 const Handle(HYDROData_Entity)& theObject ) const
602 if( theObject.IsNull() )
605 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
606 if( anIter1 != myObjectStateMap.end() )
608 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
609 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
610 if( anIter2 != aName2ObjectStateMap.end() )
612 const ObjectState& anObjectState = anIter2.value();
613 return anObjectState.Visibility;
619 void HYDROGUI_Module::setObjectVisible( const int theViewId,
620 const Handle(HYDROData_Entity)& theObject,
621 const bool theState )
623 if( !theObject.IsNull() )
625 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
626 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
627 anObjectState.Visibility = theState;
631 /////////////////// OCC SHAPES PROCESSING
632 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
633 const Handle(HYDROData_Entity)& theObject ) const
635 HYDROGUI_Shape* aResShape = NULL;
636 if( theObject.IsNull() )
639 if ( myShapesMap.contains( theViewId ) )
641 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
642 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
644 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
655 void HYDROGUI_Module::setObjectShape( const int theViewId,
656 const Handle(HYDROData_Entity)& theObject,
657 HYDROGUI_Shape* theShape )
659 if( theObject.IsNull() )
662 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
663 aViewShapes.append( theShape );
666 void HYDROGUI_Module::removeObjectShape( const int theViewId,
667 const Handle(HYDROData_Entity)& theObject )
669 if ( !myShapesMap.contains( theViewId ) )
672 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
673 Handle(HYDROData_Entity) anObject;
674 for ( int i = 0; i < aViewShapes.length(); )
676 HYDROGUI_Shape* aShape = aViewShapes.at( i );
677 anObject = aShape->getObject();
678 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
681 aViewShapes.removeAt( i );
689 void HYDROGUI_Module::removeViewShapes( const int theViewId )
691 if ( !myShapesMap.contains( theViewId ) )
694 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
695 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
697 HYDROGUI_Shape* aShape = aViewShapes.at( i );
702 myShapesMap.remove( theViewId );
704 /////////////////// END OF OCC SHAPES PROCESSING
706 /////////////////// VTKPrs PROCESSING
707 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
708 const Handle(HYDROData_Entity)& theObject ) const
710 HYDROGUI_VTKPrs* aResShape = NULL;
711 if( theObject.IsNull() )
714 if ( myVTKPrsMap.contains( theViewId ) )
716 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
717 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
719 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
730 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
731 const Handle(HYDROData_Entity)& theObject,
732 HYDROGUI_VTKPrs* theShape )
734 if( theObject.IsNull() )
737 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
738 aViewShapes.append( theShape );
741 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
742 const Handle(HYDROData_Entity)& theObject )
744 if ( !myVTKPrsMap.contains( theViewId ) )
747 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
748 Handle(HYDROData_Entity) anObject;
749 for ( int i = 0; i < aViewShapes.length(); )
751 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
752 anObject = aShape->getObject();
753 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
756 aViewShapes.removeAt( i );
764 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
766 if ( !myVTKPrsMap.contains( theViewId ) )
769 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
770 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
772 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
777 myVTKPrsMap.remove( theViewId );
779 /////////////////// END OF VTKPrs PROCESSING
781 CAM_DataModel* HYDROGUI_Module::createDataModel()
783 return new HYDROGUI_DataModel( this );
786 void HYDROGUI_Module::customEvent( QEvent* e )
788 int aType = e->type();
789 if ( aType == NewViewEvent )
791 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
792 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
794 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
796 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
797 ViewManagerRole aRole = getViewManagerRole( aViewManager );
799 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
801 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
802 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
804 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
805 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
806 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
808 //ouv: temporarily commented
809 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
812 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
815 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
821 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
823 QEvent::Type aType = theEvent->type();
824 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
826 if( aType == QEvent::Show )
828 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
829 e->setData( theObj );
830 QApplication::postEvent( this, e );
831 theObj->removeEventFilter( this );
834 return LightApp_Module::eventFilter( theObj, theEvent );
837 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
839 LightApp_Module::onViewManagerAdded( theViewManager );
841 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
843 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
844 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
846 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
848 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
849 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
852 createSelector( theViewManager ); // replace the default selector
854 ViewManagerInfo anInfo( theViewManager, VMR_General );
855 myViewManagerMap.insert( ViewManagerId++, anInfo );
858 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
860 LightApp_Module::onViewManagerRemoved( theViewManager );
862 createSelector( theViewManager ); // replace the default selector
864 int anId = getViewManagerId( theViewManager );
867 OCCViewer_ViewManager* anOCCViewManager =
868 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
869 if ( anOCCViewManager )
871 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
873 removeViewShapes( (size_t)anOCCViewer );
876 myViewManagerMap.remove( anId );
880 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
882 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
884 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
886 aViewFrame->installEventFilter( this );
888 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
890 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
891 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
894 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
896 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
898 aViewFrame->onTopView();
903 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
905 /* ouv: currently unused
906 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
908 SUIT_ViewManager* aViewManager = 0;
910 QObject* aParent = aViewPort;
911 while( aParent = aParent->parent() )
913 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
915 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
917 aViewManager = aViewer->getViewManager();
926 double aMouseX = theEvent->scenePos().x();
927 double aMouseY = theEvent->scenePos().y();
929 ViewManagerRole aRole = getViewManagerRole( aViewManager );
930 if( aRole == VMR_General )
932 int aXDeg = 0, aYDeg = 0;
933 int aXMin = 0, aYMin = 0;
934 double aXSec = 0, aYSec = 0;
935 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
936 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
938 QString aDegSymbol( QChar( 0x00B0 ) );
939 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
940 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
942 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
944 else if( aRole == VMR_TransformImage )
945 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
950 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
951 const bool theIsInit,
952 const bool theIsForced,
953 const bool theDoFitAll )
955 QList<int> aViewManagerIdList;
957 // currently, all views are updated
958 ViewManagerMapIterator anIter( myViewManagerMap );
959 while( anIter.hasNext() )
961 SUIT_ViewManager* aViewManager = anIter.next().value().first;
963 if ( theDisplayer->IsApplicable( aViewManager ) )
965 int anId = anIter.key();
966 aViewManagerIdList.append( anId );
970 QListIterator<int> anIdIter( aViewManagerIdList );
971 while( anIdIter.hasNext() )
973 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
977 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
979 if( !theViewManager )
982 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
986 QString aViewType = theViewManager->getType();
987 if( aViewType != GraphicsView_Viewer::Type() &&
988 aViewType != OCCViewer_Viewer::Type())
991 QList<SUIT_Selector*> aSelectorList;
992 aSelectionMgr->selectors( aViewType, aSelectorList );
994 // disable all alien selectors
995 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
996 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
998 SUIT_Selector* aSelector = *anIter;
999 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1000 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1001 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1002 aSelector->setEnabled( false );
1005 if ( aViewType == GraphicsView_Viewer::Type() )
1007 GraphicsView_ViewManager* aViewManager =
1008 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1010 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1012 else if ( aViewType == OCCViewer_Viewer::Type() )
1014 OCCViewer_ViewManager* aViewManager =
1015 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1017 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1021 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1023 bool aPrevState = myIsUpdateEnabled;
1024 myIsUpdateEnabled = theState;
1028 bool HYDROGUI_Module::isUpdateEnabled() const
1030 return myIsUpdateEnabled;
1033 QStringList HYDROGUI_Module::storeSelection() const
1035 QStringList anEntryList;
1036 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1038 SUIT_DataOwnerPtrList aList( true );
1039 aSelectionMgr->selected( aList );
1041 SUIT_DataOwnerPtrList::iterator anIter;
1042 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1044 const LightApp_DataOwner* anOwner =
1045 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1047 anEntryList.append( anOwner->entry() );
1053 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1055 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1057 SUIT_DataOwnerPtrList aList( true );
1058 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1059 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1060 aSelectionMgr->setSelected( aList );