[vtk-developers] New callbacks and multiple Tcl interps

Ken Martin ken.martin at kitware.com
Fri Oct 20 12:59:44 EDT 2000


I have checked in a couple of changes that may cause some dashboard 
challenges today. The first is some changes to the Tcl code to get rid of 
some old global variables that are dangerous and some new code to better 
support multiple Tcl interpreters. You can now create two instances with 
the same name as long as they are in different Tcl interpreters. At the 
same time I implemented the Subject/Observer design pattern for callbacks 
in VTK. I have left all the old callback functionality in, but the new 
style is much more flexible, centralized, less code etc. The Observers are 
notified using a vtkCommand which implements the Command design pattern. 
I've converted some of the old callbacks to use the new observer design 
which results in a smaller memory footprint for those objects.  Eventually 
I'd like to deprecate the old style callback methods such as

filter->SetStartMethod(void (*func)(void *), clientData);
filter->SetStartMethodArgDelete(void (*func)(void *));

with the new style

filter->AddObserver(vtkCommand::StartEvent, vtkCommand *cmd);

The new style also supports having multiple callbacks for each event. So 
there could be two Start callbacks or progress callbacks on an instance at 
the same time. This was not possible previously. Also the new style all 
callbacks are added through a method in vtkObject. You no longer need to 
add methods to the subclasses to allow developers to set a callback. 
Invoking a callback is pretty easy

this->InvokeEvent(vtkCommand::StartEvent,callData);


- Ken





More information about the vtk-developers mailing list