rvlib/tools_data/annotations/
mod.rs

1//! Functionality to create and modify annotations.
2pub use self::bbox_annotations::BboxAnnotations;
3pub use self::bbox_splitmode::SplitMode;
4pub use self::brush_annotations::BrushAnnotations;
5pub use self::core::{ClipboardData, InstanceAnnotations};
6
7mod bbox_annotations;
8mod bbox_splitmode;
9mod brush_annotations;
10mod core;
11#[macro_export]
12macro_rules! implement_annotations_getters {
13    ($tool_data_type:ident) => {
14        pub fn get_annos_mut(
15            &mut self,
16            file_path: &str,
17            shape_initial: ShapeI,
18        ) -> Option<&mut $tool_data_type> {
19            if !self.annotations_map.contains_key(file_path) {
20                self.annotations_map.insert(
21                    file_path.to_string(),
22                    ($tool_data_type::default(), shape_initial),
23                );
24            } else {
25                // we reset the shape every time, since a file with the same name but a different shape
26                // might have replaced the old one
27                if let Some((_, shape)) = self.annotations_map.get_mut(file_path) {
28                    if *shape != shape_initial {
29                        *shape = shape_initial;
30                    }
31                }
32            }
33            self.annotations_map
34                .get_mut(file_path)
35                .map(|(annos, _)| annos)
36        }
37        #[must_use]
38        pub fn get_annos(&self, file_path: &str) -> Option<&$tool_data_type> {
39            let annos = self.annotations_map.get(file_path);
40            annos.map(|(annos, _shape)| annos)
41        }
42        pub fn anno_iter_mut(
43            &mut self,
44        ) -> impl Iterator<Item = (&String, &mut ($tool_data_type, ShapeI))> {
45            self.annotations_map.iter_mut()
46        }
47        pub fn anno_iter(&self) -> impl Iterator<Item = (&String, &($tool_data_type, ShapeI))> {
48            self.annotations_map.iter()
49        }
50        pub fn anno_intoiter(self) -> impl Iterator<Item = (String, ($tool_data_type, ShapeI))> {
51            self.annotations_map.into_iter()
52        }
53    };
54}