Skip to content
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

Tweak line widget #1763

Merged
merged 4 commits into from Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 22 additions & 14 deletions Sources/Widgets/SVG/SVGLandmarkRepresentation/index.js
Expand Up @@ -81,27 +81,35 @@ function vtkSVGLandmarkRepresentation(publicAPI, model) {
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
circleProps: {
r: 5,
stroke: 'red',
fill: 'red',
},
textProps: {
fill: 'white',
dx: 12,
dy: -12,
},
};
function defaultValues(initialValues) {
return {
circleProps: {
r: 5,
stroke: 'red',
fill: 'red',
},
textProps: {
fill: 'white',
dx: 12,
dy: -12,
},
...initialValues,
};
}

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

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

vtkSVGRepresentation.extend(publicAPI, model, initialValues);

macro.setGet(publicAPI, model, ['circleProps', 'textProps', 'name']);
macro.setGet(publicAPI, model, [
'circleProps',
'fontProperties',
'name',
'textProps',
]);

// Object specific methods
vtkSVGLandmarkRepresentation(publicAPI, model);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Widgets/SVG/SVGRepresentation/index.js
Expand Up @@ -112,7 +112,7 @@ function vtkSVGRepresentation(publicAPI, model) {
) => {
if (model.behavior === Behavior.CONTEXT) {
publicAPI.setVisibility(widgetVisible && ctxVisible);
} else if (model.Behavior === Behavior.HANDLE) {
} else if (model.behavior === Behavior.HANDLE) {
publicAPI.setVisibility(widgetVisible && handleVisible);
}
};
Expand Down
67 changes: 40 additions & 27 deletions Sources/Widgets/Widgets3D/LineWidget/behavior.js
Expand Up @@ -175,15 +175,36 @@ export default function widgetBehavior(publicAPI, model) {
model.interactor.render();
};

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

/**
* Called when placing a point from the first time.
* @param {number} handleIndex
*/
publicAPI.placeHandle = (handleIndex) => {
const handle = publicAPI.getHandle(handleIndex);
handle.setOrigin(...model.widgetState.getMoveHandle().getOrigin());
handle.setColor(model.widgetState.getMoveHandle().getColor());
handle.setScale1(model.widgetState.getMoveHandle().getScale1());

publicAPI.updateHandleOrientations();
publicAPI.rotateHandlesToFaceCamera();
model.widgetState.getText().setOrigin(calculateTextPosition(model));
publicAPI.updateHandleVisibility(handleIndex);

if (handleIndex === 0) {
// For the line (handle1, handle2, moveHandle) to be displayed
// correctly, handle2 origin must be valid.
publicAPI
.getHandle(1)
.setOrigin(...model.widgetState.getMoveHandle().getOrigin());
// Now that handle2 has a valid origin, hide it
publicAPI.updateHandleVisibility(1);

model.widgetState
.getMoveHandle()
.setShape(publicAPI.getHandle(1).getShape());
}
if (handleIndex === 1) {
publicAPI.placeText();
publicAPI.setMoveHandleVisibility(false);
}
};

// --------------------------------------------------------------------------
Expand All @@ -204,24 +225,11 @@ export default function widgetBehavior(publicAPI, model) {
getNumberOfPlacedHandles(model.widgetState) === 0
) {
publicAPI.placeHandle(0);
model.activeState.setShape(publicAPI.getHandle(1).getShape());
// For the line (handle1, handle2, moveHandle) to be displayed
// correctly, handle2 origin must be valid.
publicAPI
.getHandle(1)
.setOrigin(...model.widgetState.getMoveHandle().getOrigin());
publicAPI.updateHandleOrientations();
// Hide handle2
publicAPI.updateHandleVisibility(1);
} else if (
model.widgetState.getMoveHandle().getActive() &&
getNumberOfPlacedHandles(model.widgetState) === 1
) {
publicAPI.placeHandle(1);
publicAPI.updateHandleOrientations();
publicAPI.placeText();
publicAPI.setMoveHandleVisibility(false);
model.widgetState.getMoveHandle().deactivate();
} else {
updateCursor();
}
Expand Down Expand Up @@ -270,23 +278,28 @@ export default function widgetBehavior(publicAPI, model) {
// --------------------------------------------------------------------------

publicAPI.handleLeftButtonRelease = () => {
if (model.isDragging && model.pickable) {
// After dragging a point or placing all points
if (
model.activeState &&
model.activeState.getActive() &&
(model.isDragging || publicAPI.isPlaced())
) {
// Recompute offsets
publicAPI.placeText();
model.openGLRenderWindow.setCursor('pointer');
model.widgetState.deactivate();
model.widgetState.getMoveHandle().deactivate();
model.activeState = null;

model.interactor.cancelAnimation(publicAPI);
publicAPI.invokeEndInteractionEvent();
} else if (model.activeState !== model.widgetState.getMoveHandle()) {
model.widgetState.deactivate();
}
if (
(model.hasFocus && !model.activeState) ||
(model.activeState && !model.activeState.getActive())
) {
model.openGLRenderWindow.setCursor('pointer');

model.hasFocus = false;

publicAPI.invokeEndInteractionEvent();
model.widgetManager.enablePicking();
model.interactor.render();
}

if (
model.isDragging === false &&
(!model.activeState || !model.activeState.getActive())
Expand Down