refactor(paste): one finalize path; carry XCLIP through all three pastes

Consolidate the duplicated paste logic and extend XCLIP-carry to every path.

- finalize_paste(): single shared step for PASTECLIP and PASTEORIG —
  merge deps + block defs + xdictionary graphs, add clones (optionally
  transformed), tessellate solids. A new cross-drawing concern is now wired
  once instead of re-implemented per command (the gap that lost the clip on
  PASTEORIG in the first place).
- recreate_clipboard_ext_roots() + recreate_ext_subtree(): PASTEBLOCK now
  recreates each entity's xdictionary graph and stamps the new root onto the
  wrapped entity before defining the block, so the block's nested insert
  keeps its spatial filter.
- block_cache: a nested insert's clip is baked into NestedRef.clip_poly at
  build time (the spatial filter isn't reachable at expand time) and applied
  on expansion — the clipped wires are finalized in an isolated batch set,
  clipped, and carried out via Batches.extra_wires. Single-instance only;
  arrays of clipped nested inserts fall through unclipped.

All three paste paths (PASTECLIP / PASTEORIG / PASTEBLOCK) now preserve an
XCLIP clip across a cross-drawing paste.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-24 09:53:28 +03:00
commit ef55b49db5
3 changed files with 166 additions and 86 deletions

View file

@ -623,27 +623,8 @@ impl OpenCADStudio {
} else {
let count = self.clipboard.len();
self.push_undo_snapshot(i, "PASTEORIG");
// Recreate any layer / style this drawing lacks, then add
// each entity with fresh handles (top-level + inline subs)
// so a same-document paste can't duplicate handles. (#129)
self.merge_clipboard_deps(i);
// …and any block definition the pasted INSERTs reference,
// else a block reference renders empty in a drawing that
// lacks the definition. (#135 / #158)
self.merge_clipboard_blocks(i);
let by_index: Vec<acadrust::Handle> = self
.clipboard
.clone()
.into_iter()
.map(|entity| self.tabs[i].scene.add_entity_clone(entity))
.collect();
// Recreate each pasted entity's xdictionary graph (XCLIP
// spatial filters etc.) so a cross-drawing paste keeps its
// clip instead of showing the whole block. (#xclip-paste)
self.merge_clipboard_ext_objects(i, &by_index);
// Tessellate any pasted ACIS solids (top-level + inside a
// recreated block) so they render instead of staying blank.
self.tabs[i].scene.populate_meshes_from_document();
// No transform: entities keep their original coordinates.
let _ = self.finalize_paste(i, None);
self.tabs[i].dirty = true;
self.refresh_layer_panel();
self.refresh_properties();
@ -667,9 +648,18 @@ impl OpenCADStudio {
// reference, so nested blocks inside the new wrapper block
// don't render empty. (#135 / #158)
self.merge_clipboard_blocks(i);
// Recreate each entity's xdictionary graph (XCLIP filters)
// and stamp the new root onto the wrapped entity, so the
// block's nested insert keeps its clip. (#xclip-paste)
let ext_roots = self.recreate_clipboard_ext_roots(i);
let name = self.unique_block_name("Block");
let base = self.clipboard_centroid;
let entities = self.clipboard.clone();
let mut entities = self.clipboard.clone();
for (idx, root) in ext_roots {
if let Some(e) = entities.get_mut(idx) {
e.common_mut().xdictionary_handle = Some(root);
}
}
match self
.tabs[i]
.scene