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 anIsObjectCanBeColored = false;
313 // Check the selected GEOM objects (take into account the Object Browser only)
314 if ( anIsObjectBrowser ) {
315 QList<GEOM::shape_type> anObstacleTypes =
316 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
317 QList<GEOM::shape_type> aPolylineTypes =
318 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
320 bool isCanBeImportedAsObstacle =
321 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
322 bool isCanBeImportedAsPolyline =
323 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
325 // Add import as obstacle action
326 if ( isCanBeImportedAsObstacle ) {
327 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
329 // Add import as polyline action
330 if ( isCanBeImportedAsPolyline ) {
331 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
334 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
335 theMenu->addSeparator();
339 // check the selected data model objects
340 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
341 int aNbOfSelectedProfiles = 0;
342 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
344 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
345 if( !anObject.IsNull() )
347 anIsSelectedDataObjects = true;
349 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
350 anIsVisibleInSelection |= aVisibility;
351 anIsHiddenInSelection |= !aVisibility;
353 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
355 anIsMustObjectBeUpdated = true;
358 ObjectKind anObjectKind = anObject->GetKind();
359 if( anObjectKind == KIND_IMAGE )
362 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
363 if( !anImage.IsNull() )
365 anIsImportedImage = anImage->HasLocalPoints();
366 anIsImageHasRefs = anImage->HasReferences();
367 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
369 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
371 QString anOperatorName = anOperator->name();
372 if( anOperatorName == ImageComposer_FuseOperator::Type() )
373 anIsFusedImage = true;
374 else if( anOperatorName == ImageComposer_CutOperator::Type() )
376 else if( anOperatorName == ImageComposer_CropOperator::Type() )
377 anIsSplittedImage = true;
382 else if( anObjectKind == KIND_POLYLINEXY )
384 else if( anObjectKind == KIND_POLYLINE )
385 anIsPolyline3D = true;
386 else if( anObjectKind == KIND_PROFILE )
389 aNbOfSelectedProfiles++;
391 Handle(HYDROData_Profile) aProfile =
392 Handle(HYDROData_Profile)::DownCast( anObject );
393 if( !aProfile.IsNull() && aProfile->IsValid() ) {
394 anIsValidProfile = true;
397 else if( anObjectKind == KIND_CALCULATION )
398 anIsCalculation = true;
399 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
400 anIsImmersibleZone = true;
401 else if( anObjectKind == KIND_VISUAL_STATE )
402 anIsVisualState = true;
403 else if( anObjectKind == KIND_REGION )
405 else if( anObjectKind == KIND_ZONE )
407 else if( anObjectKind == KIND_BATHYMETRY )
408 anIsBathymetry = true;
409 else if( anObjectKind == KIND_OBSTACLE )
411 else if( anObjectKind == KIND_STREAM )
413 else if( anObjectKind == KIND_CHANNEL )
415 else if( anObjectKind == KIND_DIGUE )
417 else if( anObjectKind == KIND_DUMMY_3D )
418 anIsDummyObject3D = true;
421 if ( !anIsObjectCanBeColored )
422 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
425 // Check if all selected objects are profiles
426 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
427 ( aNbOfSelectedProfiles == aSeq.Length() );
429 // check the selected partitions
430 if( !anIsSelectedDataObjects && anIsObjectBrowser )
432 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
433 if( aSelectedPartition != KIND_UNKNOWN )
435 switch( aSelectedPartition )
438 theMenu->addAction( action( ImportImageId ) );
440 case KIND_BATHYMETRY:
441 theMenu->addAction( action( ImportBathymetryId ) );
443 case KIND_ARTIFICIAL_OBJECT:
444 theMenu->addAction( action( CreateChannelId ) );
445 theMenu->addAction( action( CreateDigueId ) );
447 case KIND_NATURAL_OBJECT:
448 theMenu->addAction( action( CreateImmersibleZoneId ) );
449 theMenu->addAction( action( CreateStreamId ) );
452 theMenu->addAction( action( ImportObstacleFromFileId ) );
453 theMenu->addAction( action( CreateBoxId ) );
454 theMenu->addAction( action( CreateCylinderId ) );
456 case KIND_CALCULATION:
457 theMenu->addAction( action( CreateCalculationId ) );
459 case KIND_POLYLINEXY:
460 theMenu->addAction( action( CreatePolylineId ) );
463 theMenu->addAction( action( CreatePolyline3DId ) );
466 theMenu->addAction( action( CreateProfileId ) );
467 theMenu->addAction( action( ImportProfilesId ) );
468 theMenu->addAction( action( AllGeoreferencementId ) );
470 case KIND_VISUAL_STATE:
471 theMenu->addAction( action( SaveVisualStateId ) );
474 theMenu->addSeparator();
478 if( anIsSelectedDataObjects )
480 if ( anIsMustObjectBeUpdated )
482 theMenu->addAction( action( UpdateObjectId ) );
483 theMenu->addSeparator();
486 if( aSeq.Length() == 1 )
490 if( anIsImportedImage )
491 theMenu->addAction( action( EditImportedImageId ) );
492 else if( anIsImageHasRefs )
495 theMenu->addAction( action( EditFusedImageId ) );
496 else if( anIsCutImage )
497 theMenu->addAction( action( EditCutImageId ) );
498 else if( anIsSplittedImage )
499 theMenu->addAction( action( EditSplittedImageId ) );
502 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
503 theMenu->addAction( action( ExportImageId ) );
504 theMenu->addSeparator();
506 if( anIsImageHasRefs )
508 theMenu->addAction( action( RemoveImageRefsId ) );
509 theMenu->addSeparator();
512 theMenu->addAction( action( FuseImagesId ) );
513 theMenu->addAction( action( CutImagesId ) );
514 theMenu->addAction( action( SplitImageId ) );
515 theMenu->addSeparator();
517 else if( anIsBathymetry )
519 theMenu->addAction( action( EditImportedBathymetryId ) );
520 theMenu->addSeparator();
522 else if( anIsPolyline )
524 theMenu->addAction( action( EditPolylineId ) );
525 theMenu->addSeparator();
527 else if( anIsPolyline3D )
529 theMenu->addAction( action( EditPolyline3DId ) );
530 theMenu->addSeparator();
532 else if( anIsProfile )
534 theMenu->addAction( action( EditProfileId ) );
535 theMenu->addAction( action( SelectedGeoreferencementId ) );
536 theMenu->addSeparator();
538 else if( anIsCalculation )
540 theMenu->addAction( action( EditCalculationId ) );
541 theMenu->addAction( action( ExportCalculationId ) );
542 theMenu->addSeparator();
544 else if( anIsImmersibleZone )
546 theMenu->addAction( action( EditImmersibleZoneId ) );
547 theMenu->addSeparator();
549 else if( anIsStream )
551 theMenu->addAction( action( EditStreamId ) );
552 theMenu->addSeparator();
554 else if( anIsChannel )
556 theMenu->addAction( action( EditChannelId ) );
557 theMenu->addSeparator();
561 theMenu->addAction( action( EditDigueId ) );
562 theMenu->addSeparator();
564 else if( anIsVisualState && anIsObjectBrowser )
566 theMenu->addAction( action( SaveVisualStateId ) );
567 theMenu->addAction( action( LoadVisualStateId ) );
568 theMenu->addSeparator();
571 // Add set color action for geometrical objects
572 if ( anIsObjectCanBeColored )
574 theMenu->addAction( action( SetColorId ) );
575 theMenu->addSeparator();
577 } else if ( anAllAreProfiles ) {
578 theMenu->addAction( action( SelectedGeoreferencementId ) );
579 theMenu->addSeparator();
582 if( !anIsDummyObject3D )
583 theMenu->addAction( action( DeleteId ) );
584 theMenu->addSeparator();
586 if( anIsImage || anIsPolyline || anIsPolyline3D ||
587 anIsImmersibleZone || anIsZone || anIsRegion ||
588 anIsBathymetry || anIsObstacle || anIsStream ||
589 anIsChannel || anIsDigue || anIsDummyObject3D ||
592 if( anIsHiddenInSelection )
593 theMenu->addAction( action( ShowId ) );
594 theMenu->addAction( action( ShowOnlyId ) );
595 if( anIsVisibleInSelection )
596 theMenu->addAction( action( HideId ) );
597 theMenu->addSeparator();
603 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
604 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
605 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
606 theMenu->addAction( action( DeleteId ) );
609 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
611 theMenu->addAction( action( ShowAllId ) );
612 theMenu->addAction( action( HideAllId ) );
613 theMenu->addSeparator();
617 void HYDROGUI_Module::update( const int flags )
619 if( !isUpdateEnabled() )
622 QApplication::setOverrideCursor( Qt::WaitCursor );
624 // To prevent calling this method recursively
625 // from one of the methods called below
626 setUpdateEnabled( false );
628 // store selected objects
629 QStringList aSelectedEntries = storeSelection();
631 bool aDoFitAll = flags & UF_FitAll;
632 if( ( flags & UF_Viewer ) )
633 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
635 if( ( flags & UF_OCCViewer ) )
636 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
638 if( ( flags & UF_VTKViewer ) )
639 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
641 if( ( flags & UF_Model ) && getDataModel() && getApp() )
643 getDataModel()->update( getStudyId() );
645 // Temporary workaround to prevent breaking
646 // the selection in the object browser.
647 // Note: processEvents() should be called after updateGV(),
648 // otherwise the application crashes from time to time.
649 //RKV: qApp->processEvents();
650 getApp()->updateObjectBrowser( true );
653 // Object browser is currently updated by using UF_Model flag
654 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
655 getApp()->updateObjectBrowser( true );
657 if( ( flags & UF_Controls ) && getApp() )
658 getApp()->updateActions();
660 // restore selected objects
661 restoreSelection( aSelectedEntries );
663 setUpdateEnabled( true );
665 QApplication::restoreOverrideCursor();
668 void HYDROGUI_Module::updateCommandsStatus()
670 LightApp_Module::updateCommandsStatus();
672 updateUndoRedoControls();
674 action( CopyId )->setEnabled( getDataModel()->canCopy() );
675 action( PasteId )->setEnabled( getDataModel()->canPaste() );
678 void HYDROGUI_Module::selectionChanged()
680 LightApp_Module::selectionChanged();
681 updateCommandsStatus();
684 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
686 return (HYDROGUI_DataModel*)dataModel();
689 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
694 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
696 return myOCCDisplayer;
699 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
701 return myVTKDisplayer;
704 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
706 if( myViewManagerMap.contains( theId ) )
708 return myViewManagerMap[ theId ].first;
713 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
715 if( myViewManagerMap.contains( theId ) )
717 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
718 GraphicsView_ViewManager* aViewManager =
719 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
721 return aViewManager->getViewer();
726 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
728 if( myViewManagerMap.contains( theId ) )
730 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
731 OCCViewer_ViewManager* aViewManager =
732 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
734 return aViewManager->getOCCViewer();
739 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
741 if( myViewManagerMap.contains( theId ) )
743 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
744 SVTK_ViewManager* aViewManager =
745 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
747 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
752 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
754 ViewManagerMapIterator anIter( myViewManagerMap );
755 while( anIter.hasNext() )
757 int anId = anIter.next().key();
758 const ViewManagerInfo& anInfo = anIter.value();
759 if( anInfo.first == theViewManager )
765 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
767 int anId = getViewManagerId( theViewManager );
770 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
771 return anInfo.second;
776 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
777 const ViewManagerRole theRole )
779 int anId = getViewManagerId( theViewManager );
782 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
783 anInfo.second = theRole;
787 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
788 const Handle(HYDROData_Entity)& theObject ) const
790 if( theObject.IsNull() )
793 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
794 if( anIter1 != myObjectStateMap.end() )
796 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
797 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
798 if( anIter2 != aName2ObjectStateMap.end() )
800 const ObjectState& anObjectState = anIter2.value();
801 return anObjectState.Visibility;
807 void HYDROGUI_Module::setObjectVisible( const int theViewId,
808 const Handle(HYDROData_Entity)& theObject,
809 const bool theState )
811 if( !theObject.IsNull() )
813 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
814 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
815 anObjectState.Visibility = theState;
819 /////////////////// OCC SHAPES PROCESSING
820 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
821 const Handle(HYDROData_Entity)& theObject ) const
823 HYDROGUI_Shape* aResShape = NULL;
824 if( theObject.IsNull() )
827 if ( myShapesMap.contains( theViewId ) )
829 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
830 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
832 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
843 void HYDROGUI_Module::setObjectShape( const int theViewId,
844 const Handle(HYDROData_Entity)& theObject,
845 HYDROGUI_Shape* theShape )
847 if( theObject.IsNull() )
850 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
851 aViewShapes.append( theShape );
854 void HYDROGUI_Module::removeObjectShape( const int theViewId,
855 const Handle(HYDROData_Entity)& theObject )
857 if ( !myShapesMap.contains( theViewId ) )
860 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
861 Handle(HYDROData_Entity) anObject;
862 for ( int i = 0; i < aViewShapes.length(); )
864 HYDROGUI_Shape* aShape = aViewShapes.at( i );
865 anObject = aShape->getObject();
866 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
869 aViewShapes.removeAt( i );
877 void HYDROGUI_Module::removeViewShapes( const int theViewId )
879 if ( !myShapesMap.contains( theViewId ) )
882 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
883 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
885 HYDROGUI_Shape* aShape = aViewShapes.at( i );
890 myShapesMap.remove( theViewId );
892 /////////////////// END OF OCC SHAPES PROCESSING
894 /////////////////// VTKPrs PROCESSING
895 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
896 const Handle(HYDROData_Entity)& theObject ) const
898 HYDROGUI_VTKPrs* aResShape = NULL;
899 if( theObject.IsNull() )
902 if ( myVTKPrsMap.contains( theViewId ) )
904 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
905 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
907 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
918 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
919 const Handle(HYDROData_Entity)& theObject,
920 HYDROGUI_VTKPrs* theShape )
922 if( theObject.IsNull() )
925 if( theShape && theShape->needScalarBar() )
927 // Compute the new global Z range from the added presentation and the old global Z range.
928 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
929 double* aRange = theShape->getInternalZRange();
930 bool anIsUpdate = false;
931 if ( aRange[0] < aGlobalRange[0] )
933 aGlobalRange[0] = aRange[0];
936 if ( aRange[1] > aGlobalRange[1] )
938 aGlobalRange[1] = aRange[1];
944 updateVTKZRange( theViewId, aGlobalRange );
948 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
949 aViewShapes.append( theShape );
952 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
953 const Handle(HYDROData_Entity)& theObject )
955 if ( !myVTKPrsMap.contains( theViewId ) )
958 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
959 Handle(HYDROData_Entity) anObject;
960 for ( int i = 0; i < aViewShapes.length(); )
962 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
963 anObject = aShape->getObject();
964 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
967 aViewShapes.removeAt( i );
974 // Invalidate global Z range
975 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
976 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
979 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
981 if ( !myVTKPrsMap.contains( theViewId ) )
984 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
985 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
987 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
992 myVTKPrsMap.remove( theViewId );
995 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
997 if ( myVTKPrsMap.contains( theViewId ) )
999 // For the given viewer id update all VTK presentations ...
1000 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1001 HYDROGUI_VTKPrs* aShape;
1002 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1004 aShape = aViewShapes.at( i );
1005 if ( aShape && aShape->needScalarBar() )
1007 aShape->setZRange( theRange );
1011 // ... and update the global color legend scalar bar.
1012 getVTKDisplayer()->SetZRange( theViewId, theRange );
1014 /////////////////// END OF VTKPrs PROCESSING
1016 CAM_DataModel* HYDROGUI_Module::createDataModel()
1018 return new HYDROGUI_DataModel( this );
1021 void HYDROGUI_Module::customEvent( QEvent* e )
1023 int aType = e->type();
1024 if ( aType == NewViewEvent )
1026 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1027 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1029 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1031 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1032 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1034 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1036 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1037 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1039 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1040 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1041 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1043 //ouv: temporarily commented
1044 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1047 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1048 update( UF_Viewer );
1050 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1056 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1058 QEvent::Type aType = theEvent->type();
1059 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1061 if( aType == QEvent::Show )
1063 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1064 e->setData( theObj );
1065 QApplication::postEvent( this, e );
1066 theObj->removeEventFilter( this );
1069 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1071 if( aType == QEvent::Leave )
1073 SUIT_Desktop* aDesktop = getApp()->desktop();
1074 if ( aDesktop && aDesktop->statusBar() ) {
1075 aDesktop->statusBar()->clearMessage();
1080 return LightApp_Module::eventFilter( theObj, theEvent );
1083 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1085 LightApp_Module::onViewManagerAdded( theViewManager );
1087 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1089 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1090 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1092 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1094 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1095 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1096 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1097 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1100 createSelector( theViewManager ); // replace the default selector
1102 ViewManagerInfo anInfo( theViewManager, VMR_General );
1103 myViewManagerMap.insert( ViewManagerId++, anInfo );
1106 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1108 LightApp_Module::onViewManagerRemoved( theViewManager );
1110 createSelector( theViewManager ); // replace the default selector
1112 int anId = getViewManagerId( theViewManager );
1115 OCCViewer_ViewManager* anOCCViewManager =
1116 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1117 if ( anOCCViewManager )
1119 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1121 removeViewShapes( (size_t)anOCCViewer );
1124 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1126 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1129 getVTKDisplayer()->EraseScalarBar( anId, true );
1130 removeViewShapes( (size_t)aVTKViewer );
1134 myViewManagerMap.remove( anId );
1138 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1140 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1142 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1144 aViewFrame->installEventFilter( this );
1146 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1148 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1149 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1152 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1154 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1156 aViewFrame->onTopView();
1158 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1160 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1162 aViewPort->installEventFilter( this );
1168 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1170 /* ouv: currently unused
1171 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1173 SUIT_ViewManager* aViewManager = 0;
1175 QObject* aParent = aViewPort;
1176 while( aParent = aParent->parent() )
1178 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1180 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1182 aViewManager = aViewer->getViewManager();
1191 double aMouseX = theEvent->scenePos().x();
1192 double aMouseY = theEvent->scenePos().y();
1194 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1195 if( aRole == VMR_General )
1197 int aXDeg = 0, aYDeg = 0;
1198 int aXMin = 0, aYMin = 0;
1199 double aXSec = 0, aYSec = 0;
1200 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1201 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1203 QString aDegSymbol( QChar( 0x00B0 ) );
1204 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1205 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1207 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1209 else if( aRole == VMR_TransformImage )
1210 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1215 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1216 const bool theIsInit,
1217 const bool theIsForced,
1218 const bool theDoFitAll )
1220 QList<int> aViewManagerIdList;
1222 // currently, all views are updated
1223 ViewManagerMapIterator anIter( myViewManagerMap );
1224 while( anIter.hasNext() )
1226 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1228 if ( theDisplayer->IsApplicable( aViewManager ) )
1230 int anId = anIter.key();
1231 aViewManagerIdList.append( anId );
1235 QListIterator<int> anIdIter( aViewManagerIdList );
1236 while( anIdIter.hasNext() )
1238 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1242 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1244 if( !theViewManager )
1247 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1248 if( !aSelectionMgr )
1251 QString aViewType = theViewManager->getType();
1252 if( aViewType != GraphicsView_Viewer::Type() &&
1253 aViewType != OCCViewer_Viewer::Type())
1256 QList<SUIT_Selector*> aSelectorList;
1257 aSelectionMgr->selectors( aViewType, aSelectorList );
1259 // disable all alien selectors
1260 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1261 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1263 SUIT_Selector* aSelector = *anIter;
1264 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1265 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1266 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1267 aSelector->setEnabled( false );
1270 if ( aViewType == GraphicsView_Viewer::Type() )
1272 GraphicsView_ViewManager* aViewManager =
1273 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1275 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1277 else if ( aViewType == OCCViewer_Viewer::Type() )
1279 OCCViewer_ViewManager* aViewManager =
1280 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1282 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1286 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1288 bool aPrevState = myIsUpdateEnabled;
1289 myIsUpdateEnabled = theState;
1293 bool HYDROGUI_Module::isUpdateEnabled() const
1295 return myIsUpdateEnabled;
1298 QStringList HYDROGUI_Module::storeSelection() const
1300 QStringList anEntryList;
1301 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1303 SUIT_DataOwnerPtrList aList( true );
1304 aSelectionMgr->selected( aList );
1306 SUIT_DataOwnerPtrList::iterator anIter;
1307 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1309 const LightApp_DataOwner* anOwner =
1310 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1312 anEntryList.append( anOwner->entry() );
1318 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1320 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1322 SUIT_DataOwnerPtrList aList( true );
1323 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1324 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1325 aSelectionMgr->setSelected( aList );
1329 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1331 OCCViewer_ViewWindow* anOCCViewWindow =
1332 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1333 if ( !anOCCViewWindow ) {
1337 // Get the selected point coordinates
1338 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1343 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1344 aViewPort->getView() );
1346 // Show the coordinates in the status bar
1347 SUIT_Desktop* aDesktop = getApp()->desktop();
1348 if ( aDesktop && aDesktop->statusBar() ) {
1349 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1350 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1351 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );