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
//! Functionality to create and modify annotations.

pub use self::bbox_annotations::BboxAnnotations;
pub use self::bbox_splitmode::SplitMode;
pub use self::brush_annotations::BrushAnnotations;
pub use self::core::{ClipboardData, InstanceAnnotations};

mod bbox_annotations;
mod bbox_splitmode;
mod brush_annotations;
mod core;
#[macro_export]
macro_rules! implement_annotations_getters {
    ($tool_data_type:ident) => {
        pub fn get_annos_with_shape_mut(
            &mut self,
            file_path: &str,
            shape: ShapeI,
        ) -> Option<(&mut $tool_data_type, Option<&mut ShapeI>)> {
            let is_shape_none = if !self.annotations_map.contains_key(file_path) {
                self.annotations_map
                    .insert(file_path.to_string(), ($tool_data_type::default(), shape));
                true
            } else {
                false
            };
            self.annotations_map
                .get_mut(file_path)
                .map(|(annos, shape)| {
                    if is_shape_none {
                        (annos, None)
                    } else {
                        (annos, Some(shape))
                    }
                })
        }
        pub fn get_annos_mut(
            &mut self,
            file_path: &str,
            shape: ShapeI,
        ) -> Option<&mut $tool_data_type> {
            self.get_annos_with_shape_mut(file_path, shape)
                .map(|(annos, _shape)| annos)
        }
        pub fn get_annos(&self, file_path: &str) -> Option<&$tool_data_type> {
            let annos = self.annotations_map.get(file_path);
            annos.map(|(annos, _shape)| annos)
        }
        pub fn anno_iter_mut(
            &mut self,
        ) -> impl Iterator<Item = (&String, &mut ($tool_data_type, ShapeI))> {
            self.annotations_map.iter_mut()
        }
        pub fn anno_iter(&self) -> impl Iterator<Item = (&String, &($tool_data_type, ShapeI))> {
            self.annotations_map.iter()
        }
        pub fn anno_intoiter(self) -> impl Iterator<Item = (String, ($tool_data_type, ShapeI))> {
            self.annotations_map.into_iter()
        }
    };
}