From: rkv Date: Wed, 20 Nov 2013 09:38:21 +0000 (+0000) Subject: - VTKPrsDisplayer is introduced for Bathymetry visualization. X-Git-Tag: BR_hydro_v_0_3_1~40 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d5288d46b0d85156f7666edf2cef050dc6655eae;p=modules%2Fhydro.git - VTKPrsDisplayer is introduced for Bathymetry visualization. - All displayers are inherited from the abstract displayer. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 68865e5d..3c6f8487 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,8 @@ ENDIF(SALOME_BUILD_GUI) FIND_PACKAGE(SalomeCAS REQUIRED) +FIND_PACKAGE(SalomeVTK REQUIRED) + FIND_PACKAGE(SalomeSIP REQUIRED) # should come after Python and before PyQt4 FIND_PACKAGE(SalomePyQt4 REQUIRED) diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index a3666627..52ad4000 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -51,6 +51,11 @@ set(PROJECT_HEADERS HYDROGUI_UpdateFlags.h HYDROGUI_UpdateImageOp.h HYDROGUI_VisualStateOp.h + HYDROGUI_VTKPrs.h + HYDROGUI_VTKPrsBathymetry.h + HYDROGUI_VTKPrsBathymetryDriver.h + HYDROGUI_VTKPrsDisplayer.h + HYDROGUI_VTKPrsDriver.h HYDROGUI_Wizard.h HYDROGUI_Zone.h HYDROGUI_ImportGeomObjectOp.h @@ -111,6 +116,11 @@ set(PROJECT_SOURCES HYDROGUI_TwoImagesOp.cxx HYDROGUI_UpdateImageOp.cxx HYDROGUI_VisualStateOp.cxx + HYDROGUI_VTKPrs.cxx + HYDROGUI_VTKPrsBathymetry.cxx + HYDROGUI_VTKPrsBathymetryDriver.cxx + HYDROGUI_VTKPrsDisplayer.cxx + HYDROGUI_VTKPrsDriver.cxx HYDROGUI_Wizard.cxx HYDROGUI_Zone.cxx HYDROGUI_ImportGeomObjectOp.cxx @@ -142,13 +152,16 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROData ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROCurveCreator + ${VTK_INCLUDE_DIRS} ) + add_library(HYDROGUI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_HEADERS_MOC}) target_link_libraries(HYDROGUI HYDROData HYDROCurveCreator ${CAS_TKV3d} ${CAS_TKTopAlgo} ${CAS_TKBrep} ${CAS_TKBO} - ${GUI_LightApp} ${GUI_CAM} ${GUI_suit} ${GUI_qtx} ${GUI_ObjBrowser} ${GUI_GraphicsView} ${GUI_std} ${GUI_Event} ${GUI_OCCViewer} - ${GEOM_GEOM} ${GEOM_GEOMBase} + ${GUI_LightApp} ${GUI_CAM} ${GUI_suit} ${GUI_qtx} ${GUI_ObjBrowser} ${GUI_GraphicsView} ${GUI_std} + ${GUI_Event} ${GUI_OCCViewer} ${GEOM_GEOM} ${GEOM_GEOMBase} + ${VTK_LIBRARIES} ${SVTK} ${SalomeObject} ${SalomePrs} ) INSTALL(TARGETS HYDROGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) diff --git a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx index 7817f3cc..8a1262bd 100644 --- a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx @@ -26,6 +26,8 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include + HYDROGUI_AbstractDisplayer::HYDROGUI_AbstractDisplayer( HYDROGUI_Module* theModule ) : myModule( theModule ) { @@ -35,6 +37,16 @@ HYDROGUI_AbstractDisplayer::~HYDROGUI_AbstractDisplayer() { } +bool HYDROGUI_AbstractDisplayer::IsApplicable( const int theViewerId ) const +{ + return IsApplicable( myModule->getViewManager( theViewerId ) ); +} + +bool HYDROGUI_AbstractDisplayer::IsApplicable( const SUIT_ViewManager* theViewMgr ) const +{ + return ( theViewMgr && ( theViewMgr->getType() == GetType() ) ); +} + void HYDROGUI_AbstractDisplayer::UpdateAll( const int theViewerId, const bool theIsInit, const bool theIsForced, diff --git a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.h b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.h index ec3f9ed4..6438d3dd 100644 --- a/src/HYDROGUI/HYDROGUI_AbstractDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_AbstractDisplayer.h @@ -26,6 +26,7 @@ #include class HYDROGUI_Module; +class SUIT_ViewManager; /** * \class HYDROGUI_DataModel @@ -46,6 +47,20 @@ public: virtual ~HYDROGUI_AbstractDisplayer(); public: + /** + * \brief Check if this displayer is applicable to the given view manager. + * The view manager method getType is used. + * \param theViewerId viewer identifier + */ + virtual bool IsApplicable( const int theViewerId ) const; + + /** + * \brief Check if this displayer is applicable to the given view manager. + * The view manager method getType is used. + * \param theViewMgr the view manager to check + */ + virtual bool IsApplicable( const SUIT_ViewManager* theViewMgr ) const; + /** * \brief Update all objects in the viewer. * \param theViewerId viewer identifier @@ -65,6 +80,11 @@ public: virtual void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId ) = 0; + /** + * \brief Get the applicable viewer type. + */ + virtual QString GetType() const = 0; + protected: /** * \brief Update and display all objects in the viewer. @@ -113,6 +133,7 @@ protected: const bool theIsForced, const bool theDoFitAll ) = 0; +protected: /** * \brief Purge all invalid objects in the viewer. * \param theViewerId viewer identifier diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index 006c64c4..570ba30c 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -216,3 +216,8 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity return aDriver; } + +QString HYDROGUI_Displayer::GetType() const +{ + return GraphicsView_Viewer::Type(); +} diff --git a/src/HYDROGUI/HYDROGUI_Displayer.h b/src/HYDROGUI/HYDROGUI_Displayer.h index 4d808272..f7948dca 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.h +++ b/src/HYDROGUI/HYDROGUI_Displayer.h @@ -29,11 +29,9 @@ class HYDROGUI_PrsDriver; -class GraphicsView_Viewer; - /** - * \class HYDROGUI_DataModel - * \brief Class intended to create, display and update the presentations. + * \class HYDROGUI_Displayer + * \brief Class intended to create, display and update the presentations in 2D graphics viewer. */ class HYDROGUI_Displayer : public HYDROGUI_AbstractDisplayer { @@ -55,23 +53,28 @@ public: * \param theObjs sequence of objects to update * \param theViewerId viewer identifier */ - void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, - const int theViewerId ); + void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ); + + /** + * \brief Get the applicable viewer type. + */ + virtual QString GetType() const; protected: /** * \brief Erase all viewer objects. * \param theViewerId viewer identifier */ - void EraseAll( const int theViewerId ); + void EraseAll( const int theViewerId ); /** * \brief Erase the specified viewer objects. * \param theObjs sequence of objects to erase * \param theViewerId viewer identifier */ - void Erase( const HYDROData_SequenceOfObjects& theObjs, - const int theViewerId ); + void Erase( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ); /** * \brief Display the specified viewer objects. @@ -80,16 +83,17 @@ protected: * \param theIsForced flag used to update all objects, including the unchanged ones * \param theDoFitAll flag used to fit the view to all visible objects; do not fit by default */ - void Display( const HYDROData_SequenceOfObjects& theObjs, - const int theViewerId, - const bool theIsForced, - const bool theDoFitAll ); + void Display( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId, + const bool theIsForced, + const bool theDoFitAll ); +protected: /** * \brief Purge all invalid objects in the viewer. * \param theViewerId viewer identifier */ - void purgeObjects( const int theViewerId ); + void purgeObjects( const int theViewerId ); private: /** diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 5af8b51b..28fc93e7 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -35,6 +35,9 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_Shape.h" +#include "HYDROGUI_VTKPrs.h" +#include "HYDROGUI_VTKPrsDisplayer.h" +#include "HYDROGUI_AbstractDisplayer.h" #include #include @@ -68,6 +71,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -118,6 +125,7 @@ void HYDROGUI_Module::initialize( CAM_Application* theApp ) myDisplayer = new HYDROGUI_Displayer( this ); myOCCDisplayer = new HYDROGUI_OCCDisplayer( this ); + myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this ); } bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) @@ -196,7 +204,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType(); bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type(); bool anIsOCCView = theClient == OCCViewer_Viewer::Type(); - if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView ) + bool anIsVTKView = theClient == SVTK_Viewer::Type(); + if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView ) return; size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this ); @@ -213,6 +222,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsSplittedImage = false; bool anIsMustBeUpdatedImage = false; bool anIsPolyline = false; + bool anIsBathymetry = false; bool anIsCalculation = false; bool anIsImmersibleZone = false; bool anIsVisualState = false; @@ -279,6 +289,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsRegion = true; else if( anObject->GetKind() == KIND_ZONE ) anIsZone = true; + else if( anObject->GetKind() == KIND_BATHYMETRY ) + anIsBathymetry = true; else if( anObject->GetKind() == KIND_OBSTACLE ) anIsObstacle = true; } @@ -395,7 +407,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( DeleteId ) ); theMenu->addSeparator(); - if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsObstacle ) + if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); @@ -406,7 +418,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, } } - if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView ) + if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView ) { theMenu->addAction( action( ShowAllId ) ); theMenu->addAction( action( HideAllId ) ); @@ -428,15 +440,15 @@ void HYDROGUI_Module::update( const int flags ) // store selected objects QStringList aSelectedEntries = storeSelection(); + bool aDoFitAll = flags & UF_FitAll; if( ( flags & UF_Viewer ) ) - updateGV( flags & UF_GV_Init, - flags & UF_GV_Forced, - flags & UF_FitAll ); + updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll ); if( ( flags & UF_OCCViewer ) ) - updateOCCViewer( flags & UF_OCC_Init, - flags & UF_OCC_Forced, - flags & UF_FitAll ); + updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll ); + + if( ( flags & UF_VTKViewer ) ) + updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll ); if( ( flags & UF_Model ) && getDataModel() && getApp() ) { @@ -496,6 +508,20 @@ HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const return myOCCDisplayer; } +HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const +{ + return myVTKDisplayer; +} + +SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const +{ + if( myViewManagerMap.contains( theId ) ) + { + return myViewManagerMap[ theId ].first; + } + return NULL; +} + GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const { if( myViewManagerMap.contains( theId ) ) @@ -522,6 +548,19 @@ OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const return NULL; } +SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const +{ + if( myViewManagerMap.contains( theId ) ) + { + ViewManagerInfo anInfo = myViewManagerMap[ theId ]; + SVTK_ViewManager* aViewManager = + ::qobject_cast( anInfo.first ); + if( aViewManager ) + return dynamic_cast( aViewManager->getViewModel() ); + } + return NULL; +} + int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager ) { ViewManagerMapIterator anIter( myViewManagerMap ); @@ -589,6 +628,7 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId, } } +/////////////////// OCC SHAPES PROCESSING HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const { @@ -661,6 +701,82 @@ void HYDROGUI_Module::removeViewShapes( const int theViewId ) myShapesMap.remove( theViewId ); } +/////////////////// END OF OCC SHAPES PROCESSING + +/////////////////// VTKPrs PROCESSING +HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject ) const +{ + HYDROGUI_VTKPrs* aResShape = NULL; + if( theObject.IsNull() ) + return aResShape; + + if ( myVTKPrsMap.contains( theViewId ) ) + { + const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId ); + foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes ) + { + if ( !aShape || !IsEqual( aShape->getObject(), theObject ) ) + continue; + + aResShape = aShape; + break; + } + } + + return aResShape; +} + +void HYDROGUI_Module::setObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject, + HYDROGUI_VTKPrs* theShape ) +{ + if( theObject.IsNull() ) + return; + + ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ]; + aViewShapes.append( theShape ); +} + +void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject ) +{ + if ( !myVTKPrsMap.contains( theViewId ) ) + return; + + ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ]; + Handle(HYDROData_Entity) anObject; + for ( int i = 0; i < aViewShapes.length(); ) + { + HYDROGUI_VTKPrs* aShape = aViewShapes.at( i ); + anObject = aShape->getObject(); + if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) ) + { + delete aShape; + aViewShapes.removeAt( i ); + continue; + } + + ++i; + } +} + +void HYDROGUI_Module::removeViewVTKPrs( const int theViewId ) +{ + if ( !myVTKPrsMap.contains( theViewId ) ) + return; + + const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId ); + for ( int i = 0, n = aViewShapes.length(); i < n; ++i ) + { + HYDROGUI_VTKPrs* aShape = aViewShapes.at( i ); + if ( aShape ) + delete aShape; + } + + myVTKPrsMap.remove( theViewId ); +} +/////////////////// END OF VTKPrs PROCESSING CAM_DataModel* HYDROGUI_Module::createDataModel() { @@ -831,59 +947,31 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent ) */ } -void HYDROGUI_Module::updateGV( const bool theIsInit, - const bool theIsForced, - const bool theDoFitAll ) +void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, + const bool theIsInit, + const bool theIsForced, + const bool theDoFitAll ) { - if( !getDisplayer() ) - return; - QList aViewManagerIdList; // currently, all views are updated ViewManagerMapIterator anIter( myViewManagerMap ); while( anIter.hasNext() ) { - GraphicsView_ViewManager* aViewManager = - dynamic_cast( anIter.next().value().first ); - if ( !aViewManager ) - continue; + SUIT_ViewManager* aViewManager = anIter.next().value().first; - int anId = anIter.key(); - aViewManagerIdList.append( anId ); + if ( theDisplayer->IsApplicable( aViewManager ) ) + { + int anId = anIter.key(); + aViewManagerIdList.append( anId ); + } } QListIterator anIdIter( aViewManagerIdList ); while( anIdIter.hasNext() ) - getDisplayer()->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll ); -} - -void HYDROGUI_Module::updateOCCViewer( const bool theIsInit, - const bool theIsForced, - const bool theDoFitAll ) -{ - HYDROGUI_OCCDisplayer* anOCCDisplayer = getOCCDisplayer(); - if( !anOCCDisplayer ) - return; - - QList aViewManagerIdList; - - // currently, all views are updated - ViewManagerMapIterator anIter( myViewManagerMap ); - while( anIter.hasNext() ) - { - OCCViewer_ViewManager* aViewManager = - ::qobject_cast( anIter.next().value().first ); - if ( !aViewManager ) - continue; - - int anId = anIter.key(); - aViewManagerIdList.append( anId ); + { + theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll ); } - - QListIterator anIdIter( aViewManagerIdList ); - while( anIdIter.hasNext() ) - anOCCDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll ); } void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager ) @@ -909,6 +997,7 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager ) { SUIT_Selector* aSelector = *anIter; if( aSelector && ( !dynamic_cast( aSelector ) && + !dynamic_cast( aSelector ) && !dynamic_cast( aSelector ) ) ) aSelector->setEnabled( false ); } diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index d2825208..0aaf8f0b 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -32,15 +32,19 @@ class QGraphicsSceneMouseEvent; class GraphicsView_Viewer; +class OCCViewer_Viewer; +class SVTK_Viewer; class SUIT_ViewWindow; +class SUIT_ViewManager; class HYDROGUI_DataModel; class HYDROGUI_Displayer; class HYDROGUI_OCCDisplayer; +class HYDROGUI_VTKPrsDisplayer; +class HYDROGUI_AbstractDisplayer; class HYDROGUI_Shape; - -class OCCViewer_Viewer; +class HYDROGUI_VTKPrs; /**\class HYDROGUI_Module *\brief The class representing the HYDROGUI module @@ -81,6 +85,9 @@ public: typedef QList ListOfShapes; typedef QMap ViewId2ListOfShapes; + typedef QList ListOfVTKPrs; + typedef QMap ViewId2ListOfVTKPrs; + public: HYDROGUI_Module(); virtual ~HYDROGUI_Module(); @@ -98,12 +105,15 @@ public: virtual void selectionChanged(); + SUIT_ViewManager* getViewManager( const int theId ) const; HYDROGUI_DataModel* getDataModel() const; HYDROGUI_Displayer* getDisplayer() const; HYDROGUI_OCCDisplayer* getOCCDisplayer() const; + HYDROGUI_VTKPrsDisplayer* getVTKDisplayer() const; GraphicsView_Viewer* getViewer( const int theId ) const; OCCViewer_Viewer* getOCCViewer( const int theId ) const; + SVTK_Viewer* getVTKViewer( const int theId ) const; int getViewManagerId( SUIT_ViewManager* theViewManager ); ViewManagerRole getViewManagerRole( SUIT_ViewManager* theViewManager ); @@ -121,10 +131,19 @@ public: void setObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject, HYDROGUI_Shape* theShape ); - void removeViewShapes( const int theViewId ); + void removeViewShapes( const int theViewId ); void removeObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ); + HYDROGUI_VTKPrs* getObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject ) const; + void setObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject, + HYDROGUI_VTKPrs* theShape ); + void removeViewVTKPrs( const int theViewId ); + void removeObjectVTKPrs( const int theViewId, + const Handle(HYDROData_Entity)& theObject ); + QStringList GetGeomObjectsToImport(); protected: @@ -157,13 +176,10 @@ protected slots: const QStringList& ); private: - void updateGV( const bool theIsInit = false, - const bool theIsForced = false, - const bool theDoFitAll = false ); - - void updateOCCViewer( const bool theIsInit = false, - const bool theIsForced = false, - const bool theDoFitAll = false ); + void updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, + const bool theIsInit = false, + const bool theIsForced = false, + const bool theDoFitAll = false ); void createSelector( SUIT_ViewManager* viewMgr ); @@ -191,11 +207,13 @@ private: private: HYDROGUI_Displayer* myDisplayer; HYDROGUI_OCCDisplayer* myOCCDisplayer; + HYDROGUI_VTKPrsDisplayer* myVTKDisplayer; ViewManagerMap myViewManagerMap; ViewId2Name2ObjectStateMap myObjectStateMap; ViewId2ListOfShapes myShapesMap; + ViewId2ListOfVTKPrs myVTKPrsMap; bool myIsUpdateEnabled; diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 9d3e2cf4..602cb5cb 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -194,4 +194,7 @@ void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) } } - +QString HYDROGUI_OCCDisplayer::GetType() const +{ + return OCCViewer_Viewer::Type(); +} diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index 69b976ee..681e137a 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -55,6 +55,11 @@ public: void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId ); + /** + * \brief Get the applicable viewer type. + */ + virtual QString GetType() const; + protected: /** * \brief Erase all viewer objects. @@ -82,6 +87,7 @@ protected: const bool theIsForced, const bool theDoFitAll ); +protected: /** * \brief Purge all invalid objects in the viewer. * \param theViewerId viewer identifier diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index b1ddd661..755e933a 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -36,6 +36,7 @@ #include #include +#include #include @@ -130,6 +131,10 @@ void HYDROGUI_ShowHideOp::startOperation() { anUpdateFlags |= UF_OCCViewer; } + else if ( aViewMgr->getType() == SVTK_Viewer::Type() ) + { + anUpdateFlags |= UF_VTKViewer; + } } module()->update( anUpdateFlags ); diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 5e026dd4..45214704 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -217,6 +217,7 @@ void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule, ( anObject->GetKind() == KIND_POLYLINE ) || ( anObject->GetKind() == KIND_IMMERSIBLE_ZONE ) || ( anObject->GetKind() == KIND_REGION ) || + ( anObject->GetKind() == KIND_BATHYMETRY ) || ( anObject->GetKind() == KIND_ZONE ) || ( anObject->GetKind() == KIND_OBSTACLE ) ) ) { diff --git a/src/HYDROGUI/HYDROGUI_UpdateFlags.h b/src/HYDROGUI/HYDROGUI_UpdateFlags.h index 14ef92ef..c7831fbe 100644 --- a/src/HYDROGUI/HYDROGUI_UpdateFlags.h +++ b/src/HYDROGUI/HYDROGUI_UpdateFlags.h @@ -42,6 +42,10 @@ typedef enum UF_OCC_Init = 0x00000100, //!< initial update (used with UF_OCCViewer) UF_OCC_Forced = 0x00000200, //!< to force recomputing all presentations (used with UF_OCCViewer) + UF_VTKViewer = 0x00000800, //!< OCC viewer + UF_VTK_Init = 0x00001000, //!< initial update (used with UF_OCCViewer) + UF_VTK_Forced = 0x00002000, //!< to force recomputing all presentations (used with UF_OCCViewer) + UF_FitAll = 0x00000400, //!< to do fit all (used with UF_Viewer or UF_OCCViewer) UF_All = UF_Base | UF_GV_Init | UF_GV_Forced | UF_OCCViewer | UF_OCC_Init | UF_OCC_Forced//!< all update flags diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.cxx b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx new file mode 100644 index 00000000..ad2fd392 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.cxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_VTKPrs.h" + +#include "HYDROGUI_DataObject.h" + +//======================================================================= +// name : HYDROGUI_VTKPrs +// Purpose : Constructor +//======================================================================= +HYDROGUI_VTKPrs::HYDROGUI_VTKPrs( const Handle(HYDROData_Entity)& theObject ) +: myObject( theObject ), + myIsToUpdate( false ) +{ + // Define IO for actors to be added: + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject ); + myIO = new SALOME_InteractiveObject( + anEntry.toAscii(), QString::number( theObject->GetKind() ).toAscii(), theObject->GetName().toAscii() ); +} + +//======================================================================= +// name : HYDROGUI_VTKPrs +// Purpose : Destructor +//======================================================================= +HYDROGUI_VTKPrs::~HYDROGUI_VTKPrs() +{ +} + +//======================================================================= +// name : compute +// Purpose : Compute the presentation +//======================================================================= +void HYDROGUI_VTKPrs::compute() +{ +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrs.h b/src/HYDROGUI/HYDROGUI_VTKPrs.h new file mode 100644 index 00000000..d679856a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrs.h @@ -0,0 +1,56 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_VTKPrs_H +#define HYDROGUI_VTKPrs_H + +#include + +#include +#include + +/* + Class : HYDROGUI_VTKPrs + Description : Base class for all HYDRO presentation in VTK viewer +*/ +class HYDROGUI_VTKPrs : public SVTK_Prs +{ +public: + HYDROGUI_VTKPrs( const Handle(HYDROData_Entity)& theObject ); + virtual ~HYDROGUI_VTKPrs(); + + virtual void compute(); + +public: + Handle(HYDROData_Entity) getObject() const { return myObject; } + Handle(SALOME_InteractiveObject) getIO() const { return myIO; } + + bool getIsToUpdate() const { return myIsToUpdate; } + void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } + +private: + Handle(HYDROData_Entity) myObject; + Handle(SALOME_InteractiveObject) myIO; + bool myIsToUpdate; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx new file mode 100644 index 00000000..16983bf2 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -0,0 +1,98 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_VTKPrsBathymetry.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +//======================================================================= +// name : HYDROGUI_VTKPrsBathymetry +// Purpose : Constructor +//======================================================================= +HYDROGUI_VTKPrsBathymetry::HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject ) +: HYDROGUI_VTKPrs( theObject ) +{ +} + +//======================================================================= +// name : HYDROGUI_VTKPrsBathymetry +// Purpose : Destructor +//======================================================================= +HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry() +{ +} + +//================================================================ +// Function : compute +// Purpose : +//================================================================ +void HYDROGUI_VTKPrsBathymetry::compute() +{ + if ( !getObject().IsNull() ) + { + Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() ); + if ( !aBathymetry.IsNull() ) + { + HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints(); + int aNbPoints = anAltPoints.length(); + + HYDROData_Bathymetry::AltitudePoint anAltPnt; + vtkPoints* aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints( aNbPoints ); + + vtkPolyData* aVertexGrid = vtkPolyData::New(); + aVertexGrid->Allocate( aNbPoints ); + + vtkVertex* aVertex = vtkVertex::New(); + + for (int i = 0; i < aNbPoints; i++ ) + { + anAltPnt = anAltPoints.at( i ); + aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), anAltPnt.Z() ); + aVertex->GetPointIds()->SetId( 0, i ); + aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds()); + } + + aVertex->Delete(); + + aVertexGrid->SetPoints( aPoints ); + vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); + aMapper->SetInputData( aVertexGrid ); + SALOME_Actor* anActor = SALOME_Actor::New(); + anActor->SetMapper( aMapper ); + anActor->setIO( getIO() ); + //anActor->setName( aBathymetry->GetName().toLatin1() ); + AddObject( anActor ); + //anActor.AddPosition(0, 0, 6); + //anActor.GetProperty().SetDiffuseColor(1, 1, 1); + } + } +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h new file mode 100644 index 00000000..3a4098c7 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.h @@ -0,0 +1,43 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_VTKPrsBathymetry_H +#define HYDROGUI_VTKPrsBathymetry_H + +#include "HYDROGUI_VTKPrs.h" + +#include + +/* + Class : HYDROGUI_VTKPrsBathymetry + Description : Presentation for Bathymetry object +*/ +class HYDROGUI_VTKPrsBathymetry : public HYDROGUI_VTKPrs +{ +public: + HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject ); + virtual ~HYDROGUI_VTKPrsBathymetry(); + + virtual void compute(); +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx new file mode 100644 index 00000000..a00cc17a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.cxx @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_VTKPrsBathymetryDriver.h" + +#include "HYDROGUI_VTKPrsBathymetry.h" + +#include + +HYDROGUI_VTKPrsBathymetryDriver::HYDROGUI_VTKPrsBathymetryDriver() +{ +} + +HYDROGUI_VTKPrsBathymetryDriver::~HYDROGUI_VTKPrsBathymetryDriver() +{ +} + +bool HYDROGUI_VTKPrsBathymetryDriver::Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ) +{ + HYDROGUI_VTKPrsDriver::Update( theObj, thePrs ); + + if( theObj.IsNull() ) + return false; + + Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( theObj ); + if( aBathymetry.IsNull() ) + return false; + + if( !thePrs ) + thePrs = new HYDROGUI_VTKPrsBathymetry( aBathymetry ); + + HYDROGUI_VTKPrsBathymetry* aPrsBathymetry = (HYDROGUI_VTKPrsBathymetry*)thePrs; + + //aPrsBathymetry->setName( aBathymetry->GetName() ); + //aPrsBathymetry->setPath( aBathymetry->GetPainterPath() ); + + aPrsBathymetry->compute(); + + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h new file mode 100644 index 00000000..37bee693 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetryDriver.h @@ -0,0 +1,56 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_VTKPrsBathymetryDRIVER_H +#define HYDROGUI_VTKPrsBathymetryDRIVER_H + +#include + +/** + * \class HYDROGUI_VTKPrsBathymetryDriver + * \brief Presentation driver for Bathymetry objects. + */ +class HYDROGUI_VTKPrsBathymetryDriver : public HYDROGUI_VTKPrsDriver +{ +public: + /** + * \brief Constructor. + */ + HYDROGUI_VTKPrsBathymetryDriver(); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_VTKPrsBathymetryDriver(); + +public: + /** + * \brief Update or create the Bathymetry presentation on a basis of data object. + * \param theObj data object + * \param thePrs presentation + * \return status of the operation + */ + virtual bool Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ); +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx new file mode 100644 index 00000000..101176f8 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -0,0 +1,207 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_VTKPrsDisplayer.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_VTKPrs.h" +#include "HYDROGUI_VTKPrsBathymetryDriver.h" +#include "HYDROGUI_Tool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule ) +: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ) +{ +} + +HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer() +{ +} + +void HYDROGUI_VTKPrsDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( !aViewer ) + { + HYDROGUI_VTKPrs* anObjShape; + for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) + { + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); + if( !anObj.IsNull() ) + { + anObjShape = module()->getObjectVTKPrs( (size_t)aViewer, anObj ); + if ( anObjShape ) + { + anObjShape->setIsToUpdate( true ); + } + } + } + } +} + +void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId ) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + aViewer->EraseAll( true ); + module()->removeViewVTKPrs( (size_t)aViewer ); + } +} + +void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + HYDROGUI_VTKPrs* aPrs; + for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) + { + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); + if( anObj.IsNull() ) + continue; + + aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj ); + if ( aPrs ) + { + aViewer->Erase( aPrs, true ); + } + module()->removeObjectVTKPrs( (size_t)aViewer, anObj ); + } + } +} + +void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId, + const bool theIsForced, + const bool theDoFitAll) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + bool isChanged = false; + HYDROGUI_VTKPrs* aPrs; + for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) + { + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); + if( !anObj.IsNull() ) + { + bool anIsVisible = module()->isObjectVisible( (size_t)(aViewer->getViewManager()->getViewModel()), anObj ); + aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj ); + + bool anIsInserted = ( aPrs != 0 ); + if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) ) + { + if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( anObj ) ) + { + if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted ) + { + module()->setObjectVTKPrs( theViewerId, anObj, aPrs ); + aViewer->Display( aPrs ); + isChanged = true; + } + } + } + + if( aPrs && !anIsVisible ) + { + aViewer->Erase( aPrs ); + isChanged = true; + } + } + } + + if ( theDoFitAll ) + { + // Repaint is done inside OnFitAll() + aViewer->getViewManager()->getActiveView()->onAccelAction( SUIT_Accel::ZoomFit ); + } + else if ( isChanged ) + { + aViewer->Repaint(); + } + } +} + +void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId ) +{ + SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId ); + if( aViewer ) + { + SALOME_ListIO aListIO; + aViewer->GetVisible( aListIO ); + + HYDROGUI_VTKPrs* aPrs; + SALOME_ListIteratorOfListIO anIter( aListIO ); + for( ; anIter.More(); anIter.Next() ) + { + Handle(SALOME_InteractiveObject) aPrsObj = anIter.Value(); + if ( !aPrsObj.IsNull() ) + { + Handle(HYDROData_Entity) anOwnerObj = + module()->getDataModel()->objectByEntry( aPrsObj->getEntry() ); + if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() ) + { + aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anOwnerObj ); + if ( aPrs ) + { + aViewer->Erase( aPrs ); + } + module()->removeObjectVTKPrs( (size_t)aViewer, anOwnerObj ); + } + } + } + } +} + +HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDROData_Entity)& theObj ) +{ + HYDROGUI_VTKPrsDriver* aDriver = NULL; + ObjectKind aKind = theObj->GetKind(); + if( theObj->GetKind() == KIND_BATHYMETRY ) + { + if ( !myDriver ) + { + myDriver = new HYDROGUI_VTKPrsBathymetryDriver(); + } + aDriver = myDriver; + } + + return aDriver; +} + +QString HYDROGUI_VTKPrsDisplayer::GetType() const +{ + return SVTK_Viewer::Type(); +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h new file mode 100644 index 00000000..6e53647a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h @@ -0,0 +1,106 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_VTKPRSDISPLAYER_H +#define HYDROGUI_VTKPRSDISPLAYER_H + +#include "HYDROGUI_AbstractDisplayer.h" + +class HYDROGUI_VTKPrsDriver; + +/** + * \class HYDROGUI_VTKPrsDisplayer + * \brief Class intended to create, display and update the presentations in VTK viewer. + */ +class HYDROGUI_VTKPrsDisplayer : public HYDROGUI_AbstractDisplayer +{ +public: + /** + * \brief Constructor. + * \param theModule module object + */ + HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule ); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_VTKPrsDisplayer(); + +public: + /** + * \brief Force the specified objects to be updated. + * \param theObjs sequence of objects to update + * \param theViewerId viewer identifier + */ + void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ); + + /** + * \brief Get the applicable viewer type. + */ + virtual QString GetType() const; + +protected: + /** + * \brief Erase all viewer objects. + * \param theViewerId viewer identifier + */ + void EraseAll( const int theViewerId ); + + /** + * \brief Erase the specified viewer objects. + * \param theObjs sequence of objects to erase + * \param theViewerId viewer identifier + */ + void Erase( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId ); + + /** + * \brief Display the specified viewer objects. + * \param theObjs sequence of objects to display + * \param theViewerId viewer identifier + * \param theIsForced flag used to update all objects, including the unchanged ones + * \param theDoFitAll flag used to fit the view to all visible objects; do not fit by default + */ + void Display( const HYDROData_SequenceOfObjects& theObjs, + const int theViewerId, + const bool theIsForced, + const bool theDoFitAll ); + +protected: + /** + * \brief Purge all invalid objects in the viewer. + * \param theViewerId viewer identifier + */ + void purgeObjects( const int theViewerId ); + +private: + /** + * \brief Get the presentation driver for the specified data object. + * \param theObj data object + */ + HYDROGUI_VTKPrsDriver* getDriver( const Handle(HYDROData_Entity)& theObj ); + + HYDROGUI_VTKPrsDriver* myDriver; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDriver.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDriver.cxx new file mode 100644 index 00000000..1dceef46 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDriver.cxx @@ -0,0 +1,41 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_VTKPrsDriver.h" + +#include "HYDROGUI_VTKPrs.h" + +HYDROGUI_VTKPrsDriver::HYDROGUI_VTKPrsDriver() +{ +} + +HYDROGUI_VTKPrsDriver::~HYDROGUI_VTKPrsDriver() +{ +} + +bool HYDROGUI_VTKPrsDriver::Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ) +{ + if ( thePrs ) + thePrs->setIsToUpdate( false ); + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDriver.h b/src/HYDROGUI/HYDROGUI_VTKPrsDriver.h new file mode 100644 index 00000000..a66a25da --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDriver.h @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_VTKPrsDRIVER_H +#define HYDROGUI_VTKPrsDRIVER_H + +#include + +class HYDROGUI_VTKPrs; + +/** + * \class HYDROGUI_VTKPrsDriver + * \brief Base class of presentation driver, which allows to build a + * VTK presentation on a basis of data object. + */ +class HYDROGUI_VTKPrsDriver +{ +public: + /** + * \brief Constructor. + */ + HYDROGUI_VTKPrsDriver(); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_VTKPrsDriver(); + +public: + /** + * \brief Virtual method intended to update or create the presentation + * on a basis of data object. + * \param theObj data object + * \param thePrs presentation + * \return status of the operation + */ + virtual bool Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ); +}; + +#endif