UNPKG

@acransac/vtk.js

Version:

Visualization Toolkit for the Web

113 lines (92 loc) 3.89 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 vtkCircleContextRepresentation from 'vtk.js/Sources/Widgets/Representations/CircleContextRepresentation'; import widgetBehavior from 'vtk.js/Sources/Widgets/Widgets3D/EllipseWidget/behavior'; import stateGenerator from 'vtk.js/Sources/Widgets/Widgets3D/EllipseWidget/state'; import SHAPE_DEFAULT_VALUES from 'vtk.js/Sources/Widgets/Widgets3D/ShapeWidget'; import { BehaviorCategory, ShapeBehavior, } from 'vtk.js/Sources/Widgets/Widgets3D/ShapeWidget/Constants'; import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'; // ---------------------------------------------------------------------------- // Factory // ---------------------------------------------------------------------------- function vtkEllipseWidget(publicAPI, model) { model.classHierarchy.push('vtkEllipseWidget'); // --- Widget Requirement --------------------------------------------------- model.methodsToLink = [ 'activeScaleFactor', 'activeColor', 'useActiveColor', 'glyphResolution', 'defaultScale', 'drawBorder', 'drawFace', 'opacity', ]; model.behavior = widgetBehavior; publicAPI.getRepresentationsForViewType = (viewType) => { switch (viewType) { case ViewTypes.DEFAULT: case ViewTypes.GEOMETRY: case ViewTypes.SLICE: case ViewTypes.VOLUME: default: return [ { builder: vtkSphereHandleRepresentation, labels: ['moveHandle'] }, { builder: vtkCircleContextRepresentation, labels: ['ellipseHandle'], }, ]; } }; // -------------------------------------------------------------------------- // initialization // -------------------------------------------------------------------------- // Default manipulator model.manipulator = vtkPlanePointManipulator.newInstance(); model.widgetState = stateGenerator(); model.shapeHandle = model.widgetState.getEllipseHandle(); model.point1Handle = model.widgetState.getPoint1Handle(); model.point2Handle = model.widgetState.getPoint2Handle(); model.point1Handle.setManipulator(model.manipulator); model.point2Handle.setManipulator(model.manipulator); } // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { modifierBehavior: { None: { [BehaviorCategory.PLACEMENT]: ShapeBehavior[BehaviorCategory.PLACEMENT].CLICK_AND_DRAG, [BehaviorCategory.POINTS]: ShapeBehavior[BehaviorCategory.POINTS].CENTER_TO_CORNER, [BehaviorCategory.RATIO]: ShapeBehavior[BehaviorCategory.RATIO].FREE, }, Shift: { [BehaviorCategory.RATIO]: ShapeBehavior[BehaviorCategory.RATIO].FIXED, }, Control: { [BehaviorCategory.POINTS]: ShapeBehavior[BehaviorCategory.POINTS].CORNER_TO_CORNER, }, }, }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign( model, { ...SHAPE_DEFAULT_VALUES.DEFAULT_VALUES, ...DEFAULT_VALUES }, initialValues ); vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues); macro.setGet(publicAPI, model, ['manipulator', 'widgetState']); vtkEllipseWidget(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkEllipseWidget'); // ---------------------------------------------------------------------------- export default { newInstance, extend };