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( anIsBathymetry )
452 theMenu->addAction( action( EditImportedBathymetryId ) );
453 theMenu->addSeparator();
455 else if( anIsPolyline )
457 theMenu->addAction( action( EditPolylineId ) );
458 theMenu->addSeparator();
460 else if( anIsPolyline3D )
462 theMenu->addAction( action( EditPolyline3DId ) );
463 theMenu->addSeparator();
465 else if( anIsProfile )
467 theMenu->addAction( action( EditProfileId ) );
468 theMenu->addAction( action( SelectedGeoreferencementId ) );
469 theMenu->addSeparator();
471 else if( anIsCalculation )
473 theMenu->addAction( action( EditCalculationId ) );
474 theMenu->addAction( action( ExportCalculationId ) );
475 theMenu->addSeparator();
477 else if( anIsImmersibleZone )
479 theMenu->addAction( action( EditImmersibleZoneId ) );
480 theMenu->addSeparator();
482 else if( anIsStream )
484 theMenu->addAction( action( EditStreamId ) );
485 theMenu->addSeparator();
487 else if( anIsChannel )
489 theMenu->addAction( action( EditChannelId ) );
490 theMenu->addSeparator();
492 else if( anIsVisualState && anIsObjectBrowser )
494 theMenu->addAction( action( SaveVisualStateId ) );
495 theMenu->addAction( action( LoadVisualStateId ) );
496 theMenu->addSeparator();
499 // Add set color action for geometrical objects
500 if ( anIsGeomObject )
502 theMenu->addAction( action( SetColorId ) );
503 theMenu->addSeparator();
505 } else if ( anAllAreProfiles ) {
506 theMenu->addAction( action( SelectedGeoreferencementId ) );
507 theMenu->addSeparator();
510 theMenu->addAction( action( DeleteId ) );
511 theMenu->addSeparator();
513 if( anIsImage || anIsPolyline || anIsPolyline3D ||
514 anIsImmersibleZone || anIsZone || anIsRegion ||
515 anIsBathymetry || anIsObstacle || anIsStream ||
516 anIsChannel || anIsValidProfile )
518 if( anIsHiddenInSelection )
519 theMenu->addAction( action( ShowId ) );
520 theMenu->addAction( action( ShowOnlyId ) );
521 if( anIsVisibleInSelection )
522 theMenu->addAction( action( HideId ) );
523 theMenu->addSeparator();
529 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
530 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
531 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
532 theMenu->addAction( action( DeleteId ) );
535 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
537 theMenu->addAction( action( ShowAllId ) );
538 theMenu->addAction( action( HideAllId ) );
539 theMenu->addSeparator();
543 void HYDROGUI_Module::update( const int flags )
545 if( !isUpdateEnabled() )
548 QApplication::setOverrideCursor( Qt::WaitCursor );
550 // To prevent calling this method recursively
551 // from one of the methods called below
552 setUpdateEnabled( false );
554 // store selected objects
555 QStringList aSelectedEntries = storeSelection();
557 bool aDoFitAll = flags & UF_FitAll;
558 if( ( flags & UF_Viewer ) )
559 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
561 if( ( flags & UF_OCCViewer ) )
562 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
564 if( ( flags & UF_VTKViewer ) )
565 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
567 if( ( flags & UF_Model ) && getDataModel() && getApp() )
569 getDataModel()->update( getStudyId() );
571 // Temporary workaround to prevent breaking
572 // the selection in the object browser.
573 // Note: processEvents() should be called after updateGV(),
574 // otherwise the application crashes from time to time.
575 //RKV: qApp->processEvents();
576 getApp()->updateObjectBrowser( true );
579 // Object browser is currently updated by using UF_Model flag
580 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
581 getApp()->updateObjectBrowser( true );
583 if( ( flags & UF_Controls ) && getApp() )
584 getApp()->updateActions();
586 // restore selected objects
587 restoreSelection( aSelectedEntries );
589 setUpdateEnabled( true );
591 QApplication::restoreOverrideCursor();
594 void HYDROGUI_Module::updateCommandsStatus()
596 LightApp_Module::updateCommandsStatus();
598 updateUndoRedoControls();
600 action( CopyId )->setEnabled( getDataModel()->canCopy() );
601 action( PasteId )->setEnabled( getDataModel()->canPaste() );
604 void HYDROGUI_Module::selectionChanged()
606 LightApp_Module::selectionChanged();
607 updateCommandsStatus();
610 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
612 return (HYDROGUI_DataModel*)dataModel();
615 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
620 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
622 return myOCCDisplayer;
625 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
627 return myVTKDisplayer;
630 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
632 if( myViewManagerMap.contains( theId ) )
634 return myViewManagerMap[ theId ].first;
639 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
641 if( myViewManagerMap.contains( theId ) )
643 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
644 GraphicsView_ViewManager* aViewManager =
645 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
647 return aViewManager->getViewer();
652 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
654 if( myViewManagerMap.contains( theId ) )
656 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
657 OCCViewer_ViewManager* aViewManager =
658 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
660 return aViewManager->getOCCViewer();
665 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
667 if( myViewManagerMap.contains( theId ) )
669 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
670 SVTK_ViewManager* aViewManager =
671 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
673 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
678 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
680 ViewManagerMapIterator anIter( myViewManagerMap );
681 while( anIter.hasNext() )
683 int anId = anIter.next().key();
684 const ViewManagerInfo& anInfo = anIter.value();
685 if( anInfo.first == theViewManager )
691 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
693 int anId = getViewManagerId( theViewManager );
696 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
697 return anInfo.second;
702 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
703 const ViewManagerRole theRole )
705 int anId = getViewManagerId( theViewManager );
708 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
709 anInfo.second = theRole;
713 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
714 const Handle(HYDROData_Entity)& theObject ) const
716 if( theObject.IsNull() )
719 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
720 if( anIter1 != myObjectStateMap.end() )
722 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
723 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
724 if( anIter2 != aName2ObjectStateMap.end() )
726 const ObjectState& anObjectState = anIter2.value();
727 return anObjectState.Visibility;
733 void HYDROGUI_Module::setObjectVisible( const int theViewId,
734 const Handle(HYDROData_Entity)& theObject,
735 const bool theState )
737 if( !theObject.IsNull() )
739 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
740 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
741 anObjectState.Visibility = theState;
745 /////////////////// OCC SHAPES PROCESSING
746 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
747 const Handle(HYDROData_Entity)& theObject ) const
749 HYDROGUI_Shape* aResShape = NULL;
750 if( theObject.IsNull() )
753 if ( myShapesMap.contains( theViewId ) )
755 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
756 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
758 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
769 void HYDROGUI_Module::setObjectShape( const int theViewId,
770 const Handle(HYDROData_Entity)& theObject,
771 HYDROGUI_Shape* theShape )
773 if( theObject.IsNull() )
776 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
777 aViewShapes.append( theShape );
780 void HYDROGUI_Module::removeObjectShape( const int theViewId,
781 const Handle(HYDROData_Entity)& theObject )
783 if ( !myShapesMap.contains( theViewId ) )
786 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
787 Handle(HYDROData_Entity) anObject;
788 for ( int i = 0; i < aViewShapes.length(); )
790 HYDROGUI_Shape* aShape = aViewShapes.at( i );
791 anObject = aShape->getObject();
792 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
795 aViewShapes.removeAt( i );
803 void HYDROGUI_Module::removeViewShapes( const int theViewId )
805 if ( !myShapesMap.contains( theViewId ) )
808 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
809 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
811 HYDROGUI_Shape* aShape = aViewShapes.at( i );
816 myShapesMap.remove( theViewId );
818 /////////////////// END OF OCC SHAPES PROCESSING
820 /////////////////// VTKPrs PROCESSING
821 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
822 const Handle(HYDROData_Entity)& theObject ) const
824 HYDROGUI_VTKPrs* aResShape = NULL;
825 if( theObject.IsNull() )
828 if ( myVTKPrsMap.contains( theViewId ) )
830 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
831 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
833 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
844 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
845 const Handle(HYDROData_Entity)& theObject,
846 HYDROGUI_VTKPrs* theShape )
848 if( theObject.IsNull() )
851 // Compute the new global Z range from the added presentation and the old global Z range.
852 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
853 double* aRange = theShape->getInternalZRange();
854 bool anIsUpdate = false;
855 if ( aRange[0] < aGlobalRange[0] )
857 aGlobalRange[0] = aRange[0];
860 if ( aRange[1] > aGlobalRange[1] )
862 aGlobalRange[1] = aRange[1];
868 updateVTKZRange( theViewId, aGlobalRange );
871 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
872 aViewShapes.append( theShape );
875 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
876 const Handle(HYDROData_Entity)& theObject )
878 if ( !myVTKPrsMap.contains( theViewId ) )
881 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
882 Handle(HYDROData_Entity) anObject;
883 for ( int i = 0; i < aViewShapes.length(); )
885 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
886 anObject = aShape->getObject();
887 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
890 aViewShapes.removeAt( i );
897 // Invalidate global Z range
898 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
899 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
902 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
904 if ( !myVTKPrsMap.contains( theViewId ) )
907 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
908 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
910 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
915 myVTKPrsMap.remove( theViewId );
918 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
920 if ( myVTKPrsMap.contains( theViewId ) )
922 // For the given viewer id update all VTK presentations ...
923 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
924 HYDROGUI_VTKPrs* aShape;
925 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
927 aShape = aViewShapes.at( i );
930 aShape->setZRange( theRange );
934 // ... and update the global color legend scalar bar.
935 getVTKDisplayer()->SetZRange( theViewId, theRange );
937 /////////////////// END OF VTKPrs PROCESSING
939 CAM_DataModel* HYDROGUI_Module::createDataModel()
941 return new HYDROGUI_DataModel( this );
944 void HYDROGUI_Module::customEvent( QEvent* e )
946 int aType = e->type();
947 if ( aType == NewViewEvent )
949 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
950 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
952 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
954 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
955 ViewManagerRole aRole = getViewManagerRole( aViewManager );
957 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
959 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
960 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
962 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
963 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
964 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
966 //ouv: temporarily commented
967 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
970 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
973 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
979 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
981 QEvent::Type aType = theEvent->type();
982 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
984 if( aType == QEvent::Show )
986 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
987 e->setData( theObj );
988 QApplication::postEvent( this, e );
989 theObj->removeEventFilter( this );
992 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
994 if( aType == QEvent::Leave )
996 SUIT_Desktop* aDesktop = getApp()->desktop();
997 if ( aDesktop && aDesktop->statusBar() ) {
998 aDesktop->statusBar()->clearMessage();
1003 return LightApp_Module::eventFilter( theObj, theEvent );
1006 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1008 LightApp_Module::onViewManagerAdded( theViewManager );
1010 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1012 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1013 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1015 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1017 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1018 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1019 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1020 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1023 createSelector( theViewManager ); // replace the default selector
1025 ViewManagerInfo anInfo( theViewManager, VMR_General );
1026 myViewManagerMap.insert( ViewManagerId++, anInfo );
1029 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1031 LightApp_Module::onViewManagerRemoved( theViewManager );
1033 createSelector( theViewManager ); // replace the default selector
1035 int anId = getViewManagerId( theViewManager );
1038 OCCViewer_ViewManager* anOCCViewManager =
1039 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1040 if ( anOCCViewManager )
1042 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1044 removeViewShapes( (size_t)anOCCViewer );
1047 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1049 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1052 getVTKDisplayer()->DeleteScalarBar( anId );
1053 removeViewShapes( (size_t)aVTKViewer );
1057 myViewManagerMap.remove( anId );
1061 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1063 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1065 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1067 aViewFrame->installEventFilter( this );
1069 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1071 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1072 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1075 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1077 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1079 aViewFrame->onTopView();
1081 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1083 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1085 aViewPort->installEventFilter( this );
1091 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1093 /* ouv: currently unused
1094 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1096 SUIT_ViewManager* aViewManager = 0;
1098 QObject* aParent = aViewPort;
1099 while( aParent = aParent->parent() )
1101 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1103 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1105 aViewManager = aViewer->getViewManager();
1114 double aMouseX = theEvent->scenePos().x();
1115 double aMouseY = theEvent->scenePos().y();
1117 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1118 if( aRole == VMR_General )
1120 int aXDeg = 0, aYDeg = 0;
1121 int aXMin = 0, aYMin = 0;
1122 double aXSec = 0, aYSec = 0;
1123 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1124 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1126 QString aDegSymbol( QChar( 0x00B0 ) );
1127 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1128 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1130 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1132 else if( aRole == VMR_TransformImage )
1133 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1138 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1139 const bool theIsInit,
1140 const bool theIsForced,
1141 const bool theDoFitAll )
1143 QList<int> aViewManagerIdList;
1145 // currently, all views are updated
1146 ViewManagerMapIterator anIter( myViewManagerMap );
1147 while( anIter.hasNext() )
1149 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1151 if ( theDisplayer->IsApplicable( aViewManager ) )
1153 int anId = anIter.key();
1154 aViewManagerIdList.append( anId );
1158 QListIterator<int> anIdIter( aViewManagerIdList );
1159 while( anIdIter.hasNext() )
1161 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1165 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1167 if( !theViewManager )
1170 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1171 if( !aSelectionMgr )
1174 QString aViewType = theViewManager->getType();
1175 if( aViewType != GraphicsView_Viewer::Type() &&
1176 aViewType != OCCViewer_Viewer::Type())
1179 QList<SUIT_Selector*> aSelectorList;
1180 aSelectionMgr->selectors( aViewType, aSelectorList );
1182 // disable all alien selectors
1183 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1184 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1186 SUIT_Selector* aSelector = *anIter;
1187 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1188 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1189 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1190 aSelector->setEnabled( false );
1193 if ( aViewType == GraphicsView_Viewer::Type() )
1195 GraphicsView_ViewManager* aViewManager =
1196 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1198 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1200 else if ( aViewType == OCCViewer_Viewer::Type() )
1202 OCCViewer_ViewManager* aViewManager =
1203 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1205 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1209 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1211 bool aPrevState = myIsUpdateEnabled;
1212 myIsUpdateEnabled = theState;
1216 bool HYDROGUI_Module::isUpdateEnabled() const
1218 return myIsUpdateEnabled;
1221 QStringList HYDROGUI_Module::storeSelection() const
1223 QStringList anEntryList;
1224 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1226 SUIT_DataOwnerPtrList aList( true );
1227 aSelectionMgr->selected( aList );
1229 SUIT_DataOwnerPtrList::iterator anIter;
1230 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1232 const LightApp_DataOwner* anOwner =
1233 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1235 anEntryList.append( anOwner->entry() );
1241 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1243 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1245 SUIT_DataOwnerPtrList aList( true );
1246 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1247 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1248 aSelectionMgr->setSelected( aList );
1252 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1254 OCCViewer_ViewWindow* anOCCViewWindow =
1255 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1256 if ( !anOCCViewWindow ) {
1260 // Get the selected point coordinates
1261 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1266 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1267 aViewPort->getView() );
1269 // Show the coordinates in the status bar
1270 SUIT_Desktop* aDesktop = getApp()->desktop();
1271 if ( aDesktop && aDesktop->statusBar() ) {
1272 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1273 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1274 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );