forked from 1b-agent/opencadstudio-upstream
Merge pull request #1431 from ramox81:codex/angular-constraint-parity
This commit is contained in:
commit
d37ce4d617
12 files changed
+1278
-205
No files matched your search
+225
-5
@@ -1527,8 +1527,12 @@ impl OpenCADStudio {
|
||||
Some(crate::scene::named_parameters::DrivingValue::Named(_))
|
||||
)
|
||||
})
|
||||
.filter_map(|c| c.refs.first().copied())
|
||||
.filter(|reference| reference.marker.is_some())
|
||||
.flat_map(|c| {
|
||||
crate::scene::parametric_constraints::dimensional_anchor_refs(
|
||||
&self.tabs[i].scene.document,
|
||||
&c.refs,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let pending = self.begin_undo(i, "Apply named parameters", touched.len(), true);
|
||||
self.tabs[i].scene.record_undo_named_parameters_before();
|
||||
@@ -1590,7 +1594,6 @@ impl OpenCADStudio {
|
||||
&c.refs,
|
||||
)
|
||||
})
|
||||
.filter(|reference| reference.marker.is_some())
|
||||
.collect();
|
||||
self.tabs[i].dirty = true;
|
||||
if touched.is_empty() {
|
||||
@@ -1845,7 +1848,15 @@ impl OpenCADStudio {
|
||||
entity.common_mut().color = acadrust::types::Color::ByLayer;
|
||||
// The dynamic form's screen-size and horizontal-text
|
||||
// overrides go; the style draws it.
|
||||
for code in [dov::DIMSCALE, dov::DIMTIH, dov::DIMTOH] {
|
||||
for code in [
|
||||
dov::DIMSCALE,
|
||||
dov::DIMGAP,
|
||||
dov::DIMEXO,
|
||||
dov::DIMEXE,
|
||||
dov::DIMASZ,
|
||||
dov::DIMTIH,
|
||||
dov::DIMTOH,
|
||||
] {
|
||||
dov::set_on_entity(&mut entity, code, None);
|
||||
}
|
||||
} else {
|
||||
@@ -4049,6 +4060,7 @@ impl OpenCADStudio {
|
||||
direction,
|
||||
name,
|
||||
expression,
|
||||
renamed,
|
||||
label,
|
||||
} => {
|
||||
use crate::modules::annotate::{aligned_dim, linear_dim};
|
||||
@@ -4104,7 +4116,14 @@ impl OpenCADStudio {
|
||||
);
|
||||
let name = name.trim().to_string();
|
||||
if !is_valid_name(&name) {
|
||||
self.reprompt_active_command(i, "Invalid parameter name.");
|
||||
self.command_line.push_error(
|
||||
"Only alphanumeric names, starting with alpha characters, are allowed.",
|
||||
);
|
||||
self.reprompt_active_command(i, &format!("Invalid parameter name: {name}."));
|
||||
return Task::none();
|
||||
}
|
||||
if renamed && self.tabs[i].scene.named_parameters().contains(&name) {
|
||||
self.reprompt_active_command(i, "Parameter with this name already exists.");
|
||||
return Task::none();
|
||||
}
|
||||
let mut table = self.tabs[i].scene.named_parameters().clone();
|
||||
@@ -4133,6 +4152,7 @@ impl OpenCADStudio {
|
||||
false,
|
||||
Some(&expression),
|
||||
annotational,
|
||||
None,
|
||||
);
|
||||
let mut entity = if kind == ConstraintKind::Distance {
|
||||
aligned_dim::aligned_dimension_entity(
|
||||
@@ -4232,6 +4252,206 @@ impl OpenCADStudio {
|
||||
self.commit_undo_delta(i, pd);
|
||||
}
|
||||
}
|
||||
CmdResult::CancelWithMessage(message) => {
|
||||
self.command_line.push_error(&message);
|
||||
return self.apply_cmd_result(CmdResult::Cancel);
|
||||
}
|
||||
CmdResult::AddAngularConstraint {
|
||||
refs,
|
||||
points,
|
||||
location,
|
||||
sector,
|
||||
name,
|
||||
expression,
|
||||
renamed,
|
||||
} => {
|
||||
use crate::modules::annotate::angular_dim;
|
||||
use crate::scene::named_parameters::{is_valid_name, DrivingValue};
|
||||
use crate::scene::parametric_constraints::{
|
||||
angle_decimals, dynamic_dimension_text, ConstraintKind, ParametricRef,
|
||||
};
|
||||
|
||||
let scope = self.tabs[i].current_parametric_scope();
|
||||
let kind = if refs.len() == 2 {
|
||||
ConstraintKind::Angle
|
||||
} else {
|
||||
ConstraintKind::Angle3Point
|
||||
};
|
||||
// The same angle between the same sides is refused after the
|
||||
// value (whichever sector), and the command ends.
|
||||
let duplicate = self.tabs[i]
|
||||
.scene
|
||||
.parametric_constraint_set(scope)
|
||||
.is_some_and(|set| {
|
||||
set.constraints.iter().any(|c| {
|
||||
c.enabled
|
||||
&& c.kind == kind
|
||||
&& c.refs.len() == refs.len()
|
||||
&& if kind == ConstraintKind::Angle {
|
||||
c.refs.contains(&refs[0]) && c.refs.contains(&refs[1])
|
||||
} else {
|
||||
c.refs == refs
|
||||
}
|
||||
})
|
||||
});
|
||||
if duplicate {
|
||||
self.command_line
|
||||
.push_output("The constraint already exists on the selected objects.");
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.tabs[i].snap_result = None;
|
||||
return Task::none();
|
||||
}
|
||||
if let Err(message) = self.tabs[i].scene.validate_parametric_constraint(
|
||||
kind,
|
||||
&refs,
|
||||
Some(&DrivingValue::Literal(1.0)),
|
||||
) {
|
||||
self.reprompt_active_command(i, message);
|
||||
return Task::none();
|
||||
}
|
||||
let name = name.trim().to_string();
|
||||
if !is_valid_name(&name) {
|
||||
self.command_line.push_error(
|
||||
"Only alphanumeric names, starting with alpha characters, are allowed.",
|
||||
);
|
||||
self.reprompt_active_command(i, &format!("Invalid parameter name: {name}."));
|
||||
return Task::none();
|
||||
}
|
||||
if renamed && self.tabs[i].scene.named_parameters().contains(&name) {
|
||||
self.reprompt_active_command(i, "Parameter with this name already exists.");
|
||||
return Task::none();
|
||||
}
|
||||
let mut table = self.tabs[i].scene.named_parameters().clone();
|
||||
if let Err(error) = table.set(&name, &expression) {
|
||||
self.reprompt_active_command(i, &error.to_string());
|
||||
return Task::none();
|
||||
}
|
||||
let value = match table.resolve(&name) {
|
||||
Ok(value) if value.is_finite() => value,
|
||||
_ => {
|
||||
self.command_line.push_error("Invalid expression.");
|
||||
self.reprompt_active_command(
|
||||
i,
|
||||
"The parameter is used in an expression which results in an invalid value for a dimensional constraint.",
|
||||
);
|
||||
return Task::none();
|
||||
}
|
||||
};
|
||||
let annotational = self.constraint_form_annotational;
|
||||
let decimals = angle_decimals(&self.tabs[i].scene.document, None);
|
||||
let text = dynamic_dimension_text(
|
||||
&name,
|
||||
value,
|
||||
self.tabs[i].scene.constraint_name_format,
|
||||
false,
|
||||
Some(&expression),
|
||||
annotational,
|
||||
Some(decimals),
|
||||
);
|
||||
let entity = if kind == ConstraintKind::Angle {
|
||||
angular_dim::angular_two_line_entity(
|
||||
points[0], points[1], points[2], points[3], location, Some(text),
|
||||
)
|
||||
} else {
|
||||
angular_dim::angular_three_point_entity(
|
||||
points[0], points[1], points[2], location, Some(text),
|
||||
)
|
||||
};
|
||||
let Some(mut entity) = entity else {
|
||||
self.reprompt_active_command(i, "No valid constraint point found.");
|
||||
return Task::none();
|
||||
};
|
||||
crate::scene::creation_style::apply_current_creation_styles(
|
||||
&self.tabs[i].scene.document,
|
||||
&mut entity,
|
||||
);
|
||||
if annotational {
|
||||
entity
|
||||
.as_entity_mut()
|
||||
.set_layer(self.tabs[i].active_layer.clone());
|
||||
} else {
|
||||
self.tabs[i].scene.ensure_dynamic_dimension_layer();
|
||||
entity.as_entity_mut().set_layer(
|
||||
crate::scene::parametric_constraints::DYNAMIC_DIMENSION_LAYER.to_string(),
|
||||
);
|
||||
entity.common_mut().color = acadrust::types::Color::Rgb {
|
||||
r: 103,
|
||||
g: 109,
|
||||
b: 118,
|
||||
};
|
||||
}
|
||||
let constraints_before = self.tabs[i]
|
||||
.scene
|
||||
.parametric_constraint_set(scope)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
crate::scene::parametric_constraints::ParametricConstraintSet::new(scope)
|
||||
});
|
||||
let mut touched: Vec<Handle> = Vec::new();
|
||||
for reference in &refs {
|
||||
if !touched.contains(&reference.entity) {
|
||||
touched.push(reference.entity);
|
||||
}
|
||||
}
|
||||
// The first side (or the vertex and first point) stays; a
|
||||
// value other than the measured one turns the other side.
|
||||
let anchors: Vec<ParametricRef> =
|
||||
crate::scene::parametric_constraints::dimensional_anchor_refs(
|
||||
&self.tabs[i].scene.document,
|
||||
&refs,
|
||||
);
|
||||
let association = if kind == ConstraintKind::Angle {
|
||||
vec![
|
||||
Some(refs[0].entity),
|
||||
Some(refs[0].entity),
|
||||
Some(refs[1].entity),
|
||||
Some(refs[1].entity),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
Some(refs[1].entity),
|
||||
Some(refs[0].entity),
|
||||
Some(refs[2].entity),
|
||||
]
|
||||
};
|
||||
let pending = self.begin_undo(i, "Angular constraint", touched.len() + 1, false);
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.record_undo_parametric_constraints_before(scope, constraints_before);
|
||||
self.tabs[i].scene.record_undo_named_parameters_before();
|
||||
self.tabs[i].scene.named_parameters = table;
|
||||
let dimension = self.tabs[i].scene.add_entity(entity);
|
||||
let set = self.tabs[i].scene.parametric_constraint_set_mut(scope);
|
||||
let id = set.add(kind, refs, Some(DrivingValue::Named(name)));
|
||||
if let Some(constraint) = set.constraints.iter_mut().find(|c| c.id == id) {
|
||||
constraint.angle_sector = sector;
|
||||
}
|
||||
set.dimensions.insert(id, dimension);
|
||||
self.tabs[i].scene.note_parametric_constraint_applied(
|
||||
scope,
|
||||
id,
|
||||
self.constraint_bar_display,
|
||||
);
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.attach_dimension_association(dimension, association);
|
||||
let changes: Vec<(Handle, crate::scene::ChangeKind)> = touched
|
||||
.into_iter()
|
||||
.map(|handle| (handle, crate::scene::ChangeKind::Modified))
|
||||
.collect();
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.bump_entities_with_parametric_policy(&changes, &anchors, false);
|
||||
self.tabs[i].scene.refresh_hidden_dynamic_dimensions();
|
||||
self.tabs[i].scene.refresh_dynamic_dimension_scales(true);
|
||||
self.tabs[i].dirty = true;
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.tabs[i].snap_result = None;
|
||||
self.refresh_properties();
|
||||
if let Some(pd) = pending {
|
||||
self.commit_undo_delta(i, pd);
|
||||
}
|
||||
}
|
||||
CmdResult::MakeParallel {
|
||||
first_line,
|
||||
first_ends,
|
||||
|
||||
+16
-43
@@ -1569,10 +1569,8 @@ impl OpenCADStudio {
|
||||
table
|
||||
.iter()
|
||||
.map(|parameter| {
|
||||
let value = table
|
||||
.resolve(¶meter.name)
|
||||
.map(|value| format!("{value:.4}"))
|
||||
.unwrap_or_else(|_| "**".to_string());
|
||||
let value =
|
||||
self.tabs[i].scene.parameter_value_text(¶meter.name);
|
||||
format!(
|
||||
"Parameter: {:<12} Expression: {:<21} Value: {value}",
|
||||
parameter.name, parameter.source
|
||||
@@ -1597,10 +1595,7 @@ impl OpenCADStudio {
|
||||
let old = {
|
||||
let table = self.tabs[i].scene.named_parameters();
|
||||
table.get(&name).map(|parameter| {
|
||||
let value = table
|
||||
.resolve(&name)
|
||||
.map(|value| format!("{value:.4}"))
|
||||
.unwrap_or_else(|_| "**".to_string());
|
||||
let value = self.tabs[i].scene.parameter_value_text(&name);
|
||||
format!("Old Expression = {}, Value = {value}", parameter.source)
|
||||
})
|
||||
};
|
||||
@@ -1941,41 +1936,19 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
"ACONSTRAINT" | "DCANGULAR" => {
|
||||
if cmd == "DCANGULAR" {
|
||||
self.dim_constraint_last = "ANgular";
|
||||
}
|
||||
let handles = self.tabs[i].scene.selected_handles_in_order();
|
||||
if handles.is_empty() {
|
||||
use crate::modules::draw::select::SelectObjectsCommand;
|
||||
let sel = SelectObjectsCommand::new(cmd);
|
||||
self.command_line.push_info(&sel.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(sel));
|
||||
} else if handles.len() != 2 {
|
||||
self.command_line.push_output(
|
||||
"Select exactly two lines (first = reference, second = the one that rotates), then run this constraint again.",
|
||||
);
|
||||
} else {
|
||||
use crate::modules::parametric::AngleConstraintCommand;
|
||||
let command_name = if cmd == "DCANGULAR" {
|
||||
"DCANGULAR"
|
||||
} else {
|
||||
"ACONSTRAINT"
|
||||
};
|
||||
match AngleConstraintCommand::with_name(
|
||||
&self.tabs[i].scene,
|
||||
handles[0],
|
||||
handles[1],
|
||||
command_name,
|
||||
) {
|
||||
Some(new_cmd) => {
|
||||
self.command_line.push_info(&new_cmd.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
|
||||
}
|
||||
None => self
|
||||
.command_line
|
||||
.push_output("Select two lines for an angle constraint."),
|
||||
}
|
||||
}
|
||||
use crate::modules::parametric::{DimConstraintAxis, DimConstraintCommand};
|
||||
use crate::scene::parametric_constraints::{
|
||||
angle_decimals, next_angular_parameter_name,
|
||||
};
|
||||
self.dim_constraint_last = "ANgular";
|
||||
let name = next_angular_parameter_name(self.tabs[i].scene.named_parameters());
|
||||
let decimals = angle_decimals(&self.tabs[i].scene.document, None);
|
||||
// Both sides are picked inside the command.
|
||||
self.tabs[i].scene.deselect_all();
|
||||
let command = DimConstraintCommand::new(DimConstraintAxis::Angular, name)
|
||||
.with_angle_decimals(decimals);
|
||||
self.command_line.push_info(&command.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(command));
|
||||
}
|
||||
|
||||
// ── Model commands (3D primitives) ─────────────────────────────
|
||||
|
||||
@@ -1054,6 +1054,7 @@ impl OpenCADStudio {
|
||||
| "CONSTRAINTBARMODE"
|
||||
| "CONSTRAINTNAMEFORMAT"
|
||||
| "DYNCONSTRAINTDISPLAY"
|
||||
| "CCONSTRAINTFORM"
|
||||
) =>
|
||||
{
|
||||
return self.dispatch_styleprops(&format!("SETVAR {cmd}"), i);
|
||||
@@ -1279,6 +1280,7 @@ impl OpenCADStudio {
|
||||
| "CONSTRAINTBARMODE"
|
||||
| "CONSTRAINTNAMEFORMAT"
|
||||
| "DYNCONSTRAINTDISPLAY"
|
||||
| "CCONSTRAINTFORM"
|
||||
) {
|
||||
let current = match name.as_str() {
|
||||
"CONSTRAINTSOLVEMODE" => i16::from(self.constraint_solve_mode),
|
||||
@@ -1291,6 +1293,7 @@ impl OpenCADStudio {
|
||||
"DYNCONSTRAINTDISPLAY" => {
|
||||
i16::from(self.tabs[i].scene.dynamic_constraint_display)
|
||||
}
|
||||
"CCONSTRAINTFORM" => i16::from(self.constraint_form_annotational),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let maximum = match name.as_str() {
|
||||
@@ -1325,6 +1328,11 @@ impl OpenCADStudio {
|
||||
mode != 0;
|
||||
self.tabs[i].scene.refresh_hidden_dynamic_dimensions();
|
||||
}
|
||||
// The form new dimensional constraints take
|
||||
// (0 dynamic, 1 annotational), as DCFORM sets.
|
||||
"CCONSTRAINTFORM" => {
|
||||
self.constraint_form_annotational = mode != 0
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
self.persist_settings_if_changed();
|
||||
|
||||
+89
-8
@@ -2342,6 +2342,8 @@ impl OpenCADStudio {
|
||||
handle,
|
||||
) {
|
||||
Some((set, constraint)) => {
|
||||
let annotational =
|
||||
self.tabs[i].scene.dimension_is_annotational(handle);
|
||||
sections = dynamic_dimension_sections(
|
||||
&self.tabs[i].scene,
|
||||
handle,
|
||||
@@ -2349,11 +2351,23 @@ impl OpenCADStudio {
|
||||
constraint,
|
||||
sections,
|
||||
);
|
||||
match entity {
|
||||
acadrust::EntityType::Dimension(
|
||||
acadrust::entities::Dimension::Aligned(_),
|
||||
) => t!("Aligned Dimensional Constraint").into_owned(),
|
||||
_ => t!("Linear Dimensional Constraint").into_owned(),
|
||||
// An annotational constraint is an ordinary
|
||||
// dimension to the panel; the dynamic form is
|
||||
// named after its constraint.
|
||||
if annotational {
|
||||
title
|
||||
} else {
|
||||
use acadrust::entities::Dimension;
|
||||
match entity {
|
||||
acadrust::EntityType::Dimension(Dimension::Aligned(_)) => {
|
||||
t!("Aligned Dimensional Constraint")
|
||||
}
|
||||
acadrust::EntityType::Dimension(
|
||||
Dimension::Angular2Ln(_) | Dimension::Angular3Pt(_),
|
||||
) => t!("Angular Dimensional Constraint"),
|
||||
_ => t!("Linear Dimensional Constraint"),
|
||||
}
|
||||
.into_owned()
|
||||
}
|
||||
}
|
||||
None => title,
|
||||
@@ -2805,7 +2819,35 @@ handles={handles_ms:.1} panel={:.1} ribbon={ribbon_ms:.1} tail={:.1} selected={}
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.tabs[i].scene.is_dynamic_dimension(handle) {
|
||||
let dynamic_angle = match contextual.as_ref() {
|
||||
acadrust::EntityType::Dimension(
|
||||
dim @ (acadrust::entities::Dimension::Angular2Ln(_)
|
||||
| acadrust::entities::Dimension::Angular3Pt(_)),
|
||||
) if self.tabs[i].scene.is_dynamic_dimension(handle) => Some(dim),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(dim) = dynamic_angle {
|
||||
// A dynamic angle shows a triangle at each end of its arc
|
||||
// pointing away from it, and squares at the arc point and
|
||||
// the text — nothing on the sides.
|
||||
let (arc_id, text_id) =
|
||||
if matches!(dim, acadrust::entities::Dimension::Angular2Ln(_)) {
|
||||
(4, 5)
|
||||
} else {
|
||||
(3, 4)
|
||||
};
|
||||
if let Some(ends) = crate::entities::dimension::angular_arc_ends(dim) {
|
||||
entity_grips.retain(|grip| grip.id == arc_id || grip.id == text_id);
|
||||
for (point, away) in ends {
|
||||
entity_grips.insert(
|
||||
0,
|
||||
crate::entities::common::oriented_triangle_grip(
|
||||
arc_id, point, away,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if self.tabs[i].scene.is_dynamic_dimension(handle) {
|
||||
// A dynamic dimension shows the reference's grips: a
|
||||
// triangle at each constraint point aimed at the other
|
||||
// one, and the text square — no dimension line grip.
|
||||
@@ -3738,7 +3780,14 @@ fn dynamic_dimension_sections(
|
||||
row(
|
||||
t!("Value").as_ref(),
|
||||
"dyn_constraint_value",
|
||||
PropValue::ReadOnly(value.map(|v| format!("{v:.4}")).unwrap_or_default()),
|
||||
// An angle's value reads at the angular precision, as on the
|
||||
// dimension and in -PARAMETERS.
|
||||
PropValue::ReadOnly(match &constraint.driving_param {
|
||||
Some(DrivingValue::Named(name)) if set.local_parameters.is_empty() => {
|
||||
scene.parameter_value_text(name)
|
||||
}
|
||||
_ => value.map(|v| format!("{v:.4}")).unwrap_or_default(),
|
||||
}),
|
||||
),
|
||||
row(
|
||||
t!("Description").as_ref(),
|
||||
@@ -3748,7 +3797,39 @@ fn dynamic_dimension_sections(
|
||||
],
|
||||
}];
|
||||
if annotational {
|
||||
result.extend(sections);
|
||||
// The reference lists General first, then the constraint, then the
|
||||
// dimension's own groups; the constraint's dimension is not an
|
||||
// associative dimension to it, and its text is the constraint's.
|
||||
let mut sections = sections;
|
||||
sections.retain(|section| {
|
||||
section.title != t!("3D Visualization").as_ref()
|
||||
&& section.title != "Associative Data"
|
||||
});
|
||||
for section in &mut sections {
|
||||
section
|
||||
.props
|
||||
.retain(|property| property.field != "association_status");
|
||||
for property in &mut section.props {
|
||||
match property.field {
|
||||
"associative" => property.value = PropValue::ReadOnly("No".to_string()),
|
||||
"text_override" => {
|
||||
if let PropValue::PlainText(text) | PropValue::EditText(text) =
|
||||
&property.value
|
||||
{
|
||||
property.value = PropValue::ReadOnly(text.clone());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
let constraint_section = result.remove(0);
|
||||
let general = (!sections.is_empty()).then(|| sections.remove(0));
|
||||
result = general
|
||||
.into_iter()
|
||||
.chain(std::iter::once(constraint_section))
|
||||
.chain(sections)
|
||||
.collect();
|
||||
} else if let Some(text_rotation) = text_rotation {
|
||||
result.push(PropSection {
|
||||
title: t!("Text").into_owned(),
|
||||
|
||||
Reference in new issue
Block a user