mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-06 14:04:27 -05:00
* AutoLISP: entnext reaches an INSERT's ATTRIBs and SEQEND (#1660) - lisp: name an INSERT's ATTRIB and SEQEND records; entnext walks them, then the next main entity, and entget lists a record with its owner in group -2 (#1660) - lisp: entmod of an ATTRIB takes its value (group 1) only, as one undo step; another property, a SEQEND, entdel and entmake of one return nil and change nothing (#1660) - doc: the handles LISP named, shared with the drawing's snapshots and never given out by new_handle; 65,536 names, 1,024 probes past taken handles (#1660) - io: entity_sub_record, one record of an INSERT at a time, never its other records (#1660) - engine: an optional host hook for that record, so EntityCodec is unchanged (#1660) - cli, web, app: install the hook; CLI tests for the walk, the value edit, the name bounds and the refusals (#1660) - docs: autolisp.md on the records, their names, when a name ends, and the value-only edit (#1660) - reused from #1753 (closed), with thanks: the entity_list extraction with the -2 owner, the writer's record splitting, and the entnext_walks_an_inserts_attribs test skeleton * Keep AutoLISP's attribute names within their drawing - Hold an INSERT's attribute names in the session's LISP state, not in cadcraft_doc::Drawing: comparing drawings is plain data again and takes no lock. The session reserves the handles in the drawing before any change, so new_handle still never gives one out, also after a drawing swap. - End the names when the Block Editor closes: its drawing starts from the host's handles, so a name given there must never resolve to a host record. - End only the erased reference's names on ERASE. Erasing another object leaves an attribute name holding, and OOPS still revives none. - Go on to the next entity when an INSERT has no record provider installed. - Refuse an ATTRIB edit whose outer list ends in an atom. * Keep issued attribute names out of the drawing. A copied drawing could reuse a name, and storing the names in the drawing marked a saved drawing changed. * Name an INSERT's ATTRIBs and SEQEND apart from drawing handles An ATTRIB or SEQEND has no handle of its own in the drawing, so the name AutoLISP gives it is now a value of its own (an entity name for `type`), numbered from one count for the whole process that never gives a number twice. No handle of any drawing, of a copy of one, of another session or of another thread can be such a name, so nothing is reserved in the handle space any more: cadcraft-doc, `new_handle` and the copy-then-install paths are as on main, and naming or reading a record changes neither the drawing nor its saved state. What a name stands for (reference, place, tag) stays in the engine's LISP state, by document. Names end on Undo, Redo, ATTSYNC, -BLOCKREPLACE, on opening and closing the Block Editor, and when a change is taken back; erasing a reference ends only its names, and OOPS or `entdel` bringing it back revives none. `entupd` of a record answers its name; selection sets and `command` take no record. Tests cover other sessions, documents and threads giving out handles in a drawing copy, the copy paths (INSERT from a file, XATTACH, AUDIT, REFCLOSE), and the AutoLISP behaviour of the names. * Keep one ATTDEF index per state of a block's entities EntityStore gets a content token: a clone has its store's, and every edit gives the store one that no store has had. The DXF writer keys its ATTDEF index on that token and keeps the indexes of several blocks, up to a fixed number of tags in all. Two copies edited apart, or a different edit after Undo, never read each other's definition properties, in AutoLISP reads or in a saved file, and reads that alternate between references of different blocks examine each definition once. * End record names when a command puts an earlier drawing back. MOCORO Undo restored its history drawing, handle seed included, so the next Copy could reuse the removed reference's handle. That restore now advances the name epoch. An ATTDEF index that would pass the tag budget is not stored. * Match an oversized ATTDEF definition in full and remember it is too large to index * Count record names with try_update, not the deprecated fetch_update Rust 1.100 deprecates fetch_update and names try_update in its place, so clippy with -D warnings stopped the gate at RecordName::fresh. It is the same operation: the checked increment and the None once the count runs out are unchanged. try_update compiles on Rust 1.95, the workspace's minimum. Co-Authored-By: Claude Fable 5.2 <[email protected]> * Record tests check the objects they rely on Five tests could pass without the state they are about. The two ATTDEF index tests changed only a layer, so both states of the block gave T the same handle, and an index kept for the wrong state still read the right layer. One state now keeps T on the first ATTDEF and the other passes T to the second, on another layer. With one index shared by every store, the old tests passed and these fail. The MOCORO and grip Copy tests did not check that a copy was made, or that the copy after the Undo took the removed copy's handle. They now check both, and that the name read the first copy before the Undo. The walk at the top of the handle range compared two values that are both nil when the line at FFFFFFFFFFFFFFFF is not in the drawing. It now reads that line first. Co-Authored-By: Claude Fable 5.2 <[email protected]> * Test that entdel preserves unrelated ATTRIB names * Fix AutoLISP record lifetime and REFEDIT edits * Run attribute name cases in engine integration suite * Fix text fixtures after main merge --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
407 lines
18 KiB
Rust
407 lines
18 KiB
Rust
//! An INSERT's ATTRIBs and SEQEND reached from AutoLISP through the CLI (`entnext`, `entget`,
|
|
//! `entmod`, `entdel`): the walk, a value edit (one Undo step), names that stop holding (erase,
|
|
//! ATTSYNC, Undo, a reinsert that reuses the parent handle), edits that are refused, and the
|
|
//! name bounds.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::{Command, Output};
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
/// A scratch directory, removed on drop also when an assertion fails.
|
|
struct Dir(PathBuf);
|
|
|
|
impl Dir {
|
|
fn new(tag: &str) -> Dir {
|
|
let p = std::env::temp_dir().join(format!("cc-cli-attribs-{tag}-{}", std::process::id()));
|
|
let _ = std::fs::remove_dir_all(&p);
|
|
std::fs::create_dir_all(&p).expect("create scratch dir");
|
|
Dir(p)
|
|
}
|
|
|
|
fn path(&self, name: &str) -> PathBuf {
|
|
self.0.join(name)
|
|
}
|
|
}
|
|
|
|
impl Drop for Dir {
|
|
fn drop(&mut self) {
|
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
}
|
|
}
|
|
|
|
/// One `cadcraft-cli run`: a fresh profile, an optional drawing to open, and the steps to run.
|
|
struct Run {
|
|
args: Vec<String>,
|
|
}
|
|
|
|
impl Run {
|
|
fn new(dir: &Dir, file: Option<&Path>) -> Run {
|
|
let mut args: Vec<String> = vec!["run".into(), "--config-dir".into(), dir.path("profile").to_string_lossy().into_owned()];
|
|
match file {
|
|
Some(f) => args.push(f.to_string_lossy().into_owned()),
|
|
None => args.push("--metric".into()),
|
|
}
|
|
Run { args }
|
|
}
|
|
|
|
fn cmd(&mut self, id: &str, params: Value) -> &mut Run {
|
|
self.args.push("--cmd".into());
|
|
self.args.push(format!("{id} {params}"));
|
|
self
|
|
}
|
|
|
|
fn lisp(&mut self, code: &str) -> &mut Run {
|
|
self.cmd("lisp", json!({ "code": code }))
|
|
}
|
|
|
|
fn save(&mut self, path: &Path) -> &mut Run {
|
|
self.args.push("--save".into());
|
|
self.args.push(path.to_string_lossy().into_owned());
|
|
self
|
|
}
|
|
|
|
fn output(&self) -> Output {
|
|
Command::new(env!("CARGO_BIN_EXE_cadcraft-cli")).args(&self.args).output().expect("run cadcraft-cli")
|
|
}
|
|
|
|
/// Run it: the value each `lisp` step returned, in order (commands' own results are left out).
|
|
fn out(&self) -> Vec<Value> {
|
|
let out = self.output();
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(out.status.success(), "{}: {}", self.args.join(" "), err);
|
|
let text = String::from_utf8_lossy(&out.stdout);
|
|
text.lines()
|
|
.map(|l| serde_json::from_str::<Value>(l).unwrap_or_else(|e| panic!("not a result: {l}: {e}")))
|
|
.filter(|v| v.get("value").is_some())
|
|
.collect()
|
|
}
|
|
}
|
|
|
|
/// The value a `lisp` step returned, as AutoLISP's `prin1` shows it.
|
|
fn value(results: &[Value], i: usize) -> String {
|
|
match results.get(i).and_then(|r| r.get("value")) {
|
|
Some(Value::String(s)) => s.clone(),
|
|
other => panic!("step {i}: no value: {other:?} in {results:?}"),
|
|
}
|
|
}
|
|
|
|
/// `value` without the quotes `prin1` puts round a string.
|
|
fn text(results: &[Value], i: usize) -> String {
|
|
value(results, i).trim_matches('"').to_string()
|
|
}
|
|
|
|
/// TAGBLK.dxf: block TAGBLK with a circle and four attribute definitions (TAG1 D1, TAG2 D2
|
|
/// verify, TAG3 P3 preset, TAG4 C4 constant). Opening the file again gives the drawing fresh
|
|
/// names.
|
|
const FIXTURE: &str = r#"(progn
|
|
(entmake '((0 . "BLOCK") (2 . "TAGBLK") (70 . 2) (10 0.0 0.0 0.0)))
|
|
(entmake '((0 . "CIRCLE") (10 -5.0 0.0 0.0) (40 . 2.0)))
|
|
(entmake '((0 . "ATTDEF") (10 0.0 0.0 0.0) (40 . 2.5) (1 . "D1") (3 . "P1") (2 . "TAG1") (70 . 0)))
|
|
(entmake '((0 . "ATTDEF") (10 0.0 5.0 0.0) (40 . 2.5) (1 . "D2") (3 . "P2") (2 . "TAG2") (70 . 4)))
|
|
(entmake '((0 . "ATTDEF") (10 0.0 10.0 0.0) (40 . 2.5) (1 . "P3") (3 . "P3") (2 . "TAG3") (70 . 8)))
|
|
(entmake '((0 . "ATTDEF") (10 0.0 15.0 0.0) (40 . 2.5) (1 . "C4") (3 . "P4") (2 . "TAG4") (70 . 2)))
|
|
(entmake '((0 . "ENDBLK"))))"#;
|
|
|
|
/// The first reference: INSERT TAGBLK at (10,10) with TAG1 "A1", TAG2 verified as "B1" and
|
|
/// TAG3 preset ("P3"); TAG4 is constant, so it is not asked.
|
|
const INSERT: &str = r#"(command "_.-INSERT" "TAGBLK" '(10 10) 1 1 0 "A1" "B1" "")"#;
|
|
|
|
fn fixture(dir: &Dir) -> PathBuf {
|
|
let file = dir.path("TAGBLK.dxf");
|
|
let mut run = Run::new(dir, None);
|
|
let out = run.lisp(FIXTURE).save(&file).out();
|
|
assert_eq!(text(&out, 0), "TAGBLK");
|
|
file
|
|
}
|
|
|
|
/// The walk from the entity named `i`: its records' tags and values, then the type of the record
|
|
/// that ends the run.
|
|
const WALK: &str = r#"(progn
|
|
(setq e (entnext i) n 0 ts nil ed nil)
|
|
(while (and e (= "ATTRIB" (cdr (assoc 0 (setq ed (entget e))))))
|
|
(setq ts (append ts (list (cdr (assoc 2 ed)) (cdr (assoc 1 ed)))) n (1+ n) e (entnext e)))
|
|
(list n ts (cdr (assoc 0 ed))))"#;
|
|
|
|
#[test]
|
|
fn the_walk_reaches_each_attrib_and_ends_at_the_seqend() {
|
|
let dir = Dir::new("walk");
|
|
let file = fixture(&dir);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(
|
|
r#"(progn
|
|
{INSERT}
|
|
(setq i (entlast))
|
|
(setvar "ATTREQ" 0)
|
|
(command "_.-INSERT" "TAGBLK" '(60 10) 1 1 0)
|
|
(setvar "ATTREQ" 1)
|
|
(setq second (entlast))
|
|
"inserted")"#
|
|
))
|
|
// Three attributes, then the SEQEND owned by the reference, then the next main entity.
|
|
.lisp(&format!(
|
|
r#"(progn {WALK}
|
|
(list n ts (cdr (assoc 0 ed)) (equal (cdr (assoc -2 ed)) i) (equal (entnext e) second) (cdr (assoc 0 (entget (entnext e))))))"#
|
|
))
|
|
// The second reference (no attribute answers, ATTREQ 0) took the definitions' values; its
|
|
// own run ends at its SEQEND, with nothing drawn after it.
|
|
.lisp(&format!(
|
|
r#"(progn (setq i second) {WALK}
|
|
(list n ts (cdr (assoc 0 ed)) (equal (cdr (assoc -2 ed)) i) (entnext e)))"#
|
|
))
|
|
.out();
|
|
assert_eq!(text(&out, 0), "inserted");
|
|
assert_eq!(value(&out, 1), "(3 (\"TAG1\" \"A1\" \"TAG2\" \"B1\" \"TAG3\" \"P3\") \"SEQEND\" T T \"INSERT\")");
|
|
// Its record ends with its own SEQEND, and nothing is drawn after the reference.
|
|
assert_eq!(value(&out, 2), "(3 (\"TAG1\" \"D1\" \"TAG2\" \"D2\" \"TAG3\" \"P3\") \"SEQEND\" T nil)");
|
|
}
|
|
|
|
#[test]
|
|
fn a_value_edit_changes_group_one_only_and_is_one_undo_step() {
|
|
let dir = Dir::new("value");
|
|
let file = fixture(&dir);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(r#"(progn {INSERT} (setq i (entlast) a (entnext i)) (list (cdr (assoc 2 (entget a))) (cdr (assoc 1 (entget a)))))"#))
|
|
.lisp(
|
|
r#"(progn
|
|
(setq d (entget a) r (entmod (subst (cons 1 "A2") (assoc 1 d) d)))
|
|
(list (cdr (assoc 0 r)) (cdr (assoc 1 r)) (cdr (assoc 1 (entget a))) (cdr (assoc 2 (entget a)))
|
|
(cdr (assoc 40 (entget a))) (cdr (assoc 8 (entget a))) (equal (cdr (assoc -2 (entget a))) i)))"#,
|
|
)
|
|
.cmd("undo", json!({ "count": 1 }))
|
|
// The edit is one Undo step: the value is back, and the name given before it holds no
|
|
// longer (the drawing it was given in was restored from another state).
|
|
.lisp(
|
|
r#"(list (entget a) (progn (setq e (entnext (entlast)))
|
|
(list (cdr (assoc 2 (entget e))) (cdr (assoc 1 (entget e))))))"#,
|
|
)
|
|
.out();
|
|
assert_eq!(value(&out, 0), "(\"TAG1\" \"A1\")");
|
|
assert_eq!(value(&out, 1), "(\"ATTRIB\" \"A2\" \"A2\" \"TAG1\" 2.5 \"0\" T)");
|
|
assert_eq!(value(&out, 2), "(nil (\"TAG1\" \"A1\"))");
|
|
// Redo brings the edit back; the name given before the Undo still names nothing.
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(r#"(progn {INSERT} (setq i (entlast) a (entnext i) d (entget a)) (entmod (subst (cons 1 "A2") (assoc 1 d) d)))"#))
|
|
.cmd("undo", json!({ "count": 1 }))
|
|
.cmd("redo", json!({ "count": 1 }))
|
|
.lisp("(list (entget a) (cdr (assoc 1 (entget (entnext (entlast))))))")
|
|
.out();
|
|
assert_eq!(value(&out, 1), "(nil \"A2\")");
|
|
}
|
|
|
|
#[test]
|
|
fn a_name_stops_holding_after_erase_attsync_and_undo() {
|
|
let dir = Dir::new("stale");
|
|
let file = fixture(&dir);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run.lisp(&format!(r#"(progn {INSERT} (setq i (entlast)) (cdr (assoc 5 (entget i))))"#)).out();
|
|
let handle = text(&out, 0);
|
|
|
|
// Erased: the reference's records are gone with it, and the name names nothing.
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(r#"(progn {INSERT} (setq i (entlast) a (entnext i)) (cdr (assoc 2 (entget a))))"#))
|
|
.cmd("erase", json!({ "handles": [handle] }))
|
|
.lisp("(list (entget a) (entnext a))")
|
|
// Undone: the reference is back, but a name given before the Undo does not come back with
|
|
// it: a walk gives its records new ones.
|
|
.cmd("undo", json!({ "count": 1 }))
|
|
.lisp("(list (entget a) (cdr (assoc 1 (entget (entnext (entlast))))))")
|
|
// ATTSYNC rebuilds the reference's attributes: the name given before names nothing, and
|
|
// the rebuilt attribute keeps the value.
|
|
.lisp("(progn (setq b (entnext (entlast))) (cdr (assoc 2 (entget b))))")
|
|
.cmd("attsync", json!({ "name": "TAGBLK" }))
|
|
.lisp("(list (entget b) (cdr (assoc 1 (entget (entnext (entlast))))))")
|
|
.out();
|
|
assert_eq!(value(&out, 0), "\"TAG1\"");
|
|
assert_eq!(value(&out, 1), "(nil nil)");
|
|
assert_eq!(value(&out, 2), "(nil \"A1\")");
|
|
assert_eq!(value(&out, 3), "\"TAG1\"");
|
|
assert_eq!(value(&out, 4), "(nil \"A1\")");
|
|
|
|
// A reinsert after an Undo takes the parent handle back: the old name must not name its
|
|
// attribute.
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(r#"(progn {INSERT} (setq i (entlast) a (entnext i)) (list (cdr (assoc 5 (entget i))) (cdr (assoc 2 (entget a)))))"#))
|
|
.cmd("undo", json!({ "count": 1 }))
|
|
.lisp(&format!(r#"(progn {INSERT} (list (cdr (assoc 5 (entget (entlast)))) (entget a)))"#))
|
|
.lisp("(list (cdr (assoc 2 (entget (entnext (entlast))))) (cdr (assoc 1 (entget (entnext (entlast))))))")
|
|
.out();
|
|
assert_eq!(text(&out, 0), format!("(\"{handle}\" \"TAG1\")"));
|
|
// The same handle, and the old name names nothing in the new reference.
|
|
assert_eq!(value(&out, 1), format!("(\"{handle}\" nil)"));
|
|
assert_eq!(value(&out, 2), "(\"TAG1\" \"A1\")");
|
|
}
|
|
|
|
#[test]
|
|
fn an_edit_of_anything_but_the_value_is_refused() {
|
|
let dir = Dir::new("refused");
|
|
let file = fixture(&dir);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(
|
|
r#"(progn {INSERT} (setq i (entlast) a (entnext i) s (entnext (entnext (entnext a))) p0 (cdr (assoc 10 (entget a)))) "named")"#
|
|
))
|
|
.lisp(
|
|
r#"(progn
|
|
(setq d (entget a))
|
|
(list
|
|
(entmod (subst (cons 2 "TAGX") (assoc 2 d) d))
|
|
(entmod (subst (cons 40 9.0) (assoc 40 d) d))
|
|
(entmod (subst (cons 0 "SEQEND") (assoc 0 d) d))
|
|
(entmod (entget s))
|
|
(entmod (subst (cons 410 "Layout2") (assoc 410 d) d))
|
|
(entmod (subst (cons 1 "A2") (assoc 1 d) (subst (cons 410 "Layout2") (assoc 410 d) d)))
|
|
(entdel a) (entdel s)))"#,
|
|
)
|
|
// Nothing changed: the same tag, value, height and place, and the name still holds.
|
|
.lisp(
|
|
r#"(progn (setq e (entnext (entlast)) d (entget e))
|
|
(list (cdr (assoc 2 d)) (cdr (assoc 1 d)) (cdr (assoc 40 d)) (equal p0 (cdr (assoc 10 d))) (equal (entget a) d)))"#,
|
|
)
|
|
.out();
|
|
assert_eq!(text(&out, 0), "named");
|
|
assert_eq!(value(&out, 1), "(nil nil nil nil nil nil nil nil)");
|
|
assert_eq!(value(&out, 2), "(\"TAG1\" \"A1\" 2.5 T T)");
|
|
}
|
|
|
|
/// A minimal drawing: `before` (records written as they are), then an INSERT with `attribs`
|
|
/// ATTRIBs (each tag T, value V) and its SEQEND, last in the file. A header `$HANDSEED` is
|
|
/// written when `handseed` is given (a hostile file can name any next handle).
|
|
fn insert_dxf_seed(attribs: usize, before: &str, handseed: Option<&str>) -> String {
|
|
let mut s = String::with_capacity(before.len().saturating_add(attribs.saturating_mul(96)));
|
|
if let Some(seed) = handseed {
|
|
s.push_str("0\nSECTION\n2\nHEADER\n9\n$HANDSEED\n5\n");
|
|
s.push_str(seed);
|
|
s.push('\n');
|
|
s.push_str("0\nENDSEC\n");
|
|
}
|
|
s.push_str("0\nSECTION\n2\nENTITIES\n");
|
|
s.push_str(before);
|
|
s.push_str("0\nINSERT\n5\n20\n8\n0\n66\n1\n2\nTAGBLK\n10\n0\n20\n0\n30\n0\n");
|
|
for _ in 0..attribs {
|
|
s.push_str("0\nATTRIB\n5\n21\n8\n0\n10\n0\n20\n0\n30\n0\n40\n1\n1\nV\n2\nT\n70\n0\n");
|
|
}
|
|
s.push_str("0\nSEQEND\n5\n22\n0\nENDSEC\n0\nEOF\n");
|
|
s
|
|
}
|
|
|
|
fn insert_dxf(attribs: usize, before: &str) -> String {
|
|
insert_dxf_seed(attribs, before, None)
|
|
}
|
|
|
|
/// The number of records a walk from `i` reaches, counting each `entnext`.
|
|
const COUNT: &str = r#"(progn (setq e (entnext i) n 0) (while e (setq n (1+ n) e (entnext e))) n)"#;
|
|
|
|
#[test]
|
|
fn a_walk_is_stable_and_its_names_are_no_handles() {
|
|
let dir = Dir::new("stable");
|
|
// A file's line one below the top of the handle range: it keeps its handle, and the
|
|
// records' names, which are no handles, never name it.
|
|
let before = "0\nLINE\n5\nFFFFFFFFFFFFFFFE\n8\n0\n10\n0\n20\n0\n30\n0\n11\n5\n21\n5\n31\n0\n";
|
|
let file = dir.path("hostile.dxf");
|
|
std::fs::write(&file, insert_dxf(2, before)).expect("write the DXF");
|
|
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(
|
|
r#"(progn
|
|
(setq i (handent "20") line (handent "FFFFFFFFFFFFFFFE") a (entnext i) b (entnext i))
|
|
(list (cdr (assoc 5 (entget line))) (equal (handent "FFFFFFFFFFFFFFFE") line)
|
|
(not (equal a line)) (cdr (assoc 0 (entget a))) (equal a b) (equal (entnext a) (entnext b))))"#,
|
|
)
|
|
.lisp(&format!(r#"(progn (setq i (handent "20")) {COUNT})"#))
|
|
.out();
|
|
assert_eq!(value(&out, 0), "(\"FFFFFFFFFFFFFFFE\" T T \"ATTRIB\" T T)");
|
|
// Two ATTRIBs and the SEQEND, then the line (it sorts last by its handle), then the end.
|
|
assert_eq!(value(&out, 1), "4");
|
|
}
|
|
|
|
#[test]
|
|
fn a_restored_reference_does_not_revive_an_old_name() {
|
|
let dir = Dir::new("restored");
|
|
let file = fixture(&dir);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(
|
|
r#"(progn {INSERT} (setq i (entlast) a (entnext i))
|
|
(entdel i)
|
|
(setq gone (entget a))
|
|
(entdel i)
|
|
(list gone (entget a) (cdr (assoc 1 (entget (entnext i))))))"#
|
|
))
|
|
.out();
|
|
assert_eq!(value(&out, 0), "(nil nil \"A1\")", "the reference comes back, the old name does not");
|
|
|
|
// ERASE, then OOPS: the same. The old name never comes back with the reference.
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let handle = text(&run.lisp(&format!(r#"(progn {INSERT} (cdr (assoc 5 (entget (entlast)))))"#)).out(), 0);
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(&format!(r#"(progn {INSERT} (setq a (entnext (entlast))) "named")"#))
|
|
.cmd("erase", json!({ "handles": [handle] }))
|
|
.cmd("oops", json!({}))
|
|
.lisp("(list (entget a) (cdr (assoc 1 (entget (entnext (entlast))))))")
|
|
.out();
|
|
assert_eq!(value(&out, 1), "(nil \"A1\")", "OOPS restores the reference, not the old name");
|
|
}
|
|
|
|
#[test]
|
|
fn a_new_line_is_never_a_record() {
|
|
let dir = Dir::new("handseed");
|
|
let file = dir.path("hostile.dxf");
|
|
// A file's $HANDSEED in the reserved band is the file's own handle and is not followed (#913),
|
|
// so the line made after the walk gets the drawing's seed. The record's name is no handle:
|
|
// the line is the line, and the name still names the attribute. The engine's
|
|
// `a_new_object_at_any_handle_is_never_a_record` puts the seed at the top of the range.
|
|
std::fs::write(&file, insert_dxf_seed(1, "", Some("FFFFFFFFFFFFFFFF"))).expect("write the DXF");
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(r#"(progn (setq i (handent "20") a (entnext i)) (list (cdr (assoc 0 (entget a))) (cdr (assoc 5 (entget (entlast))))))"#)
|
|
.lisp(r#"(progn (entmake '((0 . "LINE") (10 0.0 0.0 0.0) (11 1.0 0.0 0.0))) (cdr (assoc 5 (entget (entlast)))))"#)
|
|
.lisp(r#"(list (cdr (assoc 0 (entget a))) (entdel a))"#)
|
|
.out();
|
|
assert_eq!(value(&out, 0), "(\"ATTRIB\" \"20\")");
|
|
assert_eq!(value(&out, 1), "\"100\"");
|
|
assert_eq!(value(&out, 2), "(\"ATTRIB\" nil)");
|
|
}
|
|
|
|
#[test]
|
|
fn lines_at_the_top_of_the_handle_range_walk_as_lines() {
|
|
let dir = Dir::new("walkrange");
|
|
let file = dir.path("hostile.dxf");
|
|
let before = "0\nLINE\n5\nFFFFFFFFFFFFFFFE\n8\n0\n10\n0\n20\n0\n30\n0\n11\n5\n21\n5\n31\n0\n\
|
|
0\nLINE\n5\nFFFFFFFFFFFFFFFF\n8\n0\n10\n0\n20\n0\n30\n0\n11\n6\n21\n6\n31\n0\n";
|
|
std::fs::write(&file, insert_dxf_seed(1, before, Some("FFFFFFFFFFFFFFFF"))).expect("write the DXF");
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run
|
|
.lisp(r#"(progn (setq i (handent "20")) (entnext i))"#)
|
|
// The line at the top of the range is in the drawing. Without it, the walk from the line
|
|
// below would end in nil, and nil equals the nil `handent` gives for a handle not there.
|
|
.lisp(r#"(progn (setq top (handent "FFFFFFFFFFFFFFFF")) (list (cdr (assoc 0 (entget top))) (cdr (assoc 5 (entget top)))))"#)
|
|
.lisp(r#"(equal (entnext (handent "FFFFFFFFFFFFFFFE")) top)"#)
|
|
.lisp("(entnext top)")
|
|
.out();
|
|
assert_eq!(value(&out, 1), "(\"LINE\" \"FFFFFFFFFFFFFFFF\")");
|
|
assert_eq!(value(&out, 2), "T");
|
|
assert_eq!(value(&out, 3), "nil");
|
|
}
|
|
|
|
#[test]
|
|
fn the_session_names_at_most_65536_records() {
|
|
let dir = Dir::new("names");
|
|
let file = dir.path("many.dxf");
|
|
// One more attribute than the limit of names: the walk stops at the limit, and nothing in the
|
|
// drawing changed.
|
|
std::fs::write(&file, insert_dxf(65_537, "")).expect("write the DXF");
|
|
let mut run = Run::new(&dir, Some(&file));
|
|
let out = run.lisp(&format!("(progn (setq i (entlast)) {COUNT})")).lisp(&format!("(progn (setq i (entlast)) {COUNT})")).out();
|
|
assert_eq!(value(&out, 0), "65536");
|
|
// The names given by the first walk hold: the second walk is the same.
|
|
assert_eq!(value(&out, 1), "65536");
|
|
}
|