1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_StreamLines_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
31 #include "VISU_Actor.h"
32 #include "VISU_StreamLinesPL.hxx"
33 #include "VISU_Convertor.hxx"
35 #include "SUIT_ResourceMgr.h"
36 #include "SALOME_Event.hxx"
38 #include <vtkDataSetMapper.h>
39 #include <vtkAppendFilter.h>
40 #include <vtkUnstructuredGrid.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
49 //---------------------------------------------------------------
52 ::IsPossible(Result_i* theResult,
53 const std::string& theMeshName,
54 VISU::Entity theEntity,
55 const std::string& theFieldName,
56 CORBA::Long theTimeStampNumber,
57 bool theIsMemoryCheck)
60 if(!TSuperClass::IsPossible(theResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, false))
63 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
67 VISU::PUnstructuredGridIDMapper anIDMapper =
68 anInput->GetTimeStampOnMesh(theMeshName,
69 VISU::TEntity(theEntity),
73 vtkUnstructuredGrid* aDataSet = anIDMapper->GetUnstructuredGridOutput();
74 size_t aResult = VISU_StreamLinesPL::IsPossible(aDataSet);
75 MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
77 }catch(std::exception& exc){
78 INFOS("Follow exception was occured :\n"<<exc.what());
80 INFOS("Unknown exception was occured!");
85 //---------------------------------------------------------------
86 int VISU::StreamLines_i::myNbPresent = 0;
88 //---------------------------------------------------------------
93 return VISU::GenerateName("StreamLines",myNbPresent++);
96 //---------------------------------------------------------------
97 const string VISU::StreamLines_i::myComment = "STREAMLINES";
99 //---------------------------------------------------------------
104 return myComment.c_str();
107 //---------------------------------------------------------------
113 return "ICON_TREE_STREAM_LINES";
115 return "ICON_TREE_STREAM_LINES_GROUPS";
118 //---------------------------------------------------------------
120 ::StreamLines_i(EPublishInStudyMode thePublishInStudyMode) :
121 ColoredPrs3d_i(thePublishInStudyMode),
122 ScalarMap_i(thePublishInStudyMode),
123 DeformedShape_i(thePublishInStudyMode),
124 myStreamLinesPL(NULL),
125 myAppendFilter(vtkAppendFilter::New())
129 //---------------------------------------------------------------
132 ::SameAs(const Prs3d_i* theOrigin)
134 TSuperClass::SameAs(theOrigin);
136 if(const StreamLines_i* aPrs3d = dynamic_cast<const StreamLines_i*>(theOrigin)) {
137 StreamLines_i* anOrigin = const_cast<StreamLines_i*>(aPrs3d);
138 SetSource(anOrigin->GetSource());
143 //---------------------------------------------------------------
146 ::Create(const std::string& theMeshName,
147 VISU::Entity theEntity,
148 const std::string& theFieldName,
149 CORBA::Long theTimeStampNumber)
151 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
155 //---------------------------------------------------------------
158 ::Restore(SALOMEDS::SObject_ptr theSObject,
159 const Storable::TRestoringMap& theMap)
161 if(!TSuperClass::Restore(theSObject, theMap))
164 double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
165 double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
166 double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
167 int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
168 double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
169 SetParams(anIntegrationStep,
174 VISU::StreamLines::Direction(aDirection));
175 mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
181 //---------------------------------------------------------------
184 ::ToStream(std::ostringstream& theStr)
186 TSuperClass::ToStream(theStr);
188 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
189 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
190 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
192 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
193 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
195 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
199 //---------------------------------------------------------------
203 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
204 myAppendFilter->Delete();
208 //---------------------------------------------------------------
211 ::SetParams(CORBA::Double theIntStep,
212 CORBA::Double thePropogationTime,
213 CORBA::Double theStepLength,
214 VISU::Prs3d_ptr thePrs3d,
215 CORBA::Double thePercents,
216 VISU::StreamLines::Direction theDirection)
218 struct TEvent: public SALOME_Event
220 CORBA::Double myIntStep;
221 CORBA::Double myPropogationTime;
222 CORBA::Double myStepLength;
223 VISU::Prs3d_ptr myPrs3d;
224 CORBA::Double myPercents;
225 VISU::StreamLines::Direction myDirection;
227 VISU_StreamLinesPL* myPipeLine;
228 VISU::Prs3d_i*& myPrs3dServant;
229 vtkAppendFilter* myAppendFilter;
230 size_t& myIsAccepted;
232 TEvent(CORBA::Double theIntStep,
233 CORBA::Double thePropogationTime,
234 CORBA::Double theStepLength,
235 VISU::Prs3d_ptr thePrs3d,
236 CORBA::Double thePercents,
237 VISU::StreamLines::Direction theDirection,
238 VISU_StreamLinesPL* thePipeLine,
239 VISU::Prs3d_i*& thePrs3dServant,
240 vtkAppendFilter* theAppendFilter,
241 size_t& theIsAccepted):
242 myIntStep(theIntStep),
243 myPropogationTime(thePropogationTime),
244 myStepLength(theStepLength),
246 myPercents(thePercents),
247 myDirection(theDirection),
248 myPipeLine(thePipeLine),
249 myPrs3dServant(thePrs3dServant),
250 myAppendFilter(theAppendFilter),
251 myIsAccepted(theIsAccepted)
258 myPrs3dServant = NULL;
259 vtkPointSet* aSource = NULL;
260 if (!CORBA::is_nil(myPrs3d)){
261 myPrs3dServant = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(myPrs3d).in());
263 myAppendFilter->RemoveAllInputs();
264 myAppendFilter->AddInput(myPrs3dServant->GetPipeLine()->GetMapper()->GetInput());
265 aSource = myAppendFilter->GetOutput();
268 myIsAccepted = myPipeLine->SetParams(myIntStep,
277 size_t anIsAccepted = false;
278 VISU::Prs3d_i* aPrs3dServant = NULL;
279 ProcessVoidEvent(new TEvent(theIntStep,
290 SetSource(aPrs3dServant);
296 //---------------------------------------------------------------
299 ::SetSource(VISU::Prs3d_ptr thePrs3d)
301 if(!thePrs3d->_is_nil()){
302 VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
307 //---------------------------------------------------------------
310 ::SetSource(VISU::Prs3d_i* thePrs3d)
316 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
317 CORBA::String_var aString = aSObject->GetID();
318 if(mySourceEntry == aString.in())
321 VISU::TSetModified aModified(this);
323 mySourceEntry = aString.in();
324 myParamsTime.Modified();
327 //---------------------------------------------------------------
332 if(!myStreamLinesPL->GetSource() && mySourceEntry == "")
335 if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput())
338 VISU::Prs3d_var aPrs3d = GetSource();
339 SetParams(GetIntegrationStep(),
340 GetPropagationTime(),
348 //---------------------------------------------------------------
351 ::GetIntegrationStep()
353 return myStreamLinesPL->GetIntegrationStep();
356 //---------------------------------------------------------------
359 ::GetPropagationTime()
361 return myStreamLinesPL->GetPropagationTime();
364 //---------------------------------------------------------------
369 return myStreamLinesPL->GetStepLength();
372 //---------------------------------------------------------------
373 VISU::StreamLines::Direction
377 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
381 //---------------------------------------------------------------
386 VISU::Prs3d_var aPrs3d;
387 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
388 if(mySourceEntry != ""){
389 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(mySourceEntry.c_str());
390 CORBA::Object_var anObj = SObjectToObject(aSObject);
391 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
393 return aPrs3d._retn();
396 //---------------------------------------------------------------
401 return myStreamLinesPL->GetUsedPoints();
405 //---------------------------------------------------------------
408 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
411 myStreamLinesPL = VISU_StreamLinesPL::New();
413 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(thePipeLine);
415 TSuperClass::CreatePipeLine(myStreamLinesPL);
419 //----------------------------------------------------------------------------
424 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
427 //---------------------------------------------------------------
433 TSuperClass::Update();
437 //---------------------------------------------------------------
442 if(VISU_Actor* anActor = TSuperClass::CreateActor(true)){
443 anActor->SetVTKMapping(true);
444 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
445 int aDispMode = aResourceMgr->integerValue("VISU", "stream_lines_represent", 1);
446 anActor->SetRepresentation(aDispMode);
453 //---------------------------------------------------------------
456 ::UpdateActor(VISU_Actor* theActor)
458 TSuperClass::UpdateActor(theActor);