1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_DeformedShape_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
31 #include "VISU_ScalarMapAct.h"
32 #include "VISU_DeformedShapePL.hxx"
33 #include "VISU_PipeLineUtils.hxx"
34 #include "VISU_Convertor.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.hxx"
39 #include <vtkDataSetMapper.h>
40 #include <vtkProperty.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
49 //---------------------------------------------------------------
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)
60 size_t aResult = TSuperClass::IsPossible(theResult,
67 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
71 VISU::PField aField = anInput->GetField(theMeshName,
72 (VISU::TEntity)theEntity,
74 if(aField->myNbComp > 1)
77 }catch(std::exception& exc){
78 INFOS("Follow exception was occured :\n"<<exc.what());
80 INFOS("Unknown exception was occured!");
86 //---------------------------------------------------------------
87 int VISU::DeformedShape_i::myNbPresent = 0;
89 //---------------------------------------------------------------
94 return VISU::GenerateName("Def.Shape",myNbPresent++);
97 //---------------------------------------------------------------
98 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
100 //---------------------------------------------------------------
102 VISU::DeformedShape_i
105 return myComment.c_str();
109 //---------------------------------------------------------------
111 VISU::DeformedShape_i
115 return "ICON_TREE_DEFORMED_SHAPE";
117 return "ICON_TREE_DEFORMED_SHAPE_GROUPS";
121 //---------------------------------------------------------------
122 VISU::DeformedShape_i
123 ::DeformedShape_i(EPublishInStudyMode thePublishInStudyMode):
124 ColoredPrs3d_i(thePublishInStudyMode),
125 ScalarMap_i(thePublishInStudyMode),
126 myDeformedShapePL(NULL)
128 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
132 //---------------------------------------------------------------
134 VISU::DeformedShape_i
135 ::SameAs(const Prs3d_i* theOrigin)
137 TSuperClass::SameAs(theOrigin);
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());
146 //---------------------------------------------------------------
148 VISU::DeformedShape_i
149 ::Create(const std::string& theMeshName,
150 VISU::Entity theEntity,
151 const std::string& theFieldName,
152 CORBA::Long theTimeStampNumber)
155 myColor.R = myColor.G = myColor.B = 0.5;
156 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
160 //---------------------------------------------------------------
162 VISU::DeformedShape_i
163 ::Restore(SALOMEDS::SObject_ptr theSObject,
164 const Storable::TRestoringMap& theMap)
166 if(!TSuperClass::Restore(theSObject, theMap))
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();
179 //---------------------------------------------------------------
181 VISU::DeformedShape_i
182 ::ToStream(std::ostringstream& theStr)
184 TSuperClass::ToStream(theStr);
186 Storable::DataToStream( theStr, "myFactor", GetScale() );
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 );
195 //---------------------------------------------------------------
196 VISU::DeformedShape_i
199 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
203 //---------------------------------------------------------------
205 VISU::DeformedShape_i
206 ::SetScale(CORBA::Double theScale)
208 VISU::TSetModified aModified(this);
210 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_DeformedShapePL, vtkFloatingPointType>
211 (GetSpecificPL(), &VISU_DeformedShapePL::SetScale, theScale));
214 //---------------------------------------------------------------
216 VISU::DeformedShape_i
219 return myDeformedShapePL->GetScale();
223 //---------------------------------------------------------------
225 VISU::DeformedShape_i
232 //---------------------------------------------------------------
234 VISU::DeformedShape_i
235 ::ShowColored(CORBA::Boolean theColored)
237 if(myIsColored == theColored)
240 myIsColored = theColored;
241 myParamsTime.Modified();
244 //---------------------------------------------------------------
246 VISU::DeformedShape_i
253 //---------------------------------------------------------------
255 VISU::DeformedShape_i
256 ::SetColor(const SALOMEDS::Color& theColor)
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);
264 VISU::TSetModified aModified(this);
267 myParamsTime.Modified();
271 //---------------------------------------------------------------
273 VISU::DeformedShape_i
274 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
277 myDeformedShapePL = VISU_DeformedShapePL::New();
279 myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine);
281 myDeformedShapePL->GetMapper()->SetScalarVisibility(IsColored());
283 TSuperClass::CreatePipeLine(myDeformedShapePL);
287 //---------------------------------------------------------------
289 VISU::DeformedShape_i
292 return IsPossible(GetCResult(),
296 GetTimeStampNumber(),
301 //---------------------------------------------------------------
303 VISU::DeformedShape_i
304 ::SetMapScale(double theMapScale)
306 VISU::TSetModified aModified(this);
308 myDeformedShapePL->SetMapScale(theMapScale);
312 //---------------------------------------------------------------
314 VISU::DeformedShape_i
315 ::CreateActor(bool toSupressShrinking)
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);
329 //---------------------------------------------------------------
331 VISU::DeformedShape_i
334 return CreateActor(false);
338 //---------------------------------------------------------------
340 VISU::DeformedShape_i
341 ::UpdateActor(VISU_Actor* theActor)
343 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
345 anActor->SetBarVisibility(true);
346 GetPipeLine()->GetMapper()->SetScalarVisibility(1);
348 anActor->SetBarVisibility(false);
349 GetPipeLine()->GetMapper()->SetScalarVisibility(0);
350 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
352 TSuperClass::UpdateActor(theActor);