fix(layers): allocate real handles for new layers (#67)

New layers were added to the table with a NULL handle, and the first
patch used the non-advancing `next_handle()` getter, so two new layers
(or a layer and the next allocated object) shared one handle. The DWG
format is handle-based, so the collision dropped the layer on save;
DXF is name-based and survived, which is why a rename appeared to fix
it.

Allocate a unique advancing handle via `allocate_handle()` in LAYER NEW
(panel + command line) and on rename when the source handle is invalid.
Rename now also clones the whole record so colour/linetype/lineweight
are kept, not just the flags.

Adds DWG/DXF round-trip tests covering one and multiple new layers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-09 19:37:42 +03:00
commit 6520195220
3 changed files with 64 additions and 11 deletions

View file

@ -3288,7 +3288,10 @@ impl OpenCADStudio {
self.command_line
.push_error(&format!("LAYER: '{}' already exists.", name));
} else {
let layer = Layer::new(&name);
let mut layer = Layer::new(&name);
// Allocate a unique handle so the layer survives a
// DWG save (handle-based format; issue #67).
layer.handle = self.tabs[i].scene.document.allocate_handle();
let _ = self.tabs[i].scene.document.layers.add(layer);
self.push_undo_snapshot(i, "LAYER NEW");
self.tabs[i].dirty = true;