[vtkusers] Re: RightButtonReleaseEvent not generated with vtkInteractorStyleSwitch?

David Cole dlrdave at aol.com
Fri Aug 2 05:13:07 EDT 2013


> I have the following code in my application to set up handling of the right

> mouse button up event to display a context menu:
Snippet 
>   m_vtkInteractorStyle= vtkInteractorStyleSwitch::New();
>   m_vtkInteractorStyle->SetCurrentStyleToTrackballCamera();
>   m_vtkInteractorStyle->AddObserver( ...

> However, the command's Execute() method is never called (it's not called

> for the Press event either).



If you look at the source code for vtkInteractorStyleSwitch, you’ll see this in the header file:

  vtkInteractorStyleJoystickActor *JoystickActor;
  vtkInteractorStyleJoystickCamera *JoystickCamera;
  vtkInteractorStyleTrackballActor *TrackballActor;
  vtkInteractorStyleTrackballCamera *TrackballCamera;
  vtkInteractorStyle* CurrentStyle;


The “Switch” class really just has 4 sub-objects that it creates, one of which is “Current” at any given time, and then takes care of allowing an end user to switch among them easily using keystrokes.


If you want to receive events from the current style object, then you will have to call AddObserver on that particular sub-object rather than on the vtkInteractorStyleSwitch object. You could either use this knowledge to build something that listens to events on all the sub-objects, or perhaps you could switch your event listeners at style-switch time, if there’s a way to detect that. I don’t see explicit code in the implementation that invokes any events at style switch time, but there might be a way to detect it. If nothing else, you could cache the current style in your own var and then inspect the value in the switch object periodically to see if it has changed...



> Is this a bug? I'm using VTK 5.10. Thanks.


In one sense, it is a bug, since you expected it to behave differently than it does. But... in another sense, it’s not a bug, since it’s working exactly as intended by the writer of this class. (The writer of the class just wanted an easy way to switch between different types of interactors and did not intend for users of the class to listen to all possible events from all of the sub-objects...)


You could certainly add functionality to this class to proxy events from the sub-objects out to listeners of the switch class itself... but this would be quite a bit of work. I’m sure if you wanted to tackle it, though, there would be VTK devs willing to review a gerrit patch to introduce such functionality. 😊



Hope this helps,

David C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130802/5aa5144c/attachment.htm>


More information about the vtkusers mailing list