use re_log_types::{hash::Hash64, EntityPath, EntityPathFilter, EntityPathSubs};
use re_types::SpaceViewClassIdentifier;
#[derive(Debug, Clone)]
pub struct RecommendedSpaceView {
pub origin: EntityPath,
pub query_filter: EntityPathFilter,
}
#[derive(Default)]
pub struct SpaceViewSpawnHeuristics {
recommended_space_views: Vec<RecommendedSpaceView>,
}
impl SpaceViewSpawnHeuristics {
#[inline]
pub fn empty() -> Self {
Self {
recommended_space_views: Vec::new(),
}
}
#[inline]
pub fn root() -> Self {
Self {
recommended_space_views: vec![RecommendedSpaceView::root()],
}
}
pub fn new(iter: impl IntoIterator<Item = RecommendedSpaceView>) -> Self {
let mut recommended_space_views: Vec<RecommendedSpaceView> = iter.into_iter().collect();
recommended_space_views.sort_by(|a, b| a.origin.cmp(&b.origin));
Self {
recommended_space_views,
}
}
#[inline]
pub fn into_vec(self) -> Vec<RecommendedSpaceView> {
self.recommended_space_views
}
}
impl RecommendedSpaceView {
#[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: SpaceViewClassIdentifier,
) -> re_types::blueprint::components::ViewerRecommendationHash {
let Self {
origin,
query_filter,
} = self;
Hash64::hash((origin, query_filter, class_id))
.hash64()
.into()
}
}