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_Lambert93.h>
45 #include <HYDROData_Tool.h>
47 #include <HYDROData_OperationsFactory.h>
49 #include <GraphicsView_ViewFrame.h>
50 #include <GraphicsView_ViewManager.h>
51 #include <GraphicsView_ViewPort.h>
52 #include <GraphicsView_Viewer.h>
54 #include <ImageComposer_CutOperator.h>
55 #include <ImageComposer_CropOperator.h>
56 #include <ImageComposer_FuseOperator.h>
58 #include <LightApp_Application.h>
59 #include <LightApp_DataOwner.h>
60 #include <LightApp_GVSelector.h>
61 #include <LightApp_SelectionMgr.h>
62 #include <LightApp_UpdateFlags.h>
64 #include <OCCViewer_ViewFrame.h>
65 #include <OCCViewer_ViewManager.h>
66 #include <OCCViewer_ViewModel.h>
68 #include <SALOME_Event.h>
70 #include <SUIT_DataBrowser.h>
71 #include <SUIT_Desktop.h>
72 #include <SUIT_Study.h>
73 #include <SUIT_ViewManager.h>
75 #include <SVTK_ViewManager.h>
76 #include <SVTK_ViewModel.h>
77 #include <SVTK_Selector.h>
80 #include <QApplication>
81 #include <QGraphicsSceneMouseEvent>
84 static int ViewManagerId = 0;
86 extern "C" HYDRO_EXPORT CAM_Module* createModule()
88 return new HYDROGUI_Module();
91 extern "C" HYDRO_EXPORT char* getModuleVersion()
93 return (char*)HYDRO_VERSION;
96 HYDROGUI_Module::HYDROGUI_Module()
97 : LightApp_Module( "HYDRO" ),
100 myIsUpdateEnabled( true )
104 HYDROGUI_Module::~HYDROGUI_Module()
108 int HYDROGUI_Module::getStudyId() const
110 LightApp_Application* anApp = getApp();
111 return anApp ? anApp->activeStudy()->id() : 0;
114 void HYDROGUI_Module::initialize( CAM_Application* theApp )
116 LightApp_Module::initialize( theApp );
119 createUndoRedoActions();
124 setMenuShown( false );
125 setToolShown( false );
127 myDisplayer = new HYDROGUI_Displayer( this );
128 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
129 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
132 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
134 bool aRes = LightApp_Module::activateModule( theStudy );
136 LightApp_Application* anApp = getApp();
137 SUIT_Desktop* aDesktop = anApp->desktop();
139 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
141 setMenuShown( true );
142 setToolShown( true );
144 #ifndef DISABLE_PYCONSOLE
145 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
146 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
151 updateCommandsStatus();
153 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
154 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
159 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
161 ViewManagerMapIterator anIter( myViewManagerMap );
162 while( anIter.hasNext() )
163 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
164 getApp()->removeViewManager( aViewManager );
165 myViewManagerMap.clear();
167 myObjectStateMap.clear();
170 // clear the data model's list of copying objects
171 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
173 setMenuShown( false );
174 setToolShown( false );
176 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
178 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
179 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
181 return LightApp_Module::deactivateModule( theStudy );
184 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
187 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
188 #ifndef DISABLE_PYCONSOLE
189 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
191 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
194 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
196 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
199 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
203 HYDROGUI_DataModel* aModel = getDataModel();
205 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
206 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
207 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
208 bool anIsVTKView = theClient == SVTK_Viewer::Type();
209 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
212 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
214 bool anIsSelectedDataObjects = false;
215 bool anIsVisibleInSelection = false;
216 bool anIsHiddenInSelection = false;
218 bool anIsImage = false;
219 bool anIsImportedImage = false;
220 bool anIsImageHasRefs = false;
221 bool anIsFusedImage = false;
222 bool anIsCutImage = false;
223 bool anIsSplittedImage = false;
224 bool anIsMustBeUpdatedImage = false;
225 bool anIsPolyline = false;
226 bool anIsProfile = false;
227 bool anIsBathymetry = false;
228 bool anIsCalculation = false;
229 bool anIsImmersibleZone = false;
230 bool anIsVisualState = false;
231 bool anIsRegion = false;
232 bool anIsZone = false;
233 bool anIsObstacle = false;
234 bool anIsGeomObject = false;
236 // check the selected GEOM objects
237 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
238 theMenu->addAction( action( ImportGeomObjectId ) );
239 theMenu->addSeparator();
242 // check the selected data model objects
243 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
244 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
246 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
247 if( !anObject.IsNull() )
249 anIsSelectedDataObjects = true;
251 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
252 anIsVisibleInSelection |= aVisibility;
253 anIsHiddenInSelection |= !aVisibility;
255 if( anObject->GetKind() == KIND_IMAGE )
258 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
259 if( !anImage.IsNull() )
261 anIsImportedImage = anImage->HasLocalPoints();
262 anIsImageHasRefs = anImage->HasReferences();
263 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
265 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
267 QString anOperatorName = anOperator->name();
268 if( anOperatorName == ImageComposer_FuseOperator::Type() )
269 anIsFusedImage = true;
270 else if( anOperatorName == ImageComposer_CutOperator::Type() )
272 else if( anOperatorName == ImageComposer_CropOperator::Type() )
273 anIsSplittedImage = true;
276 if ( anImage->IsMustBeUpdated() )
278 anIsMustBeUpdatedImage = true;
282 else if( anObject->GetKind() == KIND_POLYLINE )
284 else if( anObject->GetKind() == KIND_PROFILE )
286 else if( anObject->GetKind() == KIND_CALCULATION )
287 anIsCalculation = true;
288 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
289 anIsImmersibleZone = true;
290 else if( anObject->GetKind() == KIND_VISUAL_STATE )
291 anIsVisualState = true;
292 else if( anObject->GetKind() == KIND_REGION )
294 else if( anObject->GetKind() == KIND_ZONE )
296 else if( anObject->GetKind() == KIND_BATHYMETRY )
297 anIsBathymetry = true;
298 else if( anObject->GetKind() == KIND_OBSTACLE )
302 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
305 // check the selected partitions
306 if( !anIsSelectedDataObjects && anIsObjectBrowser )
308 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
309 if( aSelectedPartition != KIND_UNKNOWN )
311 switch( aSelectedPartition )
314 theMenu->addAction( action( ImportImageId ) );
317 theMenu->addAction( action( CreatePolylineId ) );
320 theMenu->addAction( action( CreateProfileId ) );
322 case KIND_VISUAL_STATE:
323 theMenu->addAction( action( SaveVisualStateId ) );
325 case KIND_BATHYMETRY:
326 theMenu->addAction( action( ImportBathymetryId ) );
328 case KIND_CALCULATION:
329 theMenu->addAction( action( CreateCalculationId ) );
331 case KIND_IMMERSIBLE_ZONE:
332 theMenu->addAction( action( CreateImmersibleZoneId ) );
335 theMenu->addAction( action( ImportObstacleFromFileId ) );
336 theMenu->addAction( action( CreateBoxId ) );
337 theMenu->addAction( action( CreateCylinderId ) );
340 theMenu->addSeparator();
344 if( anIsSelectedDataObjects )
346 if ( anIsMustBeUpdatedImage )
348 theMenu->addAction( action( UpdateImageId ) );
349 theMenu->addSeparator();
352 if( aSeq.Length() == 1 )
356 if( anIsImportedImage )
357 theMenu->addAction( action( EditImportedImageId ) );
358 else if( anIsImageHasRefs )
361 theMenu->addAction( action( EditFusedImageId ) );
362 else if( anIsCutImage )
363 theMenu->addAction( action( EditCutImageId ) );
364 else if( anIsSplittedImage )
365 theMenu->addAction( action( EditSplittedImageId ) );
368 theMenu->addAction( action( ObserveImageId ) );
369 theMenu->addAction( action( ExportImageId ) );
370 theMenu->addSeparator();
372 if( anIsImageHasRefs )
374 theMenu->addAction( action( RemoveImageRefsId ) );
375 theMenu->addSeparator();
378 theMenu->addAction( action( FuseImagesId ) );
379 theMenu->addAction( action( CutImagesId ) );
380 theMenu->addAction( action( SplitImageId ) );
381 theMenu->addSeparator();
383 else if( anIsPolyline )
385 theMenu->addAction( action( EditPolylineId ) );
386 theMenu->addSeparator();
388 else if( anIsProfile )
390 theMenu->addAction( action( EditProfileId ) );
391 theMenu->addSeparator();
393 else if( anIsCalculation )
395 theMenu->addAction( action( EditCalculationId ) );
396 theMenu->addAction( action( ExportCalculationId ) );
397 theMenu->addSeparator();
399 else if( anIsImmersibleZone )
401 theMenu->addAction( action( EditImmersibleZoneId ) );
402 theMenu->addSeparator();
404 else if( anIsVisualState && anIsObjectBrowser )
406 theMenu->addAction( action( SaveVisualStateId ) );
407 theMenu->addAction( action( LoadVisualStateId ) );
408 theMenu->addSeparator();
411 // Add set color action for geometrical objects
412 if ( anIsGeomObject )
414 theMenu->addAction( action( SetColorId ) );
415 theMenu->addSeparator();
419 theMenu->addAction( action( DeleteId ) );
420 theMenu->addSeparator();
422 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
424 if( anIsHiddenInSelection )
425 theMenu->addAction( action( ShowId ) );
426 theMenu->addAction( action( ShowOnlyId ) );
427 if( anIsVisibleInSelection )
428 theMenu->addAction( action( HideId ) );
429 theMenu->addSeparator();
435 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
436 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
437 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
438 theMenu->addAction( action( DeleteId ) );
441 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
443 theMenu->addAction( action( ShowAllId ) );
444 theMenu->addAction( action( HideAllId ) );
445 theMenu->addSeparator();
449 void HYDROGUI_Module::update( const int flags )
451 if( !isUpdateEnabled() )
454 QApplication::setOverrideCursor( Qt::WaitCursor );
456 // To prevent calling this method recursively
457 // from one of the methods called below
458 setUpdateEnabled( false );
460 // store selected objects
461 QStringList aSelectedEntries = storeSelection();
463 bool aDoFitAll = flags & UF_FitAll;
464 if( ( flags & UF_Viewer ) )
465 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
467 if( ( flags & UF_OCCViewer ) )
468 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
470 if( ( flags & UF_VTKViewer ) )
471 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
473 if( ( flags & UF_Model ) && getDataModel() && getApp() )
475 getDataModel()->update( getStudyId() );
477 // Temporary workaround to prevent breaking
478 // the selection in the object browser.
479 // Note: processEvents() should be called after updateGV(),
480 // otherwise the application crashes from time to time.
481 //RKV: qApp->processEvents();
482 getApp()->updateObjectBrowser( true );
485 // Object browser is currently updated by using UF_Model flag
486 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
487 getApp()->updateObjectBrowser( true );
489 if( ( flags & UF_Controls ) && getApp() )
490 getApp()->updateActions();
492 // restore selected objects
493 restoreSelection( aSelectedEntries );
495 setUpdateEnabled( true );
497 QApplication::restoreOverrideCursor();
500 void HYDROGUI_Module::updateCommandsStatus()
502 LightApp_Module::updateCommandsStatus();
504 updateUndoRedoControls();
506 action( CopyId )->setEnabled( getDataModel()->canCopy() );
507 action( PasteId )->setEnabled( getDataModel()->canPaste() );
510 void HYDROGUI_Module::selectionChanged()
512 LightApp_Module::selectionChanged();
513 updateCommandsStatus();
516 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
518 return (HYDROGUI_DataModel*)dataModel();
521 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
526 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
528 return myOCCDisplayer;
531 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
533 return myVTKDisplayer;
536 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
538 if( myViewManagerMap.contains( theId ) )
540 return myViewManagerMap[ theId ].first;
545 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
547 if( myViewManagerMap.contains( theId ) )
549 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
550 GraphicsView_ViewManager* aViewManager =
551 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
553 return aViewManager->getViewer();
558 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
560 if( myViewManagerMap.contains( theId ) )
562 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
563 OCCViewer_ViewManager* aViewManager =
564 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
566 return aViewManager->getOCCViewer();
571 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
573 if( myViewManagerMap.contains( theId ) )
575 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
576 SVTK_ViewManager* aViewManager =
577 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
579 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
584 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
586 ViewManagerMapIterator anIter( myViewManagerMap );
587 while( anIter.hasNext() )
589 int anId = anIter.next().key();
590 const ViewManagerInfo& anInfo = anIter.value();
591 if( anInfo.first == theViewManager )
597 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
599 int anId = getViewManagerId( theViewManager );
602 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
603 return anInfo.second;
608 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
609 const ViewManagerRole theRole )
611 int anId = getViewManagerId( theViewManager );
614 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
615 anInfo.second = theRole;
619 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
620 const Handle(HYDROData_Entity)& theObject ) const
622 if( theObject.IsNull() )
625 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
626 if( anIter1 != myObjectStateMap.end() )
628 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
629 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
630 if( anIter2 != aName2ObjectStateMap.end() )
632 const ObjectState& anObjectState = anIter2.value();
633 return anObjectState.Visibility;
639 void HYDROGUI_Module::setObjectVisible( const int theViewId,
640 const Handle(HYDROData_Entity)& theObject,
641 const bool theState )
643 if( !theObject.IsNull() )
645 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
646 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
647 anObjectState.Visibility = theState;
651 /////////////////// OCC SHAPES PROCESSING
652 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
653 const Handle(HYDROData_Entity)& theObject ) const
655 HYDROGUI_Shape* aResShape = NULL;
656 if( theObject.IsNull() )
659 if ( myShapesMap.contains( theViewId ) )
661 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
662 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
664 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
675 void HYDROGUI_Module::setObjectShape( const int theViewId,
676 const Handle(HYDROData_Entity)& theObject,
677 HYDROGUI_Shape* theShape )
679 if( theObject.IsNull() )
682 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
683 aViewShapes.append( theShape );
686 void HYDROGUI_Module::removeObjectShape( const int theViewId,
687 const Handle(HYDROData_Entity)& theObject )
689 if ( !myShapesMap.contains( theViewId ) )
692 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
693 Handle(HYDROData_Entity) anObject;
694 for ( int i = 0; i < aViewShapes.length(); )
696 HYDROGUI_Shape* aShape = aViewShapes.at( i );
697 anObject = aShape->getObject();
698 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
701 aViewShapes.removeAt( i );
709 void HYDROGUI_Module::removeViewShapes( const int theViewId )
711 if ( !myShapesMap.contains( theViewId ) )
714 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
715 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
717 HYDROGUI_Shape* aShape = aViewShapes.at( i );
722 myShapesMap.remove( theViewId );
724 /////////////////// END OF OCC SHAPES PROCESSING
726 /////////////////// VTKPrs PROCESSING
727 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
728 const Handle(HYDROData_Entity)& theObject ) const
730 HYDROGUI_VTKPrs* aResShape = NULL;
731 if( theObject.IsNull() )
734 if ( myVTKPrsMap.contains( theViewId ) )
736 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
737 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
739 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
750 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
751 const Handle(HYDROData_Entity)& theObject,
752 HYDROGUI_VTKPrs* theShape )
754 if( theObject.IsNull() )
757 // Compute the new global Z range from the added presentation and the old global Z range.
758 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
759 double* aRange = theShape->getInternalZRange();
760 bool anIsUpdate = false;
761 if ( aRange[0] < aGlobalRange[0] )
763 aGlobalRange[0] = aRange[0];
766 if ( aRange[1] > aGlobalRange[1] )
768 aGlobalRange[1] = aRange[1];
774 updateVTKZRange( theViewId, aGlobalRange );
777 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
778 aViewShapes.append( theShape );
781 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
782 const Handle(HYDROData_Entity)& theObject )
784 if ( !myVTKPrsMap.contains( theViewId ) )
787 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
788 Handle(HYDROData_Entity) anObject;
789 for ( int i = 0; i < aViewShapes.length(); )
791 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
792 anObject = aShape->getObject();
793 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
796 aViewShapes.removeAt( i );
803 // Invalidate global Z range
804 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
805 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
808 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
810 if ( !myVTKPrsMap.contains( theViewId ) )
813 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
814 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
816 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
821 myVTKPrsMap.remove( theViewId );
824 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
826 if ( myVTKPrsMap.contains( theViewId ) )
828 // For the given viewer id update all VTK presentations ...
829 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
830 HYDROGUI_VTKPrs* aShape;
831 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
833 aShape = aViewShapes.at( i );
836 aShape->setZRange( theRange );
840 // ... and update the global color legend scalar bar.
841 getVTKDisplayer()->SetZRange( theViewId, theRange );
843 /////////////////// END OF VTKPrs PROCESSING
845 CAM_DataModel* HYDROGUI_Module::createDataModel()
847 return new HYDROGUI_DataModel( this );
850 void HYDROGUI_Module::customEvent( QEvent* e )
852 int aType = e->type();
853 if ( aType == NewViewEvent )
855 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
856 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
858 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
860 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
861 ViewManagerRole aRole = getViewManagerRole( aViewManager );
863 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
865 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
866 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
868 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
869 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
870 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
872 //ouv: temporarily commented
873 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
876 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
879 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
885 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
887 QEvent::Type aType = theEvent->type();
888 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
890 if( aType == QEvent::Show )
892 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
893 e->setData( theObj );
894 QApplication::postEvent( this, e );
895 theObj->removeEventFilter( this );
898 return LightApp_Module::eventFilter( theObj, theEvent );
901 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
903 LightApp_Module::onViewManagerAdded( theViewManager );
905 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
907 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
908 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
910 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
912 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
913 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
916 createSelector( theViewManager ); // replace the default selector
918 ViewManagerInfo anInfo( theViewManager, VMR_General );
919 myViewManagerMap.insert( ViewManagerId++, anInfo );
922 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
924 LightApp_Module::onViewManagerRemoved( theViewManager );
926 createSelector( theViewManager ); // replace the default selector
928 int anId = getViewManagerId( theViewManager );
931 OCCViewer_ViewManager* anOCCViewManager =
932 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
933 if ( anOCCViewManager )
935 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
937 removeViewShapes( (size_t)anOCCViewer );
940 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
942 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
945 getVTKDisplayer()->DeleteScalarBar( anId );
946 removeViewShapes( (size_t)aVTKViewer );
950 myViewManagerMap.remove( anId );
954 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
956 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
958 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
960 aViewFrame->installEventFilter( this );
962 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
964 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
965 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
968 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
970 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
972 aViewFrame->onTopView();
977 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
979 /* ouv: currently unused
980 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
982 SUIT_ViewManager* aViewManager = 0;
984 QObject* aParent = aViewPort;
985 while( aParent = aParent->parent() )
987 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
989 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
991 aViewManager = aViewer->getViewManager();
1000 double aMouseX = theEvent->scenePos().x();
1001 double aMouseY = theEvent->scenePos().y();
1003 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1004 if( aRole == VMR_General )
1006 int aXDeg = 0, aYDeg = 0;
1007 int aXMin = 0, aYMin = 0;
1008 double aXSec = 0, aYSec = 0;
1009 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1010 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1012 QString aDegSymbol( QChar( 0x00B0 ) );
1013 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1014 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1016 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1018 else if( aRole == VMR_TransformImage )
1019 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1024 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1025 const bool theIsInit,
1026 const bool theIsForced,
1027 const bool theDoFitAll )
1029 QList<int> aViewManagerIdList;
1031 // currently, all views are updated
1032 ViewManagerMapIterator anIter( myViewManagerMap );
1033 while( anIter.hasNext() )
1035 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1037 if ( theDisplayer->IsApplicable( aViewManager ) )
1039 int anId = anIter.key();
1040 aViewManagerIdList.append( anId );
1044 QListIterator<int> anIdIter( aViewManagerIdList );
1045 while( anIdIter.hasNext() )
1047 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1051 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1053 if( !theViewManager )
1056 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1057 if( !aSelectionMgr )
1060 QString aViewType = theViewManager->getType();
1061 if( aViewType != GraphicsView_Viewer::Type() &&
1062 aViewType != OCCViewer_Viewer::Type())
1065 QList<SUIT_Selector*> aSelectorList;
1066 aSelectionMgr->selectors( aViewType, aSelectorList );
1068 // disable all alien selectors
1069 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1070 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1072 SUIT_Selector* aSelector = *anIter;
1073 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1074 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1075 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1076 aSelector->setEnabled( false );
1079 if ( aViewType == GraphicsView_Viewer::Type() )
1081 GraphicsView_ViewManager* aViewManager =
1082 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1084 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1086 else if ( aViewType == OCCViewer_Viewer::Type() )
1088 OCCViewer_ViewManager* aViewManager =
1089 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1091 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1095 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1097 bool aPrevState = myIsUpdateEnabled;
1098 myIsUpdateEnabled = theState;
1102 bool HYDROGUI_Module::isUpdateEnabled() const
1104 return myIsUpdateEnabled;
1107 QStringList HYDROGUI_Module::storeSelection() const
1109 QStringList anEntryList;
1110 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1112 SUIT_DataOwnerPtrList aList( true );
1113 aSelectionMgr->selected( aList );
1115 SUIT_DataOwnerPtrList::iterator anIter;
1116 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1118 const LightApp_DataOwner* anOwner =
1119 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1121 anEntryList.append( anOwner->entry() );
1127 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1129 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1131 SUIT_DataOwnerPtrList aList( true );
1132 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1133 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1134 aSelectionMgr->setSelected( aList );