Skip to content

Commit 9b598f1

Browse files
committed
fix(polygon): handle events correctly when placing polygon inside another
When placing a new polygon inside an existing one: - Right-click to remove points now works correctly - Old polygon handles no longer show on hover - Tooltip doesn't appear for containing polygon after placing finishes Key changes: - Check getPlacing() before activeState in handleRightButtonPress - Check if any other widget has focus before handling events - Properly release focus when polygon finishes placing - Hide handles on finished polygons when another is placing with points
1 parent b616796 commit 9b598f1

3 files changed

Lines changed: 360 additions & 15 deletions

File tree

src/components/tools/polygon/PolygonWidget2D.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,17 @@ export default defineComponent({
101101
onVTKEvent(widget, 'onDraggingEvent', (eventData: any) => {
102102
dragging.value = eventData.dragging;
103103
});
104+
const anotherToolPlacing = computed(() =>
105+
toolStore.tools.some(
106+
(t) => t.placing && t.id !== toolId.value && t.points.length > 0
107+
)
108+
);
104109
const showHandles = computed(() => {
105-
return lastHoverEventData.value?.hovering && !dragging.value;
110+
return (
111+
lastHoverEventData.value?.hovering &&
112+
!dragging.value &&
113+
!anotherToolPlacing.value
114+
);
106115
});
107116
watchEffect(() => {
108117
if (!lastHoverEventData.value) return;

src/vtk/PolygonWidget/behavior.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,12 @@ export default function widgetBehavior(publicAPI: any, model: any) {
246246
// So we can rely on getSelections() to be up to date now
247247
overUnselectedHandle = false;
248248

249-
if (model.hasFocus) {
250-
model._widgetManager.disablePicking();
251-
}
252-
253249
// Don't emit hover events if another widget has focus (e.g., is placing)
254-
const activeWidget = model._widgetManager.getActiveWidget();
255-
if (activeWidget && activeWidget !== publicAPI) {
250+
const widgets = model._widgetManager.getWidgets();
251+
const anotherWidgetHasFocus = widgets.some(
252+
(w: any) => w !== publicAPI && w.hasFocus()
253+
);
254+
if (anotherWidgetHasFocus) {
256255
publicAPI.invokeHoverEvent({
257256
...event,
258257
hovering: false,
@@ -344,7 +343,6 @@ export default function widgetBehavior(publicAPI: any, model: any) {
344343
(model.hasFocus && !model.activeState) ||
345344
(model.activeState && !model.activeState.getActive())
346345
) {
347-
// update if mouse hovered over handle/activeState for next onDown
348346
model._widgetManager.enablePicking();
349347
model._interactor.render();
350348
}
@@ -423,18 +421,22 @@ export default function widgetBehavior(publicAPI: any, model: any) {
423421
};
424422

425423
publicAPI.handleRightButtonPress = (eventData: any) => {
426-
if (!model.activeState) {
427-
return macro.VOID;
428-
}
429-
424+
// When placing, handle right-click regardless of what widget manager picked
430425
if (model.widgetState.getPlacing()) {
431426
removeLastHandle();
432427
return macro.EVENT_ABORT;
433428
}
434429

430+
if (!model.activeState) {
431+
return macro.VOID;
432+
}
433+
435434
// If another widget has focus (e.g., is placing), don't show context menu
436-
const activeWidget = model._widgetManager.getActiveWidget();
437-
if (activeWidget && activeWidget !== publicAPI) {
435+
const widgets = model._widgetManager.getWidgets();
436+
const anotherWidgetHasFocus = widgets.some(
437+
(w: any) => w !== publicAPI && w.hasFocus()
438+
);
439+
if (anotherWidgetHasFocus) {
438440
return macro.VOID;
439441
}
440442

@@ -465,7 +467,8 @@ export default function widgetBehavior(publicAPI: any, model: any) {
465467

466468
// Called after we are finished/placed.
467469
publicAPI.loseFocus = () => {
468-
if (model.hasFocus) {
470+
const hadFocus = model.hasFocus;
471+
if (hadFocus) {
469472
model._interactor.cancelAnimation(publicAPI);
470473
publicAPI.invokeEndInteractionEvent();
471474
}
@@ -475,6 +478,9 @@ export default function widgetBehavior(publicAPI: any, model: any) {
475478
model.widgetState.getMoveHandle().setOrigin(null);
476479
model.activeState = null;
477480
model.hasFocus = false;
481+
if (hadFocus) {
482+
model._widgetManager.releaseFocus();
483+
}
478484
model._widgetManager.enablePicking();
479485
};
480486

0 commit comments

Comments
 (0)