[vtkusers] SphereWidget InteractionEvent not triggered?

David Doria daviddoria at gmail.com
Fri Mar 8 09:05:27 EST 2013


On Thu, Mar 7, 2013 at 2:11 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
> David,
>
> On top of previous changes you need add an observer for event(s) you
> are interested.
> SphereWidget does it only for :
> vtkCommand::MouseMoveEvent,
>  vtkCommand::LeftButtonPressEvent,
> vtkCommand::LeftButtonReleaseEvent,
> vtkCommand::RightButtonPressEvent,
> vtkCommand::RightButtonReleaseEvent,
>
> In order to to it in event handler you already have You can do it in
> constructor in the referred example
>
> MySphereWidget::MySphereWidget()
> {
>   this->EventCallbackCommand->SetCallback( MySphereWidget::ProcessEvents );
>   this->AddObserver(vtkCommand::InteractionEvent, this->EventCallbackCommand);
>   this->AddObserver(vtkCommand::StartInteractionEvent,
> this->EventCallbackCommand);
> }
>
> A side note.
> Keep in mind that previous change is also required - somebody still
> needs to create InteractionEvent, etc.
> Normally this is done in  vtkSphereWidget::ProcessEvents or more
> precisely in the functions it calls
>
> Example is  OnLeftButtonUp().
> If you changed behavior of such function and call it directly from
> MySphereWidget::ProcessEvents
> So You should skip calling vtkSphereWidget::ProcessEvents in case  of
> vtkCommand::LeftButtonPressEvent
> or it will be called twice (in current implementation)
>
>     case vtkCommand::LeftButtonPressEvent:
>       std::cout << "LeftButtonPressEvent" << std::endl;
>       self->OnLeftButtonDown();
>       return; /// make sure parent process event is not called
>       break;
>     }
>
> Since currently in your new example you call parent class
> implementation of OnLeftButtonDown, it will invoke required by
> interaction
> process event, but if you want to change widget behavior you will be
> responsible to invoke  appropriate events.
>
> For example if you new implementation of OnLeftButtonDown still want
> to start some interaction it should be doing something like:
>
>   this->EventCallbackCommand->SetAbortFlag(1);
>   this->StartInteraction();
>   this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
>   this->Interactor->Render();
>
>
> Alex

We're getting closer...

I see what you're saying now that the widget is generating these
events in it's On*Button*() functions. As a first step, I just want to
show how to handle the events that are already generated (and not
reimplement the functions that actually generate them, as I was
accidentally doing).

This shows that InteractionEvent and EndInteractionEvent are behaving
as I'd expect:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/SphereWidgetEvents

That is, when I have the left mouse button held down and move the
mouse around, InteractionEvent is repeatedly triggered. When I release
the left mouse button, EndInteractionEvent is triggered. However, if
you uncomment the AddObserver line for StartInteractionEvent, when I
click the left mouse button, StartInteractionEvent is triggered, but
when I release it, EndInteractionEvent is no longer triggered. Then
even with the mouse button released, the sphere still drags around as
it does normally when the mouse button is held down. Can you explain
this? I am not doing anything different with this event than the
others - shouldn't it just produce the std::cout <<
"StartInteractionEvent" << std::endl; output and then proceed as
normal?

David



More information about the vtkusers mailing list