diff --git a/src/app/command_driver.rs b/src/app/command_driver.rs index 01624ccf7..b5bd1a2d0 100644 --- a/src/app/command_driver.rs +++ b/src/app/command_driver.rs @@ -1838,7 +1838,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::DIMGAP, 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 { diff --git a/src/app/properties.rs b/src/app/properties.rs index d95d8bfd1..7f3fbb2ff 100644 --- a/src/app/properties.rs +++ b/src/app/properties.rs @@ -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(), diff --git a/src/entities/dim_override.rs b/src/entities/dim_override.rs index d9688ea5b..d0f620a7a 100644 --- a/src/entities/dim_override.rs +++ b/src/entities/dim_override.rs @@ -702,12 +702,14 @@ pub fn set_property( | "dim_alt_precision" | "dim_tolerance_precision" | "dim_alt_tolerance_precision" => parse_precision_label(trimmed), + // "On" is text aligned with its dimension line: the horizontal + // flag (DIMTIH/DIMTOH) off. + "dim_text_outside_align" | "dim_text_inside_align" | "dim_line_inside" => { + yes(trimmed).map(|value| i16::from(value == 0)) + } "dim_ext_line_fixed" - | "dim_text_outside_align" - | "dim_text_inside_align" | "dim_text_inside" | "dim_line_forced" - | "dim_line_inside" | "dim_alt_enabled" => yes(trimmed), "dim_decimal_separator" => trimmed .chars() diff --git a/src/entities/dimension.rs b/src/entities/dimension.rs index 880aeeab2..661b8785a 100644 --- a/src/entities/dimension.rs +++ b/src/entities/dimension.rs @@ -2143,7 +2143,7 @@ pub fn style_sections( choice( t!("Text outside align").as_ref(), "dim_text_outside_align", - on(int(ov::DIMTOH, s.dimtoh as i16) != 0), + on(int(ov::DIMTOH, s.dimtoh as i16) == 0), &["On", "Off"], true, ), @@ -2178,9 +2178,15 @@ pub fn style_sections( choice( t!("Text inside align").as_ref(), "dim_text_inside_align", - on(int(ov::DIMTIH, s.dimtih as i16) != 0), + on(int(ov::DIMTIH, s.dimtih as i16) == 0), &["On", "Off"], - dimtix || matches!(dimension, Dimension::LargeRadial(_)), + dimtix + || matches!( + dimension, + Dimension::LargeRadial(_) + | Dimension::Angular2Ln(_) + | Dimension::Angular3Pt(_) + ), ), property( t!("Text position X").as_ref(), @@ -2283,7 +2289,7 @@ pub fn style_sections( choice( t!("Dim line inside").as_ref(), "dim_line_inside", - on(int(ov::DIMSOXD, s.dimsoxd as i16) != 0), + on(int(ov::DIMSOXD, s.dimsoxd as i16) == 0), &["On", "Off"], true, ), @@ -2999,13 +3005,105 @@ pub fn style_sections( ]; } sections.retain(|section| section.title != t!("Alternate Units").as_ref()); + let by_order = |order: &'static [&'static str]| { + move |property: &Property| { + order + .iter() + .position(|field| *field == property.field) + .unwrap_or(order.len()) + } + }; if let Some(tolerances) = sections .iter_mut() .find(|section| section.title == t!("Tolerances").as_ref()) { - tolerances - .props - .retain(|property| !property.field.starts_with("dim_alt_tolerance_")); + tolerances.props.retain(|property| { + !property.field.starts_with("dim_alt_tolerance_") + && !matches!( + property.field, + "dim_tolerance_suppress_zero_feet" | "dim_tolerance_suppress_zero_inches" + ) + }); + tolerances.props.sort_by_key(by_order(&[ + "dim_tolerance_alignment", + "dim_tolerance_display", + "dim_tolerance_limit_lower", + "dim_tolerance_limit_upper", + "dim_tolerance_pos_vert", + "dim_tolerance_precision", + "dim_tolerance_suppress_leading_zeros", + "dim_tolerance_suppress_trailing_zeros", + "dim_tolerance_text_height", + ])); + } + // An arc has no dimension line extension. + if let Some(lines) = sections + .iter_mut() + .find(|section| section.title == t!("Lines & Arrows").as_ref()) + { + lines.props.retain(|property| property.field != "dim_line_ext"); + } + if let Some(fit) = sections + .iter_mut() + .find(|section| section.title == t!("Fit").as_ref()) + { + fit.props.sort_by_key(by_order(&[ + "dim_line_forced", + "dim_line_inside", + "dim_scale_overall", + "dim_fit", + "dim_text_inside", + "dim_text_movement", + ])); + } + if let Some(units) = sections + .iter_mut() + .find(|section| section.title == t!("Primary Units").as_ref()) + { + units.props.sort_by_key(by_order(&[ + "dim_decimal_separator", + "dim_prefix", + "dim_suffix", + "dim_angle_suppress_leading_zeros", + "dim_angle_suppress_trailing_zeros", + "dim_angle_precision", + "dim_angle_units", + ])); + } + // The measurement reads at the angular precision, and automatic text + // reports where it is drawn rather than an unset point. + if let Some(text_section) = sections + .iter_mut() + .find(|section| section.title == t!("Text").as_ref()) + { + let automatic = stored_text_point(dimension) + .is_none() + .then(|| styled_dimension_text_position(dimension, s, 1.0)); + for property in &mut text_section.props { + match property.field { + "measurement" => { + // The row shows the number at the angular precision, + // without the text's degree sign. + let value = format_angular_value( + displayed_measurement(dimension, Some(s)), + Some(s), + ); + property.value = + PropValue::ReadOnly(value.trim_end_matches('°').to_string()); + } + "text_x" => { + if let Some(position) = automatic { + property.value = PropValue::EditText(format!("{:.4}", position.x)); + } + } + "text_y" => { + if let Some(position) = automatic { + property.value = PropValue::EditText(format!("{:.4}", position.y)); + } + } + _ => {} + } + } } } @@ -4724,18 +4822,51 @@ fn dimension_geometry( let (p3, p4) = (lv(d.angle_vertex), lv(d.definition_point)); let arc_point = lv(d.dimension_arc); match two_line_angle_frame(p1, p2, p3, p4, arc_point) { - Some((vertex, start, end)) => append_angular_dimension( - &mut g, - vertex, - vertex, - vertex, - arc_point, - arrow1, - arrow2, - Some((start, end)), - params, - suppress, - ), + Some((vertex, start, end)) => { + // An extension line runs from a side's nearer end out to + // the arc only where the arc lies beyond that side; where + // the arc crosses the side itself there is nothing to add. + let radius = vertex.distance(arc_point); + let side = |angle: f32| -> (Vec3, bool) { + let dir = Vec3::new(angle.cos(), angle.sin(), 0.0); + let deviation = + |a: Vec3, b: Vec3| normalized_or(b - a, dir).cross(dir).length(); + let (a, b) = if deviation(p1, p2) <= deviation(p3, p4) { + (p1, p2) + } else { + (p3, p4) + }; + let along = |p: Vec3| (p - vertex).dot(dir); + let (lo, hi) = (along(a).min(along(b)), along(a).max(along(b))); + let arc_end = vertex + dir * radius; + let near = if a.distance(arc_end) <= b.distance(arc_end) { + a + } else { + b + }; + (near, radius >= lo - 1e-6 && radius <= hi + 1e-6) + }; + let (first, first_covered) = side(start); + let (second, second_covered) = side(end); + let suppress = SuppressFlags { + ext1: suppress.ext1 || first_covered, + ext2: suppress.ext2 || second_covered, + dim1: suppress.dim1, + dim2: suppress.dim2, + }; + append_angular_dimension( + &mut g, + vertex, + first, + second, + arc_point, + arrow1, + arrow2, + Some((start, end)), + params, + suppress, + ) + } // Parallel lines have no vertex and so no angle to draw; the // extension lines alone say where the dimension was. None => { @@ -6357,6 +6488,24 @@ pub(crate) fn dynamic_dimension_lock_anchor( )) } +/// The two ends of an angular dimension's arc, each with the direction +/// pointing away from the arc: where a dynamic angle's triangle grips sit. +pub(crate) fn angular_arc_ends(dim: &Dimension) -> Option<[(glam::DVec3, glam::DVec3); 2]> { + let (vertex, start, end, radius) = angular_dimension_frame(dim)?; + let point = |angle: f32| { + let p = vertex + Vec3::new(angle.cos(), angle.sin(), 0.0) * radius; + glam::DVec3::new(p.x as f64, p.y as f64, p.z as f64) + }; + let away = |angle: f32, sign: f32| { + glam::DVec3::new( + (-angle.sin() * sign) as f64, + (angle.cos() * sign) as f64, + 0.0, + ) + }; + Some([(point(start), away(start, -1.0)), (point(end), away(end, 1.0))]) +} + fn dimension_text_natural_rotation(dim: &Dimension) -> f64 { let angle = match dim { Dimension::Linear(d) => d.rotation, diff --git a/src/scene/parametric_constraints.rs b/src/scene/parametric_constraints.rs index 3081eaf0c..0b8cbe752 100644 --- a/src/scene/parametric_constraints.rs +++ b/src/scene/parametric_constraints.rs @@ -2252,7 +2252,15 @@ impl super::Scene { if self.dimension_is_annotational(handle) { continue; } - for code in [ov::DIMSCALE, ov::DIMGAP, ov::DIMTIH, ov::DIMTOH] { + for code in [ + ov::DIMSCALE, + ov::DIMGAP, + ov::DIMEXO, + ov::DIMEXE, + ov::DIMASZ, + ov::DIMTIH, + ov::DIMTOH, + ] { ov::set(&mut document, handle, code, None); } } @@ -2304,10 +2312,18 @@ impl super::Scene { use crate::entities::dim_override as ov; let xdata = &dimension.base().common.extended_data; let current = ov::real(xdata, ov::DIMSCALE); - // The gap between the text and its line is a quarter of the text - // height on screen, whatever the style's DIMGAP is in units. - let gap = text_height * 0.25; - let gap_set = ov::real(xdata, ov::DIMGAP).is_some_and(|value| (value - gap).abs() < 1e-12); + // Text gap, extension offset and overshoot and arrow size follow + // the text height on screen (the reference's ratios), whatever + // the style says in drawing units. + let sizes = [ + (ov::DIMGAP, text_height * 0.25), + (ov::DIMEXO, text_height * 0.25), + (ov::DIMEXE, text_height * 0.5), + (ov::DIMASZ, text_height), + ]; + let sizes_set = sizes.iter().all(|(code, size)| { + ov::real(xdata, *code).is_some_and(|value| (value - size).abs() < 1e-12) + }); // The reference draws dynamic distance text horizontally; an // angle's text keeps its style's alignment. let angular = matches!( @@ -2317,7 +2333,7 @@ impl super::Scene { ); let horizontal = angular || (ov::int(xdata, ov::DIMTIH) == Some(1) && ov::int(xdata, ov::DIMTOH) == Some(1)); - if current.is_some_and(|value| (value - scale).abs() < 1e-9) && horizontal && gap_set { + if current.is_some_and(|value| (value - scale).abs() < 1e-9) && horizontal && sizes_set { continue; } ov::set( @@ -2326,13 +2342,15 @@ impl super::Scene { ov::DIMSCALE, Some(acadrust::xdata::XDataValue::Real(scale)), ); - if !gap_set { - ov::set( - &mut self.document, - handle, - ov::DIMGAP, - Some(acadrust::xdata::XDataValue::Real(gap)), - ); + if !sizes_set { + for (code, size) in sizes { + ov::set( + &mut self.document, + handle, + code, + Some(acadrust::xdata::XDataValue::Real(size)), + ); + } } if !horizontal { for code in [ov::DIMTIH, ov::DIMTOH] {