All files / src/components/modal ViewerScanView.vue

70.58% Statements 48/68
90% Branches 18/20
56.52% Functions 13/23
70.31% Lines 45/64

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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289                                  4x 4x 4x                         8x                           6x       4x                       4x       1x           1x           1x                                                                                   8x         8x 8x   8x   8x   8x 8x   8x 8x   8x 8x 8x   8x   8x 8x   2x   4x   1x   1x       8x 8x         8x                   8x                   8x                 8x                   8x         8x         8x           1x       1x 1x 1x       1x 1x 1x                                                                                                                    
<template>
  <div
    :class="['scan-view', viewClass]"
    ref="container"
    @mouseenter="onMouseEnter"
    @mousedown="onMouseEnter"
    @mouseleave="onMouseLeave"
    @touchstart="onMouseEnter"
    @touchmove="onMouseEnter"
    @touchend="onMouseLeave"
    @dblclick="onDoubleClick"
  >
    <v-hover #default="{ isHovering, props }">
      <div
        v-bind="props"
        class="d-flex h-100 w-100"
      >
        <div class="d-flex flex-column flex-fill overflow-hidden">
          <div class="pa-2">
            <span class="text-white">{{ name }}</span>
            <v-tooltip
              v-if="horizontalFlip"
              location="bottom"
            >
              <template #activator="{ props }">
                <v-icon
                  v-bind="props"
                  icon="swap_horiz"
                  color="blue-darken-1"
                  class="ml-2"
                />
              </template>
              <span>{{ t('texts.flippedHorizontally') }}</span>
            </v-tooltip>
            <v-tooltip
              v-if="verticalFlip"
              location="bottom"
            >
              <template #activator="{ props }">
                <v-icon
                  v-bind="props"
                  icon="swap_vert"
                  color="blue-darken-1"
                  class="ml-2"
                />
              </template>
              <span>{{ t('texts.flippedVertically') }}</span>
            </v-tooltip>
          </div>
          <v-spacer />
          <div class="pa-2">
            <Transition>
              <div v-show="isHovering || isUserInteracting">
                <ViewerActionRail
                  :target="container"
                  :view="position.DefaultView"
                  @modal="onActionModal"
                />
              </div>
            </Transition>
          </div>
        </div>
        <div class="d-flex flex-column">
          <VerticalSliderSelector
            v-if="position.DefaultView === ScanView.Transverse"
            class="px-4 my-0"
            v-model:value="scanState.Orientations.Transverse.Slice"
            v-bind="tMinMax"
          />
          <VerticalSliderSelector
            v-if="position.DefaultView === ScanView.Coronal"
            class="px-4 my-0"
            v-model:value="scanState.Orientations.Coronal.Slice"
            v-bind="cMinMax"
          />
          <VerticalSliderSelector
            v-if="position.DefaultView === ScanView.Sagittal"
            class="px-4 my-0"
            v-model:value="scanState.Orientations.Sagittal.Slice"
            v-bind="sMinMax"
          />
        </div>
      </div>
    </v-hover>
  </div>
</template>
 
<script setup lang="ts">
import {
  isHorizontalFlip,
  isVerticalFlip,
  cMinMax,
  scanState,
  sMinMax,
  tMinMax,
  isFullscreen,
  previousLayout,
} from '@/models/scanState';
import {
  LayoutActions,
  PositionData,
  ScanView,
  ViewSelectionActions,
} from '@3cr/types-ts';
import { computed, onMounted, ref, toRefs } from 'vue';
import { storeToRefs } from 'pinia';
import { useViewerStore } from '@/stores/viewer.store';
import { useI18n } from 'vue-i18n';
import { useViewName } from '@/composables/useViewName';
import { forceType } from '@/functions/tsHelper';
import { useViewer3cr } from '@/composables/useViewer3cr';
import { useActiveLayout } from '@/components/modal/layouts/composables/useActiveLayout';
 
interface Props {
  position: PositionData;
  canvas: HTMLCanvasElement;
  padding?: number;
  radius?: number;
}
 
const props = withDefaults(defineProps<Props>(), {
  padding: 8,
  radius: 8,
});
 
const { t } = useI18n();
const { activeView, enableMouse, enableKeyboard } =
  storeToRefs(useViewerStore());
const viewer3cr = useViewer3cr();
 
const { position, canvas, padding } = toRefs(props);
 
