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_Result_i.hh"
30 #include "VISU_Actor.h"
31 #include "VISU_StreamLinesPL.hxx"
32 #include "VISU_Convertor.hxx"
34 #include "SUIT_ResourceMgr.h"
36 #include <vtkDataSetMapper.h>
37 #include <vtkAppendFilter.h>
38 #include <vtkUnstructuredGrid.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
50 const char* theFieldName, int theIteration, int isMemoryCheck)
53 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false))
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);
62 }catch(std::exception& exc){
63 INFOS("Follow exception was occured :\n"<<exc.what());
65 INFOS("Unknown exception was occured!");
71 int VISU::StreamLines_i::myNbPresent = 0;
72 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
75 const string VISU::StreamLines_i::myComment = "STREAMLINES";
76 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
80 StreamLines_i(Result_i* theResult,
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())
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())
107 void VISU::StreamLines_i::SameAs(const Prs3d_i* theOrigin)
109 TSuperClass::SameAs(theOrigin);
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());
118 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
119 const char* theFieldName, int theIteration)
121 return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
125 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
127 TSuperClass::Restore(theMap);
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,
139 VISU::StreamLines::Direction(aDirection));
140 mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
146 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
147 DeformedShape_i::ToStream(theStr);
149 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
150 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
151 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
153 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
154 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
156 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
160 VISU::StreamLines_i::~StreamLines_i(){
161 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
162 myAppendFilter->UnRegisterAllOutputs();
163 myAppendFilter->Delete();
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)
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();
184 int isAccepted = myStreamLinesPL->SetParams(theIntStep,
191 if(isAccepted == 1) SetSource(aPrs3di);
192 return isAccepted == 1;
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());
202 void VISU::StreamLines_i::SetSource(VISU::Prs3d_i* thePrs3d){
205 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
206 CORBA::String_var aString = aSObject->GetID();
207 mySourceEntry = aString.in();
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(),
223 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() {
224 return myStreamLinesPL->GetIntegrationStep();
227 CORBA::Double VISU::StreamLines_i::GetPropagationTime() {
228 return myStreamLinesPL->GetPropagationTime();
231 CORBA::Double VISU::StreamLines_i::GetStepLength() {
232 return myStreamLinesPL->GetStepLength();
235 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() {
236 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
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);
248 return aPrs3d._retn();
251 CORBA::Double VISU::StreamLines_i::GetUsedPoints() {
252 return myStreamLinesPL->GetUsedPoints();
256 void VISU::StreamLines_i::DoHook(){
257 if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
258 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
260 DeformedShape_i::DoHook();
264 void VISU::StreamLines_i::Update() {
266 VISU::DeformedShape_i::Update();
272 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
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);
285 void VISU::StreamLines_i::UpdateActor(VISU_Actor* theActor) {
286 VISU::DeformedShape_i::UpdateActor(theActor);