From 2b91ec4637b44ecd1e5a39189680763986fa1a26 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 2 Apr 2026 23:18:41 +0300 Subject: [PATCH] =?UTF-8?q?Feat:=20LAYER=20command=20=E2=80=94=20list,=20n?= =?UTF-8?q?ew,=20on/off,=20freeze/thaw,=20lock,=20color,=20set=20current?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- src/app/commands.rs | 131 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/app/commands.rs b/src/app/commands.rs index 135d67f3..9055a195 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -1048,6 +1048,137 @@ impl H7CAD { } } + // ── LAYER management ───────────────────────────────────────── + cmd if cmd == "LAYER" || cmd == "LA" || cmd.starts_with("LAYER ") || cmd.starts_with("LA ") => { + use acadrust::tables::Layer; + let raw_rest = if cmd.starts_with("LAYER ") { + cmd.trim_start_matches("LAYER ").trim() + } else if cmd.starts_with("LA ") { + cmd.trim_start_matches("LA ").trim() + } else { + "" + }; + let parts: Vec<&str> = raw_rest.split_whitespace().collect(); + let sub = parts.get(0).map(|s| s.to_uppercase()).unwrap_or_default(); + match sub.as_str() { + "" | "LIST" | "?" => { + let info: Vec = self.tabs[i].scene.document.layers.iter().map(|l| { + let state = if l.flags.frozen { "frozen" } + else if l.flags.off { "off" } + else if l.flags.locked { "locked" } + else { "on" }; + format!("{}({})", l.name, state) + }).collect(); + self.command_line.push_output(&format!("Layers: {}", info.join(", "))); + } + "NEW" | "N" => { + let name = parts.get(1).map(|s| s.trim()).unwrap_or("").to_string(); + if name.is_empty() { + self.command_line.push_error("Usage: LAYER NEW "); + } else if self.tabs[i].scene.document.layers.contains(&name) { + self.command_line.push_error(&format!("LAYER: '{}' already exists.", name)); + } else { + let layer = Layer::new(&name); + let _ = self.tabs[i].scene.document.layers.add(layer); + self.push_undo_snapshot(i, "LAYER NEW"); + self.tabs[i].dirty = true; + self.command_line.push_output(&format!("LAYER: '{}' created.", name)); + } + } + "ON" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.off = false; l.flags.frozen = false; + } + } + self.push_undo_snapshot(i, "LAYER ON"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers turned on."); + } + "OFF" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.off = true; + } + } + self.push_undo_snapshot(i, "LAYER OFF"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers turned off."); + } + "FREEZE" | "FR" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.frozen = true; + } + } + self.push_undo_snapshot(i, "LAYER FREEZE"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers frozen."); + } + "THAW" | "TH" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.frozen = false; + } + } + self.push_undo_snapshot(i, "LAYER THAW"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers thawed."); + } + "LOCK" | "LO" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.locked = true; + } + } + self.push_undo_snapshot(i, "LAYER LOCK"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers locked."); + } + "UNLOCK" | "UL" => { + for name in &parts[1..] { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(name) { + l.flags.locked = false; + } + } + self.push_undo_snapshot(i, "LAYER UNLOCK"); + self.tabs[i].dirty = true; + self.command_line.push_output("LAYER: layers unlocked."); + } + "COLOR" | "C" => { + // LAYER COLOR + let layer_name = parts.get(1).map(|s| s.trim()).unwrap_or("").to_string(); + let color_str = parts.get(2).map(|s| s.trim()).unwrap_or(""); + if let Ok(idx) = color_str.parse::() { + if let Some(l) = self.tabs[i].scene.document.layers.get_mut(&layer_name) { + l.color = acadrust::types::Color::from_index(idx); + self.push_undo_snapshot(i, "LAYER COLOR"); + self.tabs[i].dirty = true; + self.command_line.push_output(&format!("LAYER: '{}' color set to ACI {}.", layer_name, idx)); + } else { + self.command_line.push_error(&format!("LAYER: '{}' not found.", layer_name)); + } + } else { + self.command_line.push_error("Usage: LAYER COLOR "); + } + } + "SET" | "S" | "CURRENT" => { + let name = parts.get(1).map(|s| s.trim()).unwrap_or("").to_string(); + if self.tabs[i].scene.document.layers.contains(&name) { + self.tabs[i].layers.current_layer = name.clone(); + self.command_line.push_output(&format!("LAYER: current layer set to '{}'.", name)); + } else { + self.command_line.push_error(&format!("LAYER: '{}' not found.", name)); + } + } + _ => { + self.command_line.push_info( + "Usage: LAYER LIST | NEW | ON/OFF/FREEZE/THAW/LOCK/UNLOCK | COLOR | SET " + ); + } + } + } + // ── UCS management ─────────────────────────────────────────── cmd if cmd == "UCS" || cmd.starts_with("UCS ") => { use acadrust::tables::Ucs;