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 anIsGeomObject = false;
272 // check the selected GEOM objects
273 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
274 theMenu->addAction( action( ImportGeomObjectId ) );
275 theMenu->addSeparator();
278 // check the selected data model objects
279 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
280 int aNbOfSelectedProfiles = 0;
281 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
283 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
284 if( !anObject.IsNull() )
286 anIsSelectedDataObjects = true;
288 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
289 anIsVisibleInSelection |= aVisibility;
290 anIsHiddenInSelection |= !aVisibility;
292 ObjectKind anObjectKind = anObject->GetKind();
293 if( anObjectKind == KIND_IMAGE )
296 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
297 if( !anImage.IsNull() )
299 anIsImportedImage = anImage->HasLocalPoints();
300 anIsImageHasRefs = anImage->HasReferences();
301 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
303 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
305 QString anOperatorName = anOperator->name();
306 if( anOperatorName == ImageComposer_FuseOperator::Type() )
307 anIsFusedImage = true;
308 else if( anOperatorName == ImageComposer_CutOperator::Type() )
310 else if( anOperatorName == ImageComposer_CropOperator::Type() )
311 anIsSplittedImage = true;
314 if ( anImage->IsMustBeUpdated() )
316 anIsMustBeUpdatedImage = true;
320 else if( anObjectKind == KIND_POLYLINEXY )
322 else if( anObjectKind == KIND_POLYLINE )
323 anIsPolyline3D = true;
324 else if( anObjectKind == KIND_PROFILE )
327 aNbOfSelectedProfiles++;
329 Handle(HYDROData_Profile) aProfile =
330 Handle(HYDROData_Profile)::DownCast( anObject );
331 if( !aProfile.IsNull() && aProfile->IsValid() ) {
332 anIsValidProfile = true;
335 else if( anObjectKind == KIND_CALCULATION )
336 anIsCalculation = true;
337 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
338 anIsImmersibleZone = true;
339 else if( anObjectKind == KIND_VISUAL_STATE )
340 anIsVisualState = true;
341 else if( anObjectKind == KIND_REGION )
343 else if( anObjectKind == KIND_ZONE )
345 else if( anObjectKind == KIND_BATHYMETRY )
346 anIsBathymetry = true;
347 else if( anObjectKind == KIND_OBSTACLE )
349 else if( anObjectKind == KIND_STREAM )
353 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
356 // Check if all selected objects are profiles
357 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
358 ( aNbOfSelectedProfiles == aSeq.Length() );
360 // check the selected partitions
361 if( !anIsSelectedDataObjects && anIsObjectBrowser )
363 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
364 if( aSelectedPartition != KIND_UNKNOWN )
366 switch( aSelectedPartition )
369 theMenu->addAction( action( ImportImageId ) );
371 case KIND_BATHYMETRY:
372 theMenu->addAction( action( ImportBathymetryId ) );
374 case KIND_ARTIFICIAL_OBJECT:
376 case KIND_NATURAL_OBJECT:
377 theMenu->addAction( action( CreateImmersibleZoneId ) );
378 theMenu->addAction( action( CreateStreamId ) );
381 theMenu->addAction( action( ImportObstacleFromFileId ) );
382 theMenu->addAction( action( CreateBoxId ) );
383 theMenu->addAction( action( CreateCylinderId ) );
385 case KIND_CALCULATION:
386 theMenu->addAction( action( CreateCalculationId ) );
388 case KIND_POLYLINEXY:
389 theMenu->addAction( action( CreatePolylineId ) );
392 theMenu->addAction( action( CreatePolyline3DId ) );
395 theMenu->addAction( action( CreateProfileId ) );
396 theMenu->addAction( action( ImportProfilesId ) );
397 theMenu->addAction( action( AllGeoreferencementId ) );
399 case KIND_VISUAL_STATE:
400 theMenu->addAction( action( SaveVisualStateId ) );
403 theMenu->addSeparator();
407 if( anIsSelectedDataObjects )
409 if ( anIsMustBeUpdatedImage )
411 theMenu->addAction( action( UpdateImageId ) );
412 theMenu->addSeparator();
415 if( aSeq.Length() == 1 )
419 if( anIsImportedImage )
420 theMenu->addAction( action( EditImportedImageId ) );
421 else if( anIsImageHasRefs )
424 theMenu->addAction( action( EditFusedImageId ) );
425 else if( anIsCutImage )
426 theMenu->addAction( action( EditCutImageId ) );
427 else if( anIsSplittedImage )
428 theMenu->addAction( action( EditSplittedImageId ) );
431 theMenu->addAction( action( ObserveImageId ) );
432 theMenu->addAction( action( ExportImageId ) );
433 theMenu->addSeparator();
435 if( anIsImageHasRefs )
437 theMenu->addAction( action( RemoveImageRefsId ) );
438 theMenu->addSeparator();
441 theMenu->addAction( action( FuseImagesId ) );
442 theMenu->addAction( action( CutImagesId ) );
443 theMenu->addAction( action( SplitImageId ) );
444 theMenu->addSeparator();
446 else if( anIsPolyline )
448 theMenu->addAction( action( EditPolylineId ) );
449 theMenu->addSeparator();
451 else if( anIsPolyline3D )
453 theMenu->addAction( action( EditPolyline3DId ) );
454 theMenu->addSeparator();
456 else if( anIsProfile )
458 theMenu->addAction( action( EditProfileId ) );
459 theMenu->addAction( action( SelectedGeoreferencementId ) );
460 theMenu->addSeparator();
462 else if( anIsCalculation )
464 theMenu->addAction( action( EditCalculationId ) );
465 theMenu->addAction( action( ExportCalculationId ) );
466 theMenu->addSeparator();
468 else if( anIsImmersibleZone )
470 theMenu->addAction( action( EditImmersibleZoneId ) );
471 theMenu->addSeparator();
473 else if( anIsStream )
475 theMenu->addAction( action( EditStreamId ) );
476 theMenu->addSeparator();
478 else if( anIsVisualState && anIsObjectBrowser )
480 theMenu->addAction( action( SaveVisualStateId ) );
481 theMenu->addAction( action( LoadVisualStateId ) );
482 theMenu->addSeparator();
485 // Add set color action for geometrical objects
486 if ( anIsGeomObject )
488 theMenu->addAction( action( SetColorId ) );
489 theMenu->addSeparator();
491 } else if ( anAllAreProfiles ) {
492 theMenu->addAction( action( SelectedGeoreferencementId ) );
493 theMenu->addSeparator();
496 theMenu->addAction( action( DeleteId ) );
497 theMenu->addSeparator();
499 if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone ||
500 anIsRegion || anIsBathymetry || anIsObstacle || anIsStream || anIsValidProfile )
502 if( anIsHiddenInSelection )
503 theMenu->addAction( action( ShowId ) );
504 theMenu->addAction( action( ShowOnlyId ) );
505 if( anIsVisibleInSelection )
506 theMenu->addAction( action( HideId ) );
507 theMenu->addSeparator();
513 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
514 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
515 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
516 theMenu->addAction( action( DeleteId ) );
519 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
521 theMenu->addAction( action( ShowAllId ) );
522 theMenu->addAction( action( HideAllId ) );
523 theMenu->addSeparator();
527 void HYDROGUI_Module::update( const int flags )
529 if( !isUpdateEnabled() )
532 QApplication::setOverrideCursor( Qt::WaitCursor );
534 // To prevent calling this method recursively
535 // from one of the methods called below
536 setUpdateEnabled( false );
538 // store selected objects
539 QStringList aSelectedEntries = storeSelection();
541 bool aDoFitAll = flags & UF_FitAll;
542 if( ( flags & UF_Viewer ) )
543 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
545 if( ( flags & UF_OCCViewer ) )
546 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
548 if( ( flags & UF_VTKViewer ) )
549 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
551 if( ( flags & UF_Model ) && getDataModel() && getApp() )
553 getDataModel()->update( getStudyId() );
555 // Temporary workaround to prevent breaking
556 // the selection in the object browser.
557 // Note: processEvents() should be called after updateGV(),
558 // otherwise the application crashes from time to time.
559 //RKV: qApp->processEvents();
560 getApp()->updateObjectBrowser( true );
563 // Object browser is currently updated by using UF_Model flag
564 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
565 getApp()->updateObjectBrowser( true );
567 if( ( flags & UF_Controls ) && getApp() )
568 getApp()->updateActions();
570 // restore selected objects
571 restoreSelection( aSelectedEntries );
573 setUpdateEnabled( true );
575 QApplication::restoreOverrideCursor();
578 void HYDROGUI_Module::updateCommandsStatus()
580 LightApp_Module::updateCommandsStatus();
582 updateUndoRedoControls();
584 action( CopyId )->setEnabled( getDataModel()->canCopy() );
585 action( PasteId )->setEnabled( getDataModel()->canPaste() );
588 void HYDROGUI_Module::selectionChanged()
590 LightApp_Module::selectionChanged();
591 updateCommandsStatus();
594 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
596 return (HYDROGUI_DataModel*)dataModel();
599 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
604 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
606 return myOCCDisplayer;
609 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
611 return myVTKDisplayer;
614 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
616 if( myViewManagerMap.contains( theId ) )
618 return myViewManagerMap[ theId ].first;
623 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
625 if( myViewManagerMap.contains( theId ) )
627 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
628 GraphicsView_ViewManager* aViewManager =
629 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
631 return aViewManager->getViewer();
636 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
638 if( myViewManagerMap.contains( theId ) )
640 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
641 OCCViewer_ViewManager* aViewManager =
642 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
644 return aViewManager->getOCCViewer();
649 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
651 if( myViewManagerMap.contains( theId ) )
653 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
654 SVTK_ViewManager* aViewManager =
655 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
657 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
662 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
664 ViewManagerMapIterator anIter( myViewManagerMap );
665 while( anIter.hasNext() )
667 int anId = anIter.next().key();
668 const ViewManagerInfo& anInfo = anIter.value();
669 if( anInfo.first == theViewManager )
675 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
677 int anId = getViewManagerId( theViewManager );
680 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
681 return anInfo.second;
686 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
687 const ViewManagerRole theRole )
689 int anId = getViewManagerId( theViewManager );
692 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
693 anInfo.second = theRole;
697 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
698 const Handle(HYDROData_Entity)& theObject ) const
700 if( theObject.IsNull() )
703 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
704 if( anIter1 != myObjectStateMap.end() )
706 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
707 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
708 if( anIter2 != aName2ObjectStateMap.end() )
710 const ObjectState& anObjectState = anIter2.value();
711 return anObjectState.Visibility;
717 void HYDROGUI_Module::setObjectVisible( const int theViewId,
718 const Handle(HYDROData_Entity)& theObject,
719 const bool theState )
721 if( !theObject.IsNull() )
723 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
724 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
725 anObjectState.Visibility = theState;
729 /////////////////// OCC SHAPES PROCESSING
730 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
731 const Handle(HYDROData_Entity)& theObject ) const
733 HYDROGUI_Shape* aResShape = NULL;
734 if( theObject.IsNull() )
737 if ( myShapesMap.contains( theViewId ) )
739 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
740 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
742 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
753 void HYDROGUI_Module::setObjectShape( const int theViewId,
754 const Handle(HYDROData_Entity)& theObject,
755 HYDROGUI_Shape* theShape )
757 if( theObject.IsNull() )
760 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
761 aViewShapes.append( theShape );
764 void HYDROGUI_Module::removeObjectShape( const int theViewId,
765 const Handle(HYDROData_Entity)& theObject )
767 if ( !myShapesMap.contains( theViewId ) )
770 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
771 Handle(HYDROData_Entity) anObject;
772 for ( int i = 0; i < aViewShapes.length(); )
774 HYDROGUI_Shape* aShape = aViewShapes.at( i );
775 anObject = aShape->getObject();
776 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
779 aViewShapes.removeAt( i );
787 void HYDROGUI_Module::removeViewShapes( const int theViewId )
789 if ( !myShapesMap.contains( theViewId ) )
792 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
793 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
795 HYDROGUI_Shape* aShape = aViewShapes.at( i );
800 myShapesMap.remove( theViewId );
802 /////////////////// END OF OCC SHAPES PROCESSING
804 /////////////////// VTKPrs PROCESSING
805 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
806 const Handle(HYDROData_Entity)& theObject ) const
808 HYDROGUI_VTKPrs* aResShape = NULL;
809 if( theObject.IsNull() )
812 if ( myVTKPrsMap.contains( theViewId ) )
814 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
815 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
817 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
828 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
829 const Handle(HYDROData_Entity)& theObject,
830 HYDROGUI_VTKPrs* theShape )
832 if( theObject.IsNull() )
835 // Compute the new global Z range from the added presentation and the old global Z range.
836 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
837 double* aRange = theShape->getInternalZRange();
838 bool anIsUpdate = false;
839 if ( aRange[0] < aGlobalRange[0] )
841 aGlobalRange[0] = aRange[0];
844 if ( aRange[1] > aGlobalRange[1] )
846 aGlobalRange[1] = aRange[1];
852 updateVTKZRange( theViewId, aGlobalRange );
855 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
856 aViewShapes.append( theShape );
859 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
860 const Handle(HYDROData_Entity)& theObject )
862 if ( !myVTKPrsMap.contains( theViewId ) )
865 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
866 Handle(HYDROData_Entity) anObject;
867 for ( int i = 0; i < aViewShapes.length(); )
869 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
870 anObject = aShape->getObject();
871 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
874 aViewShapes.removeAt( i );
881 // Invalidate global Z range
882 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
883 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
886 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
888 if ( !myVTKPrsMap.contains( theViewId ) )
891 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
892 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
894 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
899 myVTKPrsMap.remove( theViewId );
902 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
904 if ( myVTKPrsMap.contains( theViewId ) )
906 // For the given viewer id update all VTK presentations ...
907 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
908 HYDROGUI_VTKPrs* aShape;
909 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
911 aShape = aViewShapes.at( i );
914 aShape->setZRange( theRange );
918 // ... and update the global color legend scalar bar.
919 getVTKDisplayer()->SetZRange( theViewId, theRange );
921 /////////////////// END OF VTKPrs PROCESSING
923 CAM_DataModel* HYDROGUI_Module::createDataModel()
925 return new HYDROGUI_DataModel( this );
928 void HYDROGUI_Module::customEvent( QEvent* e )
930 int aType = e->type();
931 if ( aType == NewViewEvent )
933 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
934 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
936 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
938 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
939 ViewManagerRole aRole = getViewManagerRole( aViewManager );
941 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
943 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
944 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
946 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
947 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
948 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
950 //ouv: temporarily commented
951 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
954 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
957 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
963 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
965 QEvent::Type aType = theEvent->type();
966 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
968 if( aType == QEvent::Show )
970 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
971 e->setData( theObj );
972 QApplication::postEvent( this, e );
973 theObj->removeEventFilter( this );
976 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
978 if( aType == QEvent::Leave )
980 SUIT_Desktop* aDesktop = getApp()->desktop();
981 if ( aDesktop && aDesktop->statusBar() ) {
982 aDesktop->statusBar()->clearMessage();
987 return LightApp_Module::eventFilter( theObj, theEvent );
990 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
992 LightApp_Module::onViewManagerAdded( theViewManager );
994 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
996 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
997 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
999 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1001 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1002 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1003 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1004 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1007 createSelector( theViewManager ); // replace the default selector
1009 ViewManagerInfo anInfo( theViewManager, VMR_General );
1010 myViewManagerMap.insert( ViewManagerId++, anInfo );
1013 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1015 LightApp_Module::onViewManagerRemoved( theViewManager );
1017 createSelector( theViewManager ); // replace the default selector
1019 int anId = getViewManagerId( theViewManager );
1022 OCCViewer_ViewManager* anOCCViewManager =
1023 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1024 if ( anOCCViewManager )
1026 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1028 removeViewShapes( (size_t)anOCCViewer );
1031 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1033 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1036 getVTKDisplayer()->DeleteScalarBar( anId );
1037 removeViewShapes( (size_t)aVTKViewer );
1041 myViewManagerMap.remove( anId );
1045 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1047 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1049 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1051 aViewFrame->installEventFilter( this );
1053 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1055 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1056 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1059 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1061 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1063 aViewFrame->onTopView();
1065 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1067 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1069 aViewPort->installEventFilter( this );
1075 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1077 /* ouv: currently unused
1078 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1080 SUIT_ViewManager* aViewManager = 0;
1082 QObject* aParent = aViewPort;
1083 while( aParent = aParent->parent() )
1085 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1087 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1089 aViewManager = aViewer->getViewManager();
1098 double aMouseX = theEvent->scenePos().x();
1099 double aMouseY = theEvent->scenePos().y();
1101 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1102 if( aRole == VMR_General )
1104 int aXDeg = 0, aYDeg = 0;
1105 int aXMin = 0, aYMin = 0;
1106 double aXSec = 0, aYSec = 0;
1107 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1108 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1110 QString aDegSymbol( QChar( 0x00B0 ) );
1111 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1112 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1114 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1116 else if( aRole == VMR_TransformImage )
1117 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1122 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1123 const bool theIsInit,
1124 const bool theIsForced,
1125 const bool theDoFitAll )
1127 QList<int> aViewManagerIdList;
1129 // currently, all views are updated
1130 ViewManagerMapIterator anIter( myViewManagerMap );
1131 while( anIter.hasNext() )
1133 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1135 if ( theDisplayer->IsApplicable( aViewManager ) )
1137 int anId = anIter.key();
1138 aViewManagerIdList.append( anId );
1142 QListIterator<int> anIdIter( aViewManagerIdList );
1143 while( anIdIter.hasNext() )
1145 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1149 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1151 if( !theViewManager )
1154 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1155 if( !aSelectionMgr )
1158 QString aViewType = theViewManager->getType();
1159 if( aViewType != GraphicsView_Viewer::Type() &&
1160 aViewType != OCCViewer_Viewer::Type())
1163 QList<SUIT_Selector*> aSelectorList;
1164 aSelectionMgr->selectors( aViewType, aSelectorList );
1166 // disable all alien selectors
1167 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1168 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1170 SUIT_Selector* aSelector = *anIter;
1171 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1172 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1173 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1174 aSelector->setEnabled( false );
1177 if ( aViewType == GraphicsView_Viewer::Type() )
1179 GraphicsView_ViewManager* aViewManager =
1180 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1182 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1184 else if ( aViewType == OCCViewer_Viewer::Type() )
1186 OCCViewer_ViewManager* aViewManager =
1187 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1189 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1193 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1195 bool aPrevState = myIsUpdateEnabled;
1196 myIsUpdateEnabled = theState;
1200 bool HYDROGUI_Module::isUpdateEnabled() const
1202 return myIsUpdateEnabled;
1205 QStringList HYDROGUI_Module::storeSelection() const
1207 QStringList anEntryList;
1208 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1210 SUIT_DataOwnerPtrList aList( true );
1211 aSelectionMgr->selected( aList );
1213 SUIT_DataOwnerPtrList::iterator anIter;
1214 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1216 const LightApp_DataOwner* anOwner =
1217 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1219 anEntryList.append( anOwner->entry() );
1225 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1227 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1229 SUIT_DataOwnerPtrList aList( true );
1230 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1231 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1232 aSelectionMgr->setSelected( aList );
1236 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1238 OCCViewer_ViewWindow* anOCCViewWindow =
1239 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1240 if ( !anOCCViewWindow ) {
1244 // Get the selected point coordinates
1245 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1250 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1251 aViewPort->getView() );
1253 // Show the coordinates in the status bar
1254 SUIT_Desktop* aDesktop = getApp()->desktop();
1255 if ( aDesktop && aDesktop->statusBar() ) {
1256 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1257 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1258 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );