<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi David,<br>
    <br>
    The only reason that I would argue that it's a bug is that the
    behavior of the interactor style is different from other styles (as
    pointed out in my first post). This is unexpected, especially fro a
    newcomer to VTK programming. I shouldn't have to know about the
    internals of the implementation of the class to be able to use it
    effectively. For example, instead of being a container for other
    styles, vtkInteractorStyleSwitch could have been written as a
    "union" of the code of all four classes and then the behavior would
    have been identical to other interactor style classes. So the design
    decision of the implementation shouldn't affect how the interface
    behaves. The support for AddObserver() in vtkInteractorStyleSwitch
    implies that adding an observer will work, but it doesn't and it's
    not documented as such.<br>
    <br>
    Possible fixes for this. If AddObserver() were virtual (but it's
    not), vtkInteractorStyleSwitch could have overridden it and relayed
    the observers to it's members. Alternatively, if it had made its
    interactor style members accessible, users of the class would be
    aware of its container-style design and added the observers to the
    members instead of the StyleSwitch parent. Documenting that
    AddObserver() doesn't work for this class would help too.<br>
    <br>
    As it stands, I "fixed it" by subclassing the
    vtkInteractorStyleSwitch class to get access to the protected
    interactor style members and wrote a AddObserverToAllStyles()
    method. I ended up having to examine the code to figure it all out,
    which cost me a lot of wasted time trying to figure out why it
    didn't work in the first place. Maybe that could be considered as a
    future enhancement or at least exposing the contained styles to
    avoid the subclassing.<br>
    <br>
    Thanks for your reply.<br>
    <br>
    <div class="moz-cite-prefix">On 8/2/2013 5:13 AM, David Cole wrote:<br>
    </div>
    <blockquote
      cite="mid:201308020932.r729WAPH006276@emissary.infolytica.com"
      type="cite">
      <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>
      <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>&gt; I have the following code in my application to set up
          handling of the right</div>
        <div>&gt; mouse button up event to display a context menu:<br>
          <title>Snippet</title>
        </div>
        <pre style="background: white; color: black; font-family: Consolas;">&gt;   <span style="color: navy;">m_vtkInteractorStyle</span>= <span style="color: blue;">vtkInteractorStyleSwitch</span>::<span style="color: rgb(136, 0, 0);">New</span>();
&gt;   m<span style="color: navy;">_vtkInteractorStyle</span>-&gt;<span style="color: rgb(136, 0, 0);">SetCurrentStyleToTrackballCamera</span>();
&gt;   <span style="color: navy;">m_vtkInteractorStyle</span>-&gt;<span style="color: rgb(136, 0, 0);">AddObserver</span>( ...</pre>
        <div>&gt; However, the command's Execute() method is never
          called (it's not called</div>
        <div>&gt; 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>
          &gt; 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: &quot;Segoe UI
            Symbol&quot;,&quot;Apple Color Emoji&quot;;"
            data-externalstyle="false">😊</span></div>
        <div> </div>
        <div> </div>
        <div>Hope this helps,</div>
        <div>David C.</div>
        <div> </div>
        <div><br>
        </div>
      </div>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Signature</title>
      <a href="http:://www.infolytica.com">www.infolytica.com </a><br>
      300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3<br>
      (514) 849-8752 x236, Fax: (514) 849-4239
    </div>
  </body>
</html>