Skip to content

Commit b616796

Browse files
committed
fix(tools): prevent fill interference when placing annotations
- Suppress hover/context menu for existing annotations when actively placing a new polygon or rectangle - Add cross-tool awareness between polygon and rectangle tools - Check getActiveWidget() in widget behaviors to defer to focused widget - Ensure grabFocus properly sets hasFocus to maintain activeState
1 parent 4351186 commit b616796

4 files changed

Lines changed: 106 additions & 6 deletions

File tree

src/components/tools/polygon/PolygonTool.vue

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import { Tools } from '@/src/store/tools/types';
9292
import { getLPSAxisFromDir } from '@/src/utils/lps';
9393
import { LPSAxisDir } from '@/src/types/lps';
9494
import { usePolygonStore } from '@/src/store/tools/polygons';
95+
import { useRectangleStore } from '@/src/store/tools/rectangles';
9596
import {
9697
useContextMenu,
9798
useCurrentTools,
@@ -235,7 +236,31 @@ export default defineComponent({
235236
236237
// --- //
237238
238-
const { contextMenu, openContextMenu } = useContextMenu();
239+
const { contextMenu, openContextMenu: baseOpenContextMenu } =
240+
useContextMenu();
241+
242+
// Check if any rectangle is actively being placed
243+
const rectangleStore = useRectangleStore();
244+
const isAnyRectanglePlacing = () => {
245+
return rectangleStore.tools.some(
246+
(tool) => tool.placing && tool.firstPoint && tool.secondPoint
247+
);
248+
};
249+
250+
// Suppress context menu for non-placing polygons when actively placing
251+
// or when a rectangle is actively being placed
252+
const openContextMenu = (id: ToolID, event: any) => {
253+
if (isAnyRectanglePlacing()) {
254+
return;
255+
}
256+
if (placingTool.id.value && id !== placingTool.id.value) {
257+
const placingToolData = activeToolStore.toolByID[placingTool.id.value];
258+
if (placingToolData?.points?.length > 0) {
259+
return;
260+
}
261+
}
262+
baseOpenContextMenu(id, event);
263+
};
239264
240265
const currentTools = useCurrentTools(
241266
activeToolStore,
@@ -247,7 +272,24 @@ export default defineComponent({
247272
})
248273
);
249274
250-
const { onHover, overlayInfo } = useHover(currentTools, slice);
275+
const { onHover: baseOnHover, overlayInfo } = useHover(currentTools, slice);
276+
277+
// Suppress hover for non-placing polygons when actively placing (has points)
278+
// or when a rectangle is actively being placed
279+
const onHover = (id: ToolID, event: any) => {
280+
if (isAnyRectanglePlacing()) {
281+
baseOnHover(id, { ...event, hovering: false });
282+
return;
283+
}
284+
if (placingTool.id.value && id !== placingTool.id.value) {
285+
const placingToolData = activeToolStore.toolByID[placingTool.id.value];
286+
if (placingToolData?.points?.length > 0) {
287+
baseOnHover(id, { ...event, hovering: false });
288+
return;
289+
}
290+
}
291+
baseOnHover(id, event);
292+
};
251293
252294
const mergePossible = computed(
253295
() => activeToolStore.mergeableTools.length >= 1

src/components/tools/rectangle/RectangleTool.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Tools } from '@/src/store/tools/types';
2828
import { getLPSAxisFromDir } from '@/src/utils/lps';
2929
import { LPSAxisDir } from '@/src/types/lps';
3030
import { useRectangleStore } from '@/src/store/tools/rectangles';
31+
import { usePolygonStore } from '@/src/store/tools/polygons';
3132
import {
3233
useCurrentTools,
3334
useContextMenu,
@@ -39,6 +40,7 @@ import AnnotationInfo from '@/src/components/tools/AnnotationInfo.vue';
3940
import { useFrameOfReference } from '@/src/composables/useFrameOfReference';
4041
import { Maybe } from '@/src/types';
4142
import { useSliceInfo } from '@/src/composables/useSliceInfo';
43+
import { ToolID } from '@/src/types/annotation-tool';
4244
import { watchImmediate } from '@vueuse/core';
4345
import RectangleWidget2D from './RectangleWidget2D.vue';
4446
@@ -121,7 +123,8 @@ export default defineComponent({
121123
122124
// --- //
123125
124-
const { contextMenu, openContextMenu } = useContextMenu();
126+
const { contextMenu, openContextMenu: baseOpenContextMenu } =
127+
useContextMenu();
125128
126129
const currentTools = useCurrentTools(
127130
activeToolStore,
@@ -133,7 +136,31 @@ export default defineComponent({
133136
})
134137
);
135138
136-
const { onHover, overlayInfo } = useHover(currentTools, slice);
139+
const { onHover: baseOnHover, overlayInfo } = useHover(currentTools, slice);
140+
141+
// Check if any polygon is actively being placed (has points)
142+
const polygonStore = usePolygonStore();
143+
const isAnyPolygonPlacing = () => {
144+
return polygonStore.tools.some(
145+
(tool) => tool.placing && tool.points.length > 0
146+
);
147+
};
148+
149+
// Suppress hover/context menu when a polygon is actively being placed
150+
const onHover = (id: ToolID, event: any) => {
151+
if (isAnyPolygonPlacing()) {
152+
baseOnHover(id, { ...event, hovering: false });
153+
return;
154+
}
155+
baseOnHover(id, event);
156+
};
157+
158+
const openContextMenu = (id: ToolID, event: any) => {
159+
if (isAnyPolygonPlacing()) {
160+
return;
161+
}
162+
baseOpenContextMenu(id, event);
163+
};
137164
138165
return {
139166
tools: currentTools,

src/vtk/PolygonWidget/behavior.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ export default function widgetBehavior(publicAPI: any, model: any) {
192192
if (model.widgetState.getPlacing() && manipulator) {
193193
// Dropping first point?
194194
if (model.widgetState.getHandles().length === 0) {
195-
// update variables used by updateActiveStateHandle
196-
model.activeState = model.widgetState.getMoveHandle();
197195
model._widgetManager.grabFocus(publicAPI);
198196
}
199197
updateActiveStateHandle(event);
@@ -252,6 +250,16 @@ export default function widgetBehavior(publicAPI: any, model: any) {
252250
model._widgetManager.disablePicking();
253251
}
254252

253+
// 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) {
256+
publicAPI.invokeHoverEvent({
257+
...event,
258+
hovering: false,
259+
});
260+
return macro.VOID;
261+
}
262+
255263
publicAPI.invokeHoverEvent({
256264
...event,
257265
hovering: !!model.activeState || checkOverFill(),
@@ -424,6 +432,12 @@ export default function widgetBehavior(publicAPI: any, model: any) {
424432
return macro.EVENT_ABORT;
425433
}
426434

435+
// 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) {
438+
return macro.VOID;
439+
}
440+
427441
const eventWithWidgetAction = {
428442
...eventData,
429443
widgetActions: makeWidgetActions(eventData),

src/vtk/RulerWidget/behavior.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ export default function widgetBehavior(publicAPI: any, model: any) {
184184
return macro.EVENT_ABORT;
185185
}
186186

187+
// Don't emit hover events if another widget has focus (e.g., is placing)
188+
const activeWidget = model._widgetManager.getActiveWidget();
189+
if (activeWidget && activeWidget !== publicAPI) {
190+
publicAPI.invokeHoverEvent({
191+
...eventData,
192+
hovering: false,
193+
});
194+
return macro.VOID;
195+
}
196+
187197
publicAPI.invokeHoverEvent({
188198
...eventData,
189199
hovering: !!model.activeState || checkOverFill(),
@@ -220,6 +230,13 @@ export default function widgetBehavior(publicAPI: any, model: any) {
220230
) {
221231
return macro.VOID;
222232
}
233+
234+
// If another widget has focus (e.g., is placing), don't show context menu
235+
const activeWidget = model._widgetManager.getActiveWidget();
236+
if (activeWidget && activeWidget !== publicAPI) {
237+
return macro.VOID;
238+
}
239+
223240
publicAPI.invokeRightClickEvent(eventData);
224241
return macro.EVENT_ABORT;
225242
};

0 commit comments

Comments
 (0)