Salome HOME
878f25e823787d150c73698891fee802a5cebc26
[modules/visu.git] / src / VISU_I / VISU_Vectors_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Vectors_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Vectors_i.hh"
28 #include "VISU_Result_i.hh"
29
30 #include "VISU_VectorsAct.h"
31 #include "VISU_VectorsPL.hxx"
32 #include "VISU_Convertor.hxx"
33
34 #include "SUIT_ResourceMgr.h"
35
36 #include <vtkProperty.h>
37
38 using namespace VISU;
39 using namespace std;
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47 static int INCMEMORY = 4+12;
48
49 int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
50                                 const char* theFieldName, int theIteration, int isMemoryCheck)
51 {
52   bool aResult = false;
53   try{
54     aResult = DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false);
55     if(isMemoryCheck && aResult){
56       float aSize = INCMEMORY*
57         theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
58       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
59       MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
60     }
61   }catch(std::exception& exc){
62     INFOS("Follow exception was occured :\n"<<exc.what());
63   }catch(...){
64     INFOS("Unknown exception was occured!");
65   }
66   return aResult;
67 }
68
69
70 int VISU::Vectors_i::myNbPresent = 0;
71 QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);}
72
73
74 const string VISU::Vectors_i::myComment = "VECTORS";
75 const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();}
76
77
78 VISU::Vectors_i::
79 Vectors_i(Result_i* theResult, 
80           bool theAddToStudy) :
81   PrsObject_i(theResult->GetStudyDocument()), 
82   Prs3d_i(theResult,theAddToStudy),
83   ColoredPrs3d_i(theResult,theAddToStudy),
84   ScalarMap_i(theResult,theAddToStudy),
85   DeformedShape_i(theResult,theAddToStudy),
86   myVectorsPL(NULL)
87 {
88 }
89
90
91 VISU::Vectors_i::
92 Vectors_i(Result_i* theResult, 
93           SALOMEDS::SObject_ptr theSObject) :
94   PrsObject_i(theResult->GetStudyDocument()), 
95   Prs3d_i(theResult,theSObject),
96   ColoredPrs3d_i(theResult,theSObject),
97   ScalarMap_i(theResult,theSObject),
98   DeformedShape_i(theResult,theSObject),
99   myVectorsPL(NULL)
100 {
101 }
102
103
104 void VISU::Vectors_i::SameAs(const VISU::Prs3d_i* theOrigin)
105 {
106   TSuperClass::SameAs(theOrigin);
107
108   if(const Vectors_i* aPrs3d = dynamic_cast<const Vectors_i*>(theOrigin)){
109     Vectors_i* anOrigin = const_cast<Vectors_i*>(aPrs3d);
110     SetLineWidth(anOrigin->GetLineWidth());
111   }
112 }
113
114
115 VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, 
116                                         const char* theFieldName, int theIteration)
117 {
118   myLineWidth = 1.0;
119   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
120 }
121
122
123 VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap)
124 {
125   TSuperClass::Restore(theMap);
126
127   SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
128   SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
129   SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
130
131   return this;
132 }
133
134
135 void VISU::Vectors_i::ToStream(std::ostringstream& theStr){
136   DeformedShape_i::ToStream(theStr);
137
138   Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
139   Storable::DataToStream( theStr, "myPosGlyph",  int(GetGlyphPos()));
140   Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
141 }
142
143
144 VISU::Vectors_i::~Vectors_i(){
145   if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
146 }
147
148
149 void VISU::Vectors_i::SetLineWidth(CORBA::Double theWidth) { 
150   myLineWidth = theWidth;
151 }
152 CORBA::Double VISU::Vectors_i::GetLineWidth() { 
153   return myLineWidth;
154 }
155
156
157 void VISU::Vectors_i::SetGlyphType(VISU::Vectors::GlyphType theType) { 
158   myVectorsPL->SetGlyphType(VISU_VectorsPL::GlyphType(theType));
159 }
160 VISU::Vectors::GlyphType VISU::Vectors_i::GetGlyphType() { 
161   return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
162 }
163
164
165 void VISU::Vectors_i::SetGlyphPos(VISU::Vectors::GlyphPos thePos) { 
166   myVectorsPL->SetGlyphPos(VISU_VectorsPL::GlyphPos(thePos));
167 }
168 VISU::Vectors::GlyphPos VISU::Vectors_i::GetGlyphPos() { 
169   return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
170 }
171
172
173 void VISU::Vectors_i::DoHook(){
174   if(!myPipeLine) myPipeLine = VISU_VectorsPL::New();
175   myVectorsPL = dynamic_cast<VISU_VectorsPL*>(myPipeLine);
176
177   DeformedShape_i::DoHook();
178 }
179
180
181 VISU_PipeLine* VISU::Vectors_i::GetPipeLine(){
182   VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
183   aPipeLine->SetIDMapper(myPipeLine->GetIDMapper());
184   aPipeLine->ShallowCopy(myPipeLine);
185   aPipeLine->Update();
186   return aPipeLine;
187 }
188
189
190 VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
191 {
192   VISU_VectorsAct* anActor = VISU_VectorsAct::New();
193   try{
194     VISU::Prs3d_i::CreateActor(anActor,theIO);
195     anActor->SetVTKMapping(true);
196     anActor->SetBarVisibility(true);
197     anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
198     anActor->GetProperty()->SetLineWidth(GetLineWidth());
199     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
200     int  aDispMode = aResourceMgr->integerValue("VISU", "vectors_represent", 1);
201     anActor->SetRepresentation(aDispMode);
202     UpdateActor(anActor);
203   }catch(...){
204     anActor->Delete();
205     throw ;
206   }
207   return anActor;
208 }
209
210
211 void VISU::Vectors_i::UpdateActor(VISU_Actor* theActor) {
212   if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
213     VISU::DeformedShape_i::UpdateActor(anActor);
214     anActor->GetProperty()->SetLineWidth(GetLineWidth());
215     if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
216       aVectorsPL->ShallowCopy(myPipeLine);
217       aVectorsPL->Update();
218       aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());
219     }
220   }
221 }