const anchor = computed(() => position.value.Anchor);
const { layout } = useActiveLayout(anchor, canvas, padding);
 
const isUserInteracting = ref<boolean>(false);
const container = ref<HTMLDivElement>();
 
const view = computed(() => position.value.DefaultView);
const horizontalFlip = computed(() => isHorizontalFlip(view.value));
const verticalFlip = computed(() => isVerticalFlip(view.value));
 
const { name } = useViewName(view);
 
const viewClass = computed(() => {
  switch (props.position.DefaultView) {
    case ScanView.Volume:
      return 'volume';
    case ScanView.Sagittal:
      return 'sagittal';
    case ScanView.Coronal:
      return 'coronal';
    case ScanView.Transverse:
      return 'transverse';
  }
});
 
onMounted(() => {
  container.value!.addEventListener('wheel', (e: WheelEvent) => {
    e.preventDefault();
    props.canvas.dispatchEvent(new WheelEvent(e.type, e));
  });
 
  container.value!.addEventListener(
    'touchstart',
    (e: TouchEvent) => {
      props.canvas.dispatchEvent(
        new TouchEvent(e.type, forceType<TouchEventInit>(e)),
      );
    },
    { passive: true },
  );
 
  container.value!.addEventListener(
    'touchmove',
    (e: TouchEvent) => {
      props.canvas.dispatchEvent(
        new TouchEvent(e.type, forceType<TouchEventInit>(e)),
      );
    },
    { passive: true },
  );
 
  container.value!.addEventListener(
    'touchend',
    (e: TouchEvent) => {
      props.canvas.dispatchEvent(
        new TouchEvent(e.type, forceType<TouchEventInit>(e)),
      );
    },
    { passive: true },
  );
  container.value!.addEventListener(
    'touchcancel',
    (e: TouchEvent) => {
      props.canvas.dispatchEvent(
        new TouchEvent(e.type, forceType<TouchEventInit>(e)),
      );
    },
    { passive: true },
  );
 
  container.value!.addEventListener('mousedown', (e: MouseEvent) => {
    e.preventDefault();
    props.canvas.dispatchEvent(new MouseEvent(e.type, e));
  });
 
  container.value!.addEventListener('mouseup', (e: MouseEvent) => {
    e.preventDefault();
    props.canvas.dispatchEvent(new MouseEvent(e.type, e));
  });
 
  container.value!.addEventListener('contextmenu', (e: Event) => {
    e.preventDefault();
  });
});
 
function onActionModal(value: boolean): void {
  isUserInteracting.value = value;
}
 
function onMouseEnter(): void {
  activeView.value = props.position.DefaultView;
  enableMouse.value = true;
  enableKeyboard.value = true;
}
 
function onMouseLeave(): void {
  activeView.value = undefined;
  enableMouse.value = false;
  enableKeyboard.value = false;
}
 
async function onDoubleClick(): Promise<void> {
  if (!isFullscreen.value) {
    previousLayout.value = scanState.value.Layout.PositionData;
    await viewer3cr.viewSelection(
      `vs_0${view.value + 1}` as ViewSelectionActions,
    );
    await viewer3cr.layouts(LayoutActions.lo01);
    await viewer3cr.viewSelection(
      `vs_0${view.value + 1}` as ViewSelectionActions,
    ); // for compatibility < 3CR 2.1.0
  } else {
    const message = { Version: '0.0.0', PositionData: previousLayout.value };
    await viewer3cr.customLayout({ message });
    previousLayout.value = [];
  }
}
</script>
 
<style scoped lang="scss">
@use 'sass:map';
@use '@/assets/palette' as p;
 
.volume {
  cursor: grab;
}
 
.scan-view {
  left: calc(v-bind('layout.x') * 1px);
  top: calc(v-bind('layout.y') * 1px);
  width: calc(v-bind('layout.width') * 1px);
  height: calc(v-bind('layout.height') * 1px);
 
  border: transparent 2px dashed;
  border-radius: calc(v-bind('radius') * 1px);
  position: absolute;
  transition:
    border 0.5s linear,
    box-shadow 0.5s linear;
}
 
.scan-view:hover {
  border: map.get(p.$minsk, 500) 2px dashed;
  box-shadow: 0 0 8px 1px map.get(p.$minsk, 500);
}
 
.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s linear;
}
 
.v-enter-from,
.v-leave-to {
  opacity: 0;
}
</style>