Salome HOME
3aec8976ff0f236a8122dc87443985d71592e580
[modules/visu.git] / src / PIPELINE / VISU_MapperHolder.cxx
1 //  Copyright (C) 2007-2008  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 // File:    VISU_MapperHolder.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #include "VISU_MapperHolder.hxx"
28 #include "VISU_PipeLine.hxx"
29
30 #include "VISU_PipeLineUtils.hxx"
31
32 #include <vtkDataSet.h>
33
34 #ifdef _DEBUG_
35 static int MYDEBUG = 0;
36 #else
37 static int MYDEBUG = 0;
38 #endif
39
40
41 //----------------------------------------------------------------------------
42 VISU_MapperHolder
43 ::VISU_MapperHolder():
44   myPipeLine(NULL)
45 {
46   if(MYDEBUG) 
47     MESSAGE("VISU_MapperHolder::VISU_MapperHolder - "<<this);
48 }
49
50
51 //----------------------------------------------------------------------------
52 VISU_MapperHolder
53 ::~VISU_MapperHolder()
54 {
55   if(MYDEBUG)
56     MESSAGE("VISU_MapperHolder::~VISU_MapperHolder - "<<this);
57 }
58
59
60 //----------------------------------------------------------------------------
61 void 
62 VISU_MapperHolder
63 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
64               bool theIsCopyInput)
65 {
66   if(theIsCopyInput)
67     SetIDMapper(theMapperHolder->GetIDMapper());
68
69   VISU::CopyMapper(GetMapper(), 
70                    theMapperHolder->GetMapper(), 
71                    theIsCopyInput);
72 }
73
74
75 //----------------------------------------------------------------------------
76 unsigned long int
77 VISU_MapperHolder
78 ::GetMemorySize()
79 {
80   unsigned long int aSize = 0;
81
82   if(myMapper.GetPointer())
83     if(vtkDataSet* aDataSet = myMapper->GetInput())
84       aSize = aDataSet->GetActualMemorySize() * 1024;
85   
86   if(myIDMapper)
87     aSize += myIDMapper->GetMemorySize();
88   
89   return aSize;
90 }
91
92
93 //----------------------------------------------------------------------------
94 unsigned long int 
95 VISU_MapperHolder
96 ::GetMTime()
97 {
98   unsigned long int aTime = Superclass::GetMTime();
99
100   if(myIDMapper)
101     if(vtkDataSet* aDataSet = myIDMapper->GetOutput())
102       aTime = std::max(aTime, aDataSet->GetMTime());
103
104   if(myMapper.GetPointer())
105     aTime = std::max(aTime, myMapper->GetMTime());
106
107   return aTime;
108 }
109
110
111 //----------------------------------------------------------------------------
112 void
113 VISU_MapperHolder
114 ::SetPipeLine(VISU_PipeLine* thePipeLine)
115 {
116   myPipeLine = thePipeLine;
117 }
118
119
120 //----------------------------------------------------------------------------
121 void
122 VISU_MapperHolder
123 ::SetIDMapper(const VISU::PIDMapper& theIDMapper)
124 {
125   if(myIDMapper == theIDMapper)
126     return;
127
128   myIDMapper = theIDMapper;
129
130   if(myPipeLine && GetInput())
131     if(!GetMapper()->GetInput()){
132       myPipeLine->Build();
133       myPipeLine->Init();
134       myPipeLine->Update();
135     }
136
137   Modified();
138 }
139
140
141 //----------------------------------------------------------------------------
142 const VISU::PIDMapper&  
143 VISU_MapperHolder
144 ::GetIDMapper()
145 {
146   return myIDMapper;
147 }
148
149
150 //----------------------------------------------------------------------------
151 vtkDataSet* 
152 VISU_MapperHolder
153 ::GetInput()
154 {
155   if(myIDMapper)
156     return myIDMapper->GetOutput();
157
158   return NULL;
159 }
160
161
162 //----------------------------------------------------------------------------
163 vtkMapper* 
164 VISU_MapperHolder
165 ::GetMapper()
166 {
167   if(!myMapper.GetPointer())
168     OnCreateMapper();
169
170   return myMapper.GetPointer();
171 }
172
173
174 //----------------------------------------------------------------------------
175 vtkDataSet* 
176 VISU_MapperHolder
177 ::GetOutput()
178 {
179   if(myMapper.GetPointer())
180     return myMapper->GetInput();
181
182   return NULL;
183 }
184
185
186 //----------------------------------------------------------------------------
187 void 
188 VISU_MapperHolder
189 ::Update()
190 {
191   if(myMapper.GetPointer())
192     return myMapper->Update();
193 }
194
195
196 //----------------------------------------------------------------------------
197 void
198 VISU_MapperHolder
199 ::SetMapper(vtkMapper* theMapper)
200 {
201   myMapper = theMapper;
202 }
203
204
205 //----------------------------------------------------------------------------
206 vtkIdType 
207 VISU_MapperHolder
208 ::GetNodeObjID(vtkIdType theID)
209 {
210   return myIDMapper->GetNodeObjID(theID);
211 }
212
213 //----------------------------------------------------------------------------
214 vtkIdType 
215 VISU_MapperHolder
216 ::GetNodeVTKID(vtkIdType theID)
217 {
218   return myIDMapper->GetNodeVTKID(theID);
219 }
220
221 //----------------------------------------------------------------------------
222 vtkFloatingPointType* 
223 VISU_MapperHolder
224 ::GetNodeCoord(vtkIdType theObjID)
225 {
226   return myIDMapper->GetNodeCoord(theObjID);
227 }
228
229
230 //----------------------------------------------------------------------------
231 vtkIdType 
232 VISU_MapperHolder
233 ::GetElemObjID(vtkIdType theID)
234 {
235   return myIDMapper->GetElemObjID(theID);
236 }
237
238 //----------------------------------------------------------------------------
239 vtkIdType
240 VISU_MapperHolder
241 ::GetElemVTKID(vtkIdType theID)
242 {
243   return myIDMapper->GetElemVTKID(theID);
244 }
245
246 //----------------------------------------------------------------------------
247 vtkCell* 
248 VISU_MapperHolder
249 ::GetElemCell(vtkIdType  theObjID)
250 {
251   return myIDMapper->GetElemCell(theObjID);
252 }
253
254
255 //----------------------------------------------------------------------------