Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISU_I / VISU_DeformedShape_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 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_PrsObject_i.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #include "VISU_DeformedShape_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
30
31 #include "VISU_ScalarMapAct.h"
32 #include "VISU_DeformedShapePL.hxx"
33 #include "VISU_PipeLineUtils.hxx"
34 #include "VISU_Convertor.hxx"
35
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
38
39 #include <vtkDataSetMapper.h>
40 #include <vtkProperty.h>
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 using namespace std;
49
50 //---------------------------------------------------------------
51 size_t
52 VISU::DeformedShape_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)
59 {
60   try{
61     size_t aResult = TSuperClass::IsPossible(theResult,
62                                              theMeshName,
63                                              theEntity,
64                                              theFieldName,
65                                              theTimeStampNumber,
66                                              theIsMemoryCheck);
67     if(aResult){
68       VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
69                                                            theEntity,
70                                                            theFieldName,
71                                                            theTimeStampNumber);
72       VISU::PField aField = anInput->GetField(theMeshName,
73                                               (VISU::TEntity)theEntity,
74                                               theFieldName);
75       if(aField->myNbComp > 1)
76         return aResult;
77     }
78   }catch(std::exception& exc){
79     INFOS("Follow exception was occured :\n"<<exc.what());
80   }catch(...){
81     INFOS("Unknown exception was occured!");
82   }
83   return 0;
84 }
85
86
87 //---------------------------------------------------------------
88 int VISU::DeformedShape_i::myNbPresent = 0;
89
90 //---------------------------------------------------------------
91 QString 
92 VISU::DeformedShape_i
93 ::GenerateName() 
94
95   return VISU::GenerateName("Def.Shape",myNbPresent++);
96 }
97
98 //---------------------------------------------------------------
99 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
100
101 //---------------------------------------------------------------
102 const char* 
103 VISU::DeformedShape_i
104 ::GetComment() const 
105
106   return myComment.c_str();
107 }
108
109
110 //---------------------------------------------------------------
111 const char*
112 VISU::DeformedShape_i
113 ::GetIconName()
114 {
115   if (!IsGroupsUsed())
116     return "ICON_TREE_DEFORMED_SHAPE";
117   else
118     return "ICON_TREE_DEFORMED_SHAPE_GROUPS";
119 }  
120
121
122 //---------------------------------------------------------------
123 VISU::DeformedShape_i
124 ::DeformedShape_i(EPublishInStudyMode thePublishInStudyMode):
125   ColoredPrs3d_i(thePublishInStudyMode),
126   ScalarMap_i(thePublishInStudyMode),
127   MonoColorPrs_i(thePublishInStudyMode),
128   myDeformedShapePL(NULL)
129 {
130   if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
131 }
132
133
134 //---------------------------------------------------------------
135 void 
136 VISU::DeformedShape_i
137 ::SameAs(const Prs3d_i* theOrigin)
138 {
139   TSuperClass::SameAs(theOrigin);
140
141   if(const DeformedShape_i* aPrs3d = dynamic_cast<const DeformedShape_i*>(theOrigin)){
142     DeformedShape_i* anOrigin = const_cast<DeformedShape_i*>(aPrs3d);
143     SetColor(anOrigin->GetColor());
144     ShowColored(anOrigin->IsColored());
145   }
146 }
147
148 //---------------------------------------------------------------
149 VISU::Storable* 
150 VISU::DeformedShape_i
151 ::Create(const std::string& theMeshName, 
152          VISU::Entity theEntity,
153          const std::string& theFieldName, 
154          CORBA::Long theTimeStampNumber)
155 {
156   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
157 }
158
159
160 //---------------------------------------------------------------
161 VISU::Storable* 
162 VISU::DeformedShape_i
163 ::Restore(SALOMEDS::SObject_ptr theSObject,
164           const Storable::TRestoringMap& theMap)
165 {
166   if(!TSuperClass::Restore(theSObject, theMap))
167     return NULL;
168
169   SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
170
171   return this;
172 }
173
174
175 //---------------------------------------------------------------
176 void
177 VISU::DeformedShape_i
178 ::ToStream(std::ostringstream& theStr)
179 {
180   TSuperClass::ToStream(theStr);
181
182   Storable::DataToStream( theStr, "myFactor", GetScale() );
183 }
184
185
186 //---------------------------------------------------------------
187 VISU::DeformedShape_i
188 ::~DeformedShape_i()
189 {
190   if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
191 }
192
193
194 //---------------------------------------------------------------
195 void 
196 VISU::DeformedShape_i
197 ::SetScale(CORBA::Double theScale) 
198
199   VISU::TSetModified aModified(this);
200   
201   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapePL, vtkFloatingPointType>
202                    (GetSpecificPL(), &VISU_DeformedShapePL::SetScale, theScale));
203 }
204
205 //---------------------------------------------------------------
206 CORBA::Double 
207 VISU::DeformedShape_i
208 ::GetScale()
209 {
210   return myDeformedShapePL->GetScale();
211 }
212
213
214 //---------------------------------------------------------------
215 void
216 VISU::DeformedShape_i
217 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
218 {
219   if(!thePipeLine){
220     myDeformedShapePL = VISU_DeformedShapePL::New();
221   }else
222     myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine);
223
224   myDeformedShapePL->GetMapper()->SetScalarVisibility(IsColored());
225
226   TSuperClass::CreatePipeLine(myDeformedShapePL);
227 }
228
229
230 //---------------------------------------------------------------
231 bool
232 VISU::DeformedShape_i
233 ::CheckIsPossible() 
234 {
235   return IsPossible(GetCResult(),
236                     GetCMeshName(),
237                     GetEntity(),
238                     GetCFieldName(),
239                     GetTimeStampNumber(),
240                     true);
241 }
242
243
244 //---------------------------------------------------------------
245 void 
246 VISU::DeformedShape_i
247 ::SetMapScale(double theMapScale)
248 {
249   VISU::TSetModified aModified(this);
250   
251   myDeformedShapePL->SetMapScale(theMapScale);
252 }
253
254
255 //---------------------------------------------------------------
256 VISU_Actor* 
257 VISU::DeformedShape_i
258 ::CreateActor(bool toSupressShrinking) 
259 {
260   VISU_Actor* anActor = TSuperClass::CreateActor(true);
261   anActor->SetVTKMapping(false);
262   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
263   int  aDispMode = aResourceMgr->integerValue("VISU", "deformed_shape_represent", 1);
264   bool toShrink  = aResourceMgr->booleanValue("VISU", "deformed_shape_shrink", false);
265   anActor->SetRepresentation(aDispMode);
266   if (toShrink && !toSupressShrinking) anActor->SetShrink();
267   return anActor;
268 }
269
270