From 56e6f19b9cda2181bd08a86155e86ec7ac54d866 Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 22 Sep 2005 12:19:20 +0000 Subject: [PATCH] To customize ActorFactories - common for VISU_Actors and particular for GaussPtsActors --- src/OBJECT/Makefile.in | 3 +- src/OBJECT/VISU_Actor.cxx | 32 +++------------- src/OBJECT/VISU_Actor.h | 19 +++------ src/OBJECT/VISU_ActorFactory.h | 19 +-------- src/OBJECT/VISU_GaussPtsAct.cxx | 43 ++++++++++++++++----- src/OBJECT/VISU_GaussPtsAct.h | 23 ++++++++--- src/OBJECT/VISU_GaussPtsActorFactory.h | 53 ++++++++++++++++++++++++++ src/VISU_I/VISU_GaussPoints_i.cc | 46 +++++++++++----------- src/VISU_I/VISU_GaussPoints_i.hh | 14 +++---- src/VISU_I/VISU_Prs3d_i.cc | 25 ------------ src/VISU_I/VISU_Prs3d_i.hh | 13 ------- src/VVTK/Makefile.in | 12 ++++-- src/VVTK/VVTK_Renderer.cxx | 26 +++++++++---- src/VVTK/VVTK_ViewWindow.cxx | 8 +--- 14 files changed, 174 insertions(+), 162 deletions(-) create mode 100644 src/OBJECT/VISU_GaussPtsActorFactory.h diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index a6854974..add0114e 100644 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -33,8 +33,9 @@ VPATH=.:@srcdir@:@top_srcdir@/idl @COMMENCE@ EXPORT_HEADERS = \ - VISU_Actor.h \ VISU_ActorFactory.h \ + VISU_GaussPtsActorFactory.h \ + VISU_Actor.h \ VISU_MeshAct.h \ VISU_ScalarMapAct.h \ VISU_GaussPtsAct.h \ diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index cb8a21ca..596705fc 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -116,7 +116,7 @@ VISU_Actor setName(anActor->getName()); if(anActor->hasIO()) setIO(anActor->getIO()); } - SALOME_Actor::ShallowCopy(prop); + Superclass::ShallowCopy(prop); } //---------------------------------------------------------------------------- @@ -124,7 +124,7 @@ VISU_Actor ::~VISU_Actor() { if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<getName(); } @@ -166,19 +166,12 @@ VISU_Actor myActorFactory = theActorFactory; } -void -VISU_Actor -::Connect(VISU_Actor* theActor) -{ - mySetVisibilitySignal.connect(boost::bind(&VISU_Actor::SetVisibility,theActor,_1)); -} - void VISU_Actor ::Update() { myActorFactory->UpdateActor(this); - SALOME_Actor::Update(); + Superclass::Update(); } @@ -229,26 +222,11 @@ VISU_Actor //---------------------------------------------------------------------------- -void -VISU_Actor -::SetVisibility(int theMode) -{ - SALOME_Actor::SetVisibility(theMode); - mySetVisibilitySignal(GetVisibility()); -} - -int -VISU_Actor -::GetVisibility() -{ - return SALOME_Actor::GetVisibility(); -} - void VISU_Actor ::SetRepresentation(int theMode) { - SALOME_Actor::SetRepresentation(theMode); + Superclass::SetRepresentation(theMode); if(myRepresentation == VTK_POINTS) UnShrink(); } diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index f99aad37..523a5e74 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -51,6 +51,12 @@ class VISU_PipeLine; #define VTKOCC_EXPORT VTK_EXPORT #endif +namespace VISU +{ + class Prs3d_i; +} + +//---------------------------------------------------------------------------- class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor { public: @@ -84,10 +90,6 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor void SetFactory(VISU::TActorFactory* theActorFactory); - virtual - void - Connect(VISU_Actor* theActor); - virtual void Update(); @@ -102,14 +104,6 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor SetPipeLine(VISU_PipeLine* thePipeLine) ; //---------------------------------------------------------------------------- - virtual - void - SetVisibility(int theMode); - - virtual - int - GetVisibility(); - virtual void SetRepresentation(int theMode); @@ -229,7 +223,6 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor vtkSmartPointer myMapper; VISU::TActorFactory* myActorFactory; - boost::signal1 mySetVisibilitySignal; vtkSmartPointer myShrinkFilter; bool myIsShrinkable; diff --git a/src/OBJECT/VISU_ActorFactory.h b/src/OBJECT/VISU_ActorFactory.h index a23cbe64..29367eba 100644 --- a/src/OBJECT/VISU_ActorFactory.h +++ b/src/OBJECT/VISU_ActorFactory.h @@ -29,33 +29,16 @@ #ifndef VISU_ACTOR_FACTORY_H #define VISU_ACTOR_FACTORY_H -#include "SALOME_InteractiveObject.hxx" - class VISU_Actor; -class vtkImplicitFunction; +//---------------------------------------------------------------------------- namespace VISU { - class Prs3d_i; - struct TActorFactory { - virtual - VISU_Actor* - CloneActor(VISU_Actor* theActor) = 0; - virtual void UpdateActor(VISU_Actor* theActor) = 0; - - virtual - void - UpdateFromActor(VISU_Actor* theActor) = 0; - - virtual - void - SetImplicitFunction(VISU_Actor* theActor, - vtkImplicitFunction* theImplicitFunction) = 0; }; } diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 1b1ce339..eb7e7437 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -53,7 +53,6 @@ #include #include #include -#include #include #include @@ -239,7 +238,6 @@ vtkStandardNewMacro(VISU_GaussPtsAct); VISU_GaussPtsAct ::VISU_GaussPtsAct(): - myInteractorObserver(vtkInteractorObserver::New()), myEventCallbackCommand(vtkCallbackCommand::New()), myPSMapper(VISU_OpenGLPointSpriteMapper::New()), myGaussPointsPL(NULL), @@ -251,7 +249,6 @@ VISU_GaussPtsAct mySphereActor(vtkActor::New()), myCursorPyramid(VISU_CursorPyramid::New()) { - myInteractorObserver->Delete(); myEventCallbackCommand->Delete(); myEventCallbackCommand->SetClientData(this); @@ -368,21 +365,47 @@ VISU_GaussPtsAct Superclass::SetPipeLine(thePipeLine); } +VISU_GaussPointsPL* +VISU_GaussPtsAct +::GetGaussPointsPL() +{ + return myGaussPointsPL.GetPointer(); +} + void VISU_GaussPtsAct ::SetFactory(VISU::TActorFactory* theActorFactory) { - VISU_Actor::SetFactory(theActorFactory); - myUpdatePrs3dSignal.connect(boost::bind(&VISU::TActorFactory::UpdateFromActor, - theActorFactory, - _1)); + using namespace VISU; + if(TGaussPtsActorFactory* aFactory = dynamic_cast(theActorFactory)){ + myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor, + aFactory, + _1)); + VISU_Actor::SetFactory(theActorFactory); + myGaussPtsActorFactory = aFactory; + } } -VISU_GaussPointsPL* +VISU::TGaussPtsActorFactory* VISU_GaussPtsAct -::GetGaussPointsPL() +::GetGaussPtsFactory() { - return myGaussPointsPL.GetPointer(); + return myGaussPtsActorFactory; +} + +void +VISU_GaussPtsAct +::Connect(VISU_GaussPtsAct* theActor) +{ + mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct::SetVisibility,theActor,_1)); +} + +void +VISU_GaussPtsAct +::SetVisibility(int theMode) +{ + Superclass::SetVisibility(theMode); + mySetVisibilitySignal(GetVisibility()); } bool diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index d7f9e78e..fd617c99 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -30,6 +30,8 @@ #define VISU_GaussPtsAct_HeaderFile #include "VISU_ScalarMapAct.h" +#include "VISU_GaussPtsActorFactory.h" + #include class VISU_GaussPointsPL; @@ -52,7 +54,6 @@ class vtkDataSetMapper; class vtkInteractorObserver; class vtkCallbackCommand; - //---------------------------------------------------------------------------- class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct { @@ -68,12 +69,23 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct void SetPipeLine(VISU_PipeLine* thePipeLine) ; + VISU_GaussPointsPL* + GetGaussPointsPL(); + virtual void SetFactory(VISU::TActorFactory* theActorFactory); + + VISU::TGaussPtsActorFactory* + GetGaussPtsFactory(); - VISU_GaussPointsPL* - GetGaussPointsPL(); + virtual + void + Connect(VISU_GaussPtsAct* theActor); + + virtual + void + SetVisibility(int theMode); bool ChangeMagnification(); @@ -117,7 +129,6 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct SetMapperInput(vtkDataSet* theDataSet); //---------------------------------------------------------------------------- - vtkSmartPointer myInteractorObserver; vtkSmartPointer myEventCallbackCommand; // Main process VTK event method @@ -130,7 +141,9 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct void OnInteractorEvent(unsigned long theEvent); - boost::signal1 myUpdatePrs3dSignal; + VISU::TGaussPtsActorFactory* myGaussPtsActorFactory; + boost::signal1 myUpdatePrs3dSignal; + boost::signal1 mySetVisibilitySignal; bool myChangeMagnification; //---------------------------------------------------------------------------- diff --git a/src/OBJECT/VISU_GaussPtsActorFactory.h b/src/OBJECT/VISU_GaussPtsActorFactory.h new file mode 100644 index 00000000..5d273100 --- /dev/null +++ b/src/OBJECT/VISU_GaussPtsActorFactory.h @@ -0,0 +1,53 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 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 +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// 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 +// +// +// +// File : VISU_ScalarMapAct.h +// Author : Laurent CORNABE with help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISU_GAUSSPTS_ACTOR_FACTORY_H +#define VISU_GAUSSPTS_ACTOR_FACTORY_H + +#include "VISU_ActorFactory.h" + +class vtkImplicitFunction; +class VISU_GaussPtsAct; + +//---------------------------------------------------------------------------- +namespace VISU +{ + struct TGaussPtsActorFactory: virtual TActorFactory + { + virtual + VISU_GaussPtsAct* + CloneActor(VISU_GaussPtsAct* theActor) = 0; + + virtual + void + UpdateFromActor(VISU_GaussPtsAct* theActor) = 0; + }; +} + + +#endif diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index abd082fb..0e8e12e6 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -25,9 +25,11 @@ // Module : #include "VISU_GaussPoints_i.hh" -#include "VISU_GaussPointsPL.hxx" -#include "VISU_GaussPtsAct.h" + #include "VISU_Result_i.hh" +#include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" + using namespace VISU; using namespace std; @@ -225,7 +227,12 @@ VISU_PipeLine* VISU::GaussPoints_i ::GetPipeLine() { - return GetPL(); + // We create a new PipeLine instamce in order to provide + // different representation for different actors (basic and segmented) + VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New(); + aPipeLine->ShallowCopy(myPipeLine); + aPipeLine->Update(); + return aPipeLine; } @@ -248,11 +255,15 @@ VISU::GaussPoints_i } //---------------------------------------------------------------------------- -VISU_Actor* +VISU_GaussPtsAct* VISU::GaussPoints_i -::CloneActor(VISU_Actor* theActor) +::CloneActor(VISU_GaussPtsAct* theActor) { - VISU::ScalarMap_i::CloneActor(theActor); + if(VISU_GaussPtsAct* anActor = dynamic_cast(CreateActor())){ + theActor->Connect(anActor); + return anActor; + } + return NULL; } //---------------------------------------------------------------------------- @@ -279,23 +290,10 @@ VISU::GaussPoints_i //---------------------------------------------------------------------------- void VISU::GaussPoints_i -::UpdateFromActor(VISU_Actor* theActor) -{ - if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ - bool aChangeMagnification = anActor->ChangeMagnification(); - if(MYDEBUG) MESSAGE("GaussPoints_i::UpdateFromActor - this = "<Connect(anActor); - return anActor; -} - void VISU::Prs3d_i ::UpdateActor(VISU_Actor* theActor) @@ -225,14 +216,6 @@ VISU::Prs3d_i theActor->Modified(); } -void -VISU::Prs3d_i -::UpdateFromActor(VISU_Actor* theActor) -{ - if(MYDEBUG) MESSAGE("Prs3d_i::UpdateFromActor - this = "<SetImplicitFunction(theImplicitFunction); -} - // Clipping planes void VISU::Prs3d_i diff --git a/src/VISU_I/VISU_Prs3d_i.hh b/src/VISU_I/VISU_Prs3d_i.hh index 1d8d6792..8d5b88e9 100644 --- a/src/VISU_I/VISU_Prs3d_i.hh +++ b/src/VISU_I/VISU_Prs3d_i.hh @@ -138,28 +138,15 @@ namespace VISU VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) = 0; - virtual - VISU_Actor* - CloneActor(VISU_Actor* theActor); - virtual void UpdateActor(VISU_Actor* theActor); - virtual - void - UpdateFromActor(VISU_Actor* theActor); - virtual void UpdateActors(); //---------------------------------------------------------------------------- - virtual - void - SetImplicitFunction(VISU_Actor* theActor, - vtkImplicitFunction* theImplicitFunction); - // Clipping planes void RemoveAllClippingPlanes(); diff --git a/src/VVTK/Makefile.in b/src/VVTK/Makefile.in index 9b1f8014..45d817ff 100755 --- a/src/VVTK/Makefile.in +++ b/src/VVTK/Makefile.in @@ -41,12 +41,18 @@ LIB_MOC = \ VVTK_View.h CPPFLAGS += \ - $(QT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(BOOST_CPPFLAGS) \ + $(QT_INCLUDES) \ + $(OCC_INCLUDES) \ + $(VTK_INCLUDES) \ + $(BOOST_CPPFLAGS) \ -I$(KERNEL_ROOT_DIR)/include/salome \ - -I$(GUI_ROOT_DIR)/include/salome + -I$(GUI_ROOT_DIR)/include/salome \ + -I${MED_ROOT_DIR}/include/salome LDFLAGS += \ - $(QT_MT_LIBS) $(OCC_LIBS) $(VTK_LIBS) \ + $(QT_MT_LIBS) \ + $(OCC_LIBS) \ + $(VTK_LIBS) \ -L$(KERNEL_ROOT_DIR)/lib/salome \ -L$(GUI_ROOT_DIR)/lib/salome diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx index 9b1eb747..1f2ee772 100644 --- a/src/VVTK/VVTK_Renderer.cxx +++ b/src/VVTK/VVTK_Renderer.cxx @@ -29,6 +29,7 @@ #include "VVTK_Renderer.h" #include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" #include "VISU_ImplicitFunctionWidget.h" #include @@ -178,11 +179,15 @@ void VVTK_Renderer2 ::AddActor(VTKViewer_Actor* theActor) { - SVTK_Renderer::AddActor(theActor); - if(VISU_Actor* anActor = dynamic_cast(theActor)) - if(VISU::TActorFactory* aFactory = anActor->GetFactory()){ - aFactory->SetImplicitFunction(anActor,myImplicitFunction.GetPointer()); + using namespace VISU; + if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){ + if(VISU_GaussPtsAct* anActor2 = aFactory->CloneActor(anActor)){ + anActor2->GetGaussPointsPL()->SetImplicitFunction(myImplicitFunction.GetPointer()); + SVTK_Renderer::AddActor(theActor); + } } + } } //---------------------------------------------------------------------------- @@ -190,8 +195,13 @@ void VVTK_Renderer2 ::RemoveActor(VTKViewer_Actor* theActor) { - if(VISU_Actor* anActor = dynamic_cast(theActor)) - if(VISU::TActorFactory* aFactory = anActor->GetFactory()) - aFactory->SetImplicitFunction(anActor,NULL); - SVTK_Renderer::RemoveActor(theActor); + using namespace VISU; + if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){ + if(VISU_GaussPtsAct* anActor2 = aFactory->CloneActor(anActor)){ + anActor2->GetGaussPointsPL()->SetImplicitFunction(NULL); + SVTK_Renderer::RemoveActor(theActor); + } + } + } } diff --git a/src/VVTK/VVTK_ViewWindow.cxx b/src/VVTK/VVTK_ViewWindow.cxx index e5ffb4e1..e27caf23 100755 --- a/src/VVTK/VVTK_ViewWindow.cxx +++ b/src/VVTK/VVTK_ViewWindow.cxx @@ -30,11 +30,10 @@ #include "VVTK_ViewModel.h" #include "VVTK_View.h" -#include "VISU_GaussPtsAct.h" - #include "SUIT_Session.h" #include "VVTK_Renderer.h" +#include "SVTK_Selector.h" #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_GenericRenderWindowInteractor.h" @@ -143,10 +142,7 @@ VVTK_ViewWindow bool theIsUpdate) { myMainWindow1->AddActor(theActor,theIsUpdate); - if(VISU_Actor* anAct = dynamic_cast(theActor)) - if(VISU::TActorFactory* aFactory = anAct->GetFactory()) - if(VISU_Actor* anActor = aFactory->CloneActor(anAct)) - myMainWindow2->AddActor(anActor,theIsUpdate); + myMainWindow2->AddActor(theActor,theIsUpdate); } //---------------------------------------------------------------------------- -- 2.39.2