[vtkusers] Tcl event callbacks

Goodwin Lawlor goodwin.lawlor at ucd.ie
Fri May 14 15:49:34 EDT 2004


Hi All,

There's a small change just checked into CVS that's handy when using the
Observer/Callback mechanism in VTK with Tcl.

If a callback returns with

return -code -1

then subsequent callbacks observing an event are not fired. Its the same as
"vtkCommand *command->AbortFlagOn()" in C++.

For example, if you want the first callback observing an EndPickEvent of a
vtkCellPicker to check if the "f" or "p" key was pressed you could have:

vtkRenderWindowInteractor iren
    iren SetPicker picker
vtkCellPicker picker
    picker AddObserver EndPickEvent cbCheckKey
    picker AddObserver EndPickEvent cbDisplayPoint

proc cbCheckKey {} {
    if {[iren GetKeySym] == "f"} {
        return -code -1
    }
}

proc cbDisplayPoint {}{
    puts "You picked point: [picker GetPickPosition]"
}

If the "f" key is pressed then the cbDisplayPoint callback is not executed,
because cbCheckKey has set the abort flag.

hth someone,

Goodwin




More information about the vtkusers mailing list