Skip to content

refactor(polylinewidget): makes Angle and Distance widgets inherits from PolyLineWidget #2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 0 additions & 164 deletions Sources/Widgets/Widgets3D/AngleWidget/behavior.js

This file was deleted.

69 changes: 8 additions & 61 deletions Sources/Widgets/Widgets3D/AngleWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import macro from 'vtk.js/Sources/macros';
import vtkAbstractWidgetFactory from 'vtk.js/Sources/Widgets/Core/AbstractWidgetFactory';
import vtkPlanePointManipulator from 'vtk.js/Sources/Widgets/Manipulators/PlaneManipulator';
import vtkPolyLineRepresentation from 'vtk.js/Sources/Widgets/Representations/PolyLineRepresentation';
import vtkSphereHandleRepresentation from 'vtk.js/Sources/Widgets/Representations/SphereHandleRepresentation';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';

import widgetBehavior from 'vtk.js/Sources/Widgets/Widgets3D/AngleWidget/behavior';
import stateGenerator from 'vtk.js/Sources/Widgets/Widgets3D/AngleWidget/state';

import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
import vtkPolyLineWidget from 'vtk.js/Sources/Widgets/Widgets3D/PolyLineWidget';

// ----------------------------------------------------------------------------
// Factory
Expand All @@ -17,36 +10,6 @@ import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
function vtkAngleWidget(publicAPI, model) {
model.classHierarchy.push('vtkAngleWidget');

// --- Widget Requirement ---------------------------------------------------

model.methodsToLink = [
'activeScaleFactor',
'activeColor',
'useActiveColor',
'glyphResolution',
'defaultScale',
];
model.behavior = widgetBehavior;
model.widgetState = stateGenerator();

publicAPI.getRepresentationsForViewType = (viewType) => {
switch (viewType) {
case ViewTypes.DEFAULT:
case ViewTypes.GEOMETRY:
case ViewTypes.SLICE:
case ViewTypes.VOLUME:
default:
return [
{ builder: vtkSphereHandleRepresentation, labels: ['handles'] },
{ builder: vtkSphereHandleRepresentation, labels: ['moveHandle'] },
{
builder: vtkPolyLineRepresentation,
labels: ['handles', 'moveHandle'],
},
];
}
};

// --- Public methods -------------------------------------------------------

// Returns angle in radians
Expand All @@ -68,37 +31,21 @@ function vtkAngleWidget(publicAPI, model) {
vtkMath.subtract(handles[2].getOrigin(), handles[1].getOrigin(), vec2);
return vtkMath.angleBetweenVectors(vec1, vec2);
};

// --------------------------------------------------------------------------
// initialization
// --------------------------------------------------------------------------

model.widgetState.onBoundsChange((bounds) => {
const center = [
(bounds[0] + bounds[1]) * 0.5,
(bounds[2] + bounds[3]) * 0.5,
(bounds[4] + bounds[5]) * 0.5,
];
model.widgetState.getMoveHandle().setOrigin(center);
});

// Default manipulator
model.manipulator = vtkPlanePointManipulator.newInstance();
}

// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
// manipulator: null,
};
function defaultValues(initialValues) {
return {
maxPoints: 3,
...initialValues,
};
}

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
macro.setGet(publicAPI, model, ['manipulator']);
vtkPolyLineWidget.extend(publicAPI, model, defaultValues(initialValues));

vtkAngleWidget(publicAPI, model);
}
Expand Down
24 changes: 0 additions & 24 deletions Sources/Widgets/Widgets3D/AngleWidget/state.js

This file was deleted.

Loading