Skip to content

Commit 7bd6667

Browse files
committed
wip
1 parent 3886323 commit 7bd6667

File tree

6 files changed

+124
-25
lines changed

6 files changed

+124
-25
lines changed

crates/store/re_data_loader/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ pub struct DataLoaderSettings {
6464
/// The [`re_log_types::StoreId`] that is currently opened in the viewer, if any.
6565
pub opened_store_id: Option<re_log_types::StoreId>,
6666

67+
/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
68+
///
69+
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
70+
/// happens when importing things into the welcome screen).
71+
pub force_store_info: bool,
72+
6773
/// What should the logged entity paths be prefixed with?
6874
pub entity_path_prefix: Option<EntityPath>,
6975

@@ -79,6 +85,7 @@ impl DataLoaderSettings {
7985
opened_application_id: Default::default(),
8086
store_id: store_id.into(),
8187
opened_store_id: Default::default(),
88+
force_store_info: false,
8289
entity_path_prefix: Default::default(),
8390
timepoint: Default::default(),
8491
}
@@ -91,6 +98,7 @@ impl DataLoaderSettings {
9198
opened_application_id,
9299
store_id,
93100
opened_store_id,
101+
force_store_info: _,
94102
entity_path_prefix,
95103
timepoint,
96104
} = self;

crates/store/re_data_loader/src/load_file.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,13 @@ pub(crate) fn send(
308308

309309
for (store_id, store_info_already_created) in store_info_tracker {
310310
let is_a_preexisting_recording =
311-
Some(&store_id) == settings.opened_store_id.as_ref();
311+
dbg!(Some(&store_id)) == dbg!(settings.opened_store_id.as_ref());
312312

313-
if store_info_already_created || is_a_preexisting_recording {
313+
dbg!((store_info_already_created, is_a_preexisting_recording));
314+
315+
if !settings.force_store_info
316+
&& (store_info_already_created || is_a_preexisting_recording)
317+
{
314318
continue;
315319
}
316320

crates/store/re_data_source/src/data_source.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ impl DataSource {
176176
let shared_store_id =
177177
re_log_types::StoreId::random(re_log_types::StoreKind::Recording);
178178
let settings = re_data_loader::DataLoaderSettings {
179-
opened_application_id: file_source.recommended_application_id().cloned(),
180-
opened_store_id: file_source.recommended_recording_id().cloned(),
179+
opened_application_id: dbg!(file_source.recommended_application_id().cloned()),
180+
opened_store_id: dbg!(file_source.recommended_recording_id().cloned()),
181+
force_store_info: file_source.force_store_info(),
181182
..re_data_loader::DataLoaderSettings::recommended(shared_store_id)
182183
};
183184
re_data_loader::load_from_path(&settings, file_source, &path, &tx)
@@ -206,6 +207,7 @@ impl DataSource {
206207
let settings = re_data_loader::DataLoaderSettings {
207208
opened_application_id: file_source.recommended_application_id().cloned(),
208209
opened_store_id: file_source.recommended_recording_id().cloned(),
210+
force_store_info: file_source.force_store_info(),
209211
..re_data_loader::DataLoaderSettings::recommended(shared_store_id)
210212
};
211213
re_data_loader::load_from_file_contents(
@@ -275,6 +277,7 @@ fn test_data_source_from_uri() {
275277
let file_source = FileSource::DragAndDrop {
276278
recommended_application_id: None,
277279
recommended_recording_id: None,
280+
force_store_info: false,
278281
};
279282

280283
for uri in file {

crates/store/re_log_types/src/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ pub enum FileSource {
418418
/// The [`StoreId`] that the viewer heuristically recommends should be used when loading
419419
/// this data source, based on the surrounding context.
420420
recommended_recording_id: Option<StoreId>,
421+
422+
/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
423+
///
424+
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
425+
/// happens when importing things into the welcome screen).
426+
force_store_info: bool,
421427
},
422428

423429
FileDialog {
@@ -428,6 +434,12 @@ pub enum FileSource {
428434
/// The [`StoreId`] that the viewer heuristically recommends should be used when loading
429435
/// this data source, based on the surrounding context.
430436
recommended_recording_id: Option<StoreId>,
437+
438+
/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
439+
///
440+
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
441+
/// happens when importing things into the welcome screen).
442+
force_store_info: bool,
431443
},
432444

433445
Sdk,
@@ -463,6 +475,19 @@ impl FileSource {
463475
Self::Cli | Self::Sdk => None,
464476
}
465477
}
478+
479+
#[inline]
480+
pub fn force_store_info(&self) -> bool {
481+
match self {
482+
Self::FileDialog {
483+
force_store_info, ..
484+
}
485+
| Self::DragAndDrop {
486+
force_store_info, ..
487+
} => *force_store_info,
488+
Self::Cli | Self::Sdk => false,
489+
}
490+
}
466491
}
467492

468493
/// The source of a recording or blueprint.

crates/top/re_sdk/src/recording_stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ impl RecordingStream {
12591259
opened_application_id: None,
12601260
store_id: store_info.store_id.clone(),
12611261
opened_store_id: None,
1262+
force_store_info: false,
12621263
entity_path_prefix,
12631264
timepoint: (!static_).then(|| {
12641265
self.with(|inner| {

crates/viewer/re_viewer/src/app.rs

+79-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use itertools::Itertools;
34
use re_build_info::CrateVersion;
45
use re_data_source::{DataSource, FileContents};
56
use re_entity_db::entity_db::EntityDb;
@@ -573,17 +574,33 @@ impl App {
573574
store_context: Option<&StoreContext<'_>>,
574575
cmd: UICommand,
575576
) {
576-
let active_application_id = store_context
577-
.and_then(|ctx| {
578-
ctx.hub
579-
.active_app()
580-
// Don't redirect data to the welcome screen.
581-
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
582-
})
583-
.cloned();
577+
let mut force_store_info = false;
578+
let active_application_id = store_context.and_then(|ctx| {
579+
ctx.hub
580+
.active_app()
581+
// Don't redirect data to the welcome screen.
582+
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
583+
.cloned()
584+
});
584585
let active_recording_id = store_context
585-
.and_then(|ctx| ctx.hub.active_recording_id())
586-
.cloned();
586+
.and_then(|ctx| ctx.hub.active_recording_id().cloned())
587+
.or_else(|| {
588+
// When we're on the welcome screen, there is no recording ID to recommend.
589+
// But we want one, otherwise multiple things being dropped simultaneously on the
590+
// welcome screen would end up in different recordings!
591+
592+
// We're creating a recording just-in-time, directly from the viewer.
593+
// We need those those store infos or the data will just be silently ignored.
594+
force_store_info = true;
595+
596+
// NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
597+
// this can only be a recording.
598+
Some(re_log_types::StoreId::random(StoreKind::Recording))
599+
});
600+
601+
// TODO: we need to detect when drag-n-dropping multiple files at once on a welcome screen
602+
// and create an appropriate app-id, somehow, otherwise we'll end up creating empty apps
603+
// and everything will become very messy
587604

588605
match cmd {
589606
UICommand::SaveRecording => {
@@ -615,6 +632,7 @@ impl App {
615632
FileSource::FileDialog {
616633
recommended_application_id: None,
617634
recommended_recording_id: None,
635+
force_store_info,
618636
},
619637
file_path,
620638
)));
@@ -642,12 +660,33 @@ impl App {
642660

643661
#[cfg(not(target_arch = "wasm32"))]
644662
UICommand::Import => {
645-
for file_path in open_file_dialog_native() {
663+
let file_paths = open_file_dialog_native();
664+
665+
let active_application_id = active_application_id.clone().or_else(|| {
666+
if file_paths.len() > 1 {
667+
// TODO: come up with a nice compound name
668+
Some(
669+
file_paths
670+
.iter()
671+
.map(|p| p.to_string_lossy().to_string())
672+
.collect_vec()
673+
.join("|")
674+
.into(),
675+
)
676+
} else {
677+
file_paths
678+
.first()
679+
.map(|p| p.to_string_lossy().to_string().into())
680+
}
681+
});
682+
683+
for file_path in file_paths {
646684
self.command_sender
647685
.send_system(SystemCommand::LoadDataSource(DataSource::FilePath(
648686
FileSource::FileDialog {
649687
recommended_application_id: active_application_id.clone(),
650688
recommended_recording_id: active_recording_id.clone(),
689+
force_store_info,
651690
},
652691
file_path,
653692
)));
@@ -661,6 +700,8 @@ impl App {
661700
let recommended_application_id = active_application_id;
662701
let recommended_recording_id = active_recording_id;
663702

703+
// TODO: how do we even know if we have multiple files?
704+
664705
let promise = poll_promise::Promise::spawn_local(async move {
665706
let file = async_open_rrd_dialog().await;
666707
egui_ctx.request_repaint(); // Wake ui thread
@@ -1364,17 +1405,32 @@ impl App {
13641405
return;
13651406
}
13661407

1367-
let active_application_id = store_ctx
1368-
.and_then(|ctx| {
1369-
ctx.hub
1370-
.active_app()
1371-
// Don't redirect data to the welcome screen.
1372-
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
1373-
})
1374-
.cloned();
1408+
let mut force_store_info = false;
1409+
let active_application_id = store_ctx.and_then(|ctx| {
1410+
ctx.hub
1411+
.active_app()
1412+
// Don't redirect data to the welcome screen.
1413+
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
1414+
.cloned()
1415+
});
13751416
let active_recording_id = store_ctx
1376-
.and_then(|ctx| ctx.hub.active_recording_id())
1377-
.cloned();
1417+
.and_then(|ctx| ctx.hub.active_recording_id().cloned())
1418+
.or_else(|| {
1419+
// When we're on the welcome screen, there is no recording ID to recommend.
1420+
// But we want one, otherwise multiple things being dropped simultaneously on the
1421+
// welcome screen would end up in different recordings!
1422+
1423+
// We're creating a recording just-in-time, directly from the viewer.
1424+
// We need those those store infos or the data will just be silently ignored.
1425+
force_store_info = true;
1426+
1427+
// NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
1428+
// this can only be a recording.
1429+
Some(re_log_types::StoreId::random(StoreKind::Recording))
1430+
});
1431+
1432+
// TODO: same shenanigans below -- we need to detect when drag-n-dropping multiple files at
1433+
// once on a welcome screen and create an appropriate app-id, somehow
13781434

13791435
for file in dropped_files {
13801436
if let Some(bytes) = file.bytes {
@@ -1384,6 +1440,7 @@ impl App {
13841440
FileSource::DragAndDrop {
13851441
recommended_application_id: active_application_id.clone(),
13861442
recommended_recording_id: active_recording_id.clone(),
1443+
force_store_info,
13871444
},
13881445
FileContents {
13891446
name: file.name.clone(),
@@ -1400,6 +1457,7 @@ impl App {
14001457
FileSource::DragAndDrop {
14011458
recommended_application_id: active_application_id.clone(),
14021459
recommended_recording_id: active_recording_id.clone(),
1460+
force_store_info,
14031461
},
14041462
path,
14051463
)));

0 commit comments

Comments
 (0)