Skip to content

Commit

Permalink
Continue tearing out SpaceViewContents
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Nov 28, 2023
1 parent e2557ab commit 545db19
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 288 deletions.
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl DataUi for Item {
query: &re_arrow_store::LatestAtQuery,
) {
match self {
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _, _) => {
// Shouldn't be reachable since SelectionPanel::contents doesn't show data ui for these.
// If you add something in here make sure to adjust SelectionPanel::contents accordingly.
}
Expand Down
8 changes: 5 additions & 3 deletions crates/re_data_ui/src/item_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use egui::Ui;
use re_data_store::InstancePath;
use re_log_types::{ComponentPath, EntityPath, TimeInt, Timeline};
use re_viewer_context::{
DataBlueprintGroupHandle, HoverHighlight, Item, SpaceViewId, UiVerbosity, ViewerContext,
DataBlueprintGroupHandle, DataQueryId, HoverHighlight, Item, SpaceViewId, UiVerbosity,

Check warning on line 9 in crates/re_data_ui/src/item_ui.rs

View workflow job for this annotation

GitHub Actions / Build Web / Build Web (wasm32 + wasm-bindgen)

unused import: `DataBlueprintGroupHandle`
ViewerContext,
};

use super::DataUi;
Expand Down Expand Up @@ -197,9 +198,10 @@ pub fn data_blueprint_group_button_to(
ui: &mut egui::Ui,
text: impl Into<egui::WidgetText>,
space_view_id: SpaceViewId,
group_handle: DataBlueprintGroupHandle,
query_id: DataQueryId,
entity_path: EntityPath,
) -> egui::Response {
let item = Item::DataBlueprintGroup(space_view_id, group_handle);
let item = Item::DataBlueprintGroup(space_view_id, query_id, entity_path);
let response = ctx
.re_ui
.selectable_label_with_icon(
Expand Down
14 changes: 14 additions & 0 deletions crates/re_space_view/src/data_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ pub trait PropertyResolver {
fn resolve_entity_overrides(&self, ctx: &StoreContext<'_>) -> EntityOverrides;
}

pub struct NoopResolver {}

impl PropertyResolver for NoopResolver {
fn resolve_entity_overrides(&self, _ctx: &StoreContext<'_>) -> EntityOverrides {
EntityOverrides {
root: EntityProperties::default(),
individual: EntityPropertyMap::default(),
group: EntityPropertyMap::default(),
}
}
}

pub static NOOP_RESOLVER: NoopResolver = NoopResolver {};

/// The common trait implemented for data queries
///
/// Both interfaces return `DataResult`s, which are self-contained description of the data
Expand Down
13 changes: 8 additions & 5 deletions crates/re_space_view/src/data_query_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ impl DataQueryBlueprint {
pub const INDIVIDUAL_OVERRIDES_PREFIX: &str = "individual_overrides";
pub const RECURSIVE_OVERRIDES_PREFIX: &str = "recursive_overrides";

pub fn auto(space_view_class_name: SpaceViewClassName, space_path: &EntityPath) -> Self {
pub fn new<'a>(
space_view_class_name: SpaceViewClassName,
queries_entities: impl Iterator<Item = &'a EntityPathExpr>,
) -> Self {
Self {
id: DataQueryId::random(),
space_view_class_name,
expressions: vec![EntityPathExpr::Recursive(space_path.clone())
.to_string()
.into()]
.into(),
expressions: queries_entities
.map(|exp| exp.to_string().into())
.collect::<Vec<_>>()
.into(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod space_view_contents;
mod unreachable_transform_reason;

pub use blueprint::QueryExpressions;
pub use data_query::{DataQuery, EntityOverrides, PropertyResolver};
pub use data_query::{DataQuery, EntityOverrides, PropertyResolver, NOOP_RESOLVER};
pub use data_query_blueprint::DataQueryBlueprint;
pub use screenshot::ScreenshotMode;
pub use space_view_contents::{DataBlueprintGroup, SpaceViewContents};
Expand Down
2 changes: 1 addition & 1 deletion crates/re_time_panel/src/data_density_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ fn show_row_ids_tooltip(
Item::InstancePath(_, path) => {
item_ui::instance_path_button(ctx, ui, None, path);
}
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _, _) => {
// No extra info. This should never happen, but not worth printing a warning over.
// Even if it does go here, the ui after will still look ok.
}
Expand Down
13 changes: 3 additions & 10 deletions crates/re_viewer/src/ui/selection_history_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,9 @@ fn item_to_string(blueprint: &ViewportBlueprint<'_>, item: &Item) -> String {
}
}
Item::InstancePath(_, entity_path) => entity_path.to_string(),
Item::DataBlueprintGroup(sid, handle) => {
if let Some(space_view) = blueprint.space_view(sid) {
if let Some(group) = space_view.contents.group(*handle) {
group.display_name.clone()
} else {
format!("<removed Group in {}>", space_view.display_name)
}
} else {
"<Group in removed Space View>".to_owned()
}
Item::DataBlueprintGroup(sid, qid, entity_path) => {
// TODO(jleibs): How do we access the query in this context?
entity_path.to_string()
}
Item::ComponentPath(path) => {
format!("{} {}", path.entity_path, path.component_name.short_name(),)
Expand Down
84 changes: 41 additions & 43 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn has_data_section(item: &Item) -> bool {
match item {
Item::ComponentPath(_) | Item::InstancePath(_, _) => true,
// Skip data ui since we don't know yet what to show for these.
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => false,
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _, _) => false,
}
}

Expand Down Expand Up @@ -260,22 +260,23 @@ fn what_is_selected_ui(
list_existing_data_blueprints(ui, ctx, &instance_path.entity_path, viewport);
}
}
Item::DataBlueprintGroup(space_view_id, data_blueprint_group_handle) => {
Item::DataBlueprintGroup(space_view_id, _query_id, entity_path) => {
if let Some(space_view) = viewport.space_view(space_view_id) {
if let Some(group) = space_view.contents.group(*data_blueprint_group_handle) {
item_title_ui(
ctx.re_ui,
ui,
group.display_name.as_str(),
Some(&re_ui::icons::CONTAINER),
&format!("Group {:?}", group.display_name),
);
item_title_ui(
ctx.re_ui,
ui,
&entity_path.to_string(),
Some(&re_ui::icons::CONTAINER),
&format!(
"Group {:?} as shown in Space View {:?}",
entity_path, space_view.display_name
),
);

ui.horizontal(|ui| {
ui.label("in");
space_view_button(ctx, ui, space_view);
});
}
ui.horizontal(|ui| {
ui.label("in");
space_view_button(ctx, ui, space_view);
});
}
}
}
Expand Down Expand Up @@ -550,37 +551,34 @@ fn blueprint_ui(
}
}

Item::DataBlueprintGroup(space_view_id, data_blueprint_group_handle) => {
Item::DataBlueprintGroup(space_view_id, query_id, group_path) => {
if let Some(space_view) = viewport.blueprint.space_view_mut(space_view_id) {
if let Some(group) = space_view.contents.group_mut(*data_blueprint_group_handle) {
let group_path = group.group_path.clone();
let as_group = true;

let query_result = ctx.lookup_query_result(space_view.query_id());
if let Some(data_result) = query_result
.tree
.lookup_result_by_path_and_group(&group_path, as_group)
.cloned()
{
let space_view_class = *space_view.class_name();
let mut props = data_result
.individual_properties
.clone()
.unwrap_or_default();
let as_group = true;

entity_props_ui(
ctx,
ui,
&space_view_class,
None,
&mut props,
&data_result.resolved_properties,
);
data_result.save_override(Some(props), ctx);
}
} else {
ctx.selection_state_mut().clear_current();
let query_result = ctx.lookup_query_result(*query_id);
if let Some(data_result) = query_result
.tree
.lookup_result_by_path_and_group(group_path, as_group)
.cloned()
{
let space_view_class = *space_view.class_name();
let mut props = data_result
.individual_properties
.clone()
.unwrap_or_default();

entity_props_ui(
ctx,
ui,
&space_view_class,
None,
&mut props,
&data_result.resolved_properties,
);
data_result.save_override(Some(props), ctx);
}
} else {
ctx.selection_state_mut().clear_current();
}
}

Expand Down
12 changes: 8 additions & 4 deletions crates/re_viewer_context/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use itertools::Itertools as _;
use re_data_store::InstancePath;
use re_log_types::{ComponentPath, DataPath, EntityPath};

use crate::DataQueryId;

use super::{DataBlueprintGroupHandle, SpaceViewId};

Check failure on line 8 in crates/re_viewer_context/src/item.rs

View workflow job for this annotation

GitHub Actions / Checks / Rust lints (fmt, check, cranky, tests, doc)

unused import: `DataBlueprintGroupHandle`

Check warning on line 8 in crates/re_viewer_context/src/item.rs

View workflow job for this annotation

GitHub Actions / Build Web / Build Web (wasm32 + wasm-bindgen)

unused import: `DataBlueprintGroupHandle`

/// One "thing" in the UI.
Expand All @@ -15,7 +17,7 @@ pub enum Item {
ComponentPath(ComponentPath),
SpaceView(SpaceViewId),
InstancePath(Option<SpaceViewId>, InstancePath),
DataBlueprintGroup(SpaceViewId, DataBlueprintGroupHandle),
DataBlueprintGroup(SpaceViewId, DataQueryId, EntityPath),
}

impl From<SpaceViewId> for Item {
Expand Down Expand Up @@ -85,7 +87,9 @@ impl std::fmt::Debug for Item {
Item::ComponentPath(s) => s.fmt(f),
Item::SpaceView(s) => write!(f, "{s:?}"),
Item::InstancePath(sid, path) => write!(f, "({sid:?}, {path})"),
Item::DataBlueprintGroup(sid, handle) => write!(f, "({sid:?}, {handle:?})"),
Item::DataBlueprintGroup(sid, qid, entity_path) => {
write!(f, "({sid:?}, {qid:?}, {entity_path:?})")
}
}
}
}
Expand All @@ -106,7 +110,7 @@ impl Item {
}
Item::ComponentPath(_) => "Entity Component",
Item::SpaceView(_) => "Space View",
Item::DataBlueprintGroup(_, _) => "Group",
Item::DataBlueprintGroup(_, _, _) => "Group",
}
}
}
Expand Down Expand Up @@ -195,7 +199,7 @@ pub fn resolve_mono_instance_path_item(
*space_view,
resolve_mono_instance_path(query, store, instance),
),
Item::ComponentPath(_) | Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
Item::ComponentPath(_) | Item::SpaceView(_) | Item::DataBlueprintGroup(_, _, _) => {
item.clone()
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/re_viewer_context/src/query_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ pub struct DataQueryResult {
pub tree: DataResultTree,
}

impl DataQueryResult {
#[inline]
pub fn is_empty(&self) -> bool {
self.tree.is_empty()
}
}

impl Clone for DataQueryResult {
fn clone(&self) -> Self {
re_tracing::profile_function!();
Expand Down Expand Up @@ -121,6 +128,11 @@ impl DataResultTree {
.and_then(|handle| self.lookup_result(*handle))
}

#[inline]
pub fn is_empty(&self) -> bool {
self.data_results_by_path.is_empty()
}

fn visit_recursive(
&self,
handle: DataResultHandle,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer_context/src/selection_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl SelectionState {
.hovered_previous_frame
.iter()
.any(|current| match current {
Item::ComponentPath(_) | Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
Item::ComponentPath(_) | Item::SpaceView(_) | Item::DataBlueprintGroup(_, _, _) => {
current == test
}

Expand Down
Loading

0 comments on commit 545db19

Please sign in to comment.