-
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathindex.js
More file actions
113 lines (92 loc) · 3.75 KB
/
index.js
File metadata and controls
113 lines (92 loc) · 3.75 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import macro from 'vtk.js/Sources/macros';
import { getProfileForClass, getSuggestedProfile } from './profileHints';
import 'vtk.js/Sources/Rendering/OpenGL/Profiles/profileHintManifest';
import 'vtk.js/Sources/Rendering/WebGPU/Profiles/profileHintManifest';
const { vtkOnceErrorMacro } = macro;
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(' → ');
const suggestedClass = getSuggestedProfile(classNames);
const suggestedProfile = suggestedClass && getProfileForClass(suggestedClass);
if (suggestedProfile) {
return [
`No ${factoryName} implementation found for ${classNames[0]}.`,
`Class hierarchy: ${classList}.`,
'This usually means the rendering profile import is missing.',
`Try importing '@kitware/vtk.js/Rendering/Profiles/${suggestedProfile}' or 'vtk.js/Sources/Rendering/Profiles/${suggestedProfile}'.`,
"You can also use the full profile imports '@kitware/vtk.js/Rendering/Profiles/All' or 'vtk.js/Sources/Rendering/Profiles/All'.",
].join('\n');
}
return [
`No ${factoryName} implementation found for ${classNames[0]}.`,
`Class hierarchy: ${classList}.`,
'If this is a built-in renderable, a rendering profile import may be missing.',
"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 this is a custom renderable, register a matching override with the view node factory.',
].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) {
vtkOnceErrorMacro(
buildMissingImplementationMessage(publicAPI.getClassName(), classNames)
);
return null;
}
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 };