X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISU_I%2FVISU_Prs3d_i.cc;h=3ec20db4328e6cf4dab98590b1cd9df54c54ab9c;hb=d90eeb25287fa1f390fe7a336547e74161708e44;hp=5e39d80e3799988ba81fef1fdf9bbb2c69e7e4de;hpb=89c0929d7f592396b319872c9f6187275bd3e8fb;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_Prs3d_i.cc b/src/VISU_I/VISU_Prs3d_i.cc index 5e39d80e..3ec20db4 100644 --- a/src/VISU_I/VISU_Prs3d_i.cc +++ b/src/VISU_I/VISU_Prs3d_i.cc @@ -1,6 +1,6 @@ -// VISU OBJECT : interactive object for VISU entities implementation +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or @@ -17,205 +17,678 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// VISU OBJECT : interactive object for VISU entities implementation // File : VISU_Prs3d_i.cc // Author : Alexey PETROV // Module : VISU - +// +#include "VISU_Prs3d_i.hh" +#include "VISU_Prs3dUtils.hh" #include "VISU_PipeLine.hxx" + #include "VISU_Result_i.hh" -#include "VISU_Prs3d_i.hh" #include "VISU_Actor.h" -#include -#include +#include "SALOME_Event.h" + +#include +#include +#include +#include -using namespace VISU; -using namespace std; +#include #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) : - PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), - mySObject(SALOMEDS::SObject::_duplicate(theSObject)), - myAddToStudy(true), - myPipeLine(NULL) + +//---------------------------------------------------------------------------- +VISU::Prs3d_i::Prs3d_i() : + PrsObject_i(SALOMEDS::Study::_nil()), + myActorCollection(vtkActorCollection::New()), + myIsActiveSatate(true) { + if(MYDEBUG) MESSAGE("Prs3d_i::Prs3d_i - this = "<Register(); + myActorCollection->Delete(); } -VISU::Prs3d_i:: -Prs3d_i(Result_i* theResult, - bool theAddToStudy) : - PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult), - mySObject(SALOMEDS::SObject::_nil()), - myAddToStudy(theAddToStudy), - myPipeLine(NULL) + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::SameAs(const Prs3d_i* theOrigin) { - myOffset[0] = myOffset[1] = myOffset[2] = 0; - myResult->Register(); + if(Prs3d_i* anOrigin = const_cast(theOrigin)){ + VISU::TSetModified aModified(this); + + GetPipeLine()->SameAs(anOrigin->GetPipeLine()); + anOrigin->GetOffset(myOffset); + } +} + + +//---------------------------------------------------------------------------- +namespace VISU +{ + struct TInvokeSignalEvent: public SALOME_Event + { + typedef boost::signal0 TSignal; + const TSignal& mySignal; + + TInvokeSignalEvent(const TSignal& theSignal): + mySignal(theSignal) + {} + + virtual + void + Execute() + { + mySignal(); + } + }; +} + +//---------------------------------------------------------------------------- +VISU::Prs3d_i::~Prs3d_i() +{ + if(MYDEBUG) MESSAGE("Prs3d_i::~Prs3d_i - this = "<Destroy(); } -void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin) + +//---------------------------------------------------------------------------- +bool +VISU::Prs3d_i +::SetInput(bool theReInit) { - if (Prs3d_i* aOrigin = const_cast(theOrigin)) { - myPipeLine->SameAs(aOrigin->GetPL()); - aOrigin->GetOffset(myOffset); + if(GetCResult()){ + if(myMeshName != ""){ + myPreviousResult = myResult; + myPreviousMeshName = myMeshName; + return true; + } } + return false; } -VISU::Prs3d_i::~Prs3d_i() { - if(MYDEBUG) MESSAGE("~Prs3d_i() - this = "<setIO(anIO); + if(SetInput(theReInit)){ + if(myActorCollection->GetNumberOfItems()) + UpdateActors(); + return true; } - // } - 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!!!"); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<GetEntry(); + return ""; +} + +//---------------------------------------------------------------------------- +VISU::Result_i* +VISU::Prs3d_i +::GetCResult() const +{ + return myResult; +} + + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::SetResultObject(VISU::Result_ptr theResult) +{ + SetCResult(dynamic_cast(GetServant(theResult).in())); +} + + +//---------------------------------------------------------------------------- +VISU::Result_ptr +VISU::Prs3d_i +::GetResultObject() +{ + return GetCResult()->_this(); +} + + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::SetMeshName(const char* theMeshName) +{ + if(myMeshName == theMeshName) + return; + + VISU::TSetModified aModified(this); + + myMeshName = theMeshName; + myParamsTime.Modified(); +} + + +//---------------------------------------------------------------------------- +char* +VISU::Prs3d_i +::GetMeshName() +{ + return CORBA::string_dup(myMeshName.c_str()); +} + + +//---------------------------------------------------------------------------- +std::string +VISU::Prs3d_i +::GetCMeshName() const +{ + return myMeshName; +} + + +//---------------------------------------------------------------------------- +unsigned long int +VISU::Prs3d_i +::GetMTime() +{ + unsigned long int aTime = myParamsTime.GetMTime(); + if(IsPipeLineExists()) + aTime = std::max(aTime, GetPipeLine()->GetMTime()); + return aTime; +} + +//---------------------------------------------------------------------------- +bool +VISU::Prs3d_i +::GetActiveState() +{ + return myIsActiveSatate; +} + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::SetActiveState(bool theState) +{ + myIsActiveSatate = theState; +} + +//---------------------------------------------------------------------------- +VISU::Storable* +VISU::Prs3d_i +::Restore(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap) +{ + SALOMEDS::Study_var aStudy = theSObject->GetStudy(); + SetStudyDocument(aStudy); + + bool anIsExists = false; + QString aResultEntry = VISU::Storable::FindValue(theMap,"myResultEntry", &anIsExists); + if(!anIsExists){ + SALOMEDS::SObject_var aSObject = SALOMEDS::SObject::_duplicate(theSObject); + for(; aSObject->Depth() > 2 && !aResultEntry.isEmpty(); aSObject = aSObject->GetFather()){ + CORBA::Object_var anObject = VISU::SObjectToObject(aSObject); + if(CORBA::is_nil(anObject)) + continue; + + VISU::Result_var aResult = VISU::Result::_narrow(anObject); + if(CORBA::is_nil(aResult)) + continue; + + CORBA::String_var anEntry = aSObject->GetID(); + aResultEntry = anEntry.in(); + } + } + SetResultEntry(aResultEntry.toLatin1().data()); + if(!GetCResult()) + return NULL; + + SetMeshName((const char*)VISU::Storable::FindValue(theMap,"myMeshName").toLatin1()); + SetName((const char*)VISU::Storable::FindValue(theMap,"myName").toLatin1(), false); myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat(); myOffset[1] = VISU::Storable::FindValue(theMap,"myOffset[1]").toFloat(); myOffset[2] = VISU::Storable::FindValue(theMap,"myOffset[2]").toFloat(); + myParamsTime.Modified(); return this; } -void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){ - Storable::DataToStream( theStr, "myName", myName.c_str() ); +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::ToStream(std::ostringstream& theStr) +{ + Storable::DataToStream( theStr, "myResultEntry", GetResultEntry().c_str() ); + Storable::DataToStream( theStr, "myMeshName", GetCMeshName().c_str() ); + Storable::DataToStream( theStr, "myName", GetName().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 = "<FindObjectIOR(anIOR); + } + return SALOMEDS::SObject::_nil(); +} + + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::Update() +{ + if(GetMTime() < myUpdateTime.GetMTime()) + return; + + if(MYDEBUG) MESSAGE("Prs3d_i::Update - this = "<Update(); + ProcessVoidEvent(new TVoidMemFunEvent + (GetPipeLine(), &VISU_PipeLine::Update)); + myUpdateTime.Modified(); + }catch(std::exception&){ + throw; }catch(...){ throw std::runtime_error("Prs3d_i::Update >> unexpected exception was caught!!!"); } } -VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){ - return GetPL(); + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::CheckDataSet() +{ + vtkMapper *aMapper = GetPipeLine()->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 !!!"); } -VISU_PipeLine* VISU::Prs3d_i::GetPL(){ - return myPipeLine; + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::RemoveFromStudy() +{ + struct TEvent: public TInvokeSignalEvent + { + VISU::Prs3d_i* myRemovable; + + TEvent(const TSignal& theSignal, + VISU::Prs3d_i* theRemovable): + TInvokeSignalEvent(theSignal), + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + //TInvokeSignalEvent::Execute(); + myRemovable->Destroy(); + } + }; + + ProcessVoidEvent(new TEvent(myRemoveActorsFromRendererSignal, this)); } -vtkUnstructuredGrid* VISU::Prs3d_i::GetInput(){ - return myPipeLine->GetInput(); + +//---------------------------------------------------------------------------- +VISU_PipeLine* +VISU::Prs3d_i +::GetPipeLine() const +{ + if(!myPipeLine.GetPointer()) + throw std::runtime_error("VISU::Prs3d_i::myPipeLine == NULL !!!"); + + return myPipeLine.GetPointer(); } +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::SetPipeLine(VISU_PipeLine* thePipeLine) +{ + myPipeLine = thePipeLine; + if(thePipeLine) + thePipeLine->Delete(); +} -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); +//---------------------------------------------------------------------------- +bool +VISU::Prs3d_i +::IsPipeLineExists() +{ + return myPipeLine.GetPointer() != NULL; +} + +//---------------------------------------------------------------------------- +VISU_PipeLine* +VISU::Prs3d_i +::GetActorPipeLine() +{ + return GetPipeLine(); +} + +//---------------------------------------------------------------------------- +vtkDataSet* +VISU::Prs3d_i +::GetInput() +{ + return GetPipeLine()->GetInput(); +} + +//---------------------------------------------------------------------------- +Handle(SALOME_InteractiveObject) +VISU::Prs3d_i +::GetIO() +{ + if( myIO.IsNull() ) + myIO = new SALOME_InteractiveObject(GetActorEntry().c_str(), "VISU", GetName().c_str()); + + return myIO; +} + +//---------------------------------------------------------------------------- +std::string +VISU::Prs3d_i +::GetActorEntry() +{ + return GetEntry(); +} + + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::CreateActor(VISU_Actor* theActor) +{ + try{ + Handle(SALOME_InteractiveObject) anIO = GetIO(); + if(!anIO.IsNull() && anIO->hasEntry()){ + theActor->setIO(anIO); + } + + Update(); + CheckDataSet(); + + theActor->SetPrs3d(this); + theActor->SetShrinkFactor(); + theActor->SetPosition(myOffset[0],myOffset[1],myOffset[2]); + theActor->SetPipeLine(GetActorPipeLine()); + if(theActor->GetPipeLine() != GetPipeLine()){ + // To decrease actor'ss pipeline reference counter + theActor->GetPipeLine()->Delete(); + } + + theActor->SetFactory(this); + theActor->ConnectToFactory(myUpdateActorsSignal, myRemoveActorsFromRendererSignal); + + 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_ActorBase* theActor) +{ + if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActor - this = "<GetReferenceCount()); + myActorCollection->RemoveItem(theActor); +} + +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::RemoveActors() +{ + if(MYDEBUG) MESSAGE("Prs3d_i::RemoveActors - this = "<RemoveAllItems(); } +//---------------------------------------------------------------------------- +void +VISU::Prs3d_i +::UpdateActor(VISU_ActorBase* theActor) +{ + if(VISU_Actor* anActor = dynamic_cast(theActor)){ + if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor - this = "<