]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_StreamLines_i.cc
Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / VISU_I / VISU_StreamLines_i.cc
1 // Copyright (C) 2007-2013  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_PrsObject_i.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_StreamLines_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
31
32 #include "VISU_Actor.h"
33 #include "VISU_StreamLinesPL.hxx"
34 #include "VISU_Convertor.hxx"
35
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
38
39 #include <vtkDataSetMapper.h>
40 #include <vtkAppendFilter.h>
41 #include <vtkUnstructuredGrid.h>
42
43 #ifdef _DEBUG_
44 static int MYDEBUG = 0;
45 #else
46 static int MYDEBUG = 0;
47 #endif
48
49 using namespace std;
50
51 //---------------------------------------------------------------
52 size_t
53 VISU::StreamLines_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     if(!TSuperClass::IsPossible(theResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, false)) 
63       return 0;
64
65     VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
66                                                          theEntity,
67                                                          theFieldName,
68                                                          theTimeStampNumber);
69     VISU::PUnstructuredGridIDMapper anIDMapper = 
70       anInput->GetTimeStampOnMesh(theMeshName,
71                                   VISU::TEntity(theEntity),
72                                   theFieldName,
73                                   theTimeStampNumber);
74
75     vtkUnstructuredGrid* aDataSet = anIDMapper->GetUnstructuredGridOutput();
76     size_t aResult = VISU_StreamLinesPL::IsPossible(aDataSet);
77     MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
78     return aResult;
79   }catch(std::exception& exc){
80     INFOS("Follow exception was occured :\n"<<exc.what());
81   }catch(...){
82     INFOS("Unknown exception was occured!");
83   }
84   return 0;
85 }
86
87 //---------------------------------------------------------------
88 int VISU::StreamLines_i::myNbPresent = 0;
89
90 //---------------------------------------------------------------
91 QString
92 VISU::StreamLines_i
93 ::GenerateName() 
94 {
95   return VISU::GenerateName("StreamLines",myNbPresent++);
96 }
97
98 //---------------------------------------------------------------
99 const string VISU::StreamLines_i::myComment = "STREAMLINES";
100
101 //---------------------------------------------------------------
102 const char* 
103 VISU::StreamLines_i
104 ::GetComment() const 
105
106   return myComment.c_str();
107 }
108
109 //---------------------------------------------------------------
110 const char*
111 VISU::StreamLines_i
112 ::GetIconName()
113 {
114   if (!IsGroupsUsed())
115     return "ICON_TREE_STREAM_LINES";
116   else
117     return "ICON_TREE_STREAM_LINES_GROUPS";
118 }
119
120 //---------------------------------------------------------------
121 VISU::StreamLines_i
122 ::StreamLines_i(EPublishInStudyMode thePublishInStudyMode) :
123   ColoredPrs3d_i(thePublishInStudyMode),
124   ScalarMap_i(thePublishInStudyMode),
125   MonoColorPrs_i(thePublishInStudyMode),
126   myStreamLinesPL(NULL),
127   myAppendFilter(vtkAppendFilter::New())
128 {}
129
130
131 //---------------------------------------------------------------
132 void
133 VISU::StreamLines_i
134 ::SameAs(const Prs3d_i* theOrigin)
135 {
136   TSuperClass::SameAs(theOrigin);
137
138   if(const StreamLines_i* aPrs3d = dynamic_cast<const StreamLines_i*>(theOrigin)) {
139     StreamLines_i* anOrigin = const_cast<StreamLines_i*>(aPrs3d);
140     SetSource(anOrigin->GetSource());
141   }
142 }
143
144
145 //---------------------------------------------------------------
146 VISU::Storable* 
147 VISU::StreamLines_i
148 ::Create(const std::string& theMeshName, 
149          VISU::Entity theEntity,
150          const std::string& theFieldName, 
151          CORBA::Long theTimeStampNumber)
152 {
153   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
154 }
155
156
157 //---------------------------------------------------------------
158 VISU::Storable* 
159 VISU::StreamLines_i
160 ::Restore(SALOMEDS::SObject_ptr theSObject,
161           const Storable::TRestoringMap& theMap)
162 {
163   if(!TSuperClass::Restore(theSObject, theMap))
164     return NULL;
165
166   double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
167   double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
168   double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
169   int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
170   double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
171   SetParams(anIntegrationStep,
172             aPropagationTime,
173             aStepLength,
174             VISU::Prs3d::_nil(),
175             aPercents,
176             VISU::StreamLines::Direction(aDirection));
177   mySourceEntry = (const char*)VISU::Storable::FindValue(theMap,"mySourceEntry").toLatin1();
178
179   return this;
180 }
181
182
183 //---------------------------------------------------------------
184 void
185 VISU::StreamLines_i
186 ::ToStream(std::ostringstream& theStr)
187 {
188   TSuperClass::ToStream(theStr);
189
190   Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
191   Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
192   Storable::DataToStream( theStr, "myStepLength", GetStepLength());
193
194   Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
195   Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
196
197   Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
198 }
199
200
201 //---------------------------------------------------------------
202 VISU::StreamLines_i
203 ::~StreamLines_i()
204 {
205   if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
206   myAppendFilter->Delete();
207 }
208
209
210 //---------------------------------------------------------------
211 CORBA::Boolean
212 VISU::StreamLines_i
213 ::SetParams(CORBA::Double theIntStep,
214             CORBA::Double thePropogationTime,
215             CORBA::Double theStepLength,
216             VISU::Prs3d_ptr thePrs3d,
217             CORBA::Double thePercents,
218             VISU::StreamLines::Direction theDirection)
219 {
220   struct TEvent: public SALOME_Event 
221   {
222     CORBA::Double myIntStep;
223     CORBA::Double myPropogationTime;
224     CORBA::Double myStepLength;
225     VISU::Prs3d_ptr myPrs3d;
226     CORBA::Double myPercents;
227     VISU::StreamLines::Direction myDirection;
228     
229     VISU_StreamLinesPL* myPipeLine;
230     VISU::Prs3d_i*& myPrs3dServant;
231     vtkAppendFilter* myAppendFilter;
232     size_t& myIsAccepted;
233     
234     TEvent(CORBA::Double theIntStep,
235            CORBA::Double thePropogationTime,
236            CORBA::Double theStepLength,
237            VISU::Prs3d_ptr thePrs3d,
238            CORBA::Double thePercents,
239            VISU::StreamLines::Direction theDirection,
240            VISU_StreamLinesPL* thePipeLine,
241            VISU::Prs3d_i*& thePrs3dServant,
242            vtkAppendFilter* theAppendFilter,
243            size_t& theIsAccepted):
244       myIntStep(theIntStep),
245       myPropogationTime(thePropogationTime),
246       myStepLength(theStepLength),
247       myPrs3d(thePrs3d),
248       myPercents(thePercents),
249       myDirection(theDirection),
250       myPipeLine(thePipeLine),
251       myPrs3dServant(thePrs3dServant),
252       myAppendFilter(theAppendFilter),
253       myIsAccepted(theIsAccepted)
254     {}
255
256     virtual
257     void
258     Execute()
259     {
260       myPrs3dServant = NULL;
261       vtkPointSet* aSource = NULL;
262       if (!CORBA::is_nil(myPrs3d)){
263         myPrs3dServant = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(myPrs3d).in());
264         if(myPrs3dServant){
265           myAppendFilter->RemoveAllInputs();
266           myAppendFilter->AddInputData(myPrs3dServant->GetPipeLine()->GetMapper()->GetInput());
267           aSource = myAppendFilter->GetOutput();
268           myAppendFilter->Update();
269         }
270       }
271       myIsAccepted = myPipeLine->SetParams(myIntStep,
272                                            myPropogationTime,
273                                            myStepLength,
274                                            aSource,
275                                            myPercents,
276                                            myDirection);
277     }
278   };
279
280   size_t anIsAccepted = false;
281   VISU::Prs3d_i* aPrs3dServant = NULL;
282   ProcessVoidEvent(new TEvent(theIntStep,
283                               thePropogationTime,
284                               theStepLength,
285                               thePrs3d,
286                               thePercents,
287                               theDirection,
288                               GetSpecificPL(),
289                               aPrs3dServant,
290                               myAppendFilter,
291                               anIsAccepted));
292   if(anIsAccepted)
293     SetSource(aPrs3dServant);
294
295   return anIsAccepted;
296 }
297
298
299 //---------------------------------------------------------------
300 void
301 VISU::StreamLines_i
302 ::SetSource(VISU::Prs3d_ptr thePrs3d)
303 {
304   if(!thePrs3d->_is_nil()){
305     VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
306     SetSource(aPrs3di);
307   }
308 }
309
310 //---------------------------------------------------------------
311 void
312 VISU::StreamLines_i
313 ::SetSource(VISU::Prs3d_i* thePrs3d)
314 {
315   mySourceEntry = "";
316   if(!thePrs3d)
317     return;
318
319   SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
320   CORBA::String_var aString = aSObject->GetID();
321   if(mySourceEntry == aString.in())
322     return;
323   
324   VISU::TSetModified aModified(this);
325   
326   mySourceEntry = aString.in();
327   myParamsTime.Modified();
328 }
329
330 //---------------------------------------------------------------
331 void
332 VISU::StreamLines_i
333 ::SetSource()
334 {
335   if(!myStreamLinesPL->GetSource() && mySourceEntry == "") 
336     return;
337
338   if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput()) 
339     return;
340
341   VISU::Prs3d_var aPrs3d = GetSource();
342   SetParams(GetIntegrationStep(),
343             GetPropagationTime(),
344             GetStepLength(),
345             aPrs3d,
346             GetUsedPoints(),
347             GetDirection());
348 }
349
350
351 //---------------------------------------------------------------
352 CORBA::Double 
353 VISU::StreamLines_i
354 ::GetIntegrationStep() 
355
356   return myStreamLinesPL->GetIntegrationStep();
357 }
358
359 //---------------------------------------------------------------
360 CORBA::Double
361 VISU::StreamLines_i
362 ::GetPropagationTime() 
363
364   return myStreamLinesPL->GetPropagationTime();
365 }
366
367 //---------------------------------------------------------------
368 CORBA::Double
369 VISU::StreamLines_i
370 ::GetStepLength() 
371
372   return myStreamLinesPL->GetStepLength();
373 }
374
375 //---------------------------------------------------------------
376 VISU::StreamLines::Direction
377 VISU::StreamLines_i
378 ::GetDirection() 
379
380   return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
381 }
382
383
384 //---------------------------------------------------------------
385 VISU::Prs3d_ptr
386 VISU::StreamLines_i
387 ::GetSource()
388 {
389   VISU::Prs3d_var aPrs3d;
390   if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
391   if(mySourceEntry != ""){
392     SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(mySourceEntry.c_str());
393     CORBA::Object_var anObj = SObjectToObject(aSObject);
394     if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
395   }
396   return aPrs3d._retn();
397 }
398
399 //---------------------------------------------------------------
400 CORBA::Double 
401 VISU::StreamLines_i
402 ::GetUsedPoints() 
403
404   return myStreamLinesPL->GetUsedPoints();
405 }
406
407
408 //---------------------------------------------------------------
409 void 
410 VISU::StreamLines_i
411 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
412 {
413   if(!thePipeLine){
414     myStreamLinesPL = VISU_StreamLinesPL::New();
415   }else
416     myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(thePipeLine);
417
418   TSuperClass::CreatePipeLine(myStreamLinesPL);
419 }
420
421
422 //----------------------------------------------------------------------------
423 bool
424 VISU::StreamLines_i
425 ::CheckIsPossible() 
426 {
427   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
428 }
429
430 //---------------------------------------------------------------
431 void
432 VISU::StreamLines_i
433 ::Update() 
434 {
435   SetSource();
436   TSuperClass::Update();
437 }
438
439
440 //---------------------------------------------------------------
441 VISU_Actor* 
442 VISU::StreamLines_i
443 ::CreateActor() 
444 {
445   if(VISU_Actor* anActor = TSuperClass::CreateActor(true)){
446     anActor->SetVTKMapping(true);
447     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
448     int  aDispMode = aResourceMgr->integerValue("VISU", "stream_lines_represent", 1);
449     anActor->SetRepresentation(aDispMode);
450     return anActor;
451   }
452   return NULL;
453 }
454
455
456 //---------------------------------------------------------------
457 void
458 VISU::StreamLines_i
459 ::UpdateActor(VISU_Actor* theActor) 
460 {
461   TSuperClass::UpdateActor(theActor);
462 }