Skip to content

Commit

Permalink
Add rerun reset command (#3145)
Browse files Browse the repository at this point in the history
### What
`rerun reset` will clear the stored memory, including:

* egui state
* native window size and position
* blueprints

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3145) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3145)
- [Docs
preview](https://rerun.io/preview/e23352a000a8d01186383ef15cfe71f235b55700/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/e23352a000a8d01186383ef15cfe71f235b55700/examples)
<!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
emilk authored Aug 29, 2023
1 parent 99e4efa commit d7de7f9
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 82 deletions.
30 changes: 21 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ eframe = { version = "0.22.0", default-features = false, features = [
] }
egui = { version = "0.22.0", features = ["extra_debug_asserts", "log"] }
egui_extras = { version = "0.22.0", features = ["log"] }
egui_plot = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
egui_tiles = { version = "0.2" }
egui-wgpu = "0.22.0"
emath = "0.22.0"
Expand Down Expand Up @@ -158,14 +159,14 @@ debug = true
# ALWAYS document what PR the commit hash is part of, or when it was merged into the upstream trunk.

# Temporary patch until next egui release
ecolor = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
eframe = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
egui-winit = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
egui = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
emath = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
epaint = { git = "https://github.com/emilk/egui", rev = "f0addc339cd753f724253f37b37af6db1a84178b" }
ecolor = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
eframe = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
egui-winit = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
egui = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
emath = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }
epaint = { git = "https://github.com/emilk/egui", rev = "70bfc7e09f1b1f794a77064b62a4932f9e60ef15" }

# Temporary patch until next egui_tiles release
egui_tiles = { git = "https://github.com/rerun-io/egui_tiles", rev = "f835c4df1cc260a58122a8d37c7c3738902b9643" }
1 change: 1 addition & 0 deletions crates/re_data_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ahash.workspace = true
anyhow.workspace = true
bytemuck.workspace = true
egui_extras.workspace = true
egui_plot.workspace = true
egui.workspace = true
image.workspace = true
itertools.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ fn rgb8_histogram_ui(ui: &mut egui::Ui, rgb: &[u8]) -> egui::Response {
}
}

use egui::plot::{Bar, BarChart, Legend, Plot};
use egui_plot::{Bar, BarChart, Legend, Plot};

let names = ["R", "G", "B"];
let colors = [Color32::RED, Color32::GREEN, Color32::BLUE];
Expand Down
1 change: 1 addition & 0 deletions crates/re_space_view_bar_chart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ re_types.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

