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