All files / Sources/Widgets/Manipulators/AbstractManipulator index.js

35.71% Statements 10/28
0% Branches 0/17
50% Functions 2/4
45.45% Lines 10/22

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                25x   25x                 25x                               1x                           25x 25x 25x 25x                           25x         1x          
import macro from 'vtk.js/Sources/macros';
 
// ----------------------------------------------------------------------------
// vtkAbstractManipulator methods
// ----------------------------------------------------------------------------
 
function vtkAbstractManipulator(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkAbstractManipulator');
 
  publicAPI.getOrigin = (callData) => {
    if (model.userOrigin) return model.userOrigin;
    if (model.useCameraFocalPoint)
      return callData.pokedRenderer.getActiveCamera().getFocalPoint();
    if (model.handleOrigin) return model.handleOrigin;
    if (model.widgetOrigin) return model.widgetOrigin;
    return [0, 0, 0];
  };
 
  publicAPI.getNormal = (callData) => {
    if (model.userNormal) return model.userNormal;
    if (model.useCameraNormal)
      return callData.pokedRenderer
        .getActiveCamera()
        .getDirectionOfProjection();
    if (model.handleNormal) return model.handleNormal;
    if (model.widgetNormal) return model.widgetNormal;
    return [0, 0, 1];
  };
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  // userOrigin: null,
  // handleOrigin: null,
  // widgetOrigin: null,
  // userNormal: null,
  // handleNormal: null,
  // widgetNormal: null
  useCameraFocalPoint: false,
  useCameraNormal: false,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
  macro.obj(publicAPI, model);
  macro.setGet(publicAPI, model, ['useCameraFocalPoint', 'useCameraNormal']);
  macro.setGetArray(
    publicAPI,
    model,
    [
      'userOrigin',
      'handleOrigin',
      'widgetOrigin',
      'userNormal',
      'handleNormal',
      'widgetNormal',
    ],
    3
  );
 
  vtkAbstractManipulator(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkAbstractManipulator');
 
// ----------------------------------------------------------------------------
 
export default { extend, newInstance };