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)
106 myColor.R = myColor.G = myColor.B = 0.5;
107 VISU::Storable* aRes = TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration);
108 SetScalarFieldName(theFieldName);
109 SetScalarIteration(theIteration);
110 SetScalarMeshName(theMeshName);
111 int anEntity = theEntity;
112 SetScalarEntity(VISU::TEntity(anEntity));
113 SetScalarField(myScalarMeshName.c_str(),myScalarFieldName.c_str(),myScalarIteration,myScalarEntity);
117 VISU::Storable* VISU::ScalarMapOnDeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
119 TSuperClass::Restore(theMap);
121 SetScalarFieldName(VISU::Storable::FindValue(theMap,"myScalarFieldName"));
122 SetScalarMeshName(VISU::Storable::FindValue(theMap,"myScalarMeshName"));
123 SetScalarIteration(VISU::Storable::FindValue(theMap,"myScalarIteration").toInt());
124 SetScalarEntity(VISU::TEntity(VISU::Storable::FindValue(theMap,"myScalarEntity").toInt()));
125 SetScalarField(GetScalarMeshName().c_str(),
126 GetScalarFieldName().c_str(),
127 GetScalarIteration(),
130 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
131 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
132 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
133 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
134 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
139 void VISU::ScalarMapOnDeformedShape_i::ToStream(std::ostringstream& theStr)
141 TSuperClass::ToStream(theStr);
143 Storable::DataToStream( theStr, "myScalarFieldName", myScalarFieldName.c_str());
144 Storable::DataToStream( theStr, "myScalarMeshName", myScalarMeshName.c_str());
145 Storable::DataToStream( theStr, "myScalarIteration", myScalarIteration);
146 Storable::DataToStream( theStr, "myScalarEntity", int(myScalarEntity));
148 Storable::DataToStream( theStr, "myFactor", GetScale() );
149 Storable::DataToStream( theStr, "myIsColored", myIsColored );
150 Storable::DataToStream( theStr, "myColor.R", myColor.R );
151 Storable::DataToStream( theStr, "myColor.G", myColor.G );
152 Storable::DataToStream( theStr, "myColor.B", myColor.B );
156 VISU::ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i(){
157 if(MYDEBUG) MESSAGE("ScalarMapOnDeformedShape_i::~ScalarMapOnDeformedShape_i()");
161 VISU::ScalarMapOnDeformedShape_i
162 ::SameAs(const Prs3d_i* theOrigin)
164 TSuperClass::SameAs(theOrigin);
166 if(const ScalarMapOnDeformedShape_i* aPrs3d = dynamic_cast<const ScalarMapOnDeformedShape_i*>(theOrigin)){
167 ScalarMapOnDeformedShape_i* anOrigin = const_cast<ScalarMapOnDeformedShape_i*>(aPrs3d);
169 // increment the scalar iteration for using in VISU_TimeAnimation class implementation.
170 this->SetScalarField(anOrigin->GetScalarMeshName().c_str(),
171 anOrigin->GetScalarFieldName().c_str(),
172 anOrigin->GetScalarIteration() + 1,
173 anOrigin->GetScalarEntity());
178 void VISU::ScalarMapOnDeformedShape_i::SetScale(CORBA::Double theScale) {
179 myScalarMapOnDeformedShapePL->SetScale(theScale);
182 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetScale(){
183 return myScalarMapOnDeformedShapePL->GetScale();
186 void VISU::ScalarMapOnDeformedShape_i::SetSourceRange(CORBA::Double theMinRange,CORBA::Double theMaxRange){
188 aRange[0] = float(theMinRange);
189 aRange[1] = float(theMaxRange);
190 myScalarMapOnDeformedShapePL->SetScalarRange(aRange);
193 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMin(){
195 myScalarMapOnDeformedShapePL->GetSourceRange(aRange);
199 CORBA::Double VISU::ScalarMapOnDeformedShape_i::GetSourceRangeMax(){
201 myScalarMapOnDeformedShapePL->GetSourceRange(aRange);
205 void VISU::ScalarMapOnDeformedShape_i::DoHook()
208 myPipeLine = VISU_ScalarMapOnDeformedShapePL::New();
210 myScalarMapOnDeformedShapePL = dynamic_cast<VISU_ScalarMapOnDeformedShapePL*>(myPipeLine);
211 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
213 TSuperClass::DoHook();
216 VISU_Actor* VISU::ScalarMapOnDeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
218 VISU_Actor* anActor = TSuperClass::CreateActor(theIO);
219 anActor->SetRepresentation(2);
220 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
221 anActor->SetVTKMapping(false);
226 void VISU::ScalarMapOnDeformedShape_i::UpdateActor(VISU_Actor* theActor) {
227 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
229 anActor->SetBarVisibility(true);
230 myPipeLine->GetMapper()->SetScalarVisibility(1);
232 anActor->SetBarVisibility(false);
233 myPipeLine->GetMapper()->SetScalarVisibility(0);
234 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
236 TSuperClass::UpdateActor(theActor);
240 void VISU::ScalarMapOnDeformedShape_i::SetScalarField(const char* theMeshName,
241 const char* theFieldName,
242 const int theIteration,
243 const VISU::TEntity theEntity)
245 if (myScalarMapOnDeformedShapePL){
246 myField = myResult->GetInput()->GetField(theMeshName,theEntity,theFieldName);
247 TVTKOutput* aOut = myResult->GetInput()->GetTimeStampOnMesh(theMeshName,
250 theIteration)->GetVTKOutput();
251 myScalarMapOnDeformedShapePL->SetScalars(aOut);
253 this->SetScalarMeshName(theMeshName);
254 this->SetScalarFieldName(theFieldName);
255 this->SetScalarIteration(theIteration);
256 this->SetScalarEntity(theEntity);
260 void VISU::ScalarMapOnDeformedShape_i::SetScalarMeshName(const char* theName){
261 myScalarMeshName = theName;
263 std::string VISU::ScalarMapOnDeformedShape_i::GetScalarMeshName(){
264 return myScalarMeshName;
267 void VISU::ScalarMapOnDeformedShape_i::SetScalarFieldName(const char* theName){
268 myScalarFieldName = theName;
270 std::string VISU::ScalarMapOnDeformedShape_i::GetScalarFieldName(){
271 return myScalarFieldName;
274 void VISU::ScalarMapOnDeformedShape_i::SetScalarIteration(const int theValue){
275 myScalarIteration = theValue;
277 int VISU::ScalarMapOnDeformedShape_i::GetScalarIteration(){
278 return myScalarIteration;
281 void VISU::ScalarMapOnDeformedShape_i::SetScalarEntity(const VISU::TEntity theValue){
282 myScalarEntity = theValue;
284 VISU::TEntity VISU::ScalarMapOnDeformedShape_i::GetScalarEntity(){
285 return myScalarEntity;