Skip to content

Commit

Permalink
Wire the remove-entity buttons to query exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Nov 29, 2023
1 parent 9881959 commit da82cfc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
61 changes: 60 additions & 1 deletion crates/re_space_view/src/data_query_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use once_cell::sync::Lazy;
use re_data_store::{
EntityProperties, EntityPropertiesComponent, EntityPropertyMap, EntityTree, StoreDb,
};
use re_log_types::{EntityPath, EntityPathExpr};
use re_log_types::{DataRow, EntityPath, EntityPathExpr, RowId, TimePoint};
use re_viewer_context::{
DataQueryId, DataQueryResult, DataResult, DataResultHandle, DataResultNode, DataResultTree,
EntitiesPerSystem, EntitiesPerSystemPerClass, SpaceViewClassName, SpaceViewId, StoreContext,
SystemCommand, SystemCommandSender as _, ViewerContext,
};
use slotmap::SlotMap;
use smallvec::SmallVec;
Expand Down Expand Up @@ -96,6 +97,64 @@ impl DataQueryBlueprint {
.join(&Self::RECURSIVE_OVERRIDES_PREFIX.into()),
}
}

pub fn remove_entity_expr(&self, ctx: &ViewerContext<'_>, expr: EntityPathExpr) {
let mut edited = false;

let mut inclusions: Vec<EntityPathExpr> = self
.expressions
.inclusions
.iter()
.filter(|exp| !exp.as_str().is_empty())
.map(|exp| EntityPathExpr::from(exp.as_str()))
.collect();

let mut exclusions: Vec<EntityPathExpr> = self
.expressions
.exclusions
.iter()
.filter(|exp| !exp.as_str().is_empty())
.map(|exp| EntityPathExpr::from(exp.as_str()))
.collect();

inclusions.retain(|inc_expr| {
if inc_expr == &expr {
edited = true;
false
} else {
true
}
});

if !exclusions.iter().any(|exc_expr| exc_expr == &expr) {
edited = true;
exclusions.push(expr);
}

if edited {
let timepoint = TimePoint::timeless();

let expressions_component = QueryExpressions {
inclusions: inclusions.iter().map(|s| s.to_string().into()).collect(),
exclusions: exclusions.iter().map(|s| s.to_string().into()).collect(),
};

let row = DataRow::from_cells1_sized(
RowId::random(),
self.id.as_entity_path(),
timepoint.clone(),
1,
[expressions_component],
)
.unwrap();

ctx.command_sender
.send_system(SystemCommand::UpdateBlueprint(
ctx.store_context.blueprint.store_id().clone(),
vec![row],
));
}
}
}

impl DataQuery for DataQueryBlueprint {
Expand Down
3 changes: 3 additions & 0 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ fn blueprint_ui(
match item {
Item::SpaceView(space_view_id) => {
ui.horizontal(|ui| {
// TODO(#4377): Don't bother showing add/remove entities dialog since it's broken
/*
if ui
.button("Add/remove Entities")
.on_hover_text("Manually add or remove Entities from the Space View")
Expand All @@ -400,6 +402,7 @@ fn blueprint_ui(
viewport
.show_add_remove_entities_window(*space_view_id);
}
*/

if ui
.button("Clone Space View")
Expand Down
7 changes: 7 additions & 0 deletions crates/re_viewport/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ahash::HashSet;
use re_data_store::{EntityPath, EntityProperties, StoreDb, TimeInt, VisibleHistory};
use re_data_store::{EntityPropertiesComponent, EntityPropertyMap};

use re_log_types::EntityPathExpr;
use re_renderer::ScreenshotProcessor;
use re_space_view::{
DataQueryBlueprint, EntityOverrides, PropertyResolver, ScreenshotMode, SpaceViewContents,
Expand Down Expand Up @@ -327,6 +328,12 @@ impl SpaceViewBlueprint {
override_path: entity_path,
}
}

pub fn remove_entity_expr(&self, ctx: &ViewerContext<'_>, expr: EntityPathExpr) {
if let Some(query) = self.queries.first() {
query.remove_entity_expr(ctx, expr);
}
}
}

impl SpaceViewBlueprint {
Expand Down
20 changes: 8 additions & 12 deletions crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use itertools::Itertools;

use re_data_store::InstancePath;
use re_data_ui::item_ui;
use re_log_types::EntityPathExpr;
use re_ui::list_item::ListItem;
use re_ui::ReUi;
use re_viewer_context::{
Expand Down Expand Up @@ -311,8 +312,10 @@ impl ViewportBlueprint<'_> {
let response =
remove_button_ui(re_ui, ui, "Remove Entity from the Space View");
if response.clicked() {
// TODO(#4377): Fix entity removal
//space_view.contents.remove_entity(entity_path);
space_view.remove_entity_expr(
ctx,
EntityPathExpr::Exact(entity_path.clone()),
);
space_view.entities_determined_by_user = true;
}

Expand Down Expand Up @@ -374,16 +377,9 @@ impl ViewportBlueprint<'_> {
});

if remove_group {
// TODO(#4377): Fix group removal
/*
if let Some(group_handle) = space_view
.contents
.group_handle_for_entity_path(entity_path)
{
space_view.contents.remove_group(group_handle);
space_view.entities_determined_by_user = true;
}
*/
space_view
.remove_entity_expr(ctx, EntityPathExpr::Recursive(entity_path.clone()));
space_view.entities_determined_by_user = true;
}

response
Expand Down

0 comments on commit da82cfc

Please sign in to comment.