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 anIsDigue = false;
272 bool anIsGeomObject = false;
274 // check the selected GEOM objects
275 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
276 theMenu->addAction( action( ImportGeomObjectId ) );
277 theMenu->addSeparator();
280 // check the selected data model objects
281 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
282 int aNbOfSelectedProfiles = 0;
283 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
285 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
286 if( !anObject.IsNull() )
288 anIsSelectedDataObjects = true;
290 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
291 anIsVisibleInSelection |= aVisibility;
292 anIsHiddenInSelection |= !aVisibility;
294 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
296 anIsMustObjectBeUpdated = true;
299 ObjectKind anObjectKind = anObject->GetKind();
300 if( anObjectKind == KIND_IMAGE )
303 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
304 if( !anImage.IsNull() )
306 anIsImportedImage = anImage->HasLocalPoints();
307 anIsImageHasRefs = anImage->HasReferences();
308 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
310 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
312 QString anOperatorName = anOperator->name();
313 if( anOperatorName == ImageComposer_FuseOperator::Type() )
314 anIsFusedImage = true;
315 else if( anOperatorName == ImageComposer_CutOperator::Type() )
317 else if( anOperatorName == ImageComposer_CropOperator::Type() )
318 anIsSplittedImage = true;
323 else if( anObjectKind == KIND_POLYLINEXY )
325 else if( anObjectKind == KIND_POLYLINE )
326 anIsPolyline3D = true;
327 else if( anObjectKind == KIND_PROFILE )
330 aNbOfSelectedProfiles++;
332 Handle(HYDROData_Profile) aProfile =
333 Handle(HYDROData_Profile)::DownCast( anObject );
334 if( !aProfile.IsNull() && aProfile->IsValid() ) {
335 anIsValidProfile = true;
338 else if( anObjectKind == KIND_CALCULATION )
339 anIsCalculation = true;
340 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
341 anIsImmersibleZone = true;
342 else if( anObjectKind == KIND_VISUAL_STATE )
343 anIsVisualState = true;
344 else if( anObjectKind == KIND_REGION )
346 else if( anObjectKind == KIND_ZONE )
348 else if( anObjectKind == KIND_BATHYMETRY )
349 anIsBathymetry = true;
350 else if( anObjectKind == KIND_OBSTACLE )
352 else if( anObjectKind == KIND_STREAM )
354 else if( anObjectKind == KIND_CHANNEL )
356 else if( anObjectKind == KIND_DIGUE )
360 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
363 // Check if all selected objects are profiles
364 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
365 ( aNbOfSelectedProfiles == aSeq.Length() );
367 // check the selected partitions
368 if( !anIsSelectedDataObjects && anIsObjectBrowser )
370 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
371 if( aSelectedPartition != KIND_UNKNOWN )
373 switch( aSelectedPartition )
376 theMenu->addAction( action( ImportImageId ) );
378 case KIND_BATHYMETRY:
379 theMenu->addAction( action( ImportBathymetryId ) );
381 case KIND_ARTIFICIAL_OBJECT:
382 theMenu->addAction( action( CreateChannelId ) );
383 theMenu->addAction( action( CreateDigueId ) );
385 case KIND_NATURAL_OBJECT:
386 theMenu->addAction( action( CreateImmersibleZoneId ) );
387 theMenu->addAction( action( CreateStreamId ) );
390 theMenu->addAction( action( ImportObstacleFromFileId ) );
391 theMenu->addAction( action( CreateBoxId ) );
392 theMenu->addAction( action( CreateCylinderId ) );
394 case KIND_CALCULATION:
395 theMenu->addAction( action( CreateCalculationId ) );
397 case KIND_POLYLINEXY:
398 theMenu->addAction( action( CreatePolylineId ) );
401 theMenu->addAction( action( CreatePolyline3DId ) );
404 theMenu->addAction( action( CreateProfileId ) );
405 theMenu->addAction( action( ImportProfilesId ) );
406 theMenu->addAction( action( AllGeoreferencementId ) );
408 case KIND_VISUAL_STATE:
409 theMenu->addAction( action( SaveVisualStateId ) );
412 theMenu->addSeparator();
416 if( anIsSelectedDataObjects )
418 if ( anIsMustObjectBeUpdated )
420 theMenu->addAction( action( UpdateObjectId ) );
421 theMenu->addSeparator();
424 if( aSeq.Length() == 1 )
428 if( anIsImportedImage )
429 theMenu->addAction( action( EditImportedImageId ) );
430 else if( anIsImageHasRefs )
433 theMenu->addAction( action( EditFusedImageId ) );
434 else if( anIsCutImage )
435 theMenu->addAction( action( EditCutImageId ) );
436 else if( anIsSplittedImage )
437 theMenu->addAction( action( EditSplittedImageId ) );
440 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
441 theMenu->addAction( action( ExportImageId ) );
442 theMenu->addSeparator();
444 if( anIsImageHasRefs )
446 theMenu->addAction( action( RemoveImageRefsId ) );
447 theMenu->addSeparator();
450 theMenu->addAction( action( FuseImagesId ) );
451 theMenu->addAction( action( CutImagesId ) );
452 theMenu->addAction( action( SplitImageId ) );
453 theMenu->addSeparator();
455 else if( anIsBathymetry )
457 theMenu->addAction( action( EditImportedBathymetryId ) );
458 theMenu->addSeparator();
460 else if( anIsPolyline )
462 theMenu->addAction( action( EditPolylineId ) );
463 theMenu->addSeparator();
465 else if( anIsPolyline3D )
467 theMenu->addAction( action( EditPolyline3DId ) );
468 theMenu->addSeparator();
470 else if( anIsProfile )
472 theMenu->addAction( action( EditProfileId ) );
473 theMenu->addAction( action( SelectedGeoreferencementId ) );
474 theMenu->addSeparator();
476 else if( anIsCalculation )
478 theMenu->addAction( action( EditCalculationId ) );
479 theMenu->addAction( action( ExportCalculationId ) );
480 theMenu->addSeparator();
482 else if( anIsImmersibleZone )
484 theMenu->addAction( action( EditImmersibleZoneId ) );
485 theMenu->addSeparator();
487 else if( anIsStream )
489 theMenu->addAction( action( EditStreamId ) );
490 theMenu->addSeparator();
492 else if( anIsChannel )
494 theMenu->addAction( action( EditChannelId ) );
495 theMenu->addSeparator();
499 theMenu->addAction( action( EditDigueId ) );
500 theMenu->addSeparator();
502 else if( anIsVisualState && anIsObjectBrowser )
504 theMenu->addAction( action( SaveVisualStateId ) );
505 theMenu->addAction( action( LoadVisualStateId ) );
506 theMenu->addSeparator();
509 // Add set color action for geometrical objects
510 if ( anIsGeomObject )
512 theMenu->addAction( action( SetColorId ) );
513 theMenu->addSeparator();
515 } else if ( anAllAreProfiles ) {
516 theMenu->addAction( action( SelectedGeoreferencementId ) );
517 theMenu->addSeparator();
520 theMenu->addAction( action( DeleteId ) );
521 theMenu->addSeparator();
523 if( anIsImage || anIsPolyline || anIsPolyline3D ||
524 anIsImmersibleZone || anIsZone || anIsRegion ||
525 anIsBathymetry || anIsObstacle || anIsStream ||
526 anIsChannel || anIsDigue || anIsValidProfile )
528 if( anIsHiddenInSelection )
529 theMenu->addAction( action( ShowId ) );
530 theMenu->addAction( action( ShowOnlyId ) );
531 if( anIsVisibleInSelection )
532 theMenu->addAction( action( HideId ) );
533 theMenu->addSeparator();
539 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
540 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
541 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
542 theMenu->addAction( action( DeleteId ) );
545 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
547 theMenu->addAction( action( ShowAllId ) );
548 theMenu->addAction( action( HideAllId ) );
549 theMenu->addSeparator();
553 void HYDROGUI_Module::update( const int flags )
555 if( !isUpdateEnabled() )
558 QApplication::setOverrideCursor( Qt::WaitCursor );
560 // To prevent calling this method recursively
561 // from one of the methods called below
562 setUpdateEnabled( false );
564 // store selected objects
565 QStringList aSelectedEntries = storeSelection();
567 bool aDoFitAll = flags & UF_FitAll;
568 if( ( flags & UF_Viewer ) )
569 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
571 if( ( flags & UF_OCCViewer ) )
572 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
574 if( ( flags & UF_VTKViewer ) )
575 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
577 if( ( flags & UF_Model ) && getDataModel() && getApp() )
579 getDataModel()->update( getStudyId() );
581 // Temporary workaround to prevent breaking
582 // the selection in the object browser.
583 // Note: processEvents() should be called after updateGV(),
584 // otherwise the application crashes from time to time.
585 //RKV: qApp->processEvents();
586 getApp()->updateObjectBrowser( true );
589 // Object browser is currently updated by using UF_Model flag
590 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
591 getApp()->updateObjectBrowser( true );
593 if( ( flags & UF_Controls ) && getApp() )
594 getApp()->updateActions();
596 // restore selected objects
597 restoreSelection( aSelectedEntries );
599 setUpdateEnabled( true );
601 QApplication::restoreOverrideCursor();
604 void HYDROGUI_Module::updateCommandsStatus()
606 LightApp_Module::updateCommandsStatus();
608 updateUndoRedoControls();
610 action( CopyId )->setEnabled( getDataModel()->canCopy() );
611 action( PasteId )->setEnabled( getDataModel()->canPaste() );
614 void HYDROGUI_Module::selectionChanged()
616 LightApp_Module::selectionChanged();
617 updateCommandsStatus();
620 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
622 return (HYDROGUI_DataModel*)dataModel();
625 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
630 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
632 return myOCCDisplayer;
635 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
637 return myVTKDisplayer;
640 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
642 if( myViewManagerMap.contains( theId ) )
644 return myViewManagerMap[ theId ].first;
649 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
651 if( myViewManagerMap.contains( theId ) )
653 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
654 GraphicsView_ViewManager* aViewManager =
655 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
657 return aViewManager->getViewer();
662 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
664 if( myViewManagerMap.contains( theId ) )
666 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
667 OCCViewer_ViewManager* aViewManager =
668 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
670 return aViewManager->getOCCViewer();
675 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
677 if( myViewManagerMap.contains( theId ) )
679 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
680 SVTK_ViewManager* aViewManager =
681 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
683 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
688 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
690 ViewManagerMapIterator anIter( myViewManagerMap );
691 while( anIter.hasNext() )
693 int anId = anIter.next().key();
694 const ViewManagerInfo& anInfo = anIter.value();
695 if( anInfo.first == theViewManager )
701 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
703 int anId = getViewManagerId( theViewManager );
706 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
707 return anInfo.second;
712 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
713 const ViewManagerRole theRole )
715 int anId = getViewManagerId( theViewManager );
718 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
719 anInfo.second = theRole;
723 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
724 const Handle(HYDROData_Entity)& theObject ) const
726 if( theObject.IsNull() )
729 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
730 if( anIter1 != myObjectStateMap.end() )
732 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
733 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
734 if( anIter2 != aName2ObjectStateMap.end() )
736 const ObjectState& anObjectState = anIter2.value();
737 return anObjectState.Visibility;
743 void HYDROGUI_Module::setObjectVisible( const int theViewId,
744 const Handle(HYDROData_Entity)& theObject,
745 const bool theState )
747 if( !theObject.IsNull() )
749 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
750 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
751 anObjectState.Visibility = theState;
755 /////////////////// OCC SHAPES PROCESSING
756 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
757 const Handle(HYDROData_Entity)& theObject ) const
759 HYDROGUI_Shape* aResShape = NULL;
760 if( theObject.IsNull() )
763 if ( myShapesMap.contains( theViewId ) )
765 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
766 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
768 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
779 void HYDROGUI_Module::setObjectShape( const int theViewId,
780 const Handle(HYDROData_Entity)& theObject,
781 HYDROGUI_Shape* theShape )
783 if( theObject.IsNull() )
786 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
787 aViewShapes.append( theShape );
790 void HYDROGUI_Module::removeObjectShape( const int theViewId,
791 const Handle(HYDROData_Entity)& theObject )
793 if ( !myShapesMap.contains( theViewId ) )
796 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
797 Handle(HYDROData_Entity) anObject;
798 for ( int i = 0; i < aViewShapes.length(); )
800 HYDROGUI_Shape* aShape = aViewShapes.at( i );
801 anObject = aShape->getObject();
802 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
805 aViewShapes.removeAt( i );
813 void HYDROGUI_Module::removeViewShapes( const int theViewId )
815 if ( !myShapesMap.contains( theViewId ) )
818 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
819 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
821 HYDROGUI_Shape* aShape = aViewShapes.at( i );
826 myShapesMap.remove( theViewId );
828 /////////////////// END OF OCC SHAPES PROCESSING
830 /////////////////// VTKPrs PROCESSING
831 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
832 const Handle(HYDROData_Entity)& theObject ) const
834 HYDROGUI_VTKPrs* aResShape = NULL;
835 if( theObject.IsNull() )
838 if ( myVTKPrsMap.contains( theViewId ) )
840 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
841 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
843 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
854 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
855 const Handle(HYDROData_Entity)& theObject,
856 HYDROGUI_VTKPrs* theShape )
858 if( theObject.IsNull() )
861 // Compute the new global Z range from the added presentation and the old global Z range.
862 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
863 double* aRange = theShape->getInternalZRange();
864 bool anIsUpdate = false;
865 if ( aRange[0] < aGlobalRange[0] )
867 aGlobalRange[0] = aRange[0];
870 if ( aRange[1] > aGlobalRange[1] )
872 aGlobalRange[1] = aRange[1];
878 updateVTKZRange( theViewId, aGlobalRange );
881 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
882 aViewShapes.append( theShape );
885 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
886 const Handle(HYDROData_Entity)& theObject )
888 if ( !myVTKPrsMap.contains( theViewId ) )
891 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
892 Handle(HYDROData_Entity) anObject;
893 for ( int i = 0; i < aViewShapes.length(); )
895 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
896 anObject = aShape->getObject();
897 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
900 aViewShapes.removeAt( i );
907 // Invalidate global Z range
908 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
909 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
912 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
914 if ( !myVTKPrsMap.contains( theViewId ) )
917 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
918 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
920 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
925 myVTKPrsMap.remove( theViewId );
928 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
930 if ( myVTKPrsMap.contains( theViewId ) )
932 // For the given viewer id update all VTK presentations ...
933 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
934 HYDROGUI_VTKPrs* aShape;
935 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
937 aShape = aViewShapes.at( i );
940 aShape->setZRange( theRange );
944 // ... and update the global color legend scalar bar.
945 getVTKDisplayer()->SetZRange( theViewId, theRange );
947 /////////////////// END OF VTKPrs PROCESSING
949 CAM_DataModel* HYDROGUI_Module::createDataModel()
951 return new HYDROGUI_DataModel( this );
954 void HYDROGUI_Module::customEvent( QEvent* e )
956 int aType = e->type();
957 if ( aType == NewViewEvent )
959 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
960 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
962 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
964 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
965 ViewManagerRole aRole = getViewManagerRole( aViewManager );
967 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
969 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
970 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
972 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
973 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
974 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
976 //ouv: temporarily commented
977 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
980 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
983 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
989 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
991 QEvent::Type aType = theEvent->type();
992 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
994 if( aType == QEvent::Show )
996 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
997 e->setData( theObj );
998 QApplication::postEvent( this, e );
999 theObj->removeEventFilter( this );
1002 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1004 if( aType == QEvent::Leave )
1006 SUIT_Desktop* aDesktop = getApp()->desktop();
1007 if ( aDesktop && aDesktop->statusBar() ) {
1008 aDesktop->statusBar()->clearMessage();
1013 return LightApp_Module::eventFilter( theObj, theEvent );
1016 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1018 LightApp_Module::onViewManagerAdded( theViewManager );
1020 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1022 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1023 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1025 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1027 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1028 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1029 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1030 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1033 createSelector( theViewManager ); // replace the default selector
1035 ViewManagerInfo anInfo( theViewManager, VMR_General );
1036 myViewManagerMap.insert( ViewManagerId++, anInfo );
1039 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1041 LightApp_Module::onViewManagerRemoved( theViewManager );
1043 createSelector( theViewManager ); // replace the default selector
1045 int anId = getViewManagerId( theViewManager );
1048 OCCViewer_ViewManager* anOCCViewManager =
1049 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1050 if ( anOCCViewManager )
1052 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1054 removeViewShapes( (size_t)anOCCViewer );
1057 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1059 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1062 getVTKDisplayer()->DeleteScalarBar( anId );
1063 removeViewShapes( (size_t)aVTKViewer );
1067 myViewManagerMap.remove( anId );
1071 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1073 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1075 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1077 aViewFrame->installEventFilter( this );
1079 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1081 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1082 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1085 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1087 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1089 aViewFrame->onTopView();
1091 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1093 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1095 aViewPort->installEventFilter( this );
1101 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1103 /* ouv: currently unused
1104 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1106 SUIT_ViewManager* aViewManager = 0;
1108 QObject* aParent = aViewPort;
1109 while( aParent = aParent->parent() )
1111 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1113 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1115 aViewManager = aViewer->getViewManager();
1124 double aMouseX = theEvent->scenePos().x();
1125 double aMouseY = theEvent->scenePos().y();
1127 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1128 if( aRole == VMR_General )
1130 int aXDeg = 0, aYDeg = 0;
1131 int aXMin = 0, aYMin = 0;
1132 double aXSec = 0, aYSec = 0;
1133 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1134 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1136 QString aDegSymbol( QChar( 0x00B0 ) );
1137 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1138 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1140 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1142 else if( aRole == VMR_TransformImage )
1143 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1148 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1149 const bool theIsInit,
1150 const bool theIsForced,
1151 const bool theDoFitAll )
1153 QList<int> aViewManagerIdList;
1155 // currently, all views are updated
1156 ViewManagerMapIterator anIter( myViewManagerMap );
1157 while( anIter.hasNext() )
1159 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1161 if ( theDisplayer->IsApplicable( aViewManager ) )
1163 int anId = anIter.key();
1164 aViewManagerIdList.append( anId );
1168 QListIterator<int> anIdIter( aViewManagerIdList );
1169 while( anIdIter.hasNext() )
1171 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1175 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1177 if( !theViewManager )
1180 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1181 if( !aSelectionMgr )
1184 QString aViewType = theViewManager->getType();
1185 if( aViewType != GraphicsView_Viewer::Type() &&
1186 aViewType != OCCViewer_Viewer::Type())
1189 QList<SUIT_Selector*> aSelectorList;
1190 aSelectionMgr->selectors( aViewType, aSelectorList );
1192 // disable all alien selectors
1193 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1194 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1196 SUIT_Selector* aSelector = *anIter;
1197 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1198 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1199 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1200 aSelector->setEnabled( false );
1203 if ( aViewType == GraphicsView_Viewer::Type() )
1205 GraphicsView_ViewManager* aViewManager =
1206 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1208 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1210 else if ( aViewType == OCCViewer_Viewer::Type() )
1212 OCCViewer_ViewManager* aViewManager =
1213 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1215 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1219 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1221 bool aPrevState = myIsUpdateEnabled;
1222 myIsUpdateEnabled = theState;
1226 bool HYDROGUI_Module::isUpdateEnabled() const
1228 return myIsUpdateEnabled;
1231 QStringList HYDROGUI_Module::storeSelection() const
1233 QStringList anEntryList;
1234 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1236 SUIT_DataOwnerPtrList aList( true );
1237 aSelectionMgr->selected( aList );
1239 SUIT_DataOwnerPtrList::iterator anIter;
1240 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1242 const LightApp_DataOwner* anOwner =
1243 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1245 anEntryList.append( anOwner->entry() );
1251 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1253 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1255 SUIT_DataOwnerPtrList aList( true );
1256 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1257 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1258 aSelectionMgr->setSelected( aList );
1262 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1264 OCCViewer_ViewWindow* anOCCViewWindow =
1265 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1266 if ( !anOCCViewWindow ) {
1270 // Get the selected point coordinates
1271 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1276 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1277 aViewPort->getView() );
1279 // Show the coordinates in the status bar
1280 SUIT_Desktop* aDesktop = getApp()->desktop();
1281 if ( aDesktop && aDesktop->statusBar() ) {
1282 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1283 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1284 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );