From 5172b1ab9b54df8f12eccc261b2529df2584f0b7 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 13 Oct 2023 16:04:25 +0200 Subject: [PATCH] reimplement PanelView using new blueprint types (re_viewer is now arrow2-convert free) --- Cargo.lock | 1 - crates/re_types/src/blueprint/mod.rs | 1 + crates/re_types/src/blueprint/panel_view.rs | 2 +- .../re_types/src/blueprint/panel_view_ext.rs | 9 +++++ crates/re_types/src/lib.rs | 7 ++++ .../re_types_builder/src/codegen/rust/api.rs | 2 +- crates/re_viewer/Cargo.toml | 1 - crates/re_viewer/src/app_blueprint.rs | 37 +++++++++---------- .../re_viewer/src/blueprint_components/mod.rs | 3 -- .../src/blueprint_components/panel.rs | 32 ---------------- crates/re_viewer/src/lib.rs | 1 - rerun_py/src/python_bridge.rs | 15 +++++--- 12 files changed, 46 insertions(+), 65 deletions(-) create mode 100644 crates/re_types/src/blueprint/panel_view_ext.rs delete mode 100644 crates/re_viewer/src/blueprint_components/mod.rs delete mode 100644 crates/re_viewer/src/blueprint_components/panel.rs diff --git a/Cargo.lock b/Cargo.lock index 1739cbcc7bf1c..ca86c1a56a4fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4777,7 +4777,6 @@ dependencies = [ "ahash 0.8.3", "anyhow", "arrow2", - "arrow2_convert", "bytemuck", "cfg-if", "eframe", diff --git a/crates/re_types/src/blueprint/mod.rs b/crates/re_types/src/blueprint/mod.rs index fa3dd9873d2df..709b135a99b68 100644 --- a/crates/re_types/src/blueprint/mod.rs +++ b/crates/re_types/src/blueprint/mod.rs @@ -1,5 +1,6 @@ // DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/rust/api.rs mod panel_view; +mod panel_view_ext; pub use self::panel_view::PanelView; diff --git a/crates/re_types/src/blueprint/panel_view.rs b/crates/re_types/src/blueprint/panel_view.rs index 6d36811ca28e4..97394f78e0b62 100644 --- a/crates/re_types/src/blueprint/panel_view.rs +++ b/crates/re_types/src/blueprint/panel_view.rs @@ -51,7 +51,7 @@ impl<'a> From<&'a PanelView> for ::std::borrow::Cow<'a, PanelView> { } impl crate::Loggable for PanelView { - type Name = crate::DatatypeName; + type Name = crate::ComponentName; #[inline] fn name() -> Self::Name { diff --git a/crates/re_types/src/blueprint/panel_view_ext.rs b/crates/re_types/src/blueprint/panel_view_ext.rs new file mode 100644 index 0000000000000..a03bd8888987f --- /dev/null +++ b/crates/re_types/src/blueprint/panel_view_ext.rs @@ -0,0 +1,9 @@ +use super::PanelView; + +impl PanelView { + // TODO(jleibs): Would be nice if this could be a const EntityPath but making + // the hash const is a bit of a pain. + pub const BLUEPRINT_VIEW_PATH: &str = "blueprint_view"; + pub const SELECTION_VIEW_PATH: &str = "selection_view"; + pub const TIMELINE_VIEW_PATH: &str = "timeline_view"; +} diff --git a/crates/re_types/src/lib.rs b/crates/re_types/src/lib.rs index de9e92fe3e199..2b825559be632 100644 --- a/crates/re_types/src/lib.rs +++ b/crates/re_types/src/lib.rs @@ -287,6 +287,13 @@ pub mod components; /// They all implement the [`Datatype`] trait. pub mod datatypes; +/// Blueprint-related types. +/// +/// They all implement the [`Component`] trait. +/// +/// Unstable. Used for the ongoing blueprint experimentations. +pub mod blueprint; + mod archetype; mod loggable; mod loggable_batch; diff --git a/crates/re_types_builder/src/codegen/rust/api.rs b/crates/re_types_builder/src/codegen/rust/api.rs index 5a07f19a8f4af..2d052ed7a74a7 100644 --- a/crates/re_types_builder/src/codegen/rust/api.rs +++ b/crates/re_types_builder/src/codegen/rust/api.rs @@ -714,7 +714,7 @@ fn quote_trait_impls_from_obj( match kind { ObjectKind::Datatype | ObjectKind::Component | ObjectKind::Blueprint => { - let quoted_kind = if *kind == ObjectKind::Datatype || *kind == ObjectKind::Blueprint { + let quoted_kind = if *kind == ObjectKind::Datatype { quote!(Datatype) } else { quote!(Component) diff --git a/crates/re_viewer/Cargo.toml b/crates/re_viewer/Cargo.toml index f4d19503cae0e..4fdd382dd61a1 100644 --- a/crates/re_viewer/Cargo.toml +++ b/crates/re_viewer/Cargo.toml @@ -73,7 +73,6 @@ re_analytics = { workspace = true, optional = true } ahash.workspace = true anyhow.workspace = true arrow2.workspace = true -arrow2_convert.workspace = true bytemuck.workspace = true cfg-if.workspace = true eframe = { workspace = true, default-features = false, features = [ diff --git a/crates/re_viewer/src/app_blueprint.rs b/crates/re_viewer/src/app_blueprint.rs index 89833defc0d94..04598676c8e16 100644 --- a/crates/re_viewer/src/app_blueprint.rs +++ b/crates/re_viewer/src/app_blueprint.rs @@ -1,9 +1,8 @@ use re_data_store::StoreDb; use re_log_types::{DataRow, EntityPath, RowId, TimePoint}; +use re_types::blueprint::PanelView; use re_viewer_context::{CommandSender, StoreContext, SystemCommand, SystemCommandSender}; -use crate::blueprint_components::panel::PanelState; - /// Blueprint for top-level application pub struct AppBlueprint<'a> { blueprint_db: Option<&'a StoreDb>, @@ -27,17 +26,17 @@ impl<'a> AppBlueprint<'a> { if let Some(blueprint_db) = blueprint_db { if let Some(expanded) = - load_panel_state(&PanelState::BLUEPRINT_VIEW_PATH.into(), blueprint_db) + load_panel_state(&PanelView::BLUEPRINT_VIEW_PATH.into(), blueprint_db) { ret.blueprint_panel_expanded = expanded; } if let Some(expanded) = - load_panel_state(&PanelState::SELECTION_VIEW_PATH.into(), blueprint_db) + load_panel_state(&PanelView::SELECTION_VIEW_PATH.into(), blueprint_db) { ret.selection_panel_expanded = expanded; } if let Some(expanded) = - load_panel_state(&PanelState::TIMELINE_VIEW_PATH.into(), blueprint_db) + load_panel_state(&PanelView::TIMELINE_VIEW_PATH.into(), blueprint_db) { ret.time_panel_expanded = expanded; } @@ -49,30 +48,30 @@ impl<'a> AppBlueprint<'a> { pub fn toggle_blueprint_panel(&self, command_sender: &CommandSender) { let blueprint_panel_expanded = !self.blueprint_panel_expanded; self.send_panel_expanded( - PanelState::BLUEPRINT_VIEW_PATH, + PanelView::BLUEPRINT_VIEW_PATH, blueprint_panel_expanded, command_sender, ); if self.is_narrow_screen && self.blueprint_panel_expanded { - self.send_panel_expanded(PanelState::SELECTION_VIEW_PATH, false, command_sender); + self.send_panel_expanded(PanelView::SELECTION_VIEW_PATH, false, command_sender); } } pub fn toggle_selection_panel(&self, command_sender: &CommandSender) { let selection_panel_expanded = !self.selection_panel_expanded; self.send_panel_expanded( - PanelState::SELECTION_VIEW_PATH, + PanelView::SELECTION_VIEW_PATH, selection_panel_expanded, command_sender, ); if self.is_narrow_screen && self.blueprint_panel_expanded { - self.send_panel_expanded(PanelState::BLUEPRINT_VIEW_PATH, false, command_sender); + self.send_panel_expanded(PanelView::BLUEPRINT_VIEW_PATH, false, command_sender); } } pub fn toggle_time_panel(&self, command_sender: &CommandSender) { self.send_panel_expanded( - PanelState::TIMELINE_VIEW_PATH, + PanelView::TIMELINE_VIEW_PATH, !self.time_panel_expanded, command_sender, ); @@ -80,16 +79,16 @@ impl<'a> AppBlueprint<'a> { } pub fn setup_welcome_screen_blueprint(welcome_screen_blueprint: &mut StoreDb) { - for (panel_name, expanded) in [ - (PanelState::BLUEPRINT_VIEW_PATH, true), - (PanelState::SELECTION_VIEW_PATH, false), - (PanelState::TIMELINE_VIEW_PATH, false), + for (panel_name, is_expanded) in [ + (PanelView::BLUEPRINT_VIEW_PATH, true), + (PanelView::SELECTION_VIEW_PATH, false), + (PanelView::TIMELINE_VIEW_PATH, false), ] { let entity_path = EntityPath::from(panel_name); // TODO(jleibs): Seq instead of timeless? let timepoint = TimePoint::timeless(); - let component = PanelState { expanded }; + let component = PanelView { is_expanded }; let row = DataRow::from_cells1_sized(RowId::random(), entity_path, timepoint, 1, [component]) @@ -105,7 +104,7 @@ impl<'a> AppBlueprint<'a> { fn send_panel_expanded( &self, panel_name: &str, - expanded: bool, + is_expanded: bool, command_sender: &CommandSender, ) { if let Some(blueprint_db) = self.blueprint_db { @@ -113,7 +112,7 @@ impl<'a> AppBlueprint<'a> { // TODO(jleibs): Seq instead of timeless? let timepoint = TimePoint::timeless(); - let component = PanelState { expanded }; + let component = PanelView { is_expanded }; let row = DataRow::from_cells1_sized(RowId::random(), entity_path, timepoint, 1, [component]) @@ -131,6 +130,6 @@ fn load_panel_state(path: &EntityPath, blueprint_db: &re_data_store::StoreDb) -> re_tracing::profile_function!(); blueprint_db .store() - .query_timeless_component::(path) - .map(|p| p.expanded) + .query_timeless_component::(path) + .map(|p| p.is_expanded) } diff --git a/crates/re_viewer/src/blueprint_components/mod.rs b/crates/re_viewer/src/blueprint_components/mod.rs deleted file mode 100644 index 51d8db096ca69..0000000000000 --- a/crates/re_viewer/src/blueprint_components/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Potentially user-facing components to be used in blueprints. - -pub mod panel; diff --git a/crates/re_viewer/src/blueprint_components/panel.rs b/crates/re_viewer/src/blueprint_components/panel.rs deleted file mode 100644 index ec2c1d68933c4..0000000000000 --- a/crates/re_viewer/src/blueprint_components/panel.rs +++ /dev/null @@ -1,32 +0,0 @@ -use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize}; - -/// A Panel component -/// -/// ## Example -/// ``` -/// # use re_viewer::blueprint_components::panel::PanelState; -/// # use arrow2_convert::field::ArrowField; -/// # use arrow2::datatypes::{DataType, Field}; -/// assert_eq!( -/// PanelState::data_type(), -/// DataType::Struct(vec![ -/// Field::new("expanded", DataType::Boolean, false), -/// ]) -/// ); -/// ``` -// TODO(jleibs): If we want these accessible from python, they need to -// go into the registry that's back in `re_log_types` -#[derive(Debug, Clone, Copy, ArrowField, ArrowSerialize, ArrowDeserialize)] -pub struct PanelState { - pub expanded: bool, -} - -impl PanelState { - // TODO(jleibs): Would be nice if this could be a const EntityPath but making - // the hash const is a bit of a pain. - pub const BLUEPRINT_VIEW_PATH: &str = "blueprint_view"; - pub const SELECTION_VIEW_PATH: &str = "selection_view"; - pub const TIMELINE_VIEW_PATH: &str = "timeline_view"; -} - -re_log_types::arrow2convert_component_shim!(PanelState as "rerun.blueprint.PanelView"); diff --git a/crates/re_viewer/src/lib.rs b/crates/re_viewer/src/lib.rs index ebee21a080602..b2ebcb8d255f8 100644 --- a/crates/re_viewer/src/lib.rs +++ b/crates/re_viewer/src/lib.rs @@ -7,7 +7,6 @@ mod app; mod app_blueprint; mod app_state; mod background_tasks; -pub mod blueprint_components; pub mod env_vars; #[cfg(not(target_arch = "wasm32"))] mod loading; diff --git a/rerun_py/src/python_bridge.rs b/rerun_py/src/python_bridge.rs index c72f831c8db1e..dbb7b3ae5fd55 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -11,7 +11,6 @@ use pyo3::{ types::{PyBytes, PyDict}, }; -use re_viewer::blueprint_components::panel::PanelState; use re_viewer_context::SpaceViewId; use re_viewport::{ blueprint_components::{AutoSpaceViews, SpaceViewComponent, VIEWPORT_PATH}, @@ -694,26 +693,30 @@ fn set_panels( timeline_view_expanded: Option, blueprint: Option<&PyRecordingStream>, ) { + use rerun::external::re_types::blueprint::PanelView; + if let Some(expanded) = blueprint_view_expanded { - set_panel(PanelState::BLUEPRINT_VIEW_PATH, expanded, blueprint); + set_panel(PanelView::BLUEPRINT_VIEW_PATH, expanded, blueprint); } if let Some(expanded) = selection_view_expanded { - set_panel(PanelState::SELECTION_VIEW_PATH, expanded, blueprint); + set_panel(PanelView::SELECTION_VIEW_PATH, expanded, blueprint); } if let Some(expanded) = timeline_view_expanded { - set_panel(PanelState::TIMELINE_VIEW_PATH, expanded, blueprint); + set_panel(PanelView::TIMELINE_VIEW_PATH, expanded, blueprint); } } -fn set_panel(entity_path: &str, expanded: bool, blueprint: Option<&PyRecordingStream>) { +fn set_panel(entity_path: &str, is_expanded: bool, blueprint: Option<&PyRecordingStream>) { let Some(blueprint) = get_blueprint_recording(blueprint) else { return; }; + use rerun::external::re_types::blueprint::PanelView; + // TODO(jleibs): Validation this is a valid blueprint path? let entity_path = parse_entity_path(entity_path); - let panel_state = PanelState { expanded }; + let panel_state = PanelView { is_expanded }; let row = DataRow::from_cells1( RowId::random(),