Salome HOME
updated copyright message
[modules/gui.git] / src / SPV3D / SPV3D_Prs.cxx
1 // Copyright (C) 2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SALOME PV3DViewer : build PV3D viewer into Salome desktop
21 //  File   : SPV3D_Prs.cxx
22
23 #include "SPV3D_Prs.h"
24 #include "SPV3D_ViewWindow.h"
25
26 #include "vtkActor.h"
27 #include "vtkPolyData.h"
28 #include "vtkCellData.h"
29 #include "vtkMapper.h"
30 #include "pqServer.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>
38
39 bool SPV3D_EXPORTSPV3DData::IsVisible() const
40 {
41   if( IsNull() )
42     return false;
43   return GetRepresentation()->isVisible();
44 }
45
46 void SPV3D_EXPORTSPV3DData::Hide() const
47 {
48   if( GetRepresentation() )
49     GetRepresentation()->setVisible(0);
50 }
51
52 SPV3D_Prs::SPV3D_Prs( const char* entry , SPV3D_ViewWindow *view) : SALOME_PV3DPrs(entry),_view(view)
53 {
54 }
55
56 SPV3D_Prs *SPV3D_Prs::deepCopy() const
57 {
58   SPV3D_Prs *ret = new SPV3D_Prs( *this );
59   return ret;
60 }
61
62 pqProxy *getPQProxy(vtkSMProxy *proxy)
63 {
64   pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
65   return smmodel->findItem<pqProxy*>(proxy);
66 }
67
68 void SPV3D_Prs::FillUsingActor(vtkActor *actor) const
69 {
70   SPV3D_EXPORTSPV3DData *alreadyExistingSrc = nullptr;
71   alreadyExistingSrc = _view->isEntryAlreadyExist( GetEntry() );
72   if(alreadyExistingSrc && !alreadyExistingSrc->GetSourceProducer())
73   {
74     actor->GetMapper()->Update();
75     vtkDataObject *ds = actor->GetMapper()->GetInput();
76     vtkPolyData *ds3 = vtkPolyData::SafeDownCast(ds);
77     vtkNew<vtkPolyData> ds4;
78     if(ds3)
79     {
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 );
89     }
90     //
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 );
104   }
105   else
106   {
107     this->CopyInfo( alreadyExistingSrc );
108   }
109 }
110
111 SPV3D_Prs:: ~SPV3D_Prs() 
112 {
113 }
114
115 void SPV3D_Prs::DisplayIn( SALOME_View* v ) const
116 {
117   SALOME_PV3DPrs::DisplayIn(v);
118 }
119
120 void SPV3D_Prs::CopyInfo(SPV3D_EXPORTSPV3DData *info) const
121 {
122   if(!_pvRendInfo || !info)
123     return ;
124   if(_pvRendInfo == info)
125     return ;
126   *_pvRendInfo = *info;
127 }
128
129 bool SPV3D_Prs::IsNull() const
130 {
131   if(_pvRendInfo)
132     return _pvRendInfo->IsNull();
133   return true;
134 }
135
136