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"
41 #include "HYDROGUI_PolylineOp.h"
43 #include <HYDROData_Image.h>
44 #include <HYDROData_Profile.h>
45 #include <HYDROData_Lambert93.h>
46 #include <HYDROData_Tool.h>
48 #include <HYDROData_OperationsFactory.h>
50 #include <GraphicsView_ViewFrame.h>
51 #include <GraphicsView_ViewManager.h>
52 #include <GraphicsView_ViewPort.h>
53 #include <GraphicsView_Viewer.h>
55 #include <ImageComposer_CutOperator.h>
56 #include <ImageComposer_CropOperator.h>
57 #include <ImageComposer_FuseOperator.h>
59 #include <LightApp_Application.h>
60 #include <LightApp_DataOwner.h>
61 #include <LightApp_GVSelector.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_UpdateFlags.h>
65 #include <OCCViewer_ViewFrame.h>
66 #include <OCCViewer_ViewManager.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SALOME_Event.h>
71 #include <SUIT_DataBrowser.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_Study.h>
74 #include <SUIT_ViewManager.h>
76 #include <SVTK_ViewManager.h>
77 #include <SVTK_ViewModel.h>
78 #include <SVTK_Selector.h>
81 #include <QApplication>
82 #include <QGraphicsSceneMouseEvent>
85 static int ViewManagerId = 0;
87 extern "C" HYDRO_EXPORT CAM_Module* createModule()
89 return new HYDROGUI_Module();
92 extern "C" HYDRO_EXPORT char* getModuleVersion()
94 return (char*)HYDRO_VERSION;
97 HYDROGUI_Module::HYDROGUI_Module()
98 : LightApp_Module( "HYDRO" ),
101 myIsUpdateEnabled( true )
105 HYDROGUI_Module::~HYDROGUI_Module()
109 int HYDROGUI_Module::getStudyId() const
111 LightApp_Application* anApp = getApp();
112 return anApp ? anApp->activeStudy()->id() : 0;
115 void HYDROGUI_Module::initialize( CAM_Application* theApp )
117 LightApp_Module::initialize( theApp );
120 createUndoRedoActions();
125 setMenuShown( false );
126 setToolShown( false );
128 myDisplayer = new HYDROGUI_Displayer( this );
129 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
130 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
133 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
135 bool aRes = LightApp_Module::activateModule( theStudy );
137 LightApp_Application* anApp = getApp();
138 SUIT_Desktop* aDesktop = anApp->desktop();
140 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
142 setMenuShown( true );
143 setToolShown( true );
145 #ifndef DISABLE_PYCONSOLE
146 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
147 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
152 updateCommandsStatus();
154 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
155 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
157 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
162 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
164 ViewManagerMapIterator anIter( myViewManagerMap );
165 while( anIter.hasNext() )
166 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
167 getApp()->removeViewManager( aViewManager );
168 myViewManagerMap.clear();
170 myObjectStateMap.clear();
174 // clear the data model's list of copying objects
175 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
177 setMenuShown( false );
178 setToolShown( false );
180 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
182 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
183 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
185 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
187 return LightApp_Module::deactivateModule( theStudy );
190 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
193 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
194 #ifndef DISABLE_PYCONSOLE
195 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
197 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
200 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
202 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
205 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
209 HYDROGUI_DataModel* aModel = getDataModel();
211 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
212 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
213 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
214 bool anIsVTKView = theClient == SVTK_Viewer::Type();
215 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
218 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
220 bool anIsSelectedDataObjects = false;
221 bool anIsVisibleInSelection = false;
222 bool anIsHiddenInSelection = false;
224 bool anIsImage = false;
225 bool anIsImportedImage = false;
226 bool anIsImageHasRefs = false;
227 bool anIsFusedImage = false;
228 bool anIsCutImage = false;
229 bool anIsSplittedImage = false;
230 bool anIsMustBeUpdatedImage = false;
231 bool anIsPolyline = false;
232 bool anIsPolyline3D = false;
233 bool anIsProfile = false;
234 bool anIsValidProfile = false;
235 bool anAllAreProfiles = false;
236 bool anIsBathymetry = false;
237 bool anIsCalculation = false;
238 bool anIsImmersibleZone = false;
239 bool anIsVisualState = false;
240 bool anIsRegion = false;
241 bool anIsZone = false;
242 bool anIsObstacle = false;
243 bool anIsStream = false;
244 bool anIsGeomObject = false;
246 // check the selected GEOM objects
247 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
248 theMenu->addAction( action( ImportGeomObjectId ) );
249 theMenu->addSeparator();
252 // check the selected data model objects
253 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
254 int aNbOfSelectedProfiles = 0;
255 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
257 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
258 if( !anObject.IsNull() )
260 anIsSelectedDataObjects = true;
262 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
263 anIsVisibleInSelection |= aVisibility;
264 anIsHiddenInSelection |= !aVisibility;
266 ObjectKind anObjectKind = anObject->GetKind();
267 if( anObjectKind == KIND_IMAGE )
270 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
271 if( !anImage.IsNull() )
273 anIsImportedImage = anImage->HasLocalPoints();
274 anIsImageHasRefs = anImage->HasReferences();
275 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
277 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
279 QString anOperatorName = anOperator->name();
280 if( anOperatorName == ImageComposer_FuseOperator::Type() )
281 anIsFusedImage = true;
282 else if( anOperatorName == ImageComposer_CutOperator::Type() )
284 else if( anOperatorName == ImageComposer_CropOperator::Type() )
285 anIsSplittedImage = true;
288 if ( anImage->IsMustBeUpdated() )
290 anIsMustBeUpdatedImage = true;
294 else if( anObjectKind == KIND_POLYLINEXY )
296 else if( anObjectKind == KIND_POLYLINE )
297 anIsPolyline3D = true;
298 else if( anObjectKind == KIND_PROFILE )
301 aNbOfSelectedProfiles++;
303 Handle(HYDROData_Profile) aProfile =
304 Handle(HYDROData_Profile)::DownCast( anObject );
305 if( !aProfile.IsNull() && aProfile->IsValid() ) {
306 anIsValidProfile = true;
309 else if( anObjectKind == KIND_CALCULATION )
310 anIsCalculation = true;
311 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
312 anIsImmersibleZone = true;
313 else if( anObjectKind == KIND_VISUAL_STATE )
314 anIsVisualState = true;
315 else if( anObjectKind == KIND_REGION )
317 else if( anObjectKind == KIND_ZONE )
319 else if( anObjectKind == KIND_BATHYMETRY )
320 anIsBathymetry = true;
321 else if( anObjectKind == KIND_OBSTACLE )
323 else if( anObjectKind == KIND_STREAM )
327 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
330 // Check if all selected objects are profiles
331 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
332 ( aNbOfSelectedProfiles == aSeq.Length() );
334 // check the selected partitions
335 if( !anIsSelectedDataObjects && anIsObjectBrowser )
337 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
338 if( aSelectedPartition != KIND_UNKNOWN )
340 switch( aSelectedPartition )
343 theMenu->addAction( action( ImportImageId ) );
345 case KIND_POLYLINEXY:
346 theMenu->addAction( action( CreatePolylineId ) );
349 theMenu->addAction( action( CreatePolyline3DId ) );
352 theMenu->addAction( action( CreateProfileId ) );
353 theMenu->addAction( action( ImportProfilesId ) );
354 theMenu->addAction( action( AllGeoreferencementId ) );
356 case KIND_VISUAL_STATE:
357 theMenu->addAction( action( SaveVisualStateId ) );
359 case KIND_BATHYMETRY:
360 theMenu->addAction( action( ImportBathymetryId ) );
362 case KIND_CALCULATION:
363 theMenu->addAction( action( CreateCalculationId ) );
365 case KIND_IMMERSIBLE_ZONE:
366 theMenu->addAction( action( CreateImmersibleZoneId ) );
369 theMenu->addAction( action( ImportObstacleFromFileId ) );
370 theMenu->addAction( action( CreateBoxId ) );
371 theMenu->addAction( action( CreateCylinderId ) );
374 theMenu->addSeparator();
378 if( anIsSelectedDataObjects )
380 if ( anIsMustBeUpdatedImage )
382 theMenu->addAction( action( UpdateImageId ) );
383 theMenu->addSeparator();
386 if( aSeq.Length() == 1 )
390 if( anIsImportedImage )
391 theMenu->addAction( action( EditImportedImageId ) );
392 else if( anIsImageHasRefs )
395 theMenu->addAction( action( EditFusedImageId ) );
396 else if( anIsCutImage )
397 theMenu->addAction( action( EditCutImageId ) );
398 else if( anIsSplittedImage )
399 theMenu->addAction( action( EditSplittedImageId ) );
402 theMenu->addAction( action( ObserveImageId ) );
403 theMenu->addAction( action( ExportImageId ) );
404 theMenu->addSeparator();
406 if( anIsImageHasRefs )
408 theMenu->addAction( action( RemoveImageRefsId ) );
409 theMenu->addSeparator();
412 theMenu->addAction( action( FuseImagesId ) );
413 theMenu->addAction( action( CutImagesId ) );
414 theMenu->addAction( action( SplitImageId ) );
415 theMenu->addSeparator();
417 else if( anIsPolyline )
419 theMenu->addAction( action( EditPolylineId ) );
420 theMenu->addSeparator();
422 else if( anIsPolyline3D )
424 theMenu->addAction( action( EditPolyline3DId ) );
425 theMenu->addSeparator();
427 else if( anIsProfile )
429 theMenu->addAction( action( EditProfileId ) );
430 theMenu->addAction( action( SelectedGeoreferencementId ) );
431 theMenu->addSeparator();
433 else if( anIsCalculation )
435 theMenu->addAction( action( EditCalculationId ) );
436 theMenu->addAction( action( ExportCalculationId ) );
437 theMenu->addSeparator();
439 else if( anIsImmersibleZone )
441 theMenu->addAction( action( EditImmersibleZoneId ) );
442 theMenu->addSeparator();
444 else if( anIsStream )
446 theMenu->addAction( action( EditStreamId ) );
447 theMenu->addSeparator();
449 else if( anIsVisualState && anIsObjectBrowser )
451 theMenu->addAction( action( SaveVisualStateId ) );
452 theMenu->addAction( action( LoadVisualStateId ) );
453 theMenu->addSeparator();
456 // Add set color action for geometrical objects
457 if ( anIsGeomObject )
459 theMenu->addAction( action( SetColorId ) );
460 theMenu->addSeparator();
462 } else if ( anAllAreProfiles ) {
463 theMenu->addAction( action( SelectedGeoreferencementId ) );
464 theMenu->addSeparator();
467 theMenu->addAction( action( DeleteId ) );
468 theMenu->addSeparator();
470 if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone ||
471 anIsRegion || anIsBathymetry || anIsObstacle || anIsStream || anIsValidProfile )
473 if( anIsHiddenInSelection )
474 theMenu->addAction( action( ShowId ) );
475 theMenu->addAction( action( ShowOnlyId ) );
476 if( anIsVisibleInSelection )
477 theMenu->addAction( action( HideId ) );
478 theMenu->addSeparator();
484 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
485 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
486 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
487 theMenu->addAction( action( DeleteId ) );
490 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
492 theMenu->addAction( action( ShowAllId ) );
493 theMenu->addAction( action( HideAllId ) );
494 theMenu->addSeparator();
498 void HYDROGUI_Module::update( const int flags )
500 if( !isUpdateEnabled() )
503 QApplication::setOverrideCursor( Qt::WaitCursor );
505 // To prevent calling this method recursively
506 // from one of the methods called below
507 setUpdateEnabled( false );
509 // store selected objects
510 QStringList aSelectedEntries = storeSelection();
512 bool aDoFitAll = flags & UF_FitAll;
513 if( ( flags & UF_Viewer ) )
514 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
516 if( ( flags & UF_OCCViewer ) )
517 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
519 if( ( flags & UF_VTKViewer ) )
520 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
522 if( ( flags & UF_Model ) && getDataModel() && getApp() )
524 getDataModel()->update( getStudyId() );
526 // Temporary workaround to prevent breaking
527 // the selection in the object browser.
528 // Note: processEvents() should be called after updateGV(),
529 // otherwise the application crashes from time to time.
530 //RKV: qApp->processEvents();
531 getApp()->updateObjectBrowser( true );
534 // Object browser is currently updated by using UF_Model flag
535 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
536 getApp()->updateObjectBrowser( true );
538 if( ( flags & UF_Controls ) && getApp() )
539 getApp()->updateActions();
541 // restore selected objects
542 restoreSelection( aSelectedEntries );
544 setUpdateEnabled( true );
546 QApplication::restoreOverrideCursor();
549 void HYDROGUI_Module::updateCommandsStatus()
551 LightApp_Module::updateCommandsStatus();
553 updateUndoRedoControls();
555 action( CopyId )->setEnabled( getDataModel()->canCopy() );
556 action( PasteId )->setEnabled( getDataModel()->canPaste() );
559 void HYDROGUI_Module::selectionChanged()
561 LightApp_Module::selectionChanged();
562 updateCommandsStatus();
565 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
567 return (HYDROGUI_DataModel*)dataModel();
570 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
575 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
577 return myOCCDisplayer;
580 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
582 return myVTKDisplayer;
585 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
587 if( myViewManagerMap.contains( theId ) )
589 return myViewManagerMap[ theId ].first;
594 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
596 if( myViewManagerMap.contains( theId ) )
598 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
599 GraphicsView_ViewManager* aViewManager =
600 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
602 return aViewManager->getViewer();
607 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
609 if( myViewManagerMap.contains( theId ) )
611 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
612 OCCViewer_ViewManager* aViewManager =
613 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
615 return aViewManager->getOCCViewer();
620 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
622 if( myViewManagerMap.contains( theId ) )
624 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
625 SVTK_ViewManager* aViewManager =
626 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
628 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
633 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
635 ViewManagerMapIterator anIter( myViewManagerMap );
636 while( anIter.hasNext() )
638 int anId = anIter.next().key();
639 const ViewManagerInfo& anInfo = anIter.value();
640 if( anInfo.first == theViewManager )
646 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
648 int anId = getViewManagerId( theViewManager );
651 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
652 return anInfo.second;
657 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
658 const ViewManagerRole theRole )
660 int anId = getViewManagerId( theViewManager );
663 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
664 anInfo.second = theRole;
668 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
669 const Handle(HYDROData_Entity)& theObject ) const
671 if( theObject.IsNull() )
674 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
675 if( anIter1 != myObjectStateMap.end() )
677 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
678 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
679 if( anIter2 != aName2ObjectStateMap.end() )
681 const ObjectState& anObjectState = anIter2.value();
682 return anObjectState.Visibility;
688 void HYDROGUI_Module::setObjectVisible( const int theViewId,
689 const Handle(HYDROData_Entity)& theObject,
690 const bool theState )
692 if( !theObject.IsNull() )
694 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
695 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
696 anObjectState.Visibility = theState;
700 /////////////////// OCC SHAPES PROCESSING
701 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
702 const Handle(HYDROData_Entity)& theObject ) const
704 HYDROGUI_Shape* aResShape = NULL;
705 if( theObject.IsNull() )
708 if ( myShapesMap.contains( theViewId ) )
710 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
711 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
713 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
724 void HYDROGUI_Module::setObjectShape( const int theViewId,
725 const Handle(HYDROData_Entity)& theObject,
726 HYDROGUI_Shape* theShape )
728 if( theObject.IsNull() )
731 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
732 aViewShapes.append( theShape );
735 void HYDROGUI_Module::removeObjectShape( const int theViewId,
736 const Handle(HYDROData_Entity)& theObject )
738 if ( !myShapesMap.contains( theViewId ) )
741 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
742 Handle(HYDROData_Entity) anObject;
743 for ( int i = 0; i < aViewShapes.length(); )
745 HYDROGUI_Shape* aShape = aViewShapes.at( i );
746 anObject = aShape->getObject();
747 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
750 aViewShapes.removeAt( i );
758 void HYDROGUI_Module::removeViewShapes( const int theViewId )
760 if ( !myShapesMap.contains( theViewId ) )
763 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
764 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
766 HYDROGUI_Shape* aShape = aViewShapes.at( i );
771 myShapesMap.remove( theViewId );
773 /////////////////// END OF OCC SHAPES PROCESSING
775 /////////////////// VTKPrs PROCESSING
776 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
777 const Handle(HYDROData_Entity)& theObject ) const
779 HYDROGUI_VTKPrs* aResShape = NULL;
780 if( theObject.IsNull() )
783 if ( myVTKPrsMap.contains( theViewId ) )
785 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
786 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
788 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
799 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
800 const Handle(HYDROData_Entity)& theObject,
801 HYDROGUI_VTKPrs* theShape )
803 if( theObject.IsNull() )
806 // Compute the new global Z range from the added presentation and the old global Z range.
807 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
808 double* aRange = theShape->getInternalZRange();
809 bool anIsUpdate = false;
810 if ( aRange[0] < aGlobalRange[0] )
812 aGlobalRange[0] = aRange[0];
815 if ( aRange[1] > aGlobalRange[1] )
817 aGlobalRange[1] = aRange[1];
823 updateVTKZRange( theViewId, aGlobalRange );
826 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
827 aViewShapes.append( theShape );
830 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
831 const Handle(HYDROData_Entity)& theObject )
833 if ( !myVTKPrsMap.contains( theViewId ) )
836 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
837 Handle(HYDROData_Entity) anObject;
838 for ( int i = 0; i < aViewShapes.length(); )
840 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
841 anObject = aShape->getObject();
842 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
845 aViewShapes.removeAt( i );
852 // Invalidate global Z range
853 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
854 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
857 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
859 if ( !myVTKPrsMap.contains( theViewId ) )
862 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
863 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
865 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
870 myVTKPrsMap.remove( theViewId );
873 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
875 if ( myVTKPrsMap.contains( theViewId ) )
877 // For the given viewer id update all VTK presentations ...
878 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
879 HYDROGUI_VTKPrs* aShape;
880 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
882 aShape = aViewShapes.at( i );
885 aShape->setZRange( theRange );
889 // ... and update the global color legend scalar bar.
890 getVTKDisplayer()->SetZRange( theViewId, theRange );
892 /////////////////// END OF VTKPrs PROCESSING
894 CAM_DataModel* HYDROGUI_Module::createDataModel()
896 return new HYDROGUI_DataModel( this );
899 void HYDROGUI_Module::customEvent( QEvent* e )
901 int aType = e->type();
902 if ( aType == NewViewEvent )
904 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
905 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
907 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
909 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
910 ViewManagerRole aRole = getViewManagerRole( aViewManager );
912 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
914 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
915 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
917 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
918 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
919 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
921 //ouv: temporarily commented
922 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
925 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
928 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
934 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
936 QEvent::Type aType = theEvent->type();
937 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
939 if( aType == QEvent::Show )
941 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
942 e->setData( theObj );
943 QApplication::postEvent( this, e );
944 theObj->removeEventFilter( this );
947 return LightApp_Module::eventFilter( theObj, theEvent );
950 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
952 LightApp_Module::onViewManagerAdded( theViewManager );
954 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
956 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
957 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
959 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
961 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
962 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
965 createSelector( theViewManager ); // replace the default selector
967 ViewManagerInfo anInfo( theViewManager, VMR_General );
968 myViewManagerMap.insert( ViewManagerId++, anInfo );
971 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
973 LightApp_Module::onViewManagerRemoved( theViewManager );
975 createSelector( theViewManager ); // replace the default selector
977 int anId = getViewManagerId( theViewManager );
980 OCCViewer_ViewManager* anOCCViewManager =
981 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
982 if ( anOCCViewManager )
984 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
986 removeViewShapes( (size_t)anOCCViewer );
989 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
991 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
994 getVTKDisplayer()->DeleteScalarBar( anId );
995 removeViewShapes( (size_t)aVTKViewer );
999 myViewManagerMap.remove( anId );
1003 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1005 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1007 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1009 aViewFrame->installEventFilter( this );
1011 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1013 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1014 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1017 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1019 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1021 aViewFrame->onTopView();
1023 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1028 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1030 /* ouv: currently unused
1031 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1033 SUIT_ViewManager* aViewManager = 0;
1035 QObject* aParent = aViewPort;
1036 while( aParent = aParent->parent() )
1038 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1040 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1042 aViewManager = aViewer->getViewManager();
1051 double aMouseX = theEvent->scenePos().x();
1052 double aMouseY = theEvent->scenePos().y();
1054 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1055 if( aRole == VMR_General )
1057 int aXDeg = 0, aYDeg = 0;
1058 int aXMin = 0, aYMin = 0;
1059 double aXSec = 0, aYSec = 0;
1060 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1061 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1063 QString aDegSymbol( QChar( 0x00B0 ) );
1064 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1065 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1067 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1069 else if( aRole == VMR_TransformImage )
1070 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1075 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1076 const bool theIsInit,
1077 const bool theIsForced,
1078 const bool theDoFitAll )
1080 QList<int> aViewManagerIdList;
1082 // currently, all views are updated
1083 ViewManagerMapIterator anIter( myViewManagerMap );
1084 while( anIter.hasNext() )
1086 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1088 if ( theDisplayer->IsApplicable( aViewManager ) )
1090 int anId = anIter.key();
1091 aViewManagerIdList.append( anId );
1095 QListIterator<int> anIdIter( aViewManagerIdList );
1096 while( anIdIter.hasNext() )
1098 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1102 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1104 if( !theViewManager )
1107 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1108 if( !aSelectionMgr )
1111 QString aViewType = theViewManager->getType();
1112 if( aViewType != GraphicsView_Viewer::Type() &&
1113 aViewType != OCCViewer_Viewer::Type())
1116 QList<SUIT_Selector*> aSelectorList;
1117 aSelectionMgr->selectors( aViewType, aSelectorList );
1119 // disable all alien selectors
1120 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1121 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1123 SUIT_Selector* aSelector = *anIter;
1124 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1125 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1126 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1127 aSelector->setEnabled( false );
1130 if ( aViewType == GraphicsView_Viewer::Type() )
1132 GraphicsView_ViewManager* aViewManager =
1133 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1135 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1137 else if ( aViewType == OCCViewer_Viewer::Type() )
1139 OCCViewer_ViewManager* aViewManager =
1140 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1142 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1146 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1148 bool aPrevState = myIsUpdateEnabled;
1149 myIsUpdateEnabled = theState;
1153 bool HYDROGUI_Module::isUpdateEnabled() const
1155 return myIsUpdateEnabled;
1158 QStringList HYDROGUI_Module::storeSelection() const
1160 QStringList anEntryList;
1161 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1163 SUIT_DataOwnerPtrList aList( true );
1164 aSelectionMgr->selected( aList );
1166 SUIT_DataOwnerPtrList::iterator anIter;
1167 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1169 const LightApp_DataOwner* anOwner =
1170 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1172 anEntryList.append( anOwner->entry() );
1178 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1180 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1182 SUIT_DataOwnerPtrList aList( true );
1183 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1184 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1185 aSelectionMgr->setSelected( aList );