import { InteractionType, ObjectBoolean, ScanView } from '@3cr/types-ts'; import { ref, watch } from 'vue'; import { useDataOverlayStore } from '@/stores/data-overlay.store'; import { useViewer3cr } from '@/composables/useViewer3cr'; import { storeToRefs } from 'pinia'; import { useViewerStore } from '@/stores/viewer.store'; import { DataOverlayAnnotation } from '@3cr/viewer-types-ts'; export function useAnnotationMoveTool() { const viewer3cr = useViewer3cr(); const { annotationEvent } = storeToRefs(useDataOverlayStore()); const { activeView } = storeToRefs(useViewerStore()); const isActive = ref(false); const selected = ref(null); watch(isActive, async (isActive) => { if (!isActive && selected.value) { await moveAnnotation2d(selected.value.Id, false); await moveAnnotation3d(selected.value.Id, false); selected.value = null; } }); watch(annotationEvent, async (event) => { if ( isActive.value && event?.Data.Interaction === InteractionType.POINTER_UP ) { if (activeView.value === ScanView.Volume) { await moveAnnotation3d(event.Data.DataOverlay.Id, true); selected.value = event.Data.DataOverlay; } else if (activeView.value !== undefined) { await moveAnnotation2d(event.Data.DataOverlay.Id, true); selected.value = event.Data.DataOverlay; } } }); async function moveAnnotation2d(id: string, value: boolean): Promise { const message: ObjectBoolean = { Version: '0.0.0', Id: id, Value: value }; await viewer3cr.moveAnnotation2dTool({ message }); } async function moveAnnotation3d(id: string, value: boolean): Promise { const message: ObjectBoolean = { Version: '0.0.0', Id: id, Value: value }; await viewer3cr.moveAnnotation3dTool({ message }); } return { isActive, selected }; }