use super::*; impl OpenCADStudio { pub(super) fn dispatch_layerprops(&mut self, cmd: &str, i: usize) -> Option> { match cmd { // ── LAYER management ───────────────────────────────────────── cmd if cmd == "LAYER" || 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 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; 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; // By-layer colour is baked into every wire on // this layer — re-tessellate so they repaint // immediately (issue #231 class). self.tabs[i].scene.bump_geometry(); 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 " ); } } } // Bare UCS → interactive front-end (option then value as steps), so // `UCS Z 90` is typable in the command line and works headlessly. // The front-end delegates back to the inline handler below. (#169) "UCS" => { use crate::modules::view::ucs_cmd::UcsCommand; let cmd_obj = UcsCommand::new(); self.command_line.push_info(&cmd_obj.prompt()); self.tabs[i].active_cmd = Some(Box::new(cmd_obj)); } // ── UCS management (inline `UCS