use std::sync::Arc;
use re_chunk::ArrowArray;
use re_chunk_store::LatestAtQuery;
use re_log_types::{EntityPath, TimePoint};
use re_query::StorageEngineReadGuard;
use re_types::{AsComponents, ComponentBatch, ComponentName};
use crate::{DataQueryResult, DataResult, QueryContext, SpaceViewId};
pub struct ViewContext<'a> {
pub viewer_ctx: &'a crate::ViewerContext<'a>,
pub view_id: SpaceViewId,
pub view_state: &'a dyn crate::SpaceViewState,
pub defaults_path: &'a EntityPath,
pub visualizer_collection: Arc<crate::VisualizerCollection>,
}
impl<'a> ViewContext<'a> {
#[inline]
pub fn query_context(
&'a self,
data_result: &'a DataResult,
query: &'a LatestAtQuery,
) -> QueryContext<'a> {
QueryContext {
viewer_ctx: self.viewer_ctx,
target_entity_path: &data_result.entity_path,
archetype_name: None,
query,
view_state: self.view_state,
view_ctx: Some(self),
}
}
#[inline]
pub fn recording(&self) -> &re_entity_db::EntityDb {
self.viewer_ctx.recording()
}
#[inline]
pub fn recording_engine(&self) -> StorageEngineReadGuard<'_> {
self.viewer_ctx.recording_engine()
}
#[inline]
pub fn blueprint_db(&self) -> &re_entity_db::EntityDb {
self.viewer_ctx.blueprint_db()
}
#[inline]
pub fn recording_id(&self) -> re_log_types::StoreId {
self.viewer_ctx.recording_id()
}
#[inline]
pub fn selection(&self) -> &crate::ItemCollection {
self.viewer_ctx.selection()
}
#[inline]
pub fn hovered(&self) -> &crate::ItemCollection {
self.viewer_ctx.hovered()
}
#[inline]
pub fn selection_state(&self) -> &crate::ApplicationSelectionState {
self.viewer_ctx.selection_state()
}
#[inline]
pub fn current_query(&self) -> LatestAtQuery {
self.viewer_ctx.current_query()
}
#[inline]
pub fn select_hovered_on_click(
&self,
response: &egui::Response,
selection: impl Into<crate::ItemCollection>,
) {
self.viewer_ctx.select_hovered_on_click(response, selection);
}
#[inline]
pub fn lookup_query_result(&self, id: SpaceViewId) -> &DataQueryResult {
self.viewer_ctx.lookup_query_result(id)
}
#[inline]
pub fn save_blueprint_array(
&self,
entity_path: &EntityPath,
component_name: ComponentName,
array: Box<dyn ArrowArray>,
) {
self.viewer_ctx
.save_blueprint_array(entity_path, component_name, array);
}
#[inline]
pub fn save_blueprint_archetype(
&self,
entity_path: &EntityPath,
components: &dyn AsComponents,
) {
self.viewer_ctx
.save_blueprint_archetype(entity_path, components);
}
#[inline]
pub fn save_blueprint_component(
&self,
entity_path: &EntityPath,
components: &dyn ComponentBatch,
) {
self.viewer_ctx
.save_blueprint_component(entity_path, components);
}
#[inline]
pub fn save_empty_blueprint_component<C>(&self, entity_path: &EntityPath)
where
C: re_types::Component + 'a,
{
self.viewer_ctx
.save_empty_blueprint_component::<C>(entity_path);
}
#[inline]
pub fn reset_blueprint_component_by_name(
&self,
entity_path: &EntityPath,
component_name: ComponentName,
) {
self.viewer_ctx
.reset_blueprint_component_by_name(entity_path, component_name);
}
#[inline]
pub fn clear_blueprint_component_by_name(
&self,
entity_path: &EntityPath,
component_name: ComponentName,
) {
self.viewer_ctx
.clear_blueprint_component_by_name(entity_path, component_name);
}
#[inline]
pub fn blueprint_timepoint_for_writes(&self) -> TimePoint {
self.viewer_ctx
.store_context
.blueprint_timepoint_for_writes()
}
}