Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix space view cloning to also copy entity properties (visible time range, etc.) #4978

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,8 @@ fn blueprint_ui(
.on_hover_text("Create an exact duplicate of this Space View including all Blueprint settings")
.clicked()
{
if let Some(space_view) = viewport.blueprint.space_view(space_view_id) {
let new_space_view = space_view.duplicate();
let new_ids = viewport.blueprint.add_space_views(std::iter::once(new_space_view), ctx, None);
if let Some(new_id) = new_ids.first() {
ctx.selection_state().set_selection(Item::SpaceView(*new_id));
}
if let Some(new_space_view_id) = viewport.blueprint.duplicate_space_view(space_view_id, ctx) {
ctx.selection_state().set_selection(Item::SpaceView(new_space_view_id));
viewport.blueprint.mark_user_interaction(ctx);
}
}
Expand Down
24 changes: 24 additions & 0 deletions crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,30 @@ impl ViewportBlueprint {
ctx.save_blueprint_component(&VIEWPORT_PATH.into(), component);
}

/// Duplicates a space view and its entity property overrides
pub fn duplicate_space_view(
&self,
space_view_id: &SpaceViewId,
ctx: &ViewerContext<'_>,
) -> Option<SpaceViewId> {
let Some(space_view) = self.space_view(space_view_id) else {
return None;
};

let new_space_view = space_view.duplicate();
abey79 marked this conversation as resolved.
Show resolved Hide resolved
let new_space_view_id = new_space_view.id;

// copy entity properties from the old space view
let data_result = space_view.root_data_result(ctx.store_context, ctx.blueprint_query);
let new_data_result =
new_space_view.root_data_result(ctx.store_context, ctx.blueprint_query);
new_data_result.save_override(data_result.individual_properties().cloned(), ctx);
abey79 marked this conversation as resolved.
Show resolved Hide resolved

self.add_space_views(std::iter::once(new_space_view), ctx, None);

Some(new_space_view_id)
}

/// If `false`, the item is referring to data that is not present in this blueprint.
pub fn is_item_valid(&self, item: &Item) -> bool {
match item {
Expand Down
Loading