1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
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.h"
38 #include <vtkDataSetMapper.h>
39 #include <vtkAppendFilter.h>
40 #include <vtkUnstructuredGrid.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
50 //---------------------------------------------------------------
53 ::IsPossible(Result_i* theResult,
54 const std::string& theMeshName,
55 VISU::Entity theEntity,
56 const std::string& theFieldName,
57 CORBA::Long theTimeStampNumber,
58 bool theIsMemoryCheck)
61 if(!TSuperClass::IsPossible(theResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, false))
64 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
68 VISU::PUnstructuredGridIDMapper anIDMapper =
69 anInput->GetTimeStampOnMesh(theMeshName,
70 VISU::TEntity(theEntity),
74 vtkUnstructuredGrid* aDataSet = anIDMapper->GetUnstructuredGridOutput();
75 size_t aResult = VISU_StreamLinesPL::IsPossible(aDataSet);
76 MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
78 }catch(std::exception& exc){
79 INFOS("Follow exception was occured :\n"<<exc.what());
81 INFOS("Unknown exception was occured!");
86 //---------------------------------------------------------------
87 int VISU::StreamLines_i::myNbPresent = 0;
89 //---------------------------------------------------------------
94 return VISU::GenerateName("StreamLines",myNbPresent++);
97 //---------------------------------------------------------------
98 const string VISU::StreamLines_i::myComment = "STREAMLINES";
100 //---------------------------------------------------------------
105 return myComment.c_str();
108 //---------------------------------------------------------------
114 return "ICON_TREE_STREAM_LINES";
116 return "ICON_TREE_STREAM_LINES_GROUPS";
119 //---------------------------------------------------------------
121 ::StreamLines_i(EPublishInStudyMode thePublishInStudyMode) :
122 ColoredPrs3d_i(thePublishInStudyMode),
123 ScalarMap_i(thePublishInStudyMode),
124 MonoColorPrs_i(thePublishInStudyMode),
125 myStreamLinesPL(NULL),
126 myAppendFilter(vtkAppendFilter::New())
130 //---------------------------------------------------------------
133 ::SameAs(const Prs3d_i* theOrigin)
135 TSuperClass::SameAs(theOrigin);
137 if(const StreamLines_i* aPrs3d = dynamic_cast<const StreamLines_i*>(theOrigin)) {
138 StreamLines_i* anOrigin = const_cast<StreamLines_i*>(aPrs3d);
139 SetSource(anOrigin->GetSource());
144 //---------------------------------------------------------------
147 ::Create(const std::string& theMeshName,
148 VISU::Entity theEntity,
149 const std::string& theFieldName,
150 CORBA::Long theTimeStampNumber)
152 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
156 //---------------------------------------------------------------
159 ::Restore(SALOMEDS::SObject_ptr theSObject,
160 const Storable::TRestoringMap& theMap)
162 if(!TSuperClass::Restore(theSObject, theMap))
165 double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
166 double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
167 double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
168 int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
169 double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
170 SetParams(anIntegrationStep,
175 VISU::StreamLines::Direction(aDirection));
176 mySourceEntry = (const char*)VISU::Storable::FindValue(theMap,"mySourceEntry").toLatin1();
182 //---------------------------------------------------------------
185 ::ToStream(std::ostringstream& theStr)
187 TSuperClass::ToStream(theStr);
189 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
190 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
191 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
193 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
194 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
196 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
200 //---------------------------------------------------------------
204 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
205 myAppendFilter->Delete();
209 //---------------------------------------------------------------
212 ::SetParams(CORBA::Double theIntStep,
213 CORBA::Double thePropogationTime,
214 CORBA::Double theStepLength,
215 VISU::Prs3d_ptr thePrs3d,
216 CORBA::Double thePercents,
217 VISU::StreamLines::Direction theDirection)
219 struct TEvent: public SALOME_Event
221 CORBA::Double myIntStep;
222 CORBA::Double myPropogationTime;
223 CORBA::Double myStepLength;
224 VISU::Prs3d_ptr myPrs3d;
225 CORBA::Double myPercents;
226 VISU::StreamLines::Direction myDirection;
228 VISU_StreamLinesPL* myPipeLine;
229 VISU::Prs3d_i*& myPrs3dServant;
230 vtkAppendFilter* myAppendFilter;
231 size_t& myIsAccepted;
233 TEvent(CORBA::Double theIntStep,
234 CORBA::Double thePropogationTime,
235 CORBA::Double theStepLength,
236 VISU::Prs3d_ptr thePrs3d,
237 CORBA::Double thePercents,
238 VISU::StreamLines::Direction theDirection,
239 VISU_StreamLinesPL* thePipeLine,
240 VISU::Prs3d_i*& thePrs3dServant,
241 vtkAppendFilter* theAppendFilter,
242 size_t& theIsAccepted):
243 myIntStep(theIntStep),
244 myPropogationTime(thePropogationTime),
245 myStepLength(theStepLength),
247 myPercents(thePercents),
248 myDirection(theDirection),
249 myPipeLine(thePipeLine),
250 myPrs3dServant(thePrs3dServant),
251 myAppendFilter(theAppendFilter),
252 myIsAccepted(theIsAccepted)
259 myPrs3dServant = NULL;
260 vtkPointSet* aSource = NULL;
261 if (!CORBA::is_nil(myPrs3d)){
262 myPrs3dServant = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(myPrs3d).in());
264 myAppendFilter->RemoveAllInputs();
265 myAppendFilter->AddInput(myPrs3dServant->GetPipeLine()->GetMapper()->GetInput());
266 aSource = myAppendFilter->GetOutput();
269 myIsAccepted = myPipeLine->SetParams(myIntStep,
278 size_t anIsAccepted = false;
279 VISU::Prs3d_i* aPrs3dServant = NULL;
280 ProcessVoidEvent(new TEvent(theIntStep,
291 SetSource(aPrs3dServant);
297 //---------------------------------------------------------------
300 ::SetSource(VISU::Prs3d_ptr thePrs3d)
302 if(!thePrs3d->_is_nil()){
303 VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
308 //---------------------------------------------------------------
311 ::SetSource(VISU::Prs3d_i* thePrs3d)
317 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
318 CORBA::String_var aString = aSObject->GetID();
319 if(mySourceEntry == aString.in())
322 VISU::TSetModified aModified(this);
324 mySourceEntry = aString.in();
325 myParamsTime.Modified();
328 //---------------------------------------------------------------
333 if(!myStreamLinesPL->GetSource() && mySourceEntry == "")
336 if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput())
339 VISU::Prs3d_var aPrs3d = GetSource();
340 SetParams(GetIntegrationStep(),
341 GetPropagationTime(),
349 //---------------------------------------------------------------
352 ::GetIntegrationStep()
354 return myStreamLinesPL->GetIntegrationStep();
357 //---------------------------------------------------------------
360 ::GetPropagationTime()
362 return myStreamLinesPL->GetPropagationTime();
365 //---------------------------------------------------------------
370 return myStreamLinesPL->GetStepLength();
373 //---------------------------------------------------------------
374 VISU::StreamLines::Direction
378 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
382 //---------------------------------------------------------------
387 VISU::Prs3d_var aPrs3d;
388 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
389 if(mySourceEntry != ""){
390 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(mySourceEntry.c_str());
391 CORBA::Object_var anObj = SObjectToObject(aSObject);
392 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
394 return aPrs3d._retn();
397 //---------------------------------------------------------------
402 return myStreamLinesPL->GetUsedPoints();
406 //---------------------------------------------------------------
409 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
412 myStreamLinesPL = VISU_StreamLinesPL::New();
414 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(thePipeLine);
416 TSuperClass::CreatePipeLine(myStreamLinesPL);
420 //----------------------------------------------------------------------------
425 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
428 //---------------------------------------------------------------
434 TSuperClass::Update();
438 //---------------------------------------------------------------
443 if(VISU_Actor* anActor = TSuperClass::CreateActor(true)){
444 anActor->SetVTKMapping(true);
445 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
446 int aDispMode = aResourceMgr->integerValue("VISU", "stream_lines_represent", 1);
447 anActor->SetRepresentation(aDispMode);
454 //---------------------------------------------------------------
457 ::UpdateActor(VISU_Actor* theActor)
459 TSuperClass::UpdateActor(theActor);