1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU OBJECT : interactive object for VISU entities implementation
21 // File : VISU_DeformedShapeAndScalarMap_i.cc
22 // Author : Eugeny Nikolaev
25 #include "VISU_DeformedShapeAndScalarMap_i.hh"
26 #include "VISU_Prs3dUtils.hh"
27 #include "VISU_Result_i.hh"
29 #include "VISU_ScalarMapAct.h"
30 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
31 #include "VISU_Convertor.hxx"
33 #include "SUIT_ResourceMgr.h"
34 #include "SALOME_Event.h"
36 #include <vtkUnstructuredGrid.h>
37 #include <vtkProperty.h>
38 #include <vtkMapper.h>
41 static int MYDEBUG = 0;
43 static int MYDEBUG = 0;
46 static int INCMEMORY = 4+12;
50 //---------------------------------------------------------------
52 VISU::DeformedShapeAndScalarMap_i
53 ::IsPossible(Result_i* theResult,
54 const std::string& theMeshName,
55 VISU::Entity theEntity,
56 const std::string& theFieldName,
57 CORBA::Long theTimeStampNumber,
58 bool theIsMemoryCheck)
62 aResult = TSuperClass::IsPossible(theResult,
68 if(theIsMemoryCheck && aResult){
69 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
73 VISU::PField aField = anInput->GetField(theMeshName,
74 (VISU::TEntity)theEntity,
76 if(aField->myNbComp <= 1)
79 bool anIsEstimated = true;
80 size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
81 (VISU::TEntity)theEntity,
87 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
89 MESSAGE("DeformedShapeAndScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
91 }catch(std::exception& exc){
92 INFOS("Follow exception was occured :\n"<<exc.what());
94 INFOS("Unknown exception was occured!");
99 //---------------------------------------------------------------
100 int VISU::DeformedShapeAndScalarMap_i::myNbPresent = 0;
102 //---------------------------------------------------------------
104 VISU::DeformedShapeAndScalarMap_i
107 return VISU::GenerateName("ScalarDef.Shape",myNbPresent++);
110 //---------------------------------------------------------------
111 const string VISU::DeformedShapeAndScalarMap_i::myComment = "SCALARMAPONDEFORMEDSHAPE"; // It is obsolete. Use "DEFORMEDSHAPEANDSCALARMAP" instead.
113 //---------------------------------------------------------------
115 VISU::DeformedShapeAndScalarMap_i
118 return myComment.c_str();
121 //----------------------------------------------------------------------------
123 VISU::DeformedShapeAndScalarMap_i
127 return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE";
129 return "ICON_TREE_SCALAR_MAP_ON_DEFORMED_SHAPE_GROUPS";
132 //---------------------------------------------------------------
133 VISU::DeformedShapeAndScalarMap_i
134 ::DeformedShapeAndScalarMap_i(EPublishInStudyMode thePublishInStudyMode) :
135 ColoredPrs3d_i(thePublishInStudyMode),
136 ScalarMap_i(thePublishInStudyMode),
137 myDeformedShapeAndScalarMapPL(NULL),
138 myScalarTimeStampNumber(1)
142 //---------------------------------------------------------------
144 VISU::DeformedShapeAndScalarMap_i
145 ::Create(const std::string& theMeshName,
146 VISU::Entity theEntity,
147 const std::string& theFieldName,
148 CORBA::Long theTimeStampNumber)
150 TSuperClass::Create(theMeshName,
154 SetScalarField(theEntity,
155 theFieldName.c_str(),
161 //---------------------------------------------------------------
163 VISU::DeformedShapeAndScalarMap_i
164 ::Restore(SALOMEDS::SObject_ptr theSObject,
165 const Storable::TRestoringMap& theMap)
167 if(!TSuperClass::Restore(theSObject, theMap))
170 QString aMeshName = VISU::Storable::FindValue(theMap,"myScalarMeshName");
171 VISU::Entity anEntity = VISU::Entity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt());
173 QString aFieldName = VISU::Storable::FindValue(theMap,"myScalarFieldName");
174 int aTimeStampNumber = VISU::Storable::FindValue(theMap,"myScalarIteration").toInt();
176 SetScalarField(anEntity,
177 aFieldName.toLatin1().constData(),
180 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
186 //---------------------------------------------------------------
188 VISU::DeformedShapeAndScalarMap_i
189 ::ToStream(std::ostringstream& theStr)
191 TSuperClass::ToStream(theStr);
193 Storable::DataToStream( theStr, "myScalarEntity", int(myScalarEntity));
194 Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str());
195 Storable::DataToStream( theStr, "myScalarIteration", int(myScalarTimeStampNumber));
197 Storable::DataToStream( theStr, "myFactor", GetScale() );
201 //---------------------------------------------------------------
202 VISU::DeformedShapeAndScalarMap_i
203 ::~DeformedShapeAndScalarMap_i()
205 if(MYDEBUG) MESSAGE("DeformedShapeAndScalarMap_i::~DeformedShapeAndScalarMap_i()");
209 //---------------------------------------------------------------
211 VISU::DeformedShapeAndScalarMap_i
212 ::SameAs(const Prs3d_i* theOrigin)
214 TSuperClass::SameAs(theOrigin);
216 if(const DeformedShapeAndScalarMap_i* aPrs3d = dynamic_cast<const DeformedShapeAndScalarMap_i*>(theOrigin)){
217 DeformedShapeAndScalarMap_i* anOrigin = const_cast<DeformedShapeAndScalarMap_i*>(aPrs3d);
218 CORBA::String_var aFieldName = anOrigin->GetScalarFieldName();
220 SetScalarField(anOrigin->GetScalarEntity(),
222 anOrigin->GetScalarTimeStampNumber());
223 SetTitle(anOrigin->GetTitle()); //fix of 20094 issue
224 SetScalarMode(anOrigin->GetScalarMode()); //
225 if(!IsRangeFixed() && IsPipeLineExists()) //fix of 20107 issue
232 //---------------------------------------------------------------
234 VISU::DeformedShapeAndScalarMap_i
235 ::SetScale(CORBA::Double theScale)
237 VISU::TSetModified aModified(this);
239 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkFloatingPointType>
240 (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScale, theScale));
244 //---------------------------------------------------------------
246 VISU::DeformedShapeAndScalarMap_i
249 return myDeformedShapeAndScalarMapPL->GetScale();
253 //---------------------------------------------------------------
255 VISU::DeformedShapeAndScalarMap_i
256 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
259 myDeformedShapeAndScalarMapPL = VISU_DeformedShapeAndScalarMapPL::New();
261 myDeformedShapeAndScalarMapPL = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine);
263 myDeformedShapeAndScalarMapPL->GetMapper()->SetScalarVisibility(1);
265 TSuperClass::CreatePipeLine(myDeformedShapeAndScalarMapPL);
269 //---------------------------------------------------------------
271 VISU::DeformedShapeAndScalarMap_i
274 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
278 //---------------------------------------------------------------
280 VISU::DeformedShapeAndScalarMap_i
283 VISU_Actor* anActor = TSuperClass::CreateActor(true);
284 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
285 int aDispMode = aResourceMgr->integerValue("VISU", "scalar_def_represent", 2);
286 bool toShrink = aResourceMgr->booleanValue("VISU", "scalar_def_shrink", false);
287 anActor->SetRepresentation(aDispMode);
289 anActor->SetShrink();
290 anActor->SetVTKMapping(false);
295 //---------------------------------------------------------------
297 VISU::DeformedShapeAndScalarMap_i
298 ::UpdateActor(VISU_Actor* theActor)
300 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
301 anActor->SetBarVisibility(true);
302 GetPipeLine()->GetMapper()->SetScalarVisibility(1);
304 TSuperClass::UpdateActor(theActor);
308 //---------------------------------------------------------------
310 VISU::DeformedShapeAndScalarMap_i
311 ::SetField(VISU::PField theField)
313 TSuperClass::SetField(theField);
316 myScalarField = theField;
320 //---------------------------------------------------------------
322 VISU::DeformedShapeAndScalarMap_i
323 ::SetScalarField(VISU::Entity theEntity,
324 const char* theFieldName,
325 CORBA::Long theTimeStampNumber)
327 bool anIsModified = false;
330 anIsModified |= myScalarEntity != theEntity;
333 anIsModified |= myScalarFieldName != theFieldName;
336 anIsModified |= myScalarTimeStampNumber != theTimeStampNumber;
341 VISU::TSetModified aModified(this);
343 VISU::TEntity aEntity = VISU::TEntity(theEntity);
344 VISU::Result_i::PInput anInput = GetCResult()->GetInput(GetCMeshName(),
348 myScalarField = anInput->GetField(GetCMeshName(), aEntity, theFieldName);
350 VISU::PUnstructuredGridIDMapper anIDMapper =
351 anInput->GetTimeStampOnMesh(GetCMeshName(),
356 vtkUnstructuredGrid* anOutput = anIDMapper->GetUnstructuredGridOutput();
357 if(myDeformedShapeAndScalarMapPL && anOutput)
358 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapeAndScalarMapPL, vtkDataSet*>
359 (GetSpecificPL(), &VISU_DeformedShapeAndScalarMapPL::SetScalars, anOutput));
361 myScalarEntity = theEntity;
362 myScalarFieldName = theFieldName;
363 myScalarTimeStampNumber = theTimeStampNumber;
365 SetTitle(theFieldName);
366 SetScalarMode(GetScalarMode());
367 if(!IsRangeFixed() && IsPipeLineExists())
370 myParamsTime.Modified();
374 //---------------------------------------------------------------
376 VISU::DeformedShapeAndScalarMap_i
379 return myScalarEntity;
383 //---------------------------------------------------------------
385 VISU::DeformedShapeAndScalarMap_i
386 ::GetScalarFieldName()
388 return CORBA::string_dup(myScalarFieldName.c_str());
392 //---------------------------------------------------------------
394 VISU::DeformedShapeAndScalarMap_i
395 ::GetScalarTimeStampNumber()
397 return myScalarTimeStampNumber;
401 //---------------------------------------------------------------
403 VISU::DeformedShapeAndScalarMap_i
406 return myScalarField;