From a68879baf7ae9a4d883f2a0525f9d3fb7038b767 Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 22 Sep 2005 05:44:51 +0000 Subject: [PATCH] Implementation of InteractorObserver functionality for the GaussPoints Actor class --- src/OBJECT/VISU_ActorFactory.h | 5 +- src/OBJECT/VISU_GaussPtsAct.cxx | 95 ++++++++++++++++++++++++++++++++- src/OBJECT/VISU_GaussPtsAct.h | 43 +++++++++++++-- 3 files changed, 137 insertions(+), 6 deletions(-) diff --git a/src/OBJECT/VISU_ActorFactory.h b/src/OBJECT/VISU_ActorFactory.h index a41cbfed..a23cbe64 100644 --- a/src/OBJECT/VISU_ActorFactory.h +++ b/src/OBJECT/VISU_ActorFactory.h @@ -48,6 +48,10 @@ namespace VISU void UpdateActor(VISU_Actor* theActor) = 0; + virtual + void + UpdateFromActor(VISU_Actor* theActor) = 0; + virtual void SetImplicitFunction(VISU_Actor* theActor, @@ -55,5 +59,4 @@ namespace VISU }; } - #endif //VISU_ACTOR_FACTORY_H diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 8489cc3b..1b1ce339 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -32,6 +32,7 @@ #include "SVTK_Actor.h" +#include #include #include #include @@ -48,12 +49,15 @@ #include #include +#include #include +#include #include +#include #include -#include #include +#include #include #include @@ -235,6 +239,8 @@ vtkStandardNewMacro(VISU_GaussPtsAct); VISU_GaussPtsAct ::VISU_GaussPtsAct(): + myInteractorObserver(vtkInteractorObserver::New()), + myEventCallbackCommand(vtkCallbackCommand::New()), myPSMapper(VISU_OpenGLPointSpriteMapper::New()), myGaussPointsPL(NULL), myTextMapper(vtkTextMapper::New()), @@ -245,6 +251,12 @@ VISU_GaussPtsAct mySphereActor(vtkActor::New()), myCursorPyramid(VISU_CursorPyramid::New()) { + myInteractorObserver->Delete(); + myEventCallbackCommand->Delete(); + + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents); + myTextMapper->Delete(); myTextActor->Delete(); myPSMapper->Delete(); @@ -356,6 +368,16 @@ VISU_GaussPtsAct Superclass::SetPipeLine(thePipeLine); } +void +VISU_GaussPtsAct +::SetFactory(VISU::TActorFactory* theActorFactory) +{ + VISU_Actor::SetFactory(theActorFactory); + myUpdatePrs3dSignal.connect(boost::bind(&VISU::TActorFactory::UpdateFromActor, + theActorFactory, + _1)); +} + VISU_GaussPointsPL* VISU_GaussPtsAct ::GetGaussPointsPL() @@ -363,6 +385,75 @@ VISU_GaussPtsAct return myGaussPointsPL.GetPointer(); } +bool +VISU_GaussPtsAct +::ChangeMagnification() +{ + return myChangeMagnification; +} + + +//---------------------------------------------------------------------------- +void +VISU_GaussPtsAct +::SetInteractor(vtkRenderWindowInteractor* theInteractor) +{ + if(theInteractor == myInteractor) + return; + + if(myInteractor) + myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer()); + + + if(theInteractor) + theInteractor->AddObserver(vtkCommand::CharEvent, + myEventCallbackCommand.GetPointer(), + 0.0); + + + Superclass::SetInteractor(theInteractor); + + Modified(); +} + +void +VISU_GaussPtsAct +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + if(vtkObject* anObject = reinterpret_cast(theClientData)) + if(VISU_GaussPtsAct* self = dynamic_cast(anObject)) + self->OnInteractorEvent(theEvent); +} + +void +VISU_GaussPtsAct +::OnInteractorEvent(unsigned long theEvent) +{ + switch(theEvent){ + case vtkCommand::CharEvent: { + switch(myInteractor->GetKeyCode()) { + case 'm' : + case 'M' : + myChangeMagnification = true; + break; + case 'n' : + case 'N' : + myChangeMagnification = false; + break; + default: + return; + } + myUpdatePrs3dSignal(this); + return; + } + break; + } +} + + //---------------------------------------------------------------- bool VISU_GaussPtsAct @@ -502,7 +593,7 @@ VISU_GaussPtsAct Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; mySelectionMode = aSelectionMode; // - if(aSelectionMode==ActorSelection ){ //|| !theIsHighlight) { + if(aSelectionMode == ActorSelection ){ myTextActor->SetVisibility(aTextVisibility); mySphereActor->SetVisibility(aSphereVisibility); mySphereActorSelected->SetVisibility(aSphereVisibilitySelected); diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 37c1d347..d7f9e78e 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -45,10 +45,15 @@ class vtkInteractorStyle; class VISU_CursorPyramid; class VISU_GPTextActor; -//xxx + class vtkUnstructuredGrid; class vtkDataSetMapper; -//xxx + +class vtkInteractorObserver; +class vtkCallbackCommand; + + +//---------------------------------------------------------------------------- class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct { public: @@ -58,13 +63,22 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct VISU_GaussPtsAct* New(); + //---------------------------------------------------------------------------- virtual void SetPipeLine(VISU_PipeLine* thePipeLine) ; + virtual + void + SetFactory(VISU::TActorFactory* theActorFactory); + VISU_GaussPointsPL* GetGaussPointsPL(); + bool + ChangeMagnification(); + + //---------------------------------------------------------------------------- virtual void AddToRender(vtkRenderer* theRenderer); @@ -73,6 +87,11 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct void RemoveFromRender(vtkRenderer* theRenderer); + virtual + void + SetInteractor(vtkRenderWindowInteractor* theInteractor); + + //---------------------------------------------------------------------------- virtual bool PreHighlight(SVTK_Selector* theSelector, @@ -86,6 +105,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight); + //---------------------------------------------------------------------------- protected: VISU_GaussPtsAct(); @@ -96,8 +116,25 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct void SetMapperInput(vtkDataSet* theDataSet); - vtkSmartPointer myPSMapper; + //---------------------------------------------------------------------------- + vtkSmartPointer myInteractorObserver; + vtkSmartPointer myEventCallbackCommand; + // Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + void + OnInteractorEvent(unsigned long theEvent); + + boost::signal1 myUpdatePrs3dSignal; + bool myChangeMagnification; + + //---------------------------------------------------------------------------- + vtkSmartPointer myPSMapper; vtkSmartPointer myGaussPointsPL; vtkSmartPointer myTextMapper; -- 2.39.2