1 // Copyright (C) 2023 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME PV3DViewer : build PV3D viewer into Salome desktop
21 // File : SPV3D_Prs.cxx
23 #include "SPV3D_Prs.h"
24 #include "SPV3D_ViewWindow.h"
27 #include "vtkPolyData.h"
28 #include "vtkCellData.h"
29 #include "vtkMapper.h"
31 #include "pqApplicationCore.h"
32 #include "pqServerManagerModel.h"
33 #include "pqObjectBuilder.h"
34 #include "pqPipelineSource.h"
35 #include "vtkSMSourceProxy.h"
36 #include "vtkPVTrivialProducer.h"
37 #include <pqDataRepresentation.h>
39 bool SPV3D_EXPORTSPV3DData::IsVisible() const
43 return GetRepresentation()->isVisible();
46 void SPV3D_EXPORTSPV3DData::Hide() const
48 if( GetRepresentation() )
49 GetRepresentation()->setVisible(0);
52 SPV3D_Prs::SPV3D_Prs( const char* entry , SPV3D_ViewWindow *view) : SALOME_PV3DPrs(entry),_view(view)
56 SPV3D_Prs *SPV3D_Prs::deepCopy() const
58 SPV3D_Prs *ret = new SPV3D_Prs( *this );
62 pqProxy *getPQProxy(vtkSMProxy *proxy)
64 pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
65 return smmodel->findItem<pqProxy*>(proxy);
68 void SPV3D_Prs::FillUsingActor(vtkActor *actor) const
70 SPV3D_EXPORTSPV3DData *alreadyExistingSrc = nullptr;
71 alreadyExistingSrc = _view->isEntryAlreadyExist( GetEntry() );
72 if(alreadyExistingSrc && !alreadyExistingSrc->GetSourceProducer())
74 actor->GetMapper()->Update();
75 vtkDataObject *ds = actor->GetMapper()->GetInput();
76 vtkPolyData *ds3 = vtkPolyData::SafeDownCast(ds);
77 vtkNew<vtkPolyData> ds4;
80 ds4->ShallowCopy( ds3 );
81 vtkNew<vtkIdTypeArray> solidIdArray;
82 auto nbCells( ds4->GetNumberOfCells() );
83 solidIdArray->SetNumberOfComponents(1);
84 solidIdArray->SetNumberOfTuples( nbCells );
85 solidIdArray->SetName("Solid id");
86 vtkIdType *pt( solidIdArray->GetPointer(0) );
87 std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = 0; });
88 ds4->GetCellData()->AddArray( solidIdArray );
91 pqServer *serv(pqApplicationCore::instance()->getServerManagerModel()->findServer(pqServerResource("builtin:")));
92 pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
93 pqPipelineSource *mySourceProducer(builder->createSource("sources","PVTrivialProducer",serv));
94 vtkSMProxy *producerBase = mySourceProducer->getProxy();
95 vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase));
96 vtkObjectBase *clientSideObject(producer->GetClientSideObject());
97 vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject);
98 clientSideObjectCast->SetOutput(ds4);
99 mySourceProducer->updatePipeline();
100 pqProxy *producerBase2( getPQProxy(producerBase) );
101 if(producerBase2 && !_name.empty())
102 producerBase2->rename( _name.c_str() );
103 this->SetSourceProducer( mySourceProducer );
107 this->CopyInfo( alreadyExistingSrc );
111 SPV3D_Prs:: ~SPV3D_Prs()
115 void SPV3D_Prs::DisplayIn( SALOME_View* v ) const
117 SALOME_PV3DPrs::DisplayIn(v);
120 void SPV3D_Prs::CopyInfo(SPV3D_EXPORTSPV3DData *info) const
122 if(!_pvRendInfo || !info)
124 if(_pvRendInfo == info)
126 *_pvRendInfo = *info;
129 bool SPV3D_Prs::IsNull() const
132 return _pvRendInfo->IsNull();