Xref attach: placement preview, relative paths on the first save, no-match messages

The reference follows the cursor while its insertion point, scale or
rotation is asked (preview-only PScale/PX/PY/PZ/PRotate included); a
relative path chosen before the drawing had a file becomes relative on the
first save, and relative paths start from "./" at or below the drawing's
folder; -XREF name options report "No matching xref names found.".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-09-23 15:34:06 +03:00
1 parent 6bd55bc32e
commit 498a97df0f
8 files changed
+204 -7

No files matched your search

+15
View File
@@ -1864,6 +1864,21 @@ fn same_file(a: &Path, b: &Path) -> bool {
/// Shared by Detach (which then also erases the BlockRecord itself) and BIND
/// (which drops the previous merge before re-merging under `$N$` names). The
/// xref BlockRecord itself, its INSERTs, and non-prefixed symbols stay.
/// Make the named references' paths relative to `host` (their drawing's
/// first save); a reference that cannot be relative keeps its full path.
pub fn make_relative(
doc: &mut CadDocument,
names: &rustc_hash::FxHashSet<String>,
host: &Path,
) {
for name in names {
let Some(key) = doc.block_records.get(name).map(|br| br.handle.value()) else {
continue;
};
let _ = apply_pathtype(doc, key, crate::io::xref_model::Pathtype::Relative, host);
}
}
/// Drop from a save copy what resolving each xref merged into the host but
/// the file never stores: the reference's own geometry, its nested block
/// definitions and its text and dimension styles. Dependent layers and
+6 -1
View File
@@ -247,6 +247,11 @@ pub fn to_pathtype_result(
if parts.is_empty() {
return Ok(file_name_only(path));
}
// A path at or below the host folder starts "./" ("./plan.dwg",
// "./refs/plan.dwg"), as the reference writes it; one above starts "../".
if parts[0] != ".." {
parts.insert(0, ".".to_string());
}
Ok(parts.join("/"))
}
}
@@ -846,7 +851,7 @@ mod tests {
let full = to_pathtype("C:/Drawings/refs/plan.dwg", host, Pathtype::Full);
assert_eq!(full, "C:/Drawings/refs/plan.dwg");
let rel = to_pathtype("C:/Drawings/refs/plan.dwg", host, Pathtype::Relative);
assert_eq!(rel, "refs/plan.dwg");
assert_eq!(rel, "./refs/plan.dwg");
let none = to_pathtype("C:/Drawings/refs/plan.dwg", host, Pathtype::None);
assert_eq!(none, "plan.dwg");
}