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