forked from 1b-agent/opencadstudio-upstream
feat: add missing Annotate tab commands and icons
New dimension commands: QDIM, DIMEDIT, DIMTEDIT, DIMBREAK, DIMSPACE, DIMJOGLINE with full command workflows and SVG icons. New multileader commands: MLEADERADD, MLEADERREMOVE, MLEADERALIGN, MLEADERCOLLECT with entity injection pattern for in-place editing. Updated annotate ribbon: all tools exposed across Text, Dimensions, Leaders, Tables, Markup, and Annotation Scaling groups. Added STYLE, FIND, DIMSTYLE shortcut buttons. Added `inject_picked_entity` to the CadCommand trait for commands that need a cloned copy of the picked entity to modify (DIMTEDIT, MLEADERADD, MLEADERREMOVE). Sentinel-based dispatch in cmd_result.rs handles DIMBREAK, DIMSPACE, DIMJOGLINE, MLEADERALIGN, and MLEADERCOLLECT. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
510bcf11e5
commit
08b9a21d31
25 files changed
+1408
-1
No files matched your search
@@ -0,0 +1,106 @@
|
||||
// DIMSPACE command — adjust the spacing between parallel linear/aligned dimensions.
|
||||
//
|
||||
// Workflow:
|
||||
// 1. Select the base dimension
|
||||
// 2. Select the other dimensions to space (click each, Enter to finish)
|
||||
// 3. Enter spacing value (or 0 for automatic equal spacing)
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
|
||||
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/dim_space.svg"));
|
||||
|
||||
pub fn tool() -> ToolDef {
|
||||
ToolDef {
|
||||
id: "DIMSPACE",
|
||||
label: "Dim Space",
|
||||
icon: ICON,
|
||||
event: ModuleEvent::Command("DIMSPACE".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
enum Step {
|
||||
PickBase,
|
||||
PickOthers { base: Handle, others: Vec<Handle> },
|
||||
EnterSpacing { base: Handle, others: Vec<Handle> },
|
||||
}
|
||||
|
||||
pub struct DimSpaceCommand {
|
||||
step: Step,
|
||||
}
|
||||
|
||||
impl DimSpaceCommand {
|
||||
pub fn new() -> Self {
|
||||
Self { step: Step::PickBase }
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for DimSpaceCommand {
|
||||
fn name(&self) -> &'static str { "DIMSPACE" }
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
match &self.step {
|
||||
Step::PickBase => "DIMSPACE Select base dimension:".into(),
|
||||
Step::PickOthers { others, .. } =>
|
||||
format!("DIMSPACE Select dimension to space ({} selected, Enter when done):", others.len()),
|
||||
Step::EnterSpacing { .. } => "DIMSPACE Enter value (0 = auto):".into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn needs_entity_pick(&self) -> bool {
|
||||
matches!(self.step, Step::PickBase | Step::PickOthers { .. })
|
||||
}
|
||||
|
||||
fn on_entity_pick(&mut self, handle: Handle, _pt: Vec3) -> CmdResult {
|
||||
if handle.is_null() { return CmdResult::NeedPoint; }
|
||||
match &mut self.step {
|
||||
Step::PickBase => {
|
||||
self.step = Step::PickOthers { base: handle, others: vec![] };
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
Step::PickOthers { others, .. } => {
|
||||
if !others.contains(&handle) {
|
||||
others.push(handle);
|
||||
}
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
_ => CmdResult::NeedPoint,
|
||||
}
|
||||
}
|
||||
|
||||
fn wants_text_input(&self) -> bool {
|
||||
matches!(self.step, Step::EnterSpacing { .. })
|
||||
}
|
||||
|
||||
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
||||
if let Step::EnterSpacing { base, others } = &self.step {
|
||||
let spacing: f64 = text.trim().parse().unwrap_or(0.0);
|
||||
let b = *base;
|
||||
let o = others.clone();
|
||||
// Emit sentinel for commands.rs to handle
|
||||
use acadrust::entities::XLine;
|
||||
let mut xl = XLine::default();
|
||||
let handles_str: Vec<String> = o.iter().map(|h| h.value().to_string()).collect();
|
||||
xl.common.layer = format!("__DIMSPACE__{},{},{}", b.value(), handles_str.join(";"), spacing);
|
||||
return Some(CmdResult::ReplaceEntity(b, vec![acadrust::EntityType::XLine(xl)]));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn on_point(&mut self, _pt: Vec3) -> CmdResult { CmdResult::NeedPoint }
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
match &self.step {
|
||||
Step::PickOthers { base, others } if !others.is_empty() => {
|
||||
let b = *base;
|
||||
let o = others.clone();
|
||||
self.step = Step::EnterSpacing { base: b, others: o };
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
_ => CmdResult::Cancel,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user