]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_DeformedShapeAndScalarMap_i.cc
Salome HOME
8fa94e4d2e4146fdce912d95d3f65e3ee09e2754
[modules/visu.git] / src / VISU_I / VISU_DeformedShapeAndScalarMap_i.cc
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_DeformedShapeAndScalarMap_i.cc
24 //  Author : Eugeny Nikolaev
25 //  Module : VISU
26 //
27 #include "VISU_DeformedShapeAndScalarMap_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
30
31 #include "VISU_ScalarMapAct.h"
32 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
33 #include "VISU_Convertor.hxx"
34
35 #include "SUIT_ResourceMgr.h"
36 #include "SALOME_Event.h"
37
38 #include <vtkUnstructuredGrid.h>
39 #include <vtkProperty.h>
40 #include <vtkMapper.h>
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 static int INCMEMORY = 4+12;
49
50 using namespace std;
51
52 //---------------------------------------------------------------
53 size_t
54 VISU::DeformedShapeAndScalarMap_i
55 ::IsPossible(Result_i* theResult, 
56              const std::string& theMeshName, 
57              VISU::Entity theEntity,
58              const std::string& theFieldName, 
59              CORBA::Long theTimeStampNumber,
60              bool theIsMemoryCheck)
61 {
62   size_t aResult = 0;
63   try{
64     aResult = TSuperClass::IsPossible(theResult,
65                                       theMeshName,
66                                       theEntity,
67                                       theFieldName,
68                                       theTimeStampNumber,
69                                       false);
70     if(theIsMemoryCheck && aResult){
71       VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
72                                                            theEntity,
73                                                            theFieldName,
74                                                            theTimeStampNumber);
75       VISU::PField aField = anInput->GetField(theMeshName,
76                                               (VISU::TEntity)theEntity,
77                                               theFieldName);
78       if(aField->myNbComp <= 1)
79         return 0;
80
81       bool anIsEstimated = true;
82       size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
83                                                      (VISU::TEntity)theEntity,
84                                                      theFieldName,
85                                                      theTimeStampNumber,
86                                                      anIsEstimated);
87       if(anIsEstimated)
88         aSize *= INCMEMORY;
89       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
90       if(MYDEBUG) 
91         MESSAGE("DeformedShapeAndScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
92     }
93   }catch(std::exception& exc){
94     INFOS("Follow exception was occured :\n"<<exc.what());
95   }catch(...){
96     INFOS("Unknown exception was occured!");
97   }
98   return aResult;
99 }
100
101 //---------------------------------------------------------------
102 int VISU::DeformedShapeAndScalarMap_i::myNbPresent = 0;
103
104 //---------------------------------------------------------------
105 QString
106 VISU::DeformedShapeAndScalarMap_i
107 ::GenerateName() 
108 {
109   return VISU::GenerateName("ScalarDef.Shape",myNbPresent++);
110 }
111
112 //---------------------------------------------------------------
113 const string VISU::DeformedShapeAndScalarMap_i::myComment = "SCALARMAPONDEFORMEDSHAPE"; // It is obsolete. Use "DEFORMEDSHAPEANDSCALARMAP" instead.
114
115 //---------------------------------------------------------------
116 const char* 
117 VISU::DeformedShapeAndScalarMap_i
118 ::GetComment() const
119
120   return myComment.c_str();
121 }
122
123 //----------------------------------------------------------------------------
124 const char*
125 VISU::DeformedShapeAndScalarMap_i
126 ::GetIconName()
127 {
128   if (!IsGroupsUsed())
129     return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE";
130   else
131     return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE_GROUPS";
132 }
133
134 //---------------------------------------------------------------
135 VISU::DeformedShapeAndScalarMap_i
136 ::DeformedShapeAndScalarMap_i(EPublishInStudyMode thePublishInStudyMode) :
137   ColoredPrs3d_i(thePublishInStudyMode),
138   ScalarMap_i(thePublishInStudyMode),
139   myDeformedShapeAndScalarMapPL(NULL),
140   myScalarTimeStampNumber(1)
141 {}
142
143
144 //---------------------------------------------------------------
145 VISU::Storable* 
146 VISU::DeformedShapeAndScalarMap_i
147 ::Create(const std::string& theMeshName, 
148          VISU::Entity theEntity,
149          const std::string& theFieldName, 
150          CORBA::Long theTimeStampNumber)
151 {
152   TSuperClass::Create(theMeshName,
153                              theEntity,
154                              theFieldName,
155                              theTimeStampNumber);
156   SetScalarField(theEntity,
157                  theFieldName.c_str(),
158                  theTimeStampNumber);
159   return this;
160 }
161
162
163 //---------------------------------------------------------------
164 VISU::Storable*
165 VISU::DeformedShapeAndScalarMap_i
166 ::Restore(SALOMEDS::SObject_ptr theSObject,
167           const Storable::TRestoringMap& theMap)
168 {
169   if(!TSuperClass::Restore(theSObject, theMap))
170     return NULL;
171
172   QString aMeshName = VISU::Storable::FindValue(theMap,"myScalarMeshName");
173   VISU::Entity anEntity = VISU::Entity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt());
174
175   QString aFieldName = VISU::Storable::FindValue(theMap,"myScalarFieldName");
176   int aTimeStampNumber = VISU::Storable::FindValue(theMap,"myScalarIteration").toInt();
177
178   SetScalarField(anEntity,
179                  aFieldName.toLatin1().constData(),
180                  aTimeStampNumber);
181
182   SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
183   
184   return this;
185 }
186
187
188 //---------------------------------------------------------------
189 void
190 VISU::DeformedShapeAndScalarMap_i
191 ::ToStream(std::ostringstream& theStr)
192 {
193   TSuperClass::ToStream(theStr);
194   
195   Storable::DataToStream( theStr, "myScalarEntity",    int(myScalarEntity));
196   Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str());
197   Storable::DataToStream( theStr, "myScalarIteration", int(myScalarTimeStampNumber));
198
199   Storable::DataToStream( theStr, "myFactor", GetScale() );
200 }
201
202
203 //---------------------------------------------------------------
204 VISU::DeformedShapeAndScalarMap_i
205 ::~DeformedShapeAndScalarMap_i()
206 {
207   if(MYDEBUG) MESSAGE("DeformedShapeAndScalarMap_i::~DeformedShapeAndScalarMap_i()");
208 }
209
210
211 //---------------------------------------------------------------
212 void
213 VISU::DeformedShapeAndScalarMap_i
214 ::SameAs(const Prs3d_i* theOrigin)
215 {
216   TSuperClass::SameAs(theOrigin);
217   
218   if(const DeformedShapeAndScalarMap_i* aPrs3d = dynamic_cast<const DeformedShapeAndScalarMap_i*>(theOrigin)){
219     DeformedShapeAndScalarMap_i* anOrigin = const_cast<DeformedShapeAndScalarMap_i*>(aPrs3d);
220     CORBA::String_var aFieldName = anOrigin->GetScalarFieldName();
221     
222     SetScalarField(anOrigin->GetScalarEntity(),
223                    aFieldName,
224                    anOrigin->GetScalarTimeStampNumber());
225     SetTitle(anOrigin->GetTitle()); //fix of 20094 issue
226     SetScalarMode(anOrigin->GetScalarMode()); //
227     if(!IsRangeFixed() && IsPipeLineExists()) //fix of 20107 issue
228       SetSourceRange();                       //
229     Update();
230   }
231 }
232
233
234 //---------------------------------------------------------------
235 void
236 VISU::DeformedShapeAndScalarMap_i
237 ::SetScale(CORBA::Double theScale) 
238
239   VISU::TSetModified aModified(this);
240
241   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkFloatingPointType>
242                    (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScale, theScale));
243 }
244
245
246 //---------------------------------------------------------------
247 CORBA::Double
248 VISU::DeformedShapeAndScalarMap_i
249 ::GetScale()
250 {
251   return myDeformedShapeAndScalarMapPL->GetScale();
252 }
253
254
255 //---------------------------------------------------------------
256 void
257 VISU::DeformedShapeAndScalarMap_i
258 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
259 {
260   if(!thePipeLine){
261     myDeformedShapeAndScalarMapPL = VISU_DeformedShapeAndScalarMapPL::New();
262   }else
263     myDeformedShapeAndScalarMapPL = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine);
264
265   myDeformedShapeAndScalarMapPL->GetMapper()->SetScalarVisibility(1);
266
267   TSuperClass::CreatePipeLine(myDeformedShapeAndScalarMapPL);
268 }
269
270
271 //---------------------------------------------------------------
272 bool
273 VISU::DeformedShapeAndScalarMap_i
274 ::CheckIsPossible() 
275 {
276   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
277 }
278
279
280 //---------------------------------------------------------------
281 VISU_Actor* 
282 VISU::DeformedShapeAndScalarMap_i
283 ::CreateActor() 
284 {
285   VISU_Actor* anActor = TSuperClass::CreateActor(true);
286   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
287   int  aDispMode = aResourceMgr->integerValue("VISU", "scalar_def_represent", 2);
288   bool toShrink  = aResourceMgr->booleanValue("VISU", "scalar_def_shrink", false);
289   anActor->SetRepresentation(aDispMode);
290   if (toShrink) 
291     anActor->SetShrink();
292   anActor->SetVTKMapping(false);
293   return anActor;
294 }
295
296
297 //---------------------------------------------------------------
298 void
299 VISU::DeformedShapeAndScalarMap_i
300 ::UpdateActor(VISU_Actor* theActor) 
301 {
302   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
303     anActor->SetBarVisibility(true);
304     GetPipeLine()->GetMapper()->SetScalarVisibility(1);
305   }
306   TSuperClass::UpdateActor(theActor);
307 }
308
309
310 //---------------------------------------------------------------
311 void
312 VISU::DeformedShapeAndScalarMap_i
313 ::SetField(VISU::PField theField)
314 {
315   TSuperClass::SetField(theField);
316   
317   if(!myScalarField)
318     myScalarField = theField;
319 }
320
321
322 //---------------------------------------------------------------
323 void
324 VISU::DeformedShapeAndScalarMap_i
325 ::SetScalarField(VISU::Entity theEntity,
326                  const char* theFieldName,
327                  CORBA::Long theTimeStampNumber)
328 {
329   bool anIsModified = false;
330
331   if(!anIsModified)
332     anIsModified |= myScalarEntity != theEntity;
333
334   if(!anIsModified)
335     anIsModified |= myScalarFieldName != theFieldName;
336
337   if(!anIsModified)
338     anIsModified |= myScalarTimeStampNumber != theTimeStampNumber;
339   
340   if(!anIsModified)
341     return;
342
343   VISU::TSetModified aModified(this);
344
345   VISU::TEntity aEntity = VISU::TEntity(theEntity);
346   VISU::Result_i::PInput anInput = GetCResult()->GetInput(GetCMeshName(),
347                                                           theEntity,
348                                                           theFieldName,
349                                                           theTimeStampNumber);
350   myScalarField = anInput->GetField(GetCMeshName(), aEntity, theFieldName);
351
352   VISU::PUnstructuredGridIDMapper anIDMapper = 
353     anInput->GetTimeStampOnMesh(GetCMeshName(),
354                                 aEntity,
355                                 theFieldName,
356                                 theTimeStampNumber);
357
358   vtkUnstructuredGrid* anOutput = anIDMapper->GetUnstructuredGridOutput();
359   if(myDeformedShapeAndScalarMapPL && anOutput)
360     ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkDataSet*>
361                      (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScalars, anOutput));
362   
363   myScalarEntity = theEntity;
364   myScalarFieldName = theFieldName;
365   myScalarTimeStampNumber = theTimeStampNumber;
366
367   SetTitle(theFieldName);
368   SetScalarMode(GetScalarMode());
369   if(!IsRangeFixed() && IsPipeLineExists())
370     SetSourceRange();
371
372   myParamsTime.Modified();
373 }
374
375
376 //---------------------------------------------------------------
377 VISU::Entity 
378 VISU::DeformedShapeAndScalarMap_i
379 ::GetScalarEntity()
380 {
381   return myScalarEntity;
382 }
383
384
385 //---------------------------------------------------------------
386 char* 
387 VISU::DeformedShapeAndScalarMap_i
388 ::GetScalarFieldName()
389 {
390   return CORBA::string_dup(myScalarFieldName.c_str());
391 }
392
393
394 //---------------------------------------------------------------
395 CORBA::Long 
396 VISU::DeformedShapeAndScalarMap_i
397 ::GetScalarTimeStampNumber()
398 {
399   return myScalarTimeStampNumber;
400 }
401
402
403 //---------------------------------------------------------------
404 VISU::PField
405 VISU::DeformedShapeAndScalarMap_i
406 ::GetScalarField()
407 {
408   return myScalarField;
409 }