]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_Vectors_i.cc
Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_Vectors_i.cc
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_Vectors_i.cc
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_Vectors_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
31
32 #include "VISU_VectorsAct.h"
33 #include "VISU_VectorsPL.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "VISU_Convertor.hxx"
36
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
39
40 #include <vtkProperty.h>
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 static int INCMEMORY = 4+12;
49
50 using namespace std;
51
52 //---------------------------------------------------------------
53 size_t 
54 VISU::Vectors_i
55 ::IsPossible(Result_i* theResult, 
56              const std::string& theMeshName, 
57              VISU::Entity theEntity,
58              const std::string& theFieldName, 
59              CORBA::Long theTimeStampNumber,
60              bool theIsMemoryCheck)
61 {
62   try{
63     size_t aResult = TSuperClass::IsPossible(theResult,
64                                              theMeshName,
65                                              theEntity,
66                                              theFieldName,
67                                              theTimeStampNumber,
68                                              false);
69     if(theIsMemoryCheck && aResult){
70       bool anIsEstimated = true;
71       VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
72                                                            theEntity,
73                                                            theFieldName,
74                                                            theTimeStampNumber);
75       size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
76                                                      (VISU::TEntity)theEntity,
77                                                      theFieldName,
78                                                      theTimeStampNumber,
79                                                      anIsEstimated);
80       if(anIsEstimated)
81         aSize *= INCMEMORY;
82       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
83       if(MYDEBUG) 
84         MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
85     }
86     return aResult;
87   }catch(std::exception& exc){
88     INFOS("Follow exception was occured :\n"<<exc.what());
89   }catch(...){
90     INFOS("Unknown exception was occured!");
91   }
92   return 0;
93 }
94
95 //---------------------------------------------------------------
96 int VISU::Vectors_i::myNbPresent = 0;
97
98 //---------------------------------------------------------------
99 QString 
100 VISU::Vectors_i
101 ::GenerateName() 
102 {
103   return VISU::GenerateName("Vectors",myNbPresent++);
104 }
105
106 //---------------------------------------------------------------
107 const string VISU::Vectors_i::myComment = "VECTORS";
108
109 //---------------------------------------------------------------
110 const char* 
111 VISU::Vectors_i
112 ::GetComment() const
113 {
114   return myComment.c_str();
115 }
116
117
118 //---------------------------------------------------------------
119 const char*
120 VISU::Vectors_i
121 ::GetIconName()
122 {
123   if (!IsGroupsUsed())
124     return "ICON_TREE_VECTORS";
125   else
126     return "ICON_TREE_VECTORS_GROUPS";
127 }
128
129 //---------------------------------------------------------------
130 VISU::Vectors_i
131 ::Vectors_i(EPublishInStudyMode thePublishInStudyMode) :
132   ColoredPrs3d_i(thePublishInStudyMode),
133   ScalarMap_i(thePublishInStudyMode),
134   MonoColorPrs_i(thePublishInStudyMode),
135   DeformedShape_i(thePublishInStudyMode),
136   myLineWidth(1.0),
137   myVectorsPL(NULL)
138 {}
139
140
141 //---------------------------------------------------------------
142 void
143 VISU::Vectors_i
144 ::SameAs(const VISU::Prs3d_i* theOrigin)
145 {
146   TSuperClass::SameAs(theOrigin);
147
148   if(const Vectors_i* aPrs3d = dynamic_cast<const Vectors_i*>(theOrigin)){
149     Vectors_i* anOrigin = const_cast<Vectors_i*>(aPrs3d);
150     SetLineWidth(anOrigin->GetLineWidth());
151   }
152 }
153
154
155 //---------------------------------------------------------------
156 VISU::Storable* 
157 VISU::Vectors_i
158 ::Create(const std::string& theMeshName, 
159          VISU::Entity theEntity,
160          const std::string& theFieldName, 
161          CORBA::Long theTimeStampNumber)
162 {
163   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
164 }
165
166
167 //---------------------------------------------------------------
168 VISU::Storable* 
169 VISU::Vectors_i
170 ::Restore(SALOMEDS::SObject_ptr theSObject,
171           const Storable::TRestoringMap& theMap)
172 {
173   if(!TSuperClass::Restore(theSObject, theMap))
174     return NULL;
175
176   SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
177   SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
178   SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
179
180   return this;
181 }
182
183
184 //---------------------------------------------------------------
185 void 
186 VISU::Vectors_i
187 ::ToStream(std::ostringstream& theStr)
188 {
189   TSuperClass::ToStream(theStr);
190
191   Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
192   Storable::DataToStream( theStr, "myPosGlyph",  int(GetGlyphPos()));
193   Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
194 }
195
196
197 //---------------------------------------------------------------
198 VISU::Vectors_i
199 ::~Vectors_i()
200 {
201   if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
202 }
203
204
205 //---------------------------------------------------------------
206 void
207 VISU::Vectors_i
208 ::SetLineWidth(CORBA::Double theWidth) 
209
210   if(VISU::CheckIsSameValue(myLineWidth, theWidth))
211     return;
212
213   VISU::TSetModified aModified(this);
214
215   myLineWidth = theWidth;
216   myParamsTime.Modified();
217 }
218
219 //---------------------------------------------------------------
220 CORBA::Double
221 VISU::Vectors_i
222 ::GetLineWidth() 
223
224   return myLineWidth;
225 }
226
227
228 //---------------------------------------------------------------
229 void 
230 VISU::Vectors_i
231 ::SetGlyphType(VISU::Vectors::GlyphType theType) 
232
233   VISU::TSetModified aModified(this);
234
235   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphType>
236                    (GetSpecificPL(), &VISU_VectorsPL::SetGlyphType, VISU_VectorsPL::GlyphType(theType)));
237 }
238
239 //---------------------------------------------------------------
240 VISU::Vectors::GlyphType 
241 VISU::Vectors_i
242 ::GetGlyphType() 
243
244   return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
245 }
246
247
248 //---------------------------------------------------------------
249 void
250 VISU::Vectors_i
251 ::SetGlyphPos(VISU::Vectors::GlyphPos thePos) 
252
253   VISU::TSetModified aModified(this);
254
255   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphPos>
256                    (GetSpecificPL(), &VISU_VectorsPL::SetGlyphPos, VISU_VectorsPL::GlyphPos(thePos)));
257 }
258
259 //---------------------------------------------------------------
260 VISU::Vectors::GlyphPos 
261 VISU::Vectors_i::GetGlyphPos() 
262
263   return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
264 }
265
266
267 //---------------------------------------------------------------
268 void
269 VISU::Vectors_i
270 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
271 {
272   if(!thePipeLine){
273     myVectorsPL = VISU_VectorsPL::New();
274   }else
275     myVectorsPL = dynamic_cast<VISU_VectorsPL*>(thePipeLine);
276
277   TSuperClass::CreatePipeLine(myVectorsPL);
278 }
279
280
281 //---------------------------------------------------------------
282 VISU_PipeLine* 
283 VISU::Vectors_i
284 ::GetActorPipeLine()
285 {
286   VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
287   aPipeLine->ShallowCopy(GetPipeLine(), true);
288   return aPipeLine;
289 }
290
291
292 //---------------------------------------------------------------
293 bool
294 VISU::Vectors_i
295 ::CheckIsPossible() 
296 {
297   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
298 }
299
300 //---------------------------------------------------------------
301 VISU_Actor* 
302 VISU::Vectors_i
303 ::CreateActor()
304 {
305   VISU_VectorsAct* anActor = VISU_VectorsAct::New();
306   try{
307     VISU::Prs3d_i::CreateActor(anActor);
308     anActor->SetVTKMapping(true);
309     anActor->SetBarVisibility(true);
310     anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
311     anActor->GetProperty()->SetLineWidth(GetLineWidth());
312     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
313     int  aDispMode = aResourceMgr->integerValue("VISU", "vectors_represent", 1);
314     bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
315     anActor->SetRepresentation(aDispMode);
316     anActor->SetShading(toUseShading);
317     UpdateActor(anActor);
318   }catch(...){
319     anActor->Delete();
320     throw ;
321   }
322   return anActor;
323 }
324
325
326 //---------------------------------------------------------------
327 void 
328 VISU::Vectors_i
329 ::UpdateActor(VISU_ActorBase* theActor) 
330 {
331   if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
332     TSuperClass::UpdateActor(anActor);
333     anActor->GetProperty()->SetLineWidth(GetLineWidth());
334     if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
335       aVectorsPL->ShallowCopy(GetPipeLine(), true);
336       aVectorsPL->Update();
337       aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());
338     }
339   }
340 }