1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_PrsObject_i.cxx
25 // Author : Alexey PETROV
28 #include "VISU_StreamLines_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_Actor.h"
33 #include "VISU_StreamLinesPL.hxx"
34 #include "VISU_Convertor.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
39 #include <vtkDataSetMapper.h>
40 #include <vtkAppendFilter.h>
41 #include <vtkUnstructuredGrid.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
51 //---------------------------------------------------------------
54 ::IsPossible(Result_i* theResult,
55 const std::string& theMeshName,
56 VISU::Entity theEntity,
57 const std::string& theFieldName,
58 CORBA::Long theTimeStampNumber,
59 bool theIsMemoryCheck)
62 if(!TSuperClass::IsPossible(theResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, false))
65 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
69 VISU::PUnstructuredGridIDMapper anIDMapper =
70 anInput->GetTimeStampOnMesh(theMeshName,
71 VISU::TEntity(theEntity),
75 vtkUnstructuredGrid* aDataSet = anIDMapper->GetUnstructuredGridOutput();
76 size_t aResult = VISU_StreamLinesPL::IsPossible(aDataSet);
77 MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
79 }catch(std::exception& exc){
80 INFOS("Follow exception was occured :\n"<<exc.what());
82 INFOS("Unknown exception was occured!");
87 //---------------------------------------------------------------
88 int VISU::StreamLines_i::myNbPresent = 0;
90 //---------------------------------------------------------------
95 return VISU::GenerateName("StreamLines",myNbPresent++);
98 //---------------------------------------------------------------
99 const string VISU::StreamLines_i::myComment = "STREAMLINES";
101 //---------------------------------------------------------------
106 return myComment.c_str();
109 //---------------------------------------------------------------
115 return "ICON_TREE_STREAM_LINES";
117 return "ICON_TREE_STREAM_LINES_GROUPS";
120 //---------------------------------------------------------------
122 ::StreamLines_i(EPublishInStudyMode thePublishInStudyMode) :
123 ColoredPrs3d_i(thePublishInStudyMode),
124 ScalarMap_i(thePublishInStudyMode),
125 MonoColorPrs_i(thePublishInStudyMode),
126 myStreamLinesPL(NULL),
127 myAppendFilter(vtkAppendFilter::New())
131 //---------------------------------------------------------------
134 ::SameAs(const Prs3d_i* theOrigin)
136 TSuperClass::SameAs(theOrigin);
138 if(const StreamLines_i* aPrs3d = dynamic_cast<const StreamLines_i*>(theOrigin)) {
139 StreamLines_i* anOrigin = const_cast<StreamLines_i*>(aPrs3d);
140 SetSource(anOrigin->GetSource());
145 //---------------------------------------------------------------
148 ::Create(const std::string& theMeshName,
149 VISU::Entity theEntity,
150 const std::string& theFieldName,
151 CORBA::Long theTimeStampNumber)
153 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
157 //---------------------------------------------------------------
160 ::Restore(SALOMEDS::SObject_ptr theSObject,
161 const Storable::TRestoringMap& theMap)
163 if(!TSuperClass::Restore(theSObject, theMap))
166 double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
167 double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
168 double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
169 int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
170 double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
171 SetParams(anIntegrationStep,
176 VISU::StreamLines::Direction(aDirection));
177 mySourceEntry = (const char*)VISU::Storable::FindValue(theMap,"mySourceEntry").toLatin1();
183 //---------------------------------------------------------------
186 ::ToStream(std::ostringstream& theStr)
188 TSuperClass::ToStream(theStr);
190 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
191 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
192 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
194 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
195 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
197 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
201 //---------------------------------------------------------------
205 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
206 myAppendFilter->Delete();
210 //---------------------------------------------------------------
213 ::SetParams(CORBA::Double theIntStep,
214 CORBA::Double thePropogationTime,
215 CORBA::Double theStepLength,
216 VISU::Prs3d_ptr thePrs3d,
217 CORBA::Double thePercents,
218 VISU::StreamLines::Direction theDirection)
220 struct TEvent: public SALOME_Event
222 CORBA::Double myIntStep;
223 CORBA::Double myPropogationTime;
224 CORBA::Double myStepLength;
225 VISU::Prs3d_ptr myPrs3d;
226 CORBA::Double myPercents;
227 VISU::StreamLines::Direction myDirection;
229 VISU_StreamLinesPL* myPipeLine;
230 VISU::Prs3d_i*& myPrs3dServant;
231 vtkAppendFilter* myAppendFilter;
232 size_t& myIsAccepted;
234 TEvent(CORBA::Double theIntStep,
235 CORBA::Double thePropogationTime,
236 CORBA::Double theStepLength,
237 VISU::Prs3d_ptr thePrs3d,
238 CORBA::Double thePercents,
239 VISU::StreamLines::Direction theDirection,
240 VISU_StreamLinesPL* thePipeLine,
241 VISU::Prs3d_i*& thePrs3dServant,
242 vtkAppendFilter* theAppendFilter,
243 size_t& theIsAccepted):
244 myIntStep(theIntStep),
245 myPropogationTime(thePropogationTime),
246 myStepLength(theStepLength),
248 myPercents(thePercents),
249 myDirection(theDirection),
250 myPipeLine(thePipeLine),
251 myPrs3dServant(thePrs3dServant),
252 myAppendFilter(theAppendFilter),
253 myIsAccepted(theIsAccepted)
260 myPrs3dServant = NULL;
261 vtkPointSet* aSource = NULL;
262 if (!CORBA::is_nil(myPrs3d)){
263 myPrs3dServant = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(myPrs3d).in());
265 myAppendFilter->RemoveAllInputs();
266 myAppendFilter->AddInput(myPrs3dServant->GetPipeLine()->GetMapper()->GetInput());
267 aSource = myAppendFilter->GetOutput();
270 myIsAccepted = myPipeLine->SetParams(myIntStep,
279 size_t anIsAccepted = false;
280 VISU::Prs3d_i* aPrs3dServant = NULL;
281 ProcessVoidEvent(new TEvent(theIntStep,
292 SetSource(aPrs3dServant);
298 //---------------------------------------------------------------
301 ::SetSource(VISU::Prs3d_ptr thePrs3d)
303 if(!thePrs3d->_is_nil()){
304 VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
309 //---------------------------------------------------------------
312 ::SetSource(VISU::Prs3d_i* thePrs3d)
318 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
319 CORBA::String_var aString = aSObject->GetID();
320 if(mySourceEntry == aString.in())
323 VISU::TSetModified aModified(this);
325 mySourceEntry = aString.in();
326 myParamsTime.Modified();
329 //---------------------------------------------------------------
334 if(!myStreamLinesPL->GetSource() && mySourceEntry == "")
337 if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput())
340 VISU::Prs3d_var aPrs3d = GetSource();
341 SetParams(GetIntegrationStep(),
342 GetPropagationTime(),
350 //---------------------------------------------------------------
353 ::GetIntegrationStep()
355 return myStreamLinesPL->GetIntegrationStep();
358 //---------------------------------------------------------------
361 ::GetPropagationTime()
363 return myStreamLinesPL->GetPropagationTime();
366 //---------------------------------------------------------------
371 return myStreamLinesPL->GetStepLength();
374 //---------------------------------------------------------------
375 VISU::StreamLines::Direction
379 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
383 //---------------------------------------------------------------
388 VISU::Prs3d_var aPrs3d;
389 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
390 if(mySourceEntry != ""){
391 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(mySourceEntry.c_str());
392 CORBA::Object_var anObj = SObjectToObject(aSObject);
393 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
395 return aPrs3d._retn();
398 //---------------------------------------------------------------
403 return myStreamLinesPL->GetUsedPoints();
407 //---------------------------------------------------------------
410 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
413 myStreamLinesPL = VISU_StreamLinesPL::New();
415 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(thePipeLine);
417 TSuperClass::CreatePipeLine(myStreamLinesPL);
421 //----------------------------------------------------------------------------
426 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
429 //---------------------------------------------------------------
435 TSuperClass::Update();
439 //---------------------------------------------------------------
444 if(VISU_Actor* anActor = TSuperClass::CreateActor(true)){
445 anActor->SetVTKMapping(true);
446 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
447 int aDispMode = aResourceMgr->integerValue("VISU", "stream_lines_represent", 1);
448 anActor->SetRepresentation(aDispMode);
455 //---------------------------------------------------------------
458 ::UpdateActor(VISU_Actor* theActor)
460 TSuperClass::UpdateActor(theActor);