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_Result_i.hh"
30 #include "VISU_ScalarMapAct.h"
31 #include "VISU_DeformedShapePL.hxx"
32 #include "VISU_Convertor.hxx"
34 #include "SUIT_ResourceMgr.h"
36 #include <vtkDataSetMapper.h>
37 #include <vtkProperty.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
49 const char* theFieldName, int theIteration, int isMemoryCheck)
52 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck)) return 0;
53 const VISU::PField aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
54 return aField->myNbComp > 1;
55 }catch(std::exception& exc){
56 INFOS("Follow exception was occured :\n"<<exc.what());
58 INFOS("Unknown exception was occured!");
63 int VISU::DeformedShape_i::myNbPresent = 0;
64 QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);}
66 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
67 const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();}
70 VISU::DeformedShape_i::
71 DeformedShape_i(Result_i* theResult,
73 PrsObject_i(theResult->GetStudyDocument()),
74 Prs3d_i(theResult,theAddToStudy),
75 ColoredPrs3d_i(theResult,theAddToStudy),
76 ScalarMap_i(theResult,theAddToStudy),
77 myDeformedShapePL(NULL)
79 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
83 VISU::DeformedShape_i::
84 DeformedShape_i(Result_i* theResult,
85 SALOMEDS::SObject_ptr theSObject) :
86 PrsObject_i(theResult->GetStudyDocument()),
87 Prs3d_i(theResult,theSObject),
88 ColoredPrs3d_i(theResult,theSObject),
89 ScalarMap_i(theResult,theSObject),
90 myDeformedShapePL(NULL)
92 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
96 void VISU::DeformedShape_i::SameAs(const Prs3d_i* theOrigin)
98 TSuperClass::SameAs(theOrigin);
100 if(const DeformedShape_i* aPrs3d = dynamic_cast<const DeformedShape_i*>(theOrigin)){
101 DeformedShape_i* anOrigin = const_cast<DeformedShape_i*>(aPrs3d);
102 SetColor(anOrigin->GetColor());
103 ShowColored(anOrigin->IsColored());
108 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
109 const char* theFieldName, int theIteration)
112 myColor.R = myColor.G = myColor.B = 0.5;
113 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
117 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
119 TSuperClass::Restore(theMap);
121 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
122 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
123 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
124 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
125 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
131 void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){
132 ScalarMap_i::ToStream(theStr);
134 Storable::DataToStream( theStr, "myFactor", GetScale() );
136 Storable::DataToStream( theStr, "myIsColored", myIsColored );
137 Storable::DataToStream( theStr, "myColor.R", myColor.R );
138 Storable::DataToStream( theStr, "myColor.G", myColor.G );
139 Storable::DataToStream( theStr, "myColor.B", myColor.B );
143 VISU::DeformedShape_i::~DeformedShape_i(){
144 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
148 void VISU::DeformedShape_i::SetScale(CORBA::Double theScale) {
149 myDeformedShapePL->SetScale(theScale);
151 CORBA::Double VISU::DeformedShape_i::GetScale(){
152 return myDeformedShapePL->GetScale();
156 void VISU::DeformedShape_i::DoHook(){
157 if(!myPipeLine) myPipeLine = VISU_DeformedShapePL::New();
158 myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(myPipeLine);
159 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
161 ScalarMap_i::DoHook();
165 void VISU::DeformedShape_i::SetMapScale(double theMapScale){
166 myDeformedShapePL->SetMapScale(theMapScale);
171 VISU::DeformedShape_i
172 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
174 VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO);
175 anActor->SetVTKMapping(false);
176 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
177 int aDispMode = aResourceMgr->integerValue("VISU", "deformed_shape_represent", 1);
178 bool toShrink = aResourceMgr->booleanValue("VISU", "deformed_shape_shrink", false);
179 anActor->SetRepresentation(aDispMode);
180 if (toShrink) anActor->SetShrink();
181 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
186 void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor) {
187 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
189 anActor->SetBarVisibility(true);
190 myPipeLine->GetMapper()->SetScalarVisibility(1);
192 anActor->SetBarVisibility(false);
193 myPipeLine->GetMapper()->SetScalarVisibility(0);
194 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
196 VISU::ScalarMap_i::UpdateActor(theActor);