2026-04-03 09:29:11 +03:00
|
|
|
// 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};
|
feat: redesign Annotate ribbon tab with proper groups and SVG icons
Added 15 SVG icons for all annotation tools (dimensions, leaders,
table, wipeout, revision cloud, tolerance, ddedit).
Annotate ribbon now has 6 groups matching standard CAD layout:
- Text: MText (large dropdown) + Text + Edit Text
- Dimensions: Linear (large dropdown with 6 types) + Continue + Baseline + Tolerance
- Leaders: Multileader (large dropdown) + Leader
- Tables: Table (large)
- Markup: Wipeout + Rev Cloud
- Annotation Scaling: Scale List, Add Scale, Scale Edit, Sync Scales
Added pub tool() + ICON to all annotate tools that were missing them
(aligned_dim, diameter_dim, dim_continue, dim_baseline, table_cmd,
tolerance_cmd, ddedit), and to home/draw/wipeout and revcloud.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 03:03:08 +03:00
|
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
2026-06-16 11:33:46 +03:00
|
|
|
use crate::scene::model::wire_model::WireModel;
|
2026-04-03 09:29:11 +03:00
|
|
|
|
feat: redesign Annotate ribbon tab with proper groups and SVG icons
Added 15 SVG icons for all annotation tools (dimensions, leaders,
table, wipeout, revision cloud, tolerance, ddedit).
Annotate ribbon now has 6 groups matching standard CAD layout:
- Text: MText (large dropdown) + Text + Edit Text
- Dimensions: Linear (large dropdown with 6 types) + Continue + Baseline + Tolerance
- Leaders: Multileader (large dropdown) + Leader
- Tables: Table (large)
- Markup: Wipeout + Rev Cloud
- Annotation Scaling: Scale List, Add Scale, Scale Edit, Sync Scales
Added pub tool() + ICON to all annotate tools that were missing them
(aligned_dim, diameter_dim, dim_continue, dim_baseline, table_cmd,
tolerance_cmd, ddedit), and to home/draw/wipeout and revcloud.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 03:03:08 +03:00
|
|
|
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/dim_aligned.svg"));
|
|
|
|
|
|
|
|
|
|
pub fn tool() -> ToolDef {
|
|
|
|
|
ToolDef {
|
|
|
|
|
id: "DIMALIGNED",
|
|
|
|
|
label: "Aligned",
|
|
|
|
|
icon: ICON,
|
|
|
|
|
event: ModuleEvent::Command("DIMALIGNED".to_string()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 09:29:11 +03:00
|
|
|
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 {
|
2026-05-12 10:36:15 +03:00
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"DIMALIGNED"
|
|
|
|
|
}
|
2026-04-03 09:29:11 +03:00
|
|
|
|
|
|
|
|
fn prompt(&self) -> String {
|
|
|
|
|
match self.step {
|
2026-05-12 10:36:15 +03:00
|
|
|
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(),
|
2026-04-03 09:29:11 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2026-05-12 10:36:15 +03:00
|
|
|
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,
|
|
|
|
|
));
|
2026-04-03 09:29:11 +03:00
|
|
|
dim.base.insertion_point = dim.base.text_middle_point;
|
|
|
|
|
dim.base.actual_measurement = dim.measurement();
|
|
|
|
|
CmdResult::CommitAndExit(EntityType::Dimension(Dimension::Aligned(dim)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 10:36:15 +03:00
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
|
|
|
CmdResult::Cancel
|
|
|
|
|
}
|
2026-04-03 09:29:11 +03:00
|
|
|
|
|
|
|
|
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]],
|
2026-06-23 17:08:54 +03:00
|
|
|
points_low: Vec::new(),
|
2026-04-03 09:29:11 +03:00
|
|
|
color: WireModel::CYAN,
|
|
|
|
|
selected: false,
|
|
|
|
|
pattern_length: 0.0,
|
|
|
|
|
pattern: [0.0; 8],
|
|
|
|
|
line_weight_px: 1.0,
|
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
tangent_geoms: vec![],
|
2026-04-06 23:19:08 +03:00
|
|
|
aci: 0,
|
2026-04-03 09:29:11 +03:00
|
|
|
key_vertices: vec![],
|
2026-04-26 12:21:51 +03:00
|
|
|
aabb: WireModel::UNBOUNDED_AABB,
|
2026-05-06 06:55:28 +03:00
|
|
|
plinegen: true,
|
2026-05-06 07:12:05 +03:00
|
|
|
vp_scissor: None,
|
2026-05-06 23:24:26 +03:00
|
|
|
fill_tris: vec![],
|
2026-04-03 09:29:11 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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![
|
2026-05-12 10:36:15 +03:00
|
|
|
[p1.x, p1.y, p1.z],
|
|
|
|
|
[d1.x, d1.y, d1.z],
|
2026-04-03 09:29:11 +03:00
|
|
|
[f32::NAN, 0.0, 0.0],
|
2026-05-12 10:36:15 +03:00
|
|
|
[p2.x, p2.y, p2.z],
|
|
|
|
|
[d2.x, d2.y, d2.z],
|
2026-04-03 09:29:11 +03:00
|
|
|
[f32::NAN, 0.0, 0.0],
|
2026-05-12 10:36:15 +03:00
|
|
|
[d1.x, d1.y, d1.z],
|
|
|
|
|
[d2.x, d2.y, d2.z],
|
2026-04-03 09:29:11 +03:00
|
|
|
],
|
2026-06-23 17:08:54 +03:00
|
|
|
points_low: Vec::new(),
|
2026-04-03 09:29:11 +03:00
|
|
|
color: WireModel::CYAN,
|
|
|
|
|
selected: false,
|
|
|
|
|
pattern_length: 0.0,
|
|
|
|
|
pattern: [0.0; 8],
|
|
|
|
|
line_weight_px: 1.0,
|
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
tangent_geoms: vec![],
|
2026-04-06 23:19:08 +03:00
|
|
|
aci: 0,
|
2026-05-12 10:36:15 +03:00
|
|
|
key_vertices: vec![],
|
|
|
|
|
aabb: WireModel::UNBOUNDED_AABB,
|
|
|
|
|
plinegen: true,
|
|
|
|
|
vp_scissor: None,
|
|
|
|
|
fill_tris: vec![],
|
2026-04-03 09:29:11 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-05-26 22:45:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
|
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["DAL", "DIMALIGNED"] }); // AlignedDimensionCommand
|