-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathSelectTool.vue
More file actions
59 lines (52 loc) · 1.91 KB
/
SelectTool.vue
File metadata and controls
59 lines (52 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script setup lang="ts">
import { onVTKEvent } from '@/src/composables/onVTKEvent';
import { WIDGET_PRIORITY } from '@kitware/vtk.js/Widgets/Core/AbstractWidget/Constants';
import { useToolSelectionStore } from '@/src/store/tools/toolSelection';
import { useToolStore } from '@/src/store/tools';
import { Tools } from '@/src/store/tools/types';
import { vtkAnnotationToolWidget } from '@/src/vtk/ToolWidgetUtils/types';
import { inject } from 'vue';
import { VtkViewContext } from '@/src/components/vtk/context';
const view = inject(VtkViewContext);
if (!view) throw new Error('No VtkView');
const selectionStore = useToolSelectionStore();
const toolStore = useToolStore();
const PLACING_TOOLS = [Tools.Ruler, Tools.Rectangle, Tools.Polygon];
onVTKEvent(
view.interactor,
'onLeftButtonPress',
(event: any) => {
if (PLACING_TOOLS.includes(toolStore.currentTool)) {
// avoid bugs when starting a placing tool on an existing tool and right clicking and deleting existing tools
return;
}
const withModifiers = !!(event.shiftKey || event.controlKey);
const selectedData = view.widgetManager.getSelectedData();
if ('widget' in selectedData) {
// clicked in empty space.
const widget = selectedData.widget as vtkAnnotationToolWidget;
const widgetState = widget.getWidgetState();
const id = widgetState.getId();
const type = widgetState.getToolType();
// preserve if we've used shift or ctrl
if (withModifiers) {
selectionStore.toggleSelection(id, type);
} else {
selectionStore.clearSelection();
selectionStore.addSelection(id, type);
}
} else if (!withModifiers) {
// if no modifiers, then deselect
selectionStore.clearSelection();
}
},
{
// capture all events by calling handler before widgets
priority: WIDGET_PRIORITY + 1,
}
);
const render = () => {};
</script>
<template>
<render />
</template>