FreeMat

- Main Page
- Related Pages

vtkWidgetSet

Section: Visualization Toolkit Widget Classes

# Usage

The class synchronizes a set of vtkAbstractWidget(s). Widgets typically invoke "Actions" that drive the geometry/behaviour of their representations in response to interactor events. Interactor interactions on a render window are mapped into "Callbacks" by the widget, from which "Actions" are dispatched to the entire set. This architecture allows us to tie widgets existing in different render windows together. For instance a HandleWidget might exist on the sagittal view. Moving it around should update the representations of the corresponding handle widget that lies on the axial and coronal and volume views as well.

.SECTION User API A user would use this class as follows.

     vtkWidgetSet *set = vtkWidgetSet::New();
     vtkParallelopipedWidget *w1 = vtkParallelopipedWidget::New();
     set->AddWidget(w1);
     w1->SetInteractor(axialRenderWindow->GetInteractor());
     vtkParallelopipedWidget *w2 = vtkParallelopipedWidget::New();
     set->AddWidget(w2);
     w2->SetInteractor(coronalRenderWindow->GetInteractor());
     vtkParallelopipedWidget *w3 = vtkParallelopipedWidget::New();
     set->AddWidget(w3);
     w3->SetInteractor(sagittalRenderWindow->GetInteractor());
     set->SetEnabled(1);

.SECTION Motivation The motivation for this class is really to provide a usable API to tie together multiple widgets of the same kind. To enable this, subclasses of vtkAbstractWidget, must be written as follows: They will generally have callback methods mapped to some user interaction such as:

     this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent,
                             vtkEvent::NoModifier, 0, 0, NULL,
                             vtkPaintbrushWidget::BeginDrawStrokeEvent,
                             this, vtkPaintbrushWidget::BeginDrawCallback);

The callback invoked when the left button is pressed looks like:

     void vtkPaintbrushWidget::BeginDrawCallback(vtkAbstractWidget *w)
     {
       vtkPaintbrushWidget *self = vtkPaintbrushWidget::SafeDownCast(w);
       self->WidgetSet->DispatchAction(self, &vtkPaintbrushWidget::BeginDrawAction);
     }

The actual code for handling the drawing is written in the BeginDrawAction method.

     void vtkPaintbrushWidget::BeginDrawAction( vtkPaintbrushWidget *dispatcher)
     {
     // Do stuff to draw...
     // Here dispatcher is the widget that was interacted with, the one that
     // dispatched an action to all the other widgets in its group. You may, if
     // necessary find it helpful to get parameters from it.
     //   For instance for a ResizeAction:
     //     if (this != dispatcher)
     //       {
     //       double *newsize = dispatcher->GetRepresentation()->GetSize();
     //       this->WidgetRep->SetSize(newsize);
     //       }
     //     else
     //       {
     //       this->WidgetRep->IncrementSizeByDelta();
     //       }
     }

To create an instance of class vtkWidgetSet, simply invoke its constructor as follows

      obj = vtkWidgetSet

# Methods

The class vtkWidgetSet has several methods that can be used. They are listed below. Note that the documentation is translated automatically from the VTK sources, and may not be completely intelligible. When in doubt, consult the VTK website. In the methods listed below, `obj` is an instance of the vtkWidgetSet class.

- `string = obj.GetClassName ()` - Standard methods for a VTK class.
- `int = obj.IsA (string name)` - Standard methods for a VTK class.
- `vtkWidgetSet = obj.NewInstance ()` - Standard methods for a VTK class.
- `vtkWidgetSet = obj.SafeDownCast (vtkObject o)` - Standard methods for a VTK class.
- `obj.SetEnabled (int )` - Method for activiating and deactiviating all widgets in the group.
- `obj.EnabledOn ()` - Method for activiating and deactiviating all widgets in the group.
- `obj.EnabledOff ()` - Method for activiating and deactiviating all widgets in the group.
- `obj.AddWidget (vtkAbstractWidget )` - Add a widget to the set.
- `obj.RemoveWidget (vtkAbstractWidget )` - Remove a widget from the set
- `int = obj.GetNumberOfWidgets ()` - Get number of widgets in the set.
- `vtkAbstractWidget = obj.GetNthWidget (int )` - Get the Nth widget in the set.