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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 <vtkDataSetMapper.h>
35 #include <vtkAppendFilter.h>
36 #include <vtkUnstructuredGrid.h>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
48 const char* theFieldName, int theIteration, int isMemoryCheck)
51 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false))
54 VISU::PIDMapper anIDMapper =
55 theResult->GetInput()->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration);
56 VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput();
57 bool aResult = VISU_StreamLinesPL::IsPossible(aDataSet);
58 MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
60 }catch(std::exception& exc){
61 INFOS("Follow exception was occured :\n"<<exc.what());
63 INFOS("Unknown exception was occured!");
69 int VISU::StreamLines_i::myNbPresent = 0;
70 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
73 const string VISU::StreamLines_i::myComment = "STREAMLINES";
74 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
78 StreamLines_i(Result_i* theResult,
80 PrsObject_i(theResult->GetStudyDocument()),
81 Prs3d_i(theResult,theAddToStudy),
82 ColoredPrs3d_i(theResult,theAddToStudy),
83 ScalarMap_i(theResult,theAddToStudy),
84 DeformedShape_i(theResult,theAddToStudy),
85 myStreamLinesPL(NULL),
86 myAppendFilter(vtkAppendFilter::New())
92 StreamLines_i(Result_i* theResult,
93 SALOMEDS::SObject_ptr theSObject) :
94 PrsObject_i(theResult->GetStudyDocument()),
95 Prs3d_i(theResult,theSObject),
96 ColoredPrs3d_i(theResult,theSObject),
97 ScalarMap_i(theResult,theSObject),
98 DeformedShape_i(theResult,theSObject),
99 myStreamLinesPL(NULL),
100 myAppendFilter(vtkAppendFilter::New())
105 void VISU::StreamLines_i::SameAs(const Prs3d_i* theOrigin)
107 TSuperClass::SameAs(theOrigin);
109 if(const StreamLines_i* aPrs3d = dynamic_cast<const StreamLines_i*>(theOrigin)) {
110 StreamLines_i* anOrigin = const_cast<StreamLines_i*>(aPrs3d);
111 SetSource(anOrigin->GetSource());
116 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
117 const char* theFieldName, int theIteration)
119 return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
123 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
125 TSuperClass::Restore(theMap);
127 double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
128 double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
129 double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
130 int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
131 double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
132 SetParams(anIntegrationStep,
137 VISU::StreamLines::Direction(aDirection));
138 mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
144 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
145 DeformedShape_i::ToStream(theStr);
147 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
148 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
149 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
151 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
152 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
154 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
158 VISU::StreamLines_i::~StreamLines_i(){
159 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
160 myAppendFilter->UnRegisterAllOutputs();
161 myAppendFilter->Delete();
166 VISU::StreamLines_i::SetParams(CORBA::Double theIntStep,
167 CORBA::Double thePropogationTime,
168 CORBA::Double theStepLength,
169 VISU::Prs3d_ptr thePrs3d,
170 CORBA::Double thePercents,
171 VISU::StreamLines::Direction theDirection)
173 VISU::Prs3d_i* aPrs3di = NULL;
174 vtkPointSet* aSource = NULL;
175 if(!thePrs3d->_is_nil())
176 if((aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in()))){
177 for(int i = myAppendFilter->GetNumberOfInputs()-1; i >= 0; i--)
178 myAppendFilter->RemoveInput(myAppendFilter->GetInput(i));
179 myAppendFilter->AddInput(aPrs3di->GetPL()->GetMapper()->GetInput());
180 aSource = myAppendFilter->GetOutput();
182 int isAccepted = myStreamLinesPL->SetParams(theIntStep,
189 if(isAccepted == 1) SetSource(aPrs3di);
190 return isAccepted == 1;
194 void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){
195 if(!thePrs3d->_is_nil()){
196 VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
200 void VISU::StreamLines_i::SetSource(VISU::Prs3d_i* thePrs3d){
203 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
204 CORBA::String_var aString = aSObject->GetID();
205 mySourceEntry = aString.in();
208 void VISU::StreamLines_i::SetSource(){
209 if(!myStreamLinesPL->GetSource() && mySourceEntry == "") return;
210 if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput()) return;
211 VISU::Prs3d_var aPrs3d = GetSource();
212 SetParams(GetIntegrationStep(),
213 GetPropagationTime(),
221 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() {
222 return myStreamLinesPL->GetIntegrationStep();
225 CORBA::Double VISU::StreamLines_i::GetPropagationTime() {
226 return myStreamLinesPL->GetPropagationTime();
229 CORBA::Double VISU::StreamLines_i::GetStepLength() {
230 return myStreamLinesPL->GetStepLength();
233 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() {
234 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
238 VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){
239 VISU::Prs3d_var aPrs3d;
240 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
241 if(mySourceEntry != ""){
242 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(mySourceEntry.c_str());
243 CORBA::Object_var anObj = SObjectToObject(aSObject);
244 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
246 return aPrs3d._retn();
249 CORBA::Double VISU::StreamLines_i::GetUsedPoints() {
250 return myStreamLinesPL->GetUsedPoints();
254 void VISU::StreamLines_i::DoHook(){
255 if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
256 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
258 DeformedShape_i::DoHook();
262 void VISU::StreamLines_i::Update() {
264 VISU::DeformedShape_i::Update();
270 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
272 if(VISU_Actor* anActor = VISU::DeformedShape_i::CreateActor(theIO)){
273 anActor->SetVTKMapping(true);
280 void VISU::StreamLines_i::UpdateActor(VISU_Actor* theActor) {
281 VISU::DeformedShape_i::UpdateActor(theActor);