1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_OCCDisplayer.h"
32 #include "HYDROGUI_OCCSelector.h"
33 #include "HYDROGUI_Operations.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_Shape.h"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
41 #include "HYDROGUI_PolylineOp.h"
43 #include <HYDROData_Image.h>
44 #include <HYDROData_Profile.h>
45 #include <HYDROData_Lambert93.h>
46 #include <HYDROData_Tool.h>
48 #include <HYDROData_OperationsFactory.h>
50 #include <GraphicsView_ViewFrame.h>
51 #include <GraphicsView_ViewManager.h>
52 #include <GraphicsView_ViewPort.h>
53 #include <GraphicsView_Viewer.h>
55 #include <ImageComposer_CutOperator.h>
56 #include <ImageComposer_CropOperator.h>
57 #include <ImageComposer_FuseOperator.h>
59 #include <LightApp_Application.h>
60 #include <LightApp_DataOwner.h>
61 #include <LightApp_GVSelector.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_UpdateFlags.h>
65 #include <OCCViewer_ViewFrame.h>
66 #include <OCCViewer_ViewManager.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SALOME_Event.h>
71 #include <SUIT_DataBrowser.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_Study.h>
74 #include <SUIT_ViewManager.h>
76 #include <SVTK_ViewManager.h>
77 #include <SVTK_ViewModel.h>
78 #include <SVTK_Selector.h>
80 #include <OCCViewer_ViewPort3d.h>
82 #include <GEOMUtils.hxx>
85 #include <QApplication>
86 #include <QGraphicsSceneMouseEvent>
88 #include <QMouseEvent>
91 static int ViewManagerId = 0;
93 extern "C" HYDRO_EXPORT CAM_Module* createModule()
95 return new HYDROGUI_Module();
98 extern "C" HYDRO_EXPORT char* getModuleVersion()
100 return (char*)HYDRO_VERSION;
103 HYDROGUI_Module::HYDROGUI_Module()
104 : LightApp_Module( "HYDRO" ),
107 myIsUpdateEnabled( true )
111 HYDROGUI_Module::~HYDROGUI_Module()
115 int HYDROGUI_Module::getStudyId() const
117 LightApp_Application* anApp = getApp();
118 return anApp ? anApp->activeStudy()->id() : 0;
121 void HYDROGUI_Module::initialize( CAM_Application* theApp )
123 LightApp_Module::initialize( theApp );
126 createUndoRedoActions();
131 setMenuShown( false );
132 setToolShown( false );
134 myDisplayer = new HYDROGUI_Displayer( this );
135 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
136 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
139 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
141 bool aRes = LightApp_Module::activateModule( theStudy );
143 LightApp_Application* anApp = getApp();
144 SUIT_Desktop* aDesktop = anApp->desktop();
146 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
148 setMenuShown( true );
149 setToolShown( true );
151 #ifndef DISABLE_PYCONSOLE
152 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
153 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
156 // Remove defunct view managers from the map.
157 // It's essential to do this before "update( UF_All )" call!
158 QList<int> anObsoleteIds;
159 ViewManagerList anAllViewManagers = anApp->viewManagers();
160 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
161 ViewManagerMapIterator anIter( myViewManagerMap );
162 while( anIter.hasNext() ) {
163 int anId = anIter.next().key();
164 const ViewManagerInfo& anInfo = anIter.value();
166 aHydroViewManagers << anInfo.first;
168 if ( !anAllViewManagers.contains( anInfo.first ) ) {
169 anObsoleteIds << anId;
172 foreach ( const int anId, anObsoleteIds ) {
173 myViewManagerMap.remove( anId );
174 myObjectStateMap.remove( anId );
175 myShapesMap.remove( anId );
176 myVTKPrsMap.remove( anId );
178 // Replace the default selector for all view managers.
179 // Add view managers created outside of HYDRO module to the map.
180 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
181 createSelector( aViewManager ); // replace the default selector
182 if ( !aHydroViewManagers.contains( aViewManager ) ) {
183 ViewManagerInfo anInfo( aViewManager, VMR_General );
184 myViewManagerMap.insert( ViewManagerId++, anInfo );
190 updateCommandsStatus();
192 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
193 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
195 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
197 ViewManagerList anOCCViewManagers;
198 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
199 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
200 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
201 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
202 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
203 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
204 if ( aViewFrame && aViewFrame->getViewPort() ) {
205 aViewFrame->getViewPort()->installEventFilter( this );
213 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
216 ViewManagerMapIterator anIter( myViewManagerMap );
217 while( anIter.hasNext() )
218 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
219 getApp()->removeViewManager( aViewManager );
220 myViewManagerMap.clear();
223 ViewManagerList anOCCViewManagers;
224 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
225 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
226 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
227 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
231 myObjectStateMap.clear();
236 // clear the data model's list of copying objects
237 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
239 setMenuShown( false );
240 setToolShown( false );
242 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
244 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
245 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
247 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
249 return LightApp_Module::deactivateModule( theStudy );
252 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
255 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
256 #ifndef DISABLE_PYCONSOLE
257 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
259 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
262 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
264 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
267 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
271 HYDROGUI_DataModel* aModel = getDataModel();
273 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
274 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
275 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
276 bool anIsVTKView = theClient == SVTK_Viewer::Type();
277 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
280 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
282 bool anIsSelectedDataObjects = false;
283 bool anIsVisibleInSelection = false;
284 bool anIsHiddenInSelection = false;
286 bool anIsImage = false;
287 bool anIsImportedImage = false;
288 bool anIsImageHasRefs = false;
289 bool anIsFusedImage = false;
290 bool anIsCutImage = false;
291 bool anIsSplittedImage = false;
292 bool anIsMustObjectBeUpdated = false;
293 bool anIsPolyline = false;
294 bool anIsPolyline3D = false;
295 bool anIsProfile = false;
296 bool anIsValidProfile = false;
297 bool anAllAreProfiles = false;
298 bool anIsBathymetry = false;
299 bool anIsCalculation = false;
300 bool anIsImmersibleZone = false;
301 bool anIsVisualState = false;
302 bool anIsRegion = false;
303 bool anIsZone = false;
304 bool anIsObstacle = false;
305 bool anIsStream = false;
306 bool anIsChannel = false;
307 bool anIsDigue = false;
308 bool anIsGeomObject = false;
309 bool anIsDummyObject3D = false;
311 // check the selected GEOM objects
312 if ( anIsObjectBrowser && !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
313 theMenu->addAction( action( ImportGeomObjectId ) );
314 theMenu->addSeparator();
317 // check the selected data model objects
318 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
319 int aNbOfSelectedProfiles = 0;
320 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
322 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
323 if( !anObject.IsNull() )
325 anIsSelectedDataObjects = true;
327 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
328 anIsVisibleInSelection |= aVisibility;
329 anIsHiddenInSelection |= !aVisibility;
331 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
333 anIsMustObjectBeUpdated = true;
336 ObjectKind anObjectKind = anObject->GetKind();
337 if( anObjectKind == KIND_IMAGE )
340 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
341 if( !anImage.IsNull() )
343 anIsImportedImage = anImage->HasLocalPoints();
344 anIsImageHasRefs = anImage->HasReferences();
345 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
347 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
349 QString anOperatorName = anOperator->name();
350 if( anOperatorName == ImageComposer_FuseOperator::Type() )
351 anIsFusedImage = true;
352 else if( anOperatorName == ImageComposer_CutOperator::Type() )
354 else if( anOperatorName == ImageComposer_CropOperator::Type() )
355 anIsSplittedImage = true;
360 else if( anObjectKind == KIND_POLYLINEXY )
362 else if( anObjectKind == KIND_POLYLINE )
363 anIsPolyline3D = true;
364 else if( anObjectKind == KIND_PROFILE )
367 aNbOfSelectedProfiles++;
369 Handle(HYDROData_Profile) aProfile =
370 Handle(HYDROData_Profile)::DownCast( anObject );
371 if( !aProfile.IsNull() && aProfile->IsValid() ) {
372 anIsValidProfile = true;
375 else if( anObjectKind == KIND_CALCULATION )
376 anIsCalculation = true;
377 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
378 anIsImmersibleZone = true;
379 else if( anObjectKind == KIND_VISUAL_STATE )
380 anIsVisualState = true;
381 else if( anObjectKind == KIND_REGION )
383 else if( anObjectKind == KIND_ZONE )
385 else if( anObjectKind == KIND_BATHYMETRY )
386 anIsBathymetry = true;
387 else if( anObjectKind == KIND_OBSTACLE )
389 else if( anObjectKind == KIND_STREAM )
391 else if( anObjectKind == KIND_CHANNEL )
393 else if( anObjectKind == KIND_DIGUE )
395 else if( anObjectKind == KIND_DUMMY_3D )
396 anIsDummyObject3D = true;
399 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
402 // Check if all selected objects are profiles
403 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
404 ( aNbOfSelectedProfiles == aSeq.Length() );
406 // check the selected partitions
407 if( !anIsSelectedDataObjects && anIsObjectBrowser )
409 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
410 if( aSelectedPartition != KIND_UNKNOWN )
412 switch( aSelectedPartition )
415 theMenu->addAction( action( ImportImageId ) );
417 case KIND_BATHYMETRY:
418 theMenu->addAction( action( ImportBathymetryId ) );
420 case KIND_ARTIFICIAL_OBJECT:
421 theMenu->addAction( action( CreateChannelId ) );
422 theMenu->addAction( action( CreateDigueId ) );
424 case KIND_NATURAL_OBJECT:
425 theMenu->addAction( action( CreateImmersibleZoneId ) );
426 theMenu->addAction( action( CreateStreamId ) );
429 theMenu->addAction( action( ImportObstacleFromFileId ) );
430 theMenu->addAction( action( CreateBoxId ) );
431 theMenu->addAction( action( CreateCylinderId ) );
433 case KIND_CALCULATION:
434 theMenu->addAction( action( CreateCalculationId ) );
436 case KIND_POLYLINEXY:
437 theMenu->addAction( action( CreatePolylineId ) );
440 theMenu->addAction( action( CreatePolyline3DId ) );
443 theMenu->addAction( action( CreateProfileId ) );
444 theMenu->addAction( action( ImportProfilesId ) );
445 theMenu->addAction( action( AllGeoreferencementId ) );
447 case KIND_VISUAL_STATE:
448 theMenu->addAction( action( SaveVisualStateId ) );
451 theMenu->addSeparator();
455 if( anIsSelectedDataObjects )
457 if ( anIsMustObjectBeUpdated )
459 theMenu->addAction( action( UpdateObjectId ) );
460 theMenu->addSeparator();
463 if( aSeq.Length() == 1 )
467 if( anIsImportedImage )
468 theMenu->addAction( action( EditImportedImageId ) );
469 else if( anIsImageHasRefs )
472 theMenu->addAction( action( EditFusedImageId ) );
473 else if( anIsCutImage )
474 theMenu->addAction( action( EditCutImageId ) );
475 else if( anIsSplittedImage )
476 theMenu->addAction( action( EditSplittedImageId ) );
479 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
480 theMenu->addAction( action( ExportImageId ) );
481 theMenu->addSeparator();
483 if( anIsImageHasRefs )
485 theMenu->addAction( action( RemoveImageRefsId ) );
486 theMenu->addSeparator();
489 theMenu->addAction( action( FuseImagesId ) );
490 theMenu->addAction( action( CutImagesId ) );
491 theMenu->addAction( action( SplitImageId ) );
492 theMenu->addSeparator();
494 else if( anIsBathymetry )
496 theMenu->addAction( action( EditImportedBathymetryId ) );
497 theMenu->addSeparator();
499 else if( anIsPolyline )
501 theMenu->addAction( action( EditPolylineId ) );
502 theMenu->addSeparator();
504 else if( anIsPolyline3D )
506 theMenu->addAction( action( EditPolyline3DId ) );
507 theMenu->addSeparator();
509 else if( anIsProfile )
511 theMenu->addAction( action( EditProfileId ) );
512 theMenu->addAction( action( SelectedGeoreferencementId ) );
513 theMenu->addSeparator();
515 else if( anIsCalculation )
517 theMenu->addAction( action( EditCalculationId ) );
518 theMenu->addAction( action( ExportCalculationId ) );
519 theMenu->addSeparator();
521 else if( anIsImmersibleZone )
523 theMenu->addAction( action( EditImmersibleZoneId ) );
524 theMenu->addSeparator();
526 else if( anIsStream )
528 theMenu->addAction( action( EditStreamId ) );
529 theMenu->addSeparator();
531 else if( anIsChannel )
533 theMenu->addAction( action( EditChannelId ) );
534 theMenu->addSeparator();
538 theMenu->addAction( action( EditDigueId ) );
539 theMenu->addSeparator();
541 else if( anIsVisualState && anIsObjectBrowser )
543 theMenu->addAction( action( SaveVisualStateId ) );
544 theMenu->addAction( action( LoadVisualStateId ) );
545 theMenu->addSeparator();
548 // Add set color action for geometrical objects
549 if ( anIsGeomObject )
551 theMenu->addAction( action( SetColorId ) );
552 theMenu->addSeparator();
554 } else if ( anAllAreProfiles ) {
555 theMenu->addAction( action( SelectedGeoreferencementId ) );
556 theMenu->addSeparator();
559 theMenu->addAction( action( DeleteId ) );
560 theMenu->addSeparator();
562 if( anIsImage || anIsPolyline || anIsPolyline3D ||
563 anIsImmersibleZone || anIsZone || anIsRegion ||
564 anIsBathymetry || anIsObstacle || anIsStream ||
565 anIsChannel || anIsDigue || anIsDummyObject3D ||
568 if( anIsHiddenInSelection )
569 theMenu->addAction( action( ShowId ) );
570 theMenu->addAction( action( ShowOnlyId ) );
571 if( anIsVisibleInSelection )
572 theMenu->addAction( action( HideId ) );
573 theMenu->addSeparator();
579 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
580 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
581 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
582 theMenu->addAction( action( DeleteId ) );
585 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
587 theMenu->addAction( action( ShowAllId ) );
588 theMenu->addAction( action( HideAllId ) );
589 theMenu->addSeparator();
593 void HYDROGUI_Module::update( const int flags )
595 if( !isUpdateEnabled() )
598 QApplication::setOverrideCursor( Qt::WaitCursor );
600 // To prevent calling this method recursively
601 // from one of the methods called below
602 setUpdateEnabled( false );
604 // store selected objects
605 QStringList aSelectedEntries = storeSelection();
607 bool aDoFitAll = flags & UF_FitAll;
608 if( ( flags & UF_Viewer ) )
609 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
611 if( ( flags & UF_OCCViewer ) )
612 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
614 if( ( flags & UF_VTKViewer ) )
615 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
617 if( ( flags & UF_Model ) && getDataModel() && getApp() )
619 getDataModel()->update( getStudyId() );
621 // Temporary workaround to prevent breaking
622 // the selection in the object browser.
623 // Note: processEvents() should be called after updateGV(),
624 // otherwise the application crashes from time to time.
625 //RKV: qApp->processEvents();
626 getApp()->updateObjectBrowser( true );
629 // Object browser is currently updated by using UF_Model flag
630 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
631 getApp()->updateObjectBrowser( true );
633 if( ( flags & UF_Controls ) && getApp() )
634 getApp()->updateActions();
636 // restore selected objects
637 restoreSelection( aSelectedEntries );
639 setUpdateEnabled( true );
641 QApplication::restoreOverrideCursor();
644 void HYDROGUI_Module::updateCommandsStatus()
646 LightApp_Module::updateCommandsStatus();
648 updateUndoRedoControls();
650 action( CopyId )->setEnabled( getDataModel()->canCopy() );
651 action( PasteId )->setEnabled( getDataModel()->canPaste() );
654 void HYDROGUI_Module::selectionChanged()
656 LightApp_Module::selectionChanged();
657 updateCommandsStatus();
660 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
662 return (HYDROGUI_DataModel*)dataModel();
665 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
670 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
672 return myOCCDisplayer;
675 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
677 return myVTKDisplayer;
680 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
682 if( myViewManagerMap.contains( theId ) )
684 return myViewManagerMap[ theId ].first;
689 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
691 if( myViewManagerMap.contains( theId ) )
693 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
694 GraphicsView_ViewManager* aViewManager =
695 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
697 return aViewManager->getViewer();
702 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
704 if( myViewManagerMap.contains( theId ) )
706 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
707 OCCViewer_ViewManager* aViewManager =
708 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
710 return aViewManager->getOCCViewer();
715 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
717 if( myViewManagerMap.contains( theId ) )
719 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
720 SVTK_ViewManager* aViewManager =
721 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
723 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
728 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
730 ViewManagerMapIterator anIter( myViewManagerMap );
731 while( anIter.hasNext() )
733 int anId = anIter.next().key();
734 const ViewManagerInfo& anInfo = anIter.value();
735 if( anInfo.first == theViewManager )
741 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
743 int anId = getViewManagerId( theViewManager );
746 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
747 return anInfo.second;
752 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
753 const ViewManagerRole theRole )
755 int anId = getViewManagerId( theViewManager );
758 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
759 anInfo.second = theRole;
763 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
764 const Handle(HYDROData_Entity)& theObject ) const
766 if( theObject.IsNull() )
769 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
770 if( anIter1 != myObjectStateMap.end() )
772 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
773 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
774 if( anIter2 != aName2ObjectStateMap.end() )
776 const ObjectState& anObjectState = anIter2.value();
777 return anObjectState.Visibility;
783 void HYDROGUI_Module::setObjectVisible( const int theViewId,
784 const Handle(HYDROData_Entity)& theObject,
785 const bool theState )
787 if( !theObject.IsNull() )
789 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
790 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
791 anObjectState.Visibility = theState;
795 /////////////////// OCC SHAPES PROCESSING
796 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
797 const Handle(HYDROData_Entity)& theObject ) const
799 HYDROGUI_Shape* aResShape = NULL;
800 if( theObject.IsNull() )
803 if ( myShapesMap.contains( theViewId ) )
805 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
806 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
808 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
819 void HYDROGUI_Module::setObjectShape( const int theViewId,
820 const Handle(HYDROData_Entity)& theObject,
821 HYDROGUI_Shape* theShape )
823 if( theObject.IsNull() )
826 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
827 aViewShapes.append( theShape );
830 void HYDROGUI_Module::removeObjectShape( const int theViewId,
831 const Handle(HYDROData_Entity)& theObject )
833 if ( !myShapesMap.contains( theViewId ) )
836 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
837 Handle(HYDROData_Entity) anObject;
838 for ( int i = 0; i < aViewShapes.length(); )
840 HYDROGUI_Shape* aShape = aViewShapes.at( i );
841 anObject = aShape->getObject();
842 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
845 aViewShapes.removeAt( i );
853 void HYDROGUI_Module::removeViewShapes( const int theViewId )
855 if ( !myShapesMap.contains( theViewId ) )
858 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
859 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
861 HYDROGUI_Shape* aShape = aViewShapes.at( i );
866 myShapesMap.remove( theViewId );
868 /////////////////// END OF OCC SHAPES PROCESSING
870 /////////////////// VTKPrs PROCESSING
871 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
872 const Handle(HYDROData_Entity)& theObject ) const
874 HYDROGUI_VTKPrs* aResShape = NULL;
875 if( theObject.IsNull() )
878 if ( myVTKPrsMap.contains( theViewId ) )
880 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
881 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
883 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
894 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
895 const Handle(HYDROData_Entity)& theObject,
896 HYDROGUI_VTKPrs* theShape )
898 if( theObject.IsNull() )
901 // Compute the new global Z range from the added presentation and the old global Z range.
902 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
903 double* aRange = theShape->getInternalZRange();
904 bool anIsUpdate = false;
905 if ( aRange[0] < aGlobalRange[0] )
907 aGlobalRange[0] = aRange[0];
910 if ( aRange[1] > aGlobalRange[1] )
912 aGlobalRange[1] = aRange[1];
918 updateVTKZRange( theViewId, aGlobalRange );
921 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
922 aViewShapes.append( theShape );
925 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
926 const Handle(HYDROData_Entity)& theObject )
928 if ( !myVTKPrsMap.contains( theViewId ) )
931 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
932 Handle(HYDROData_Entity) anObject;
933 for ( int i = 0; i < aViewShapes.length(); )
935 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
936 anObject = aShape->getObject();
937 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
940 aViewShapes.removeAt( i );
947 // Invalidate global Z range
948 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
949 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
952 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
954 if ( !myVTKPrsMap.contains( theViewId ) )
957 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
958 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
960 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
965 myVTKPrsMap.remove( theViewId );
968 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
970 if ( myVTKPrsMap.contains( theViewId ) )
972 // For the given viewer id update all VTK presentations ...
973 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
974 HYDROGUI_VTKPrs* aShape;
975 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
977 aShape = aViewShapes.at( i );
980 aShape->setZRange( theRange );
984 // ... and update the global color legend scalar bar.
985 getVTKDisplayer()->SetZRange( theViewId, theRange );
987 /////////////////// END OF VTKPrs PROCESSING
989 CAM_DataModel* HYDROGUI_Module::createDataModel()
991 return new HYDROGUI_DataModel( this );
994 void HYDROGUI_Module::customEvent( QEvent* e )
996 int aType = e->type();
997 if ( aType == NewViewEvent )
999 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1000 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1002 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1004 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1005 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1007 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1009 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1010 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1012 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1013 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1014 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1016 //ouv: temporarily commented
1017 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1020 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1021 update( UF_Viewer );
1023 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1029 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1031 QEvent::Type aType = theEvent->type();
1032 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1034 if( aType == QEvent::Show )
1036 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1037 e->setData( theObj );
1038 QApplication::postEvent( this, e );
1039 theObj->removeEventFilter( this );
1042 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1044 if( aType == QEvent::Leave )
1046 SUIT_Desktop* aDesktop = getApp()->desktop();
1047 if ( aDesktop && aDesktop->statusBar() ) {
1048 aDesktop->statusBar()->clearMessage();
1053 return LightApp_Module::eventFilter( theObj, theEvent );
1056 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1058 LightApp_Module::onViewManagerAdded( theViewManager );
1060 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1062 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1063 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1065 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1067 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1068 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1069 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1070 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1073 createSelector( theViewManager ); // replace the default selector
1075 ViewManagerInfo anInfo( theViewManager, VMR_General );
1076 myViewManagerMap.insert( ViewManagerId++, anInfo );
1079 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1081 LightApp_Module::onViewManagerRemoved( theViewManager );
1083 createSelector( theViewManager ); // replace the default selector
1085 int anId = getViewManagerId( theViewManager );
1088 OCCViewer_ViewManager* anOCCViewManager =
1089 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1090 if ( anOCCViewManager )
1092 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1094 removeViewShapes( (size_t)anOCCViewer );
1097 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1099 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1102 getVTKDisplayer()->DeleteScalarBar( anId );
1103 removeViewShapes( (size_t)aVTKViewer );
1107 myViewManagerMap.remove( anId );
1111 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1113 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1115 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1117 aViewFrame->installEventFilter( this );
1119 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1121 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1122 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1125 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1127 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1129 aViewFrame->onTopView();
1131 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1133 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1135 aViewPort->installEventFilter( this );
1141 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1143 /* ouv: currently unused
1144 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1146 SUIT_ViewManager* aViewManager = 0;
1148 QObject* aParent = aViewPort;
1149 while( aParent = aParent->parent() )
1151 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1153 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1155 aViewManager = aViewer->getViewManager();
1164 double aMouseX = theEvent->scenePos().x();
1165 double aMouseY = theEvent->scenePos().y();
1167 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1168 if( aRole == VMR_General )
1170 int aXDeg = 0, aYDeg = 0;
1171 int aXMin = 0, aYMin = 0;
1172 double aXSec = 0, aYSec = 0;
1173 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1174 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1176 QString aDegSymbol( QChar( 0x00B0 ) );
1177 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1178 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1180 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1182 else if( aRole == VMR_TransformImage )
1183 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1188 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1189 const bool theIsInit,
1190 const bool theIsForced,
1191 const bool theDoFitAll )
1193 QList<int> aViewManagerIdList;
1195 // currently, all views are updated
1196 ViewManagerMapIterator anIter( myViewManagerMap );
1197 while( anIter.hasNext() )
1199 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1201 if ( theDisplayer->IsApplicable( aViewManager ) )
1203 int anId = anIter.key();
1204 aViewManagerIdList.append( anId );
1208 QListIterator<int> anIdIter( aViewManagerIdList );
1209 while( anIdIter.hasNext() )
1211 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1215 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1217 if( !theViewManager )
1220 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1221 if( !aSelectionMgr )
1224 QString aViewType = theViewManager->getType();
1225 if( aViewType != GraphicsView_Viewer::Type() &&
1226 aViewType != OCCViewer_Viewer::Type())
1229 QList<SUIT_Selector*> aSelectorList;
1230 aSelectionMgr->selectors( aViewType, aSelectorList );
1232 // disable all alien selectors
1233 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1234 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1236 SUIT_Selector* aSelector = *anIter;
1237 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1238 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1239 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1240 aSelector->setEnabled( false );
1243 if ( aViewType == GraphicsView_Viewer::Type() )
1245 GraphicsView_ViewManager* aViewManager =
1246 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1248 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1250 else if ( aViewType == OCCViewer_Viewer::Type() )
1252 OCCViewer_ViewManager* aViewManager =
1253 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1255 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1259 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1261 bool aPrevState = myIsUpdateEnabled;
1262 myIsUpdateEnabled = theState;
1266 bool HYDROGUI_Module::isUpdateEnabled() const
1268 return myIsUpdateEnabled;
1271 QStringList HYDROGUI_Module::storeSelection() const
1273 QStringList anEntryList;
1274 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1276 SUIT_DataOwnerPtrList aList( true );
1277 aSelectionMgr->selected( aList );
1279 SUIT_DataOwnerPtrList::iterator anIter;
1280 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1282 const LightApp_DataOwner* anOwner =
1283 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1285 anEntryList.append( anOwner->entry() );
1291 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1293 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1295 SUIT_DataOwnerPtrList aList( true );
1296 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1297 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1298 aSelectionMgr->setSelected( aList );
1302 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1304 OCCViewer_ViewWindow* anOCCViewWindow =
1305 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1306 if ( !anOCCViewWindow ) {
1310 // Get the selected point coordinates
1311 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1316 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1317 aViewPort->getView() );
1319 // Show the coordinates in the status bar
1320 SUIT_Desktop* aDesktop = getApp()->desktop();
1321 if ( aDesktop && aDesktop->statusBar() ) {
1322 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1323 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1324 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );