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