Skip to content

Commit

Permalink
Merge pull request Kitware#1913 from floryst/unique-class-hierarchy
Browse files Browse the repository at this point in the history
Unique class hierarchy
  • Loading branch information
floryst authored Jun 23, 2021
2 parents a815919 + c64e70b commit 8db884a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Sources/Common/Core/ClassHierarchy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default class ClassHierarchy extends Array {
push(...args) {
// no perf issue since args.length should be small
const newArgs = args.filter((arg) => !this.includes(arg));
return super.push(...newArgs);
}
}
11 changes: 8 additions & 3 deletions Sources/Widgets/Core/AbstractWidgetFactory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ function vtkAbstractWidgetFactory(publicAPI, model) {
camera,
} = extractRenderingComponents(renderer);
const widgetModel = {};
const widgetPublicAPI = {
const widgetPublicAPI = {};

macro.obj(widgetPublicAPI, widgetModel);
Object.assign(widgetPublicAPI, {
onWidgetChange: publicAPI.onWidgetChange,
};
Object.assign(widgetModel, model, {
});
Object.assign(widgetModel, {
widgetState: model.widgetState,
manipulator: model.manipulator,
viewType,
renderer,
camera,
Expand Down
8 changes: 7 additions & 1 deletion Sources/macro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import vtk from './vtk';
import ClassHierarchy from './Common/Core/ClassHierarchy';

let globalMTime = 0;

Expand Down Expand Up @@ -214,7 +215,12 @@ export function obj(publicAPI = {}, model = {}) {
if (!Number.isInteger(model.mtime)) {
model.mtime = ++globalMTime;
}
model.classHierarchy = ['vtkObject'];

if (!('classHierarchy' in model)) {
model.classHierarchy = new ClassHierarchy('vtkObject');
} else if (!(model.classHierarchy instanceof ClassHierarchy)) {
model.classHierarchy = ClassHierarchy.from(model.classHierarchy);
}

function off(index) {
callbacks[index] = null;
Expand Down

0 comments on commit 8db884a

Please sign in to comment.