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 <vtkAppendFilter.h>
38 static int MYDEBUG = 0;
39 static int MYDEBUGWITHFILES = 0;
41 static int MYDEBUG = 0;
42 static int MYDEBUGWITHFILES = 0;
45 static int INCMEMORY = 2;
47 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
48 const char* theFieldName, int theIteration)
52 (VISU_StreamLinesPL::myMaxIncrementMemorySize+INCMEMORY)*
53 theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
54 if(MYDEBUG) MESSAGE("StreamLines_i::IsPossible - CheckAvailableMemory = "<<aSize);
55 if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
57 }catch(std::runtime_error& exc){
58 INFOS("Follow exception was accured :\n"<<exc.what());
60 INFOS("Unknown exception was accured!");
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) :
75 PrsObject_i(theResult->GetStudyDocument()),
77 ScalarMap_i(theResult, theAddToStudy),
78 DeformedShape_i(theResult, theAddToStudy)
80 myStreamLinesPL = NULL;
83 void VISU::StreamLines_i::Destroy(){
84 DeformedShape_i::Destroy();
88 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
89 StreamLines_i* aStreamLines = const_cast<StreamLines_i*>(theOrigin);
90 VISU::DeformedShape_i::SameAs(theOrigin);
92 //Order of setting of the values are important
93 //SetIntegrationStep(aStreamLines->GetIntegrationStep());
94 //SetPropagationTime(aStreamLines->GetPropagationTime());
95 //SetStepLength(aStreamLines->GetStepLength());
97 //SetUsedPoints(aStreamLines->GetUsedPoints());
98 //SetDirection(aStreamLines->GetDirection());
100 SetSource(aStreamLines->GetSource());
104 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
105 const char* theFieldName, int theIteration)
107 return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
111 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap)
112 throw(std::logic_error&)
114 DeformedShape_i::Restore(theMap);
116 //Order of setting of the values are important
117 SetIntegrationStep(VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble());
118 SetPropagationTime(VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble());
119 SetStepLength(VISU::Storable::FindValue(theMap,"myStepLength").toDouble());
121 SetDirection(VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt()));
122 SetUsedPoints(VISU::Storable::FindValue(theMap,"myPercents").toDouble());
123 mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1();
129 void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){
130 DeformedShape_i::ToStream(theStr);
132 Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep());
133 Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime());
134 Storable::DataToStream( theStr, "myStepLength", GetStepLength());
136 Storable::DataToStream( theStr, "myDirection", int(GetDirection()));
137 Storable::DataToStream( theStr, "myPercents", GetUsedPoints());
139 Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str());
143 VISU::Storable* VISU::StreamLines_i::Restore(SALOMEDS::SObject_ptr theSObject,
144 const string& thePrefix, const Storable::TRestoringMap& theMap)
145 throw(std::logic_error&)
147 VISU::Result_i* pResult = GetResult(theSObject);
149 VISU::StreamLines_i* pResent = new VISU::StreamLines_i(pResult);
150 return pResent->Restore(theMap);
156 VISU::StreamLines_i::~StreamLines_i(){
157 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
161 void VISU::StreamLines_i::SetDirection(VISU::StreamLines::Direction theDirection) {
162 myStreamLinesPL->SetDirection(theDirection);
164 VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() {
165 return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection());
169 void VISU::StreamLines_i::SetStepLength(CORBA::Double theStep) {
170 myStreamLinesPL->SetStepLength(theStep);
172 CORBA::Double VISU::StreamLines_i::GetStepLength() {
173 return myStreamLinesPL->GetStepLength();
177 void VISU::StreamLines_i::SetPropagationTime(CORBA::Double theTime) {
178 myStreamLinesPL->SetPropagationTime(theTime);
180 CORBA::Double VISU::StreamLines_i::GetPropagationTime() {
181 return myStreamLinesPL->GetPropagationTime();
185 void VISU::StreamLines_i::SetIntegrationStep(CORBA::Double theStep) {
186 myStreamLinesPL->SetIntegrationStep(theStep);
188 CORBA::Double VISU::StreamLines_i::GetIntegrationStep() {
189 return myStreamLinesPL->GetIntegrationStep();
193 void VISU::StreamLines_i::SetUsedPoints(CORBA::Double thePercents) {
194 myStreamLinesPL->SetUsedPoints(thePercents);
196 CORBA::Double VISU::StreamLines_i::GetUsedPoints() {
197 return myStreamLinesPL->GetUsedPoints();
201 void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){
202 if(!thePrs3d->_is_nil())
203 if(VISU::Prs3d_i* aPrs3di = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs3d))){
204 CORBA::String_var aString = thePrs3d->GetID();
205 SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(aString);
206 if(!CORBA::is_nil(aSObject)){
207 vtkAppendFilter* anAppendFilter = vtkAppendFilter::New();
208 anAppendFilter->AddInput(aPrs3di->GetPipeLine()->GetMapper()->GetInput());
209 myStreamLinesPL->SetSource(anAppendFilter->GetOutput());
210 anAppendFilter->Register(myStreamLinesPL);
211 anAppendFilter->Delete();
212 aString = aSObject->GetID();
213 mySourceEntry = aString.in();
217 myStreamLinesPL->SetSource(NULL);
220 VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){
221 VISU::Prs3d_var aPrs3d;
222 if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<<mySourceEntry<<"'");
223 if(mySourceEntry != ""){
224 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(mySourceEntry.c_str());
225 CORBA::Object_var anObj = SObjectToObject(aSObject);
226 if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj);
228 return aPrs3d._retn();
232 float VISU::StreamLines_i::GetMaxIntegrationStep(){
233 return myStreamLinesPL->GetMaxIntegrationStep();
237 float VISU::StreamLines_i::GetMinIntegrationStep(){
238 return myStreamLinesPL->GetMinIntegrationStep();
242 float VISU::StreamLines_i::GetBasePropagationTime(){
243 return myStreamLinesPL->GetBasePropagationTime();
247 void VISU::StreamLines_i::DoHook(){
248 if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New();
249 myStreamLinesPL = dynamic_cast<VISU_StreamLinesPL*>(myPipeLine);
251 DeformedShape_i::DoHook();