AbstractWidget

The abstract class that implements some shared functionality used by widgets. In
reality, there aren’t any abstract methods to implement, as widgets are
constructed via vtkAbstractWidgetFactory.

vtkAbstractWidget extends from vtkInteractorObserver.

getWidgetManager()

Returns the widget manager the widget has been registered into.

setWidgetManager(widgetManager)

Automatically called by the widget manager when widget is registered.

getViewWidgets()

Returns all the registered view widgets of the factory.
A widget is registered when added to a view (i.e. widgetManager).

Source

Constants.js
export const WIDGET_PRIORITY = 0.5;

export default { WIDGET_PRIORITY };
index.js
import macro from 'vtk.js/Sources/macro';
import vtkInteractorObserver from 'vtk.js/Sources/Rendering/Core/InteractorObserver';
import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop';

import { RenderingTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
import { WIDGET_PRIORITY } from 'vtk.js/Sources/Widgets/Core/AbstractWidget/Constants';

// ----------------------------------------------------------------------------

function vtkAbstractWidget(publicAPI, model) {
model.classHierarchy.push('vtkAbstractWidget');
model.actorToRepresentationMap = new WeakMap();

// --------------------------------------------------------------------------
publicAPI.getBounds = model.widgetState.getBounds;
publicAPI.getNestedProps = () => model.representations;
// --------------------------------------------------------------------------

publicAPI.activateHandle = ({ selectedState, representation }) => {
model.widgetState.activateOnly(selectedState);
model.activeState = selectedState;
if (selectedState && selectedState.updateManipulator) {
selectedState.updateManipulator();
}
publicAPI.invokeActivateHandle({ selectedState, representation });
if (publicAPI.updateCursor) {
publicAPI.updateCursor();
}
};

// --------------------------------------------------------------------------

publicAPI.deactivateAllHandles = () => {
model.widgetState.deactivate();
};

// --------------------------------------------------------------------------

publicAPI.hasActor = (actor) => model.actorToRepresentationMap.has(actor);

// --------------------------------------------------------------------------

publicAPI.grabFocus = () => {
model.hasFocus = true;
};
publicAPI.loseFocus = () => {
model.hasFocus = false;
};
publicAPI.hasFocus = () => model.hasFocus;

// --------------------------------------------------------------------------

publicAPI.placeWidget = (bounds) => model.widgetState.placeWidget(bounds);
publicAPI.getPlaceFactor = () => model.widgetState.getPlaceFactor();
publicAPI.setPlaceFactor = (factor) =>
model.widgetState.setPlaceFactor(factor);

// --------------------------------------------------------------------------

publicAPI.getRepresentationFromActor = (actor) =>
model.actorToRepresentationMap.get(actor);

// --------------------------------------------------------------------------

publicAPI.updateRepresentationForRender = (
renderingType = RenderingTypes.FRONT_BUFFER
) => {
for (let i = 0; i < model.representations.length; i++) {
const representation = model.representations[i];
representation.updateActorVisibility(
renderingType,
model.visibility,
model.contextVisibility,
model.handleVisibility
);
}
};

publicAPI.getViewWidgets = () => {
return model.factory
.getViewIds()
.map((viewId) => model.factory.getWidgetForView({ viewId }));
};

// --------------------------------------------------------------------------
// Initialization calls
// --------------------------------------------------------------------------

publicAPI.setPriority(WIDGET_PRIORITY);
}

// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
contextVisibility: true,
handleVisibility: true,
hasFocus: false,
};

/**
* @param {*} publicAPI public methods to populate
* @param {*} model internal values to populate
* @param {object} initialValues Contains at least
* {viewType, renderer, camera, openGLRenderWindow, factory}
*/
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

vtkProp.extend(publicAPI, model, initialValues);
vtkInteractorObserver.extend(publicAPI, model, initialValues);

macro.setGet(publicAPI, model, [
'contextVisibility',
'handleVisibility',
'widgetManager',
]);
macro.get(publicAPI, model, ['representations', 'widgetState']);
macro.event(publicAPI, model, 'ActivateHandle');

vtkAbstractWidget(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkAbstractWidget');

// ----------------------------------------------------------------------------

export default { newInstance, extend };