import { defineStore } from 'pinia'; import { computed, ref } from 'vue'; import { AnchorPoint, PositionData, ScanView } from '@3cr/types-ts'; import { DataOverlay, ViewerOptions } from '@3cr/viewer-types-ts'; import { zip } from 'lodash'; function makeLayout2x2(views: ScanView[]): PositionData[] { const anchors = [ AnchorPoint.TOP_LEFT, AnchorPoint.TOP_RIGHT, AnchorPoint.BOTTOM_LEFT, AnchorPoint.BOTTOM_RIGHT, ]; return zip(views, anchors).map(([view, anchor], idx) => ({ Version: '0.0.0', ActiveView: idx === 0, DefaultView: view!, Anchor: anchor!, Offset: { Version: '0.0.0', X: 0, Y: 0 }, AspectRatio: -1, MaxSize: { Version: '0.0.0', X: 0.5, Y: 0.5 }, Priority: 0, })); } function makeLayout1x3(views: ScanView[]): PositionData[] { const anchors = [ AnchorPoint.CENTER, AnchorPoint.TOP_RIGHT, AnchorPoint.RIGHT, AnchorPoint.BOTTOM_RIGHT, ]; return zip(views, anchors).map(([view, anchor], idx) => ({ Version: '1.0.0', ActiveView: idx === 0, DefaultView: view!, Anchor: anchor!, Offset: { Version: '1.0.0', X: 0, Y: 0 }, AspectRatio: idx === 0 ? -1 : 1, MaxSize: { Version: '1.0.0', X: 1, Y: idx === 0 ? 1 : 1 / 3 }, Priority: idx === 0 ? 0 : 1, })); } export const useViewerStore = defineStore('viewer', () => { const activeView = ref(); const enableMouse = ref(false); const enableKeyboard = ref(false); const inputOverride = ref(false); const options = ref({}); const notifications = ref(false); const measurementToDelete = ref(); const s_annotationDelete = ref(false); const s_measurementDelete = ref(false); const defaultLayout2x2 = computed(() => { if (options.value.layout2x2 && options.value.layout2x2.length === 4) { return makeLayout2x2(options.value.layout2x2); } else { const defaults = [ ScanView.Volume, ScanView.Sagittal, ScanView.Transverse, ScanView.Coronal, ]; return makeLayout2x2(defaults); } }); const defaultLayout1x3 = computed(() => { if (options.value.layout1x3 && options.value.layout1x3.length === 4) { return makeLayout1x3(options.value.layout1x3); } else { const defaults = [ ScanView.Volume, ScanView.Transverse, ScanView.Coronal, ScanView.Sagittal, ]; return makeLayout1x3(defaults); } }); return { activeView, enableMouse, inputOverride, enableKeyboard, options, notifications, measurementToDelete, s_annotationDelete, s_measurementDelete, defaultLayout2x2, defaultLayout1x3, }; });