]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Management of visibility into GEOM
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 6 Apr 2023 11:32:45 +0000 (13:32 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 6 Apr 2023 11:32:45 +0000 (13:32 +0200)
src/SPV3D/SPV3D_Prs.cxx
src/SPV3D/SPV3D_Prs.h
src/SPV3D/SPV3D_ViewModel.cxx
src/SPV3D/SPV3D_ViewWindow.cxx
src/SPV3D/SPV3D_ViewWindow.h

index cc520896c9e9d9216a63e50cc6aa38f6fe559ad2..4613be0c1d31e5751951c7d7001d23ebe41e746f 100644 (file)
 #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);
-}
index 36318017e5a48a1fb30ca17f8e2eaf1c50262271..492555fa2b10174c7bffa4142aa2428846a406dd 100644 (file)
@@ -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;
 };
index 952f5a6206d08d69d60804f5b5f3b965a2e2b7f2..afff2e86f0da61e0e69cf0eebd1f35befe278539 100644 (file)
@@ -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<SPV3D_ViewWindow*>(getViewManager()->getActiveView()))
-    {
-      aViewWindow->appendPrs( prs );
-    }
+  if(SPV3D_ViewWindow* aViewWindow = dynamic_cast<SPV3D_ViewWindow*>(getViewManager()->getActiveView()))
+  {
+    return aViewWindow->findOrCreatePrs( entry );
   }
-  return prs;
+  return nullptr;
 }
 
 /*!
index d8daba0e3d52f5c199d4dadea77b0fcbb26d7465..855874ed19a18bb6a85cbea5a7146d4f9b54cdd8 100644 (file)
@@ -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<SPV3D_EXPORTSPV3DData> data(new SPV3D_EXPORTSPV3DData);
+  prsOut->SetPVRenderInfo( data.get() );
+  std::pair<std::string, std::unique_ptr<SPV3D_EXPORTSPV3DData> > 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();
index d68b4a9297ea5cd548f74434c2a07f751444b95a..546eeeebe20d57f78fd4f3291e10ef1f5811186d 100644 (file)
@@ -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 <vtkSmartPointer.h>
 
 #include <list>
+#include <memory>
 
 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<std::string, std::unique_ptr<SPV3D_EXPORTSPV3DData> > > myPrs;
 };
 
 #ifdef WIN32