Files
OneCAD-Draft/src/modules/annotate/dimspace.rs
T
Hakan SevenandClaude Opus 4.8 4f7a98a2ad feat(f64): command layer compiles on DVec3
Whole command/snap/grip/cursor chain now builds on f64 DVec3 end to end,
so picked points, snaps and grip drags stay precise at UTM-scale
coordinates instead of quantizing to ~0.5 m through f32.

- All ~80 command files migrated: draw (line/circle/arc/ellipse/shapes
  in full f64; others via point methods), modify, annotate, insert, view,
  inquiry, layers, groups, clipboard, layout.
- Entity apply_grip impls updated for GripApply::{Absolute,Translate}(DVec3).
- Construction sites (EntityTransform/CmdResult/DynAnchor) emit DVec3;
  wire-preview boundaries cast to f32 only at the GPU edge.
- Modify/annotate commands keep internal Vec3 geometry where precision is
  non-critical, casting at the DVec3 boundary; key draw commands store f64.

Builds clean (no warnings). Visual verification of crosshair/snap/grip at
extreme UTM zoom pending.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 03:51:50 +03:00

132 lines
3.9 KiB
Rust

// 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::DVec3;
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: DVec3) -> 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: DVec3) -> 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,
}
}
}
// ── Autocomplete registry ─────────────────────────────────
inventory::submit!(crate::command::CommandRegistration { names: &["DIMSPACE", "DSPACE"] }); // DimSpaceCommand