// Static void method with same signature as "Main" is always // file base name: // /// <summary> /// VTK test Main method /// </summary> public static void vtkViewSelectionChangedEvtTest(string[] args) { bool interactive = false; foreach (string s in args) { // -I means "interactive" test -- do not automatically quit: // if (s == "-I") { interactive = true; } } SelectionChangedCallCount = 0; // Create an object to send an event: // Kitware.VTK.vtkGraphLayoutView view = Kitware.VTK.vtkGraphLayoutView.New(); Kitware.VTK.vtkRandomGraphSource g = Kitware.VTK.vtkRandomGraphSource.New(); Kitware.VTK.vtkVertexDegree f = Kitware.VTK.vtkVertexDegree.New(); view.SetLayoutStrategyToSimple2D(); f.SetInputConnection(g.GetOutputPort()); view.AddRepresentationFromInputConnection(f.GetOutputPort()); view.SetVertexLabelArrayName("VertexDegree"); view.VertexLabelVisibilityOn(); view.SetVertexColorArrayName("VertexDegree"); view.ColorVerticesOn(); view.GetRenderer().ResetCamera(); view.Update(); // Connect a new handler for the SelectionChanged event: // Kitware.VTK.vtkObject.vtkObjectEventHandler handler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(SelectionChanged); view.SelectionChangedEvt += handler; if (interactive) { view.GetInteractor().Start(); } // Disconnect them: // view.SelectionChangedEvt -= handler; // Dispose for proper RenderWindow clean up: // f.Dispose(); g.Dispose(); view.Dispose(); // if (2 != SelectionChangedCallCount) // { // throw new System.Exception(System.String.Format( // "error: SelectionChanged was called {0} times. Expected exactly 2 calls.", // SelectionChangedCallCount)); // } }
private void HookErrorWindowEvents() { if (null == this.ErrorWindow) { this.ErrorWindow = Kitware.VTK.vtkOutputWindow.GetInstance(); this.ErrorHandler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(ErrorWindow_ErrorHandler); this.ErrorWindow.ErrorEvt += this.ErrorHandler; } }
public void UnhookEvents() { this.UserStyle.KeyPressEvt -= this.UserHandler; this.UserStyle.CharEvt -= this.UserHandler; this.UserStyle.KeyReleaseEvt -= this.UserHandler; this.Interactor.AnyEvt -= this.InteractorHandler; this.UserHandler = null; this.UserStyle = null; this.InteractorHandler = null; this.Interactor = null; }
// Static void method with same signature as "Main" is always // file base name: // /// <summary> /// VTK test Main method /// </summary> public static void vtkObjectModifiedEvtTest(string[] args) { ObjectModifiedCallCount = 0; // Create an object to send an event: // Kitware.VTK.vtkActor2D sender = new Kitware.VTK.vtkActor2D(); // Connect a new handler for the Modified event: // Kitware.VTK.vtkObject.vtkObjectEventHandler handler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(ObjectModified); sender.ModifiedEvt += handler; // Trigger the event: // sender.Modified(); // Toggle Debug, trigger event again, then turn off Debug before objects are destroyed... // sender.SetDebug((byte)((0 == sender.GetDebug()) ? 1 : 0)); sender.Modified(); sender.DebugOff(); // Disconnect them: // sender.ModifiedEvt -= handler; if (2 != ObjectModifiedCallCount) { throw new System.Exception(System.String.Format( "error: ObjectModified was called {0} times. Expected exactly 2 calls.", ObjectModifiedCallCount)); } }
public void HookEvents() { this.HookErrorWindowEvents(); this.Interactor = this.renderWindowControl1.RenderWindow.GetInteractor(); this.InteractorHandler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(Interactor_AnyEventHandler); this.Interactor.AnyEvt += this.InteractorHandler; // Give our own style a higher priority than the built-in one // so that we see the events first: // float builtInPriority = this.Interactor.GetInteractorStyle().GetPriority(); this.UserStyle = Kitware.VTK.vtkInteractorStyleUser.New(); this.UserStyle.SetPriority(0.5f); this.UserStyle.SetInteractor(this.Interactor); this.UserHandler = new Kitware.VTK.vtkObject.vtkObjectEventHandler(UserStyle_MultipleEventHandler); // Keyboard events: this.UserStyle.KeyPressEvt += this.UserHandler; this.UserStyle.CharEvt += this.UserHandler; this.UserStyle.KeyReleaseEvt += this.UserHandler; }