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
use re_types::{archetypes::AnnotationContext, Archetype, ComponentNameSet};
use re_viewer_context::{
    AnnotationMap, IdentifiedViewSystem, ViewContextSystem, ViewSystemIdentifier,
};

#[derive(Default)]
pub struct AnnotationSceneContext(pub AnnotationMap);

impl IdentifiedViewSystem for AnnotationSceneContext {
    fn identifier() -> ViewSystemIdentifier {
        "AnnotationSceneContext".into()
    }
}

impl ViewContextSystem for AnnotationSceneContext {
    fn compatible_component_sets(&self) -> Vec<ComponentNameSet> {
        vec![
            AnnotationContext::required_components()
                .iter()
                .map(ToOwned::to_owned)
                .collect(), //
        ]
    }

    fn execute(
        &mut self,
        ctx: &re_viewer_context::ViewContext<'_>,
        query: &re_viewer_context::ViewQuery<'_>,
    ) {
        re_tracing::profile_function!();
        // We create a list of *all* entities here, do not only iterate over those with annotation context.
        // TODO(andreas): But knowing ahead of time where we have annotation contexts could be used for optimization.
        self.0.load(
            ctx.viewer_ctx,
            &query.latest_at_query(),
            query.iter_all_entities(),
        );
    }

    fn as_any(&self) -> &dyn std::any::Any {
        self
    }
}