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