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_Prs3d_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_PipeLine.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Prs3d_i.hh"
30 #include "VISU_Actor.h"
32 #include <vtkGeometryFilter.h>
33 #include <vtkDataSetMapper.h>
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
45 Prs3d_i(Result_i* theResult,
46 SALOMEDS::SObject_ptr theSObject) :
47 PrsObject_i(theResult->GetStudyDocument()),
49 mySObject(SALOMEDS::SObject::_duplicate(theSObject)),
53 myOffset[0] = myOffset[1] = myOffset[2] = 0;
58 Prs3d_i(Result_i* theResult,
60 PrsObject_i(theResult->GetStudyDocument()),
62 mySObject(SALOMEDS::SObject::_nil()),
63 myAddToStudy(theAddToStudy),
66 myOffset[0] = myOffset[1] = myOffset[2] = 0;
70 void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
72 if (Prs3d_i* aOrigin = const_cast<Prs3d_i*>(theOrigin)) {
73 myPipeLine->SameAs(aOrigin->GetPL());
74 aOrigin->GetOffset(myOffset);
78 VISU::Prs3d_i::~Prs3d_i() {
79 if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this
80 <<"; GetReferenceCount() = "<<myPipeLine->GetReferenceCount());
85 void VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
90 Handle(SALOME_InteractiveObject) anIO = theIO;
91 if(anIO.IsNull() && (!mySObject->_is_nil())){
92 anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
93 theActor->setIO(anIO);
96 theActor->SetPipeLine(GetPipeLine());
97 theActor->SetPrs3d(this);
98 theActor->SetPosition(myOffset);
99 }catch(std::bad_alloc& ex){
100 throw std::runtime_error("CreateActor >> No enough memory");
102 } catch(std::exception& ex){
105 throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
109 void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) {
110 if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor() - this = "<<this);
111 theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper());
112 theActor->SetPosition(myOffset);
113 theActor->Modified();
116 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap)
118 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
119 myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat();
120 myOffset[1] = VISU::Storable::FindValue(theMap,"myOffset[1]").toFloat();
121 myOffset[2] = VISU::Storable::FindValue(theMap,"myOffset[2]").toFloat();
125 void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){
126 Storable::DataToStream( theStr, "myName", myName.c_str() );
127 Storable::DataToStream( theStr, "myOffset[0]", myOffset[0] );
128 Storable::DataToStream( theStr, "myOffset[1]", myOffset[1] );
129 Storable::DataToStream( theStr, "myOffset[2]", myOffset[2] );
132 void VISU::Prs3d_i::Update() {
133 if(MYDEBUG) MESSAGE("Prs3d_i::Update() - this = "<<this);
135 myPipeLine->Update();
137 throw std::runtime_error("Prs3d_i::Update >> unexpected exception was caught!!!");
141 VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){
145 VISU_PipeLine* VISU::Prs3d_i::GetPL(){
149 vtkUnstructuredGrid* VISU::Prs3d_i::GetInput(){
150 return myPipeLine->GetInput();
154 SALOMEDS::SObject_var VISU::Prs3d_i::GetSObject(){
155 if (CORBA::is_nil(mySObject.in())) {
156 const SALOMEDS::Study_var& aStudy = myResult->GetStudyDocument();
157 CORBA::String_var anIOR = GetID();
158 mySObject = aStudy->FindObjectIOR(anIOR);
163 void VISU::Prs3d_i::GetBounds(float aBounds[6]){
164 myPipeLine->GetMapper()->GetBounds(aBounds);
169 void VISU::Prs3d_i::RemoveAllClippingPlanes(){
170 myPipeLine->RemoveAllClippingPlanes();
173 vtkIdType VISU::Prs3d_i::GetNumberOfClippingPlanes() const{
174 return myPipeLine->GetNumberOfClippingPlanes();
177 bool VISU::Prs3d_i::AddClippingPlane(vtkPlane* thePlane){
178 return myPipeLine->AddClippingPlane(thePlane);
181 vtkPlane* VISU::Prs3d_i::GetClippingPlane(vtkIdType theID) const{
182 return myPipeLine->GetClippingPlane(theID);
185 void VISU::Prs3d_i::SetPlaneParam (float theDir[3], float theDist, vtkPlane* thePlane) {
186 myPipeLine->SetPlaneParam(theDir, theDist, thePlane);
189 VISU::Result_i* VISU::GetResult(SALOMEDS::SObject_ptr theSObject){
190 VISU::Result_var aResult = FindResult(theSObject);
191 if(!aResult->_is_nil())
192 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
196 void VISU::Prs3d_i::SetOffset(const float* theOffsets)
198 myOffset[0] = theOffsets[0];
199 myOffset[1] = theOffsets[1];
200 myOffset[2] = theOffsets[2];
203 void VISU::Prs3d_i::SetOffset(float theDx, float theDy, float theDz)
210 void VISU::Prs3d_i::GetOffset(float* theOffsets)
212 theOffsets[0] = myOffset[0];
213 theOffsets[1] = myOffset[1];
214 theOffsets[2] = myOffset[2];
216 void VISU::Prs3d_i::GetOffset(float& theDx, float& theDy, float& theDz)