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_DeformedShapePL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_DeformedShape_i.hh"
30 #include "VISU_ScalarMapAct.h"
32 #include <vtkDataSetMapper.h>
38 static int MYDEBUG = 0;
40 static int MYDEBUG = 0;
43 int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
44 const char* theFieldName, int theIteration, int isMemoryCheck)
47 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck)) return 0;
48 const VISU::PField aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
49 return aField->myNbComp > 1;
50 }catch(std::exception& exc){
51 INFOS("Follow exception was occured :\n"<<exc.what());
53 INFOS("Unknown exception was occured!");
58 int VISU::DeformedShape_i::myNbPresent = 0;
59 QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);}
61 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
62 const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();}
65 VISU::DeformedShape_i::
66 DeformedShape_i(Result_i* theResult,
68 PrsObject_i(theResult->GetStudyDocument()),
69 Prs3d_i(theResult,theAddToStudy),
70 ScalarMap_i(theResult,theAddToStudy),
71 myDeformedShapePL(NULL)
73 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
77 VISU::DeformedShape_i::
78 DeformedShape_i(Result_i* theResult,
79 SALOMEDS::SObject_ptr theSObject) :
80 PrsObject_i(theResult->GetStudyDocument()),
81 Prs3d_i(theResult,theSObject),
82 ScalarMap_i(theResult,theSObject),
83 myDeformedShapePL(NULL)
85 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
89 void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin)
91 DeformedShape_i* aDefShape = const_cast<DeformedShape_i*>(theOrigin);
92 VISU::ScalarMap_i::SameAs(theOrigin);
94 SetColor(aDefShape->GetColor());
95 ShowColored(aDefShape->IsColored());
99 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
100 const char* theFieldName, int theIteration)
103 myColor.R = myColor.G = myColor.B = 0.5;
104 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
108 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
111 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
112 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
113 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
114 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
115 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
117 return ScalarMap_i::Restore(theMap);
121 void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){
122 ScalarMap_i::ToStream(theStr);
124 Storable::DataToStream( theStr, "myFactor", GetScale() );
126 Storable::DataToStream( theStr, "myIsColored", myIsColored );
127 Storable::DataToStream( theStr, "myColor.R", myColor.R );
128 Storable::DataToStream( theStr, "myColor.G", myColor.G );
129 Storable::DataToStream( theStr, "myColor.B", myColor.B );
133 VISU::DeformedShape_i::~DeformedShape_i(){
134 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
138 void VISU::DeformedShape_i::SetScale(CORBA::Double theScale) {
139 myDeformedShapePL->SetScale(theScale);
141 CORBA::Double VISU::DeformedShape_i::GetScale(){
142 return myDeformedShapePL->GetScale();
146 void VISU::DeformedShape_i::DoHook(){
147 if(!myPipeLine) myPipeLine = VISU_DeformedShapePL::New();
148 myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(myPipeLine);
149 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
151 ScalarMap_i::DoHook();
155 void VISU::DeformedShape_i::SetMapScale(double theMapScale){
156 myDeformedShapePL->SetMapScale(theMapScale);
160 VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
162 VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO);
163 anActor->SetRepresentation(1);
164 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
169 void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor) {
170 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
172 anActor->SetBarVisibility(true);
173 myPipeLine->GetMapper()->SetScalarVisibility(1);
175 anActor->SetBarVisibility(false);
176 myPipeLine->GetMapper()->SetScalarVisibility(0);
177 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
179 VISU::ScalarMap_i::UpdateActor(theActor);