-
-
Notifications
You must be signed in to change notification settings - Fork 412
Expand file tree
/
Copy pathindex.js
More file actions
94 lines (76 loc) · 2.83 KB
/
index.js
File metadata and controls
94 lines (76 loc) · 2.83 KB
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
import macro from 'vtk.js/Sources/macros';
function listClassHierarchy(dataObject) {
const classNames = [];
let depth = 0;
let className = dataObject.getClassName(depth++);
while (className) {
classNames.push(className);
className = dataObject.getClassName(depth++);
}
return classNames;
}
function buildMissingImplementationMessage(factoryName, classNames) {
const classList = classNames.join(' → ');
return [
`No ${factoryName} implementation found for ${classNames[0]}.`,
`Class hierarchy: ${classList}.`,
`A rendering Profile is likely missing for ${classNames[0]}.`,
"Try importing '@kitware/vtk.js/Rendering/Profiles/All' or 'vtk.js/Sources/Rendering/Profiles/All',",
'or import the specific rendering profile needed by this renderable if known.',
'See https://kitware.github.io/vtk-js/docs/concepts_profile.html for details.',
].join('\n');
}
// ----------------------------------------------------------------------------
// vtkViewNodeFactory methods
// ----------------------------------------------------------------------------
function vtkViewNodeFactory(publicAPI, model) {
// Make sure our overrides is just for our instance not shared with everyone...
if (!model.overrides) {
model.overrides = {};
}
// Set our className
model.classHierarchy.push('vtkViewNodeFactory');
publicAPI.createNode = (dataObject) => {
if (dataObject.isDeleted()) {
return null;
}
const classNames = listClassHierarchy(dataObject);
let cpt = 0;
let className = classNames[cpt++];
let isObject = false;
const keys = Object.keys(model.overrides);
while (className && !isObject) {
if (keys.indexOf(className) !== -1) {
isObject = true;
} else {
className = dataObject.getClassName(cpt++);
}
}
if (!isObject) {
throw new Error(
buildMissingImplementationMessage(publicAPI.getClassName(), classNames)
);
}
const vn = model.overrides[className]();
vn.setMyFactory(publicAPI);
return vn;
};
}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
// overrides: {},
};
// ----------------------------------------------------------------------------
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
// Build VTK API
macro.obj(publicAPI, model);
// Object methods
vtkViewNodeFactory(publicAPI, model);
}
// ----------------------------------------------------------------------------
export const newInstance = macro.newInstance(extend, 'vtkViewNodeFactory');
// ----------------------------------------------------------------------------
export default { newInstance, extend };