egui_plot.workspace = true
egui.workspace = true
vec1.workspace = true
4 changes: 2 additions & 2 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SpaceViewClass for BarChartSpaceView {
_query: &ViewQuery<'_>,
_draw_data: Vec<re_renderer::QueueableDrawData>,
) -> Result<(), SpaceViewSystemExecutionError> {
use egui::plot::{Bar, BarChart, Legend, Plot};
use egui_plot::{Bar, BarChart, Legend, Plot};

let charts = &parts.get::<BarChartViewPartSystem>()?.charts;

Expand All @@ -94,7 +94,7 @@ impl SpaceViewClass for BarChartSpaceView {
Plot::new("bar_chart_plot")
.legend(Legend::default())
.clamp_grid(true)
.allow_zoom(egui::plot::AxisBools {
.allow_zoom(egui_plot::AxisBools {
x: true,
y: zoom_both_axis,
})
Expand Down
1 change: 1 addition & 0 deletions crates/re_space_view_time_series/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ re_viewer_context.workspace = true
re_query.workspace = true
re_format.workspace = true

egui_plot.workspace = true
egui.workspace = true
vec1.workspace = true
14 changes: 7 additions & 7 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::plot::{Legend, Line, Plot, Points};
use egui_plot::{Legend, Line, Plot, Points};

use re_arrow_store::TimeType;
use re_format::next_grid_tick_magnitude_ns;
Expand Down Expand Up @@ -125,12 +125,12 @@ impl SpaceViewClass for TimeSeriesSpaceView {
let zoom_both_axis = !ui.input(|i| i.modifiers.contains(controls::ASPECT_SCROLL_MODIFIER));

let mut plot = Plot::new(plot_id_src)
.allow_zoom(egui::plot::AxisBools {
.allow_zoom(egui_plot::AxisBools {
x: true,
y: zoom_both_axis,
})
.legend(Legend {
position: egui::plot::Corner::RightBottom,
position: egui_plot::Corner::RightBottom,
..Default::default()
})
.x_axis_formatter(move |time, _, _| format_time(time_type, time as i64 + time_offset))
Expand All @@ -151,7 +151,7 @@ impl SpaceViewClass for TimeSeriesSpaceView {
plot = plot.x_grid_spacer(move |spacer| ns_grid_spacer(canvas_size, &spacer));
}

let egui::plot::PlotResponse {
let egui_plot::PlotResponse {
inner: time_x,
response,
transform,
Expand Down Expand Up @@ -242,8 +242,8 @@ fn format_time(time_type: TimeType, time_int: i64) -> String {

fn ns_grid_spacer(
canvas_size: egui::Vec2,
input: &egui::plot::GridInput,
) -> Vec<egui::plot::GridMark> {
input: &egui_plot::GridInput,
) -> Vec<egui_plot::GridMark> {
let minimum_medium_line_spacing = 150.0; // ≈min size of a label
let max_medium_lines = canvas_size.x as f64 / minimum_medium_line_spacing;

Expand Down Expand Up @@ -272,7 +272,7 @@ fn ns_grid_spacer(
small_spacing_ns
};

marks.push(egui::plot::GridMark {
marks.push(egui_plot::GridMark {
value: current_ns as f64,
step_size: step_size as f64,
});
Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ eframe = { workspace = true, default-features = false, features = [
"puffin",
"wgpu",
] }
egui.workspace = true
egui_plot.workspace = true
egui-wgpu.workspace = true
egui.workspace = true
image = { workspace = true, default-features = false, features = ["png"] }
itertools = { workspace = true }
once_cell = { workspace = true }
Expand Down
5 changes: 4 additions & 1 deletion crates/re_viewer/src/native.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use re_log_types::LogMsg;

/// Used by `eframe` to decide where to store the app state.
pub const APP_ID: &str = "rerun";

type AppCreator =
Box<dyn FnOnce(&eframe::CreationContext<'_>, re_ui::ReUi) -> Box<dyn eframe::App>>;

Expand All @@ -21,7 +24,7 @@ pub fn run_native_app(app_creator: AppCreator) -> eframe::Result<()> {
pub fn eframe_options() -> eframe::NativeOptions {
eframe::NativeOptions {
// Controls where on disk the app state is persisted.
app_id: Some("rerun_example_rerun".to_owned()),
app_id: Some(APP_ID.to_owned()),

initial_window_size: Some([1600.0, 1200.0].into()),
min_window_size: Some([320.0, 450.0].into()), // Should be high enough to fit the rerun menu
Expand Down
83 changes: 42 additions & 41 deletions crates/re_viewer/src/saving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,50 @@ pub fn default_blueprint_path(app_id: &ApplicationId) -> anyhow::Result<std::pat

use anyhow::Context;

// TODO(jleibs) is there a better way to get this folder from egui?
if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", "rerun") {
let data_dir = proj_dirs.data_dir().join("blueprints");
std::fs::create_dir_all(&data_dir).context("Could not create blueprint save directory.")?;

// We want a unique filename (not a directory) for each app-id.

// First we sanitize to remove disallowed characters
let mut sanitized_app_id = sanitize_app_id(app_id);

// Make sure the filename isn't too long
// This is overly conservative in most cases but some versions of Windows 10
// still have this restriction.
// TODO(jleibs): Determine this value from the environment.
const MAX_PATH: usize = 255;
let directory_part_length = data_dir.as_os_str().len();
let hash_part_length = 16 + 1;
let extension_part_length = ".blueprint".len();
let total_reserved_length =
directory_part_length + hash_part_length + extension_part_length;
if total_reserved_length > MAX_PATH {
anyhow::bail!("Could not form blueprint path: total minimum length exceeds {MAX_PATH} characters.")
}
sanitized_app_id.truncate(MAX_PATH - total_reserved_length);

// If the sanitization actually did something, we no longer have a uniqueness guarantee,
// so insert the hash.
if sanitized_app_id != app_id.0 {
// Hash the original app-id.

let hash = {
let mut hasher = ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher();
app_id.0.hash(&mut hasher);
hasher.finish()
};

sanitized_app_id = format!("{sanitized_app_id}-{hash:x}");
}

Ok(data_dir.join(format!("{sanitized_app_id}.blueprint")))
} else {
let Some(storage_dir) = eframe::storage_dir(crate::native::APP_ID) else {
anyhow::bail!("Error finding project directory for blueprints.")
};

let blueprint_dir = storage_dir.join("blueprints");
std::fs::create_dir_all(&blueprint_dir)
.context("Could not create blueprint save directory.")?;

// We want a unique filename (not a directory) for each app-id.

// First we sanitize to remove disallowed characters
let mut sanitized_app_id = sanitize_app_id(app_id);

// Make sure the filename isn't too long
// This is overly conservative in most cases but some versions of Windows 10
// still have this restriction.
// TODO(jleibs): Determine this value from the environment.
const MAX_PATH: usize = 255;
let directory_part_length = blueprint_dir.as_os_str().len();
let hash_part_length = 16 + 1;
let extension_part_length = ".blueprint".len();
let total_reserved_length = directory_part_length + hash_part_length + extension_part_length;
if total_reserved_length > MAX_PATH {
anyhow::bail!(
"Could not form blueprint path: total minimum length exceeds {MAX_PATH} characters."
)
}
sanitized_app_id.truncate(MAX_PATH - total_reserved_length);

// If the sanitization actually did something, we no longer have a uniqueness guarantee,
// so insert the hash.
if sanitized_app_id != app_id.0 {
// Hash the original app-id.

let hash = {
let mut hasher = ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher();
app_id.0.hash(&mut hasher);
hasher.finish()
};

sanitized_app_id = format!("{sanitized_app_id}-{hash:x}");
}

Ok(blueprint_dir.join(format!("{sanitized_app_id}.blueprint")))
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down
Loading

0 comments on commit d7de7f9

Please sign in to comment.