Accept two-point MEASURE spacing in spatial coordinates

This commit is contained in:
ramox81 committed 2026-09-11 10:57:05 +03:00
1 parent ec723fb97b
commit 83a930950a
1 file changed
+22 -4
+22 -4
View File
@@ -21,6 +21,7 @@ pub struct MeasurementMarkerCommand {
align: bool,
plane: WorkingPlane,
valid_pick: bool,
value_origin: Option<DVec3>,
}
pub type MeasureCommand = MeasurementMarkerCommand;
@@ -29,7 +30,7 @@ impl MeasurementMarkerCommand {
pub fn new() -> Self {
Self { target: None, pick_point: DVec3::ZERO, step: Step::Pick,
blocks: Vec::new(), block: None, align: true,
plane: WorkingPlane::default(), valid_pick: false }
plane: WorkingPlane::default(), valid_pick: false, value_origin: None }
}
pub fn with_blocks(mut self, blocks: Vec<String>) -> Self {
self.blocks = blocks;
@@ -45,6 +46,7 @@ impl MeasurementMarkerCommand {
impl CadCommand for MeasurementMarkerCommand {
fn name(&self) -> &'static str { if MEASURE { "MEASURE" } else { "DIVIDE" } }
fn prompt(&self) -> String {
if self.value_origin.is_some() { return "MEASURE Specify second point:".into(); }
let prompt = match self.step {
Step::Pick if MEASURE => "Select object to measure:",
Step::Pick => "Select object to divide:",
@@ -58,6 +60,7 @@ impl CadCommand for MeasurementMarkerCommand {
format!("{} {}", self.name(), prompt)
}
fn options(&self) -> Vec<CmdOption> {
if self.value_origin.is_some() { return vec![]; }
match self.step {
Step::Amount if self.block.is_none() => vec![CmdOption::new("Block", "B")],
Step::Align => vec![CmdOption::new("Yes", "Y"), CmdOption::new("No", "N")],
@@ -79,7 +82,8 @@ impl CadCommand for MeasurementMarkerCommand {
}
fn wants_text_input(&self) -> bool { self.step != Step::Pick }
fn dyn_field(&self) -> crate::command::DynField {
if self.step == Step::Amount { crate::command::DynField::Scalar }
if self.step == Step::Amount && MEASURE { crate::command::DynField::Distance }
else if self.step == Step::Amount { crate::command::DynField::Scalar }
else { crate::command::DynField::Point }
}
fn dyn_commit_as_text(&self) -> bool { self.step == Step::Amount }
@@ -99,7 +103,7 @@ impl CadCommand for MeasurementMarkerCommand {
self.step = Step::Amount;
}
Step::Amount => {
if self.block.is_none() && matches!(text.to_ascii_uppercase().as_str(), "B" | "BLOCK") {
if self.block.is_none() && self.value_origin.is_none() && matches!(text.to_ascii_uppercase().as_str(), "B" | "BLOCK") {
self.step = Step::BlockName;
} else {
let segment_length = text.replace(',', ".").parse::<f64>().ok()
@@ -112,7 +116,21 @@ impl CadCommand for MeasurementMarkerCommand {
}
Some(CmdResult::NeedPoint)
}
fn on_point(&mut self, _pt: DVec3) -> CmdResult { CmdResult::NeedPoint }
fn dyn_live_value(&self, cursor: DVec3) -> Option<f64> {
if !MEASURE || self.step != Step::Amount || !cursor.is_finite() { return None; }
let origin = self.value_origin?;
let distance = cadkernel::space::Vec3::from(cursor.to_array()).distance(origin.to_array().into());
(distance.is_finite() && distance > 0.0).then_some(distance)
}
fn on_point(&mut self, pt: DVec3) -> CmdResult {
if MEASURE && self.step == Step::Amount && pt.is_finite() {
if self.value_origin.is_none() { self.value_origin = Some(pt); }
else if let Some(value) = self.dyn_live_value(pt) {
return self.on_text_input(&value.to_string()).unwrap_or(CmdResult::NeedPoint);
}
}
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
if self.step == Step::Align {
self.align = true;