Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Nov 5, 2024
1 parent 3886323 commit 7bd6667
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 25 deletions.
8 changes: 8 additions & 0 deletions crates/store/re_data_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ pub struct DataLoaderSettings {
/// The [`re_log_types::StoreId`] that is currently opened in the viewer, if any.
pub opened_store_id: Option<re_log_types::StoreId>,

/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
///
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
/// happens when importing things into the welcome screen).
pub force_store_info: bool,

/// What should the logged entity paths be prefixed with?
pub entity_path_prefix: Option<EntityPath>,

Expand All @@ -79,6 +85,7 @@ impl DataLoaderSettings {
opened_application_id: Default::default(),
store_id: store_id.into(),
opened_store_id: Default::default(),
force_store_info: false,
entity_path_prefix: Default::default(),
timepoint: Default::default(),
}
Expand All @@ -91,6 +98,7 @@ impl DataLoaderSettings {
opened_application_id,
store_id,
opened_store_id,
force_store_info: _,
entity_path_prefix,
timepoint,
} = self;
Expand Down
8 changes: 6 additions & 2 deletions crates/store/re_data_loader/src/load_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,13 @@ pub(crate) fn send(

for (store_id, store_info_already_created) in store_info_tracker {
let is_a_preexisting_recording =
Some(&store_id) == settings.opened_store_id.as_ref();
dbg!(Some(&store_id)) == dbg!(settings.opened_store_id.as_ref());

if store_info_already_created || is_a_preexisting_recording {
dbg!((store_info_already_created, is_a_preexisting_recording));

if !settings.force_store_info
&& (store_info_already_created || is_a_preexisting_recording)
{
continue;
}

Expand Down
7 changes: 5 additions & 2 deletions crates/store/re_data_source/src/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ impl DataSource {
let shared_store_id =
re_log_types::StoreId::random(re_log_types::StoreKind::Recording);
let settings = re_data_loader::DataLoaderSettings {
opened_application_id: file_source.recommended_application_id().cloned(),
opened_store_id: file_source.recommended_recording_id().cloned(),
opened_application_id: dbg!(file_source.recommended_application_id().cloned()),
opened_store_id: dbg!(file_source.recommended_recording_id().cloned()),
force_store_info: file_source.force_store_info(),
..re_data_loader::DataLoaderSettings::recommended(shared_store_id)
};
re_data_loader::load_from_path(&settings, file_source, &path, &tx)
Expand Down Expand Up @@ -206,6 +207,7 @@ impl DataSource {
let settings = re_data_loader::DataLoaderSettings {
opened_application_id: file_source.recommended_application_id().cloned(),
opened_store_id: file_source.recommended_recording_id().cloned(),
force_store_info: file_source.force_store_info(),
..re_data_loader::DataLoaderSettings::recommended(shared_store_id)
};
re_data_loader::load_from_file_contents(
Expand Down Expand Up @@ -275,6 +277,7 @@ fn test_data_source_from_uri() {
let file_source = FileSource::DragAndDrop {
recommended_application_id: None,
recommended_recording_id: None,
force_store_info: false,
};

for uri in file {
Expand Down
25 changes: 25 additions & 0 deletions crates/store/re_log_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ pub enum FileSource {
/// The [`StoreId`] that the viewer heuristically recommends should be used when loading
/// this data source, based on the surrounding context.
recommended_recording_id: Option<StoreId>,

/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
///
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
/// happens when importing things into the welcome screen).
force_store_info: bool,
},

FileDialog {
Expand All @@ -428,6 +434,12 @@ pub enum FileSource {
/// The [`StoreId`] that the viewer heuristically recommends should be used when loading
/// this data source, based on the surrounding context.
recommended_recording_id: Option<StoreId>,

/// Whether `SetStoreInfo`s should be sent, regardless of the surrounding context.
///
/// Only useful when creating a recording just-in-time directly in the viewer (which is what
/// happens when importing things into the welcome screen).
force_store_info: bool,
},

Sdk,
Expand Down Expand Up @@ -463,6 +475,19 @@ impl FileSource {
Self::Cli | Self::Sdk => None,
}
}

#[inline]
pub fn force_store_info(&self) -> bool {
match self {
Self::FileDialog {
force_store_info, ..
}
| Self::DragAndDrop {
force_store_info, ..
} => *force_store_info,
Self::Cli | Self::Sdk => false,
}
}
}

/// The source of a recording or blueprint.
Expand Down
1 change: 1 addition & 0 deletions crates/top/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ impl RecordingStream {
opened_application_id: None,
store_id: store_info.store_id.clone(),
opened_store_id: None,
force_store_info: false,
entity_path_prefix,
timepoint: (!static_).then(|| {
self.with(|inner| {
Expand Down
100 changes: 79 additions & 21 deletions crates/viewer/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use itertools::Itertools;
use re_build_info::CrateVersion;
use re_data_source::{DataSource, FileContents};
use re_entity_db::entity_db::EntityDb;
Expand Down Expand Up @@ -573,17 +574,33 @@ impl App {
store_context: Option<&StoreContext<'_>>,
cmd: UICommand,
) {
let active_application_id = store_context
.and_then(|ctx| {
ctx.hub
.active_app()
// Don't redirect data to the welcome screen.
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
})
.cloned();
let mut force_store_info = false;
let active_application_id = store_context.and_then(|ctx| {
ctx.hub
.active_app()
// Don't redirect data to the welcome screen.
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
.cloned()
});
let active_recording_id = store_context
.and_then(|ctx| ctx.hub.active_recording_id())
.cloned();
.and_then(|ctx| ctx.hub.active_recording_id().cloned())
.or_else(|| {
// When we're on the welcome screen, there is no recording ID to recommend.
// But we want one, otherwise multiple things being dropped simultaneously on the
// welcome screen would end up in different recordings!

// We're creating a recording just-in-time, directly from the viewer.
// We need those those store infos or the data will just be silently ignored.
force_store_info = true;

// NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
// this can only be a recording.
Some(re_log_types::StoreId::random(StoreKind::Recording))
});

// TODO: we need to detect when drag-n-dropping multiple files at once on a welcome screen
// and create an appropriate app-id, somehow, otherwise we'll end up creating empty apps
// and everything will become very messy

match cmd {
UICommand::SaveRecording => {
Expand Down Expand Up @@ -615,6 +632,7 @@ impl App {
FileSource::FileDialog {
recommended_application_id: None,
recommended_recording_id: None,
force_store_info,
},
file_path,
)));
Expand Down Expand Up @@ -642,12 +660,33 @@ impl App {

#[cfg(not(target_arch = "wasm32"))]
UICommand::Import => {
for file_path in open_file_dialog_native() {
let file_paths = open_file_dialog_native();

let active_application_id = active_application_id.clone().or_else(|| {
if file_paths.len() > 1 {
// TODO: come up with a nice compound name
Some(
file_paths
.iter()
.map(|p| p.to_string_lossy().to_string())
.collect_vec()
.join("|")
.into(),
)
} else {
file_paths
.first()
.map(|p| p.to_string_lossy().to_string().into())
}
});

for file_path in file_paths {
self.command_sender
.send_system(SystemCommand::LoadDataSource(DataSource::FilePath(
FileSource::FileDialog {
recommended_application_id: active_application_id.clone(),
recommended_recording_id: active_recording_id.clone(),
force_store_info,
},
file_path,
)));
Expand All @@ -661,6 +700,8 @@ impl App {
let recommended_application_id = active_application_id;
let recommended_recording_id = active_recording_id;

// TODO: how do we even know if we have multiple files?

let promise = poll_promise::Promise::spawn_local(async move {
let file = async_open_rrd_dialog().await;
egui_ctx.request_repaint(); // Wake ui thread
Expand Down Expand Up @@ -1364,17 +1405,32 @@ impl App {
return;
}

let active_application_id = store_ctx
.and_then(|ctx| {
ctx.hub
.active_app()
// Don't redirect data to the welcome screen.
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
})
.cloned();
let mut force_store_info = false;
let active_application_id = store_ctx.and_then(|ctx| {
ctx.hub
.active_app()
// Don't redirect data to the welcome screen.
.filter(|&app_id| app_id != &StoreHub::welcome_screen_app_id())
.cloned()
});
let active_recording_id = store_ctx
.and_then(|ctx| ctx.hub.active_recording_id())
.cloned();
.and_then(|ctx| ctx.hub.active_recording_id().cloned())
.or_else(|| {
// When we're on the welcome screen, there is no recording ID to recommend.
// But we want one, otherwise multiple things being dropped simultaneously on the
// welcome screen would end up in different recordings!

// We're creating a recording just-in-time, directly from the viewer.
// We need those those store infos or the data will just be silently ignored.
force_store_info = true;

// NOTE: We don't override blueprints' store IDs anyhow, so it is sound to assume that
// this can only be a recording.
Some(re_log_types::StoreId::random(StoreKind::Recording))
});

// TODO: same shenanigans below -- we need to detect when drag-n-dropping multiple files at
// once on a welcome screen and create an appropriate app-id, somehow

for file in dropped_files {
if let Some(bytes) = file.bytes {
Expand All @@ -1384,6 +1440,7 @@ impl App {
FileSource::DragAndDrop {
recommended_application_id: active_application_id.clone(),
recommended_recording_id: active_recording_id.clone(),
force_store_info,
},
FileContents {
name: file.name.clone(),
Expand All @@ -1400,6 +1457,7 @@ impl App {
FileSource::DragAndDrop {
recommended_application_id: active_application_id.clone(),
recommended_recording_id: active_recording_id.clone(),
force_store_info,
},
path,
)));
Expand Down

0 comments on commit 7bd6667

Please sign in to comment.