All files / src/tools annotation-move.tool.ts

100% Statements 23/23
100% Branches 12/12
100% Functions 5/5
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                  18x 18x 18x   18x 18x   18x 7x 1x 1x 1x       18x 18x       12x 2x 2x 10x 6x 6x           7x 7x       3x 3x     18x    
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<boolean>(false);
  const selected = ref<DataOverlayAnnotation | null>(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<void> {
    const message: ObjectBoolean = { Version: '0.0.0', Id: id, Value: value };
    await viewer3cr.moveAnnotation2dTool({ message });
  }
 
  async function moveAnnotation3d(id: string, value: boolean): Promise<void> {
    const message: ObjectBoolean = { Version: '0.0.0', Id: id, Value: value };
    await viewer3cr.moveAnnotation3dTool({ message });
  }
 
  return { isActive, selected };
}