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"
36 static int MYDEBUG = 0;
37 static int MYDEBUGWITHFILES = 0;
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 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::TField& aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
49 return aField.myNbComp > 1;
50 }catch(std::runtime_error& exc){
51 INFOS("Follow exception was accured :\n"<<exc.what());
53 INFOS("Unknown exception was accured!");
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::DeformedShape_i(Result_i* theResult, bool theAddToStudy, SALOMEDS::SObject_ptr theSObject) :
66 PrsObject_i(theResult->GetStudyDocument()),
67 Prs3d_i(theResult,theSObject),
68 ScalarMap_i(theResult,theAddToStudy,theSObject)
70 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
71 myDeformedShapePL = NULL;
76 void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin)
78 DeformedShape_i* aDefShape = const_cast<DeformedShape_i*>(theOrigin);
79 VISU::ScalarMap_i::SameAs(theOrigin);
81 SetColor(aDefShape->GetColor());
82 ShowColored(aDefShape->IsColored());
86 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
87 const char* theFieldName, int theIteration)
90 myColor.R = myColor.G = myColor.B = 0.5;
91 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
95 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap)
96 throw(std::logic_error&)
99 SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble());
100 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
101 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
102 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
103 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
105 return ScalarMap_i::Restore(theMap);
109 void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){
110 ScalarMap_i::ToStream(theStr);
112 Storable::DataToStream( theStr, "myFactor", GetScale() );
114 Storable::DataToStream( theStr, "myIsColored", myIsColored );
115 Storable::DataToStream( theStr, "myColor.R", myColor.R );
116 Storable::DataToStream( theStr, "myColor.G", myColor.G );
117 Storable::DataToStream( theStr, "myColor.B", myColor.B );
121 VISU::DeformedShape_i::~DeformedShape_i(){
122 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
126 void VISU::DeformedShape_i::SetScale(CORBA::Double theScale) {
127 myDeformedShapePL->SetScale(theScale);
129 CORBA::Double VISU::DeformedShape_i::GetScale(){
130 return myDeformedShapePL->GetScale();
134 void VISU::DeformedShape_i::DoHook(){
135 if(!myPipeLine) myPipeLine = VISU_DeformedShapePL::New();
136 myDeformedShapePL = dynamic_cast<VISU_DeformedShapePL*>(myPipeLine);
137 myPipeLine->GetMapper()->SetScalarVisibility(IsColored());
139 ScalarMap_i::DoHook();
143 void VISU::DeformedShape_i::SetMapScale(double theMapScale){
144 myDeformedShapePL->SetMapScale(theMapScale);
148 VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
149 throw (std::runtime_error&)
151 VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO);
152 anActor->SetRepresentation(1);
153 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
158 void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor) throw(std::runtime_error&){
159 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
161 anActor->SetBarVisibility(true);
162 myPipeLine->GetMapper()->SetScalarVisibility(1);
164 anActor->SetBarVisibility(false);
165 myPipeLine->GetMapper()->SetScalarVisibility(0);
166 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
168 VISU::ScalarMap_i::UpdateActor(theActor);