1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_ScalarMapOnDeformedShape_i.cc
24 // Author : Eugeny Nikolaev
27 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_ScalarMap_i.hh"
30 #include "VISU_ScalarMapOnDeformedShape_i.hh"
31 #include "VISU_Convertor.hxx"
32 #include "VISU_ScalarMapAct.h"
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkProperty.h>
36 #include <vtkMapper.h>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 static int INCMEMORY = 4+12;
49 int VISU::ScalarMapOnDeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
50 const char* theFieldName, int theIteration, int isMemoryCheck)
54 aResult = VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false);
55 if(isMemoryCheck && aResult){
56 const VISU::PField aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
57 if(aField->myNbComp <= 1)
59 float aSize = INCMEMORY*
60 theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
61 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
62 MESSAGE("ScalarMapOnDeformedShape_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
64 }catch(std::exception& exc){
65 INFOS("Follow exception was occured :\n"<<exc.what());
67 INFOS("Unknown exception was occured!");
72 int VISU::ScalarMapOnDeformedShape_i::myNbPresent = 0;
73 QString VISU::ScalarMapOnDeformedShape_i::GenerateName() { return VISU::GenerateName("ScalarDef.Shape",myNbPresent++);}
75 const string VISU::ScalarMapOnDeformedShape_i::myComment = "SCALARMAPONDEFORMEDSHAPE";
76 const char* VISU::ScalarMapOnDeformedShape_i::GetComment() const { return myComment.c_str();}
78 VISU::ScalarMapOnDeformedShape_i::
79 ScalarMapOnDeformedShape_i(Result_i* theResult,
81 PrsObject_i(theResult->GetStudyDocument()),
82 Prs3d_i(theResult,theAddToStudy),
83 ColoredPrs3d_i(theResult,theAddToStudy),
84 ScalarMap_i(theResult,theAddToStudy),
85 myScalarMapOnDeformedShapePL(NULL),
90 VISU::ScalarMapOnDeformedShape_i::
91 ScalarMapOnDeformedShape_i(Result_i* theResult,
92 SALOMEDS::SObject_ptr theSObject) :
93 PrsObject_i(theResult->GetStudyDocument()),
94 Prs3d_i(theResult,theSObject),
95 ColoredPrs3d_i(theResult,theSObject),
96 ScalarMap_i(theResult,theSObject),
97 myScalarMapOnDeformedShapePL(NULL),
102 VISU::Storable* VISU::ScalarMapOnDeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
103 const char* theFieldName, int theIteration)
105 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::Create:"<<__LINE__<<endl;
107 myColor.R = myColor.G = myColor.B = 0.5;
108 VISU::Storable* aRes = TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration);
109 SetScalarFieldName(theFieldName);
110 SetScalarIteration(theIteration);
111 SetScalarMeshName(theMeshName);
112 int anEntity = theEntity;
113 SetScalarEntity(VISU::TEntity(anEntity));
114 SetScalarField(myScalarMeshName.c_str(),myScalarFieldName.c_str(),myScalarIteration,myScalarEntity);
118 VISU::Storable* VISU::ScalarMapOnDeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
120 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::Restore:"<<__LINE__<<endl;
121 TSuperClass::Restore(theMap);
123 SetScalarFieldName(VISU::Storable::FindValue(theMap,"myScalarFieldName"));
124 SetScalarMeshName(VISU::Storable::FindValue(theMap,"myScalarMeshName"));
125 SetScalarIteration(VISU::Storable::FindValue(theMap,"myScalarIteration").toInt());
126 SetScalarEntity(VISU::TEntity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt()));
127 SetScalarField(GetScalarMeshName().c_str(),
128 GetScalarFieldName().c_str(),
129 GetScalarIteration(),
132 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
133 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
134 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
135 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
136 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
141 void VISU::ScalarMapOnDeformedShape_i::ToStream(std::ostringstream& theStr)
143 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::ToStream:"<<__LINE__<<endl;
144 TSuperClass::ToStream(theStr);
146 Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str());
147 Storable::DataToStream( theStr, "myScalarMeshName", myScalarMeshName.c_str());
148 Storable::DataToStream( theStr, "myScalarIteration", myScalarIteration);
149 Storable::DataToStream( theStr, "myScalarEntity", int(myScalarEntity));
151 Storable::DataToStream( theStr, "myFactor", GetScale() );
152 Storable::DataToStream( theStr, "myIsColored", myIsColored );
153 Storable::DataToStream( theStr, "myColor.R", myColor.R );
154 Storable::DataToStream( theStr, "myColor.G", myColor.G );
155 Storable::DataToStream( theStr, "myColor.B", myColor.B );
159 VISU::ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i(){
160 if(MYDEBUG) MESSAGE("ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i()");
164 VISU::ScalarMapOnDeformedShape_i
165 ::SameAs(const Prs3d_i* theOrigin)
167 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::SameAs:"<<__LINE__<<endl;
168 int theScalarIter = this->GetScalarIteration();
169 string theScalarMeshName = this->GetScalarMeshName();
170 string theScalarFieldName = this->GetScalarFieldName();
171 if(MYDEBUG) cout << "SameAs:"<<endl
172 << "\t"<<theScalarIter<<":"<<theScalarMeshName.c_str()<<":"<<theScalarFieldName.c_str()<<endl;
174 TSuperClass::SameAs(theOrigin);
176 if(const ScalarMapOnDeformedShape_i* aPrs3d = dynamic_cast<const ScalarMapOnDeformedShape_i*>(theOrigin)){
177 ScalarMapOnDeformedShape_i* anOrigin = const_cast<ScalarMapOnDeformedShape_i*>(aPrs3d);
179 this->SetScalarField(anOrigin->GetScalarMeshName().c_str(),
180 anOrigin->GetScalarFieldName().c_str(),
182 anOrigin->GetScalarEntity());
187 void VISU::ScalarMapOnDeformedShape_i::SetScale(CORBA::Double theScale) {
188 myScalarMapOnDeformedShapePL->SetScale(theScale);
191 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetScale(){
192 return myScalarMapOnDeformedShapePL->GetScale();
195 void VISU::ScalarMapOnDeformedShape_i::SetSourceRange(CORBA::Double theMinRange,CORBA::Double theMaxRange){
197 aRange[0] = float(theMinRange);
198 aRange[1] = float(theMaxRange);
199 myScalarMapOnDeformedShapePL->SetScalarRange(aRange);
202 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMin(){
204 myScalarMapOnDeformedShapePL->GetSourceRange(aRange);
208 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMax(){
210 myScalarMapOnDeformedShapePL->GetSourceRange(aRange);
214 void VISU::ScalarMapOnDeformedShape_i::DoHook()
216 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::DoHook:"<<__LINE__<<endl;
218 myPipeLine = VISU_ScalarMapOnDeformedShapePL::New();
220 myScalarMapOnDeformedShapePL = dynamic_cast<VISU_ScalarMapOnDeformedShapePL*>(myPipeLine);
221 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
223 TSuperClass::DoHook();
226 VISU_Actor* VISU::ScalarMapOnDeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
228 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::CreateActor:"<<__LINE__<<endl;
229 VISU_Actor* anActor = TSuperClass::CreateActor(theIO);
230 anActor->SetRepresentation(2);
231 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
232 anActor->SetVTKMapping(false);
237 void VISU::ScalarMapOnDeformedShape_i::UpdateActor(VISU_Actor* theActor) {
238 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::UpdateActor:"<<__LINE__<<endl;
239 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
241 anActor->SetBarVisibility(true);
242 myPipeLine->GetMapper()->SetScalarVisibility(1);
244 anActor->SetBarVisibility(false);
245 myPipeLine->GetMapper()->SetScalarVisibility(0);
246 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
248 TSuperClass::UpdateActor(theActor);
252 void VISU::ScalarMapOnDeformedShape_i::SetScalarField(const char* theMeshName,
253 const char* theFieldName,
254 const int theIteration,
255 const VISU::TEntity theEntity)
257 if(MYDEBUG) cout << "VISU::ScalarMapOnDeformedShape_i::SetScalarField:"<<__LINE__<<endl;
258 if(MYDEBUG) cout << "\ttheFieldName="<<theFieldName<<endl;
259 if(MYDEBUG) cout << "\ttheIteration="<<theIteration<<endl;
260 myScalarField = myResult->GetInput()->GetField(theMeshName,theEntity,theFieldName);
261 TVTKOutput* aOut = myResult->GetInput()->GetTimeStampOnMesh(theMeshName,
264 theIteration)->GetVTKOutput();
265 if (myScalarMapOnDeformedShapePL){
266 myScalarMapOnDeformedShapePL->SetScalars(aOut);
268 this->SetScalarMeshName(theMeshName);
269 this->SetScalarFieldName(theFieldName);
270 this->SetScalarIteration(theIteration);
271 this->SetScalarEntity(theEntity);
274 void VISU::ScalarMapOnDeformedShape_i::SetScalarField(const char* theMeshName,
275 const char* theFieldName,
276 const long theIteration,
277 const VISU::Entity theEntity)
279 this->SetScalarField(theMeshName,theFieldName,(int)theIteration,VISU::TEntity(theEntity));
282 void VISU::ScalarMapOnDeformedShape_i::SetScalarMeshName(const char* theName){
283 myScalarMeshName = theName;
285 std::string VISU::ScalarMapOnDeformedShape_i::GetScalarMeshName(){
286 return myScalarMeshName;
289 void VISU::ScalarMapOnDeformedShape_i::SetScalarFieldName(const char* theName){
290 myScalarFieldName = theName;
292 std::string VISU::ScalarMapOnDeformedShape_i::GetScalarFieldName(){
293 return myScalarFieldName;
296 void VISU::ScalarMapOnDeformedShape_i::SetScalarIteration(const int theValue){
297 myScalarIteration = theValue;
301 int VISU::ScalarMapOnDeformedShape_i::GetScalarIteration(){
302 return myScalarIteration;
305 void VISU::ScalarMapOnDeformedShape_i::SetScalarEntity(const VISU::TEntity theValue){
306 myScalarEntity = theValue;
309 VISU::TEntity VISU::ScalarMapOnDeformedShape_i::GetScalarEntity(){
310 return myScalarEntity;
313 void VISU::ScalarMapOnDeformedShape_i::SetScalarEEntity(const VISU::Entity theValue){
314 myScalarEntity = VISU::TEntity(theValue);
317 VISU::Entity VISU::ScalarMapOnDeformedShape_i::GetScalarEEntity(){
318 return VISU::Entity(myScalarEntity);
322 VISU::ScalarMapOnDeformedShape_i
325 return myScalarField;