Files
OneCAD-Draft/src/modules/draw/constrain/equal_distance.rs
T
Felix RiestraandClaude Sonnet 5 31b5ef4ec3 Add 8 geometric constraint kinds and an opt-in DWG-native persistence toggle
New ConstraintKind variants — Concentric, CenterPoint, Colinear, Midpoint,
Fixed, PointOnCurve, EqualDistance, Symmetric — each built entirely from
existing ocs_gcs (FreeCAD planegcs) primitives, no new solver math needed.
build_constraint now returns Vec<Rc<dyn Constraint>> instead of
Option<Rc<...>>, generalizing the old Coincident-only "needs a second
system-level constraint" special case to every kind that needs one.
Wired into the ribbon (7 new buttons), a new point+pre-selected-entity
command for CenterPoint/Midpoint/PointOnCurve, a new 4-point command for
EqualDistance, and the existing DWG-native class-name mapping (all 8 reuse
the same generic "plain Geometrical node" path already built for
Coincident/Horizontal/etc.). Deliberately not modeled: Normal and
EqualCurvature, which for this app's Line/Circle-only entity model would
just be Perpendicular and Equal wearing different DWG class names.

Also makes DWG-native constraint persistence opt-in (Options > General,
off by default) rather than unconditional: a scope that doesn't yet have
the native graph is only given one when the setting is on, but a scope
that already has one — from an earlier save, or a file that came from
real AutoCAD — keeps getting it resynced regardless of the setting, so
toggling it off never freezes a stale graph in place.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 19:38:31 +02:00

68 lines
2.1 KiB
Rust

//! EDCONSTRAINT — AutoCAD's fourth `Equal` sub-kind
//! (`ACEQUALDISTANCECONSTRAINT`): the distance between one point pair
//! equals the distance between another, rather than two whole entities
//! being equal length/radius. Needs four point picks (unlike the two
//! whole-entity selections `ECONSTRAINT` uses), so — like
//! `CoincidentConstraintCommand` — it accumulates raw points and hands them
//! back for the host to resolve (`CadCommand` has no document access).
use glam::DVec3;
use crate::command::{CadCommand, CmdResult};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub mod equal_distance_tool {
use super::*;
pub fn tool() -> ToolDef {
ToolDef {
id: "EDCONSTRAINT",
label: "Equal Distance",
icon: IconKind::Glyph("≐"),
event: ModuleEvent::Command("EDCONSTRAINT".to_string()),
}
}
}
#[derive(Default)]
pub struct EqualDistanceConstraintCommand {
points: Vec<DVec3>,
}
impl EqualDistanceConstraintCommand {
pub fn new() -> Self {
Self::default()
}
}
impl CadCommand for EqualDistanceConstraintCommand {
fn name(&self) -> &'static str {
"EDCONSTRAINT"
}
fn prompt(&self) -> String {
match self.points.len() {
0 => "EQUAL DISTANCE Specify first point of first pair:".to_string(),
1 => "EQUAL DISTANCE Specify second point of first pair:".to_string(),
2 => "EQUAL DISTANCE Specify first point of second pair:".to_string(),
_ => "EQUAL DISTANCE Specify second point of second pair:".to_string(),
}
}
fn on_point(&mut self, pt: DVec3) -> CmdResult {
self.points.push(pt);
if self.points.len() < 4 {
return CmdResult::NeedPoint;
}
let [a, b, c, d] = self.points[..] else { unreachable!("just checked len == 4") };
CmdResult::AddEqualDistanceConstraint { points: [a, b, c, d], label: "Equal distance constraint" }
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_escape(&mut self) -> CmdResult {
CmdResult::Cancel
}
}