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_Prs3d_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_PipeLine.hxx"
28 #include "VISU_Prs3d_i.hh"
30 #include "VISU_Result_i.hh"
31 #include "VISU_Actor.h"
33 #include "SALOME_Event.hxx"
35 #include <vtkActorCollection.h>
36 #include <vtkDataSet.h>
37 #include <vtkMapper.h>
39 #include <boost/bind.hpp>
45 static int MYDEBUG = 1;
47 static int MYDEBUG = 0;
51 //----------------------------------------------------------------------------
53 ::Prs3d_i(Result_i* theResult,
54 SALOMEDS::SObject_ptr theSObject) :
55 PrsObject_i(theResult->GetStudyDocument()),
56 mySObject(SALOMEDS::SObject::_duplicate(theSObject)),
57 myActorCollection(vtkActorCollection::New()),
62 if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<<this);
63 myOffset[0] = myOffset[1] = myOffset[2] = 0;
64 myActorCollection->Delete();
69 ::Prs3d_i(Result_i* theResult,
71 PrsObject_i(theResult->GetStudyDocument()),
72 myActorCollection(vtkActorCollection::New()),
73 mySObject(SALOMEDS::SObject::_nil()),
74 myAddToStudy(theAddToStudy),
78 if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<<this);
79 myOffset[0] = myOffset[1] = myOffset[2] = 0;
80 myActorCollection->Delete();
86 ::SameAs(const Prs3d_i* theOrigin)
88 if (Prs3d_i* aOrigin = const_cast<Prs3d_i*>(theOrigin)) {
89 myPipeLine->SameAs(aOrigin->GetPL());
90 aOrigin->GetOffset(myOffset);
97 if(MYDEBUG) MESSAGE("Prs3d_i::~Prs3d_i - this = "<<this);
98 myRemoveActorsFromRendererSignal();
104 //----------------------------------------------------------------------------
107 ::Restore(const Storable::TRestoringMap& theMap)
109 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
110 myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat();
111 myOffset[1] = VISU::Storable::FindValue(theMap,"myOffset[1]").toFloat();
112 myOffset[2] = VISU::Storable::FindValue(theMap,"myOffset[2]").toFloat();
118 ::ToStream(std::ostringstream& theStr)
120 Storable::DataToStream( theStr, "myName", myName.c_str() );
121 Storable::DataToStream( theStr, "myOffset[0]", myOffset[0] );
122 Storable::DataToStream( theStr, "myOffset[1]", myOffset[1] );
123 Storable::DataToStream( theStr, "myOffset[2]", myOffset[2] );
127 //----------------------------------------------------------------------------
128 SALOMEDS::SObject_var
132 if(CORBA::is_nil(mySObject.in())){
133 const SALOMEDS::Study_var& aStudy = myResult->GetStudyDocument();
134 CORBA::String_var anIOR = GetID();
135 mySObject = aStudy->FindObjectIOR(anIOR);
149 ::GetMeshName() const
155 //----------------------------------------------------------------------------
160 if(MYDEBUG) MESSAGE("Prs3d_i::Update - this = "<<this);
162 myPipeLine->Update();
164 throw std::runtime_error("Prs3d_i::Update >> unexpected exception was caught!!!");
169 //----------------------------------------------------------------------------
174 vtkMapper *aMapper = myPipeLine->GetMapper();
175 vtkDataSet *aDataSet = aMapper->GetInput();
177 throw std::runtime_error("There is no input data !!!");
179 static float eps = VTK_LARGE_FLOAT * 0.1 ;
180 if (!aDataSet->GetNumberOfCells())
181 throw std::runtime_error("There are no visible elements");
182 if (aDataSet->GetLength() > eps)
183 throw std::runtime_error("Diagonal of the actor is too large !!!");
190 struct TRemoveFromStudy: public SALOME_Event
192 VISU::Prs3d_i* myRemovable;
193 typedef boost::signal0<void> TRemoveFromStudySignal;
194 const TRemoveFromStudySignal& myRemoveFromStudySignal;
196 TRemoveFromStudy(VISU::Prs3d_i* theRemovable,
197 const TRemoveFromStudySignal& theRemoveFromStudySignal):
198 myRemovable(theRemovable),
199 myRemoveFromStudySignal(theRemoveFromStudySignal)
206 myRemoveFromStudySignal();
207 myRemovable->Destroy();
211 ProcessVoidEvent(new TRemoveFromStudy(this,myRemoveActorsFromRendererSignal));
215 //----------------------------------------------------------------------------
234 return myPipeLine->GetInput();
238 //----------------------------------------------------------------------------
241 ::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
244 Handle(SALOME_InteractiveObject) anIO = theIO;
245 if(anIO.IsNull() && (!mySObject->_is_nil())){
246 anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
247 theActor->setIO(anIO);
253 theActor->SetPrs3d(this);
254 theActor->SetShrinkFactor();
255 theActor->SetPosition(myOffset[0],myOffset[1],myOffset[2]);
256 theActor->SetPipeLine(GetPipeLine());
258 theActor->SetFactory(this);
259 myUpdateActorsSignal.connect(boost::bind(&VISU_Actor::UpdateFromFactory,theActor));
260 myRemoveActorsFromRendererSignal.connect(boost::bind(&VISU_Actor::RemoveFromRender,theActor));
262 myActorCollection->AddItem(theActor);
265 }catch(std::bad_alloc& ex){
266 throw std::runtime_error("CreateActor >> No enough memory");
268 } catch(std::exception&){
271 throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
277 ::RemoveActor(VISU_Actor* theActor)
279 if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActor - this = "<<this<<"; theActor = "<<theActor);
280 myActorCollection->RemoveItem(theActor);
287 if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActors - this = "<<this);
288 myRemoveActorsFromRendererSignal();
289 myActorCollection->RemoveAllItems();
294 ::UpdateActor(VISU_Actor* theActor)
296 if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor - this = "<<this<<"; theActor = "<<theActor);
297 theActor->ShallowCopyPL(myPipeLine);
298 theActor->SetPosition(myOffset[0],myOffset[1],myOffset[2]);
299 theActor->Modified();
306 if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActors - this = "<<this);
309 myUpdateActorsSignal();
313 //----------------------------------------------------------------------------
317 ::RemoveAllClippingPlanes()
319 myPipeLine->RemoveAllClippingPlanes();
324 ::AddClippingPlane(vtkPlane* thePlane)
326 return myPipeLine->AddClippingPlane(thePlane);
331 ::GetNumberOfClippingPlanes() const
333 return myPipeLine->GetNumberOfClippingPlanes();
338 GetClippingPlane(vtkIdType theID) const
340 return myPipeLine->GetClippingPlane(theID);
345 ::SetPlaneParam (vtkFloatingPointType theDir[3],
346 vtkFloatingPointType theDist,
349 myPipeLine->SetPlaneParam(theDir, theDist, thePlane);
353 //----------------------------------------------------------------------------
356 ::GetBounds(vtkFloatingPointType aBounds[6])
358 myPipeLine->GetMapper()->GetBounds(aBounds);
363 ::SetOffset(const CORBA::Float* theOffsets)
365 myOffset[0] = theOffsets[0];
366 myOffset[1] = theOffsets[1];
367 myOffset[2] = theOffsets[2];
372 ::SetOffset(CORBA::Float theDx,
383 ::GetOffset(CORBA::Float* theOffsets)
385 theOffsets[0] = myOffset[0];
386 theOffsets[1] = myOffset[1];
387 theOffsets[2] = myOffset[2];
392 ::GetOffset(CORBA::Float& theDx,
402 //----------------------------------------------------------------------------
404 VISU::GetResult(SALOMEDS::SObject_ptr theSObject)
406 VISU::Result_var aResult = FindResult(theSObject);
407 if(!aResult->_is_nil())
408 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());