Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_MapperHolder.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_MapperHolder.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27 //
28 #include "VISU_MapperHolder.hxx"
29 #include "VISU_PipeLine.hxx"
30
31 #include "VISU_PipeLineUtils.hxx"
32
33 #include <vtkDataSet.h>
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 #endif
40
41
42 //----------------------------------------------------------------------------
43 VISU_MapperHolder
44 ::VISU_MapperHolder():
45   myPipeLine(NULL)
46 {
47   if(MYDEBUG) 
48     MESSAGE("VISU_MapperHolder::VISU_MapperHolder - "<<this);
49 }
50
51
52 //----------------------------------------------------------------------------
53 VISU_MapperHolder
54 ::~VISU_MapperHolder()
55 {
56   if(MYDEBUG)
57     MESSAGE("VISU_MapperHolder::~VISU_MapperHolder - "<<this);
58 }
59
60
61 //----------------------------------------------------------------------------
62 void 
63 VISU_MapperHolder
64 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
65               bool theIsCopyInput)
66 {
67   if(theIsCopyInput)
68     SetIDMapper(theMapperHolder->GetIDMapper());
69
70   VISU::CopyMapper(GetMapper(), 
71                    theMapperHolder->GetMapper(), 
72                    theIsCopyInput);
73 }
74
75
76 //----------------------------------------------------------------------------
77 unsigned long int
78 VISU_MapperHolder
79 ::GetMemorySize()
80 {
81   unsigned long int aSize = 0;
82
83   if(myMapper.GetPointer())
84     if(vtkDataSet* aDataSet = myMapper->GetInput())
85       aSize = aDataSet->GetActualMemorySize() * 1024;
86   
87   if(myIDMapper)
88     aSize += myIDMapper->GetMemorySize();
89   
90   return aSize;
91 }
92
93
94 //----------------------------------------------------------------------------
95 unsigned long int 
96 VISU_MapperHolder
97 ::GetMTime()
98 {
99   unsigned long int aTime = Superclass::GetMTime();
100
101   if(myIDMapper)
102     if(vtkDataSet* aDataSet = myIDMapper->GetOutput())
103       aTime = std::max(aTime, aDataSet->GetMTime());
104
105   if(myMapper.GetPointer())
106     aTime = std::max(aTime, myMapper->GetMTime());
107
108   return aTime;
109 }
110
111
112 //----------------------------------------------------------------------------
113 void
114 VISU_MapperHolder
115 ::SetPipeLine(VISU_PipeLine* thePipeLine)
116 {
117   myPipeLine = thePipeLine;
118 }
119
120
121 //----------------------------------------------------------------------------
122 void
123 VISU_MapperHolder
124 ::SetIDMapper(const VISU::PIDMapper& theIDMapper)
125 {
126   if(myIDMapper == theIDMapper)
127     return;
128
129   myIDMapper = theIDMapper;
130
131   if(myPipeLine && GetInput())
132     if(!GetMapper()->GetInput()){
133       myPipeLine->Build();
134       myPipeLine->Init();
135       myPipeLine->Update();
136     }
137
138   Modified();
139 }
140
141
142 //----------------------------------------------------------------------------
143 const VISU::PIDMapper&  
144 VISU_MapperHolder
145 ::GetIDMapper()
146 {
147   return myIDMapper;
148 }
149
150
151 //----------------------------------------------------------------------------
152 vtkDataSet* 
153 VISU_MapperHolder
154 ::GetInput()
155 {
156   if(myIDMapper)
157     return myIDMapper->GetOutput();
158
159   return NULL;
160 }
161
162
163 //----------------------------------------------------------------------------
164 vtkMapper* 
165 VISU_MapperHolder
166 ::GetMapper()
167 {
168   if(!myMapper.GetPointer())
169     OnCreateMapper();
170
171   return myMapper.GetPointer();
172 }
173
174
175 //----------------------------------------------------------------------------
176 vtkDataSet* 
177 VISU_MapperHolder
178 ::GetOutput()
179 {
180   if(myMapper.GetPointer())
181     return myMapper->GetInput();
182
183   return NULL;
184 }
185
186
187 //----------------------------------------------------------------------------
188 void 
189 VISU_MapperHolder
190 ::Update()
191 {
192   if(myMapper.GetPointer())
193     return myMapper->Update();
194 }
195
196
197 //----------------------------------------------------------------------------
198 void
199 VISU_MapperHolder
200 ::SetMapper(vtkMapper* theMapper)
201 {
202   myMapper = theMapper;
203 }
204
205
206 //----------------------------------------------------------------------------
207 vtkIdType 
208 VISU_MapperHolder
209 ::GetNodeObjID(vtkIdType theID)
210 {
211   return myIDMapper->GetNodeObjID(theID);
212 }
213
214 //----------------------------------------------------------------------------
215 vtkIdType 
216 VISU_MapperHolder
217 ::GetNodeVTKID(vtkIdType theID)
218 {
219   return myIDMapper->GetNodeVTKID(theID);
220 }
221
222 //----------------------------------------------------------------------------
223 vtkFloatingPointType* 
224 VISU_MapperHolder
225 ::GetNodeCoord(vtkIdType theObjID)
226 {
227   return myIDMapper->GetNodeCoord(theObjID);
228 }
229
230
231 //----------------------------------------------------------------------------
232 vtkIdType 
233 VISU_MapperHolder
234 ::GetElemObjID(vtkIdType theID)
235 {
236   return myIDMapper->GetElemObjID(theID);
237 }
238
239 //----------------------------------------------------------------------------
240 vtkIdType
241 VISU_MapperHolder
242 ::GetElemVTKID(vtkIdType theID)
243 {
244   return myIDMapper->GetElemVTKID(theID);
245 }
246
247 //----------------------------------------------------------------------------
248 vtkCell* 
249 VISU_MapperHolder
250 ::GetElemCell(vtkIdType  theObjID)
251 {
252   return myIDMapper->GetElemCell(theObjID);
253 }
254
255
256 //----------------------------------------------------------------------------