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