<html><head><style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst, p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle, p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style></head><body><div data-externalstyle="false" dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt;"><div>> I have the following code in my application to set up handling of
the right</div><div>> mouse button up event to display a context menu:<br>
<title>Snippet</title>
</div><pre style="background: white; color: black; font-family: Consolas;">> <span style="color: navy;">m_vtkInteractorStyle</span>= <span style="color: blue;">vtkInteractorStyleSwitch</span>::<span style="color: rgb(136, 0, 0);">New</span>();
> m<span style="color: navy;">_vtkInteractorStyle</span>-><span style="color: rgb(136, 0, 0);">SetCurrentStyleToTrackballCamera</span>();
> <span style="color: navy;">m_vtkInteractorStyle</span>-><span style="color: rgb(136, 0, 0);">AddObserver</span>( ...</pre><div>> However, the command's Execute() method is never called (it's not
called</div><div>> for the Press event either).<br>
</div><div> </div><div>If you look at the source code for vtkInteractorStyleSwitch, you’ll see this in the header file:</div><div> vtkInteractorStyleJoystickActor *JoystickActor;<br> vtkInteractorStyleJoystickCamera *JoystickCamera;<br> vtkInteractorStyleTrackballActor *TrackballActor;<br> vtkInteractorStyleTrackballCamera *TrackballCamera;<br> vtkInteractorStyle* CurrentStyle;<br></div><div>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.</div><div> </div><div>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...</div><div><br>
<br>
> Is this a bug? I'm using VTK 5.10. Thanks.<br>
</div><div>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...)</div><div> </div><div>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. <span style='font-family: "Segoe UI Symbol","Apple Color Emoji";' data-externalstyle="false">😊</span></div><div> </div><div> </div><div>Hope this helps,</div><div>David C.</div><div> </div><div><br>
</div></div></body></html>