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 anIsMustobjectBeUpdated = 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 if ( anObject->IsMustBeUpdated() )
295 anIsMustobjectBeUpdated = true;
298 ObjectKind anObjectKind = anObject->GetKind();
299 if( anObjectKind == KIND_IMAGE )
302 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
303 if( !anImage.IsNull() )
305 anIsImportedImage = anImage->HasLocalPoints();
306 anIsImageHasRefs = anImage->HasReferences();
307 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
309 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
311 QString anOperatorName = anOperator->name();
312 if( anOperatorName == ImageComposer_FuseOperator::Type() )
313 anIsFusedImage = true;
314 else if( anOperatorName == ImageComposer_CutOperator::Type() )
316 else if( anOperatorName == ImageComposer_CropOperator::Type() )
317 anIsSplittedImage = true;
322 else if( anObjectKind == KIND_POLYLINEXY )
324 else if( anObjectKind == KIND_POLYLINE )
325 anIsPolyline3D = true;
326 else if( anObjectKind == KIND_PROFILE )
329 aNbOfSelectedProfiles++;
331 Handle(HYDROData_Profile) aProfile =
332 Handle(HYDROData_Profile)::DownCast( anObject );
333 if( !aProfile.IsNull() && aProfile->IsValid() ) {
334 anIsValidProfile = true;
337 else if( anObjectKind == KIND_CALCULATION )
338 anIsCalculation = true;
339 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
340 anIsImmersibleZone = true;
341 else if( anObjectKind == KIND_VISUAL_STATE )
342 anIsVisualState = true;
343 else if( anObjectKind == KIND_REGION )
345 else if( anObjectKind == KIND_ZONE )
347 else if( anObjectKind == KIND_BATHYMETRY )
348 anIsBathymetry = true;
349 else if( anObjectKind == KIND_OBSTACLE )
351 else if( anObjectKind == KIND_STREAM )
353 else if( anObjectKind == KIND_CHANNEL )
357 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
360 // Check if all selected objects are profiles
361 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
362 ( aNbOfSelectedProfiles == aSeq.Length() );
364 // check the selected partitions
365 if( !anIsSelectedDataObjects && anIsObjectBrowser )
367 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
368 if( aSelectedPartition != KIND_UNKNOWN )
370 switch( aSelectedPartition )
373 theMenu->addAction( action( ImportImageId ) );
375 case KIND_BATHYMETRY:
376 theMenu->addAction( action( ImportBathymetryId ) );
378 case KIND_ARTIFICIAL_OBJECT:
379 theMenu->addAction( action( CreateChannelId ) );
381 case KIND_NATURAL_OBJECT:
382 theMenu->addAction( action( CreateImmersibleZoneId ) );
383 theMenu->addAction( action( CreateStreamId ) );
386 theMenu->addAction( action( ImportObstacleFromFileId ) );
387 theMenu->addAction( action( CreateBoxId ) );
388 theMenu->addAction( action( CreateCylinderId ) );
390 case KIND_CALCULATION:
391 theMenu->addAction( action( CreateCalculationId ) );
393 case KIND_POLYLINEXY:
394 theMenu->addAction( action( CreatePolylineId ) );
397 theMenu->addAction( action( CreatePolyline3DId ) );
400 theMenu->addAction( action( CreateProfileId ) );
401 theMenu->addAction( action( ImportProfilesId ) );
402 theMenu->addAction( action( AllGeoreferencementId ) );
404 case KIND_VISUAL_STATE:
405 theMenu->addAction( action( SaveVisualStateId ) );
408 theMenu->addSeparator();
412 if( anIsSelectedDataObjects )
414 if ( anIsMustobjectBeUpdated )
416 theMenu->addAction( action( UpdateObjectId ) );
417 theMenu->addSeparator();
420 if( aSeq.Length() == 1 )
424 if( anIsImportedImage )
425 theMenu->addAction( action( EditImportedImageId ) );
426 else if( anIsImageHasRefs )
429 theMenu->addAction( action( EditFusedImageId ) );
430 else if( anIsCutImage )
431 theMenu->addAction( action( EditCutImageId ) );
432 else if( anIsSplittedImage )
433 theMenu->addAction( action( EditSplittedImageId ) );
436 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
437 theMenu->addAction( action( ExportImageId ) );
438 theMenu->addSeparator();
440 if( anIsImageHasRefs )
442 theMenu->addAction( action( RemoveImageRefsId ) );
443 theMenu->addSeparator();
446 theMenu->addAction( action( FuseImagesId ) );
447 theMenu->addAction( action( CutImagesId ) );
448 theMenu->addAction( action( SplitImageId ) );
449 theMenu->addSeparator();
451 else if( anIsBathymetry )
453 theMenu->addAction( action( EditImportedBathymetryId ) );
454 theMenu->addSeparator();
456 else if( anIsPolyline )
458 theMenu->addAction( action( EditPolylineId ) );
459 theMenu->addSeparator();
461 else if( anIsPolyline3D )
463 theMenu->addAction( action( EditPolyline3DId ) );
464 theMenu->addSeparator();
466 else if( anIsProfile )
468 theMenu->addAction( action( EditProfileId ) );
469 theMenu->addAction( action( SelectedGeoreferencementId ) );
470 theMenu->addSeparator();
472 else if( anIsCalculation )
474 theMenu->addAction( action( EditCalculationId ) );
475 theMenu->addAction( action( ExportCalculationId ) );
476 theMenu->addSeparator();
478 else if( anIsImmersibleZone )
480 theMenu->addAction( action( EditImmersibleZoneId ) );
481 theMenu->addSeparator();
483 else if( anIsStream )
485 theMenu->addAction( action( EditStreamId ) );
486 theMenu->addSeparator();
488 else if( anIsChannel )
490 theMenu->addAction( action( EditChannelId ) );
491 theMenu->addSeparator();
493 else if( anIsVisualState && anIsObjectBrowser )
495 theMenu->addAction( action( SaveVisualStateId ) );
496 theMenu->addAction( action( LoadVisualStateId ) );
497 theMenu->addSeparator();
500 // Add set color action for geometrical objects
501 if ( anIsGeomObject )
503 theMenu->addAction( action( SetColorId ) );
504 theMenu->addSeparator();
506 } else if ( anAllAreProfiles ) {
507 theMenu->addAction( action( SelectedGeoreferencementId ) );
508 theMenu->addSeparator();
511 theMenu->addAction( action( DeleteId ) );
512 theMenu->addSeparator();
514 if( anIsImage || anIsPolyline || anIsPolyline3D ||
515 anIsImmersibleZone || anIsZone || anIsRegion ||
516 anIsBathymetry || anIsObstacle || anIsStream ||
517 anIsChannel || anIsValidProfile )
519 if( anIsHiddenInSelection )
520 theMenu->addAction( action( ShowId ) );
521 theMenu->addAction( action( ShowOnlyId ) );
522 if( anIsVisibleInSelection )
523 theMenu->addAction( action( HideId ) );
524 theMenu->addSeparator();
530 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
531 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
532 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
533 theMenu->addAction( action( DeleteId ) );
536 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
538 theMenu->addAction( action( ShowAllId ) );
539 theMenu->addAction( action( HideAllId ) );
540 theMenu->addSeparator();
544 void HYDROGUI_Module::update( const int flags )
546 if( !isUpdateEnabled() )
549 QApplication::setOverrideCursor( Qt::WaitCursor );
551 // To prevent calling this method recursively
552 // from one of the methods called below
553 setUpdateEnabled( false );
555 // store selected objects
556 QStringList aSelectedEntries = storeSelection();
558 bool aDoFitAll = flags & UF_FitAll;
559 if( ( flags & UF_Viewer ) )
560 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
562 if( ( flags & UF_OCCViewer ) )
563 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
565 if( ( flags & UF_VTKViewer ) )
566 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
568 if( ( flags & UF_Model ) && getDataModel() && getApp() )
570 getDataModel()->update( getStudyId() );
572 // Temporary workaround to prevent breaking
573 // the selection in the object browser.
574 // Note: processEvents() should be called after updateGV(),
575 // otherwise the application crashes from time to time.
576 //RKV: qApp->processEvents();
577 getApp()->updateObjectBrowser( true );
580 // Object browser is currently updated by using UF_Model flag
581 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
582 getApp()->updateObjectBrowser( true );
584 if( ( flags & UF_Controls ) && getApp() )
585 getApp()->updateActions();
587 // restore selected objects
588 restoreSelection( aSelectedEntries );
590 setUpdateEnabled( true );
592 QApplication::restoreOverrideCursor();
595 void HYDROGUI_Module::updateCommandsStatus()
597 LightApp_Module::updateCommandsStatus();
599 updateUndoRedoControls();
601 action( CopyId )->setEnabled( getDataModel()->canCopy() );
602 action( PasteId )->setEnabled( getDataModel()->canPaste() );
605 void HYDROGUI_Module::selectionChanged()
607 LightApp_Module::selectionChanged();
608 updateCommandsStatus();
611 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
613 return (HYDROGUI_DataModel*)dataModel();
616 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
621 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
623 return myOCCDisplayer;
626 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
628 return myVTKDisplayer;
631 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
633 if( myViewManagerMap.contains( theId ) )
635 return myViewManagerMap[ theId ].first;
640 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
642 if( myViewManagerMap.contains( theId ) )
644 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
645 GraphicsView_ViewManager* aViewManager =
646 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
648 return aViewManager->getViewer();
653 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
655 if( myViewManagerMap.contains( theId ) )
657 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
658 OCCViewer_ViewManager* aViewManager =
659 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
661 return aViewManager->getOCCViewer();
666 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
668 if( myViewManagerMap.contains( theId ) )
670 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
671 SVTK_ViewManager* aViewManager =
672 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
674 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
679 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
681 ViewManagerMapIterator anIter( myViewManagerMap );
682 while( anIter.hasNext() )
684 int anId = anIter.next().key();
685 const ViewManagerInfo& anInfo = anIter.value();
686 if( anInfo.first == theViewManager )
692 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
694 int anId = getViewManagerId( theViewManager );
697 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
698 return anInfo.second;
703 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
704 const ViewManagerRole theRole )
706 int anId = getViewManagerId( theViewManager );
709 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
710 anInfo.second = theRole;
714 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
715 const Handle(HYDROData_Entity)& theObject ) const
717 if( theObject.IsNull() )
720 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
721 if( anIter1 != myObjectStateMap.end() )
723 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
724 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
725 if( anIter2 != aName2ObjectStateMap.end() )
727 const ObjectState& anObjectState = anIter2.value();
728 return anObjectState.Visibility;
734 void HYDROGUI_Module::setObjectVisible( const int theViewId,
735 const Handle(HYDROData_Entity)& theObject,
736 const bool theState )
738 if( !theObject.IsNull() )
740 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
741 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
742 anObjectState.Visibility = theState;
746 /////////////////// OCC SHAPES PROCESSING
747 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
748 const Handle(HYDROData_Entity)& theObject ) const
750 HYDROGUI_Shape* aResShape = NULL;
751 if( theObject.IsNull() )
754 if ( myShapesMap.contains( theViewId ) )
756 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
757 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
759 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
770 void HYDROGUI_Module::setObjectShape( const int theViewId,
771 const Handle(HYDROData_Entity)& theObject,
772 HYDROGUI_Shape* theShape )
774 if( theObject.IsNull() )
777 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
778 aViewShapes.append( theShape );
781 void HYDROGUI_Module::removeObjectShape( const int theViewId,
782 const Handle(HYDROData_Entity)& theObject )
784 if ( !myShapesMap.contains( theViewId ) )
787 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
788 Handle(HYDROData_Entity) anObject;
789 for ( int i = 0; i < aViewShapes.length(); )
791 HYDROGUI_Shape* aShape = aViewShapes.at( i );
792 anObject = aShape->getObject();
793 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
796 aViewShapes.removeAt( i );
804 void HYDROGUI_Module::removeViewShapes( const int theViewId )
806 if ( !myShapesMap.contains( theViewId ) )
809 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
810 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
812 HYDROGUI_Shape* aShape = aViewShapes.at( i );
817 myShapesMap.remove( theViewId );
819 /////////////////// END OF OCC SHAPES PROCESSING
821 /////////////////// VTKPrs PROCESSING
822 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
823 const Handle(HYDROData_Entity)& theObject ) const
825 HYDROGUI_VTKPrs* aResShape = NULL;
826 if( theObject.IsNull() )
829 if ( myVTKPrsMap.contains( theViewId ) )
831 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
832 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
834 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
845 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
846 const Handle(HYDROData_Entity)& theObject,
847 HYDROGUI_VTKPrs* theShape )
849 if( theObject.IsNull() )
852 // Compute the new global Z range from the added presentation and the old global Z range.
853 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
854 double* aRange = theShape->getInternalZRange();
855 bool anIsUpdate = false;
856 if ( aRange[0] < aGlobalRange[0] )
858 aGlobalRange[0] = aRange[0];
861 if ( aRange[1] > aGlobalRange[1] )
863 aGlobalRange[1] = aRange[1];
869 updateVTKZRange( theViewId, aGlobalRange );
872 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
873 aViewShapes.append( theShape );
876 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
877 const Handle(HYDROData_Entity)& theObject )
879 if ( !myVTKPrsMap.contains( theViewId ) )
882 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
883 Handle(HYDROData_Entity) anObject;
884 for ( int i = 0; i < aViewShapes.length(); )
886 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
887 anObject = aShape->getObject();
888 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
891 aViewShapes.removeAt( i );
898 // Invalidate global Z range
899 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
900 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
903 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
905 if ( !myVTKPrsMap.contains( theViewId ) )
908 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
909 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
911 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
916 myVTKPrsMap.remove( theViewId );
919 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
921 if ( myVTKPrsMap.contains( theViewId ) )
923 // For the given viewer id update all VTK presentations ...
924 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
925 HYDROGUI_VTKPrs* aShape;
926 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
928 aShape = aViewShapes.at( i );
931 aShape->setZRange( theRange );
935 // ... and update the global color legend scalar bar.
936 getVTKDisplayer()->SetZRange( theViewId, theRange );
938 /////////////////// END OF VTKPrs PROCESSING
940 CAM_DataModel* HYDROGUI_Module::createDataModel()
942 return new HYDROGUI_DataModel( this );
945 void HYDROGUI_Module::customEvent( QEvent* e )
947 int aType = e->type();
948 if ( aType == NewViewEvent )
950 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
951 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
953 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
955 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
956 ViewManagerRole aRole = getViewManagerRole( aViewManager );
958 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
960 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
961 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
963 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
964 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
965 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
967 //ouv: temporarily commented
968 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
971 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
974 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
980 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
982 QEvent::Type aType = theEvent->type();
983 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
985 if( aType == QEvent::Show )
987 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
988 e->setData( theObj );
989 QApplication::postEvent( this, e );
990 theObj->removeEventFilter( this );
993 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
995 if( aType == QEvent::Leave )
997 SUIT_Desktop* aDesktop = getApp()->desktop();
998 if ( aDesktop && aDesktop->statusBar() ) {
999 aDesktop->statusBar()->clearMessage();
1004 return LightApp_Module::eventFilter( theObj, theEvent );
1007 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1009 LightApp_Module::onViewManagerAdded( theViewManager );
1011 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1013 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1014 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1016 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1018 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1019 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1020 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1021 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1024 createSelector( theViewManager ); // replace the default selector
1026 ViewManagerInfo anInfo( theViewManager, VMR_General );
1027 myViewManagerMap.insert( ViewManagerId++, anInfo );
1030 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1032 LightApp_Module::onViewManagerRemoved( theViewManager );
1034 createSelector( theViewManager ); // replace the default selector
1036 int anId = getViewManagerId( theViewManager );
1039 OCCViewer_ViewManager* anOCCViewManager =
1040 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1041 if ( anOCCViewManager )
1043 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1045 removeViewShapes( (size_t)anOCCViewer );
1048 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1050 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1053 getVTKDisplayer()->DeleteScalarBar( anId );
1054 removeViewShapes( (size_t)aVTKViewer );
1058 myViewManagerMap.remove( anId );
1062 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1064 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1066 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1068 aViewFrame->installEventFilter( this );
1070 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1072 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1073 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1076 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1078 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1080 aViewFrame->onTopView();
1082 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1084 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1086 aViewPort->installEventFilter( this );
1092 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1094 /* ouv: currently unused
1095 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1097 SUIT_ViewManager* aViewManager = 0;
1099 QObject* aParent = aViewPort;
1100 while( aParent = aParent->parent() )
1102 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1104 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1106 aViewManager = aViewer->getViewManager();
1115 double aMouseX = theEvent->scenePos().x();
1116 double aMouseY = theEvent->scenePos().y();
1118 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1119 if( aRole == VMR_General )
1121 int aXDeg = 0, aYDeg = 0;
1122 int aXMin = 0, aYMin = 0;
1123 double aXSec = 0, aYSec = 0;
1124 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1125 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1127 QString aDegSymbol( QChar( 0x00B0 ) );
1128 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1129 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1131 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1133 else if( aRole == VMR_TransformImage )
1134 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1139 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1140 const bool theIsInit,
1141 const bool theIsForced,
1142 const bool theDoFitAll )
1144 QList<int> aViewManagerIdList;
1146 // currently, all views are updated
1147 ViewManagerMapIterator anIter( myViewManagerMap );
1148 while( anIter.hasNext() )
1150 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1152 if ( theDisplayer->IsApplicable( aViewManager ) )
1154 int anId = anIter.key();
1155 aViewManagerIdList.append( anId );
1159 QListIterator<int> anIdIter( aViewManagerIdList );
1160 while( anIdIter.hasNext() )
1162 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1166 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1168 if( !theViewManager )
1171 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1172 if( !aSelectionMgr )
1175 QString aViewType = theViewManager->getType();
1176 if( aViewType != GraphicsView_Viewer::Type() &&
1177 aViewType != OCCViewer_Viewer::Type())
1180 QList<SUIT_Selector*> aSelectorList;
1181 aSelectionMgr->selectors( aViewType, aSelectorList );
1183 // disable all alien selectors
1184 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1185 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1187 SUIT_Selector* aSelector = *anIter;
1188 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1189 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1190 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1191 aSelector->setEnabled( false );
1194 if ( aViewType == GraphicsView_Viewer::Type() )
1196 GraphicsView_ViewManager* aViewManager =
1197 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1199 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1201 else if ( aViewType == OCCViewer_Viewer::Type() )
1203 OCCViewer_ViewManager* aViewManager =
1204 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1206 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1210 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1212 bool aPrevState = myIsUpdateEnabled;
1213 myIsUpdateEnabled = theState;
1217 bool HYDROGUI_Module::isUpdateEnabled() const
1219 return myIsUpdateEnabled;
1222 QStringList HYDROGUI_Module::storeSelection() const
1224 QStringList anEntryList;
1225 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1227 SUIT_DataOwnerPtrList aList( true );
1228 aSelectionMgr->selected( aList );
1230 SUIT_DataOwnerPtrList::iterator anIter;
1231 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1233 const LightApp_DataOwner* anOwner =
1234 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1236 anEntryList.append( anOwner->entry() );
1242 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1244 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1246 SUIT_DataOwnerPtrList aList( true );
1247 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1248 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1249 aSelectionMgr->setSelected( aList );
1253 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1255 OCCViewer_ViewWindow* anOCCViewWindow =
1256 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1257 if ( !anOCCViewWindow ) {
1261 // Get the selected point coordinates
1262 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1267 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1268 aViewPort->getView() );
1270 // Show the coordinates in the status bar
1271 SUIT_Desktop* aDesktop = getApp()->desktop();
1272 if ( aDesktop && aDesktop->statusBar() ) {
1273 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1274 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1275 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );