Sketch commands return the ids of the points, curves, constraints and dimensions they create as created: {points, curves, constraints, dimensions}, worked out in Session::execute from the sketch before and after, so a script can dimension and constrain new geometry right away; ids stay stable and are not reused after a delete (undo rewinds the counters with the design). The MCP execute tool describes the field
This commit is contained in:
1 parent
22672585c9
commit
cc22672041
12 files changed
+510
-121
No files matched your search
@@ -351,6 +351,7 @@ impl Session {
|
||||
let changed = !Arc::ptr_eq(&self.doc, &before.doc);
|
||||
match r {
|
||||
Ok(v) => {
|
||||
let v = if changed { self.with_created(spec.id, params, &before, v) } else { v };
|
||||
if changed {
|
||||
if spec.undoable {
|
||||
self.undo.push(before);
|
||||
@@ -374,6 +375,28 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
/// A sketch command's result gets `created`: the ids of the points, curves, constraints and
|
||||
/// dimensions it added to its sketch (the `sketch` param, else the active sketch), so every
|
||||
/// drawing and modify command reports them the same way (see `cmd::sketch_created`).
|
||||
fn with_created(&self, id: &str, params: &Value, before: &Snapshot, mut v: Value) -> Value {
|
||||
if !id.starts_with("sketch.") {
|
||||
return v;
|
||||
}
|
||||
let Some(out) = v.as_object_mut() else { return v };
|
||||
if out.contains_key("created") {
|
||||
return v;
|
||||
}
|
||||
let named = match params.get("sketch") {
|
||||
Some(Value::Number(n)) => self.doc.find_feature(&n.to_string()).map(|f| f.id),
|
||||
Some(Value::String(x)) => self.doc.find_feature(x).map(|f| f.id),
|
||||
_ => None,
|
||||
};
|
||||
let Some(sk) = named.or(self.active_sketch).or(before.active_sketch) else { return v };
|
||||
let Ok(after) = self.doc.sketch(sk) else { return v };
|
||||
out.insert("created".into(), cmd::sketch_created(before.doc.sketch(sk).ok(), after));
|
||||
v
|
||||
}
|
||||
|
||||
/// Remember the design, active sketch and undo history; returns the checkpoint's id.
|
||||
pub fn checkpoint(&mut self) -> u64 {
|
||||
let id = self.next_checkpoint;
|
||||
|
||||
Reference in new issue
Block a user