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