Hi Dieter,<br /><br />
as so often an example is worth a thousand words:
<pre> <span style=' color: Blue;'>private</span> <span style=' color: Blue;'>void</span> InteractorStyleUser() {
<span style=' color: Green;'>// Create a sphere. </span>
vtkSphereSource sphereSource = vtkSphereSource.New();
sphereSource.SetRadius(<span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.5</span>);
<span style=' color: Green;'>// retrieve renderWindow from our renderWindowControl</span>
vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
<span style=' color: Green;'>// define interactorStyle of type vtkInteractorStyleUser</span>
vtkInteractorStyleUser interactorStyleUser = vtkInteractorStyleUser.New();
<span style=' color: Green;'>// tell renderWindow to use our own interactorStyle</span>
renderWindow.GetInteractor().SetInteractorStyle(interactorStyleUser);
<span style=' color: Green;'>// define eventhandler</span>
interactorStyleUser.LeftButtonPressEvt += <span style=' color: Blue;'>new</span> vtkObject.vtkObjectEventHandler(interactorStyleUser_LeftButtonPressEvt);
interactorStyleUser.LeftButtonReleaseEvt += <span style=' color: Blue;'>new</span> vtkObject.vtkObjectEventHandler(interactorStyleUser_LeftButtonReleaseEvt);
interactorStyleUser.KeyPressEvt += <span style=' color: Blue;'>new</span> vtkObject.vtkObjectEventHandler(interactorStyleUser_KeyPressEvt);
<span style=' color: Green;'>/* here you can define more eventhandler
all available eventhandler are marked in Intellisense with a lightning symbol
to create the handler type for instance
interactorStyleUser.RightButtonPressEvt+=
and then press the tab key
the eventhandler method is being created automatically
*/</span>
<span style=' color: Green;'>// mapper</span>
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(sphereSource.GetOutputPort());
<span style=' color: Green;'>// actor</span>
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
renderer.SetBackground(<span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.3</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.2</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.1</span>);
renderer.AddActor(actor);
}
<span style=' color: Blue;'>void</span> interactorStyleUser_KeyPressEvt(vtkObject sender, vtkObjectEventArgs e) {
vtkInteractorStyleUser style = vtkInteractorStyleUser.New();
style = (vtkInteractorStyleUser)e.Caller;
<span style=' color: Blue;'>int</span> keyCode = style.GetChar();
<span style=' color: Blue;'>string</span> keySym = style.GetKeySym();
<span style=' color: Blue;'>bool</span> IsShiftKeyPressed = ( style.GetShiftKey() == <span style=' color: Maroon;'>1</span> ? <span style=' color: Maroon;'>true</span> : <span style=' color: Maroon;'>false</span> );
<span style=' color: Blue;'>bool</span> IsCtrlKeyPressed = ( style.GetCtrlKey() == <span style=' color: Maroon;'>1</span> ? <span style=' color: Maroon;'>true</span> : <span style=' color: Maroon;'>false</span> );
Debug.WriteLine(<span style=' color: Maroon;'>"keyCode: "</span> + keyCode);
Debug.WriteLine(<span style=' color: Maroon;'>"keySym: "</span> + keySym);
Debug.WriteLine(<span style=' color: Maroon;'>"shift key: "</span> + IsShiftKeyPressed);
Debug.WriteLine(<span style=' color: Maroon;'>"ctrl key: "</span> + IsCtrlKeyPressed);
}
<span style=' color: Blue;'>void</span> interactorStyleUser_LeftButtonReleaseEvt(vtkObject sender, vtkObjectEventArgs e) {
vtkInteractorStyleUser caller = vtkInteractorStyleUser.New();
caller = (vtkInteractorStyleUser)e.Caller;
<span style=' color: Blue;'>int</span>[] mousePosition = caller.GetLastPos();
Debug.WriteLine(<span style=' color: Maroon;'>"left mouse button released -> mouse position: "</span> + mousePosition[<span style=' color: Maroon;'>0</span>] + <span style=' color: Maroon;'>" "</span> + mousePosition[<span style=' color: Maroon;'>1</span>]);
}
<span style=' color: Blue;'>void</span> interactorStyleUser_LeftButtonPressEvt(vtkObject sender, vtkObjectEventArgs e) {
vtkInteractorStyleUser caller = vtkInteractorStyleUser.New();
caller = (vtkInteractorStyleUser)e.Caller;
<span style=' color: Blue;'>int</span>[] mousePosition = caller.GetLastPos();
Debug.WriteLine(<span style=' color: Maroon;'>"left mouse button pressed -> mouse position: "</span> + mousePosition[<span style=' color: Maroon;'>0</span>] + <span style=' color: Maroon;'>" "</span> + mousePosition[<span style=' color: Maroon;'>1</span>]);
}
</pre>
> And does anyone know if there is an official replacement for the factory<br />
><br />
> vtkStandardNewMacro(InteractorStyle)<br />
><br />
> I was using a simple static New here, which works, but probably is not dogmatic.<br />
<br />
There is no replacement in C# for vtkStandardNewMacro(...)<br /><br />
In C# it's just fine to instantiate a class the way you doing it:<br />
vtkObject myObject = vtkObject.New();<br /><br />
Note: All classes are static, that's the reason why you cannot inherit from any wrapped vtk class.<br />
But as I learned a few days ago there's a way to extent a static class.<br />
If you like I can show you how to do that.<br /><br />
with best regards<br />
Jochen
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/vtkCallbackCommand-in-ActiveViz-tp5714143p5714151.html">Re: vtkCallbackCommand in ActiveViz</a><br/>
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html">VTK - Users mailing list archive</a> at Nabble.com.<br/>