Salome HOME
fad4604c74db590f7bc2f1dca686367cf50193dd
[modules/visu.git] / src / VISU_I / VISU_Deformation_i.cc
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VISU_Deformation_i.cc
21 //  Author : 
22 //  Module : VISU
23 //
24 #include "VISU_Deformation_i.hh"
25 #include "VISU_Result_i.hh"
26 #include "VISU_Prs3dUtils.hh"
27
28 #include "VISU_DeformationPL.hxx"
29 #include "VISU_Convertor.hxx"
30 #include "VISU_DeformationPL.hxx"
31 #include "VISUConfig.hh"
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 0;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39 //---------------------------------------------------------------
40 VISU::Deformation_i::Deformation_i(VISU::ColoredPrs3d_i *thePrs3d):
41   myColoredPrs3d(thePrs3d)
42 {
43   if(MYDEBUG) MESSAGE("Deformation_i::Deformation_i()");
44 }
45
46 //---------------------------------------------------------------
47 VISU::Deformation_i::~Deformation_i()
48 {
49   if(MYDEBUG) MESSAGE("Deformation_i::~Deformation_i()");
50 }
51
52 //---------------------------------------------------------------
53 void VISU::Deformation_i::SetScale(CORBA::Double theScale)
54 {
55   if(MYDEBUG) MESSAGE("Deformation_i::SetScale()");
56
57   VISU::TSetModified aModified(GetColoredPrs3d());
58
59   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformationPL, vtkFloatingPointType>
60                    (GetSpecificDeformedPL(), &VISU_DeformationPL::SetScale, theScale));
61 }
62
63 //---------------------------------------------------------------
64 void VISU::Deformation_i::InitDeformedPipeLine(VISU_DeformationPL* theDeformedPipeLine){
65   
66   if(MYDEBUG) MESSAGE("Deformation_i::InitDeformedPipeLine()");
67   myDeformationPL = theDeformedPipeLine;
68 }
69
70 //---------------------------------------------------------------
71 CORBA::Double 
72 VISU::Deformation_i
73 ::GetScale()
74 {
75   if(MYDEBUG) MESSAGE("Deformation_i::GetScale()");
76   return GetSpecificDeformedPL()->GetScale();
77 }
78
79 //---------------------------------------------------------------
80 VISU::Entity VISU::Deformation_i::GetVectorialFieldEntity(){
81   return myVectorialEntity;
82 }
83
84 //---------------------------------------------------------------
85 char* VISU::Deformation_i::GetVectorialFieldName(){
86   return CORBA::string_dup(myVectorialFieldName.c_str());
87 }
88
89 //---------------------------------------------------------------
90 void VISU::Deformation_i::
91 DeformationToStream(std::ostringstream& theStr)
92 {
93   Storable::DataToStream(theStr,"myScaleFactor", GetScale());
94   Storable::DataToStream(theStr,"myVectorialField", GetVectorialFieldName());
95   Storable::DataToStream(theStr,"myVectorialEntiry", GetVectorialFieldEntity());
96
97 }
98
99 //---------------------------------------------------------------
100 void
101 VISU::Deformation_i::RestoreDeformation(SALOMEDS::SObject_ptr theSObject,
102                                         const Storable::TRestoringMap& theMap)
103 {
104   SetScale(VISU::Storable::FindValue(theMap,"myScaleFactor").toDouble());
105   VISU::Entity anEntity = VISU::Entity(VISU::Storable::FindValue(theMap, "myVectorialEntiry").toInt());
106   
107   SetVectorialField(anEntity,
108                     VISU::Storable::FindValue(theMap, "myVectorialField").toLatin1().constData()); 
109 }
110
111 //---------------------------------------------------------------
112 void
113 VISU::Deformation_i::SameAsDeformation(const Deformation_i *aDeformedPrs){
114   if(const Deformation_i* aPrs = dynamic_cast<const Deformation_i*>(aDeformedPrs)) {
115     Deformation_i* anOrigin = const_cast<Deformation_i*>(aPrs);
116     
117     CORBA::String_var aVectorialFieldName = anOrigin->GetVectorialFieldName();
118     VISU::Entity anEntity = anOrigin->GetVectorialFieldEntity();
119     this->SetVectorialField(anEntity,
120                             aVectorialFieldName);
121     this->SetScale(anOrigin->GetScale());
122   }
123 }
124
125 void VISU::Deformation_i::SetVectorialField(Entity theEntity, const char* theFieldName){
126   if(MYDEBUG) MESSAGE("CutPlanes_i::SetVectorialField()");
127
128   bool anIsModified = false;
129   if(!anIsModified)
130     anIsModified |= GetVectorialFieldEntity() != theEntity;
131   
132   if(!anIsModified)
133     anIsModified |= GetVectorialFieldName() != theFieldName;
134
135   if(!anIsModified)
136     return;
137
138   ColoredPrs3d_i *aColoredPrs = GetColoredPrs3d();
139   int aTimeStampNumber = aColoredPrs->GetTimeStampNumber();
140
141   VISU::TEntity aEntity = VISU::TEntity(theEntity);
142
143   VISU::Result_i::PInput anInput = aColoredPrs->GetCResult()->GetInput(aColoredPrs->GetCMeshName(),
144                                                                        theEntity,
145                                                                        theFieldName,
146                                                                        aTimeStampNumber);
147
148   PField aVectorialField = anInput->GetField(aColoredPrs->GetCMeshName(), aEntity, theFieldName);
149
150   VISU::PUnstructuredGridIDMapper anIDMapper = 
151     anInput->GetTimeStampOnMesh(aColoredPrs->GetCMeshName(),
152                                 aEntity,
153                                 theFieldName,
154                                 aTimeStampNumber);
155   if(GetSpecificDeformedPL() && anIDMapper) {
156     ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformationPL, VISU::PUnstructuredGridIDMapper>
157                      (GetSpecificDeformedPL(), &VISU_DeformationPL::SetVectorialField, anIDMapper));
158     
159     VISU::TSetModified aModified(GetColoredPrs3d());
160     
161     myVectorialEntity = theEntity;
162     myVectorialFieldName = theFieldName;
163     myVectorialField = anIDMapper;
164   }
165 };