All files / src/components/navigation/measurement MeasurementTools.vue

100% Statements 26/26
100% Branches 10/10
100% Functions 10/10
100% Lines 25/25

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                                                            666x               1x       1x       1x         1x                                 68x 68x   68x         68x     68x 68x 68x   68x                                         68x 60x       1x 1x 1x       1x 1x 1x       1x 1x 1x     68x              
<template>
  <v-card
    v-bind="$attrs"
    color="background"
    flat
    tile
  >
    <DrawerTitle :title="t('labels.measurementTools')" />
    <v-card-text class="px-2 pb-4">
      <v-tabs
        :model-value="activeIndex"
        fixed-tabs
        :mandatory="false"
      >
        <template v-for="tab in tabs">
          <v-tooltip
            location="bottom"
            open-delay="1000"
          >
            <template #activator="{ props }">
              <v-tab
                v-bind="props"
                @click="tab.click"
              >
                <v-icon :icon="tab.icon" />
              </v-tab>
            </template>
            <span
              >{{ tab.tooltip }}
              {{ translateTooltipShortcut(tab.tooltipShortcut) }}</span
            >
          </v-tooltip>
        </template>
      </v-tabs>
    </v-card-text>
  </v-card>
  <MeasurementLengthSnackbar
    class="mb-3"
    v-model="s_length"
  />
  <MeasurementPolygonSnackbar
    class="mb-3"
    v-model="s_polygon"
  />
  <MeasurementAngleSnackbar
    class="mb-3"
    v-model="s_angle"
  />
  <MeasurementDeleteSnackbar
    class="mb-3"
    v-if="measurementToDelete"
    v-model="s_measurementDelete"
    :measurement="measurementToDelete"
  />
</template>
 
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from 'vue';
import { useToolStore } from '@/stores/tool.store';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n';
import {
  SHORTCUT_TEXT,
  translateTooltipShortcut,
} from '@/functions/translateTooltipShortcut';
import { useViewerStore } from '@/stores/viewer.store';
import { useToolGroup } from '@/composables/useToolGroup';
 
const { t } = useI18n();
const { measurementAngleTool, measurementLengthTool, measurementPolygonTool } =
  useToolStore();
const { activeTool, activeIndex, toggleTool } = useToolGroup(
  measurementLengthTool,
  measurementPolygonTool,
  measurementAngleTool,
);
const { measurementToDelete, s_measurementDelete } =
  storeToRefs(useViewerStore());
 
const s_length = ref<boolean>(false);
const s_polygon = ref<boolean>(false);
const s_angle = ref<boolean>(false);
 
const tabs = computed(() => [
  {
    icon: 'straighten',
    click: length,
    tooltip: t('labels.length'),
    tooltipShortcut: SHORTCUT_TEXT.l,
  },
  {
    icon: 'polyline',
    click: polygon,
    tooltip: t('labels.polygon'),
    tooltipShortcut: SHORTCUT_TEXT.p,
  },
  {
    icon: 'square_foot',
    click: angle,
    tooltip: t('labels.angle'),
    tooltipShortcut: SHORTCUT_TEXT.a,
  },
]);
 
onBeforeUnmount(() => {
  activeTool.value = null;
});
 
function angle(): void {
  s_angle.value = toggleTool(measurementAngleTool);
  s_length.value = false;
  s_polygon.value = false;
}
 
function length(): void {
  s_angle.value = false;
  s_length.value = toggleTool(measurementLengthTool);
  s_polygon.value = false;
}
 
function polygon(): void {
  s_angle.value = false;
  s_length.value = false;
  s_polygon.value = toggleTool(measurementPolygonTool);
}
 
defineExpose({
  angle,
  length,
  polygon,
});
defineOptions({ inheritAttrs: false });
</script>