Skip to content

Commit

Permalink
Prevent save/load cycle from editing blueprint due to auto-values
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jul 1, 2023
1 parent a40df4b commit 2b527c0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
10 changes: 10 additions & 0 deletions crates/re_data_store/src/editable_auto_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ where
self
}
}

/// Determine whether this `EditableAutoValue` has user-edits relative to another `EditableAutoValue`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
match (self, other) {
(EditableAutoValue::UserEdited(s), EditableAutoValue::UserEdited(o)) => s == o,
(EditableAutoValue::Auto(_), EditableAutoValue::Auto(_)) => true,
_ => false,
}
}
}
33 changes: 33 additions & 0 deletions crates/re_data_store/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ impl EntityPropertyMap {
pub fn iter(&self) -> impl Iterator<Item = (&EntityPath, &EntityProperties)> {
self.props.iter()
}

/// Determine whether this `EntityPropertyMap` has user-edits relative to another `EntityPropertyMap`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
self.props
.iter()
.zip(other.props.iter())
.all(|(x, y)| x.0 == y.0 && x.1.unedited(y.1))
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -116,6 +125,30 @@ impl EntityProperties {
.clone(),
}
}

/// Determine whether this `EntityProperty` has user-edits relative to another `EntityProperty`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
let Self {
visible,
visible_history,
interactive,
color_mapper,
pinhole_image_plane_distance,
backproject_depth,
depth_from_world_scale,
backproject_radius_scale,
} = self;

visible == &other.visible
&& visible_history == &other.visible_history
&& interactive == &other.interactive
&& color_mapper.unedited(&other.color_mapper)
&& pinhole_image_plane_distance.unedited(&other.pinhole_image_plane_distance)
&& backproject_depth.unedited(&other.backproject_depth)
&& depth_from_world_scale.unedited(&other.depth_from_world_scale)
&& backproject_radius_scale.unedited(&other.backproject_radius_scale)
}
}

// ----------------------------------------------------------------------------
Expand Down
38 changes: 35 additions & 3 deletions crates/re_space_view/src/data_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use slotmap::SlotMap;
use smallvec::{smallvec, SmallVec};

/// A grouping of several data-blueprints.
#[derive(Clone, Default, PartialEq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
pub struct DataBlueprintGroup {
pub display_name: String,

Expand All @@ -31,9 +31,29 @@ pub struct DataBlueprintGroup {
pub entities: BTreeSet<EntityPath>,
}

// Manually implement `PartialEq` since properties_projected is serde skip
impl PartialEq for DataBlueprintGroup {
fn eq(&self, other: &Self) -> bool {
let Self {
display_name,
properties_individual,
properties_projected: _,
parent,
children,
entities,
} = self;

display_name == &other.display_name
&& properties_individual.unedited(&other.properties_individual)
&& parent == &other.parent
&& children == &other.children
&& entities == &other.entities
}
}

/// Data blueprints for all entity paths in a space view.
#[derive(Clone, Default, PartialEq, serde::Deserialize, serde::Serialize)]
struct DataBlueprints {
#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
pub struct DataBlueprints {
/// Individual settings. Mutate this.
individual: EntityPropertyMap,

Expand All @@ -44,6 +64,18 @@ struct DataBlueprints {
projected: EntityPropertyMap,
}

// Manually implement `PartialEq` since projected is serde skip
impl PartialEq for DataBlueprints {
fn eq(&self, other: &Self) -> bool {
let Self {
individual,
projected: _,
} = self;

individual.unedited(&other.individual)
}
}

/// Tree of all data blueprint groups for a single space view.
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct DataBlueprintTree {
Expand Down

0 comments on commit 2b527c0

Please sign in to comment.