1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_DeformedShapeAndScalarMap_i.cc
24 // Author : Eugeny Nikolaev
27 #include "VISU_DeformedShapeAndScalarMap_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
31 #include "VISU_ScalarMapAct.h"
32 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
33 #include "VISU_Convertor.hxx"
35 #include "SUIT_ResourceMgr.h"
36 #include "SALOME_Event.h"
38 #include <vtkUnstructuredGrid.h>
39 #include <vtkProperty.h>
40 #include <vtkMapper.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 static int INCMEMORY = 4+12;
52 //---------------------------------------------------------------
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)
64 aResult = TSuperClass::IsPossible(theResult,
70 if(theIsMemoryCheck && aResult){
71 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
75 VISU::PField aField = anInput->GetField(theMeshName,
76 (VISU::TEntity)theEntity,
78 if(aField->myNbComp <= 1)
81 bool anIsEstimated = true;
82 size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
83 (VISU::TEntity)theEntity,
89 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
91 MESSAGE("DeformedShapeAndScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
93 }catch(std::exception& exc){
94 INFOS("Follow exception was occured :\n"<<exc.what());
96 INFOS("Unknown exception was occured!");
101 //---------------------------------------------------------------
102 int VISU::DeformedShapeAndScalarMap_i::myNbPresent = 0;
104 //---------------------------------------------------------------
106 VISU::DeformedShapeAndScalarMap_i
109 return VISU::GenerateName("ScalarDef.Shape",myNbPresent++);
112 //---------------------------------------------------------------
113 const string VISU::DeformedShapeAndScalarMap_i::myComment = "SCALARMAPONDEFORMEDSHAPE"; // It is obsolete. Use "DEFORMEDSHAPEANDSCALARMAP" instead.
115 //---------------------------------------------------------------
117 VISU::DeformedShapeAndScalarMap_i
120 return myComment.c_str();
123 //----------------------------------------------------------------------------
125 VISU::DeformedShapeAndScalarMap_i
129 return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE";
131 return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE_GROUPS";
134 //---------------------------------------------------------------
135 VISU::DeformedShapeAndScalarMap_i
136 ::DeformedShapeAndScalarMap_i(EPublishInStudyMode thePublishInStudyMode) :
137 ColoredPrs3d_i(thePublishInStudyMode),
138 ScalarMap_i(thePublishInStudyMode),
139 myDeformedShapeAndScalarMapPL(NULL),
140 myScalarTimeStampNumber(1)
144 //---------------------------------------------------------------
146 VISU::DeformedShapeAndScalarMap_i
147 ::Create(const std::string& theMeshName,
148 VISU::Entity theEntity,
149 const std::string& theFieldName,
150 CORBA::Long theTimeStampNumber)
152 TSuperClass::Create(theMeshName,
156 SetScalarField(theEntity,
157 theFieldName.c_str(),
163 //---------------------------------------------------------------
165 VISU::DeformedShapeAndScalarMap_i
166 ::Restore(SALOMEDS::SObject_ptr theSObject,
167 const Storable::TRestoringMap& theMap)
169 if(!TSuperClass::Restore(theSObject, theMap))
172 QString aMeshName = VISU::Storable::FindValue(theMap,"myScalarMeshName");
173 VISU::Entity anEntity = VISU::Entity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt());
175 QString aFieldName = VISU::Storable::FindValue(theMap,"myScalarFieldName");
176 int aTimeStampNumber = VISU::Storable::FindValue(theMap,"myScalarIteration").toInt();
178 SetScalarField(anEntity,
179 aFieldName.toLatin1().constData(),
182 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
188 //---------------------------------------------------------------
190 VISU::DeformedShapeAndScalarMap_i
191 ::ToStream(std::ostringstream& theStr)
193 TSuperClass::ToStream(theStr);
195 Storable::DataToStream( theStr, "myScalarEntity", int(myScalarEntity));
196 Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str());
197 Storable::DataToStream( theStr, "myScalarIteration", int(myScalarTimeStampNumber));
199 Storable::DataToStream( theStr, "myFactor", GetScale() );
203 //---------------------------------------------------------------
204 VISU::DeformedShapeAndScalarMap_i
205 ::~DeformedShapeAndScalarMap_i()
207 if(MYDEBUG) MESSAGE("DeformedShapeAndScalarMap_i::~DeformedShapeAndScalarMap_i()");
211 //---------------------------------------------------------------
213 VISU::DeformedShapeAndScalarMap_i
214 ::SameAs(const Prs3d_i* theOrigin)
216 TSuperClass::SameAs(theOrigin);
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();
222 SetScalarField(anOrigin->GetScalarEntity(),
224 anOrigin->GetScalarTimeStampNumber());
225 SetTitle(anOrigin->GetTitle()); //fix of 20094 issue
226 SetScalarMode(anOrigin->GetScalarMode()); //
227 if(!IsRangeFixed() && IsPipeLineExists()) //fix of 20107 issue
234 //---------------------------------------------------------------
236 VISU::DeformedShapeAndScalarMap_i
237 ::SetScale(CORBA::Double theScale)
239 VISU::TSetModified aModified(this);
241 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkFloatingPointType>
242 (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScale, theScale));
246 //---------------------------------------------------------------
248 VISU::DeformedShapeAndScalarMap_i
251 return myDeformedShapeAndScalarMapPL->GetScale();
255 //---------------------------------------------------------------
257 VISU::DeformedShapeAndScalarMap_i
258 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
261 myDeformedShapeAndScalarMapPL = VISU_DeformedShapeAndScalarMapPL::New();
263 myDeformedShapeAndScalarMapPL = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine);
265 myDeformedShapeAndScalarMapPL->GetMapper()->SetScalarVisibility(1);
267 TSuperClass::CreatePipeLine(myDeformedShapeAndScalarMapPL);
271 //---------------------------------------------------------------
273 VISU::DeformedShapeAndScalarMap_i
276 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
280 //---------------------------------------------------------------
282 VISU::DeformedShapeAndScalarMap_i
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);
291 anActor->SetShrink();
292 anActor->SetVTKMapping(false);
297 //---------------------------------------------------------------
299 VISU::DeformedShapeAndScalarMap_i
300 ::UpdateActor(VISU_Actor* theActor)
302 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
303 anActor->SetBarVisibility(true);
304 GetPipeLine()->GetMapper()->SetScalarVisibility(1);
306 TSuperClass::UpdateActor(theActor);
310 //---------------------------------------------------------------
312 VISU::DeformedShapeAndScalarMap_i
313 ::SetField(VISU::PField theField)
315 TSuperClass::SetField(theField);
318 myScalarField = theField;
322 //---------------------------------------------------------------
324 VISU::DeformedShapeAndScalarMap_i
325 ::SetScalarField(VISU::Entity theEntity,
326 const char* theFieldName,
327 CORBA::Long theTimeStampNumber)
329 bool anIsModified = false;
332 anIsModified |= myScalarEntity != theEntity;
335 anIsModified |= myScalarFieldName != theFieldName;
338 anIsModified |= myScalarTimeStampNumber != theTimeStampNumber;
343 VISU::TSetModified aModified(this);
345 VISU::TEntity aEntity = VISU::TEntity(theEntity);
346 VISU::Result_i::PInput anInput = GetCResult()->GetInput(GetCMeshName(),
350 myScalarField = anInput->GetField(GetCMeshName(), aEntity, theFieldName);
352 VISU::PUnstructuredGridIDMapper anIDMapper =
353 anInput->GetTimeStampOnMesh(GetCMeshName(),
358 vtkUnstructuredGrid* anOutput = anIDMapper->GetUnstructuredGridOutput();
359 if(myDeformedShapeAndScalarMapPL && anOutput)
360 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkDataSet*>
361 (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScalars, anOutput));
363 myScalarEntity = theEntity;
364 myScalarFieldName = theFieldName;
365 myScalarTimeStampNumber = theTimeStampNumber;
367 SetTitle(theFieldName);
368 SetScalarMode(GetScalarMode());
369 if(!IsRangeFixed() && IsPipeLineExists())
372 myParamsTime.Modified();
376 //---------------------------------------------------------------
378 VISU::DeformedShapeAndScalarMap_i
381 return myScalarEntity;
385 //---------------------------------------------------------------
387 VISU::DeformedShapeAndScalarMap_i
388 ::GetScalarFieldName()
390 return CORBA::string_dup(myScalarFieldName.c_str());
394 //---------------------------------------------------------------
396 VISU::DeformedShapeAndScalarMap_i
397 ::GetScalarTimeStampNumber()
399 return myScalarTimeStampNumber;
403 //---------------------------------------------------------------
405 VISU::DeformedShapeAndScalarMap_i
408 return myScalarField;