Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
import { types } from "mobx-state-tree";
 
/**
 * This mixing defines perItem control-tag's parameter and related basic functionality
 * It should be used right after ClassificationBase mixin
 * @see ClassificationBase
 */
const PerItemMixin = types
  .model({
    peritem: types.optional(types.boolean, false),
  })
  .extend((self) => {
    /* Validation */
    if (self.isClassificationTag !== true) {
      throw new Error("The PerItemMixin mixin should be used only for classification control-tags");
    }
    return {};
  })
  .views((self) => ({
    get _perItemResult() {
      return self.annotation.results.find((r) => {
        return r.from_name === self && r.area.item_index === self.toNameTag.currentItemIndex;
      });
    },
  }))
  .actions((self) => ({
    /**
     * Validates all values related to the current classification per item (Multi Items Segmentation).
     *
     * - This method should not be overridden.
     * - It is used only in validate method of the ClassificationBase mixin.
     *
     * @returns {boolean}
     * @private
     */
    _validatePerItem() {
      const objectTag = self.toNameTag;
 
      return self.annotation.regions.every((reg) => {
        const result = reg.results.find((s) => s.from_name === self);
 
        if (!result?.hasValue) {
          return true;
        }
        const value = result.mainValue;
        const isValid = self.validateValue(value);
 
        if (!isValid) {
          objectTag.setCurrentItem(reg.item_index);
          return false;
        }
        return true;
      });
    },
    createPerItemResult() {
      self.createPerObjectResult({
        item_index: self.toNameTag.currentItemIndex,
      });
    },
  }));
 
export default PerItemMixin;