fix(blocks): a dynamic block copied to another drawing stays dynamic (#1816)

Only the definition's entities crossed drawings: its record's object
graph (parameters, visibility states, grips) stayed behind, and a
reference showing an evaluated copy lost the link to its definition.
The clipboard now captures the graph and the dynamic definition of an
evaluated reference, and paste and the block palette's insert-from-file
recreate them on the new records, re-pointing members and element tags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-16 00:36:59 +03:00
1 parent ca408f4329
commit 091331f3bd
6 files changed
+109 -21

No files matched your search

+13 -4
View File
@@ -424,18 +424,27 @@ impl OpenCADStudio {
let i = self.active_tab;
self.push_undo_snapshot(i, "INSERT");
self.merge_dependencies(i, &deps);
for def in deps.blocks {
let mut created = Vec::new();
for def in &deps.blocks {
let scene = &mut self.tabs[i].scene;
if redefine && def.name.eq_ignore_ascii_case(name) {
if let Err(err) = scene.redefine_block_raw(&def.name, def.base_point, def.entities)
{
let entities = def.entities.clone();
if let Err(err) = scene.redefine_block_raw(&def.name, def.base_point, entities) {
self.command_line.push_error(&err);
return Err(err);
}
} else if scene.document.block_records.get(&def.name).is_none() {
scene.define_block_raw(&def.name, def.base_point, def.entities);
scene.define_block_raw(&def.name, def.base_point, def.entities.clone());
created.push(def);
}
}
// A dynamic definition keeps its parameters and states.
use crate::app::command_driver::clipboard::{block_record_map, import_block_def_graph};
let document = &mut self.tabs[i].scene.document;
let records = block_record_map(document, &deps.blocks);
for def in created {
import_block_def_graph(document, def, &records);
}
self.tabs[i].scene.populate_meshes_from_document();
self.tabs[i].dirty = true;
Ok(())