* claim: #1134 * doc: key pattern/mirror seeds and construction planes by feature id (#1134) * engine: resolve seed names the way evaluation did; keep timeline.edit name input (#1134) * fmt/clippy cleanups (#1134) * ui: resolve construction-plane names by feature id in plane_description (#1134) * fmt: sketch_attachment_ui after rebase adaptation * engine: timeline.add resolves legacy name-keyed seeds and plane names (#1134) * chore: re-trigger CI (GPU runner timeout flake) * doc: replayed_sources walks id-keyed pattern seeds (rebase adaptation) --------- Co-authored-by: Dahak Builds <dahakbuilds@users.noreply.github.com>
This commit is contained in:
@@ -35,7 +35,9 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
.get("feature")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or_else(|| bad(cmd, "`feature` must be a feature object, as a design file or timeline.inspect has it"))?;
|
||||
let feature = recorded_feature(cmd, raw)?;
|
||||
let mut raw = raw.clone();
|
||||
resolve_legacy_names(&mut raw, &s.doc);
|
||||
let feature = recorded_feature(cmd, &raw)?;
|
||||
let params = step_params(cmd, p.get("params"))?;
|
||||
let id = s.doc_mut().insert_feature(feature, params)?;
|
||||
s.refresh();
|
||||
@@ -44,6 +46,58 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"feature": id, "name": name, "error": r.and_then(|r| r.error.clone()), "warning": r.and_then(|r| r.warning.clone())}))
|
||||
}
|
||||
|
||||
/// timeline.add keeps accepting legacy name-keyed pattern and mirror seeds and construction
|
||||
/// plane names (#1134): a script recorded before these references were keyed by id resolves
|
||||
/// them against the design as it stands, exactly the way opening a saved design migrates them
|
||||
/// (`format::pending::feature_id_refs`) — a name that finds no feature keeps id 0, which
|
||||
/// dangles at evaluation with the same warning or error it always gave.
|
||||
fn resolve_legacy_names(raw: &mut Map<String, Value>, doc: &Document) {
|
||||
let kind = raw.get("type").and_then(Value::as_str).unwrap_or("").to_string();
|
||||
// A pattern's or mirror's seeds: each name becomes the feature's id.
|
||||
if matches!(kind.as_str(), "pattern" | "mirror")
|
||||
&& let Some(Value::Array(seeds)) = raw.get_mut("features")
|
||||
{
|
||||
for seed in seeds.iter_mut() {
|
||||
if let Value::String(name) = seed {
|
||||
let name = name.clone();
|
||||
*seed = json!(doc.seed_feature(&name).map(|f| f.id).unwrap_or(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Construction plane references, everywhere but a revolve's axis: an
|
||||
// `AxisRef::Construction` has the same shape but names a construction axis, which is
|
||||
// still keyed by name.
|
||||
let skip_axis = matches!(kind.as_str(), "revolve" | "surface_revolve");
|
||||
for (key, v) in raw.iter_mut() {
|
||||
if !(skip_axis && key == "axis") {
|
||||
resolve_plane_refs(v, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Rewrite every `{"type": "construction", "name": …}` plane reference in `v` to carry the
|
||||
/// feature's id, resolved by `Document::find_feature`; nothing is id 0.
|
||||
fn resolve_plane_refs(v: &mut Value, doc: &Document) {
|
||||
match v {
|
||||
Value::Object(o) => {
|
||||
if o.get("type").and_then(Value::as_str) == Some("construction") {
|
||||
if let Some(name) = o.get("name").and_then(Value::as_str) {
|
||||
let name = name.to_string();
|
||||
let id = doc.find_feature(&name).map(|f| f.id).unwrap_or(0);
|
||||
o.remove("name");
|
||||
o.insert("feature".into(), json!(id));
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (_, x) in o.iter_mut() {
|
||||
resolve_plane_refs(x, doc);
|
||||
}
|
||||
}
|
||||
Value::Array(a) => a.iter_mut().for_each(|x| resolve_plane_refs(x, doc)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// The feature, through the checks a design file gets when it opens (numbers, sketch sizes, 3D
|
||||
/// curves, face attachments…), so a script step can hold nothing a design could not.
|
||||
fn recorded_feature(cmd: &str, raw: &Map<String, Value>) -> Result<Feature> {
|
||||
|
||||
Reference in New Issue
Block a user