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"
42 #include "HYDROGUI_SetColorOp.h"
43 #include "HYDROGUI_ImportGeomObjectOp.h"
45 #include <HYDROData_Image.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Lambert93.h>
48 #include <HYDROData_Tool.h>
50 #include <HYDROData_OperationsFactory.h>
52 #include <GraphicsView_ViewFrame.h>
53 #include <GraphicsView_ViewManager.h>
54 #include <GraphicsView_ViewPort.h>
55 #include <GraphicsView_Viewer.h>
57 #include <ImageComposer_CutOperator.h>
58 #include <ImageComposer_CropOperator.h>
59 #include <ImageComposer_FuseOperator.h>
61 #include <LightApp_Application.h>
62 #include <LightApp_DataOwner.h>
63 #include <LightApp_GVSelector.h>
64 #include <LightApp_SelectionMgr.h>
65 #include <LightApp_UpdateFlags.h>
67 #include <OCCViewer_ViewFrame.h>
68 #include <OCCViewer_ViewManager.h>
69 #include <OCCViewer_ViewModel.h>
71 #include <SALOME_Event.h>
73 #include <SUIT_DataBrowser.h>
74 #include <SUIT_Desktop.h>
75 #include <SUIT_Study.h>
76 #include <SUIT_ViewManager.h>
78 #include <SVTK_ViewManager.h>
79 #include <SVTK_ViewModel.h>
80 #include <SVTK_Selector.h>
82 #include <OCCViewer_ViewPort3d.h>
84 #include <GEOMUtils.hxx>
87 #include <QApplication>
88 #include <QGraphicsSceneMouseEvent>
90 #include <QMouseEvent>
93 static int ViewManagerId = 0;
95 extern "C" HYDRO_EXPORT CAM_Module* createModule()
97 return new HYDROGUI_Module();
100 extern "C" HYDRO_EXPORT char* getModuleVersion()
102 return (char*)HYDRO_VERSION;
105 HYDROGUI_Module::HYDROGUI_Module()
106 : LightApp_Module( "HYDRO" ),
109 myIsUpdateEnabled( true )
113 HYDROGUI_Module::~HYDROGUI_Module()
117 int HYDROGUI_Module::getStudyId() const
119 LightApp_Application* anApp = getApp();
120 return anApp ? anApp->activeStudy()->id() : 0;
123 void HYDROGUI_Module::initialize( CAM_Application* theApp )
125 LightApp_Module::initialize( theApp );
128 createUndoRedoActions();
133 setMenuShown( false );
134 setToolShown( false );
136 myDisplayer = new HYDROGUI_Displayer( this );
137 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
138 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
141 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
143 bool aRes = LightApp_Module::activateModule( theStudy );
145 LightApp_Application* anApp = getApp();
146 SUIT_Desktop* aDesktop = anApp->desktop();
148 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
150 setMenuShown( true );
151 setToolShown( true );
153 #ifndef DISABLE_PYCONSOLE
154 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
155 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
158 // Remove defunct view managers from the map.
159 // It's essential to do this before "update( UF_All )" call!
160 QList<int> anObsoleteIds;
161 ViewManagerList anAllViewManagers = anApp->viewManagers();
162 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
163 ViewManagerMapIterator anIter( myViewManagerMap );
164 while( anIter.hasNext() ) {
165 int anId = anIter.next().key();
166 const ViewManagerInfo& anInfo = anIter.value();
168 aHydroViewManagers << anInfo.first;
170 if ( !anAllViewManagers.contains( anInfo.first ) ) {
171 anObsoleteIds << anId;
174 foreach ( const int anId, anObsoleteIds ) {
175 myViewManagerMap.remove( anId );
176 myObjectStateMap.remove( anId );
177 myShapesMap.remove( anId );
178 myVTKPrsMap.remove( anId );
180 // Replace the default selector for all view managers.
181 // Add view managers created outside of HYDRO module to the map.
182 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
183 createSelector( aViewManager ); // replace the default selector
184 if ( !aHydroViewManagers.contains( aViewManager ) ) {
185 ViewManagerInfo anInfo( aViewManager, VMR_General );
186 myViewManagerMap.insert( ViewManagerId++, anInfo );
192 updateCommandsStatus();
194 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
195 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
197 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
199 ViewManagerList anOCCViewManagers;
200 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
201 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
202 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
203 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
204 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
205 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
206 if ( aViewFrame && aViewFrame->getViewPort() ) {
207 aViewFrame->getViewPort()->installEventFilter( this );
215 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
218 ViewManagerMapIterator anIter( myViewManagerMap );
219 while( anIter.hasNext() )
220 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
221 getApp()->removeViewManager( aViewManager );
222 myViewManagerMap.clear();
225 ViewManagerList anOCCViewManagers;
226 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
227 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
228 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
229 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
233 myObjectStateMap.clear();
238 // clear the data model's list of copying objects
239 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
241 setMenuShown( false );
242 setToolShown( false );
244 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
246 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
247 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
249 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
251 return LightApp_Module::deactivateModule( theStudy );
254 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
257 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
258 #ifndef DISABLE_PYCONSOLE
259 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
261 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
264 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
266 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
269 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
273 HYDROGUI_DataModel* aModel = getDataModel();
275 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
276 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
277 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
278 bool anIsVTKView = theClient == SVTK_Viewer::Type();
279 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
282 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
284 bool anIsSelectedDataObjects = false;
285 bool anIsVisibleInSelection = false;
286 bool anIsHiddenInSelection = false;
288 bool anIsImage = false;
289 bool anIsImportedImage = false;
290 bool anIsImageHasRefs = false;
291 bool anIsFusedImage = false;
292 bool anIsCutImage = false;
293 bool anIsSplittedImage = false;
294 bool anIsMustObjectBeUpdated = false;
295 bool anIsPolyline = false;
296 bool anIsPolyline3D = false;
297 bool anIsProfile = false;
298 bool anIsValidProfile = false;
299 bool anAllAreProfiles = false;
300 bool anIsBathymetry = false;
301 bool anIsCalculation = false;
302 bool anIsImmersibleZone = false;
303 bool anIsVisualState = false;
304 bool anIsRegion = false;
305 bool anIsZone = false;
306 bool anIsObstacle = false;
307 bool anIsStream = false;
308 bool anIsChannel = false;
309 bool anIsDigue = false;
310 bool anIsDummyObject3D = false;
311 bool anIsGroup = false;
312 bool anIsObjectCanBeColored = false;
314 // Check the selected GEOM objects (take into account the Object Browser only)
315 if ( anIsObjectBrowser ) {
316 QList<GEOM::shape_type> anObstacleTypes =
317 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
318 QList<GEOM::shape_type> aPolylineTypes =
319 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
321 bool isCanBeImportedAsObstacle =
322 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
323 bool isCanBeImportedAsPolyline =
324 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
326 // Add import as obstacle action
327 if ( isCanBeImportedAsObstacle ) {
328 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
330 // Add import as polyline action
331 if ( isCanBeImportedAsPolyline ) {
332 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
335 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
336 theMenu->addSeparator();
340 // check the selected data model objects
341 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
342 int aNbOfSelectedProfiles = 0;
343 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
345 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
346 if( !anObject.IsNull() )
348 anIsSelectedDataObjects = true;
350 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
351 anIsVisibleInSelection |= aVisibility;
352 anIsHiddenInSelection |= !aVisibility;
354 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
356 anIsMustObjectBeUpdated = true;
359 ObjectKind anObjectKind = anObject->GetKind();
360 if( anObjectKind == KIND_IMAGE )
363 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
364 if( !anImage.IsNull() )
366 anIsImportedImage = anImage->HasLocalPoints();
367 anIsImageHasRefs = anImage->HasReferences();
368 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
370 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
372 QString anOperatorName = anOperator->name();
373 if( anOperatorName == ImageComposer_FuseOperator::Type() )
374 anIsFusedImage = true;
375 else if( anOperatorName == ImageComposer_CutOperator::Type() )
377 else if( anOperatorName == ImageComposer_CropOperator::Type() )
378 anIsSplittedImage = true;
383 else if( anObjectKind == KIND_POLYLINEXY )
385 else if( anObjectKind == KIND_POLYLINE )
386 anIsPolyline3D = true;
387 else if( anObjectKind == KIND_PROFILE )
390 aNbOfSelectedProfiles++;
392 Handle(HYDROData_Profile) aProfile =
393 Handle(HYDROData_Profile)::DownCast( anObject );
394 if( !aProfile.IsNull() && aProfile->IsValid() ) {
395 anIsValidProfile = true;
398 else if( anObjectKind == KIND_CALCULATION )
399 anIsCalculation = true;
400 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
401 anIsImmersibleZone = true;
402 else if( anObjectKind == KIND_VISUAL_STATE )
403 anIsVisualState = true;
404 else if( anObjectKind == KIND_REGION )
406 else if( anObjectKind == KIND_ZONE )
408 else if( anObjectKind == KIND_BATHYMETRY )
409 anIsBathymetry = true;
410 else if( anObjectKind == KIND_OBSTACLE )
412 else if( anObjectKind == KIND_STREAM )
414 else if( anObjectKind == KIND_CHANNEL )
416 else if( anObjectKind == KIND_DIGUE )
418 else if( anObjectKind == KIND_DUMMY_3D )
419 anIsDummyObject3D = true;
420 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
424 if ( !anIsObjectCanBeColored )
425 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
428 // Check if all selected objects are profiles
429 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
430 ( aNbOfSelectedProfiles == aSeq.Length() );
432 // check the selected partitions
433 if( !anIsSelectedDataObjects && anIsObjectBrowser )
435 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
436 if( aSelectedPartition != KIND_UNKNOWN )
438 switch( aSelectedPartition )
441 theMenu->addAction( action( ImportImageId ) );
443 case KIND_BATHYMETRY:
444 theMenu->addAction( action( ImportBathymetryId ) );
446 case KIND_ARTIFICIAL_OBJECT:
447 theMenu->addAction( action( CreateChannelId ) );
448 theMenu->addAction( action( CreateDigueId ) );
450 case KIND_NATURAL_OBJECT:
451 theMenu->addAction( action( CreateImmersibleZoneId ) );
452 theMenu->addAction( action( CreateStreamId ) );
455 theMenu->addAction( action( ImportObstacleFromFileId ) );
456 theMenu->addAction( action( CreateBoxId ) );
457 theMenu->addAction( action( CreateCylinderId ) );
459 case KIND_CALCULATION:
460 theMenu->addAction( action( CreateCalculationId ) );
462 case KIND_POLYLINEXY:
463 theMenu->addAction( action( CreatePolylineId ) );
466 theMenu->addAction( action( CreatePolyline3DId ) );
469 theMenu->addAction( action( CreateProfileId ) );
470 theMenu->addAction( action( ImportProfilesId ) );
471 theMenu->addAction( action( AllGeoreferencementId ) );
473 case KIND_VISUAL_STATE:
474 theMenu->addAction( action( SaveVisualStateId ) );
477 theMenu->addSeparator();
481 if( anIsSelectedDataObjects )
483 if ( anIsMustObjectBeUpdated )
485 theMenu->addAction( action( UpdateObjectId ) );
486 theMenu->addSeparator();
489 if( aSeq.Length() == 1 )
493 if( anIsImportedImage )
494 theMenu->addAction( action( EditImportedImageId ) );
495 else if( anIsImageHasRefs )
498 theMenu->addAction( action( EditFusedImageId ) );
499 else if( anIsCutImage )
500 theMenu->addAction( action( EditCutImageId ) );
501 else if( anIsSplittedImage )
502 theMenu->addAction( action( EditSplittedImageId ) );
505 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
506 theMenu->addAction( action( ExportImageId ) );
507 theMenu->addSeparator();
509 if( anIsImageHasRefs )
511 theMenu->addAction( action( RemoveImageRefsId ) );
512 theMenu->addSeparator();
515 theMenu->addAction( action( FuseImagesId ) );
516 theMenu->addAction( action( CutImagesId ) );
517 theMenu->addAction( action( SplitImageId ) );
518 theMenu->addSeparator();
520 else if( anIsBathymetry )
522 theMenu->addAction( action( EditImportedBathymetryId ) );
523 theMenu->addSeparator();
525 else if( anIsPolyline )
527 theMenu->addAction( action( EditPolylineId ) );
528 theMenu->addSeparator();
530 else if( anIsPolyline3D )
532 theMenu->addAction( action( EditPolyline3DId ) );
533 theMenu->addSeparator();
535 else if( anIsProfile )
537 theMenu->addAction( action( EditProfileId ) );
538 theMenu->addAction( action( SelectedGeoreferencementId ) );
539 theMenu->addSeparator();
541 else if( anIsCalculation )
543 theMenu->addAction( action( EditCalculationId ) );
544 theMenu->addAction( action( ExportCalculationId ) );
545 theMenu->addSeparator();
547 else if( anIsImmersibleZone )
549 theMenu->addAction( action( EditImmersibleZoneId ) );
550 theMenu->addSeparator();
552 else if( anIsStream )
554 theMenu->addAction( action( EditStreamId ) );
555 theMenu->addSeparator();
557 else if( anIsChannel )
559 theMenu->addAction( action( EditChannelId ) );
560 theMenu->addSeparator();
564 theMenu->addAction( action( EditDigueId ) );
565 theMenu->addSeparator();
567 else if( anIsVisualState && anIsObjectBrowser )
569 theMenu->addAction( action( SaveVisualStateId ) );
570 theMenu->addAction( action( LoadVisualStateId ) );
571 theMenu->addSeparator();
574 // Add set color action for geometrical objects
575 if ( anIsObjectCanBeColored )
577 theMenu->addAction( action( SetColorId ) );
578 theMenu->addSeparator();
580 } else if ( anAllAreProfiles ) {
581 theMenu->addAction( action( SelectedGeoreferencementId ) );
582 theMenu->addSeparator();
585 if( !anIsDummyObject3D )
586 theMenu->addAction( action( DeleteId ) );
587 theMenu->addSeparator();
589 if( anIsImage || anIsPolyline || anIsPolyline3D ||
590 anIsImmersibleZone || anIsZone || anIsRegion ||
591 anIsBathymetry || anIsObstacle || anIsStream ||
592 anIsChannel || anIsDigue || anIsDummyObject3D ||
593 anIsValidProfile || anIsGroup )
595 if( anIsHiddenInSelection )
596 theMenu->addAction( action( ShowId ) );
597 theMenu->addAction( action( ShowOnlyId ) );
598 if( anIsVisibleInSelection )
599 theMenu->addAction( action( HideId ) );
600 theMenu->addSeparator();
606 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
607 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
608 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
609 theMenu->addAction( action( DeleteId ) );
612 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
614 theMenu->addAction( action( ShowAllId ) );
615 theMenu->addAction( action( HideAllId ) );
616 theMenu->addSeparator();
620 void HYDROGUI_Module::update( const int flags )
622 if( !isUpdateEnabled() )
625 QApplication::setOverrideCursor( Qt::WaitCursor );
627 // To prevent calling this method recursively
628 // from one of the methods called below
629 setUpdateEnabled( false );
631 // store selected objects
632 QStringList aSelectedEntries = storeSelection();
634 bool aDoFitAll = flags & UF_FitAll;
635 if( ( flags & UF_Viewer ) )
636 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
638 if( ( flags & UF_OCCViewer ) )
639 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
641 if( ( flags & UF_VTKViewer ) )
642 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
644 if( ( flags & UF_Model ) && getDataModel() && getApp() )
646 getDataModel()->update( getStudyId() );
648 // Temporary workaround to prevent breaking
649 // the selection in the object browser.
650 // Note: processEvents() should be called after updateGV(),
651 // otherwise the application crashes from time to time.
652 //RKV: qApp->processEvents();
653 getApp()->updateObjectBrowser( true );
656 // Object browser is currently updated by using UF_Model flag
657 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
658 getApp()->updateObjectBrowser( true );
660 if( ( flags & UF_Controls ) && getApp() )
661 getApp()->updateActions();
663 // restore selected objects
664 restoreSelection( aSelectedEntries );
666 setUpdateEnabled( true );
668 QApplication::restoreOverrideCursor();
671 void HYDROGUI_Module::updateCommandsStatus()
673 LightApp_Module::updateCommandsStatus();
675 updateUndoRedoControls();
677 action( CopyId )->setEnabled( getDataModel()->canCopy() );
678 action( PasteId )->setEnabled( getDataModel()->canPaste() );
681 void HYDROGUI_Module::selectionChanged()
683 LightApp_Module::selectionChanged();
684 updateCommandsStatus();
687 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
689 return (HYDROGUI_DataModel*)dataModel();
692 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
697 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
699 return myOCCDisplayer;
702 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
704 return myVTKDisplayer;
707 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
709 if( myViewManagerMap.contains( theId ) )
711 return myViewManagerMap[ theId ].first;
716 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
718 if( myViewManagerMap.contains( theId ) )
720 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
721 GraphicsView_ViewManager* aViewManager =
722 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
724 return aViewManager->getViewer();
729 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
731 if( myViewManagerMap.contains( theId ) )
733 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
734 OCCViewer_ViewManager* aViewManager =
735 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
737 return aViewManager->getOCCViewer();
742 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
744 if( myViewManagerMap.contains( theId ) )
746 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
747 SVTK_ViewManager* aViewManager =
748 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
750 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
755 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
757 ViewManagerMapIterator anIter( myViewManagerMap );
758 while( anIter.hasNext() )
760 int anId = anIter.next().key();
761 const ViewManagerInfo& anInfo = anIter.value();
762 if( anInfo.first == theViewManager )
768 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
770 int anId = getViewManagerId( theViewManager );
773 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
774 return anInfo.second;
779 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
780 const ViewManagerRole theRole )
782 int anId = getViewManagerId( theViewManager );
785 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
786 anInfo.second = theRole;
790 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
791 const Handle(HYDROData_Entity)& theObject ) const
793 if( theObject.IsNull() )
796 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
797 if( anIter1 != myObjectStateMap.end() )
799 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
800 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
801 if( anIter2 != aName2ObjectStateMap.end() )
803 const ObjectState& anObjectState = anIter2.value();
804 return anObjectState.Visibility;
810 void HYDROGUI_Module::setObjectVisible( const int theViewId,
811 const Handle(HYDROData_Entity)& theObject,
812 const bool theState )
814 if( !theObject.IsNull() )
816 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
817 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
818 anObjectState.Visibility = theState;
822 /////////////////// OCC SHAPES PROCESSING
823 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
824 const Handle(HYDROData_Entity)& theObject ) const
826 HYDROGUI_Shape* aResShape = NULL;
827 if( theObject.IsNull() )
830 if ( myShapesMap.contains( theViewId ) )
832 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
833 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
835 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
846 void HYDROGUI_Module::setObjectShape( const int theViewId,
847 const Handle(HYDROData_Entity)& theObject,
848 HYDROGUI_Shape* theShape )
850 if( theObject.IsNull() )
853 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
854 aViewShapes.append( theShape );
857 void HYDROGUI_Module::removeObjectShape( const int theViewId,
858 const Handle(HYDROData_Entity)& theObject )
860 if ( !myShapesMap.contains( theViewId ) )
863 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
864 Handle(HYDROData_Entity) anObject;
865 for ( int i = 0; i < aViewShapes.length(); )
867 HYDROGUI_Shape* aShape = aViewShapes.at( i );
868 anObject = aShape->getObject();
869 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
872 aViewShapes.removeAt( i );
880 void HYDROGUI_Module::removeViewShapes( const int theViewId )
882 if ( !myShapesMap.contains( theViewId ) )
885 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
886 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
888 HYDROGUI_Shape* aShape = aViewShapes.at( i );
893 myShapesMap.remove( theViewId );
895 /////////////////// END OF OCC SHAPES PROCESSING
897 /////////////////// VTKPrs PROCESSING
898 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
899 const Handle(HYDROData_Entity)& theObject ) const
901 HYDROGUI_VTKPrs* aResShape = NULL;
902 if( theObject.IsNull() )
905 if ( myVTKPrsMap.contains( theViewId ) )
907 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
908 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
910 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
921 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
922 const Handle(HYDROData_Entity)& theObject,
923 HYDROGUI_VTKPrs* theShape )
925 if( theObject.IsNull() )
928 if( theShape && theShape->needScalarBar() )
930 // Compute the new global Z range from the added presentation and the old global Z range.
931 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
932 double* aRange = theShape->getInternalZRange();
933 bool anIsUpdate = false;
934 if ( aRange[0] < aGlobalRange[0] )
936 aGlobalRange[0] = aRange[0];
939 if ( aRange[1] > aGlobalRange[1] )
941 aGlobalRange[1] = aRange[1];
947 updateVTKZRange( theViewId, aGlobalRange );
951 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
952 aViewShapes.append( theShape );
955 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
956 const Handle(HYDROData_Entity)& theObject )
958 if ( !myVTKPrsMap.contains( theViewId ) )
961 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
962 Handle(HYDROData_Entity) anObject;
963 for ( int i = 0; i < aViewShapes.length(); )
965 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
966 anObject = aShape->getObject();
967 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
970 aViewShapes.removeAt( i );
977 // Invalidate global Z range
978 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
979 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
982 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
984 if ( !myVTKPrsMap.contains( theViewId ) )
987 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
988 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
990 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
995 myVTKPrsMap.remove( theViewId );
998 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1000 if ( myVTKPrsMap.contains( theViewId ) )
1002 // For the given viewer id update all VTK presentations ...
1003 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1004 HYDROGUI_VTKPrs* aShape;
1005 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1007 aShape = aViewShapes.at( i );
1008 if ( aShape && aShape->needScalarBar() )
1010 aShape->setZRange( theRange );
1014 // ... and update the global color legend scalar bar.
1015 getVTKDisplayer()->SetZRange( theViewId, theRange );
1017 /////////////////// END OF VTKPrs PROCESSING
1019 CAM_DataModel* HYDROGUI_Module::createDataModel()
1021 return new HYDROGUI_DataModel( this );
1024 void HYDROGUI_Module::customEvent( QEvent* e )
1026 int aType = e->type();
1027 if ( aType == NewViewEvent )
1029 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1030 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1032 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1034 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1035 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1037 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1039 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1040 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1042 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1043 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1044 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1046 //ouv: temporarily commented
1047 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1050 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1051 update( UF_Viewer );
1053 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1059 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1061 QEvent::Type aType = theEvent->type();
1062 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1064 if( aType == QEvent::Show )
1066 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1067 e->setData( theObj );
1068 QApplication::postEvent( this, e );
1069 theObj->removeEventFilter( this );
1072 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1074 if( aType == QEvent::Leave )
1076 SUIT_Desktop* aDesktop = getApp()->desktop();
1077 if ( aDesktop && aDesktop->statusBar() ) {
1078 aDesktop->statusBar()->clearMessage();
1083 return LightApp_Module::eventFilter( theObj, theEvent );
1086 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1088 LightApp_Module::onViewManagerAdded( theViewManager );
1090 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1092 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1093 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1095 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1097 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1098 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1099 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1100 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1103 createSelector( theViewManager ); // replace the default selector
1105 ViewManagerInfo anInfo( theViewManager, VMR_General );
1106 myViewManagerMap.insert( ViewManagerId++, anInfo );
1109 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1111 LightApp_Module::onViewManagerRemoved( theViewManager );
1113 createSelector( theViewManager ); // replace the default selector
1115 int anId = getViewManagerId( theViewManager );
1118 OCCViewer_ViewManager* anOCCViewManager =
1119 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1120 if ( anOCCViewManager )
1122 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1124 removeViewShapes( (size_t)anOCCViewer );
1127 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1129 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1132 getVTKDisplayer()->EraseScalarBar( anId, true );
1133 removeViewShapes( (size_t)aVTKViewer );
1137 myViewManagerMap.remove( anId );
1141 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1143 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1145 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1147 aViewFrame->installEventFilter( this );
1149 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1151 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1152 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1155 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1157 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1159 aViewFrame->onTopView();
1161 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1163 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1165 aViewPort->installEventFilter( this );
1171 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1173 /* ouv: currently unused
1174 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1176 SUIT_ViewManager* aViewManager = 0;
1178 QObject* aParent = aViewPort;
1179 while( aParent = aParent->parent() )
1181 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1183 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1185 aViewManager = aViewer->getViewManager();
1194 double aMouseX = theEvent->scenePos().x();
1195 double aMouseY = theEvent->scenePos().y();
1197 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1198 if( aRole == VMR_General )
1200 int aXDeg = 0, aYDeg = 0;
1201 int aXMin = 0, aYMin = 0;
1202 double aXSec = 0, aYSec = 0;
1203 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1204 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1206 QString aDegSymbol( QChar( 0x00B0 ) );
1207 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1208 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1210 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1212 else if( aRole == VMR_TransformImage )
1213 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1218 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1219 const bool theIsInit,
1220 const bool theIsForced,
1221 const bool theDoFitAll )
1223 QList<int> aViewManagerIdList;
1225 // currently, all views are updated
1226 ViewManagerMapIterator anIter( myViewManagerMap );
1227 while( anIter.hasNext() )
1229 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1231 if ( theDisplayer->IsApplicable( aViewManager ) )
1233 int anId = anIter.key();
1234 aViewManagerIdList.append( anId );
1238 QListIterator<int> anIdIter( aViewManagerIdList );
1239 while( anIdIter.hasNext() )
1241 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1245 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1247 if( !theViewManager )
1250 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1251 if( !aSelectionMgr )
1254 QString aViewType = theViewManager->getType();
1255 if( aViewType != GraphicsView_Viewer::Type() &&
1256 aViewType != OCCViewer_Viewer::Type())
1259 QList<SUIT_Selector*> aSelectorList;
1260 aSelectionMgr->selectors( aViewType, aSelectorList );
1262 // disable all alien selectors
1263 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1264 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1266 SUIT_Selector* aSelector = *anIter;
1267 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1268 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1269 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1270 aSelector->setEnabled( false );
1273 if ( aViewType == GraphicsView_Viewer::Type() )
1275 GraphicsView_ViewManager* aViewManager =
1276 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1278 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1280 else if ( aViewType == OCCViewer_Viewer::Type() )
1282 OCCViewer_ViewManager* aViewManager =
1283 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1285 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1289 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1291 bool aPrevState = myIsUpdateEnabled;
1292 myIsUpdateEnabled = theState;
1296 bool HYDROGUI_Module::isUpdateEnabled() const
1298 return myIsUpdateEnabled;
1301 QStringList HYDROGUI_Module::storeSelection() const
1303 QStringList anEntryList;
1304 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1306 SUIT_DataOwnerPtrList aList( true );
1307 aSelectionMgr->selected( aList );
1309 SUIT_DataOwnerPtrList::iterator anIter;
1310 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1312 const LightApp_DataOwner* anOwner =
1313 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1315 anEntryList.append( anOwner->entry() );
1321 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1323 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1325 SUIT_DataOwnerPtrList aList( true );
1326 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1327 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1328 aSelectionMgr->setSelected( aList );
1332 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1334 OCCViewer_ViewWindow* anOCCViewWindow =
1335 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1336 if ( !anOCCViewWindow ) {
1340 // Get the selected point coordinates
1341 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1346 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1347 aViewPort->getView() );
1349 // Show the coordinates in the status bar
1350 SUIT_Desktop* aDesktop = getApp()->desktop();
1351 if ( aDesktop && aDesktop->statusBar() ) {
1352 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1353 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1354 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );