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