fix: preserve current layer for hatches and DWG loading

This commit is contained in:
gianlucafiore committed 2026-08-12 00:30:21 -03:00
1 parent b8b66163d6
commit ff61164d8b
3 files changed
+45 -5

No files matched your search

+9 -2
View File
@@ -1203,7 +1203,8 @@ impl OpenCADStudio {
CmdResult::CommitHatch(hatch) => {
let label = self.history_label_from_active_cmd(i, "HATCH");
let pending = self.begin_undo(i, label, 1, true);
let new_handle = self.tabs[i].scene.add_hatch(hatch);
let layer = self.tabs[i].active_layer.clone();
let new_handle = self.tabs[i].scene.add_hatch(hatch, Some(&layer));
if !new_handle.is_null() {
self.tabs[i].scene.select_entity(new_handle, true);
}
@@ -2914,6 +2915,12 @@ impl OpenCADStudio {
angle,
} => {
if let Some(mut model) = self.tabs[i].scene.hatches.get(&handle).cloned() {
let layer = self.tabs[i]
.scene
.document
.get_entity(handle)
.map(|entity| entity.as_entity().layer().to_string())
.unwrap_or_else(|| "0".to_string());
// Update model fields
if !name.is_empty() {
use crate::scene::model::hatch_model::HatchPattern;
@@ -2933,7 +2940,7 @@ impl OpenCADStudio {
// Remove old hatch (entity + GPU model)
self.tabs[i].scene.erase_entities(&[handle]);
// Re-add with updated model
self.tabs[i].scene.add_hatch(model);
self.tabs[i].scene.add_hatch(model, Some(&layer));
self.tabs[i].dirty = true;
self.command_line.push_output(crate::t!("HATCHEDIT: hatch updated.").as_ref());
} else {
+28
View File
@@ -1096,6 +1096,34 @@ pub(super) fn on_open_file(&mut self) -> Task<Message> {
self.tabs[i].scene.material_base_dir =
path.parent().map(std::path::Path::to_path_buf);
self.tabs[i].scene.document = doc;
// DWG stores CLAYER as a layer handle. Resolve that handle back to
// the layer name after opening so the per-tab creation state and
// header name stay in sync. DXF already provides current_layer_name,
// so keep it as a fallback.
let current_layer = {
let doc = &self.tabs[i].scene.document;
doc.layers
.iter()
.find(|layer| layer.handle == doc.header.current_layer_handle)
.map(|layer| (layer.name.clone(), layer.handle))
.or_else(|| {
doc.layers
.get(&doc.header.current_layer_name)
.map(|layer| (layer.name.clone(), layer.handle))
})
.or_else(|| {
doc.layers
.get("0")
.map(|layer| (layer.name.clone(), layer.handle))
})
};
if let Some((name, handle)) = current_layer {
self.tabs[i].scene.document.header.current_layer_name = name.clone();
self.tabs[i].scene.document.header.current_layer_handle = handle;
self.tabs[i].active_layer = name;
}
// A file saved without the built-in Standard styles (foreign
// or damaged) gets them re-seeded so nothing dangles (#366).
crate::app::style_ops::ensure_standard_styles(