All files / Sources/Interaction/Style/InteractorStyleManipulator Presets.js

83.33% Statements 15/18
83.33% Branches 5/6
50% Functions 2/4
82.35% Lines 14/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111    1x                                   1x                                                                                                       6x 6x 60x 60x     60x 6x 54x 6x 48x     48x       6x       6x                                  
import Manipulators from 'vtk.js/Sources/Interaction/Manipulators';
 
const MANIPULTOR_TYPES = {
  slice: Manipulators.vtkMouseCameraSliceManipulator,
  multiRotate: Manipulators.vtkMouseCameraTrackballMultiRotateManipulator,
  pan: Manipulators.vtkMouseCameraTrackballPanManipulator,
  roll: Manipulators.vtkMouseCameraTrackballRollManipulator,
  rotate: Manipulators.vtkMouseCameraTrackballRotateManipulator,
  axisRotate: Manipulators.vtkMouseCameraAxisRotateManipulator,
  zoom: Manipulators.vtkMouseCameraTrackballZoomManipulator,
  zoomToMouse: Manipulators.vtkMouseCameraTrackballZoomToMouseManipulator,
  range: Manipulators.vtkMouseRangeManipulator,
  vrPan: Manipulators.vtkVRButtonPanManipulator,
  gestureCamera: Manipulators.vtkGestureCameraManipulator,
  movement: Manipulators.vtkKeyboardCameraManipulator,
  freeLook: Manipulators.vtkMouseCameraTrackballFirstPersonManipulator,
  unicam: Manipulators.vtkMouseCameraUnicamManipulator,
  unicamRotate: Manipulators.vtkMouseCameraUnicamRotateManipulator,
};
 
const STYLES = {
  '3D': [
    { type: 'rotate' },
    { type: 'pan', options: { shift: true } },
    { type: 'zoom', options: { control: true } },
    { type: 'zoom', options: { alt: true } },
    { type: 'zoom', options: { dragEnabled: false, scrollEnabled: true } },
    { type: 'zoom', options: { button: 3 } },
    { type: 'roll', options: { shift: true, control: true } },
    { type: 'roll', options: { shift: true, alt: true } },
    { type: 'roll', options: { shift: true, button: 3 } },
    { type: 'vrPan' },
    { type: 'gestureCamera' },
  ],
  '2D': [
    { type: 'pan', options: { shift: true } },
    { type: 'zoom', options: { control: true } },
    { type: 'zoom', options: { alt: true } },
    { type: 'zoom', options: { button: 3 } },
    { type: 'roll', options: { shift: true, alt: true } },
    { type: 'roll', options: { shift: true, button: 3 } },
    { type: 'roll', options: { shift: true } },
    { type: 'vrPan' },
    { type: 'gestureCamera' },
  ],
  FirstPerson: [{ type: 'movement' }, { type: 'freeLook' }],
  Unicam: [{ type: 'unicam' }],
  zRotateTop: [
    { type: 'pan', options: { shift: true } },
    {
      type: 'axisRotate',
      options: { rotationAxis: [0, 0, 1], useHalfAxis: true },
    },
    { type: 'zoom', options: { control: true } },
    { type: 'zoom', options: { alt: true } },
    { type: 'zoom', options: { dragEnabled: false, scrollEnabled: true } },
    { type: 'zoom', options: { button: 3 } },
  ],
  zRotateAll: [
    { type: 'pan', options: { shift: true } },
    {
      type: 'axisRotate',
      options: { rotationAxis: [0, 0, 1], useHalfAxis: false },
    },
    { type: 'zoom', options: { control: true } },
    { type: 'zoom', options: { alt: true } },
    { type: 'zoom', options: { dragEnabled: false, scrollEnabled: true } },
    { type: 'zoom', options: { button: 3 } },
  ],
};
 
function applyDefinitions(definitions, manipulatorStyle) {
  manipulatorStyle.removeAllManipulators();
  for (let idx = 0; idx < definitions.length; idx++) {
    const definition = definitions[idx];
    const instance = MANIPULTOR_TYPES[definition.type].newInstance(
      definition.options
    );
    if (instance.isA('vtkCompositeVRManipulator')) {
      manipulatorStyle.addVRManipulator(instance);
    } else if (instance.isA('vtkCompositeGestureManipulator')) {
      manipulatorStyle.addGestureManipulator(instance);
    } else Iif (instance.isA('vtkCompositeKeyboardManipulator')) {
      manipulatorStyle.addKeyboardManipulator(instance);
    } else {
      manipulatorStyle.addMouseManipulator(instance);
    }
  }
 
  return true;
}
 
function applyPreset(name, manipulatorStyle) {
  return applyDefinitions(STYLES[name], manipulatorStyle);
}
 
function registerManipulatorType(type, classDef) {
  MANIPULTOR_TYPES[type] = classDef;
}
 
function registerStylePreset(name, definitions) {
  STYLES[name] = definitions;
}
 
export default {
  applyDefinitions,
  applyPreset,
  registerManipulatorType,
  registerStylePreset,
};