Skip to content

Commit df418ff

Browse files
committed
feat(Rendering): report missing view node profile imports
fixes #3343
1 parent 9d00695 commit df418ff

File tree

1 file changed

+67
-1
lines changed
  • Sources/Rendering/SceneGraph/ViewNodeFactory

1 file changed

+67
-1
lines changed

Sources/Rendering/SceneGraph/ViewNodeFactory/index.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
11
import macro from 'vtk.js/Sources/macros';
22

3+
const { vtkOnceErrorMacro } = macro;
4+
5+
const PROFILE_BY_CLASS = {
6+
vtkActor: 'Geometry',
7+
vtkActor2D: 'Geometry',
8+
vtkCamera: 'Geometry',
9+
vtkCubeAxesActor: 'Geometry',
10+
vtkMapper: 'Geometry',
11+
vtkMapper2D: 'Geometry',
12+
vtkPixelSpaceCallbackMapper: 'Geometry',
13+
vtkRenderWindow: 'Geometry',
14+
vtkRenderer: 'Geometry',
15+
vtkScalarBarActor: 'Geometry',
16+
vtkSkybox: 'Geometry',
17+
vtkTexture: 'Geometry',
18+
vtkGlyph3DMapper: 'Glyph',
19+
vtkImageCPRMapper: 'Volume',
20+
vtkImageMapper: 'Volume',
21+
vtkImageResliceMapper: 'Volume',
22+
vtkImageSlice: 'Volume',
23+
vtkAbstractImageMapper: 'Volume',
24+
vtkVolume: 'Volume',
25+
vtkVolumeMapper: 'Volume',
26+
vtkSphereMapper: 'Molecule',
27+
vtkStickMapper: 'Molecule',
28+
vtkSurfaceLICMapper: 'LIC',
29+
};
30+
31+
function listClassHierarchy(dataObject) {
32+
const classNames = [];
33+
let depth = 0;
34+
let className = dataObject.getClassName(depth++);
35+
while (className) {
36+
classNames.push(className);
37+
className = dataObject.getClassName(depth++);
38+
}
39+
return classNames;
40+
}
41+
42+
function buildMissingImplementationMessage(factoryName, classNames) {
43+
const profile = classNames.find((className) => PROFILE_BY_CLASS[className]);
44+
const suggestedProfile = profile && PROFILE_BY_CLASS[profile];
45+
const classList = classNames.join(' → ');
46+
47+
if (suggestedProfile) {
48+
return [
49+
`No ${factoryName} implementation found for ${classNames[0]}.`,
50+
`Class hierarchy: ${classList}.`,
51+
'This usually means the rendering profile import is missing.',
52+
`Try importing '@kitware/vtk.js/Rendering/Profiles/${suggestedProfile}' or 'vtk.js/Sources/Rendering/Profiles/${suggestedProfile}'.`,
53+
"You can also use the full profile imports '@kitware/vtk.js/Rendering/Profiles/All' or 'vtk.js/Sources/Rendering/Profiles/All'.",
54+
].join('\n');
55+
}
56+
57+
return [
58+
`No ${factoryName} implementation found for ${classNames[0]}.`,
59+
`Class hierarchy: ${classList}.`,
60+
'If this is a built-in renderable, a rendering profile import may be missing.',
61+
'If this is a custom renderable, register a matching override with the view node factory.',
62+
].join('\n');
63+
}
64+
365
// ----------------------------------------------------------------------------
466
// vtkViewNodeFactory methods
567
// ----------------------------------------------------------------------------
@@ -18,8 +80,9 @@ function vtkViewNodeFactory(publicAPI, model) {
1880
return null;
1981
}
2082

83+
const classNames = listClassHierarchy(dataObject);
2184
let cpt = 0;
22-
let className = dataObject.getClassName(cpt++);
85+
let className = classNames[cpt++];
2386
let isObject = false;
2487
const keys = Object.keys(model.overrides);
2588
while (className && !isObject) {
@@ -31,6 +94,9 @@ function vtkViewNodeFactory(publicAPI, model) {
3194
}
3295

3396
if (!isObject) {
97+
vtkOnceErrorMacro(
98+
buildMissingImplementationMessage(publicAPI.getClassName(), classNames)
99+
);
34100
return null;
35101
}
36102
const vn = model.overrides[className]();

0 commit comments

Comments
 (0)