Skip to content

Commit

Permalink
First pass tearing out the old viewport sync logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Dec 14, 2023
1 parent 33e30d7 commit 890d868
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 398 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 9 additions & 14 deletions crates/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ impl AppState {
.values()
.flat_map(|space_view| {
space_view.queries.iter().map(|query| {
let resolver =
query.build_resolver(space_view.id, &space_view.auto_properties);
let state = viewport.state.read();
let props = state.space_view_props(space_view.id);
let resolver = query.build_resolver(space_view.id, props);
(
query.id,
query.execute_query(
Expand Down Expand Up @@ -186,11 +187,12 @@ impl AppState {
viewport
.blueprint
.space_views
.values_mut()
.values()
.flat_map(|space_view| {
space_view.queries.iter().map(|query| {
let resolver =
query.build_resolver(space_view.id, &space_view.auto_properties);
let state = viewport.state.read();
let props = state.space_view_props(space_view.id);
let resolver = query.build_resolver(space_view.id, props);
(
query.id,
query.execute_query(
Expand All @@ -206,12 +208,7 @@ impl AppState {
ctx.query_results = &updated_query_results;

time_panel.show_panel(&ctx, ui, app_blueprint.time_panel_expanded);
selection_panel.show_panel(
&ctx,
ui,
&mut viewport,
app_blueprint.selection_panel_expanded,
);
selection_panel.show_panel(&ctx, ui, &viewport, app_blueprint.selection_panel_expanded);

let central_panel_frame = egui::Frame {
fill: ui.style().visuals.panel_fill,
Expand Down Expand Up @@ -250,7 +247,7 @@ impl AppState {
ui.add_space(4.0);
}

blueprint_panel_ui(&mut viewport.blueprint, &ctx, ui, &spaces_info);
blueprint_panel_ui(&viewport.blueprint, &ctx, ui, &spaces_info);
},
);

Expand All @@ -273,8 +270,6 @@ impl AppState {
});
});

viewport.sync_blueprint_changes(command_sender);

{
// We move the time at the very end of the frame,
// so we have one frame to see the first data before we move the time.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/blueprint_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use re_viewport::{SpaceInfoCollection, ViewportBlueprint};

/// Show the Blueprint section of the left panel based on the current [`ViewportBlueprint`]
pub fn blueprint_panel_ui(
blueprint: &mut ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
spaces_info: &SpaceInfoCollection,
Expand Down
12 changes: 6 additions & 6 deletions crates/re_viewer/src/ui/selection_history_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl SelectionHistoryUi {
&mut self,
re_ui: &re_ui::ReUi,
ui: &mut egui::Ui,
blueprint: &ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
history: &mut SelectionHistory,
) -> Option<ItemCollection> {
let next = self.next_button_ui(re_ui, ui, blueprint, history);
Expand All @@ -27,7 +27,7 @@ impl SelectionHistoryUi {
&mut self,
re_ui: &re_ui::ReUi,
ui: &mut egui::Ui,
blueprint: &ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
history: &mut SelectionHistory,
) -> Option<ItemCollection> {
// undo selection
Expand Down Expand Up @@ -77,7 +77,7 @@ impl SelectionHistoryUi {
&mut self,
re_ui: &re_ui::ReUi,
ui: &mut egui::Ui,
blueprint: &ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
history: &mut SelectionHistory,
) -> Option<ItemCollection> {
// redo selection
Expand Down Expand Up @@ -126,7 +126,7 @@ impl SelectionHistoryUi {
#[allow(clippy::unused_self)]
fn history_item_ui(
&mut self,
blueprint: &ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
ui: &mut egui::Ui,
index: usize,
history: &mut SelectionHistory,
Expand Down Expand Up @@ -157,7 +157,7 @@ fn item_kind_ui(ui: &mut egui::Ui, sel: &Item) {
ui.weak(RichText::new(format!("({})", sel.kind())));
}

fn item_collection_to_string(blueprint: &ViewportBlueprint<'_>, items: &ItemCollection) -> String {
fn item_collection_to_string(blueprint: &ViewportBlueprint, items: &ItemCollection) -> String {
assert!(!items.is_empty()); // history never contains empty selections.
if items.len() == 1 {
item_to_string(blueprint, items.iter().next().unwrap())
Expand All @@ -168,7 +168,7 @@ fn item_collection_to_string(blueprint: &ViewportBlueprint<'_>, items: &ItemColl
}
}

fn item_to_string(blueprint: &ViewportBlueprint<'_>, item: &Item) -> String {
fn item_to_string(blueprint: &ViewportBlueprint, item: &Item) -> String {
match item {
Item::SpaceView(sid) => {
if let Some(space_view) = blueprint.space_view(sid) {
Expand Down
80 changes: 45 additions & 35 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl SelectionPanel {
&mut self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
viewport: &mut Viewport<'_, '_>,
viewport: &Viewport<'_>,
expanded: bool,
) {
let screen_width = ui.ctx().screen_rect().width();
Expand Down Expand Up @@ -97,12 +97,7 @@ impl SelectionPanel {
}

#[allow(clippy::unused_self)]
fn contents(
&mut self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
viewport: &mut Viewport<'_, '_>,
) {
fn contents(&mut self, ctx: &ViewerContext<'_>, ui: &mut egui::Ui, viewport: &Viewport<'_>) {
re_tracing::profile_function!();

let query = ctx.current_query();
Expand All @@ -122,18 +117,18 @@ impl SelectionPanel {
};
for (i, item) in selection.iter().enumerate() {
ui.push_id(i, |ui| {
what_is_selected_ui(ui, ctx, &mut viewport.blueprint, item);
what_is_selected_ui(ui, ctx, &viewport.blueprint, item);

match item {
Item::Container(tile_id) => {
container_top_level_properties(ui, ctx, &mut viewport.blueprint, tile_id);
container_top_level_properties(ui, ctx, &viewport.blueprint, tile_id);
}

Item::SpaceView(space_view_id) => {
space_view_top_level_properties(
ui,
ctx,
&mut viewport.blueprint,
&viewport.blueprint,
space_view_id,
);
}
Expand Down Expand Up @@ -197,7 +192,7 @@ fn space_view_button(
fn what_is_selected_ui(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
viewport: &mut ViewportBlueprint<'_>,
viewport: &ViewportBlueprint,
item: &Item,
) {
match item {
Expand Down Expand Up @@ -236,7 +231,7 @@ fn what_is_selected_ui(
list_existing_data_blueprints(ui, ctx, entity_path, viewport);
}
Item::SpaceView(space_view_id) => {
if let Some(space_view) = viewport.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.space_view(space_view_id) {
let space_view_class = space_view.class(ctx.space_view_class_registry);
item_title_ui(
ctx.re_ui,
Expand All @@ -259,7 +254,7 @@ fn what_is_selected_ui(
};

if let Some(space_view_id) = space_view_id {
if let Some(space_view) = viewport.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.space_view(space_view_id) {
item_title_ui(
ctx.re_ui,
ui,
Expand Down Expand Up @@ -334,7 +329,7 @@ fn list_existing_data_blueprints(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
entity_path: &EntityPath,
blueprint: &ViewportBlueprint<'_>,
blueprint: &ViewportBlueprint,
) {
let space_views_with_path = blueprint.space_views_containing_entity_path(ctx, entity_path);

Expand Down Expand Up @@ -367,20 +362,23 @@ fn list_existing_data_blueprints(
fn space_view_top_level_properties(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
viewport: &mut ViewportBlueprint<'_>,
viewport: &ViewportBlueprint,
space_view_id: &SpaceViewId,
) {
if let Some(space_view) = viewport.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.space_view(space_view_id) {
egui::Grid::new("space_view_top_level_properties")
.num_columns(2)
.show(ui, |ui| {
let mut name = space_view.display_name.clone();
ui.label("Name").on_hover_text(
"The name of the Space View used for display purposes. This can be any text \
string.",
);
ui.text_edit_singleline(&mut space_view.display_name);
ui.text_edit_singleline(&mut name);
ui.end_row();

space_view.set_display_name(name, ctx);

ui.label("Space origin").on_hover_text(
"The origin Entity for this Space View. For spatial Space Views, the Space \
View's origin is the same as this Entity's origin and all transforms are \
Expand Down Expand Up @@ -409,10 +407,11 @@ fn space_view_top_level_properties(
fn container_top_level_properties(
ui: &mut egui::Ui,
_ctx: &ViewerContext<'_>,
viewport: &mut ViewportBlueprint<'_>,
viewport: &ViewportBlueprint,
tile_id: &egui_tiles::TileId,
) {
if let Some(Tile::Container(container)) = viewport.tree.tiles.get_mut(*tile_id) {
// TODO(jleibs): fix container-editing
if let Some(Tile::Container(container)) = viewport.tree.tiles.get(*tile_id) {
egui::Grid::new("container_top_level_properties")
.num_columns(2)
.show(ui, |ui| {
Expand Down Expand Up @@ -447,7 +446,9 @@ fn container_top_level_properties(
);
});

container.set_kind(container_kind);
// TODO(jleibs): fix container-editing
re_log::warn!("TODO(jleibs): Fix container editing");
//container.set_kind(container_kind);

ui.end_row();

Expand All @@ -467,19 +468,30 @@ fn container_top_level_properties(
ui.style_mut().wrap = Some(false);
ui.set_min_width(64.0);

// TODO(jleibs): Fix container-editing
ui.label(format!("Layout: {}", grid_layout_to_string(&grid.layout)));
/*
ui.selectable_value(
&mut grid.layout,
GridLayout::Auto,
grid_layout_to_string(&GridLayout::Auto),
);
*/
ui.separator();

for columns in 1..=grid.num_children() {
// TODO(jleibs): fix container-editing
ui.label(format!(
"Layout: {}",
grid_layout_to_string(&GridLayout::Columns(columns))
));
/*
ui.selectable_value(
&mut grid.layout,
GridLayout::Columns(columns),
grid_layout_to_string(&GridLayout::Columns(columns)),
);
*/
}
});

Expand All @@ -498,12 +510,7 @@ fn has_blueprint_section(item: &Item) -> bool {
}

/// What is the blueprint stuff for this item?
fn blueprint_ui(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
viewport: &mut Viewport<'_, '_>,
item: &Item,
) {
fn blueprint_ui(ui: &mut egui::Ui, ctx: &ViewerContext<'_>, viewport: &Viewport<'_>, item: &Item) {
match item {
Item::SpaceView(space_view_id) => {
ui.horizontal(|ui| {
Expand All @@ -524,13 +531,13 @@ fn blueprint_ui(
if let Some(space_view) = viewport.blueprint.space_view(space_view_id) {
let mut new_space_view = space_view.clone();
new_space_view.id = SpaceViewId::random();
viewport.blueprint.add_space_view(new_space_view);
viewport.blueprint.mark_user_interaction();
viewport.blueprint.add_space_view(new_space_view, ctx);
viewport.blueprint.mark_user_interaction(ctx);
}
}
});

if let Some(space_view) = viewport.blueprint.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.blueprint.space_view(space_view_id) {
if let Some(query) = space_view.queries.first() {
let inclusions = query.expressions.inclusions.join("\n");
let mut edited_inclusions = inclusions.clone();
Expand Down Expand Up @@ -565,16 +572,19 @@ fn blueprint_ui(
vec![row],
));

space_view.entities_determined_by_user = true;
space_view.set_entity_determined_by_user(ctx);
}
}
}

ui.add_space(ui.spacing().item_spacing.y);

if let Some(space_view) = viewport.blueprint.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.blueprint.space_view(space_view_id) {
let space_view_class = *space_view.class_identifier();
let space_view_state = viewport.state.space_view_state_mut(

let mut state = viewport.state.write();

let space_view_state = state.space_view_state_mut(
ctx.space_view_class_registry,
space_view.id,
space_view.class_identifier(),
Expand Down Expand Up @@ -602,7 +612,7 @@ fn blueprint_ui(
.selection_ui(
ctx,
ui,
space_view_state,
space_view_state.space_view_state.as_mut(),
&space_view.space_origin,
space_view.id,
&mut props,
Expand Down Expand Up @@ -630,7 +640,7 @@ fn blueprint_ui(

Item::InstancePath(space_view_id, instance_path) => {
if let Some(space_view_id) = space_view_id {
if let Some(space_view) = viewport.blueprint.space_view_mut(space_view_id) {
if let Some(space_view) = viewport.blueprint.space_view(space_view_id) {
if instance_path.instance_key.is_specific() {
ui.horizontal(|ui| {
ui.label("Part of");
Expand Down Expand Up @@ -674,7 +684,7 @@ fn blueprint_ui(
}

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(space_view) = viewport.blueprint.space_view(space_view_id) {
let as_group = true;

let query_result = ctx.lookup_query_result(*query_id);
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ image = { workspace = true, default-features = false, features = ["png"] }
itertools.workspace = true
nohash-hasher.workspace = true
once_cell.workspace = true
parking_lot.workspace = true
rayon.workspace = true
rmp-serde.workspace = true
tinyvec.workspace = true
Loading

0 comments on commit 890d868

Please sign in to comment.