]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_StreamLines_i.cc
Salome HOME
sources v1.2c
[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 static int INCMEMORY = 2;
46
47 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
48                                     const char* theFieldName, int theIteration)
49 {
50   try{
51     vtkIdType aSize = 
52       (VISU_StreamLinesPL::myMaxIncrementMemorySize+INCMEMORY)*
53       theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
54     if(MYDEBUG) MESSAGE("StreamLines_i::IsPossible - CheckAvailableMemory = "<<aSize);
55     if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
56     return false;
57   }catch(std::runtime_error& exc){
58     INFOS("Follow exception was accured :\n"<<exc.what());
59   }catch(...){
60     INFOS("Unknown exception was accured!");
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) :
75        PrsObject_i(theResult->GetStudyDocument()), 
76        Prs3d_i(theResult),       
77        ScalarMap_i(theResult, theAddToStudy),
78        DeformedShape_i(theResult, theAddToStudy)
79 {
80   myStreamLinesPL = NULL;
81 }
82
83 void VISU::StreamLines_i::Destroy(){
84   DeformedShape_i::Destroy();
85 }
86
87
88 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
89   StreamLines_i* aStreamLines = const_cast<StreamLines_i*>(theOrigin);
90   VISU::DeformedShape_i::SameAs(theOrigin);
91
92   //Order of setting of the values are important 
93   //SetIntegrationStep(aStreamLines->GetIntegrationStep());
94   //SetPropagationTime(aStreamLines->GetPropagationTime());
95   //SetStepLength(aStreamLines->GetStepLength());
96
97   //SetUsedPoints(aStreamLines->GetUsedPoints());
98   //SetDirection(aStreamLines->GetDirection());
99
100   SetSource(aStreamLines->GetSource());
101 }
102
103
104 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity, 
105                                             const char* theFieldName, int theIteration)
106 {
107   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
108 }
109
110
111 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
112   throw(std::logic_error&)
113 {
114   DeformedShape_i::Restore(theMap);
115
116   //Order of setting of the values are important 
117   SetIntegrationStep(VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble());
118   SetPropagationTime(VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble());
119   SetStepLength(VISU::Storable::FindValue(theMap,"myStepLength").toDouble());
120
121   SetDirection(VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt()));
122   SetUsedPoints(VISU::Storable::FindValue(theMap,"myPercents").toDouble());
123   mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
124
125   return Build(true);
126 }
127
128
129 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
130   DeformedShape_i::ToStream(theStr);
131
132   Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
133   Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
134   Storable::DataToStream( theStr, "myStepLength", GetStepLength());
135
136   Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
137   Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
138
139   Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
140 }
141
142
143 VISU::Storable* VISU::StreamLines_i::Restore(SALOMEDS::SObject_ptr theSObject, 
144                                              const string& thePrefix, const Storable::TRestoringMap& theMap)
145   throw(std::logic_error&)
146 {
147   VISU::Result_i* pResult = GetResult(theSObject);
148   if(pResult != NULL){
149     VISU::StreamLines_i* pResent = new VISU::StreamLines_i(pResult);
150     return pResent->Restore(theMap);
151   }
152   return NULL;
153 }
154
155
156 VISU::StreamLines_i::~StreamLines_i(){
157   if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
158 }
159
160
161 void VISU::StreamLines_i::SetDirection(VISU::StreamLines::Direction theDirection) { 
162   myStreamLinesPL->SetDirection(theDirection);
163 }
164 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() { 
165   return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
166 }
167
168
169 void VISU::StreamLines_i::SetStepLength(CORBA::Double theStep) { 
170   myStreamLinesPL->SetStepLength(theStep);
171 }
172 CORBA::Double VISU::StreamLines_i::GetStepLength() { 
173   return myStreamLinesPL->GetStepLength();
174 }
175
176
177 void VISU::StreamLines_i::SetPropagationTime(CORBA::Double theTime) { 
178   myStreamLinesPL->SetPropagationTime(theTime);
179 }
180 CORBA::Double VISU::StreamLines_i::GetPropagationTime() { 
181   return myStreamLinesPL->GetPropagationTime();
182 }
183
184
185 void VISU::StreamLines_i::SetIntegrationStep(CORBA::Double theStep) { 
186   myStreamLinesPL->SetIntegrationStep(theStep);
187 }
188 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() { 
189   return myStreamLinesPL->GetIntegrationStep();
190 }
191
192
193 void VISU::StreamLines_i::SetUsedPoints(CORBA::Double thePercents) { 
194   myStreamLinesPL->SetUsedPoints(thePercents);
195 }
196 CORBA::Double VISU::StreamLines_i::GetUsedPoints() { 
197   return myStreamLinesPL->GetUsedPoints();
198 }
199
200
201 void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){
202   if(!thePrs3d->_is_nil())
203     if(VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d))){
204       CORBA::String_var aString = thePrs3d->GetID();
205       SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(aString);
206       if(!CORBA::is_nil(aSObject)){
207         vtkAppendFilter* anAppendFilter = vtkAppendFilter::New();
208         anAppendFilter->AddInput(aPrs3di->GetPipeLine()->GetMapper()->GetInput());
209         myStreamLinesPL->SetSource(anAppendFilter->GetOutput());
210         anAppendFilter->Register(myStreamLinesPL);
211         anAppendFilter->Delete();
212         aString = aSObject->GetID();
213         mySourceEntry = aString.in();
214         return;
215       }
216     }
217   myStreamLinesPL->SetSource(NULL);
218   mySourceEntry = "";
219 }
220 VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){
221   VISU::Prs3d_var aPrs3d;
222   if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
223   if(mySourceEntry != ""){
224     SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(mySourceEntry.c_str());
225     CORBA::Object_var anObj = SObjectToObject(aSObject);
226     if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
227   }
228   return aPrs3d._retn();
229 }
230
231
232 float VISU::StreamLines_i::GetMaxIntegrationStep(){
233   return myStreamLinesPL->GetMaxIntegrationStep();
234 }
235
236
237 float VISU::StreamLines_i::GetMinIntegrationStep(){
238   return myStreamLinesPL->GetMinIntegrationStep();
239 }
240
241
242 float VISU::StreamLines_i::GetBasePropagationTime(){
243   return myStreamLinesPL->GetBasePropagationTime();
244 }
245
246
247 void VISU::StreamLines_i::DoHook(){
248   if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
249   myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
250
251   DeformedShape_i::DoHook();
252 }