// Module : VISU
#include "VISU_PipeLine.hxx"
-#include "VISU_Result_i.hh"
#include "VISU_Prs3d_i.hh"
+
+#include "VISU_Result_i.hh"
#include "VISU_Actor.h"
-#include <vtkGeometryFilter.h>
-#include <vtkDataSetMapper.h>
+#include "SALOME_Event.hxx"
+
+#include <vtkActorCollection.h>
+#include <vtkDataSet.h>
+#include <vtkMapper.h>
+
+#include <boost/bind.hpp>
using namespace VISU;
using namespace std;
#ifdef _DEBUG_
-static int MYDEBUG = 0;
+static int MYDEBUG = 1;
#else
static int MYDEBUG = 0;
#endif
-VISU::Prs3d_i::
-Prs3d_i(Result_i* theResult,
- SALOMEDS::SObject_ptr theSObject) :
+
+//----------------------------------------------------------------------------
+VISU::Prs3d_i
+::Prs3d_i(Result_i* theResult,
+ SALOMEDS::SObject_ptr theSObject) :
PrsObject_i(theResult->GetStudyDocument()),
- myResult(theResult),
mySObject(SALOMEDS::SObject::_duplicate(theSObject)),
+ myActorCollection(vtkActorCollection::New()),
+ myResult(theResult),
myAddToStudy(true),
myPipeLine(NULL)
{
+ if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<<this);
myOffset[0] = myOffset[1] = myOffset[2] = 0;
+ myActorCollection->Delete();
myResult->Register();
}
-VISU::Prs3d_i::
-Prs3d_i(Result_i* theResult,
- bool theAddToStudy) :
+VISU::Prs3d_i
+::Prs3d_i(Result_i* theResult,
+ bool theAddToStudy) :
PrsObject_i(theResult->GetStudyDocument()),
- myResult(theResult),
+ myActorCollection(vtkActorCollection::New()),
mySObject(SALOMEDS::SObject::_nil()),
myAddToStudy(theAddToStudy),
+ myResult(theResult),
myPipeLine(NULL)
{
+ if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<<this);
myOffset[0] = myOffset[1] = myOffset[2] = 0;
+ myActorCollection->Delete();
myResult->Register();
}
-void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
+void
+VISU::Prs3d_i
+::SameAs(const Prs3d_i* theOrigin)
{
if (Prs3d_i* aOrigin = const_cast<Prs3d_i*>(theOrigin)) {
myPipeLine->SameAs(aOrigin->GetPL());
}
}
-VISU::Prs3d_i::~Prs3d_i() {
- if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<<this
- <<"; GetReferenceCount() = "<<myPipeLine->GetReferenceCount());
+VISU::Prs3d_i
+::~Prs3d_i()
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::~Prs3d_i - this = "<<this);
+ myRemoveActorsFromRendererSignal();
myPipeLine->Delete();
myResult->Destroy();
}
-void VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
-{
- try{
- Update();
- // if(myAddToStudy){
- Handle(SALOME_InteractiveObject) anIO = theIO;
- if(anIO.IsNull() && (!mySObject->_is_nil())){
- anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
- theActor->setIO(anIO);
- }
- // }
- theActor->SetPipeLine(GetPipeLine());
- theActor->SetPrs3d(this);
- theActor->SetPosition(myOffset);
- }catch(std::bad_alloc& ex){
- throw std::runtime_error("CreateActor >> No enough memory");
- throw ex;
- } catch(std::exception& ex){
- throw ex;
- }catch(...) {
- throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
- }
-}
-void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) {
- if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor() - this = "<<this);
- theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper());
- theActor->SetPosition(myOffset);
- theActor->Modified();
-}
-
-VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap)
+//----------------------------------------------------------------------------
+VISU::Storable*
+VISU::Prs3d_i
+::Restore(const Storable::TRestoringMap& theMap)
{
myName = VISU::Storable::FindValue(theMap,"myName").latin1();
myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat();
return this;
}
-void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){
+void
+VISU::Prs3d_i
+::ToStream(std::ostringstream& theStr)
+{
Storable::DataToStream( theStr, "myName", myName.c_str() );
Storable::DataToStream( theStr, "myOffset[0]", myOffset[0] );
Storable::DataToStream( theStr, "myOffset[1]", myOffset[1] );
Storable::DataToStream( theStr, "myOffset[2]", myOffset[2] );
}
-void VISU::Prs3d_i::Update() {
- if(MYDEBUG) MESSAGE("Prs3d_i::Update() - this = "<<this);
+
+//----------------------------------------------------------------------------
+SALOMEDS::SObject_var
+VISU::Prs3d_i
+::GetSObject()
+{
+ if(CORBA::is_nil(mySObject.in())){
+ const SALOMEDS::Study_var& aStudy = myResult->GetStudyDocument();
+ CORBA::String_var anIOR = GetID();
+ mySObject = aStudy->FindObjectIOR(anIOR);
+ }
+ return mySObject;
+}
+
+Result_i*
+VISU::Prs3d_i
+::GetResult() const
+{
+ return myResult;
+}
+
+const std::string&
+VISU::Prs3d_i
+::GetMeshName() const
+{
+ return myMeshName;
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU::Prs3d_i
+::Update()
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::Update - this = "<<this);
try{
myPipeLine->Update();
}catch(...){
}
}
-VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){
+
+//----------------------------------------------------------------------------
+void
+VISU::Prs3d_i
+::CheckDataSet()
+{
+ vtkMapper *aMapper = myPipeLine->GetMapper();
+ vtkDataSet *aDataSet = aMapper->GetInput();
+ if (!aDataSet)
+ throw std::runtime_error("There is no input data !!!");
+ aDataSet->Update();
+ static float eps = VTK_LARGE_FLOAT * 0.1 ;
+ if (!aDataSet->GetNumberOfCells())
+ throw std::runtime_error("There are no visible elements");
+ if (aDataSet->GetLength() > eps)
+ throw std::runtime_error("Diagonal of the actor is too large !!!");
+}
+
+void
+VISU::Prs3d_i
+::RemoveFromStudy()
+{
+ struct TRemoveFromStudy: public SALOME_Event
+ {
+ VISU::Prs3d_i* myRemovable;
+ typedef boost::signal0<void> TRemoveFromStudySignal;
+ const TRemoveFromStudySignal& myRemoveFromStudySignal;
+
+ TRemoveFromStudy(VISU::Prs3d_i* theRemovable,
+ const TRemoveFromStudySignal& theRemoveFromStudySignal):
+ myRemovable(theRemovable),
+ myRemoveFromStudySignal(theRemoveFromStudySignal)
+ {}
+
+ virtual
+ void
+ Execute()
+ {
+ myRemoveFromStudySignal();
+ myRemovable->Destroy();
+ }
+ };
+
+ ProcessVoidEvent(new TRemoveFromStudy(this,myRemoveActorsFromRendererSignal));
+}
+
+
+//----------------------------------------------------------------------------
+VISU_PipeLine*
+VISU::Prs3d_i
+::GetPipeLine()
+{
return GetPL();
}
-VISU_PipeLine* VISU::Prs3d_i::GetPL(){
+VISU_PipeLine*
+VISU::Prs3d_i
+::GetPL()
+{
return myPipeLine;
}
-vtkUnstructuredGrid* VISU::Prs3d_i::GetInput(){
+vtkUnstructuredGrid*
+VISU::Prs3d_i::
+GetInput()
+{
return myPipeLine->GetInput();
}
-SALOMEDS::SObject_var VISU::Prs3d_i::GetSObject(){
- if (CORBA::is_nil(mySObject.in())) {
- const SALOMEDS::Study_var& aStudy = myResult->GetStudyDocument();
- CORBA::String_var anIOR = GetID();
- mySObject = aStudy->FindObjectIOR(anIOR);
+//----------------------------------------------------------------------------
+void
+VISU::Prs3d_i
+::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO)
+{
+ try{
+ Handle(SALOME_InteractiveObject) anIO = theIO;
+ if(anIO.IsNull() && (!mySObject->_is_nil())){
+ anIO = new SALOME_InteractiveObject(mySObject->GetID(),"VISU",GetName());
+ theActor->setIO(anIO);
+ }
+
+ Update();
+ CheckDataSet();
+
+ theActor->SetPrs3d(this);
+ theActor->SetShrinkFactor();
+ theActor->SetPosition(myOffset);
+ theActor->SetPipeLine(GetPipeLine());
+
+ theActor->SetFactory(this);
+ myUpdateActorsSignal.connect(boost::bind(&VISU_Actor::UpdateFromFactory,theActor));
+ myRemoveActorsFromRendererSignal.connect(boost::bind(&VISU_Actor::RemoveFromRender,theActor));
+
+ myActorCollection->AddItem(theActor);
+ theActor->Delete();
+
+ }catch(std::bad_alloc& ex){
+ throw std::runtime_error("CreateActor >> No enough memory");
+ throw ex;
+ } catch(std::exception&){
+ throw;
+ }catch(...) {
+ throw std::runtime_error("CreateActor >> unexpected exception was caught!!!");
}
- return mySObject;
}
-void VISU::Prs3d_i::GetBounds(float aBounds[6]){
- myPipeLine->GetMapper()->GetBounds(aBounds);
+void
+VISU::Prs3d_i
+::RemoveActor(VISU_Actor* theActor)
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActor - this = "<<this<<"; theActor = "<<theActor);
+ myActorCollection->RemoveItem(theActor);
}
-// Clipping planes
+void
+VISU::Prs3d_i
+::RemoveActors()
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActors - this = "<<this);
+ myRemoveActorsFromRendererSignal();
+ myActorCollection->RemoveAllItems();
+}
+
+void
+VISU::Prs3d_i
+::UpdateActor(VISU_Actor* theActor)
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor - this = "<<this<<"; theActor = "<<theActor);
+ theActor->ShallowCopyPL(myPipeLine);
+ theActor->SetPosition(myOffset);
+ theActor->Modified();
+}
-void VISU::Prs3d_i::RemoveAllClippingPlanes(){
+void
+VISU::Prs3d_i
+::UpdateActors()
+{
+ if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActors - this = "<<this);
+ Update();
+ CheckDataSet();
+ myUpdateActorsSignal();
+}
+
+
+//----------------------------------------------------------------------------
+// Clipping planes
+void
+VISU::Prs3d_i
+::RemoveAllClippingPlanes()
+{
myPipeLine->RemoveAllClippingPlanes();
}
-vtkIdType VISU::Prs3d_i::GetNumberOfClippingPlanes() const{
- return myPipeLine->GetNumberOfClippingPlanes();
+bool
+VISU::Prs3d_i
+::AddClippingPlane(vtkPlane* thePlane)
+{
+ return myPipeLine->AddClippingPlane(thePlane);
}
-void VISU::Prs3d_i::AddClippingPlane(vtkPlane* thePlane){
- myPipeLine->AddClippingPlane(thePlane);
+vtkIdType
+VISU::Prs3d_i
+::GetNumberOfClippingPlanes() const
+{
+ return myPipeLine->GetNumberOfClippingPlanes();
}
-vtkPlane* VISU::Prs3d_i::GetClippingPlane(vtkIdType theID) const{
+vtkPlane*
+VISU::Prs3d_i::
+GetClippingPlane(vtkIdType theID) const
+{
return myPipeLine->GetClippingPlane(theID);
}
-void VISU::Prs3d_i::SetPlaneParam (float theDir[3], float theDist, vtkPlane* thePlane) {
+void
+VISU::Prs3d_i
+::SetPlaneParam (float theDir[3], float theDist, vtkPlane* thePlane)
+{
myPipeLine->SetPlaneParam(theDir, theDist, thePlane);
}
-VISU::Result_i* VISU::GetResult(SALOMEDS::SObject_ptr theSObject){
- VISU::Result_var aResult = FindResult(theSObject);
- if(!aResult->_is_nil())
- return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
- return NULL;
+
+//----------------------------------------------------------------------------
+void
+VISU::Prs3d_i
+::GetBounds(float aBounds[6])
+{
+ myPipeLine->GetMapper()->GetBounds(aBounds);
}
-void VISU::Prs3d_i::SetOffset(const float* theOffsets)
+void
+VISU::Prs3d_i
+::SetOffset(const float* theOffsets)
{
myOffset[0] = theOffsets[0];
myOffset[1] = theOffsets[1];
myOffset[2] = theOffsets[2];
}
-void VISU::Prs3d_i::SetOffset(float theDx, float theDy, float theDz)
+void
+VISU::Prs3d_i
+::SetOffset(float theDx, float theDy, float theDz)
{
myOffset[0] = theDx;
myOffset[1] = theDy;
myOffset[2] = theDz;
}
-void VISU::Prs3d_i::GetOffset(float* theOffsets)
+void
+VISU::Prs3d_i
+::GetOffset(float* theOffsets)
{
theOffsets[0] = myOffset[0];
theOffsets[1] = myOffset[1];
theOffsets[2] = myOffset[2];
}
-void VISU::Prs3d_i::GetOffset(float& theDx, float& theDy, float& theDz)
+
+void
+VISU::Prs3d_i
+::GetOffset(float& theDx, float& theDy, float& theDz)
{
theDx = myOffset[0];
theDy = myOffset[1];
theDz = myOffset[2];
}
+
+
+//----------------------------------------------------------------------------
+VISU::Result_i*
+VISU::GetResult(SALOMEDS::SObject_ptr theSObject)
+{
+ VISU::Result_var aResult = FindResult(theSObject);
+ if(!aResult->_is_nil())
+ return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()).in());
+ return NULL;
+}
+