Menu

virtual methods

Help
aperture3
2006-10-20
2013-04-25
  • aperture3

    aperture3 - 2006-10-20

    I have created a custom interactor style that is derived from vtkInteractorStyleSwitch. I am attempting to override the virtual void OnChar() method but am running into the error:
    cannot override inherited member 'vtk.vtkInteractorStyle.OnChar()' because it is not marked virtual, abstract, or override
    Has anyone else had any success with virtual overrides? Is it possible?

     
    • Andrew Dolgert

      Andrew Dolgert - 2006-10-21

      Hi. It won't be possible to override methods on the wrapper classes the way they are compiled now. The error message is correct that the wrapper code needs the virtual keyword in order for overrides to work. It isn't difficult to add the virtual keyword to the wrappers, but it probably won't help.

      In C++, you can change the behavior of a vtkInteractorStyle by deriving a subclass. Even if we add the virtual keyword to the wrappers, this won't work right away for the managed version. We would need to implement a special native C++ class that knows how to call managed wrappers. I don't know of a good way around this. Is there another way to customize the interactor?

      - Drew

       
    • aperture3

      aperture3 - 2006-10-23

      Thanks for the information. I have spoken to some others here at the office and they agree with your comments. The only suggestion that was made was about SWIG. SWIGs latest version has a feature called 'directors' that allows for wrapped objects to be overridden.
      I am going to look into the use of notifications and callbacks today. In the worst case I will have to add a c++ class to the vtk project and then wrap it.
      I will post my findings on the forum.

       
    • aperture3

      aperture3 - 2006-10-23

      Solution for virtual overrides in the interaction classes.

      As this thread has discussed it is not possible to extend a class on the c# side of the wrappers because:
      1) Virtual methods are not wrapped as virtual.
      2) The wrapping is just a proxy. New objects that are derived from wrapped objects can not be passed across the proxy layer intact. The native (c++) code will not deal with the derived class properly.

      The solution to this problem is as simple as adding an observer to the vtkInteractorStyle for the events that you want to extend. When one observes a vtkInteractorStyle for a specific event such as OnChar (vtk.EventIds.CharEvent), the event is not only observed, but the existing interaction operation is replaced with your observer callback.

      This behavior will allow developers to essentially override any of the interactor events without deriving a new class on the C# side of the code.

      The 'ControlSample' includes example code for adding observers.

       

Log in to post a comment.