Dimensional constraints: DCFORM, DIMCONSTRAINT options, -PARAMETERS, value prompt, save without display overrides

DCFORM sets the annotational or dynamic form and continues into the
DIMCONSTRAINT option prompt, whose wording and last-used default match the
reference. -PARAMETERS manages parameters from the command line; a
double-clicked constraint dimension opens its value prompt. Dynamic
dimensions rescale on every camera change and their display overrides stay
out of the saved file. A driving dimension between an entity's own ends no
longer has its length retained, so a new value moves the second point along
the dimension axis; parameter edits hold the first constraint point.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
ramox81andClaude Fable 5.1 committed 2026-09-21 15:08:44 +03:00
1 parent aa51765a62
commit 3e28604752
12 files changed
+810 -34

No files matched your search

+151 -4
View File
@@ -392,9 +392,16 @@ impl CadCommand for DimConstraintCommand {
/// `DIMCONSTRAINT`: the reference's option front end for the dimensional
/// constraint family; each choice runs the focused command.
pub struct DimConstraintMenuCommand;
pub struct DimConstraintMenuCommand {
/// The option Enter takes: the dimensional constraint used last.
default: &'static str,
}
impl DimConstraintMenuCommand {
pub fn new(default: &'static str) -> Self {
Self { default }
}
fn dispatch(keyword: &str) -> Option<&'static str> {
Some(match keyword {
"L" | "LINEAR" => "DCLINEAR",
@@ -404,10 +411,24 @@ impl DimConstraintMenuCommand {
"AN" | "ANGULAR" => "DCANGULAR",
"R" | "RADIAL" | "RADIUS" => "DCRADIUS",
"D" | "DIAMETER" => "DCDIAMETER",
"F" | "FORM" => "DCFORM",
"C" | "CONVERT" => "DCCONVERT",
_ => return None,
})
}
fn command_for_label(label: &str) -> &'static str {
match label {
"Linear" => "DCLINEAR",
"Horizontal" => "DCHORIZONTAL",
"Vertical" => "DCVERTICAL",
"ANgular" => "DCANGULAR",
"Radius" => "DCRADIUS",
"Diameter" => "DCDIAMETER",
"Convert" => "DCCONVERT",
_ => "DCALIGNED",
}
}
}
impl CadCommand for DimConstraintMenuCommand {
@@ -416,7 +437,10 @@ impl CadCommand for DimConstraintMenuCommand {
}
fn prompt(&self) -> String {
"DIMCONSTRAINT Enter dimensional constraint option [Linear/Horizontal/Vertical/Aligned/ANgular/Radial/Diameter/Convert] <Aligned>:".to_string()
format!(
"DIMCONSTRAINT Enter a dimensional constraint option [Linear/Horizontal/Vertical/Aligned/ANgular/Radius/Diameter/Form/Convert] <{}>:",
self.default
)
}
fn options(&self) -> Vec<CmdOption> {
@@ -426,8 +450,9 @@ impl CadCommand for DimConstraintMenuCommand {
CmdOption::new("Vertical", "V"),
CmdOption::new("Aligned", "A"),
CmdOption::new("ANgular", "AN"),
CmdOption::new("Radial", "R"),
CmdOption::new("Radius", "R"),
CmdOption::new("Diameter", "D"),
CmdOption::new("Form", "F"),
CmdOption::new("Convert", "C"),
]
}
@@ -446,7 +471,129 @@ impl CadCommand for DimConstraintMenuCommand {
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Dispatch("DCALIGNED".to_string())
CmdResult::Dispatch(Self::command_for_label(self.default).to_string())
}
fn on_escape(&mut self) -> CmdResult {
CmdResult::Cancel
}
}
/// `DCFORM`: `Enter constraint form [Annotational/Dynamic] <current>:`;
/// the host records the answer and continues into DIMCONSTRAINT's option
/// prompt, as the reference does.
pub struct ConstraintFormCommand {
annotational: bool,
}
impl ConstraintFormCommand {
pub fn new(annotational: bool) -> Self {
Self { annotational }
}
fn current(&self) -> &'static str {
if self.annotational {
"Annotational"
} else {
"Dynamic"
}
}
}
impl CadCommand for ConstraintFormCommand {
fn name(&self) -> &'static str {
"DCFORM"
}
fn prompt(&self) -> String {
format!(
"DCFORM Enter constraint form [Annotational/Dynamic] <{}>:",
self.current()
)
}
fn options(&self) -> Vec<CmdOption> {
vec![
CmdOption::new("Annotational", "A"),
CmdOption::new("Dynamic", "D"),
]
}
fn wants_text_input(&self) -> bool {
true
}
fn point_step_accepts_keywords(&self) -> bool {
true
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let keyword = text.trim().trim_start_matches('_').to_ascii_uppercase();
let form = match keyword.as_str() {
"A" | "ANNOTATIONAL" => "Annotational",
"D" | "DYNAMIC" => "Dynamic",
_ => return None,
};
Some(CmdResult::Dispatch(format!("DCFORM_SET {form}")))
}
fn on_point(&mut self, _point: DVec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Dispatch(format!("DCFORM_SET {}", self.current()))
}
fn on_escape(&mut self) -> CmdResult {
CmdResult::Cancel
}
}
/// The value prompt a double-clicked dynamic dimension opens, standing in
/// for the reference's in-place editor; `name=expression` also renames.
pub struct DimensionValueCommand {
name: String,
current: String,
}
impl DimensionValueCommand {
pub fn new(name: String, current: String) -> Self {
Self { name, current }
}
}
impl CadCommand for DimensionValueCommand {
fn name(&self) -> &'static str {
"DCVALUE"
}
fn prompt(&self) -> String {
format!(
"DCVALUE Enter value or name and value <{}={}>:",
self.name, self.current
)
}
fn wants_text_input(&self) -> bool {
true
}
fn point_step_accepts_keywords(&self) -> bool {
true
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let text = text.trim();
(!text.is_empty()).then(|| CmdResult::Dispatch(format!("DCVALUE {} {text}", self.name)))
}
fn on_point(&mut self, _point: DVec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_escape(&mut self) -> CmdResult {
+7 -2
View File
@@ -5,6 +5,7 @@
mod coincident;
mod concentric;
mod dim_constraint;
mod parameters_cli;
mod constraint_bar;
mod equal_distance;
#[path = "equal.rs"]
@@ -26,7 +27,11 @@ mod tools;
mod value;
pub use coincident::{coincident_tool, CoincidentConstraintCommand};
pub use concentric::ConcentricConstraintCommand;
pub use dim_constraint::{DimConstraintAxis, DimConstraintCommand, DimConstraintMenuCommand};
pub use dim_constraint::{
ConstraintFormCommand, DimConstraintAxis, DimConstraintCommand, DimConstraintMenuCommand,
DimensionValueCommand,
};
pub use parameters_cli::ParametersCliCommand;
pub use constraint_bar::ConstraintBarOptionCommand;
pub use equal_command::EqualConstraintCommand;
pub use equal_distance::{equal_distance_tool, EqualDistanceConstraintCommand};
@@ -158,7 +163,7 @@ inventory::submit!(crate::command::CommandRegistration {
names: &[
"AUTOCONSTRAIN", "CONSTRAINTSETTINGS", "GCSMOOTH", "GCSHOW", "GCHIDE", "GCRESET",
"GCSHOWALL", "GCHIDEALL", "DCSHOW", "DCHIDE", "DCSHOWALL", "DCHIDEALL",
"DCCONVERT", "DELCONSTRAINT", "DIMCONSTRAINT",
"DCCONVERT", "DELCONSTRAINT", "DIMCONSTRAINT", "DCFORM", "-PARAMETERS",
]
});
+146
View File
@@ -0,0 +1,146 @@
use glam::DVec3;
use crate::command::{CadCommand, CmdOption, CmdResult};
/// `-PARAMETERS`: the reference's command-line parameter manager. One run
/// performs one operation; the host answers the `LIST`, `NEW`, `EDIT`,
/// `SET`, `RENAME` and `DELETE` dispatches.
pub struct ParametersCliCommand {
step: Step,
}
#[derive(Clone)]
enum Step {
/// `Enter a parameter option [New/Edit/Rename/Delete/?]:`
Option,
/// `Enter name for new user parameter:`
NewName,
/// `Enter expression:`
NewExpression { name: String },
/// `Enter parameter name:`
EditName,
/// `Enter expression:` after the host printed the old expression.
EditExpression { name: String },
/// `Enter old parameter name:`
RenameOld,
/// `Enter new parameter name:`
RenameNew { old: String },
/// `Enter parameter name to delete:`
DeleteName,
}
impl ParametersCliCommand {
pub fn new() -> Self {
Self { step: Step::Option }
}
/// The expression prompt the host opens after printing the old expression.
pub fn edit_expression(name: String) -> Self {
Self {
step: Step::EditExpression { name },
}
}
}
impl Default for ParametersCliCommand {
fn default() -> Self {
Self::new()
}
}
impl CadCommand for ParametersCliCommand {
fn name(&self) -> &'static str {
"-PARAMETERS"
}
fn prompt(&self) -> String {
let text = match &self.step {
Step::Option => "Enter a parameter option [New/Edit/Rename/Delete/?]:",
Step::NewName => "Enter name for new user parameter:",
Step::NewExpression { .. } | Step::EditExpression { .. } => "Enter expression:",
Step::EditName => "Enter parameter name:",
Step::RenameOld => "Enter old parameter name:",
Step::RenameNew { .. } => "Enter new parameter name:",
Step::DeleteName => "Enter parameter name to delete:",
};
format!("-PARAMETERS {text}")
}
fn options(&self) -> Vec<CmdOption> {
match self.step {
Step::Option => vec![
CmdOption::new("New", "N"),
CmdOption::new("Edit", "E"),
CmdOption::new("Rename", "R"),
CmdOption::new("Delete", "D"),
CmdOption::new("?", "?"),
],
_ => Vec::new(),
}
}
fn wants_text_input(&self) -> bool {
true
}
fn point_step_accepts_keywords(&self) -> bool {
true
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let text = text.trim();
if text.is_empty() {
return None;
}
match self.step.clone() {
Step::Option => {
let keyword = text.trim_start_matches('_').to_ascii_uppercase();
let next = match keyword.as_str() {
"N" | "NEW" => Step::NewName,
"E" | "EDIT" => Step::EditName,
"R" | "RENAME" => Step::RenameOld,
"D" | "DELETE" => Step::DeleteName,
"?" => return Some(CmdResult::Dispatch("-PARAMETERS LIST".to_string())),
_ => return None,
};
self.step = next;
Some(CmdResult::NeedPoint)
}
Step::NewName => {
self.step = Step::NewExpression {
name: text.to_string(),
};
Some(CmdResult::NeedPoint)
}
Step::NewExpression { name } => {
Some(CmdResult::Dispatch(format!("-PARAMETERS NEW {name} {text}")))
}
Step::EditName => Some(CmdResult::Dispatch(format!("-PARAMETERS EDIT {text}"))),
Step::EditExpression { name } => {
Some(CmdResult::Dispatch(format!("-PARAMETERS SET {name} {text}")))
}
Step::RenameOld => {
self.step = Step::RenameNew {
old: text.to_string(),
};
Some(CmdResult::NeedPoint)
}
Step::RenameNew { old } => {
Some(CmdResult::Dispatch(format!("-PARAMETERS RENAME {old} {text}")))
}
Step::DeleteName => Some(CmdResult::Dispatch(format!("-PARAMETERS DELETE {text}"))),
}
}
fn on_point(&mut self, _point: DVec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_escape(&mut self) -> CmdResult {
CmdResult::Cancel
}
}