Skip to content

Commit

Permalink
Merge pull request #2475 from tomsuchel/fix-line-widget-move-handle-n…
Browse files Browse the repository at this point in the history
…ot-visible

fix(linewidget): moveHandle not visible and last point of polyline is ignored
  • Loading branch information
finetjul authored Jun 22, 2022
2 parents 298c01b + 6c1ab00 commit 9f2ec70
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
17 changes: 1 addition & 16 deletions Sources/Widgets/Representations/PolyLineRepresentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,7 @@ function vtkPolyLineRepresentation(publicAPI, model) {
subStates.push(subState);
return subStates;
}, []);
let size = list.length;

// Do not render last point if not visible or too close from previous point.
if (size > 1) {
const lastState = list[list.length - 1];
const last = lastState.getOrigin();
const prevLast = list[list.length - 2].getOrigin();
let delta =
vtkMath.distance2BetweenPoints(last, prevLast) > model.threshold
? 0
: 1;
if (!delta && lastState.isVisible && !lastState.isVisible()) {
delta++;
}
size -= delta;
}
const size = list.length;

const points = allocateSize(size, model.closePolyLine && size > 2);

Expand Down
1 change: 1 addition & 0 deletions Sources/Widgets/Widgets3D/AngleWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default function widgetBehavior(publicAPI, model) {
model.widgetState.deactivate();
model.widgetState.getMoveHandle().deactivate();
model.widgetState.getMoveHandle().setVisible(false);
model.widgetState.getMoveHandle().setOrigin(null);
model.activeState = null;
model.hasFocus = false;
model._widgetManager.enablePicking();
Expand Down
1 change: 1 addition & 0 deletions Sources/Widgets/Widgets3D/DistanceWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default function widgetBehavior(publicAPI, model) {
model.widgetState.deactivate();
model.widgetState.getMoveHandle().deactivate();
model.widgetState.getMoveHandle().setVisible(false);
model.widgetState.getMoveHandle().setOrigin(null);
model.activeState = null;
model.hasFocus = false;
model._widgetManager.enablePicking();
Expand Down
30 changes: 22 additions & 8 deletions Sources/Widgets/Widgets3D/LineWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ export default function widgetBehavior(publicAPI, model) {
publicAPI.getHandle = (handleIndex) =>
model.widgetState[handleGetters[handleIndex]]();

/**
* Return the index in the of tbe handle in `representations` array,
* or -1 if the handle is not present in the widget state.
*/
publicAPI.getHandleIndex = (handle) => {
switch (handle) {
case model.widgetState.getHandle1():
return 0;
case model.widgetState.getHandle2():
return 1;
case model.widgetState.getMoveHandle():
return 2;
default:
return -1;
}
};

publicAPI.isPlaced = () =>
getNumberOfPlacedHandles(model.widgetState) === MAX_POINTS;

Expand Down Expand Up @@ -159,12 +176,6 @@ export default function widgetBehavior(publicAPI, model) {

// Handles visibility ---------------------------------------------------------

publicAPI.setMoveHandleVisibility = (visibility) => {
model.representations[2].setVisibilityFlagArray([visibility, visibility]);
model.widgetState.getMoveHandle().setVisible(visibility);
model.representations[2].updateActorVisibility();
};

/**
* Set actor visibility to true unless it is a NONE handle
* and uses state visibility variable for the displayActor visibility to
Expand Down Expand Up @@ -212,7 +223,7 @@ export default function widgetBehavior(publicAPI, model) {
}
if (handleIndex === 1) {
publicAPI.placeText();
publicAPI.setMoveHandleVisibility(false);
publicAPI.loseFocus();
}
};

Expand Down Expand Up @@ -278,6 +289,9 @@ export default function widgetBehavior(publicAPI, model) {
) {
if (model.activeState.setOrigin) {
model.activeState.setOrigin(worldCoords);
publicAPI.updateHandleVisibility(
publicAPI.getHandleIndex(model.activeState)
);
} else {
// Dragging line
publicAPI
Expand Down Expand Up @@ -355,7 +369,6 @@ export default function widgetBehavior(publicAPI, model) {
if (!model.hasFocus && !publicAPI.isPlaced()) {
model.activeState = model.widgetState.getMoveHandle();
model.activeState.setShape(publicAPI.getHandle(0).getShape());
publicAPI.setMoveHandleVisibility(true);
model.activeState.activate();
model._interactor.requestAnimation(publicAPI);
publicAPI.invokeStartInteractionEvent();
Expand All @@ -372,6 +385,7 @@ export default function widgetBehavior(publicAPI, model) {
}
model.widgetState.deactivate();
model.widgetState.getMoveHandle().deactivate();
model.widgetState.getMoveHandle().setOrigin(null);
model.activeState = null;
model.hasFocus = false;
model._widgetManager.enablePicking();
Expand Down
4 changes: 4 additions & 0 deletions Sources/Widgets/Widgets3D/LineWidget/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function updateTextPosition(model) {
}

export function isHandlePlaced(handleIndex, widgetState) {
if (handleIndex === 2) {
return widgetState.getMoveHandle().getOrigin() != null;
}

const handle1Origin = widgetState.getHandle1().getOrigin();
if (handleIndex === 0) {
return handle1Origin != null;
Expand Down
1 change: 1 addition & 0 deletions Sources/Widgets/Widgets3D/PolyLineWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export default function widgetBehavior(publicAPI, model) {
model.widgetState.deactivate();
model.widgetState.getMoveHandle().deactivate();
model.widgetState.getMoveHandle().setVisible(false);
model.widgetState.getMoveHandle().setOrigin(null);
model.activeState = null;
model.hasFocus = false;
model._widgetManager.enablePicking();
Expand Down

0 comments on commit 9f2ec70

Please sign in to comment.