re_viewer_context/view/
view_context.rs1use re_chunk_store::LatestAtQuery;
2use re_log_types::{EntityPath, TimePoint};
3use re_query::StorageEngineReadGuard;
4use re_types::{AsComponents, ComponentBatch, ComponentDescriptor, ViewClassIdentifier};
5
6use crate::{
7 DataQueryResult, DataResult, QueryContext, ViewId, blueprint_helpers::BlueprintContext as _,
8};
9
10use super::VisualizerCollection;
11
12pub struct ViewContext<'a> {
20 pub viewer_ctx: &'a crate::ViewerContext<'a>,
21 pub view_id: ViewId,
22 pub view_class_identifier: ViewClassIdentifier,
23 pub view_state: &'a dyn crate::ViewState,
24 pub query_result: &'a DataQueryResult,
25}
26
27impl<'a> ViewContext<'a> {
28 #[inline]
29 pub fn query_context(
30 &'a self,
31 data_result: &'a DataResult,
32 query: &'a LatestAtQuery,
33 ) -> QueryContext<'a> {
34 QueryContext {
35 view_ctx: self,
36 target_entity_path: &data_result.entity_path,
37 archetype_name: None,
38 query,
39 }
40 }
41
42 #[inline]
43 pub fn render_ctx(&self) -> &re_renderer::RenderContext {
44 self.viewer_ctx.global_context.render_ctx
45 }
46
47 #[inline]
48 pub fn egui_ctx(&self) -> &egui::Context {
49 self.viewer_ctx.global_context.egui_ctx
50 }
51
52 pub fn tokens(&self) -> &'static re_ui::DesignTokens {
53 self.viewer_ctx.tokens()
54 }
55
56 #[inline]
58 pub fn recording(&self) -> &re_entity_db::EntityDb {
59 self.viewer_ctx.recording()
60 }
61
62 #[inline]
64 pub fn recording_engine(&self) -> StorageEngineReadGuard<'_> {
65 self.viewer_ctx.recording_engine()
66 }
67
68 #[inline]
70 pub fn blueprint_db(&self) -> &re_entity_db::EntityDb {
71 self.viewer_ctx.blueprint_db()
72 }
73
74 #[inline]
76 pub fn blueprint_query(&self) -> &LatestAtQuery {
77 self.viewer_ctx.blueprint_query
78 }
79
80 #[inline]
82 pub fn store_id(&self) -> &re_log_types::StoreId {
83 self.viewer_ctx.store_id()
84 }
85
86 #[inline]
88 pub fn selection(&self) -> &crate::ItemCollection {
89 self.viewer_ctx.selection()
90 }
91
92 #[inline]
94 pub fn hovered(&self) -> &crate::ItemCollection {
95 self.viewer_ctx.hovered()
96 }
97
98 #[inline]
99 pub fn selection_state(&self) -> &crate::ApplicationSelectionState {
100 self.viewer_ctx.selection_state()
101 }
102
103 #[inline]
105 pub fn current_query(&self) -> LatestAtQuery {
106 self.viewer_ctx.current_query()
107 }
108
109 #[inline]
110 pub fn lookup_query_result(&self, id: ViewId) -> &DataQueryResult {
111 self.viewer_ctx.lookup_query_result(id)
112 }
113
114 #[inline]
115 pub fn save_blueprint_array(
116 &self,
117 entity_path: EntityPath,
118 component_descr: ComponentDescriptor,
119 array: arrow::array::ArrayRef,
120 ) {
121 self.viewer_ctx
122 .save_blueprint_array(entity_path, component_descr, array);
123 }
124
125 #[inline]
126 pub fn save_blueprint_archetype(&self, entity_path: EntityPath, components: &dyn AsComponents) {
127 self.viewer_ctx
128 .save_blueprint_archetype(entity_path, components);
129 }
130
131 #[inline]
132 pub fn save_blueprint_component(
133 &self,
134 entity_path: EntityPath,
135 component_desc: &ComponentDescriptor,
136 component_batch: &dyn ComponentBatch,
137 ) {
138 self.viewer_ctx
139 .save_blueprint_component(entity_path, component_desc, component_batch);
140 }
141
142 #[inline]
143 pub fn reset_blueprint_component(
144 &self,
145 entity_path: EntityPath,
146 component_descr: ComponentDescriptor,
147 ) {
148 self.viewer_ctx
149 .reset_blueprint_component(entity_path, component_descr);
150 }
151
152 #[inline]
154 pub fn clear_blueprint_component(
155 &self,
156 entity_path: EntityPath,
157 component_descr: ComponentDescriptor,
158 ) {
159 self.viewer_ctx
160 .clear_blueprint_component(entity_path, component_descr);
161 }
162
163 #[inline]
164 pub fn blueprint_timepoint_for_writes(&self) -> TimePoint {
165 self.viewer_ctx
166 .store_context
167 .blueprint_timepoint_for_writes()
168 }
169
170 pub fn new_visualizer_collection(&self) -> VisualizerCollection {
175 self.viewer_ctx
176 .view_class_registry()
177 .new_visualizer_collection(self.view_class_identifier)
178 }
179}