Skip to content

Commit cc16f97

Browse files
committed
Don't override saved times per timeline
1 parent c2f541d commit cc16f97

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed

crates/viewer/re_viewer_context/src/blueprint_helpers.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,49 @@ pub trait BlueprintContext {
257257
}
258258
}
259259
}
260+
261+
fn clear_static_blueprint_component(
262+
&self,
263+
entity_path: EntityPath,
264+
component_descr: ComponentDescriptor,
265+
) {
266+
let blueprint = self.current_blueprint();
267+
268+
let Some(datatype) = blueprint
269+
.latest_at(self.blueprint_query(), &entity_path, [&component_descr])
270+
.get(&component_descr)
271+
.and_then(|unit| {
272+
unit.component_batch_raw(&component_descr)
273+
.map(|array| array.data_type().clone())
274+
})
275+
else {
276+
// There's no component at this path yet, so there's nothing to clear.
277+
return;
278+
};
279+
280+
let chunk = Chunk::builder(entity_path)
281+
.with_row(
282+
RowId::new(),
283+
TimePoint::STATIC,
284+
[(
285+
component_descr,
286+
re_chunk::external::arrow::array::new_empty_array(&datatype),
287+
)],
288+
)
289+
.build();
290+
291+
match chunk {
292+
Ok(chunk) => self
293+
.command_sender()
294+
.send_system(SystemCommand::AppendToStore(
295+
blueprint.store_id().clone(),
296+
vec![chunk],
297+
)),
298+
Err(err) => {
299+
re_log::error_once!("Failed to create Chunk for blueprint component: {}", err);
300+
}
301+
}
302+
}
260303
}
261304

262305
impl BlueprintContext for ViewerContext<'_> {

crates/viewer/re_viewer_context/src/time_control.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ pub fn time_panel_blueprint_entity_path() -> EntityPath {
2424

2525
/// Helper trait to write time panel related blueprint components.
2626
pub trait TimeBlueprintExt {
27-
fn set_timeline_and_time(&self, timeline: TimelineName, time: impl Into<TimeInt>) {
28-
self.set_timeline(timeline);
29-
self.set_time(time);
30-
}
27+
fn set_timeline_and_time(&self, timeline: TimelineName, time: impl Into<TimeInt>);
3128

3229
fn set_time(&self, time: impl Into<TimeInt>);
3330

@@ -39,9 +36,20 @@ pub trait TimeBlueprintExt {
3936

4037
/// Replaces the current timeline with the automatic one.
4138
fn clear_timeline(&self);
39+
40+
fn clear_time(&self);
4241
}
4342

4443
impl<T: BlueprintContext> TimeBlueprintExt for T {
44+
fn set_timeline_and_time(&self, timeline: TimelineName, time: impl Into<TimeInt>) {
45+
self.save_blueprint_component(
46+
time_panel_blueprint_entity_path(),
47+
&TimePanelBlueprint::descriptor_timeline(),
48+
&re_types::blueprint::components::TimelineName::from(timeline.as_str()),
49+
);
50+
self.set_time(time);
51+
}
52+
4553
fn set_time(&self, time: impl Into<TimeInt>) {
4654
let time: TimeInt = time.into();
4755
self.save_blueprint_component_static(
@@ -69,6 +77,7 @@ impl<T: BlueprintContext> TimeBlueprintExt for T {
6977
&TimePanelBlueprint::descriptor_timeline(),
7078
&re_types::blueprint::components::TimelineName::from(timeline.as_str()),
7179
);
80+
self.clear_time();
7281
}
7382

7483
fn get_timeline(&self) -> Option<TimelineName> {
@@ -89,6 +98,13 @@ impl<T: BlueprintContext> TimeBlueprintExt for T {
8998
TimePanelBlueprint::descriptor_timeline(),
9099
);
91100
}
101+
102+
fn clear_time(&self) {
103+
self.clear_static_blueprint_component(
104+
time_panel_blueprint_entity_path(),
105+
TimePanelBlueprint::descriptor_time(),
106+
);
107+
}
92108
}
93109

94110
/// The time range we are currently zoomed in on.
@@ -318,7 +334,7 @@ impl TimeControl {
318334
pub fn from_blueprint(blueprint_ctx: &impl BlueprintContext) -> Self {
319335
let mut this = Self::default();
320336

321-
this.update_from_blueprint(blueprint_ctx);
337+
this.update_from_blueprint(blueprint_ctx, None);
322338

323339
this
324340
}
@@ -356,7 +372,11 @@ impl TimeControl {
356372
self.set_time(time);
357373
}
358374

359-
fn update_from_blueprint(&mut self, blueprint_ctx: &impl BlueprintContext) {
375+
fn update_from_blueprint(
376+
&mut self,
377+
blueprint_ctx: &impl BlueprintContext,
378+
times_per_timeline: Option<&TimesPerTimeline>,
379+
) {
360380
if let Some(timeline) = blueprint_ctx.get_timeline() {
361381
if matches!(self.timeline, ActiveTimeline::Auto(_))
362382
|| timeline.as_str() != self.timeline().name().as_str()
@@ -367,10 +387,18 @@ impl TimeControl {
367387
self.timeline = ActiveTimeline::Auto(*self.timeline());
368388
}
369389

370-
if let Some(time) = blueprint_ctx.get_time()
371-
&& self.time_int() != Some(time)
372-
{
373-
self.set_time(time.into());
390+
if let Some(times_per_timeline) = times_per_timeline {
391+
self.select_a_valid_timeline(times_per_timeline);
392+
}
393+
394+
if let Some(time) = blueprint_ctx.get_time() {
395+
if self.time_int() != Some(time) {
396+
self.set_time(time.into());
397+
}
398+
}
399+
// If the blueprint time wasn't set, but the current state's time was, we likely just switched timelines, so restore that timeline's time.
400+
else if let Some(state) = self.states.get(self.timeline().name()) {
401+
blueprint_ctx.set_time(state.current.time.floor());
374402
}
375403
}
376404

@@ -384,11 +412,11 @@ impl TimeControl {
384412
blueprint_ctx: Option<&impl BlueprintContext>,
385413
) -> TimeControlResponse {
386414
if let Some(blueprint_ctx) = blueprint_ctx {
387-
self.update_from_blueprint(blueprint_ctx);
415+
self.update_from_blueprint(blueprint_ctx, Some(times_per_timeline));
416+
} else {
417+
self.select_a_valid_timeline(times_per_timeline);
388418
}
389419

390-
self.select_a_valid_timeline(times_per_timeline);
391-
392420
let Some(full_valid_range) = self.full_valid_range(times_per_timeline) else {
393421
return TimeControlResponse::no_repaint(); // we have no data on this timeline yet, so bail
394422
};

0 commit comments

Comments
 (0)