All files / Sources/Rendering/Core/Prop index.js

71.23% Statements 52/73
61.11% Branches 11/18
44.44% Functions 12/27
75.8% Lines 47/62

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150      1x     1868x                 934x   934x 8486x 8486x 118x 118x 2x     8486x     934x   3949x 934x 934x 934x   934x 934x   934x 4780x   934x 2320x   934x       934x   934x         934x       934x       934x           934x   3839x 934x 934x 12x 12x 12x       934x               934x           934x   934x 8x             1x                                   934x     934x 934x 934x                 934x     934x         1x          
import macro from 'vtk.js/Sources/macros';
import Constants from 'vtk.js/Sources/Rendering/Core/Prop/Constants';
 
const { CoordinateSystem } = Constants;
 
function notImplemented(method) {
  return () => macro.vtkErrorMacro(`vtkProp::${method} - NOT IMPLEMENTED`);
}
 
// ----------------------------------------------------------------------------
// vtkProp methods
// ----------------------------------------------------------------------------
 
function vtkProp(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkProp');
 
  publicAPI.getMTime = () => {
    let m1 = model.mtime;
    for (let index = 0; index < model.textures.length; ++index) {
      const m2 = model.textures[index].getMTime();
      if (m2 > m1) {
        m1 = m2;
      }
    }
    return m1;
  };
 
  publicAPI.processSelectorPixelBuffers = (selector, pixeloffsets) => {};
 
  publicAPI.getNestedProps = () => null;
  publicAPI.getActors = () => [];
  publicAPI.getActors2D = () => [];
  publicAPI.getVolumes = () => [];
 
  publicAPI.pick = notImplemented('pick');
  publicAPI.hasKey = notImplemented('hasKey');
 
  publicAPI.getNestedVisibility = () =>
    model.visibility &&
    (!model._parentProp || model._parentProp.getNestedVisibility());
  publicAPI.getNestedPickable = () =>
    model.pickable &&
    (!model._parentProp || model._parentProp.getNestedPickable());
  publicAPI.getNestedDragable = () =>
    model.dragable &&
    (!model._parentProp || model._parentProp.getNestedDragable());
 
  publicAPI.getRedrawMTime = () => model.mtime;
 
  publicAPI.setEstimatedRenderTime = (t) => {
    model.estimatedRenderTime = t;
    model.savedEstimatedRenderTime = t;
  };
 
  publicAPI.restoreEstimatedRenderTime = () => {
    model.estimatedRenderTime = model.savedEstimatedRenderTime;
  };
 
  publicAPI.addEstimatedRenderTime = (t) => {
    model.estimatedRenderTime += t;
  };
 
  publicAPI.setAllocatedRenderTime = (t) => {
    model.allocatedRenderTime = t;
    model.savedEstimatedRenderTime = model.estimatedRenderTime;
    model.estimatedRenderTime = 0;
  };
 
  publicAPI.getSupportsSelection = () => false;
 
  publicAPI.getTextures = () => model.textures;
  publicAPI.hasTexture = (texture) => model.textures.indexOf(texture) !== -1;
  publicAPI.addTexture = (texture) => {
    if (texture && !publicAPI.hasTexture(texture)) {
      model.textures = model.textures.concat(texture);
      publicAPI.modified();
    }
  };
 
  publicAPI.removeTexture = (texture) => {
    const newTextureList = model.textures.filter((item) => item !== texture);
    if (model.textures.length !== newTextureList.length) {
      model.textures = newTextureList;
      publicAPI.modified();
    }
  };
 
  publicAPI.removeAllTextures = () => {
    model.textures = [];
    publicAPI.modified();
  };
 
  // not all mappers support all coordinate systems
  publicAPI.setCoordinateSystemToWorld = () =>
    publicAPI.setCoordinateSystem(CoordinateSystem.WORLD);
  publicAPI.setCoordinateSystemToDisplay = () =>
    publicAPI.setCoordinateSystem(CoordinateSystem.DISPLAY);
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  // _parentProp: null,
  allocatedRenderTime: 10,
  coordinateSystem: CoordinateSystem.WORLD,
  dragable: true,
  estimatedRenderTime: 0,
  paths: null,
  pickable: true,
  renderTimeMultiplier: 1,
  savedEstimatedRenderTime: 0,
  textures: [],
  useBounds: true,
  visibility: true,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Build VTK API
  macro.obj(publicAPI, model);
  macro.get(publicAPI, model, ['estimatedRenderTime', 'allocatedRenderTime']);
  macro.setGet(publicAPI, model, [
    '_parentProp',
    'coordinateSystem',
    'dragable',
    'pickable',
    'renderTimeMultiplier',
    'useBounds',
    'visibility',
  ]);
  macro.moveToProtected(publicAPI, model, ['parentProp']);
 
  // Object methods
  vtkProp(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkProp');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend, ...Constants };