diff --git a/crates/store/re_types/definitions/rerun/blueprint/archetypes/visible_time_ranges.fbs b/crates/store/re_types/definitions/rerun/blueprint/archetypes/visible_time_ranges.fbs index fecafb5878a3..3706c4b5d9fe 100644 --- a/crates/store/re_types/definitions/rerun/blueprint/archetypes/visible_time_ranges.fbs +++ b/crates/store/re_types/definitions/rerun/blueprint/archetypes/visible_time_ranges.fbs @@ -12,8 +12,7 @@ namespace rerun.blueprint.archetypes; /// - For time series views, the default is to show the entire timeline. /// - For any other view, the default is to apply latest-at semantics. table VisibleTimeRanges ( - // TODO:? - //"attr.rust.archetype_eager", + "attr.rust.archetype_eager", "attr.rerun.scope": "blueprint", "attr.rust.derive": "Default", "attr.python.aliases": "datatypes.VisibleTimeRangeLike, Sequence[datatypes.VisibleTimeRangeLike]" diff --git a/crates/store/re_types/src/blueprint/archetypes/mod.rs b/crates/store/re_types/src/blueprint/archetypes/mod.rs index e226ce3141b4..20bbbac5355f 100644 --- a/crates/store/re_types/src/blueprint/archetypes/mod.rs +++ b/crates/store/re_types/src/blueprint/archetypes/mod.rs @@ -22,7 +22,6 @@ mod view_blueprint; mod view_contents; mod viewport_blueprint; mod visible_time_ranges; -mod visible_time_ranges_ext; mod visual_bounds2d; pub use self::background::Background; diff --git a/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges.rs b/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges.rs index db09e1d83237..e55280213b66 100644 --- a/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges.rs +++ b/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges.rs @@ -32,7 +32,7 @@ pub struct VisibleTimeRanges { /// The time ranges to show for each timeline unless specified otherwise on a per-entity basis. /// /// If a timeline is specified more than once, the first entry will be used. - pub ranges: Vec, + pub ranges: Option, } impl VisibleTimeRanges { @@ -128,38 +128,21 @@ impl ::re_types_core::Archetype for VisibleTimeRanges { re_tracing::profile_function!(); use ::re_types_core::{Loggable as _, ResultExt as _}; let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect(); - let ranges = { - let array = arrays_by_descr - .get(&Self::descriptor_ranges()) - .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.blueprint.archetypes.VisibleTimeRanges#ranges")?; - ::from_arrow_opt(&**array) - .with_context("rerun.blueprint.archetypes.VisibleTimeRanges#ranges")? - .into_iter() - .map(|v| v.ok_or_else(DeserializationError::missing_data)) - .collect::>>() - .with_context("rerun.blueprint.archetypes.VisibleTimeRanges#ranges")? - }; + let ranges = arrays_by_descr + .get(&Self::descriptor_ranges()) + .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_ranges())); Ok(Self { ranges }) } } impl ::re_types_core::AsComponents for VisibleTimeRanges { - fn as_component_batches(&self) -> Vec> { - re_tracing::profile_function!(); + #[inline] + fn as_serialized_batches(&self) -> Vec { use ::re_types_core::Archetype as _; - [ - Some(Self::indicator()), - (Some(&self.ranges as &dyn ComponentBatch)).map(|batch| { - ::re_types_core::ComponentBatchCowWithDescriptor { - batch: batch.into(), - descriptor_override: Some(Self::descriptor_ranges()), - } - }), - ] - .into_iter() - .flatten() - .collect() + [Self::indicator().serialized(), self.ranges.clone()] + .into_iter() + .flatten() + .collect() } } @@ -172,9 +155,39 @@ impl VisibleTimeRanges { ranges: impl IntoIterator>, ) -> Self { Self { - ranges: ranges.into_iter().map(Into::into).collect(), + ranges: try_serialize_field(Self::descriptor_ranges(), ranges), + } + } + + /// Update only some specific fields of a `VisibleTimeRanges`. + #[inline] + pub fn update_fields() -> Self { + Self::default() + } + + /// Clear all the fields of a `VisibleTimeRanges`. + #[inline] + pub fn clear_fields() -> Self { + use ::re_types_core::Loggable as _; + Self { + ranges: Some(SerializedComponentBatch::new( + crate::blueprint::components::VisibleTimeRange::arrow_empty(), + Self::descriptor_ranges(), + )), } } + + /// The time ranges to show for each timeline unless specified otherwise on a per-entity basis. + /// + /// If a timeline is specified more than once, the first entry will be used. + #[inline] + pub fn with_ranges( + mut self, + ranges: impl IntoIterator>, + ) -> Self { + self.ranges = try_serialize_field(Self::descriptor_ranges(), ranges); + self + } } impl ::re_byte_size::SizeBytes for VisibleTimeRanges { @@ -182,9 +195,4 @@ impl ::re_byte_size::SizeBytes for VisibleTimeRanges { fn heap_size_bytes(&self) -> u64 { self.ranges.heap_size_bytes() } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - } } diff --git a/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges_ext.rs b/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges_ext.rs deleted file mode 100644 index d57ffcac5a0f..000000000000 --- a/crates/store/re_types/src/blueprint/archetypes/visible_time_ranges_ext.rs +++ /dev/null @@ -1,38 +0,0 @@ -use re_types_core::datatypes::TimeRange; - -use super::VisibleTimeRanges; - -impl VisibleTimeRanges { - /// Retrieves the time range for a given timeline. - pub fn range_for_timeline(&self, timeline_name: &str) -> Option<&TimeRange> { - self.ranges - .iter() - .find(|range| range.timeline.as_str() == timeline_name) - .map(|range| &range.range) - } - - /// Sets the time range for a given timeline. - /// - /// If the range is `None`, the timeline will be removed from the list of visible time ranges. - pub fn set_range_for_timeline(&mut self, timeline_name: &str, range: Option) { - if let Some(range) = range { - if let Some(existing_range) = self - .ranges - .iter_mut() - .find(|range| range.timeline.as_str() == timeline_name) - { - existing_range.0.range = range; - } else { - self.ranges.push( - crate::datatypes::VisibleTimeRange { - timeline: timeline_name.to_owned().into(), - range, - } - .into(), - ); - } - } else { - self.ranges.retain(|r| r.timeline.as_str() != timeline_name); - } - } -} diff --git a/crates/viewer/re_selection_panel/src/visible_time_range_ui.rs b/crates/viewer/re_selection_panel/src/visible_time_range_ui.rs index 7caae1c0e531..01a309723497 100644 --- a/crates/viewer/re_selection_panel/src/visible_time_range_ui.rs +++ b/crates/viewer/re_selection_panel/src/visible_time_range_ui.rs @@ -61,7 +61,7 @@ fn visible_time_range_ui( ) { use re_types::Component as _; - let ranges = ctx + let visible_time_ranges = ctx .blueprint_db() .latest_at( ctx.blueprint_query, @@ -70,12 +70,11 @@ fn visible_time_range_ui( ) .component_batch::() .unwrap_or_default(); - let visible_time_ranges = re_types::blueprint::archetypes::VisibleTimeRanges { ranges }; let timeline_name = *ctx.rec_cfg.time_ctrl.read().timeline().name(); let mut has_individual_range = visible_time_ranges - .range_for_timeline(timeline_name.as_str()) - .is_some(); + .iter() + .any(|range| range.timeline.as_str() == timeline_name.as_str()); let has_individual_range_before = has_individual_range; let query_range_before = resolved_query_range.clone(); @@ -112,7 +111,7 @@ fn save_visible_time_ranges( has_individual_range: bool, query_range: QueryRange, property_path: &EntityPath, - mut visible_time_ranges: re_types::blueprint::archetypes::VisibleTimeRanges, + mut visible_time_range_list: Vec, ) { if has_individual_range { let time_range = match query_range { @@ -125,12 +124,26 @@ fn save_visible_time_ranges( return; } }; - visible_time_ranges.set_range_for_timeline(timeline_name, Some(time_range)); + + if let Some(existing) = visible_time_range_list + .iter_mut() + .find(|r| r.timeline.as_str() == timeline_name.as_str()) + { + existing.range = time_range; + } else { + visible_time_range_list.push( + re_types::datatypes::VisibleTimeRange { + timeline: timeline_name.as_str().into(), + range: time_range, + } + .into(), + ); + } } else { - visible_time_ranges.set_range_for_timeline(timeline_name, None); + visible_time_range_list.retain(|r| r.timeline.as_str() != timeline_name.as_str()); } - ctx.save_blueprint_archetype(property_path, &visible_time_ranges); + ctx.save_blueprint_component(property_path, &visible_time_range_list); } /// Draws ui for showing and configuring a query range. diff --git a/crates/viewer/re_viewport_blueprint/src/view.rs b/crates/viewer/re_viewport_blueprint/src/view.rs index 3eb5bb1f453f..7d223dff19fb 100644 --- a/crates/viewer/re_viewport_blueprint/src/view.rs +++ b/crates/viewer/re_viewport_blueprint/src/view.rs @@ -364,12 +364,13 @@ impl ViewBlueprint { blueprint_query, self.id, ); - let ranges = property.component_array(); + let ranges = property.component_array::(); let time_range = ranges.ok().flatten().and_then(|ranges| { - blueprint_archetypes::VisibleTimeRanges { ranges } - .range_for_timeline(active_timeline.name().as_str()) - .cloned() + ranges + .iter() + .find(|range| range.timeline.as_str() == active_timeline.name().as_str()) + .map(|range| range.range.clone()) }); time_range.map_or_else( || {