fix(annotate): align annotation ribbon workflows

This commit is contained in:
ramox81 committed 2026-09-14 11:55:08 +03:00
1 parent fc1788df65
commit 6505b27818
26 files changed
+1921 -345

No files matched your search

+105 -43
View File
@@ -1,13 +1,11 @@
// DIMEDIT command — edit dimension text or reset it to the measured value.
//
// Workflow:
// 1. Pick a dimension entity
// 2. Enter new text (blank = reset to auto-measured value, "<>" = measured value placeholder)
// DIMEDIT — edit dimension text, rotation, extension-line obliquing or home position.
use acadrust::Handle;
use glam::DVec3;
use crate::command::{CadCommand, CmdResult};
use crate::command::{
CadCommand, CmdOption, CmdResult, DimensionEditOperation, InputKind,
};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::t;
@@ -23,8 +21,11 @@ pub fn tool() -> ToolDef {
}
enum Step {
PickDim,
EnterText { handle: Handle },
Choose,
NewText,
Rotate,
Oblique,
Select(DimensionEditOperation),
}
pub struct DimEditCommand {
@@ -33,9 +34,12 @@ pub struct DimEditCommand {
impl DimEditCommand {
pub fn new() -> Self {
Self {
step: Step::PickDim,
}
Self { step: Step::Choose }
}
fn select(&mut self, operation: DimensionEditOperation) -> CmdResult {
self.step = Step::Select(operation);
CmdResult::NeedPoint
}
}
@@ -45,48 +49,106 @@ impl CadCommand for DimEditCommand {
}
fn prompt(&self) -> String {
match &self.step {
Step::PickDim => t!("DIMEDIT Select dimension:").into_owned(),
Step::EnterText { .. } => {
t!("DIMEDIT Enter text override (blank = reset to measured):").into_owned()
match self.step {
Step::Choose => {
t!("DIMEDIT Enter type of dimension editing [Home/New/Rotate/Oblique] <Home>:")
.into_owned()
}
Step::NewText => t!("DIMEDIT Enter new dimension text <measured value>:").into_owned(),
Step::Rotate => t!("DIMEDIT Specify angle for dimension text:").into_owned(),
Step::Oblique => {
t!("DIMEDIT Enter obliquing angle (press Enter for none):").into_owned()
}
Step::Select(_) => t!("DIMEDIT Select objects:").into_owned(),
}
}
fn options(&self) -> Vec<CmdOption> {
if !matches!(self.step, Step::Choose) {
return Vec::new();
}
vec![
CmdOption::new("Home", "HOME"),
CmdOption::new("New", "NEW"),
CmdOption::new("Rotate", "ROTATE"),
CmdOption::new("Oblique", "OBLIQUE"),
]
}
fn input_kind(&self) -> InputKind {
match self.step {
Step::NewText => InputKind::FreeText,
Step::Select(_) => InputKind::Point,
Step::Choose | Step::Rotate | Step::Oblique => InputKind::SingleToken,
}
}
fn is_selection_gathering(&self) -> bool {
matches!(self.step, Step::Select(_))
}
fn on_selection_complete(&mut self, handles: Vec<Handle>) -> CmdResult {
let Step::Select(operation) = &self.step else {
return CmdResult::Cancel;
};
if handles.is_empty() {
CmdResult::Cancel
} else {
CmdResult::EditDimensions {
handles,
operation: operation.clone(),
}
}
}
fn needs_entity_pick(&self) -> bool {
matches!(self.step, Step::PickDim)
}
fn on_entity_pick(&mut self, handle: Handle, _pt: DVec3) -> CmdResult {
if handle.is_null() {
return CmdResult::NeedPoint;
}
self.step = Step::EnterText { handle };
CmdResult::NeedPoint
}
fn wants_text_input(&self) -> bool {
matches!(self.step, Step::EnterText { .. })
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let handle = match &self.step {
Step::EnterText { handle } => *handle,
_ => return None,
};
// Empty = reset to auto-measured, "<>" = keep measured, else override
let new_text = text.trim().to_string();
Some(CmdResult::DdeditEntity { handle, new_text })
let value = text.trim();
let keyword = value.to_ascii_uppercase();
match self.step {
Step::Choose => match keyword.as_str() {
"H" | "HOME" => Some(self.select(DimensionEditOperation::Home)),
"N" | "NEW" => {
self.step = Step::NewText;
Some(CmdResult::NeedPoint)
}
"R" | "ROTATE" => {
self.step = Step::Rotate;
Some(CmdResult::NeedPoint)
}
"O" | "OBLIQUE" => {
self.step = Step::Oblique;
Some(CmdResult::NeedPoint)
}
_ => None,
},
Step::NewText => Some(self.select(DimensionEditOperation::NewText(
if value == "<>" { String::new() } else { text.to_string() },
))),
Step::Rotate => value
.parse::<f64>()
.ok()
.map(|degrees| self.select(DimensionEditOperation::Rotate(degrees))),
Step::Oblique => value
.parse::<f64>()
.ok()
.filter(|degrees| (-85.0..=85.0).contains(degrees))
.map(|degrees| self.select(DimensionEditOperation::Oblique(degrees))),
Step::Select(_) => None,
}
}
fn on_point(&mut self, _pt: DVec3) -> CmdResult {
fn on_point(&mut self, _point: DVec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
match self.step {
Step::Choose => self.select(DimensionEditOperation::Home),
Step::NewText => self.select(DimensionEditOperation::NewText(String::new())),
Step::Oblique => self.select(DimensionEditOperation::Oblique(0.0)),
Step::Rotate | Step::Select(_) => CmdResult::Cancel,
}
}
}
// ── Autocomplete registry ─────────────────────────────────
inventory::submit!(crate::command::CommandRegistration { names: &["DIMEDIT"] }); // DimEditCommand
inventory::submit!(crate::command::CommandRegistration { names: &["DIMEDIT"] });