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

[pure refactor] move selection state into an independent crate, re_viewer_context #2037

Merged
merged 6 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
18 changes: 18 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ version = "0.6.0-alpha.0"
# This is because we treat alpha-releases as incompatible, but semver doesn't.
# In particular: if we compile rerun 0.3.0-alpha.0 we only want it to use
# re_log_types 0.3.0-alpha.0, NOT 0.3.0-alpha.4 even though it is newer and semver-compatible.
re_sdk_comms = { path = "crates/re_sdk_comms", version = "=0.6.0-alpha.0" }
re_analytics = { path = "crates/re_analytics", version = "=0.6.0-alpha.0" }
re_arrow_store = { path = "crates/re_arrow_store", version = "=0.6.0-alpha.0" }
re_build_build_info = { path = "crates/re_build_build_info", version = "=0.6.0-alpha.0" }
Expand All @@ -40,12 +39,14 @@ re_memory = { path = "crates/re_memory", version = "=0.6.0-alpha.0" }
re_query = { path = "crates/re_query", version = "=0.6.0-alpha.0" }
re_renderer = { path = "crates/re_renderer", version = "=0.6.0-alpha.0", default-features = false }
re_sdk = { path = "crates/re_sdk", version = "=0.6.0-alpha.0" }
re_sdk_comms = { path = "crates/re_sdk_comms", version = "=0.6.0-alpha.0" }
re_smart_channel = { path = "crates/re_smart_channel", version = "=0.6.0-alpha.0" }
re_string_interner = { path = "crates/re_string_interner", version = "=0.6.0-alpha.0" }
re_tensor_ops = { path = "crates/re_tensor_ops", version = "=0.6.0-alpha.0" }
re_tuid = { path = "crates/re_tuid", version = "=0.6.0-alpha.0" }
re_ui = { path = "crates/re_ui", version = "=0.6.0-alpha.0" }
re_viewer = { path = "crates/re_viewer", version = "=0.6.0-alpha.0", default-features = false }
re_viewer_context = { path = "crates/re_viewer_context", version = "=0.6.0-alpha.0" }
re_web_viewer_server = { path = "crates/re_web_viewer_server", version = "=0.6.0-alpha.0" }
re_ws_comms = { path = "crates/re_ws_comms", version = "=0.6.0-alpha.0" }
rerun = { path = "crates/rerun", version = "=0.6.0-alpha.0" }
Expand All @@ -54,6 +55,8 @@ ahash = "0.8"
anyhow = "1.0"
arrow2 = "0.16"
arrow2_convert = "0.4.2"
nohash-hasher = "0.2"
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
bytemuck = { version = "1.11", features = ["extern_crate_alloc"] }
cfg-if = "1.0"
clap = "4.0"
comfy-table = { version = "6.1", default-features = false }
Expand Down Expand Up @@ -90,6 +93,7 @@ tinyvec = { version = "1.6", features = ["alloc", "rustc_1_55"] }
tokio = { version = "1.24", default-features = false }
wgpu = { version = "0.16" }
wgpu-core = { version = "0.16" }
slotmap = { version = "1.0.6", features = ["serde"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort!



[profile.dev]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ re_log.workspace = true
ahash.workspace = true
anyhow.workspace = true
bitflags = "1.3"
bytemuck = { version = "1.12", features = ["derive"] }
bytemuck.workspace = true
clean-path = "0.2"
document-features = "0.2"
ecolor = { workspace = true, features = ["bytemuck"] }
Expand All @@ -60,7 +60,7 @@ macaw.workspace = true
never = '0.1'
ordered-float = "3.2"
parking_lot.workspace = true
slotmap = "1.0.6"
slotmap.workspace = true
smallvec.workspace = true
static_assertions = "1.1"
thiserror.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ re_renderer = { workspace = true, default-features = false, features = [
re_smart_channel.workspace = true
re_tensor_ops.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true
re_ws_comms = { workspace = true, features = ["client"] }

# Internal (optional):
Expand Down Expand Up @@ -98,7 +99,7 @@ rfd = { version = "0.11.3", default_features = false, features = [
"xdg-portal",
] }
serde = { version = "1", features = ["derive"] }
slotmap = { version = "1.0.6", features = ["serde"] }
slotmap.workspace = true
smallvec = { workspace = true, features = ["serde"] }
thiserror.workspace = true
time = { workspace = true, features = ["formatting"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod remote_viewer_app;
mod ui;
mod viewer_analytics;

pub(crate) use misc::{mesh_loader, Item, TimeControl, TimeView, ViewerContext};
pub(crate) use misc::{mesh_loader, TimeControl, TimeView, ViewerContext};
use re_log_types::PythonVersion;
pub(crate) use ui::{memory_panel, selection_panel, time_panel, UiVerbosity};

Expand Down
10 changes: 1 addition & 9 deletions crates/re_viewer/src/misc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
mod app_options;
pub mod caches;
pub mod format_time;
mod item;
pub(crate) mod mesh_loader;
pub mod queries;
mod selection_state;
pub(crate) mod space_info;
mod space_view_highlights;
pub(crate) mod time_control;
Expand All @@ -28,14 +26,8 @@ pub(crate) mod profiler;
#[cfg(not(target_arch = "wasm32"))]
pub mod clipboard;

pub use app_options::AppOptions;
pub use transform_cache::{TransformCache, UnreachableTransform};
pub use {
app_options::*,
item::{Item, ItemCollection},
selection_state::{
HoverHighlight, HoveredSpace, InteractionHighlight, SelectionHighlight, SelectionState,
},
};

pub use space_view_highlights::{
highlights_for_space_view, OptionalSpaceViewEntityHighlight, SpaceViewHighlights,
Expand Down
9 changes: 4 additions & 5 deletions crates/re_viewer/src/misc/space_view_highlights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use nohash_hasher::IntMap;

use re_log_types::{component_types::InstanceKey, EntityPath, EntityPathHash};
use re_renderer::OutlineMaskPreference;

use super::{InteractionHighlight, SelectionState};
use crate::{
misc::{HoverHighlight, Item, SelectionHighlight},
ui::{SpaceView, SpaceViewId},
use re_viewer_context::{
HoverHighlight, InteractionHighlight, Item, SelectionHighlight, SelectionState, SpaceViewId,
};

use crate::ui::SpaceView;

/// Highlights of a specific entity path in a specific space view.
///
/// Using this in bulk on many instances is faster than querying single objects.
Expand Down
16 changes: 7 additions & 9 deletions crates/re_viewer/src/misc/viewer_context.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use re_data_store::{log_db::LogDb, InstancePath};
use re_log_types::{ComponentPath, EntityPath, TimeInt, Timeline};
use re_viewer_context::{
DataBlueprintGroupHandle, HoverHighlight, Item, ItemCollection, SelectionState, SpaceViewId,
};

use crate::ui::{
data_ui::{ComponentUiRegistry, DataUi},
DataBlueprintGroupHandle, SpaceViewId, UiVerbosity,
};

use super::{
item::{Item, ItemCollection},
HoverHighlight,
UiVerbosity,
};

/// Common things needed by many parts of the viewer.
Expand Down Expand Up @@ -299,11 +297,11 @@ impl<'a> ViewerContext<'a> {
self.rec_cfg.selection_state.set_hovered(hovered);
}

pub fn selection_state(&self) -> &super::SelectionState {
pub fn selection_state(&self) -> &SelectionState {
&self.rec_cfg.selection_state
}

pub fn selection_state_mut(&mut self) -> &mut super::SelectionState {
pub fn selection_state_mut(&mut self) -> &mut SelectionState {
&mut self.rec_cfg.selection_state
}

Expand All @@ -323,5 +321,5 @@ pub struct RecordingConfig {
pub time_ctrl: crate::TimeControl,

/// Selection & hovering state.
pub selection_state: super::SelectionState,
pub selection_state: SelectionState,
}
3 changes: 2 additions & 1 deletion crates/re_viewer/src/ui/auto_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use egui::Vec2;
use itertools::Itertools as _;

use re_data_store::{EntityPath, EntityPathPart};
use re_viewer_context::SpaceViewId;

use super::{space_view::SpaceView, view_category::ViewCategory, SpaceViewId};
use super::{space_view::SpaceView, view_category::ViewCategory};

#[derive(Clone, Debug)]
pub struct SpaceMakeInfo {
Expand Down
4 changes: 3 additions & 1 deletion crates/re_viewer/src/ui/blueprint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::misc::{space_info::SpaceInfoCollection, Item, ViewerContext};
use re_viewer_context::Item;

use crate::misc::{space_info::SpaceInfoCollection, ViewerContext};

use super::viewport::Viewport;

Expand Down
3 changes: 1 addition & 2 deletions crates/re_viewer/src/ui/data_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use std::collections::BTreeSet;

use nohash_hasher::{IntMap, IntSet};
use re_data_store::{EntityPath, EntityProperties, EntityPropertyMap};
use re_viewer_context::DataBlueprintGroupHandle;
use slotmap::SlotMap;
use smallvec::{smallvec, SmallVec};

slotmap::new_key_type! { pub struct DataBlueprintGroupHandle; }

/// A grouping of several data-blueprints.
#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
pub struct DataBlueprintGroup {
Expand Down
5 changes: 1 addition & 4 deletions crates/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod auto_layout;
mod blueprint;
mod data_blueprint;
mod scene;
mod selection_history;
mod selection_history_ui;
mod space_view;
mod space_view_entity_picker;
Expand All @@ -27,11 +26,9 @@ pub mod view_spatial;
use self::scene::SceneQuery;

pub(crate) use self::blueprint::Blueprint;
pub(crate) use self::space_view::{SpaceView, SpaceViewId};
pub(crate) use self::space_view::SpaceView;

pub use self::annotations::{Annotations, DefaultColor, MISSING_ANNOTATIONS};
pub use self::data_blueprint::DataBlueprintGroupHandle;
pub use self::selection_history::{HistoricalSelection, SelectionHistory};
pub use self::view_category::ViewCategory;
pub use self::viewport::Viewport;

Expand Down
5 changes: 2 additions & 3 deletions crates/re_viewer/src/ui/selection_history_ui.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use egui::RichText;
use re_ui::Command;
use re_viewer_context::{Item, ItemCollection, SelectionHistory};

use crate::{misc::ItemCollection, ui::Blueprint, Item};

use super::SelectionHistory;
use crate::ui::Blueprint;

// ---

Expand Down
5 changes: 3 additions & 2 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use re_log_types::{
component_types::{Tensor, TensorDataMeaning},
TimeType, Transform,
};
use re_viewer_context::{Item, SpaceViewId};

use crate::{ui::Blueprint, Item, UiVerbosity, ViewerContext};
use crate::{ui::Blueprint, UiVerbosity, ViewerContext};

use super::{
data_ui::DataUi, selection_history_ui::SelectionHistoryUi, space_view::ViewState,
Expand Down Expand Up @@ -267,7 +268,7 @@ fn blueprint_ui(
{
if let Some(space_view) = blueprint.viewport.space_view(space_view_id) {
let mut new_space_view = space_view.clone();
new_space_view.id = super::SpaceViewId::random();
new_space_view.id = SpaceViewId::random();
blueprint.viewport.add_space_view(new_space_view);
blueprint.viewport.mark_user_interaction();
}
Expand Down
21 changes: 2 additions & 19 deletions crates/re_viewer/src/ui/space_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use re_arrow_store::Timeline;
use re_data_store::{EntityPath, EntityPropertyMap, EntityTree, InstancePath, TimeInt};
use re_renderer::{GpuReadbackIdentifier, ScreenshotProcessor};
use re_renderer::ScreenshotProcessor;
use re_viewer_context::SpaceViewId;

use crate::{
misc::{space_info::SpaceInfoCollection, SpaceViewHighlights, TransformCache, ViewerContext},
Expand All @@ -15,24 +16,6 @@ use super::{

// ----------------------------------------------------------------------------

/// A unique id for each space view.
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
)]
pub struct SpaceViewId(uuid::Uuid);

impl SpaceViewId {
pub fn random() -> Self {
Self(uuid::Uuid::new_v4())
}

pub fn gpu_readback_id(self) -> GpuReadbackIdentifier {
re_log_types::hash::Hash64::hash(self).hash64()
}
}

// ----------------------------------------------------------------------------

#[derive(PartialEq, Eq, Clone, Copy)]
#[allow(dead_code)] // Not used on the web.
pub enum ScreenshotMode {
Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/src/ui/space_view_entity_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use itertools::Itertools;
use nohash_hasher::IntMap;
use re_arrow_store::Timeline;
use re_data_store::{EntityPath, EntityTree, InstancePath};
use re_viewer_context::SpaceViewId;

use crate::misc::{space_info::SpaceInfoCollection, ViewerContext};

use super::{
view_category::{categorize_entity_path, ViewCategory},
SpaceView, SpaceViewId,
SpaceView,
};

/// Window for adding/removing entities from a space view.
Expand Down
6 changes: 2 additions & 4 deletions crates/re_viewer/src/ui/time_panel/data_density_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ use egui::{epaint::Vertex, lerp, pos2, remap, Color32, NumExt as _, Rect, Shape}

use re_data_store::TimeHistogram;
use re_log_types::{TimeInt, TimeRange, TimeReal};
use re_viewer_context::Item;

use crate::{
misc::{Item, ViewerContext},
ui::Blueprint,
};
use crate::{misc::ViewerContext, ui::Blueprint};

use super::time_ranges_ui::TimeRangesUi;

Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/src/ui/time_panel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use egui::{pos2, Color32, CursorIcon, NumExt, PointerButton, Rect, Shape, Vec2};

use re_data_store::{EntityTree, InstancePath, TimeHistogram};
use re_log_types::{ComponentPath, EntityPathPart, TimeInt, TimeRange, TimeReal};
use re_viewer_context::Item;

use crate::{Item, TimeControl, TimeView, ViewerContext};
use crate::{TimeControl, TimeView, ViewerContext};

use super::{data_ui::DataUi, selection_panel::what_is_selected_ui, Blueprint};

Expand Down
Loading