Skip to content

Commit c446bca

Browse files
committed
fix more functions
1 parent dbb85cc commit c446bca

File tree

8 files changed

+270
-147
lines changed

8 files changed

+270
-147
lines changed

crates/viewer/re_test_context/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl TestContext {
193193
let reflection =
194194
re_types::reflection::generate_reflection().expect("Failed to generate reflection");
195195

196-
Self {
196+
let this = Self {
197197
app_options: Default::default(),
198198

199199
view_class_registry: Default::default(),
@@ -215,7 +215,13 @@ impl TestContext {
215215
called_setup_kittest_for_rendering: AtomicBool::new(false),
216216

217217
store_hub: Mutex::new(store_hub),
218-
}
218+
};
219+
220+
this.with_blueprint_ctx(|ctx| {
221+
ctx.set_timeline("log_tick".into());
222+
});
223+
224+
this
219225
}
220226

221227
/// Create a new test context that knows about a specific view class.

crates/viewer/re_time_panel/tests/time_panel_filter_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn test_various_filter_ui_snapshot() {
4444
}
4545

4646
run_time_panel_and_save_snapshot(
47-
test_context,
47+
&test_context,
4848
time_panel,
4949
&format!(
5050
"various_filters-{}",
@@ -116,7 +116,7 @@ fn add_point_to_chunk_builder(builder: ChunkBuilder) -> ChunkBuilder {
116116
}
117117

118118
fn run_time_panel_and_save_snapshot(
119-
test_context: TestContext,
119+
test_context: &TestContext,
120120
mut time_panel: TimePanel,
121121
snapshot_name: &str,
122122
) {

crates/viewer/re_time_panel/tests/time_panel_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn run_time_panel_filter_tests(filter_active: bool, query: &str, snapshot_na
226226
time_panel.activate_filter(query);
227227
}
228228

229-
run_time_panel_and_save_snapshot(&mut test_context, time_panel, 300.0, false, snapshot_name);
229+
run_time_panel_and_save_snapshot(&test_context, time_panel, 300.0, false, snapshot_name);
230230
}
231231

232232
// --
@@ -263,7 +263,7 @@ pub fn test_various_entity_kinds_in_time_panel() {
263263
let time_panel = TimePanel::default();
264264

265265
run_time_panel_and_save_snapshot(
266-
&mut test_context,
266+
&test_context,
267267
time_panel,
268268
1200.0,
269269
true,
@@ -287,7 +287,7 @@ pub fn test_focused_item_is_focused() {
287287
let time_panel = TimePanel::default();
288288

289289
run_time_panel_and_save_snapshot(
290-
&mut test_context,
290+
&test_context,
291291
time_panel,
292292
200.0,
293293
false,

crates/viewer/re_viewer/src/app.rs

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ impl App {
916916
time,
917917
} => {
918918
if let Some(blueprint_ctx) =
919-
blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
919+
active_blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
920920
{
921921
blueprint_ctx.set_timeline(timeline);
922922

@@ -941,7 +941,7 @@ impl App {
941941
time_range,
942942
} => {
943943
if let Some(blueprint_ctx) =
944-
blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
944+
active_blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
945945
{
946946
blueprint_ctx.set_timeline(*timeline.name());
947947

@@ -1021,14 +1021,22 @@ impl App {
10211021
url: url.to_string(),
10221022
follow: *follow,
10231023
};
1024+
let Some(blueprint_ctx) =
1025+
active_blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
1026+
else {
1027+
return;
1028+
};
1029+
10241030
if all_sources.any(|source| source.is_same_ignoring_uri_fragments(&new_source)) {
10251031
if let Some(entity_db) = store_hub.find_recording_store_by_source(&new_source) {
10261032
if *follow {
1027-
let rec_cfg = self.state.recording_config_mut(entity_db);
1033+
let rec_cfg =
1034+
self.state.recording_config_mut(entity_db, &blueprint_ctx);
10281035
let time_ctrl = rec_cfg.time_ctrl.get_mut();
10291036
time_ctrl.set_play_state(
10301037
entity_db.times_per_timeline(),
10311038
PlayState::Following,
1039+
&blueprint_ctx,
10321040
);
10331041
}
10341042

@@ -1688,26 +1696,26 @@ impl App {
16881696
}) else {
16891697
return;
16901698
};
1691-
let rec_cfg = self.state.recording_config_mut(entity_db);
1699+
let rec_cfg = self.state.recording_config_mut(entity_db, &blueprint_ctx);
16921700
let time_ctrl = rec_cfg.time_ctrl.get_mut();
16931701

16941702
let times_per_timeline = entity_db.times_per_timeline();
16951703

16961704
match command {
16971705
TimeControlCommand::TogglePlayPause => {
1698-
time_ctrl.toggle_play_pause(times_per_timeline);
1706+
time_ctrl.toggle_play_pause(times_per_timeline, &blueprint_ctx);
16991707
}
17001708
TimeControlCommand::Follow => {
1701-
time_ctrl.set_play_state(times_per_timeline, PlayState::Following);
1709+
time_ctrl.set_play_state(times_per_timeline, PlayState::Following, &blueprint_ctx);
17021710
}
17031711
TimeControlCommand::StepBack => {
1704-
time_ctrl.step_time_back(&blueprint_ctx, times_per_timeline);
1712+
time_ctrl.step_time_back(times_per_timeline, &blueprint_ctx);
17051713
}
17061714
TimeControlCommand::StepForward => {
1707-
time_ctrl.step_time_fwd(&blueprint_ctx, times_per_timeline);
1715+
time_ctrl.step_time_fwd(times_per_timeline, &blueprint_ctx);
17081716
}
17091717
TimeControlCommand::Restart => {
1710-
time_ctrl.restart(times_per_timeline);
1718+
time_ctrl.restart(times_per_timeline, &blueprint_ctx);
17111719
}
17121720
}
17131721
}
@@ -2364,8 +2372,11 @@ impl App {
23642372
store_hub: &StoreHub,
23652373
store_id: &StoreId,
23662374
) -> Option<&mut RecordingConfig> {
2367-
if let Some(entity_db) = store_hub.store_bundle().get(store_id) {
2368-
Some(self.state.recording_config_mut(entity_db))
2375+
if let Some(entity_db) = store_hub.store_bundle().get(store_id)
2376+
&& let Some(blueprint_ctx) =
2377+
active_blueprint_ctx(&mut self.state, &self.command_sender, store_hub)
2378+
{
2379+
Some(self.state.recording_config_mut(entity_db, &blueprint_ctx))
23692380
} else {
23702381
re_log::debug!("Failed to find recording '{store_id:?}' in store hub");
23712382
None
@@ -2609,6 +2620,25 @@ impl App {
26092620
self.screenshotter.save(&self.egui_ctx, image);
26102621
}
26112622
}
2623+
2624+
/// Get an [`AppBlueprintCtx`] to interact with the given recording.
2625+
pub fn blueprint_ctx<'a>(&'a self, recording_id: &StoreId) -> Option<AppBlueprintCtx<'a>> {
2626+
let hub = self.store_hub.as_ref()?;
2627+
2628+
let blueprint = hub.active_blueprint_for_app(recording_id.application_id())?;
2629+
2630+
let default_blueprint = hub.default_blueprint_for_app(recording_id.application_id());
2631+
2632+
let blueprint_query =
2633+
re_chunk::LatestAtQuery::latest(re_viewer_context::blueprint_timeline());
2634+
2635+
Some(AppBlueprintCtx {
2636+
command_sender: &self.command_sender,
2637+
current_blueprint: blueprint,
2638+
default_blueprint,
2639+
blueprint_query,
2640+
})
2641+
}
26122642
}
26132643

26142644
#[cfg(target_arch = "wasm32")]
@@ -3334,10 +3364,10 @@ async fn async_save_dialog(
33343364
}
33353365

33363366
pub struct AppBlueprintCtx<'a> {
3337-
command_sender: &'a CommandSender,
3338-
current_blueprint: &'a EntityDb,
3339-
default_blueprint: Option<&'a EntityDb>,
3340-
blueprint_query: re_chunk::LatestAtQuery,
3367+
pub command_sender: &'a CommandSender,
3368+
pub current_blueprint: &'a EntityDb,
3369+
pub default_blueprint: Option<&'a EntityDb>,
3370+
pub blueprint_query: re_chunk::LatestAtQuery,
33413371
}
33423372

33433373
impl BlueprintContext for AppBlueprintCtx<'_> {
@@ -3359,21 +3389,22 @@ impl BlueprintContext for AppBlueprintCtx<'_> {
33593389
}
33603390

33613391
/// Build a [`AppBlueprintCtx`] to interact with the active blueprint.
3362-
fn blueprint_ctx<'a>(
3392+
pub fn active_blueprint_ctx<'a>(
33633393
app_state: &mut AppState,
33643394
command_sender: &'a CommandSender,
3365-
store_hub: &'a mut StoreHub,
3395+
hub: &'a StoreHub,
33663396
) -> Option<AppBlueprintCtx<'a>> {
3367-
let (_, Some(store_context)) = store_hub.read_context() else {
3368-
return None;
3369-
};
3397+
let active_app = hub.active_app()?;
3398+
let current_blueprint = hub.active_blueprint_for_app(active_app)?;
3399+
3400+
let default_blueprint = hub.default_blueprint_for_app(active_app);
33703401

3371-
let blueprint_query = app_state.blueprint_query_for_viewer(store_context.blueprint);
3402+
let blueprint_query = app_state.blueprint_query_for_viewer(current_blueprint);
33723403

33733404
Some(AppBlueprintCtx {
33743405
command_sender,
3375-
current_blueprint: store_context.blueprint,
3376-
default_blueprint: store_context.default_blueprint,
3406+
current_blueprint,
3407+
default_blueprint,
33773408
blueprint_query,
33783409
})
33793410
}

crates/viewer/re_viewer/src/app_state.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ use re_smart_channel::ReceiveSet;
1313
use re_types::blueprint::components::PanelState;
1414
use re_ui::{ContextExt as _, UiExt as _};
1515
use re_viewer_context::{
16-
AppOptions, ApplicationSelectionState, AsyncRuntimeHandle, BlueprintTimeControl,
17-
BlueprintUndoState, CommandSender, ComponentUiRegistry, DisplayMode, DragAndDropManager,
18-
GlobalContext, Item, PlayState, RecordingConfig, SelectionChange, StorageContext, StoreContext,
19-
StoreHub, SystemCommand, SystemCommandSender as _, TableStore, TimeControl, ViewClassRegistry,
20-
ViewStates, ViewerContext, blueprint_timeline,
16+
AppOptions, ApplicationSelectionState, AsyncRuntimeHandle, BlueprintContext,
17+
BlueprintTimeControl, BlueprintUndoState, CommandSender, ComponentUiRegistry, DisplayMode,
18+
DragAndDropManager, GlobalContext, Item, PlayState, RecordingConfig, SelectionChange,
19+
StorageContext, StoreContext, StoreHub, SystemCommand, SystemCommandSender as _, TableStore,
20+
ViewClassRegistry, ViewStates, ViewerContext, blueprint_timeline,
2121
open_url::{self, ViewerOpenUrl},
2222
};
2323
use re_viewport::ViewportUi;
2424
use re_viewport_blueprint::ViewportBlueprint;
2525
use re_viewport_blueprint::ui::add_view_or_container_modal_ui;
2626

2727
use crate::{
28-
StartupOptions, app_blueprint::AppBlueprint, event::ViewerEventDispatcher,
29-
navigation::Navigation, open_url_description::ViewerOpenUrlDescription, ui::settings_screen_ui,
28+
StartupOptions, app::AppBlueprintCtx, app_blueprint::AppBlueprint,
29+
event::ViewerEventDispatcher, navigation::Navigation,
30+
open_url_description::ViewerOpenUrlDescription, ui::settings_screen_ui,
3031
};
3132

3233
const WATERMARK: bool = false; // Nice for recording media material
@@ -311,7 +312,16 @@ impl AppState {
311312
.collect::<_>()
312313
};
313314

314-
let rec_cfg = recording_config_entry(recording_configs, recording);
315+
let app_blueprint_ctx = AppBlueprintCtx {
316+
command_sender,
317+
current_blueprint: store_context.blueprint,
318+
default_blueprint: store_context.default_blueprint,
319+
blueprint_query,
320+
};
321+
let rec_cfg =
322+
recording_config_entry(recording_configs, recording, &app_blueprint_ctx);
323+
let blueprint_query = app_blueprint_ctx.blueprint_query;
324+
315325
let egui_ctx = ui.ctx().clone();
316326
let display_mode = self.navigation.peek();
317327
let ctx = ViewerContext {
@@ -722,8 +732,12 @@ impl AppState {
722732
self.recording_configs.get(rec_id)
723733
}
724734

725-
pub fn recording_config_mut(&mut self, entity_db: &EntityDb) -> &mut RecordingConfig {
726-
recording_config_entry(&mut self.recording_configs, entity_db)
735+
pub fn recording_config_mut(
736+
&mut self,
737+
entity_db: &EntityDb,
738+
blueprint_ctx: &impl BlueprintContext,
739+
) -> &mut RecordingConfig {
740+
recording_config_entry(&mut self.recording_configs, entity_db, blueprint_ctx)
727741
}
728742

729743
pub fn cleanup(&mut self, store_hub: &StoreHub) {
@@ -795,7 +809,7 @@ fn move_time(
795809
// The state diffs are used to trigger callbacks if they are configured.
796810
// Unless we have a real recording open, we should not actually trigger any callbacks.
797811
should_diff_time_ctrl,
798-
Some(ctx),
812+
ctx,
799813
);
800814

801815
handle_time_ctrl_event(recording, events, &recording_time_ctrl_response);
@@ -812,7 +826,6 @@ fn move_time(
812826
dt,
813827
more_data_is_coming,
814828
should_diff_time_ctrl,
815-
None::<&ViewerContext<'_>>,
816829
)
817830
.needs_repaint
818831
} else {
@@ -851,8 +864,12 @@ fn handle_time_ctrl_event(
851864
pub(crate) fn recording_config_entry<'cfgs>(
852865
configs: &'cfgs mut HashMap<StoreId, RecordingConfig>,
853866
entity_db: &'_ EntityDb,
867+
blueprint_ctx: &'_ impl BlueprintContext,
854868
) -> &'cfgs mut RecordingConfig {
855-
fn new_recording_config(entity_db: &'_ EntityDb) -> RecordingConfig {
869+
fn new_recording_config(
870+
entity_db: &'_ EntityDb,
871+
blueprint_ctx: &'_ impl BlueprintContext,
872+
) -> RecordingConfig {
856873
let play_state = if let Some(data_source) = &entity_db.data_source {
857874
match data_source {
858875
// Play files from the start by default - it feels nice and alive.
@@ -873,19 +890,20 @@ pub(crate) fn recording_config_entry<'cfgs>(
873890
PlayState::Following // No known source 🤷‍♂️
874891
};
875892

876-
let mut rec_cfg = RecordingConfig::<TimeControl>::default();
893+
let mut rec_cfg = RecordingConfig::from_blueprint(blueprint_ctx);
877894

878-
rec_cfg
879-
.time_ctrl
880-
.get_mut()
881-
.set_play_state(entity_db.times_per_timeline(), play_state);
895+
rec_cfg.time_ctrl.get_mut().set_play_state(
896+
entity_db.times_per_timeline(),
897+
play_state,
898+
blueprint_ctx,
899+
);
882900

883901
rec_cfg
884902
}
885903

886904
configs
887905
.entry(entity_db.store_id().clone())
888-
.or_insert_with(|| new_recording_config(entity_db))
906+
.or_insert_with(|| new_recording_config(entity_db, blueprint_ctx))
889907
}
890908

891909
/// Handles all kind of links that can be opened within the viewer.

0 commit comments

Comments
 (0)