Feat: DIMALIGNED (DAL) and DIMDIAMETER (DDI) dimension commands

DIMALIGNED: 3-click flow (p1 → p2 → dim line position) → DimensionAligned.
Rubber-band preview shows extension lines and dim line offset.

DIMDIAMETER: 3-click flow (center → arc point → text position) → DimensionDiameter.
Previews the diameter chord line.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-04-03 09:29:11 +03:00
commit 77327bf730
4 changed files with 232 additions and 1 deletions

View file

@ -761,6 +761,20 @@ impl H7CAD {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMALIGNED"|"DAL" => {
use crate::modules::annotate::aligned_dim::AlignedDimensionCommand;
let cmd = AlignedDimensionCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMDIAMETER"|"DDI" => {
use crate::modules::annotate::diameter_dim::DiameterDimensionCommand;
let cmd = DiameterDimensionCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMLINEAR" => {
use crate::modules::annotate::linear_dim::LinearDimensionCommand;
let new_cmd = LinearDimensionCommand::new();
@ -1338,7 +1352,7 @@ impl H7CAD {
Modify: MOVE COPY ROTATE SCALE MIRROR ERASE OFFSET EXTEND FILLET CHAMFER STRETCH EXPLODE TRIM BREAK JOIN LENGTHEN ALIGN | \
Array: ARRAY ARRAYRECT ARRAYPOLAR ARRAYPATH | \
Text: TEXT MTEXT LEADER MLEADER | \
Dimension: DIMLINEAR DIMANGULAR DIMRADIUS | \
Dimension: DIMLINEAR DIMALIGNED DIMANGULAR DIMRADIUS DIMDIAMETER | \
Inquiry: DIST ID AREA LIST FIND FINDALL COUNT QSELECT | Draw on entity: DIVIDE MEASURE | \
Utilities: FLATTEN LAYISO LAYUNISO PEDIT MLINE MLEADER | \
View: ZOOM EXTENTS VIEW LIST/SAVE/RESTORE/DELETE | \

View file

@ -0,0 +1,124 @@
// DIMALIGNED command — aligned dimension (measures true distance between two points).
use acadrust::entities::{Dimension, DimensionAligned};
use acadrust::types::Vector3;
use acadrust::EntityType;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::scene::wire_model::WireModel;
enum Step {
First,
Second(Vec3),
DimLine { p1: Vec3, p2: Vec3 },
}
pub struct AlignedDimensionCommand {
step: Step,
}
impl AlignedDimensionCommand {
pub fn new() -> Self {
Self { step: Step::First }
}
}
impl CadCommand for AlignedDimensionCommand {
fn name(&self) -> &'static str { "DIMALIGNED" }
fn prompt(&self) -> String {
match self.step {
Step::First => "DIMALIGNED Specify first extension line origin:".into(),
Step::Second(_) => "DIMALIGNED Specify second extension line origin:".into(),
Step::DimLine { .. } => "DIMALIGNED Specify dimension line location:".into(),
}
}
fn on_point(&mut self, pt: Vec3) -> CmdResult {
match self.step {
Step::First => {
self.step = Step::Second(pt);
CmdResult::NeedPoint
}
Step::Second(p1) => {
self.step = Step::DimLine { p1, p2: pt };
CmdResult::NeedPoint
}
Step::DimLine { p1, p2 } => {
let mut dim = DimensionAligned::new(v3(p1), v3(p2));
// Set offset: distance from p2 to the dim line location
let dx = pt.x as f64 - p2.x as f64;
let dy = pt.z as f64 - p2.z as f64;
let offset = (dx * dx + dy * dy).sqrt();
dim.set_offset(offset);
dim.base.definition_point = v3(pt);
dim.base.text_middle_point = v3(
Vec3::new(
(p1.x + p2.x) * 0.5,
(p1.y + p2.y) * 0.5,
(p1.z + p2.z) * 0.5,
)
);
dim.base.insertion_point = dim.base.text_middle_point;
dim.base.actual_measurement = dim.measurement();
CmdResult::CommitAndExit(EntityType::Dimension(Dimension::Aligned(dim)))
}
}
}
fn on_enter(&mut self) -> CmdResult { CmdResult::Cancel }
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
let (p1, p2) = match self.step {
Step::First => return None,
Step::Second(p1) => (p1, pt),
Step::DimLine { p1, p2 } => {
return Some(preview_aligned(p1, p2, pt));
}
};
Some(WireModel {
name: "dimaligned_preview".into(),
points: vec![[p1.x, p1.y, p1.z], [p2.x, p2.y, p2.z]],
color: WireModel::CYAN,
selected: false,
pattern_length: 0.0,
pattern: [0.0; 8],
line_weight_px: 1.0,
snap_pts: vec![],
tangent_geoms: vec![],
key_vertices: vec![],
})
}
}
fn v3(p: Vec3) -> Vector3 {
Vector3::new(p.x as f64, p.y as f64, p.z as f64)
}
fn preview_aligned(p1: Vec3, p2: Vec3, dim_pt: Vec3) -> WireModel {
// Show ext lines + dim line
let dir = (p2 - p1).normalize_or_zero();
let perp = Vec3::new(-dir.z, dir.y, dir.x).normalize_or_zero();
let offset = (dim_pt - p2).dot(perp);
let d1 = p1 + perp * offset;
let d2 = p2 + perp * offset;
WireModel {
name: "dimaligned_preview".into(),
points: vec![
[p1.x, p1.y, p1.z], [d1.x, d1.y, d1.z],
[f32::NAN, 0.0, 0.0],
[p2.x, p2.y, p2.z], [d2.x, d2.y, d2.z],
[f32::NAN, 0.0, 0.0],
[d1.x, d1.y, d1.z], [d2.x, d2.y, d2.z],
],
color: WireModel::CYAN,
selected: false,
pattern_length: 0.0,
pattern: [0.0; 8],
line_weight_px: 1.0,
snap_pts: vec![],
tangent_geoms: vec![],
key_vertices: vec![],
}
}

View file

@ -0,0 +1,91 @@
// DIMDIAMETER command — diameter dimension for circles and arcs.
use acadrust::entities::{Dimension, DimensionDiameter};
use acadrust::types::Vector3;
use acadrust::EntityType;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::scene::wire_model::WireModel;
enum Step {
CenterPoint,
ArcPoint(Vec3),
TextPoint { center: Vec3, arc_pt: Vec3 },
}
pub struct DiameterDimensionCommand {
step: Step,
}
impl DiameterDimensionCommand {
pub fn new() -> Self {
Self { step: Step::CenterPoint }
}
}
impl CadCommand for DiameterDimensionCommand {
fn name(&self) -> &'static str { "DIMDIAMETER" }
fn prompt(&self) -> String {
match self.step {
Step::CenterPoint => "DIMDIAMETER Specify center point:".into(),
Step::ArcPoint(_) => "DIMDIAMETER Specify point on circle:".into(),
Step::TextPoint {..} => "DIMDIAMETER Specify dimension line location:".into(),
}
}
fn on_point(&mut self, pt: Vec3) -> CmdResult {
match self.step {
Step::CenterPoint => {
self.step = Step::ArcPoint(pt);
CmdResult::NeedPoint
}
Step::ArcPoint(center) => {
self.step = Step::TextPoint { center, arc_pt: pt };
CmdResult::NeedPoint
}
Step::TextPoint { center, arc_pt } => {
let mut dim = DimensionDiameter::new(v3(center), v3(arc_pt));
dim.base.definition_point = v3(arc_pt);
dim.base.text_middle_point = v3(pt);
dim.base.insertion_point = v3(pt);
dim.leader_length = arc_pt.distance(pt) as f64;
dim.base.actual_measurement = dim.measurement();
CmdResult::CommitAndExit(EntityType::Dimension(Dimension::Diameter(dim)))
}
}
}
fn on_enter(&mut self) -> CmdResult { CmdResult::Cancel }
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
match self.step {
Step::CenterPoint => None,
Step::ArcPoint(center) => Some(preview_line(center, pt)),
Step::TextPoint { center, arc_pt } => {
let far = center + (center - arc_pt); // opposite point on circle
Some(preview_line(far, pt))
}
}
}
}
fn v3(p: Vec3) -> Vector3 {
Vector3::new(p.x as f64, p.y as f64, p.z as f64)
}
fn preview_line(a: Vec3, b: Vec3) -> WireModel {
WireModel {
name: "dimdia_preview".into(),
points: vec![[a.x, a.y, a.z], [b.x, b.y, b.z]],
color: WireModel::CYAN,
selected: false,
pattern_length: 0.0,
pattern: [0.0; 8],
line_weight_px: 1.0,
snap_pts: vec![],
tangent_geoms: vec![],
key_vertices: vec![],
}
}

View file

@ -1,6 +1,8 @@
// Annotate module — dimension and text annotation tools.
pub mod aligned_dim;
pub mod angular_dim;
pub mod diameter_dim;
pub mod leader_cmd;
pub mod linear_dim;
pub mod mleader_cmd;