Skip to content

Commit

Permalink
THIS COMMIT MAKES SENSE BUT BREAKS THE VIEWPORT
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Oct 17, 2024
1 parent 8156d2a commit 36907de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
11 changes: 9 additions & 2 deletions crates/viewer/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ impl<'a> Viewport<'a> {
// If the blueprint tree is empty/missing we need to auto-layout.
let tree = if blueprint.tree.is_empty() {
edited = true;
super::auto_layout::tree_from_space_views(
let auto_tree = super::auto_layout::tree_from_space_views(
space_view_class_registry,
&blueprint.space_views,
)
);
re_log::trace!(
"New auto-tree: {auto_tree:#?} based on {} space_views",
blueprint.space_views.len()
);
auto_tree
} else {
blueprint.tree.clone()
};
Expand Down Expand Up @@ -429,6 +434,8 @@ impl<'a> Viewport<'a> {
if self.tree_edited {
// TODO(#4687): Be extra careful here. If we mark edited inappropriately we can create an infinite edit loop.

re_log::trace!("Saving edited tree: {:#?}", self.tree);

// Simplify before we save the tree. Normally additional simplification will
// happen on the next render loop, but that's too late -- unsimplified
// changes will be baked into the tree.
Expand Down
59 changes: 25 additions & 34 deletions crates/viewer/re_viewport_blueprint/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use std::sync::atomic::{AtomicBool, Ordering};
use ahash::HashMap;
use egui_tiles::{SimplificationOptions, TileId};
use nohash_hasher::IntSet;
use re_types::{Archetype as _, SpaceViewClassIdentifier};
use smallvec::SmallVec;

use re_chunk_store::LatestAtQuery;
use re_entity_db::EntityPath;
use re_types::blueprint::components::ViewerRecommendationHash;
use re_types::{Archetype as _, SpaceViewClassIdentifier};
use re_types_blueprint::blueprint::archetypes as blueprint_archetypes;
use re_types_blueprint::blueprint::components::{
AutoLayout, AutoSpaceViews, IncludedSpaceView, RootContainer, SpaceViewMaximized,
Expand Down Expand Up @@ -91,19 +91,28 @@ impl ViewportBlueprint {
past_viewer_recommendations: results.component_batch(),
};

// This visits all space views that ever has been, which is likely more than exist now.
// TODO(emilk): optimize this by starting at the root and only visit reachable space viewa.
let all_space_view_ids: Vec<SpaceViewId> = blueprint_db
.tree()
.children
.get(SpaceViewId::registry_part())
.map(|tree| {
tree.children
.values()
.map(|subtree| SpaceViewId::from_entity_path(&subtree.path))
.collect()
})
.unwrap_or_default();
let root_container = root_container.map(|id| id.0.into());

let mut containers: BTreeMap<ContainerId, ContainerBlueprint> = Default::default();
let mut all_space_view_ids: Vec<SpaceViewId> = Default::default();

if let Some(root_container) = root_container {
re_tracing::profile_scope!("visit_all_containers");
let mut container_ids_to_visit = vec![root_container];
while let Some(id) = container_ids_to_visit.pop() {
if let Some(container) = ContainerBlueprint::try_from_db(blueprint_db, query, id) {
for &content in &container.contents {
match content {
Contents::Container(id) => container_ids_to_visit.push(id),
Contents::SpaceView(id) => {
all_space_view_ids.push(id);
}
}
}
containers.insert(id, container);
}
}
}

let space_views: BTreeMap<SpaceViewId, SpaceViewBlueprint> = all_space_view_ids
.into_iter()
Expand All @@ -113,26 +122,6 @@ impl ViewportBlueprint {
.map(|sv| (sv.id, sv))
.collect();

let all_container_ids: Vec<ContainerId> = blueprint_db
.tree()
.children
.get(ContainerId::registry_part())
.map(|tree| {
tree.children
.values()
.map(|subtree| ContainerId::from_entity_path(&subtree.path))
.collect()
})
.unwrap_or_default();

let containers: BTreeMap<ContainerId, ContainerBlueprint> = all_container_ids
.into_iter()
.filter_map(|id| ContainerBlueprint::try_from_db(blueprint_db, query, id))
.map(|c| (c.id, c))
.collect();

let root_container = root_container.map(|id| id.0.into());

// Auto layouting and auto space view are only enabled if no blueprint has been provided by the user.
// Only enable auto-space-views if this is the app-default blueprint
let is_app_default_blueprint = blueprint_db
Expand Down Expand Up @@ -893,8 +882,10 @@ impl ViewportBlueprint {
.and_then(|contents| contents.as_container_id())
.map(|container_id| RootContainer((container_id).into()))
{
re_log::trace!("Saving with a root container");
ctx.save_blueprint_component(&VIEWPORT_PATH.into(), &root_container);
} else {
re_log::trace!("Saving empty viewport");
ctx.save_empty_blueprint_component::<RootContainer>(&VIEWPORT_PATH.into());
}
}
Expand Down

0 comments on commit 36907de

Please sign in to comment.