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_StreamLinesPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_StreamLines_i.hh"
30 #include "VISU_Actor.h"
32 #include <vtkDataSetMapper.h>
33 #include <vtkAppendFilter.h>
34 #include <vtkUnstructuredGrid.h>
40 static int MYDEBUG = 0;
41 static int MYDEBUGWITHFILES = 0;
43 static int MYDEBUG = 0;
44 static int MYDEBUGWITHFILES = 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)) return 0;
52 VISU_Convertor::TOutput *anOutput =
53 theResult->GetInput()->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration);
54 bool aResult = VISU_StreamLinesPL::IsPossible(anOutput);
55 MESSAGE("StreamLines_i::IsPossible - aResult = "<<aResult);
57 }catch(std::exception& exc){
58 INFOS("Follow exception was occured :\n"<<exc.what());
60 INFOS("Unknown exception was occured!");
66 int VISU::StreamLines_i::myNbPresent = 0;
67 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
70 const string VISU::StreamLines_i::myComment = "STREAMLINES";
71 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
74 VISU::StreamLines_i::StreamLines_i(Result_i* theResult, bool theAddToStudy, SALOMEDS::SObject_ptr theSObject) :
75 PrsObject_i(theResult->GetStudyDocument()),
76 Prs3d_i(theResult,theSObject),
77 ScalarMap_i(theResult,theAddToStudy,theSObject),
78 DeformedShape_i(theResult,theAddToStudy,theSObject)
80 myStreamLinesPL = NULL;
81 myAppendFilter = vtkAppendFilter::New();
84 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
85 StreamLines_i* aStreamLines = const_cast<StreamLines_i*>(theOrigin);
86 VISU::DeformedShape_i::SameAs(theOrigin);
87 SetSource(aStreamLines->GetSource());
91 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
92 const char* theFieldName, int theIteration)
94 return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
98 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
101 VISU::Storable* aStorable = DeformedShape_i::Restore(theMap);
103 double anIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
104 double aPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
105 double aStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
106 int aDirection = VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt());
107 double aPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble();
108 SetParams(anIntegrationStep,
113 VISU::StreamLines::Direction(aDirection));
114 mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
120 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
121 DeformedShape_i::ToStream(theStr);
123 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
124 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
125 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
127 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
128 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
130 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
134 VISU::StreamLines_i::~StreamLines_i(){
135 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
136 myAppendFilter->UnRegisterAllOutputs();
137 myAppendFilter->Delete();
142 VISU::StreamLines_i::SetParams(CORBA::Double theIntStep,
143 CORBA::Double thePropogationTime,
144 CORBA::Double theStepLength,
145 VISU::Prs3d_ptr thePrs3d,
146 CORBA::Double thePercents,
147 VISU::StreamLines::Direction theDirection)
149 VISU::Prs3d_i* aPrs3di = NULL;
150 vtkPointSet* aSource = NULL;
151 if(!thePrs3d->_is_nil())
152 if((aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in()))){
153 for(int i = myAppendFilter->GetNumberOfInputs()-1; i >= 0; i--)
154 myAppendFilter->RemoveInput(myAppendFilter->GetInput(i));
155 myAppendFilter->AddInput(aPrs3di->GetPL()->GetMapper()->GetInput());
156 aSource = myAppendFilter->GetOutput();
158 int isAccepted = myStreamLinesPL->SetParams(theIntStep,
165 if(isAccepted == 1) SetSource(aPrs3di);
166 return isAccepted == 1;
170 void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){
171 if(!thePrs3d->_is_nil()){
172 VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d).in());
176 void VISU::StreamLines_i::SetSource(VISU::Prs3d_i* thePrs3d){
179 SALOMEDS::SObject_var aSObject = thePrs3d->GetSObject();
180 CORBA::String_var aString = aSObject->GetID();
181 mySourceEntry = aString.in();
184 void VISU::StreamLines_i::SetSource(){
185 if(!myStreamLinesPL->GetSource() && mySourceEntry == "") return;
186 if(myStreamLinesPL->GetSource() == myAppendFilter->GetOutput()) return;
187 VISU::Prs3d_var aPrs3d = GetSource();
188 SetParams(GetIntegrationStep(),
189 GetPropagationTime(),
197 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() {
198 return myStreamLinesPL->GetIntegrationStep();
201 CORBA::Double VISU::StreamLines_i::GetPropagationTime() {
202 return myStreamLinesPL->GetPropagationTime();
205 CORBA::Double VISU::StreamLines_i::GetStepLength() {
206 return myStreamLinesPL->GetStepLength();
209 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() {
210 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
214 VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){
215 VISU::Prs3d_var aPrs3d;
216 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
217 if(mySourceEntry != ""){
218 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(mySourceEntry.c_str());
219 CORBA::Object_var anObj = SObjectToObject(aSObject);
220 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
222 return aPrs3d._retn();
225 CORBA::Double VISU::StreamLines_i::GetUsedPoints() {
226 return myStreamLinesPL->GetUsedPoints();
230 void VISU::StreamLines_i::DoHook(){
231 if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
232 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
234 DeformedShape_i::DoHook();
238 void VISU::StreamLines_i::Update() {
240 VISU::DeformedShape_i::Update();
244 VISU_Actor* VISU::StreamLines_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
246 return VISU::DeformedShape_i::CreateActor(theIO);
250 void VISU::StreamLines_i::UpdateActor(VISU_Actor* theActor) {
251 VISU::DeformedShape_i::UpdateActor(theActor);