Feature editor: a section, an analysis or the selection changed while it is open leaves OK and Cancel working (#10687) (#10822)
The editor accepts revision changes that only changed what is shown,
counted by the display revision, but only hiding and showing counted
there. Section Analysis, the surface analyses, continuity, the
selection, the status pill catching up and view.render_select bumped
the revision alone, so turning a section off with an editor open made
OK refuse ("the design changed while the feature editor was open") and
Cancel leave the timeline rolled back. They now go through
refresh_display, as visibility changes do.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a735620aa8
commit
a22ea76ab6
7 files changed
+44
-13
No files matched your search
@@ -1330,7 +1330,7 @@ fn select_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.selection.push(x);
|
||||
}
|
||||
}
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
Ok(json!({"selected": s.selection.len()}))
|
||||
}
|
||||
|
||||
@@ -1387,7 +1387,7 @@ fn select_same_look(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
fn select_clear(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
s.selection.clear();
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
Ok(json!({"selected": 0}))
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ fn section(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if bool_(p, "clear").unwrap_or(false) {
|
||||
s.section = None;
|
||||
s.status_slot(crate::status_items::StatusId::Section, false);
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
return serde_json::to_value(contract::SectionResult { section: None, param_warnings: Vec::new() }).map_err(|e| bad(cmd, e.to_string()));
|
||||
}
|
||||
// A named plane's world axis: which component of a point lies along its normal.
|
||||
@@ -82,7 +82,7 @@ fn section(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.section_hatch = bool_(p, "hatch").unwrap_or(true);
|
||||
s.status_slot(crate::status_items::StatusId::Section, true);
|
||||
s.status_activated(crate::status_items::StatusId::Section);
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
let section = contract::Section {
|
||||
origin: [origin.x, origin.y, origin.z],
|
||||
normal: [normal.x, normal.y, normal.z],
|
||||
|
||||
@@ -91,7 +91,7 @@ fn set(s: &mut Session, p: &Value, a: SurfaceAnalysis) -> Result<Value> {
|
||||
s.analysis = Some(a);
|
||||
}
|
||||
s.status_analysis_changed((!bool_(p, "clear").unwrap_or(false)).then_some(crate::status_items::StatusId::SurfaceAnalysis));
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
let vector = |v: Vec3| [v.x, v.y, v.z];
|
||||
let analysis = s.analysis.map(|a| match a {
|
||||
SurfaceAnalysis::Zebra { stripes } => contract::Analysis::Zebra { stripes },
|
||||
@@ -155,7 +155,7 @@ fn continuity(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if bool_(p, "clear").unwrap_or(false) {
|
||||
s.continuity.clear();
|
||||
s.status_analysis_changed(None);
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
return serde_json::to_value(contract::ContinuityResult::Cleared {
|
||||
analysis: "continuity".into(),
|
||||
cleared: true,
|
||||
@@ -273,7 +273,7 @@ fn continuity(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.continuity = seams;
|
||||
}
|
||||
s.status_analysis_changed(Some(crate::status_items::StatusId::Continuity));
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
serde_json::to_value(contract::ContinuityResult::Measured {
|
||||
analysis: "continuity".into(),
|
||||
samples,
|
||||
|
||||
@@ -315,7 +315,7 @@ fn render_select(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let result = serde_json::to_value(request).map_err(|e| bad("view.render_select", e.to_string()))?;
|
||||
if !s.selection.is_empty() {
|
||||
s.selection.clear();
|
||||
s.revision += 1;
|
||||
s.refresh_display();
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -149,6 +149,35 @@ fn editor_visibility_changes_allow_apply_and_preserve_separate_undo_steps() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A section, an analysis or the selection changed while an editor is open changes only what is
|
||||
/// shown: OK still applies the edit and Cancel puts the design back (#10687).
|
||||
#[test]
|
||||
fn editor_display_changes_allow_apply_and_cancel() {
|
||||
let cases: [&[(&str, serde_json::Value)]; 5] = [
|
||||
&[("inspect.section", json!({"plane":"XZ","offset":1}))],
|
||||
&[("inspect.section", json!({"plane":"XZ","offset":1})), ("inspect.section", json!({"clear":true}))],
|
||||
&[("inspect.zebra", json!({"stripes":14.5}))],
|
||||
&[("select.set", json!({"items":[{"type":"body","name":"Other"}]}))],
|
||||
&[("select.clear", json!({}))],
|
||||
];
|
||||
for display in cases {
|
||||
let (mut session, source, original, commands) = extrusion_editor();
|
||||
for (id, params) in display {
|
||||
session.execute(id, params).unwrap();
|
||||
}
|
||||
let prepared =
|
||||
session.scratch().compute_editor_commands(&commands, &source, original).unwrap_or_else(|e| panic!("OK after {display:?}: {e}"));
|
||||
session.accept_commands(prepared).unwrap();
|
||||
assert_editor_volume(&mut session, 12024.0);
|
||||
let (mut session, source, original, _) = extrusion_editor();
|
||||
for (id, params) in display {
|
||||
session.execute(id, params).unwrap();
|
||||
}
|
||||
session.restore_editor(&source, original).unwrap_or_else(|e| panic!("Cancel after {display:?}: {e}"));
|
||||
assert_editor_volume(&mut session, 6024.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_visibility_changes_allow_cancel_and_keep_undo_and_redo_at_the_original_marker() {
|
||||
for undo_hide in [false, true] {
|
||||
|
||||
@@ -463,8 +463,9 @@ pub struct Session {
|
||||
pub log: Vec<String>,
|
||||
/// Increments on every document change (views use it to refresh).
|
||||
pub revision: u64,
|
||||
/// Revision increments caused only by visibility. Comparing both counters proves that
|
||||
/// every intervening increment left an editor's document and model untouched.
|
||||
/// Revision increments caused only by what is shown ([`Session::refresh_display`]).
|
||||
/// Comparing both counters proves that every intervening increment left an editor's
|
||||
/// document and model untouched.
|
||||
visibility_revision: u64,
|
||||
/// [`Document::browser_stamp`] when the browser's groups and order were last checked.
|
||||
browser_stamp: [u64; 6],
|
||||
@@ -1339,8 +1340,9 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
/// Only what is hidden or shown changed: the model is untouched, so only the view revision
|
||||
/// moves (the visibility caches are keyed on it) and the viewport redraws.
|
||||
/// Only what is shown changed (hidden or shown items, a section or analysis, the selection):
|
||||
/// the design and model are untouched, so only the view revision moves and the viewport
|
||||
/// redraws. An open feature editor stays valid across it (#10687).
|
||||
pub(crate) fn refresh_display(&mut self) {
|
||||
self.revision += 1;
|
||||
self.visibility_revision += 1;
|
||||
|
||||
@@ -144,7 +144,7 @@ impl Session {
|
||||
self.status_slot(id, active);
|
||||
}
|
||||
if self.status_items() != before {
|
||||
self.revision += 1;
|
||||
self.refresh_display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user