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 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
196 ViewManagerList anOCCViewManagers;
197 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
198 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
199 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
200 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
201 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
202 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
203 if ( aViewFrame && aViewFrame->getViewPort() ) {
204 aViewFrame->getViewPort()->installEventFilter( this );
212 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
215 ViewManagerMapIterator anIter( myViewManagerMap );
216 while( anIter.hasNext() )
217 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
218 getApp()->removeViewManager( aViewManager );
219 myViewManagerMap.clear();
222 ViewManagerList anOCCViewManagers;
223 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
224 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
225 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
226 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
230 myObjectStateMap.clear();
235 // clear the data model's list of copying objects
236 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
238 setMenuShown( false );
239 setToolShown( false );
241 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
243 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
245 return LightApp_Module::deactivateModule( theStudy );
248 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
251 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
252 #ifndef DISABLE_PYCONSOLE
253 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
255 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
258 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
260 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
263 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
267 HYDROGUI_DataModel* aModel = getDataModel();
269 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
270 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
271 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
272 bool anIsVTKView = theClient == SVTK_Viewer::Type();
273 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
276 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
278 bool anIsSelectedDataObjects = false;
279 bool anIsVisibleInSelection = false;
280 bool anIsHiddenInSelection = false;
282 bool anIsImage = false;
283 bool anIsImportedImage = false;
284 bool anIsImageHasRefs = false;
285 bool anIsFusedImage = false;
286 bool anIsCutImage = false;
287 bool anIsSplittedImage = false;
288 bool anIsMustObjectBeUpdated = false;
289 bool anIsPolyline = false;
290 bool anIsPolyline3D = false;
291 bool anIsProfile = false;
292 bool anIsValidProfile = false;
293 bool anAllAreProfiles = false;
294 bool anIsBathymetry = false;
295 bool anIsCalculation = false;
296 bool anIsImmersibleZone = false;
297 bool anIsVisualState = false;
298 bool anIsRegion = false;
299 bool anIsZone = false;
300 bool anIsObstacle = false;
301 bool anIsStream = false;
302 bool anIsChannel = false;
303 bool anIsDigue = false;
304 bool anIsDummyObject3D = false;
305 bool anIsGroup = false;
306 bool anIsObjectCanBeColored = false;
308 // Check the selected GEOM objects (take into account the Object Browser only)
309 if ( anIsObjectBrowser ) {
310 QList<GEOM::shape_type> anObstacleTypes =
311 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
312 QList<GEOM::shape_type> aPolylineTypes =
313 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
315 bool isCanBeImportedAsObstacle =
316 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
317 bool isCanBeImportedAsPolyline =
318 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
320 // Add import as obstacle action
321 if ( isCanBeImportedAsObstacle ) {
322 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
324 // Add import as polyline action
325 if ( isCanBeImportedAsPolyline ) {
326 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
329 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
330 theMenu->addSeparator();
334 // check the selected data model objects
335 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
336 int aNbOfSelectedProfiles = 0;
337 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
339 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
340 if( !anObject.IsNull() )
342 anIsSelectedDataObjects = true;
344 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
345 anIsVisibleInSelection |= aVisibility;
346 anIsHiddenInSelection |= !aVisibility;
348 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
350 anIsMustObjectBeUpdated = true;
353 ObjectKind anObjectKind = anObject->GetKind();
354 if( anObjectKind == KIND_IMAGE )
357 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
358 if( !anImage.IsNull() )
360 anIsImportedImage = anImage->HasLocalPoints();
361 anIsImageHasRefs = anImage->HasReferences();
362 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
364 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
366 QString anOperatorName = anOperator->name();
367 if( anOperatorName == ImageComposer_FuseOperator::Type() )
368 anIsFusedImage = true;
369 else if( anOperatorName == ImageComposer_CutOperator::Type() )
371 else if( anOperatorName == ImageComposer_CropOperator::Type() )
372 anIsSplittedImage = true;
377 else if( anObjectKind == KIND_POLYLINEXY )
379 else if( anObjectKind == KIND_POLYLINE )
380 anIsPolyline3D = true;
381 else if( anObjectKind == KIND_PROFILE )
384 aNbOfSelectedProfiles++;
386 Handle(HYDROData_Profile) aProfile =
387 Handle(HYDROData_Profile)::DownCast( anObject );
388 if( !aProfile.IsNull() && aProfile->IsValid() ) {
389 anIsValidProfile = true;
392 else if( anObjectKind == KIND_CALCULATION )
393 anIsCalculation = true;
394 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
395 anIsImmersibleZone = true;
396 else if( anObjectKind == KIND_VISUAL_STATE )
397 anIsVisualState = true;
398 else if( anObjectKind == KIND_REGION )
400 else if( anObjectKind == KIND_ZONE )
402 else if( anObjectKind == KIND_BATHYMETRY )
403 anIsBathymetry = true;
404 else if( anObjectKind == KIND_OBSTACLE )
406 else if( anObjectKind == KIND_STREAM )
408 else if( anObjectKind == KIND_CHANNEL )
410 else if( anObjectKind == KIND_DIGUE )
412 else if( anObjectKind == KIND_DUMMY_3D )
413 anIsDummyObject3D = true;
414 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
418 if ( !anIsObjectCanBeColored )
419 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
422 // Check if all selected objects are profiles
423 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
424 ( aNbOfSelectedProfiles == aSeq.Length() );
426 // check the selected partitions
427 if( !anIsSelectedDataObjects && anIsObjectBrowser )
429 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
430 if( aSelectedPartition != KIND_UNKNOWN )
432 switch( aSelectedPartition )
435 theMenu->addAction( action( ImportImageId ) );
437 case KIND_BATHYMETRY:
438 theMenu->addAction( action( ImportBathymetryId ) );
440 case KIND_ARTIFICIAL_OBJECT:
441 theMenu->addAction( action( CreateChannelId ) );
442 theMenu->addAction( action( CreateDigueId ) );
444 case KIND_NATURAL_OBJECT:
445 theMenu->addAction( action( CreateImmersibleZoneId ) );
446 theMenu->addAction( action( CreateStreamId ) );
449 theMenu->addAction( action( ImportObstacleFromFileId ) );
450 theMenu->addAction( action( CreateBoxId ) );
451 theMenu->addAction( action( CreateCylinderId ) );
453 case KIND_CALCULATION:
454 theMenu->addAction( action( CreateCalculationId ) );
456 case KIND_POLYLINEXY:
457 theMenu->addAction( action( CreatePolylineId ) );
460 theMenu->addAction( action( CreatePolyline3DId ) );
463 theMenu->addAction( action( CreateProfileId ) );
464 theMenu->addAction( action( ImportProfilesId ) );
465 theMenu->addAction( action( AllGeoreferencementId ) );
467 case KIND_VISUAL_STATE:
468 theMenu->addAction( action( SaveVisualStateId ) );
471 theMenu->addSeparator();
475 if( anIsSelectedDataObjects )
477 if ( anIsMustObjectBeUpdated )
479 theMenu->addAction( action( UpdateObjectId ) );
480 theMenu->addSeparator();
483 if( aSeq.Length() == 1 )
487 if( anIsImportedImage )
488 theMenu->addAction( action( EditImportedImageId ) );
489 else if( anIsImageHasRefs )
492 theMenu->addAction( action( EditFusedImageId ) );
493 else if( anIsCutImage )
494 theMenu->addAction( action( EditCutImageId ) );
495 else if( anIsSplittedImage )
496 theMenu->addAction( action( EditSplittedImageId ) );
499 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
500 theMenu->addAction( action( ExportImageId ) );
501 theMenu->addSeparator();
503 if( anIsImageHasRefs )
505 theMenu->addAction( action( RemoveImageRefsId ) );
506 theMenu->addSeparator();
509 theMenu->addAction( action( FuseImagesId ) );
510 theMenu->addAction( action( CutImagesId ) );
511 theMenu->addAction( action( SplitImageId ) );
512 theMenu->addSeparator();
514 else if( anIsBathymetry )
516 theMenu->addAction( action( EditImportedBathymetryId ) );
517 theMenu->addAction( action( BathymetryBoundsId ) );
518 theMenu->addSeparator();
520 else if( anIsPolyline )
522 theMenu->addAction( action( EditPolylineId ) );
523 theMenu->addSeparator();
525 else if( anIsPolyline3D )
527 theMenu->addAction( action( EditPolyline3DId ) );
528 theMenu->addSeparator();
530 else if( anIsProfile )
532 theMenu->addAction( action( EditProfileId ) );
533 theMenu->addAction( action( SelectedGeoreferencementId ) );
534 theMenu->addSeparator();
536 else if( anIsCalculation )
538 theMenu->addAction( action( EditCalculationId ) );
539 theMenu->addAction( action( ExportCalculationId ) );
540 theMenu->addSeparator();
542 else if( anIsImmersibleZone )
544 theMenu->addAction( action( EditImmersibleZoneId ) );
545 theMenu->addSeparator();
547 else if( anIsStream )
549 theMenu->addAction( action( EditStreamId ) );
550 theMenu->addSeparator();
552 else if( anIsChannel )
554 theMenu->addAction( action( EditChannelId ) );
555 theMenu->addSeparator();
559 theMenu->addAction( action( EditDigueId ) );
560 theMenu->addSeparator();
562 else if( anIsVisualState && anIsObjectBrowser )
564 theMenu->addAction( action( SaveVisualStateId ) );
565 theMenu->addAction( action( LoadVisualStateId ) );
566 theMenu->addSeparator();
569 // Add set color action for geometrical objects
570 if ( anIsObjectCanBeColored )
572 theMenu->addAction( action( SetColorId ) );
573 theMenu->addSeparator();
575 } else if ( anAllAreProfiles ) {
576 theMenu->addAction( action( SelectedGeoreferencementId ) );
577 theMenu->addSeparator();
580 if( !anIsDummyObject3D )
581 theMenu->addAction( action( DeleteId ) );
582 theMenu->addSeparator();
584 if( anIsImage || anIsPolyline || anIsPolyline3D ||
585 anIsImmersibleZone || anIsZone || anIsRegion ||
586 anIsBathymetry || anIsObstacle || anIsStream ||
587 anIsChannel || anIsDigue || anIsDummyObject3D ||
588 anIsValidProfile || anIsGroup )
590 if( anIsHiddenInSelection )
591 theMenu->addAction( action( ShowId ) );
592 theMenu->addAction( action( ShowOnlyId ) );
593 if( anIsVisibleInSelection )
594 theMenu->addAction( action( HideId ) );
595 theMenu->addSeparator();
601 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
602 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
603 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
604 theMenu->addAction( action( DeleteId ) );
607 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
609 theMenu->addAction( action( ShowAllId ) );
610 theMenu->addAction( action( HideAllId ) );
611 theMenu->addSeparator();
615 void HYDROGUI_Module::update( const int flags )
617 if( !isUpdateEnabled() )
620 QApplication::setOverrideCursor( Qt::WaitCursor );
622 // To prevent calling this method recursively
623 // from one of the methods called below
624 setUpdateEnabled( false );
626 // store selected objects
627 QStringList aSelectedEntries = storeSelection();
629 bool aDoFitAll = flags & UF_FitAll;
630 if( ( flags & UF_Viewer ) )
631 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
633 if( ( flags & UF_OCCViewer ) )
634 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
636 if( ( flags & UF_VTKViewer ) )
637 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
639 if( ( flags & UF_Model ) && getDataModel() && getApp() )
641 getDataModel()->update( getStudyId() );
643 // Temporary workaround to prevent breaking
644 // the selection in the object browser.
645 // Note: processEvents() should be called after updateGV(),
646 // otherwise the application crashes from time to time.
647 //RKV: qApp->processEvents();
648 getApp()->updateObjectBrowser( true );
651 // Object browser is currently updated by using UF_Model flag
652 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
653 getApp()->updateObjectBrowser( true );
655 if( ( flags & UF_Controls ) && getApp() )
656 getApp()->updateActions();
658 // restore selected objects
659 restoreSelection( aSelectedEntries );
661 setUpdateEnabled( true );
663 QApplication::restoreOverrideCursor();
666 void HYDROGUI_Module::updateCommandsStatus()
668 LightApp_Module::updateCommandsStatus();
670 updateUndoRedoControls();
672 action( CopyId )->setEnabled( getDataModel()->canCopy() );
673 action( PasteId )->setEnabled( getDataModel()->canPaste() );
676 void HYDROGUI_Module::selectionChanged()
678 LightApp_Module::selectionChanged();
679 updateCommandsStatus();
682 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
684 return (HYDROGUI_DataModel*)dataModel();
687 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
692 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
694 return myOCCDisplayer;
697 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
699 return myVTKDisplayer;
702 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
704 if( myViewManagerMap.contains( theId ) )
706 return myViewManagerMap[ theId ].first;
711 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
713 if( myViewManagerMap.contains( theId ) )
715 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
716 GraphicsView_ViewManager* aViewManager =
717 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
719 return aViewManager->getViewer();
724 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
726 if( myViewManagerMap.contains( theId ) )
728 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
729 OCCViewer_ViewManager* aViewManager =
730 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
732 return aViewManager->getOCCViewer();
737 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
739 if( myViewManagerMap.contains( theId ) )
741 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
742 SVTK_ViewManager* aViewManager =
743 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
745 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
750 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
752 ViewManagerMapIterator anIter( myViewManagerMap );
753 while( anIter.hasNext() )
755 int anId = anIter.next().key();
756 const ViewManagerInfo& anInfo = anIter.value();
757 if( anInfo.first == theViewManager )
763 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
765 int anId = getViewManagerId( theViewManager );
768 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
769 return anInfo.second;
774 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
775 const ViewManagerRole theRole )
777 int anId = getViewManagerId( theViewManager );
780 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
781 anInfo.second = theRole;
785 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
786 const Handle(HYDROData_Entity)& theObject ) const
788 if( theObject.IsNull() )
791 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
792 if( anIter1 != myObjectStateMap.end() )
794 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
795 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
796 if( anIter2 != aName2ObjectStateMap.end() )
798 const ObjectState& anObjectState = anIter2.value();
799 return anObjectState.Visibility;
805 void HYDROGUI_Module::setObjectVisible( const int theViewId,
806 const Handle(HYDROData_Entity)& theObject,
807 const bool theState )
809 if( !theObject.IsNull() )
811 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
812 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
813 anObjectState.Visibility = theState;
817 /////////////////// OCC SHAPES PROCESSING
818 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
819 const Handle(HYDROData_Entity)& theObject ) const
821 HYDROGUI_Shape* aResShape = NULL;
822 if( theObject.IsNull() )
825 if ( myShapesMap.contains( theViewId ) )
827 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
828 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
830 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
841 void HYDROGUI_Module::setObjectShape( const int theViewId,
842 const Handle(HYDROData_Entity)& theObject,
843 HYDROGUI_Shape* theShape )
845 if( theObject.IsNull() )
848 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
849 aViewShapes.append( theShape );
852 void HYDROGUI_Module::removeObjectShape( const int theViewId,
853 const Handle(HYDROData_Entity)& theObject )
855 if ( !myShapesMap.contains( theViewId ) )
858 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
859 Handle(HYDROData_Entity) anObject;
860 for ( int i = 0; i < aViewShapes.length(); )
862 HYDROGUI_Shape* aShape = aViewShapes.at( i );
863 anObject = aShape->getObject();
864 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
867 aViewShapes.removeAt( i );
875 void HYDROGUI_Module::removeViewShapes( const int theViewId )
877 if ( !myShapesMap.contains( theViewId ) )
880 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
881 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
883 HYDROGUI_Shape* aShape = aViewShapes.at( i );
888 myShapesMap.remove( theViewId );
890 /////////////////// END OF OCC SHAPES PROCESSING
892 /////////////////// VTKPrs PROCESSING
893 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
894 const Handle(HYDROData_Entity)& theObject ) const
896 HYDROGUI_VTKPrs* aResShape = NULL;
897 if( theObject.IsNull() )
900 if ( myVTKPrsMap.contains( theViewId ) )
902 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
903 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
905 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
916 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
917 const Handle(HYDROData_Entity)& theObject,
918 HYDROGUI_VTKPrs* theShape )
920 if( theObject.IsNull() )
923 if( theShape && theShape->needScalarBar() )
925 // Compute the new global Z range from the added presentation and the old global Z range.
926 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
927 double* aRange = theShape->getInternalZRange();
928 bool anIsUpdate = false;
929 if ( aRange[0] < aGlobalRange[0] )
931 aGlobalRange[0] = aRange[0];
934 if ( aRange[1] > aGlobalRange[1] )
936 aGlobalRange[1] = aRange[1];
942 updateVTKZRange( theViewId, aGlobalRange );
946 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
947 aViewShapes.append( theShape );
950 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
951 const Handle(HYDROData_Entity)& theObject )
953 if ( !myVTKPrsMap.contains( theViewId ) )
956 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
957 Handle(HYDROData_Entity) anObject;
958 for ( int i = 0; i < aViewShapes.length(); )
960 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
961 anObject = aShape->getObject();
962 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
965 aViewShapes.removeAt( i );
972 // Invalidate global Z range
973 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
974 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
977 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
979 if ( !myVTKPrsMap.contains( theViewId ) )
982 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
983 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
985 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
990 myVTKPrsMap.remove( theViewId );
993 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
995 if ( myVTKPrsMap.contains( theViewId ) )
997 // For the given viewer id update all VTK presentations ...
998 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
999 HYDROGUI_VTKPrs* aShape;
1000 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1002 aShape = aViewShapes.at( i );
1003 if ( aShape && aShape->needScalarBar() )
1005 aShape->setZRange( theRange );
1009 // ... and update the global color legend scalar bar.
1010 getVTKDisplayer()->SetZRange( theViewId, theRange );
1012 /////////////////// END OF VTKPrs PROCESSING
1014 CAM_DataModel* HYDROGUI_Module::createDataModel()
1016 return new HYDROGUI_DataModel( this );
1019 void HYDROGUI_Module::customEvent( QEvent* e )
1021 int aType = e->type();
1022 if ( aType == NewViewEvent )
1024 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1025 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1027 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1029 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1030 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1032 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1034 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1035 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1037 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1038 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1039 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1041 //ouv: temporarily commented
1042 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1045 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1046 update( UF_Viewer );
1048 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1054 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1056 QEvent::Type aType = theEvent->type();
1057 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1059 if( aType == QEvent::Show )
1061 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1062 e->setData( theObj );
1063 QApplication::postEvent( this, e );
1064 theObj->removeEventFilter( this );
1067 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1069 if( aType == QEvent::Leave )
1071 SUIT_Desktop* aDesktop = getApp()->desktop();
1072 if ( aDesktop && aDesktop->statusBar() ) {
1073 aDesktop->statusBar()->clearMessage();
1078 return LightApp_Module::eventFilter( theObj, theEvent );
1081 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1083 LightApp_Module::onViewManagerAdded( theViewManager );
1085 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1087 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1088 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1090 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1092 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1093 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1094 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1095 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1098 createSelector( theViewManager ); // replace the default selector
1100 ViewManagerInfo anInfo( theViewManager, VMR_General );
1101 myViewManagerMap.insert( ViewManagerId++, anInfo );
1104 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1106 LightApp_Module::onViewManagerRemoved( theViewManager );
1108 createSelector( theViewManager ); // replace the default selector
1110 int anId = getViewManagerId( theViewManager );
1113 OCCViewer_ViewManager* anOCCViewManager =
1114 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1115 if ( anOCCViewManager )
1117 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1119 removeViewShapes( (size_t)anOCCViewer );
1122 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1124 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1127 getVTKDisplayer()->EraseScalarBar( anId, true );
1128 removeViewShapes( (size_t)aVTKViewer );
1132 myViewManagerMap.remove( anId );
1136 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1138 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1140 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1142 aViewFrame->installEventFilter( this );
1144 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1146 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1147 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1150 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1152 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1154 aViewFrame->onTopView();
1156 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1158 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1160 aViewPort->installEventFilter( this );
1166 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1168 /* ouv: currently unused
1169 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1171 SUIT_ViewManager* aViewManager = 0;
1173 QObject* aParent = aViewPort;
1174 while( aParent = aParent->parent() )
1176 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1178 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1180 aViewManager = aViewer->getViewManager();
1189 double aMouseX = theEvent->scenePos().x();
1190 double aMouseY = theEvent->scenePos().y();
1192 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1193 if( aRole == VMR_General )
1195 int aXDeg = 0, aYDeg = 0;
1196 int aXMin = 0, aYMin = 0;
1197 double aXSec = 0, aYSec = 0;
1198 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1199 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1201 QString aDegSymbol( QChar( 0x00B0 ) );
1202 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1203 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1205 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1207 else if( aRole == VMR_TransformImage )
1208 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1213 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1214 const bool theIsInit,
1215 const bool theIsForced,
1216 const bool theDoFitAll )
1218 QList<int> aViewManagerIdList;
1220 // currently, all views are updated
1221 ViewManagerMapIterator anIter( myViewManagerMap );
1222 while( anIter.hasNext() )
1224 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1226 if ( theDisplayer->IsApplicable( aViewManager ) )
1228 int anId = anIter.key();
1229 aViewManagerIdList.append( anId );
1233 QListIterator<int> anIdIter( aViewManagerIdList );
1234 while( anIdIter.hasNext() )
1236 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1240 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1242 if( !theViewManager )
1245 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1246 if( !aSelectionMgr )
1249 QString aViewType = theViewManager->getType();
1250 if( aViewType != GraphicsView_Viewer::Type() &&
1251 aViewType != OCCViewer_Viewer::Type())
1254 QList<SUIT_Selector*> aSelectorList;
1255 aSelectionMgr->selectors( aViewType, aSelectorList );
1257 // disable all alien selectors
1258 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1259 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1261 SUIT_Selector* aSelector = *anIter;
1262 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1263 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1264 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1265 aSelector->setEnabled( false );
1268 if ( aViewType == GraphicsView_Viewer::Type() )
1270 GraphicsView_ViewManager* aViewManager =
1271 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1273 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1275 else if ( aViewType == OCCViewer_Viewer::Type() )
1277 OCCViewer_ViewManager* aViewManager =
1278 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1280 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1284 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1286 bool aPrevState = myIsUpdateEnabled;
1287 myIsUpdateEnabled = theState;
1291 bool HYDROGUI_Module::isUpdateEnabled() const
1293 return myIsUpdateEnabled;
1296 QStringList HYDROGUI_Module::storeSelection() const
1298 QStringList anEntryList;
1299 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1301 SUIT_DataOwnerPtrList aList( true );
1302 aSelectionMgr->selected( aList );
1304 SUIT_DataOwnerPtrList::iterator anIter;
1305 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1307 const LightApp_DataOwner* anOwner =
1308 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1310 anEntryList.append( anOwner->entry() );
1316 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1318 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1320 SUIT_DataOwnerPtrList aList( true );
1321 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1322 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1323 aSelectionMgr->setSelected( aList );
1327 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1329 OCCViewer_ViewWindow* anOCCViewWindow =
1330 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1331 if ( !anOCCViewWindow ) {
1335 // Get the selected point coordinates
1336 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1341 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1342 aViewPort->getView() );
1344 // Show the coordinates in the status bar
1345 SUIT_Desktop* aDesktop = getApp()->desktop();
1346 if ( aDesktop && aDesktop->statusBar() ) {
1347 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1348 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1349 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );