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 ) ) );
158 updateCommandsStatus();
160 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
161 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
163 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
165 ViewManagerList anOCCViewManagers;
166 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
167 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
168 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
169 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
170 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
171 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
172 if ( aViewFrame && aViewFrame->getViewPort() ) {
173 aViewFrame->getViewPort()->installEventFilter( this );
181 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
183 ViewManagerMapIterator anIter( myViewManagerMap );
184 while( anIter.hasNext() )
185 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
186 getApp()->removeViewManager( aViewManager );
187 myViewManagerMap.clear();
189 ViewManagerList anOCCViewManagers;
190 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
191 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
192 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
193 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
196 myObjectStateMap.clear();
200 // clear the data model's list of copying objects
201 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
203 setMenuShown( false );
204 setToolShown( false );
206 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
208 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
209 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
211 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
213 return LightApp_Module::deactivateModule( theStudy );
216 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
219 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
220 #ifndef DISABLE_PYCONSOLE
221 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
223 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
226 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
228 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
231 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
235 HYDROGUI_DataModel* aModel = getDataModel();
237 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
238 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
239 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
240 bool anIsVTKView = theClient == SVTK_Viewer::Type();
241 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
244 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
246 bool anIsSelectedDataObjects = false;
247 bool anIsVisibleInSelection = false;
248 bool anIsHiddenInSelection = false;
250 bool anIsImage = false;
251 bool anIsImportedImage = false;
252 bool anIsImageHasRefs = false;
253 bool anIsFusedImage = false;
254 bool anIsCutImage = false;
255 bool anIsSplittedImage = false;
256 bool anIsMustBeUpdatedImage = false;
257 bool anIsPolyline = false;
258 bool anIsPolyline3D = false;
259 bool anIsProfile = false;
260 bool anIsValidProfile = false;
261 bool anAllAreProfiles = false;
262 bool anIsBathymetry = false;
263 bool anIsCalculation = false;
264 bool anIsImmersibleZone = false;
265 bool anIsVisualState = false;
266 bool anIsRegion = false;
267 bool anIsZone = false;
268 bool anIsObstacle = false;
269 bool anIsStream = false;
270 bool anIsChannel = false;
271 bool anIsGeomObject = false;
273 // check the selected GEOM objects
274 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
275 theMenu->addAction( action( ImportGeomObjectId ) );
276 theMenu->addSeparator();
279 // check the selected data model objects
280 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
281 int aNbOfSelectedProfiles = 0;
282 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
284 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
285 if( !anObject.IsNull() )
287 anIsSelectedDataObjects = true;
289 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
290 anIsVisibleInSelection |= aVisibility;
291 anIsHiddenInSelection |= !aVisibility;
293 ObjectKind anObjectKind = anObject->GetKind();
294 if( anObjectKind == KIND_IMAGE )
297 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
298 if( !anImage.IsNull() )
300 anIsImportedImage = anImage->HasLocalPoints();
301 anIsImageHasRefs = anImage->HasReferences();
302 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
304 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
306 QString anOperatorName = anOperator->name();
307 if( anOperatorName == ImageComposer_FuseOperator::Type() )
308 anIsFusedImage = true;
309 else if( anOperatorName == ImageComposer_CutOperator::Type() )
311 else if( anOperatorName == ImageComposer_CropOperator::Type() )
312 anIsSplittedImage = true;
315 if ( anImage->IsMustBeUpdated() )
317 anIsMustBeUpdatedImage = true;
321 else if( anObjectKind == KIND_POLYLINEXY )
323 else if( anObjectKind == KIND_POLYLINE )
324 anIsPolyline3D = true;
325 else if( anObjectKind == KIND_PROFILE )
328 aNbOfSelectedProfiles++;
330 Handle(HYDROData_Profile) aProfile =
331 Handle(HYDROData_Profile)::DownCast( anObject );
332 if( !aProfile.IsNull() && aProfile->IsValid() ) {
333 anIsValidProfile = true;
336 else if( anObjectKind == KIND_CALCULATION )
337 anIsCalculation = true;
338 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
339 anIsImmersibleZone = true;
340 else if( anObjectKind == KIND_VISUAL_STATE )
341 anIsVisualState = true;
342 else if( anObjectKind == KIND_REGION )
344 else if( anObjectKind == KIND_ZONE )
346 else if( anObjectKind == KIND_BATHYMETRY )
347 anIsBathymetry = true;
348 else if( anObjectKind == KIND_OBSTACLE )
350 else if( anObjectKind == KIND_STREAM )
352 else if( anObjectKind == KIND_CHANNEL )
356 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
359 // Check if all selected objects are profiles
360 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
361 ( aNbOfSelectedProfiles == aSeq.Length() );
363 // check the selected partitions
364 if( !anIsSelectedDataObjects && anIsObjectBrowser )
366 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
367 if( aSelectedPartition != KIND_UNKNOWN )
369 switch( aSelectedPartition )
372 theMenu->addAction( action( ImportImageId ) );
374 case KIND_BATHYMETRY:
375 theMenu->addAction( action( ImportBathymetryId ) );
377 case KIND_ARTIFICIAL_OBJECT:
378 theMenu->addAction( action( CreateChannelId ) );
380 case KIND_NATURAL_OBJECT:
381 theMenu->addAction( action( CreateImmersibleZoneId ) );
382 theMenu->addAction( action( CreateStreamId ) );
385 theMenu->addAction( action( ImportObstacleFromFileId ) );
386 theMenu->addAction( action( CreateBoxId ) );
387 theMenu->addAction( action( CreateCylinderId ) );
389 case KIND_CALCULATION:
390 theMenu->addAction( action( CreateCalculationId ) );
392 case KIND_POLYLINEXY:
393 theMenu->addAction( action( CreatePolylineId ) );
396 theMenu->addAction( action( CreatePolyline3DId ) );
399 theMenu->addAction( action( CreateProfileId ) );
400 theMenu->addAction( action( ImportProfilesId ) );
401 theMenu->addAction( action( AllGeoreferencementId ) );
403 case KIND_VISUAL_STATE:
404 theMenu->addAction( action( SaveVisualStateId ) );
407 theMenu->addSeparator();
411 if( anIsSelectedDataObjects )
413 if ( anIsMustBeUpdatedImage )
415 theMenu->addAction( action( UpdateImageId ) );
416 theMenu->addSeparator();
419 if( aSeq.Length() == 1 )
423 if( anIsImportedImage )
424 theMenu->addAction( action( EditImportedImageId ) );
425 else if( anIsImageHasRefs )
428 theMenu->addAction( action( EditFusedImageId ) );
429 else if( anIsCutImage )
430 theMenu->addAction( action( EditCutImageId ) );
431 else if( anIsSplittedImage )
432 theMenu->addAction( action( EditSplittedImageId ) );
435 theMenu->addAction( action( ObserveImageId ) );
436 theMenu->addAction( action( ExportImageId ) );
437 theMenu->addSeparator();
439 if( anIsImageHasRefs )
441 theMenu->addAction( action( RemoveImageRefsId ) );
442 theMenu->addSeparator();
445 theMenu->addAction( action( FuseImagesId ) );
446 theMenu->addAction( action( CutImagesId ) );
447 theMenu->addAction( action( SplitImageId ) );
448 theMenu->addSeparator();
450 else if( anIsPolyline )
452 theMenu->addAction( action( EditPolylineId ) );
453 theMenu->addSeparator();
455 else if( anIsPolyline3D )
457 theMenu->addAction( action( EditPolyline3DId ) );
458 theMenu->addSeparator();
460 else if( anIsProfile )
462 theMenu->addAction( action( EditProfileId ) );
463 theMenu->addAction( action( SelectedGeoreferencementId ) );
464 theMenu->addSeparator();
466 else if( anIsCalculation )
468 theMenu->addAction( action( EditCalculationId ) );
469 theMenu->addAction( action( ExportCalculationId ) );
470 theMenu->addSeparator();
472 else if( anIsImmersibleZone )
474 theMenu->addAction( action( EditImmersibleZoneId ) );
475 theMenu->addSeparator();
477 else if( anIsStream )
479 theMenu->addAction( action( EditStreamId ) );
480 theMenu->addSeparator();
482 else if( anIsChannel )
484 theMenu->addAction( action( EditChannelId ) );
485 theMenu->addSeparator();
487 else if( anIsVisualState && anIsObjectBrowser )
489 theMenu->addAction( action( SaveVisualStateId ) );
490 theMenu->addAction( action( LoadVisualStateId ) );
491 theMenu->addSeparator();
494 // Add set color action for geometrical objects
495 if ( anIsGeomObject )
497 theMenu->addAction( action( SetColorId ) );
498 theMenu->addSeparator();
500 } else if ( anAllAreProfiles ) {
501 theMenu->addAction( action( SelectedGeoreferencementId ) );
502 theMenu->addSeparator();
505 theMenu->addAction( action( DeleteId ) );
506 theMenu->addSeparator();
508 if( anIsImage || anIsPolyline || anIsPolyline3D ||
509 anIsImmersibleZone || anIsZone || anIsRegion ||
510 anIsBathymetry || anIsObstacle || anIsStream ||
511 anIsChannel || anIsValidProfile )
513 if( anIsHiddenInSelection )
514 theMenu->addAction( action( ShowId ) );
515 theMenu->addAction( action( ShowOnlyId ) );
516 if( anIsVisibleInSelection )
517 theMenu->addAction( action( HideId ) );
518 theMenu->addSeparator();
524 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
525 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
526 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
527 theMenu->addAction( action( DeleteId ) );
530 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
532 theMenu->addAction( action( ShowAllId ) );
533 theMenu->addAction( action( HideAllId ) );
534 theMenu->addSeparator();
538 void HYDROGUI_Module::update( const int flags )
540 if( !isUpdateEnabled() )
543 QApplication::setOverrideCursor( Qt::WaitCursor );
545 // To prevent calling this method recursively
546 // from one of the methods called below
547 setUpdateEnabled( false );
549 // store selected objects
550 QStringList aSelectedEntries = storeSelection();
552 bool aDoFitAll = flags & UF_FitAll;
553 if( ( flags & UF_Viewer ) )
554 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
556 if( ( flags & UF_OCCViewer ) )
557 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
559 if( ( flags & UF_VTKViewer ) )
560 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
562 if( ( flags & UF_Model ) && getDataModel() && getApp() )
564 getDataModel()->update( getStudyId() );
566 // Temporary workaround to prevent breaking
567 // the selection in the object browser.
568 // Note: processEvents() should be called after updateGV(),
569 // otherwise the application crashes from time to time.
570 //RKV: qApp->processEvents();
571 getApp()->updateObjectBrowser( true );
574 // Object browser is currently updated by using UF_Model flag
575 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
576 getApp()->updateObjectBrowser( true );
578 if( ( flags & UF_Controls ) && getApp() )
579 getApp()->updateActions();
581 // restore selected objects
582 restoreSelection( aSelectedEntries );
584 setUpdateEnabled( true );
586 QApplication::restoreOverrideCursor();
589 void HYDROGUI_Module::updateCommandsStatus()
591 LightApp_Module::updateCommandsStatus();
593 updateUndoRedoControls();
595 action( CopyId )->setEnabled( getDataModel()->canCopy() );
596 action( PasteId )->setEnabled( getDataModel()->canPaste() );
599 void HYDROGUI_Module::selectionChanged()
601 LightApp_Module::selectionChanged();
602 updateCommandsStatus();
605 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
607 return (HYDROGUI_DataModel*)dataModel();
610 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
615 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
617 return myOCCDisplayer;
620 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
622 return myVTKDisplayer;
625 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
627 if( myViewManagerMap.contains( theId ) )
629 return myViewManagerMap[ theId ].first;
634 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
636 if( myViewManagerMap.contains( theId ) )
638 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
639 GraphicsView_ViewManager* aViewManager =
640 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
642 return aViewManager->getViewer();
647 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
649 if( myViewManagerMap.contains( theId ) )
651 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
652 OCCViewer_ViewManager* aViewManager =
653 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
655 return aViewManager->getOCCViewer();
660 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
662 if( myViewManagerMap.contains( theId ) )
664 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
665 SVTK_ViewManager* aViewManager =
666 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
668 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
673 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
675 ViewManagerMapIterator anIter( myViewManagerMap );
676 while( anIter.hasNext() )
678 int anId = anIter.next().key();
679 const ViewManagerInfo& anInfo = anIter.value();
680 if( anInfo.first == theViewManager )
686 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
688 int anId = getViewManagerId( theViewManager );
691 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
692 return anInfo.second;
697 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
698 const ViewManagerRole theRole )
700 int anId = getViewManagerId( theViewManager );
703 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
704 anInfo.second = theRole;
708 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
709 const Handle(HYDROData_Entity)& theObject ) const
711 if( theObject.IsNull() )
714 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
715 if( anIter1 != myObjectStateMap.end() )
717 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
718 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
719 if( anIter2 != aName2ObjectStateMap.end() )
721 const ObjectState& anObjectState = anIter2.value();
722 return anObjectState.Visibility;
728 void HYDROGUI_Module::setObjectVisible( const int theViewId,
729 const Handle(HYDROData_Entity)& theObject,
730 const bool theState )
732 if( !theObject.IsNull() )
734 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
735 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
736 anObjectState.Visibility = theState;
740 /////////////////// OCC SHAPES PROCESSING
741 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
742 const Handle(HYDROData_Entity)& theObject ) const
744 HYDROGUI_Shape* aResShape = NULL;
745 if( theObject.IsNull() )
748 if ( myShapesMap.contains( theViewId ) )
750 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
751 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
753 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
764 void HYDROGUI_Module::setObjectShape( const int theViewId,
765 const Handle(HYDROData_Entity)& theObject,
766 HYDROGUI_Shape* theShape )
768 if( theObject.IsNull() )
771 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
772 aViewShapes.append( theShape );
775 void HYDROGUI_Module::removeObjectShape( const int theViewId,
776 const Handle(HYDROData_Entity)& theObject )
778 if ( !myShapesMap.contains( theViewId ) )
781 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
782 Handle(HYDROData_Entity) anObject;
783 for ( int i = 0; i < aViewShapes.length(); )
785 HYDROGUI_Shape* aShape = aViewShapes.at( i );
786 anObject = aShape->getObject();
787 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
790 aViewShapes.removeAt( i );
798 void HYDROGUI_Module::removeViewShapes( const int theViewId )
800 if ( !myShapesMap.contains( theViewId ) )
803 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
804 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
806 HYDROGUI_Shape* aShape = aViewShapes.at( i );
811 myShapesMap.remove( theViewId );
813 /////////////////// END OF OCC SHAPES PROCESSING
815 /////////////////// VTKPrs PROCESSING
816 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
817 const Handle(HYDROData_Entity)& theObject ) const
819 HYDROGUI_VTKPrs* aResShape = NULL;
820 if( theObject.IsNull() )
823 if ( myVTKPrsMap.contains( theViewId ) )
825 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
826 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
828 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
839 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
840 const Handle(HYDROData_Entity)& theObject,
841 HYDROGUI_VTKPrs* theShape )
843 if( theObject.IsNull() )
846 // Compute the new global Z range from the added presentation and the old global Z range.
847 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
848 double* aRange = theShape->getInternalZRange();
849 bool anIsUpdate = false;
850 if ( aRange[0] < aGlobalRange[0] )
852 aGlobalRange[0] = aRange[0];
855 if ( aRange[1] > aGlobalRange[1] )
857 aGlobalRange[1] = aRange[1];
863 updateVTKZRange( theViewId, aGlobalRange );
866 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
867 aViewShapes.append( theShape );
870 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
871 const Handle(HYDROData_Entity)& theObject )
873 if ( !myVTKPrsMap.contains( theViewId ) )
876 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
877 Handle(HYDROData_Entity) anObject;
878 for ( int i = 0; i < aViewShapes.length(); )
880 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
881 anObject = aShape->getObject();
882 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
885 aViewShapes.removeAt( i );
892 // Invalidate global Z range
893 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
894 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
897 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
899 if ( !myVTKPrsMap.contains( theViewId ) )
902 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
903 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
905 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
910 myVTKPrsMap.remove( theViewId );
913 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
915 if ( myVTKPrsMap.contains( theViewId ) )
917 // For the given viewer id update all VTK presentations ...
918 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
919 HYDROGUI_VTKPrs* aShape;
920 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
922 aShape = aViewShapes.at( i );
925 aShape->setZRange( theRange );
929 // ... and update the global color legend scalar bar.
930 getVTKDisplayer()->SetZRange( theViewId, theRange );
932 /////////////////// END OF VTKPrs PROCESSING
934 CAM_DataModel* HYDROGUI_Module::createDataModel()
936 return new HYDROGUI_DataModel( this );
939 void HYDROGUI_Module::customEvent( QEvent* e )
941 int aType = e->type();
942 if ( aType == NewViewEvent )
944 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
945 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
947 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
949 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
950 ViewManagerRole aRole = getViewManagerRole( aViewManager );
952 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
954 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
955 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
957 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
958 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
959 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
961 //ouv: temporarily commented
962 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
965 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
968 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
974 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
976 QEvent::Type aType = theEvent->type();
977 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
979 if( aType == QEvent::Show )
981 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
982 e->setData( theObj );
983 QApplication::postEvent( this, e );
984 theObj->removeEventFilter( this );
987 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
989 if( aType == QEvent::Leave )
991 SUIT_Desktop* aDesktop = getApp()->desktop();
992 if ( aDesktop && aDesktop->statusBar() ) {
993 aDesktop->statusBar()->clearMessage();
998 return LightApp_Module::eventFilter( theObj, theEvent );
1001 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1003 LightApp_Module::onViewManagerAdded( theViewManager );
1005 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1007 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1008 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1010 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1012 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1013 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1014 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1015 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1018 createSelector( theViewManager ); // replace the default selector
1020 ViewManagerInfo anInfo( theViewManager, VMR_General );
1021 myViewManagerMap.insert( ViewManagerId++, anInfo );
1024 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1026 LightApp_Module::onViewManagerRemoved( theViewManager );
1028 createSelector( theViewManager ); // replace the default selector
1030 int anId = getViewManagerId( theViewManager );
1033 OCCViewer_ViewManager* anOCCViewManager =
1034 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1035 if ( anOCCViewManager )
1037 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1039 removeViewShapes( (size_t)anOCCViewer );
1042 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1044 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1047 getVTKDisplayer()->DeleteScalarBar( anId );
1048 removeViewShapes( (size_t)aVTKViewer );
1052 myViewManagerMap.remove( anId );
1056 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1058 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1060 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1062 aViewFrame->installEventFilter( this );
1064 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1066 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1067 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1070 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1072 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1074 aViewFrame->onTopView();
1076 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1078 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1080 aViewPort->installEventFilter( this );
1086 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1088 /* ouv: currently unused
1089 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1091 SUIT_ViewManager* aViewManager = 0;
1093 QObject* aParent = aViewPort;
1094 while( aParent = aParent->parent() )
1096 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1098 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1100 aViewManager = aViewer->getViewManager();
1109 double aMouseX = theEvent->scenePos().x();
1110 double aMouseY = theEvent->scenePos().y();
1112 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1113 if( aRole == VMR_General )
1115 int aXDeg = 0, aYDeg = 0;
1116 int aXMin = 0, aYMin = 0;
1117 double aXSec = 0, aYSec = 0;
1118 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1119 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1121 QString aDegSymbol( QChar( 0x00B0 ) );
1122 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1123 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1125 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1127 else if( aRole == VMR_TransformImage )
1128 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1133 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1134 const bool theIsInit,
1135 const bool theIsForced,
1136 const bool theDoFitAll )
1138 QList<int> aViewManagerIdList;
1140 // currently, all views are updated
1141 ViewManagerMapIterator anIter( myViewManagerMap );
1142 while( anIter.hasNext() )
1144 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1146 if ( theDisplayer->IsApplicable( aViewManager ) )
1148 int anId = anIter.key();
1149 aViewManagerIdList.append( anId );
1153 QListIterator<int> anIdIter( aViewManagerIdList );
1154 while( anIdIter.hasNext() )
1156 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1160 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1162 if( !theViewManager )
1165 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1166 if( !aSelectionMgr )
1169 QString aViewType = theViewManager->getType();
1170 if( aViewType != GraphicsView_Viewer::Type() &&
1171 aViewType != OCCViewer_Viewer::Type())
1174 QList<SUIT_Selector*> aSelectorList;
1175 aSelectionMgr->selectors( aViewType, aSelectorList );
1177 // disable all alien selectors
1178 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1179 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1181 SUIT_Selector* aSelector = *anIter;
1182 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1183 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1184 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1185 aSelector->setEnabled( false );
1188 if ( aViewType == GraphicsView_Viewer::Type() )
1190 GraphicsView_ViewManager* aViewManager =
1191 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1193 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1195 else if ( aViewType == OCCViewer_Viewer::Type() )
1197 OCCViewer_ViewManager* aViewManager =
1198 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1200 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1204 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1206 bool aPrevState = myIsUpdateEnabled;
1207 myIsUpdateEnabled = theState;
1211 bool HYDROGUI_Module::isUpdateEnabled() const
1213 return myIsUpdateEnabled;
1216 QStringList HYDROGUI_Module::storeSelection() const
1218 QStringList anEntryList;
1219 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1221 SUIT_DataOwnerPtrList aList( true );
1222 aSelectionMgr->selected( aList );
1224 SUIT_DataOwnerPtrList::iterator anIter;
1225 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1227 const LightApp_DataOwner* anOwner =
1228 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1230 anEntryList.append( anOwner->entry() );
1236 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1238 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1240 SUIT_DataOwnerPtrList aList( true );
1241 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1242 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1243 aSelectionMgr->setSelected( aList );
1247 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1249 OCCViewer_ViewWindow* anOCCViewWindow =
1250 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1251 if ( !anOCCViewWindow ) {
1255 // Get the selected point coordinates
1256 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1261 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1262 aViewPort->getView() );
1264 // Show the coordinates in the status bar
1265 SUIT_Desktop* aDesktop = getApp()->desktop();
1266 if ( aDesktop && aDesktop->statusBar() ) {
1267 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1268 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1269 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );