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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_DeformedShape_i.hh"
28 #include "VISU_Result_i.hh"
30 #include "VISU_ScalarMapAct.h"
31 #include "VISU_DeformedShapePL.hxx"
32 #include "VISU_Convertor.hxx"
34 #include <vtkDataSetMapper.h>
35 #include <vtkProperty.h>
41 static int MYDEBUG = 0;
43 static int MYDEBUG = 0;
46 int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
47 const char* theFieldName, int theIteration, int isMemoryCheck)
50 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck)) return 0;
51 const VISU::PField aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
52 return aField->myNbComp > 1;
53 }catch(std::exception& exc){
54 INFOS("Follow exception was occured :\n"<<exc.what());
56 INFOS("Unknown exception was occured!");
61 int VISU::DeformedShape_i::myNbPresent = 0;
62 QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);}
64 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
65 const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();}
68 VISU::DeformedShape_i::
69 DeformedShape_i(Result_i* theResult,
71 PrsObject_i(theResult->GetStudyDocument()),
72 Prs3d_i(theResult,theAddToStudy),
73 ColoredPrs3d_i(theResult,theAddToStudy),
74 ScalarMap_i(theResult,theAddToStudy),
75 myDeformedShapePL(NULL)
77 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
81 VISU::DeformedShape_i::
82 DeformedShape_i(Result_i* theResult,
83 SALOMEDS::SObject_ptr theSObject) :
84 PrsObject_i(theResult->GetStudyDocument()),
85 Prs3d_i(theResult,theSObject),
86 ColoredPrs3d_i(theResult,theSObject),
87 ScalarMap_i(theResult,theSObject),
88 myDeformedShapePL(NULL)
90 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
94 void VISU::DeformedShape_i::SameAs(const Prs3d_i* theOrigin)
96 TSuperClass::SameAs(theOrigin);
98 if(const DeformedShape_i* aPrs3d = dynamic_cast<const DeformedShape_i*>(theOrigin)){
99 DeformedShape_i* anOrigin = const_cast<DeformedShape_i*>(aPrs3d);
100 SetColor(anOrigin->GetColor());
101 ShowColored(anOrigin->IsColored());
106 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
107 const char* theFieldName, int theIteration)
110 myColor.R = myColor.G = myColor.B = 0.5;
111 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
115 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
117 TSuperClass::Restore(theMap);
119 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
120 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
121 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
122 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
123 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
129 void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){
130 ScalarMap_i::ToStream(theStr);
132 Storable::DataToStream( theStr, "myFactor", GetScale() );
134 Storable::DataToStream( theStr, "myIsColored", myIsColored );
135 Storable::DataToStream( theStr, "myColor.R", myColor.R );
136 Storable::DataToStream( theStr, "myColor.G", myColor.G );
137 Storable::DataToStream( theStr, "myColor.B", myColor.B );
141 VISU::DeformedShape_i::~DeformedShape_i(){
142 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
146 void VISU::DeformedShape_i::SetScale(CORBA::Double theScale) {
147 myDeformedShapePL->SetScale(theScale);
149 CORBA::Double VISU::DeformedShape_i::GetScale(){
150 return myDeformedShapePL->GetScale();
154 void VISU::DeformedShape_i::DoHook(){
155 if(!myPipeLine) myPipeLine = VISU_DeformedShapePL::New();
156 myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(myPipeLine);
157 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
159 ScalarMap_i::DoHook();
163 void VISU::DeformedShape_i::SetMapScale(double theMapScale){
164 myDeformedShapePL->SetMapScale(theMapScale);
169 VISU::DeformedShape_i
170 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
172 VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO);
173 anActor->SetRepresentation(1);
174 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
175 anActor->SetVTKMapping(false);
180 void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor) {
181 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
183 anActor->SetBarVisibility(true);
184 myPipeLine->GetMapper()->SetScalarVisibility(1);
186 anActor->SetBarVisibility(false);
187 myPipeLine->GetMapper()->SetScalarVisibility(0);
188 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
190 VISU::ScalarMap_i::UpdateActor(theActor);