Salome HOME
5e8ae25df85037ccdb09dd3661c2870ab03b4893
[modules/visu.git] / src / VISU_I / VISU_DeformedShape_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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 //
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.hxx"
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
49 //---------------------------------------------------------------
50 size_t
51 VISU::DeformedShape_i
52 ::IsPossible(Result_i* theResult, 
53              const std::string& theMeshName, 
54              VISU::Entity theEntity,
55              const std::string& theFieldName, 
56              CORBA::Long theTimeStampNumber,
57              bool theIsMemoryCheck)
58 {
59   try{
60     size_t aResult = TSuperClass::IsPossible(theResult,
61                                              theMeshName,
62                                              theEntity,
63                                              theFieldName,
64                                              theTimeStampNumber,
65                                              theIsMemoryCheck);
66     if(aResult){
67       VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
68                                                            theEntity,
69                                                            theFieldName,
70                                                            theTimeStampNumber);
71       VISU::PField aField = anInput->GetField(theMeshName,
72                                               (VISU::TEntity)theEntity,
73                                               theFieldName);
74       if(aField->myNbComp > 1)
75         return aResult;
76     }
77   }catch(std::exception& exc){
78     INFOS("Follow exception was occured :\n"<<exc.what());
79   }catch(...){
80     INFOS("Unknown exception was occured!");
81   }
82   return 0;
83 }
84
85
86 //---------------------------------------------------------------
87 int VISU::DeformedShape_i::myNbPresent = 0;
88
89 //---------------------------------------------------------------
90 QString 
91 VISU::DeformedShape_i
92 ::GenerateName() 
93
94   return VISU::GenerateName("Def.Shape",myNbPresent++);
95 }
96
97 //---------------------------------------------------------------
98 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
99
100 //---------------------------------------------------------------
101 const char* 
102 VISU::DeformedShape_i
103 ::GetComment() const 
104
105   return myComment.c_str();
106 }
107
108
109 //---------------------------------------------------------------
110 const char*
111 VISU::DeformedShape_i
112 ::GetIconName()
113 {
114   if (!IsGroupsUsed())
115     return "ICON_TREE_DEFORMED_SHAPE";
116   else
117     return "ICON_TREE_DEFORMED_SHAPE_GROUPS";
118 }  
119
120
121 //---------------------------------------------------------------
122 VISU::DeformedShape_i
123 ::DeformedShape_i(EPublishInStudyMode thePublishInStudyMode):
124   ColoredPrs3d_i(thePublishInStudyMode),
125   ScalarMap_i(thePublishInStudyMode),
126   myDeformedShapePL(NULL)
127 {
128   if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
129 }
130
131
132 //---------------------------------------------------------------
133 void 
134 VISU::DeformedShape_i
135 ::SameAs(const Prs3d_i* theOrigin)
136 {
137   TSuperClass::SameAs(theOrigin);
138
139   if(const DeformedShape_i* aPrs3d = dynamic_cast<const DeformedShape_i*>(theOrigin)){
140     DeformedShape_i* anOrigin = const_cast<DeformedShape_i*>(aPrs3d);
141     SetColor(anOrigin->GetColor());
142     ShowColored(anOrigin->IsColored());
143   }
144 }
145
146 //---------------------------------------------------------------
147 VISU::Storable* 
148 VISU::DeformedShape_i
149 ::Create(const std::string& theMeshName, 
150          VISU::Entity theEntity,
151          const std::string& theFieldName, 
152          CORBA::Long theTimeStampNumber)
153 {
154   myIsColored = false;
155   myColor.R = myColor.G = myColor.B = 0.5;
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   myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
171   myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
172   myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
173   myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
174
175   return this;
176 }
177
178
179 //---------------------------------------------------------------
180 void
181 VISU::DeformedShape_i
182 ::ToStream(std::ostringstream& theStr)
183 {
184   TSuperClass::ToStream(theStr);
185
186   Storable::DataToStream( theStr, "myFactor", GetScale() );
187
188   Storable::DataToStream( theStr, "myIsColored", myIsColored );
189   Storable::DataToStream( theStr, "myColor.R", myColor.R );
190   Storable::DataToStream( theStr, "myColor.G", myColor.G );
191   Storable::DataToStream( theStr, "myColor.B", myColor.B );
192 }
193
194
195 //---------------------------------------------------------------
196 VISU::DeformedShape_i
197 ::~DeformedShape_i()
198 {
199   if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
200 }
201
202
203 //---------------------------------------------------------------
204 void 
205 VISU::DeformedShape_i
206 ::SetScale(CORBA::Double theScale) 
207
208   VISU::TSetModified aModified(this);
209   
210   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapePL, vtkFloatingPointType>
211                    (GetSpecificPL(), &VISU_DeformedShapePL::SetScale, theScale));
212 }
213
214 //---------------------------------------------------------------
215 CORBA::Double 
216 VISU::DeformedShape_i
217 ::GetScale()
218 {
219   return myDeformedShapePL->GetScale();
220 }
221
222
223 //---------------------------------------------------------------
224 CORBA::Boolean 
225 VISU::DeformedShape_i
226 ::IsColored()
227 {
228   return myIsColored;
229 }
230
231
232 //---------------------------------------------------------------
233 void
234 VISU::DeformedShape_i
235 ::ShowColored(CORBA::Boolean theColored)
236 {
237   if(myIsColored == theColored)
238     return;
239
240   myIsColored = theColored; 
241   myParamsTime.Modified();
242 }
243
244 //---------------------------------------------------------------
245 SALOMEDS::Color 
246 VISU::DeformedShape_i
247 ::GetColor()
248 {
249   return myColor;
250 }
251
252
253 //---------------------------------------------------------------
254 void
255 VISU::DeformedShape_i
256 ::SetColor(const SALOMEDS::Color& theColor)
257 {
258   bool anIsSameValue = VISU::CheckIsSameValue(myColor.R, theColor.R);
259   anIsSameValue &= VISU::CheckIsSameValue(myColor.G, theColor.G);
260   anIsSameValue &= VISU::CheckIsSameValue(myColor.B, theColor.B);
261   if(anIsSameValue)
262     return;
263
264   VISU::TSetModified aModified(this);
265   
266   myColor = theColor;
267   myParamsTime.Modified();
268 }
269
270
271 //---------------------------------------------------------------
272 void
273 VISU::DeformedShape_i
274 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
275 {
276   if(!thePipeLine){
277     myDeformedShapePL = VISU_DeformedShapePL::New();
278   }else
279     myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine);
280
281   myDeformedShapePL->GetMapper()->SetScalarVisibility(IsColored());
282
283   TSuperClass::CreatePipeLine(myDeformedShapePL);
284 }
285
286
287 //---------------------------------------------------------------
288 bool
289 VISU::DeformedShape_i
290 ::CheckIsPossible() 
291 {
292   return IsPossible(GetCResult(),
293                     GetCMeshName(),
294                     GetEntity(),
295                     GetCFieldName(),
296                     GetTimeStampNumber(),
297                     true);
298 }
299
300
301 //---------------------------------------------------------------
302 void 
303 VISU::DeformedShape_i
304 ::SetMapScale(double theMapScale)
305 {
306   VISU::TSetModified aModified(this);
307   
308   myDeformedShapePL->SetMapScale(theMapScale);
309 }
310
311
312 //---------------------------------------------------------------
313 VISU_Actor* 
314 VISU::DeformedShape_i
315 ::CreateActor(bool toSupressShrinking) 
316 {
317   VISU_Actor* anActor = TSuperClass::CreateActor(true);
318   anActor->SetVTKMapping(false);
319   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
320   int  aDispMode = aResourceMgr->integerValue("VISU", "deformed_shape_represent", 1);
321   bool toShrink  = aResourceMgr->booleanValue("VISU", "deformed_shape_shrink", false);
322   anActor->SetRepresentation(aDispMode);
323   if (toShrink && !toSupressShrinking) anActor->SetShrink();
324   anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
325   return anActor;
326 }
327
328
329 //---------------------------------------------------------------
330 VISU_Actor* 
331 VISU::DeformedShape_i
332 ::CreateActor() 
333 {
334   return CreateActor(false);
335 }
336
337
338 //---------------------------------------------------------------
339 void
340 VISU::DeformedShape_i
341 ::UpdateActor(VISU_Actor* theActor) 
342 {
343   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
344     if(IsColored()){
345       anActor->SetBarVisibility(true);
346       GetPipeLine()->GetMapper()->SetScalarVisibility(1);
347     }else{
348       anActor->SetBarVisibility(false);
349       GetPipeLine()->GetMapper()->SetScalarVisibility(0);
350       anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
351     }
352     TSuperClass::UpdateActor(theActor);
353   }
354 }