|
| 1 | +import macro from 'vtk.js/Sources/macro'; |
| 2 | + |
| 3 | +// ---------------------------------------------------------------------------- |
| 4 | +// vtkJSONReader methods |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | + |
| 7 | +function vtkJSONReader(publicAPI, model) { |
| 8 | + // Set our className |
| 9 | + model.classHierarchy.push('vtkJSONReader'); |
| 10 | + |
| 11 | + // Internal method to fetch Array |
| 12 | + function fetchData(url, option = {}) { |
| 13 | + return model.dataAccessHelper.fetchText(publicAPI, url, option); |
| 14 | + } |
| 15 | + |
| 16 | + // Set DataSet url |
| 17 | + publicAPI.setUrl = (url, option = {}) => { |
| 18 | + model.url = url; |
| 19 | + |
| 20 | + // Fetch metadata |
| 21 | + return publicAPI.loadData(option); |
| 22 | + }; |
| 23 | + |
| 24 | + // Fetch the actual data arrays |
| 25 | + publicAPI.loadData = (option = {}) => |
| 26 | + fetchData(model.url, option).then(publicAPI.parseAsText); |
| 27 | + |
| 28 | + publicAPI.parseAsText = (content) => { |
| 29 | + if (!content) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + model.data = JSON.parse(content); |
| 33 | + publicAPI.modified(); |
| 34 | + return true; |
| 35 | + }; |
| 36 | + |
| 37 | + publicAPI.requestData = (inData, outData) => { |
| 38 | + outData[0] = model.data; |
| 39 | + }; |
| 40 | + |
| 41 | + // return Busy state |
| 42 | + publicAPI.isBusy = () => false; |
| 43 | + |
| 44 | + publicAPI.getNumberOfOutputPorts = () => model.numberOfOutputs; |
| 45 | +} |
| 46 | + |
| 47 | +// ---------------------------------------------------------------------------- |
| 48 | +// Object factory |
| 49 | +// ---------------------------------------------------------------------------- |
| 50 | + |
| 51 | +const DEFAULT_VALUES = { |
| 52 | + // url: null, |
| 53 | +}; |
| 54 | + |
| 55 | +// ---------------------------------------------------------------------------- |
| 56 | + |
| 57 | +export function extend(publicAPI, model, initialValues = {}) { |
| 58 | + Object.assign(model, DEFAULT_VALUES, initialValues); |
| 59 | + |
| 60 | + // Build VTK API |
| 61 | + macro.obj(publicAPI, model); |
| 62 | + macro.get(publicAPI, model, ['url']); |
| 63 | + macro.algo(publicAPI, model, 0, 1); |
| 64 | + macro.event(publicAPI, model, 'busy'); |
| 65 | + |
| 66 | + // Object methods |
| 67 | + vtkJSONReader(publicAPI, model); |
| 68 | +} |
| 69 | + |
| 70 | +// ---------------------------------------------------------------------------- |
| 71 | + |
| 72 | +export const newInstance = macro.newInstance(extend, 'vtkJSONReader'); |
| 73 | + |
| 74 | +// ---------------------------------------------------------------------------- |
| 75 | + |
| 76 | +export default { newInstance, extend }; |
0 commit comments