Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python serializable ViewportBlueprint #5385

Merged
merged 8 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/re_data_ui/src/editors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn edit_color_ui(
let [r, g, b, a] = edit_color.to_array();
let new_color = Color::from_unmultiplied_rgba(r, g, b, a);

ctx.save_blueprint_component(override_path, new_color);
ctx.save_blueprint_component(override_path, &new_color);
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ fn edit_text_ui(
if edit_text != current_text {
let new_text = Text::from(edit_text);

ctx.save_blueprint_component(override_path, new_text);
ctx.save_blueprint_component(override_path, &new_text);
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ fn edit_name_ui(
if edit_text != current_text {
let new_text = Name::from(edit_text);

ctx.save_blueprint_component(override_path, new_text);
ctx.save_blueprint_component(override_path, &new_text);
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ fn edit_scatter_ui(
if edit_scatter != current_scatter {
let new_scatter = ScalarScattering::from(edit_scatter);

ctx.save_blueprint_component(override_path, new_scatter);
ctx.save_blueprint_component(override_path, &new_scatter);
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ fn edit_radius_ui(
if edit_radius != current_radius {
let new_radius = Radius::from(edit_radius);

ctx.save_blueprint_component(override_path, new_radius);
ctx.save_blueprint_component(override_path, &new_radius);
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ fn edit_marker_shape_ui(
});

if edit_marker != current_marker {
ctx.save_blueprint_component(override_path, edit_marker);
ctx.save_blueprint_component(override_path, &edit_marker);
}
}

Expand Down Expand Up @@ -352,7 +352,7 @@ fn edit_stroke_width_ui(
if edit_stroke_width != current_stroke_width {
let new_stroke_width = StrokeWidth::from(edit_stroke_width);

ctx.save_blueprint_component(override_path, new_stroke_width);
ctx.save_blueprint_component(override_path, &new_stroke_width);
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ fn edit_marker_size_ui(
if edit_marker_size != current_marker_size {
let new_marker_size = MarkerSize::from(edit_marker_size);

ctx.save_blueprint_component(override_path, new_marker_size);
ctx.save_blueprint_component(override_path, &new_marker_size);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view/src/data_query_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl DataQueryBlueprint {

ctx.save_blueprint_component(
&self.id.as_entity_path(),
QueryExpressions::from(&self.entity_path_filter),
&QueryExpressions::from(&self.entity_path_filter),
);
}

Expand Down Expand Up @@ -175,7 +175,7 @@ impl DataQueryBlueprint {

pub fn clear(&self, ctx: &ViewerContext<'_>) {
let clear = Clear::recursive();
ctx.save_blueprint_component(&self.id.as_entity_path(), clear.is_recursive);
ctx.save_blueprint_component(&self.id.as_entity_path(), &clear.is_recursive);
}

pub fn build_resolver<'a>(
Expand Down
10 changes: 5 additions & 5 deletions crates/re_space_view/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl SpaceViewBlueprint {

pub fn clear(&self, ctx: &ViewerContext<'_>) {
let clear = Clear::recursive();
ctx.save_blueprint_component(&self.entity_path(), clear.is_recursive);
ctx.save_blueprint_component(&self.entity_path(), &clear.is_recursive);

for query in &self.queries {
query.clear(ctx);
Expand All @@ -328,7 +328,7 @@ impl SpaceViewBlueprint {
pub fn set_entity_determined_by_user(&self, ctx: &ViewerContext<'_>) {
if !self.entities_determined_by_user {
let component = EntitiesDeterminedByUser(true);
ctx.save_blueprint_component(&self.entity_path(), component);
ctx.save_blueprint_component(&self.entity_path(), &component);
}
}

Expand All @@ -338,7 +338,7 @@ impl SpaceViewBlueprint {
match name {
Some(name) => {
let component = Name(name.into());
ctx.save_blueprint_component(&self.entity_path(), component);
ctx.save_blueprint_component(&self.entity_path(), &component);
}
None => {
ctx.save_empty_blueprint_component::<Name>(&self.entity_path());
Expand All @@ -351,15 +351,15 @@ impl SpaceViewBlueprint {
pub fn set_origin(&self, ctx: &ViewerContext<'_>, origin: &EntityPath) {
if origin != &self.space_origin {
let component = SpaceViewOrigin(origin.into());
ctx.save_blueprint_component(&self.entity_path(), component);
ctx.save_blueprint_component(&self.entity_path(), &component);
}
}

#[inline]
pub fn set_visible(&self, ctx: &ViewerContext<'_>, visible: bool) {
if visible != self.visible {
let component = Visible(visible);
ctx.save_blueprint_component(&self.entity_path(), component);
ctx.save_blueprint_component(&self.entity_path(), &component);
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn legend_ui(ctx: &ViewerContext<'_>, space_view_id: SpaceViewId, ui: &mut egui:
let mut edit_visibility = visible;
ctx.re_ui.checkbox(ui, &mut edit_visibility.0, "Visible");
if visible != edit_visibility {
ctx.save_blueprint_component(&blueprint_path, edit_visibility);
ctx.save_blueprint_component(&blueprint_path, &edit_visibility);
}

let corner = corner.unwrap_or(DEFAULT_LEGEND_CORNER.into());
Expand Down Expand Up @@ -658,7 +658,7 @@ fn legend_ui(ctx: &ViewerContext<'_>, space_view_id: SpaceViewId, ui: &mut egui:
);
});
if corner != edit_corner {
ctx.save_blueprint_component(&blueprint_path, edit_corner);
ctx.save_blueprint_component(&blueprint_path, &edit_corner);
}
});

Expand Down Expand Up @@ -726,7 +726,7 @@ fn axis_ui(
});

if y_range != Some(range_edit) {
ctx.save_blueprint_component(&blueprint_path, range_edit);
ctx.save_blueprint_component(&blueprint_path, &range_edit);
}
} else if y_range.is_some() {
ctx.save_empty_blueprint_component::<Range1D>(&blueprint_path);
Expand All @@ -751,7 +751,7 @@ fn axis_ui(
"If set, when zooming, the Y axis range will remain locked to the specified range.",
);
if y_lock_zoom != edit_locked {
ctx.save_blueprint_component(&blueprint_path, edit_locked);
ctx.save_blueprint_component(&blueprint_path, &edit_locked);
}
})
});
Expand Down
1 change: 0 additions & 1 deletion crates/re_types/definitions/rerun/blueprint.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ include "./blueprint/components/row_shares.fbs";
include "./blueprint/components/space_view_class.fbs";
include "./blueprint/components/space_view_maximized.fbs";
include "./blueprint/components/space_view_origin.fbs";
include "./blueprint/components/viewport_layout.fbs";
include "./blueprint/components/visible.fbs";
include "./blueprint/components/corner_2d.fbs";
include "./blueprint/components/lock_range_during_zoom.fbs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ table ViewportBlueprint (

// --- Optional ---

/// The layout of the space-views
layout: rerun.blueprint.components.ViewportLayout ("attr.rerun.component_optional", nullable, order: 2000);

/// The layout of the space-views
root_container: rerun.blueprint.components.RootContainer ("attr.rerun.component_optional", nullable, order: 2500);

/// Show one tab as maximized?
maximized: rerun.blueprint.components.SpaceViewMaximized ("attr.rerun.component_optional", nullable, order: 3000);

// TODO(andreas): This is to be removed in the future, all new space views without an explicit container
// should always insert themselves using a heuristic.
/// Whether the viewport layout is determined automatically.
///
/// Set to `false` the first time the user messes around with the viewport blueprint.
/// If `true`, the container layout will be reset whenever a new space view is added or removed.
/// This defaults to `false` and is automatically set to `false` when there is user determined layout.
auto_layout: rerun.blueprint.components.AutoLayout ("attr.rerun.component_optional", nullable, order: 4000);

// TODO(jleibs): This should come with an optional container id that specifies where to insert new space views.
/// Whether or not space views should be created automatically.
auto_space_views: rerun.blueprint.components.AutoSpaceViews ("attr.rerun.component_optional", nullable, order: 5000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace rerun.blueprint.components;
struct AutoLayout (
"attr.arrow.transparent",
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "bool",
"attr.rust.derive": "Copy",
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace rerun.blueprint.components;
struct AutoSpaceViews (
"attr.arrow.transparent",
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "bool",
"attr.rust.derive": "Copy, Default",
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ table IncludedSpaceView (
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent"
) {
space_view_ids: rerun.datatypes.Uuid (order: 100);
space_view_id: rerun.datatypes.Uuid (order: 100);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace rerun.blueprint.components;

/// The container that sits at the root of a viewport.
table RootContainer (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
"attr.rust.override_crate": "re_viewport"
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "npt.NDArray[np.uint8], npt.ArrayLike, Sequence[int], bytes",
"attr.rust.derive": "Default",
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent"
) {
/// `ContainerId` for the root.
id: rerun.datatypes.Uuid (order: 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ namespace rerun.blueprint.components;
///
/// Unstable. Used for the ongoing blueprint experimentations.
table SpaceViewMaximized (
"attr.arrow.transparent",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy, Default, PartialEq, Eq",
"attr.python.aliases": "npt.NDArray[np.uint8], npt.ArrayLike, Sequence[int], bytes",
"attr.rust.derive": "Default",
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct"
"attr.rust.repr": "transparent"
) {
space_view_id: rerun.datatypes.Uuid (order: 100, nullable);
space_view_id: rerun.datatypes.Uuid (order: 100);
}

This file was deleted.

30 changes: 30 additions & 0 deletions crates/re_types_core/src/loggable_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ impl<D: Datatype> DatatypeBatch for D {}

impl<C: Component> ComponentBatch for C {}

// --- Unary Option ---

impl<L: Clone + Loggable> LoggableBatch for Option<L> {
type Name = L::Name;

#[inline]
fn name(&self) -> Self::Name {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.is_some() as usize
}

#[inline]
fn arrow_field(&self) -> arrow2::datatypes::Field {
L::arrow_field()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
}
}

impl<D: Datatype> DatatypeBatch for Option<D> {}

impl<C: Component> ComponentBatch for Option<C> {}

// --- Vec ---

impl<L: Clone + Loggable> LoggableBatch for Vec<L> {
Expand Down
2 changes: 0 additions & 2 deletions crates/re_viewer/src/blueprint/validation_gen/mod.rs

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

4 changes: 2 additions & 2 deletions crates/re_viewer/src/ui/override_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub fn override_visualizer_ui(
.collect::<Vec<_>>(),
);

ctx.save_blueprint_component(override_path, component);
ctx.save_blueprint_component(override_path, &component);
}
});
// Visualizer label
Expand Down Expand Up @@ -462,7 +462,7 @@ pub fn add_new_visualizer(
.collect::<Vec<_>>(),
);

ctx.save_blueprint_component(override_path, component);
ctx.save_blueprint_component(override_path, &component);

ui.close_menu();
}
Expand Down
Loading
Loading