Salome HOME
Fix pb with Animation
[modules/visu.git] / src / VISU_I / VISU_StreamLines_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_PrsObject_i.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_StreamLinesPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_StreamLines_i.hh"
30 #include "VISU_Actor.h"
31
32 #include <vtkDataSetMapper.h>
33 #include <vtkAppendFilter.h>
34 #include <vtkUnstructuredGrid.h>
35
36 using namespace VISU;
37 using namespace std;
38
39 #ifdef _DEBUG_
40 static int MYDEBUG = 0;
41 #else
42 static int MYDEBUG = 0;
43 #endif
44
45 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
46                                     const char* theFieldName, int theIteration, int isMemoryCheck)
47 {
48   try{
49     if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false)) return 0;
50     VISU_Convertor::TOutput *anOutput = 
51       theResult->GetInput()->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration);
52     bool aResult = VISU_StreamLinesPL::IsPossible(anOutput);
53     MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
54     return aResult;
55   }catch(std::exception& exc){
56     INFOS("Follow exception was occured :\n"<<exc.what());
57   }catch(...){
58     INFOS("Unknown exception was occured!");
59   }
60   return 0;
61 }
62
63
64 int VISU::StreamLines_i::myNbPresent = 0;
65 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
66
67
68 const string VISU::StreamLines_i::myComment = "STREAMLINES";
69 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
70
71
72 VISU::StreamLines_i::
73 StreamLines_i(Result_i* theResult, 
74               bool theAddToStudy) :
75   PrsObject_i(theResult->GetStudyDocument()), 
76   Prs3d_i(theResult,theAddToStudy),
77   ScalarMap_i(theResult,theAddToStudy),
78   DeformedShape_i(theResult,theAddToStudy),
79   myStreamLinesPL(NULL),
80   myAppendFilter(vtkAppendFilter::New())
81 {
82 }
83
84
85 VISU::StreamLines_i::
86 StreamLines_i(Result_i* theResult, 
87               SALOMEDS::SObject_ptr theSObject) :
88   PrsObject_i(theResult->GetStudyDocument()), 
89   Prs3d_i(theResult,theSObject),
90   ScalarMap_i(theResult,theSObject),
91   DeformedShape_i(theResult,theSObject),
92   myStreamLinesPL(NULL),
93   myAppendFilter(vtkAppendFilter::New())
94 {
95 }
96
97
98 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
99   StreamLines_i* aStreamLines = const_cast<StreamLines_i*>(theOrigin);
100   VISU::DeformedShape_i::SameAs(theOrigin);
101   SetSource(aStreamLines->GetSource());
102 }
103
104
105 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity, 
106                                             const char* theFieldName, int theIteration)
107 {
108   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
109 }
110
111
112 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
113 {
114   DoHook();
115   VISU::Storable* aStorable = DeformedShape_i::Restore(theMap);
116
117   double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
118   double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
119   double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
120   int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
121   double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
122   SetParams(anIntegrationStep,
123             aPropagationTime,
124             aStepLength,
125             VISU::Prs3d::_nil(),
126             aPercents,
127             VISU::StreamLines::Direction(aDirection));
128   mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
129
130   return aStorable;
131 }
132
133
134 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
135   DeformedShape_i::ToStream(theStr);
136
137   Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
138   Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
139   Storable::DataToStream( theStr, "myStepLength", GetStepLength());
140
141   Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
142   Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
143
144   Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
145 }
146
147
148 VISU::StreamLines_i::~StreamLines_i(){
149   if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
150   myAppendFilter->UnRegisterAllOutputs();
151   myAppendFilter->Delete();
152 }
153
154
155 CORBA::Boolean 
156 VISU::StreamLines_i::SetParams(CORBA::Double theIntStep,
157                                CORBA::Double thePropogationTime,
158                                CORBA::Double theStepLength,
159                                VISU::Prs3d_ptr thePrs3d, 
160                                CORBA::Double thePercents,
161                                VISU::StreamLines::Direction theDirection) 
162
163   VISU::Prs3d_i* aPrs3di = NULL;
164   vtkPointSet* aSource = NULL;
165   if(!thePrs3d->_is_nil())
166     if((aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in()))){
167       for(int i = myAppendFilter->GetNumberOfInputs()-1; i >= 0; i--)
168         myAppendFilter->RemoveInput(myAppendFilter->GetInput(i));
169       myAppendFilter->AddInput(aPrs3di->GetPL()->GetMapper()->GetInput());
170       aSource = myAppendFilter->GetOutput();
171     }
172   int isAccepted = myStreamLinesPL->SetParams(theIntStep,
173                                               thePropogationTime,
174                                               theStepLength,
175                                               aSource,
176                                               thePercents,
177                                               theDirection,
178                                               1);
179   if(isAccepted == 1) SetSource(aPrs3di);
180   return isAccepted == 1;
181 }
182
183
184 void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){
185   if(!thePrs3d->_is_nil()){
186     VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
187     SetSource(aPrs3di);
188   }
189 }
190 void VISU::StreamLines_i::SetSource(VISU::Prs3d_i* thePrs3d){
191   mySourceEntry = "";
192   if(thePrs3d){
193     SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
194     CORBA::String_var aString = aSObject->GetID();
195     mySourceEntry = aString.in();
196   }
197 }
198 void VISU::StreamLines_i::SetSource(){
199   if(!myStreamLinesPL->GetSource() && mySourceEntry == "") return;
200   if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput()) return;
201   VISU::Prs3d_var aPrs3d = GetSource();
202   SetParams(GetIntegrationStep(),
203             GetPropagationTime(),
204             GetStepLength(),
205             aPrs3d,
206             GetUsedPoints(),
207             GetDirection());
208 }
209
210
211 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() { 
212   return myStreamLinesPL->GetIntegrationStep();
213 }
214
215 CORBA::Double VISU::StreamLines_i::GetPropagationTime() { 
216   return myStreamLinesPL->GetPropagationTime();
217 }
218
219 CORBA::Double VISU::StreamLines_i::GetStepLength() { 
220   return myStreamLinesPL->GetStepLength();
221 }
222
223 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() { 
224   return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
225 }
226
227
228 VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){
229   VISU::Prs3d_var aPrs3d;
230   if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
231   if(mySourceEntry != ""){
232     SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(mySourceEntry.c_str());
233     CORBA::Object_var anObj = SObjectToObject(aSObject);
234     if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
235   }
236   return aPrs3d._retn();
237 }
238
239 CORBA::Double VISU::StreamLines_i::GetUsedPoints() { 
240   return myStreamLinesPL->GetUsedPoints();
241 }
242
243
244 void VISU::StreamLines_i::DoHook(){
245   if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
246   myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
247
248   DeformedShape_i::DoHook();
249 }
250
251
252 void VISU::StreamLines_i::Update() {
253   SetSource();
254   VISU::DeformedShape_i::Update();
255 }
256
257
258 VISU_Actor* VISU::StreamLines_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
259 {
260   return VISU::DeformedShape_i::CreateActor(theIO);
261 }
262
263
264 void VISU::StreamLines_i::UpdateActor(VISU_Actor* theActor) {
265   VISU::DeformedShape_i::UpdateActor(theActor);
266 }