use re_log_types::{hash::Hash64, EntityPath, EntityPathFilter, EntityPathSubs};
use re_types::ViewClassIdentifier;
#[derive(Debug, Clone)]
pub struct RecommendedView {
pub origin: EntityPath,
pub query_filter: EntityPathFilter,
}
#[derive(Default)]
pub struct ViewSpawnHeuristics {
recommended_views: Vec<RecommendedView>,
}
impl ViewSpawnHeuristics {
#[inline]
pub fn empty() -> Self {
Self {
recommended_views: Vec::new(),
}
}
#[inline]
pub fn root() -> Self {
Self {
recommended_views: vec![RecommendedView::root()],
}
}
pub fn new(iter: impl IntoIterator<Item = RecommendedView>) -> Self {
let mut recommended_views: Vec<RecommendedView> = iter.into_iter().collect();
recommended_views.sort_by(|a, b| a.origin.cmp(&b.origin));
Self { recommended_views }
}
#[inline]
pub fn into_vec(self) -> Vec<RecommendedView> {
self.recommended_views
}
}
impl RecommendedView {
#[inline]
pub fn new<'a>(origin: EntityPath, expressions: impl IntoIterator<Item = &'a str>) -> Self {
let space_env = EntityPathSubs::new_with_origin(&origin);
Self {
origin,
query_filter: EntityPathFilter::from_query_expressions_forgiving(
expressions,
&space_env,
),
}
}
#[inline]
pub fn new_subtree(origin: EntityPath) -> Self {
Self::new(origin, std::iter::once("$origin/**"))
}
#[inline]
pub fn new_single_entity(origin: EntityPath) -> Self {
Self::new(origin, std::iter::once("$origin"))
}
#[inline]
pub fn root() -> Self {
Self::new_subtree(EntityPath::root())
}
pub fn recommendation_hash(
&self,
class_id: ViewClassIdentifier,
) -> re_types::blueprint::components::ViewerRecommendationHash {
let Self {
origin,
query_filter,
} = self;
Hash64::hash((origin, query_filter, class_id))
.hash64()
.into()
}
}