From 1543974bfa2f67e3ffbfa3f45432d40c716051d7 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 6 Apr 2023 13:32:45 +0200 Subject: [PATCH] Management of visibility into GEOM --- src/SPV3D/SPV3D_Prs.cxx | 40 ++++++++++++++++------------- src/SPV3D/SPV3D_Prs.h | 46 ++++++++++++++++++++++++++++------ src/SPV3D/SPV3D_ViewModel.cxx | 12 ++++----- src/SPV3D/SPV3D_ViewWindow.cxx | 30 ++++++++++++++++------ src/SPV3D/SPV3D_ViewWindow.h | 6 +++-- 5 files changed, 91 insertions(+), 43 deletions(-) diff --git a/src/SPV3D/SPV3D_Prs.cxx b/src/SPV3D/SPV3D_Prs.cxx index cc520896c..4613be0c1 100644 --- a/src/SPV3D/SPV3D_Prs.cxx +++ b/src/SPV3D/SPV3D_Prs.cxx @@ -35,18 +35,31 @@ #include "MBDebug.h" //--------------------------------------------------------- -/*! - Default constructor -*/ +bool SPV3D_EXPORTSPV3DData::IsVisible() const +{ + if( IsNull() ) + return false; + return GetRepresentation()->isVisible(); +} + +void SPV3D_EXPORTSPV3DData::Hide() const +{ + if( GetRepresentation() ) + GetRepresentation()->setVisible(0); +} + SPV3D_Prs::SPV3D_Prs( const char* entry ) : SALOME_PV3DPrs(entry) { DBG_FUN(); ARG(entry); } -/*! - Destructor -*/ +SPV3D_Prs *SPV3D_Prs::deepCopy() const +{ + SPV3D_Prs *ret = new SPV3D_Prs( *this ); + return ret; +} + SPV3D_Prs:: ~SPV3D_Prs() { DBG_FUN(); @@ -59,18 +72,9 @@ void SPV3D_Prs::DisplayIn( SALOME_View* v ) const bool SPV3D_Prs::IsNull() const { - return !_sourceProducer && !_repr; + if(_pvRendInfo) + return _pvRendInfo->IsNull(); + return true; } -bool SPV3D_Prs::isVisible() const -{ - if( IsNull() ) - return false; - return _repr->isVisible(); -} -void SPV3D_Prs::hide() const -{ - if( _repr ) - _repr->setVisible(0); -} diff --git a/src/SPV3D/SPV3D_Prs.h b/src/SPV3D/SPV3D_Prs.h index 36318017e..492555fa2 100644 --- a/src/SPV3D/SPV3D_Prs.h +++ b/src/SPV3D/SPV3D_Prs.h @@ -27,27 +27,57 @@ class vtkActor; class pqPipelineSource; class pqDataRepresentation; +class SPV3D_EXPORTSPV3DData +{ +public: + SPV3D_EXPORTSPV3DData() = default; + SPV3D_EXPORTSPV3DData *deepCopy() { return new SPV3D_EXPORTSPV3DData(*this); } + void SetSourceProducer(pqPipelineSource *sourceProducer) const { _sourceProducer = sourceProducer; } + pqPipelineSource *GetSourceProducer() const { return _sourceProducer; } + + void SetRepresentation(pqDataRepresentation *repr) const { _repr = repr; } + pqDataRepresentation *GetRepresentation() const { return _repr; } + + bool IsNull() const { return !_sourceProducer && !_repr; } + + bool IsVisible() const; + void Hide() const; +private: + SPV3D_EXPORTSPV3DData(const SPV3D_EXPORTSPV3DData& other) = default; +private: + mutable pqPipelineSource *_sourceProducer = nullptr; + mutable pqDataRepresentation *_repr = nullptr; +}; + class SPV3D_EXPORT SPV3D_Prs : public SALOME_PV3DPrs { public: explicit SPV3D_Prs( const char* entry ); ~SPV3D_Prs(); + SPV3D_Prs *deepCopy() const; + void DisplayIn( SALOME_View* v ) const override; - void SetSourceProducer(pqPipelineSource *sourceProducer) { _sourceProducer = sourceProducer; } - pqPipelineSource *GetSourceProducer() const { return _sourceProducer; } + void SetPVRenderInfo(SPV3D_EXPORTSPV3DData *pvRendInfo) { _pvRendInfo = pvRendInfo; } + + void SetSourceProducer(pqPipelineSource *sourceProducer) const { if(_pvRendInfo) _pvRendInfo->SetSourceProducer(sourceProducer); } + pqPipelineSource *GetSourceProducer() const { if(_pvRendInfo) return _pvRendInfo->GetSourceProducer(); return nullptr; } - void SetRepresentation(pqDataRepresentation *repr) const { _repr = repr; } - pqDataRepresentation *GetRepresentation() const { return _repr; } + void SetRepresentation(pqDataRepresentation *repr) const { if(_pvRendInfo) _pvRendInfo->SetRepresentation(repr); } + pqDataRepresentation *GetRepresentation() const { if(_pvRendInfo) return _pvRendInfo->GetRepresentation(); return nullptr; } bool IsNull() const override; +private: + + SPV3D_Prs(const SPV3D_Prs& other) = default; + public: - void hide() const; - bool isVisible() const; + void hide() const { if(_pvRendInfo) return _pvRendInfo->Hide(); } + bool isVisible() const { if(_pvRendInfo) return _pvRendInfo->IsVisible(); return false; } private: - pqPipelineSource *_sourceProducer = nullptr; - mutable pqDataRepresentation *_repr = nullptr; + + SPV3D_EXPORTSPV3DData *_pvRendInfo = nullptr; }; diff --git a/src/SPV3D/SPV3D_ViewModel.cxx b/src/SPV3D/SPV3D_ViewModel.cxx index 952f5a620..afff2e86f 100644 --- a/src/SPV3D/SPV3D_ViewModel.cxx +++ b/src/SPV3D/SPV3D_ViewModel.cxx @@ -237,6 +237,7 @@ void SPV3D_ViewModel::Display( const SALOME_PV3DPrs* prs ) pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder()); pqActiveObjects::instance().setActiveView(getView()); pqPipelineSource *mySourceProducer = aPrs->GetSourceProducer(); + aPrs->SetSourceProducer( mySourceProducer ); pqDataRepresentation* myRepr(builder->createDataRepresentation(mySourceProducer->getOutputPort(0),getView(),"GeometryRepresentation")); vtkSMViewProxy::RepresentationVisibilityChanged(myRepr->getViewProxy(), myRepr->getProxy(), true); aPrs->SetRepresentation(myRepr); @@ -295,14 +296,11 @@ SALOME_Prs* SPV3D_ViewModel::CreatePrs( const char* entry ) { DBG_FUN(); ARG(entry); - SPV3D_Prs* prs = new SPV3D_Prs( entry ); - if ( entry ) { - if(SPV3D_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) - { - aViewWindow->appendPrs( prs ); - } + if(SPV3D_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) + { + return aViewWindow->findOrCreatePrs( entry ); } - return prs; + return nullptr; } /*! diff --git a/src/SPV3D/SPV3D_ViewWindow.cxx b/src/SPV3D/SPV3D_ViewWindow.cxx index d8daba0e3..855874ed1 100644 --- a/src/SPV3D/SPV3D_ViewWindow.cxx +++ b/src/SPV3D/SPV3D_ViewWindow.cxx @@ -80,9 +80,23 @@ void SPV3D_ViewWindow::init() setCentralWidget( myModel->getView()->widget() ); } -void SPV3D_ViewWindow::appendPrs( SPV3D_Prs* prs ) +SPV3D_Prs *SPV3D_ViewWindow::findOrCreatePrs( const char* entry ) { - myPrs.push_back(prs); + std::string entryCpp( entry ); + SPV3D_Prs *prsOut( new SPV3D_Prs( entry ) ); + for(auto& prs : myPrs) + { + if(entryCpp == prs.first) + { + prsOut->SetPVRenderInfo( prs.second.get() ); + return prsOut; + } + } + std::unique_ptr data(new SPV3D_EXPORTSPV3DData); + prsOut->SetPVRenderInfo( data.get() ); + std::pair > p(entryCpp,std::move(data)); + myPrs.emplace_back( std::move(p) ); + return prsOut; } /*! @@ -95,11 +109,11 @@ SPV3D_ViewWindow::~SPV3D_ViewWindow() bool SPV3D_ViewWindow::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) { - std::string ior( theIObject->getEntry() ); - for(auto prs : myPrs) + std::string entryCpp( theIObject->getEntry() ); + for(auto& prs : myPrs) { - if(ior == prs->GetEntry() ) - return prs->isVisible(); + if(entryCpp == prs.first ) + return prs.second->IsVisible(); } return false; } @@ -154,9 +168,9 @@ void SPV3D_ViewWindow::DisplayAll() void SPV3D_ViewWindow::EraseAll() { DBG_FUN(); - for(auto prs : myPrs) + for(auto& prs : myPrs) { - prs->hide(); + prs.second->Hide(); } if(myModel) myModel->render(); diff --git a/src/SPV3D/SPV3D_ViewWindow.h b/src/SPV3D/SPV3D_ViewWindow.h index d68b4a929..546eeeebe 100644 --- a/src/SPV3D/SPV3D_ViewWindow.h +++ b/src/SPV3D/SPV3D_ViewWindow.h @@ -30,6 +30,7 @@ #include "SPV3D.h" #include "Qtx.h" #include "PV3DViewer_ViewWindow.h" +#include "SPV3D_Prs.h" #include "SALOME_InteractiveObject.hxx" #include "SALOME_ListIO.hxx" @@ -38,6 +39,7 @@ #include #include +#include class SUIT_Desktop; class SUIT_ResourceMgr; @@ -87,7 +89,7 @@ class SPV3D_EXPORT SPV3D_ViewWindow : public PV3DViewer_ViewWindow //SUIT_ViewWi //! To construct #SPV3D_ViewWindow instance SPV3D_ViewWindow(SUIT_Desktop* theDesktop, SPV3D_ViewModel* theModel); - void appendPrs( SPV3D_Prs* prs ); + SPV3D_Prs *findOrCreatePrs( const char* entry ); void init(); @@ -138,7 +140,7 @@ protected slots: protected: SPV3D_ViewModel* myModel; - std::list< SPV3D_Prs* > myPrs; + std::list< std::pair > > myPrs; }; #ifdef WIN32 -- 2.39.2