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"
44 #include <HYDROData_Image.h>
45 #include <HYDROData_Profile.h>
46 #include <HYDROData_Lambert93.h>
47 #include <HYDROData_Tool.h>
49 #include <HYDROData_OperationsFactory.h>
51 #include <GraphicsView_ViewFrame.h>
52 #include <GraphicsView_ViewManager.h>
53 #include <GraphicsView_ViewPort.h>
54 #include <GraphicsView_Viewer.h>
56 #include <ImageComposer_CutOperator.h>
57 #include <ImageComposer_CropOperator.h>
58 #include <ImageComposer_FuseOperator.h>
60 #include <LightApp_Application.h>
61 #include <LightApp_DataOwner.h>
62 #include <LightApp_GVSelector.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_UpdateFlags.h>
66 #include <OCCViewer_ViewFrame.h>
67 #include <OCCViewer_ViewManager.h>
68 #include <OCCViewer_ViewModel.h>
70 #include <SALOME_Event.h>
72 #include <SUIT_DataBrowser.h>
73 #include <SUIT_Desktop.h>
74 #include <SUIT_Study.h>
75 #include <SUIT_ViewManager.h>
77 #include <SVTK_ViewManager.h>
78 #include <SVTK_ViewModel.h>
79 #include <SVTK_Selector.h>
81 #include <OCCViewer_ViewPort3d.h>
83 #include <GEOMUtils.hxx>
86 #include <QApplication>
87 #include <QGraphicsSceneMouseEvent>
89 #include <QMouseEvent>
92 static int ViewManagerId = 0;
94 extern "C" HYDRO_EXPORT CAM_Module* createModule()
96 return new HYDROGUI_Module();
99 extern "C" HYDRO_EXPORT char* getModuleVersion()
101 return (char*)HYDRO_VERSION;
104 HYDROGUI_Module::HYDROGUI_Module()
105 : LightApp_Module( "HYDRO" ),
108 myIsUpdateEnabled( true )
112 HYDROGUI_Module::~HYDROGUI_Module()
116 int HYDROGUI_Module::getStudyId() const
118 LightApp_Application* anApp = getApp();
119 return anApp ? anApp->activeStudy()->id() : 0;
122 void HYDROGUI_Module::initialize( CAM_Application* theApp )
124 LightApp_Module::initialize( theApp );
127 createUndoRedoActions();
132 setMenuShown( false );
133 setToolShown( false );
135 myDisplayer = new HYDROGUI_Displayer( this );
136 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
137 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
140 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
142 bool aRes = LightApp_Module::activateModule( theStudy );
144 LightApp_Application* anApp = getApp();
145 SUIT_Desktop* aDesktop = anApp->desktop();
147 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
149 setMenuShown( true );
150 setToolShown( true );
152 #ifndef DISABLE_PYCONSOLE
153 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
154 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
157 // Remove defunct view managers from the map.
158 // It's essential to do this before "update( UF_All )" call!
159 QList<int> anObsoleteIds;
160 ViewManagerList anAllViewManagers = anApp->viewManagers();
161 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
162 ViewManagerMapIterator anIter( myViewManagerMap );
163 while( anIter.hasNext() ) {
164 int anId = anIter.next().key();
165 const ViewManagerInfo& anInfo = anIter.value();
167 aHydroViewManagers << anInfo.first;
169 if ( !anAllViewManagers.contains( anInfo.first ) ) {
170 anObsoleteIds << anId;
173 foreach ( const int anId, anObsoleteIds ) {
174 myViewManagerMap.remove( anId );
175 myObjectStateMap.remove( anId );
176 myShapesMap.remove( anId );
177 myVTKPrsMap.remove( anId );
179 // Replace the default selector for all view managers.
180 // Add view managers created outside of HYDRO module to the map.
181 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
182 createSelector( aViewManager ); // replace the default selector
183 if ( !aHydroViewManagers.contains( aViewManager ) ) {
184 ViewManagerInfo anInfo( aViewManager, VMR_General );
185 myViewManagerMap.insert( ViewManagerId++, anInfo );
191 updateCommandsStatus();
193 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
194 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
196 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
198 ViewManagerList anOCCViewManagers;
199 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
200 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
201 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
202 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
203 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
204 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
205 if ( aViewFrame && aViewFrame->getViewPort() ) {
206 aViewFrame->getViewPort()->installEventFilter( this );
214 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
217 ViewManagerMapIterator anIter( myViewManagerMap );
218 while( anIter.hasNext() )
219 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
220 getApp()->removeViewManager( aViewManager );
221 myViewManagerMap.clear();
224 ViewManagerList anOCCViewManagers;
225 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
226 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
227 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
228 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
232 myObjectStateMap.clear();
237 // clear the data model's list of copying objects
238 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
240 setMenuShown( false );
241 setToolShown( false );
243 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
245 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
246 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
248 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
250 return LightApp_Module::deactivateModule( theStudy );
253 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
256 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
257 #ifndef DISABLE_PYCONSOLE
258 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
260 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
263 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
265 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
268 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
272 HYDROGUI_DataModel* aModel = getDataModel();
274 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
275 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
276 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
277 bool anIsVTKView = theClient == SVTK_Viewer::Type();
278 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
281 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
283 bool anIsSelectedDataObjects = false;
284 bool anIsVisibleInSelection = false;
285 bool anIsHiddenInSelection = false;
287 bool anIsImage = false;
288 bool anIsImportedImage = false;
289 bool anIsImageHasRefs = false;
290 bool anIsFusedImage = false;
291 bool anIsCutImage = false;
292 bool anIsSplittedImage = false;
293 bool anIsMustObjectBeUpdated = false;
294 bool anIsPolyline = false;
295 bool anIsPolyline3D = false;
296 bool anIsProfile = false;
297 bool anIsValidProfile = false;
298 bool anAllAreProfiles = false;
299 bool anIsBathymetry = false;
300 bool anIsCalculation = false;
301 bool anIsImmersibleZone = false;
302 bool anIsVisualState = false;
303 bool anIsRegion = false;
304 bool anIsZone = false;
305 bool anIsObstacle = false;
306 bool anIsStream = false;
307 bool anIsChannel = false;
308 bool anIsDigue = false;
309 bool anIsDummyObject3D = false;
310 bool anIsObjectCanBeColored = false;
312 // check the selected GEOM objects
313 if ( anIsObjectBrowser && !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
314 theMenu->addAction( action( ImportGeomObjectId ) );
315 theMenu->addSeparator();
318 // check the selected data model objects
319 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
320 int aNbOfSelectedProfiles = 0;
321 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
323 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
324 if( !anObject.IsNull() )
326 anIsSelectedDataObjects = true;
328 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
329 anIsVisibleInSelection |= aVisibility;
330 anIsHiddenInSelection |= !aVisibility;
332 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
334 anIsMustObjectBeUpdated = true;
337 ObjectKind anObjectKind = anObject->GetKind();
338 if( anObjectKind == KIND_IMAGE )
341 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
342 if( !anImage.IsNull() )
344 anIsImportedImage = anImage->HasLocalPoints();
345 anIsImageHasRefs = anImage->HasReferences();
346 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
348 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
350 QString anOperatorName = anOperator->name();
351 if( anOperatorName == ImageComposer_FuseOperator::Type() )
352 anIsFusedImage = true;
353 else if( anOperatorName == ImageComposer_CutOperator::Type() )
355 else if( anOperatorName == ImageComposer_CropOperator::Type() )
356 anIsSplittedImage = true;
361 else if( anObjectKind == KIND_POLYLINEXY )
363 else if( anObjectKind == KIND_POLYLINE )
364 anIsPolyline3D = true;
365 else if( anObjectKind == KIND_PROFILE )
368 aNbOfSelectedProfiles++;
370 Handle(HYDROData_Profile) aProfile =
371 Handle(HYDROData_Profile)::DownCast( anObject );
372 if( !aProfile.IsNull() && aProfile->IsValid() ) {
373 anIsValidProfile = true;
376 else if( anObjectKind == KIND_CALCULATION )
377 anIsCalculation = true;
378 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
379 anIsImmersibleZone = true;
380 else if( anObjectKind == KIND_VISUAL_STATE )
381 anIsVisualState = true;
382 else if( anObjectKind == KIND_REGION )
384 else if( anObjectKind == KIND_ZONE )
386 else if( anObjectKind == KIND_BATHYMETRY )
387 anIsBathymetry = true;
388 else if( anObjectKind == KIND_OBSTACLE )
390 else if( anObjectKind == KIND_STREAM )
392 else if( anObjectKind == KIND_CHANNEL )
394 else if( anObjectKind == KIND_DIGUE )
396 else if( anObjectKind == KIND_DUMMY_3D )
397 anIsDummyObject3D = true;
400 if ( !anIsObjectCanBeColored )
401 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
404 // Check if all selected objects are profiles
405 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
406 ( aNbOfSelectedProfiles == aSeq.Length() );
408 // check the selected partitions
409 if( !anIsSelectedDataObjects && anIsObjectBrowser )
411 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
412 if( aSelectedPartition != KIND_UNKNOWN )
414 switch( aSelectedPartition )
417 theMenu->addAction( action( ImportImageId ) );
419 case KIND_BATHYMETRY:
420 theMenu->addAction( action( ImportBathymetryId ) );
422 case KIND_ARTIFICIAL_OBJECT:
423 theMenu->addAction( action( CreateChannelId ) );
424 theMenu->addAction( action( CreateDigueId ) );
426 case KIND_NATURAL_OBJECT:
427 theMenu->addAction( action( CreateImmersibleZoneId ) );
428 theMenu->addAction( action( CreateStreamId ) );
431 theMenu->addAction( action( ImportObstacleFromFileId ) );
432 theMenu->addAction( action( CreateBoxId ) );
433 theMenu->addAction( action( CreateCylinderId ) );
435 case KIND_CALCULATION:
436 theMenu->addAction( action( CreateCalculationId ) );
438 case KIND_POLYLINEXY:
439 theMenu->addAction( action( CreatePolylineId ) );
442 theMenu->addAction( action( CreatePolyline3DId ) );
445 theMenu->addAction( action( CreateProfileId ) );
446 theMenu->addAction( action( ImportProfilesId ) );
447 theMenu->addAction( action( AllGeoreferencementId ) );
449 case KIND_VISUAL_STATE:
450 theMenu->addAction( action( SaveVisualStateId ) );
453 theMenu->addSeparator();
457 if( anIsSelectedDataObjects )
459 if ( anIsMustObjectBeUpdated )
461 theMenu->addAction( action( UpdateObjectId ) );
462 theMenu->addSeparator();
465 if( aSeq.Length() == 1 )
469 if( anIsImportedImage )
470 theMenu->addAction( action( EditImportedImageId ) );
471 else if( anIsImageHasRefs )
474 theMenu->addAction( action( EditFusedImageId ) );
475 else if( anIsCutImage )
476 theMenu->addAction( action( EditCutImageId ) );
477 else if( anIsSplittedImage )
478 theMenu->addAction( action( EditSplittedImageId ) );
481 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
482 theMenu->addAction( action( ExportImageId ) );
483 theMenu->addSeparator();
485 if( anIsImageHasRefs )
487 theMenu->addAction( action( RemoveImageRefsId ) );
488 theMenu->addSeparator();
491 theMenu->addAction( action( FuseImagesId ) );
492 theMenu->addAction( action( CutImagesId ) );
493 theMenu->addAction( action( SplitImageId ) );
494 theMenu->addSeparator();
496 else if( anIsBathymetry )
498 theMenu->addAction( action( EditImportedBathymetryId ) );
499 theMenu->addSeparator();
501 else if( anIsPolyline )
503 theMenu->addAction( action( EditPolylineId ) );
504 theMenu->addSeparator();
506 else if( anIsPolyline3D )
508 theMenu->addAction( action( EditPolyline3DId ) );
509 theMenu->addSeparator();
511 else if( anIsProfile )
513 theMenu->addAction( action( EditProfileId ) );
514 theMenu->addAction( action( SelectedGeoreferencementId ) );
515 theMenu->addSeparator();
517 else if( anIsCalculation )
519 theMenu->addAction( action( EditCalculationId ) );
520 theMenu->addAction( action( ExportCalculationId ) );
521 theMenu->addSeparator();
523 else if( anIsImmersibleZone )
525 theMenu->addAction( action( EditImmersibleZoneId ) );
526 theMenu->addSeparator();
528 else if( anIsStream )
530 theMenu->addAction( action( EditStreamId ) );
531 theMenu->addSeparator();
533 else if( anIsChannel )
535 theMenu->addAction( action( EditChannelId ) );
536 theMenu->addSeparator();
540 theMenu->addAction( action( EditDigueId ) );
541 theMenu->addSeparator();
543 else if( anIsVisualState && anIsObjectBrowser )
545 theMenu->addAction( action( SaveVisualStateId ) );
546 theMenu->addAction( action( LoadVisualStateId ) );
547 theMenu->addSeparator();
550 // Add set color action for geometrical objects
551 if ( anIsObjectCanBeColored )
553 theMenu->addAction( action( SetColorId ) );
554 theMenu->addSeparator();
556 } else if ( anAllAreProfiles ) {
557 theMenu->addAction( action( SelectedGeoreferencementId ) );
558 theMenu->addSeparator();
561 if( !anIsDummyObject3D )
562 theMenu->addAction( action( DeleteId ) );
563 theMenu->addSeparator();
565 if( anIsImage || anIsPolyline || anIsPolyline3D ||
566 anIsImmersibleZone || anIsZone || anIsRegion ||
567 anIsBathymetry || anIsObstacle || anIsStream ||
568 anIsChannel || anIsDigue || anIsDummyObject3D ||
571 if( anIsHiddenInSelection )
572 theMenu->addAction( action( ShowId ) );
573 theMenu->addAction( action( ShowOnlyId ) );
574 if( anIsVisibleInSelection )
575 theMenu->addAction( action( HideId ) );
576 theMenu->addSeparator();
582 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
583 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
584 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
585 theMenu->addAction( action( DeleteId ) );
588 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
590 theMenu->addAction( action( ShowAllId ) );
591 theMenu->addAction( action( HideAllId ) );
592 theMenu->addSeparator();
596 void HYDROGUI_Module::update( const int flags )
598 if( !isUpdateEnabled() )
601 QApplication::setOverrideCursor( Qt::WaitCursor );
603 // To prevent calling this method recursively
604 // from one of the methods called below
605 setUpdateEnabled( false );
607 // store selected objects
608 QStringList aSelectedEntries = storeSelection();
610 bool aDoFitAll = flags & UF_FitAll;
611 if( ( flags & UF_Viewer ) )
612 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
614 if( ( flags & UF_OCCViewer ) )
615 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
617 if( ( flags & UF_VTKViewer ) )
618 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
620 if( ( flags & UF_Model ) && getDataModel() && getApp() )
622 getDataModel()->update( getStudyId() );
624 // Temporary workaround to prevent breaking
625 // the selection in the object browser.
626 // Note: processEvents() should be called after updateGV(),
627 // otherwise the application crashes from time to time.
628 //RKV: qApp->processEvents();
629 getApp()->updateObjectBrowser( true );
632 // Object browser is currently updated by using UF_Model flag
633 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
634 getApp()->updateObjectBrowser( true );
636 if( ( flags & UF_Controls ) && getApp() )
637 getApp()->updateActions();
639 // restore selected objects
640 restoreSelection( aSelectedEntries );
642 setUpdateEnabled( true );
644 QApplication::restoreOverrideCursor();
647 void HYDROGUI_Module::updateCommandsStatus()
649 LightApp_Module::updateCommandsStatus();
651 updateUndoRedoControls();
653 action( CopyId )->setEnabled( getDataModel()->canCopy() );
654 action( PasteId )->setEnabled( getDataModel()->canPaste() );
657 void HYDROGUI_Module::selectionChanged()
659 LightApp_Module::selectionChanged();
660 updateCommandsStatus();
663 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
665 return (HYDROGUI_DataModel*)dataModel();
668 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
673 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
675 return myOCCDisplayer;
678 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
680 return myVTKDisplayer;
683 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
685 if( myViewManagerMap.contains( theId ) )
687 return myViewManagerMap[ theId ].first;
692 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
694 if( myViewManagerMap.contains( theId ) )
696 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
697 GraphicsView_ViewManager* aViewManager =
698 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
700 return aViewManager->getViewer();
705 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
707 if( myViewManagerMap.contains( theId ) )
709 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
710 OCCViewer_ViewManager* aViewManager =
711 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
713 return aViewManager->getOCCViewer();
718 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
720 if( myViewManagerMap.contains( theId ) )
722 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
723 SVTK_ViewManager* aViewManager =
724 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
726 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
731 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
733 ViewManagerMapIterator anIter( myViewManagerMap );
734 while( anIter.hasNext() )
736 int anId = anIter.next().key();
737 const ViewManagerInfo& anInfo = anIter.value();
738 if( anInfo.first == theViewManager )
744 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
746 int anId = getViewManagerId( theViewManager );
749 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
750 return anInfo.second;
755 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
756 const ViewManagerRole theRole )
758 int anId = getViewManagerId( theViewManager );
761 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
762 anInfo.second = theRole;
766 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
767 const Handle(HYDROData_Entity)& theObject ) const
769 if( theObject.IsNull() )
772 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
773 if( anIter1 != myObjectStateMap.end() )
775 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
776 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
777 if( anIter2 != aName2ObjectStateMap.end() )
779 const ObjectState& anObjectState = anIter2.value();
780 return anObjectState.Visibility;
786 void HYDROGUI_Module::setObjectVisible( const int theViewId,
787 const Handle(HYDROData_Entity)& theObject,
788 const bool theState )
790 if( !theObject.IsNull() )
792 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
793 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
794 anObjectState.Visibility = theState;
798 /////////////////// OCC SHAPES PROCESSING
799 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
800 const Handle(HYDROData_Entity)& theObject ) const
802 HYDROGUI_Shape* aResShape = NULL;
803 if( theObject.IsNull() )
806 if ( myShapesMap.contains( theViewId ) )
808 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
809 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
811 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
822 void HYDROGUI_Module::setObjectShape( const int theViewId,
823 const Handle(HYDROData_Entity)& theObject,
824 HYDROGUI_Shape* theShape )
826 if( theObject.IsNull() )
829 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
830 aViewShapes.append( theShape );
833 void HYDROGUI_Module::removeObjectShape( const int theViewId,
834 const Handle(HYDROData_Entity)& theObject )
836 if ( !myShapesMap.contains( theViewId ) )
839 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
840 Handle(HYDROData_Entity) anObject;
841 for ( int i = 0; i < aViewShapes.length(); )
843 HYDROGUI_Shape* aShape = aViewShapes.at( i );
844 anObject = aShape->getObject();
845 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
848 aViewShapes.removeAt( i );
856 void HYDROGUI_Module::removeViewShapes( const int theViewId )
858 if ( !myShapesMap.contains( theViewId ) )
861 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
862 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
864 HYDROGUI_Shape* aShape = aViewShapes.at( i );
869 myShapesMap.remove( theViewId );
871 /////////////////// END OF OCC SHAPES PROCESSING
873 /////////////////// VTKPrs PROCESSING
874 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
875 const Handle(HYDROData_Entity)& theObject ) const
877 HYDROGUI_VTKPrs* aResShape = NULL;
878 if( theObject.IsNull() )
881 if ( myVTKPrsMap.contains( theViewId ) )
883 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
884 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
886 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
897 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
898 const Handle(HYDROData_Entity)& theObject,
899 HYDROGUI_VTKPrs* theShape )
901 if( theObject.IsNull() )
904 // Compute the new global Z range from the added presentation and the old global Z range.
905 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
906 double* aRange = theShape->getInternalZRange();
907 bool anIsUpdate = false;
908 if ( aRange[0] < aGlobalRange[0] )
910 aGlobalRange[0] = aRange[0];
913 if ( aRange[1] > aGlobalRange[1] )
915 aGlobalRange[1] = aRange[1];
921 updateVTKZRange( theViewId, aGlobalRange );
924 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
925 aViewShapes.append( theShape );
928 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
929 const Handle(HYDROData_Entity)& theObject )
931 if ( !myVTKPrsMap.contains( theViewId ) )
934 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
935 Handle(HYDROData_Entity) anObject;
936 for ( int i = 0; i < aViewShapes.length(); )
938 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
939 anObject = aShape->getObject();
940 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
943 aViewShapes.removeAt( i );
950 // Invalidate global Z range
951 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
952 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
955 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
957 if ( !myVTKPrsMap.contains( theViewId ) )
960 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
961 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
963 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
968 myVTKPrsMap.remove( theViewId );
971 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
973 if ( myVTKPrsMap.contains( theViewId ) )
975 // For the given viewer id update all VTK presentations ...
976 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
977 HYDROGUI_VTKPrs* aShape;
978 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
980 aShape = aViewShapes.at( i );
983 aShape->setZRange( theRange );
987 // ... and update the global color legend scalar bar.
988 getVTKDisplayer()->SetZRange( theViewId, theRange );
990 /////////////////// END OF VTKPrs PROCESSING
992 CAM_DataModel* HYDROGUI_Module::createDataModel()
994 return new HYDROGUI_DataModel( this );
997 void HYDROGUI_Module::customEvent( QEvent* e )
999 int aType = e->type();
1000 if ( aType == NewViewEvent )
1002 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1003 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1005 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1007 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1008 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1010 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1012 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1013 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1015 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1016 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1017 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1019 //ouv: temporarily commented
1020 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1023 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1024 update( UF_Viewer );
1026 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1032 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1034 QEvent::Type aType = theEvent->type();
1035 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1037 if( aType == QEvent::Show )
1039 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1040 e->setData( theObj );
1041 QApplication::postEvent( this, e );
1042 theObj->removeEventFilter( this );
1045 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1047 if( aType == QEvent::Leave )
1049 SUIT_Desktop* aDesktop = getApp()->desktop();
1050 if ( aDesktop && aDesktop->statusBar() ) {
1051 aDesktop->statusBar()->clearMessage();
1056 return LightApp_Module::eventFilter( theObj, theEvent );
1059 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1061 LightApp_Module::onViewManagerAdded( theViewManager );
1063 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1065 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1066 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1068 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1070 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1071 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1072 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1073 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1076 createSelector( theViewManager ); // replace the default selector
1078 ViewManagerInfo anInfo( theViewManager, VMR_General );
1079 myViewManagerMap.insert( ViewManagerId++, anInfo );
1082 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1084 LightApp_Module::onViewManagerRemoved( theViewManager );
1086 createSelector( theViewManager ); // replace the default selector
1088 int anId = getViewManagerId( theViewManager );
1091 OCCViewer_ViewManager* anOCCViewManager =
1092 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1093 if ( anOCCViewManager )
1095 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1097 removeViewShapes( (size_t)anOCCViewer );
1100 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1102 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1105 getVTKDisplayer()->DeleteScalarBar( anId );
1106 removeViewShapes( (size_t)aVTKViewer );
1110 myViewManagerMap.remove( anId );
1114 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1116 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1118 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1120 aViewFrame->installEventFilter( this );
1122 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1124 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1125 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1128 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1130 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1132 aViewFrame->onTopView();
1134 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1136 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1138 aViewPort->installEventFilter( this );
1144 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1146 /* ouv: currently unused
1147 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1149 SUIT_ViewManager* aViewManager = 0;
1151 QObject* aParent = aViewPort;
1152 while( aParent = aParent->parent() )
1154 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1156 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1158 aViewManager = aViewer->getViewManager();
1167 double aMouseX = theEvent->scenePos().x();
1168 double aMouseY = theEvent->scenePos().y();
1170 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1171 if( aRole == VMR_General )
1173 int aXDeg = 0, aYDeg = 0;
1174 int aXMin = 0, aYMin = 0;
1175 double aXSec = 0, aYSec = 0;
1176 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1177 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1179 QString aDegSymbol( QChar( 0x00B0 ) );
1180 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1181 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1183 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1185 else if( aRole == VMR_TransformImage )
1186 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1191 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1192 const bool theIsInit,
1193 const bool theIsForced,
1194 const bool theDoFitAll )
1196 QList<int> aViewManagerIdList;
1198 // currently, all views are updated
1199 ViewManagerMapIterator anIter( myViewManagerMap );
1200 while( anIter.hasNext() )
1202 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1204 if ( theDisplayer->IsApplicable( aViewManager ) )
1206 int anId = anIter.key();
1207 aViewManagerIdList.append( anId );
1211 QListIterator<int> anIdIter( aViewManagerIdList );
1212 while( anIdIter.hasNext() )
1214 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1218 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1220 if( !theViewManager )
1223 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1224 if( !aSelectionMgr )
1227 QString aViewType = theViewManager->getType();
1228 if( aViewType != GraphicsView_Viewer::Type() &&
1229 aViewType != OCCViewer_Viewer::Type())
1232 QList<SUIT_Selector*> aSelectorList;
1233 aSelectionMgr->selectors( aViewType, aSelectorList );
1235 // disable all alien selectors
1236 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1237 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1239 SUIT_Selector* aSelector = *anIter;
1240 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1241 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1242 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1243 aSelector->setEnabled( false );
1246 if ( aViewType == GraphicsView_Viewer::Type() )
1248 GraphicsView_ViewManager* aViewManager =
1249 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1251 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1253 else if ( aViewType == OCCViewer_Viewer::Type() )
1255 OCCViewer_ViewManager* aViewManager =
1256 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1258 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1262 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1264 bool aPrevState = myIsUpdateEnabled;
1265 myIsUpdateEnabled = theState;
1269 bool HYDROGUI_Module::isUpdateEnabled() const
1271 return myIsUpdateEnabled;
1274 QStringList HYDROGUI_Module::storeSelection() const
1276 QStringList anEntryList;
1277 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1279 SUIT_DataOwnerPtrList aList( true );
1280 aSelectionMgr->selected( aList );
1282 SUIT_DataOwnerPtrList::iterator anIter;
1283 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1285 const LightApp_DataOwner* anOwner =
1286 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1288 anEntryList.append( anOwner->entry() );
1294 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1296 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1298 SUIT_DataOwnerPtrList aList( true );
1299 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1300 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1301 aSelectionMgr->setSelected( aList );
1305 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1307 OCCViewer_ViewWindow* anOCCViewWindow =
1308 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1309 if ( !anOCCViewWindow ) {
1313 // Get the selected point coordinates
1314 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1319 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1320 aViewPort->getView() );
1322 // Show the coordinates in the status bar
1323 SUIT_Desktop* aDesktop = getApp()->desktop();
1324 if ( aDesktop && aDesktop->statusBar() ) {
1325 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1326 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1327 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );