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