UNPKG

paraview-glance

Version:

Web application for Visualizing Scientific and Medical datasets

109 lines (87 loc) 3.47 kB
import macro from 'vtk.js/Sources/macro'; import vtkAbstractWidgetFactory from 'vtk.js/Sources/Widgets/Core/AbstractWidgetFactory'; import vtkPlanePointManipulator from 'vtk.js/Sources/Widgets/Manipulators/PlaneManipulator'; import vtkSphereHandleRepresentation from 'vtk.js/Sources/Widgets/Representations/SphereHandleRepresentation'; import widgetBehavior from 'paraview-glance/src/vtk/TextWidget/behavior'; import stateGenerator from 'paraview-glance/src/vtk/TextWidget/state'; import vtkSVGCircleHandleRepresentation from 'paraview-glance/src/vtk/SVGCircleHandleRepresentation'; import vtkSVGLabelRepresentation from 'paraview-glance/src/vtk/SVGLabelRepresentation'; import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'; // ---------------------------------------------------------------------------- // Factory // ---------------------------------------------------------------------------- function vtkTextWidget(publicAPI, model) { model.classHierarchy.push('vtkDistanceWidget'); // --- Widget Requirement --------------------------------------------------- model.methodsToLink = [ 'activeScaleFactor', 'activeColor', 'useActiveColor', 'defaultScale', 'circleProps', 'textProps', 'text', 'textStateIndex', 'handleScale', ]; model.behavior = widgetBehavior; model.widgetState = stateGenerator(); publicAPI.getRepresentationsForViewType = (viewType) => { switch (viewType) { case ViewTypes.DEFAULT: case ViewTypes.GEOMETRY: case ViewTypes.SLICE: case ViewTypes.VOLUME: default: return [ { builder: vtkSphereHandleRepresentation, labels: ['handles'], initialValues: { scaleInPixels: true, }, }, { builder: vtkSphereHandleRepresentation, labels: ['moveHandle'], }, { builder: vtkSVGCircleHandleRepresentation, labels: ['handles', 'moveHandle'], }, { builder: vtkSVGLabelRepresentation, labels: ['handles'], }, ]; } }; // -------------------------------------------------------------------------- // initialization // -------------------------------------------------------------------------- model.widgetState.onBoundsChange((bounds) => { const center = [ (bounds[0] + bounds[1]) * 0.5, (bounds[2] + bounds[3]) * 0.5, (bounds[4] + bounds[5]) * 0.5, ]; model.widgetState.getMoveHandle().setOrigin(center); }); // Default manipulator model.manipulator = vtkPlanePointManipulator.newInstance(); } // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { // manipulator: null, }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues); macro.setGet(publicAPI, model, ['manipulator']); vtkTextWidget(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkTextWidget'); // ---------------------------------------------------------------------------- export default { newInstance, extend };