Commit 90d2aea5 authored by Jeff Baumes's avatar Jeff Baumes
Browse files

ENH: Add a PassiveObserver flag to vtkCommand. Passive observers do not...

ENH: Add a PassiveObserver flag to vtkCommand.  Passive observers do not change the system state, and always get events, even if another command has focus.  Change vtkObject to process passive observers first.
ENH: Change vtkInteractorEventRecorder to have PassiveObserver commands.
ENH: Change InteractorStyleTreeMapHover to use the vtkInteractorEventRecorder.
parent daf0f361
......@@ -97,7 +97,7 @@ static const char *vtkCommandEventStrings[] = {
};
//----------------------------------------------------------------
vtkCommand::vtkCommand():AbortFlag(0)
vtkCommand::vtkCommand():AbortFlag(0),PassiveObserver(0)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass("vtkCommand or subclass");
......
......@@ -92,6 +92,20 @@ public:
void AbortFlagOff()
{ this->SetAbortFlag(0); }
// Description:
// Set/Get the passive observer flag. If this is set to true, this
// indicates that this command does not change the state of the
// system in any way. Passive observers are processed first, and
// are not called even when another command has focus.
void SetPassiveObserver(int f)
{ this->PassiveObserver = f; }
int GetPassiveObserver()
{ return this->PassiveObserver; }
void PassiveObserverOn()
{ this->SetPassiveObserver(1); }
void PassiveObserverOff()
{ this->SetPassiveObserver(0); }
//BTX
// Description:
// All the currently defined events are listed here. Developers can
......@@ -179,6 +193,8 @@ public:
protected:
int AbortFlag;
int PassiveObserver;
vtkCommand();
virtual ~vtkCommand() {}
......
......@@ -21,7 +21,7 @@
#include <vtkstd/map>
vtkCxxRevisionMacro(vtkObject, "1.100");
vtkCxxRevisionMacro(vtkObject, "1.101");
// Initialize static member that controls warning display
static int vtkObjectGlobalWarningDisplay = 1;
......@@ -490,7 +490,13 @@ int vtkSubjectHelper::InvokeEvent(unsigned long event, void *callData,
elem = elem->Next;
}
// Loop once or twice, giving preference to focus holders, if any.
// Loop two or three times, giving preference to passive observers
// and focus holders, if any.
//
// 0. Passive observer loop
// Loop over all observers and execute those that are passive observers.
// These observers should not affect the state of the system in any way,
// and should not be allowed to abort the event.
//
// 1. Focus loop
// If there is a focus holder, loop over all observers and execute
......@@ -502,12 +508,41 @@ int vtkSubjectHelper::InvokeEvent(unsigned long event, void *callData,
// remaining observers. This loop will always get executed when there
// is no focus holder.
// 0. Passive observer loop
//
elem = this->Start;
vtkObserver *next;
while (elem)
{
// store the next pointer because elem could disappear due to Command
next = elem->Next;
VisitedMapType::iterator vIter = visited.find(elem->Tag);
if ((vIter != visited.end()) && (vIter->second == false) &&
elem->Command->GetPassiveObserver() &&
(elem->Event == event || elem->Event == vtkCommand::AnyEvent))
{
vIter->second = true;;
vtkCommand* command = elem->Command;
command->Register(command);
elem->Command->Execute(self,event,callData);
command->UnRegister();
}
if (this->ListModified)
{
elem = this->Start;
this->ListModified = 0;
}
else
{
elem = next;
}
}
// 1. Focus loop
//
if (this->Focus1 || this->Focus2)
{
elem = this->Start;
vtkObserver *next;
while (elem)
{
// store the next pointer because elem could disappear due to Command
......@@ -550,13 +585,13 @@ int vtkSubjectHelper::InvokeEvent(unsigned long event, void *callData,
if (!focusHandled)
{
elem = this->Start;
vtkObserver *next;
while (elem)
{
// store the next pointer because elem could disappear due to Command
next = elem->Next;
VisitedMapType::iterator vIter = visited.find(elem->Tag);
if ((vIter != visited.end()) && (vIter->second == false) &&
!elem->Command->GetPassiveObserver() &&
(elem->Event == event || elem->Event == vtkCommand::AnyEvent))
{
vIter->second = true;;
......
......@@ -39,7 +39,7 @@
#include "vtkWorldPointPicker.h"
#include "vtkVariant.h"
vtkCxxRevisionMacro(vtkInteractorStyleTreeMapHover, "1.11");
vtkCxxRevisionMacro(vtkInteractorStyleTreeMapHover, "1.12");
vtkStandardNewMacro(vtkInteractorStyleTreeMapHover);
//----------------------------------------------------------------------------
......@@ -331,6 +331,23 @@ void vtkInteractorStyleTreeMapHover::OnLeftButtonUp()
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);
#if 0
vtkRenderer* r = this->CurrentRenderer;
if (r == NULL)
{
return;
}
if (!r->HasViewProp(this->Balloon))
{
r->AddActor(this->Balloon);
this->Balloon->SetRenderer(r);
}
double loc[2] = {x, y};
this->Balloon->EndWidgetInteraction(loc);
#endif
this->CurrentSelectedId = GetTreeMapIdAtPos(x,y);
// Get the pedigree id of this object and
......
......@@ -19,7 +19,7 @@
#include <vtksys/ios/sstream>
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.12");
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.13");
vtkStandardNewMacro(vtkInteractorEventRecorder);
float vtkInteractorEventRecorder::StreamVersion = 1.0;
......@@ -30,10 +30,11 @@ vtkInteractorEventRecorder::vtkInteractorEventRecorder()
//take over the processing of delete and keypress events from the superclass
this->KeyPressCallbackCommand->SetCallback(
vtkInteractorEventRecorder::ProcessCharEvent);
this->EventCallbackCommand->SetPassiveObserver(1); // get events first
this->Priority = VTK_LARGE_FLOAT; //get events first
this->EventCallbackCommand->SetCallback(
vtkInteractorEventRecorder::ProcessEvents);
this->EventCallbackCommand->SetPassiveObserver(1); // get events first
this->FileName = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment