Repository navigation
Drawings: ASME zone letters and numbers print at 6 mm #26831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
43c22d4
20c6884
0da83a0
f3f6bbd
b9b8ee4
af21761
cb1bc32
f9053f5
51814ae
044b00b
2068054
e67090e
2ee5711
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ use super::length_format::{LengthFormat, fractional_inches}; | |
| use super::{Drawing, Units, add_by_id, in_id_order, require}; | ||
| use crate::config::MAX_REFERENCE_NAME_BYTES; | ||
| use crate::construct::{MAX_VERTEX_EDGES, point_tolerance, shared_ends}; | ||
| use crate::display_units::unit_scale; | ||
| use crate::display_units::{NumberFormat, decimal_text, format_number, unit_scale}; | ||
| use crate::format::MAX_REAL; | ||
| use solidcraft_feature_drawing::arc_span::{CircleArc, arcs_span_across}; | ||
| use solidcraft_kernel::{EdgeCircle, FaceSurface, PointClass, edge_circle, face_surface}; | ||
|
|
@@ -112,24 +112,27 @@ pub enum LabelKind { | |
| SphericalDiameter, | ||
| } | ||
|
|
||
| /// A length in model millimetres, written in `units` with exactly `decimals` places. | ||
| /// | ||
| /// A dimension asks for the places it shows, in inches as in any other unit. The shared length | ||
| /// helper keeps extra inch digits for labels that did not ask; a dimension did (#25623). | ||
| fn length_as_asked(mm: f64, units: &str, decimals: u8) -> String { | ||
| format!("{:.*}", usize::from(decimals), mm * unit_scale(units).0) | ||
| /// Format a rounded decimal using the profile. The legacy path also covers values | ||
| /// outside the shared formatter's range. | ||
| fn decimal_label(value: f64, decimals: u8, number: NumberFormat) -> String { | ||
| if number == NumberFormat::default() || !value.is_finite() { | ||
| return format!("{:.*}", usize::from(decimals), value); | ||
| } | ||
| format_number(value, decimals, &number) | ||
| .map_or_else(|_| decimal_text(&format!("{:.*}", usize::from(decimals), value.abs()), value.is_sign_negative(), &number), |shown| shown.text) | ||
|
Comment on lines
+121
to
+122
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve rounding when only number presentation changes. For Separate presentation options from rounding, or retain enough input information to distinguish this value from an exact midpoint. Changing trailing-zero presentation must not change the nominal dimension.
|
||
| } | ||
|
|
||
| /// [`length_as_asked`], or fractional inches when `format` asks for them and `units` is the inch. | ||
| /// In any other unit, and for what a fraction cannot show, it is the decimal, as it always was. | ||
| fn length_in_format(mm: f64, units: &str, decimals: u8, format: LengthFormat) -> String { | ||
| /// Fractional inches when the drawing asks for them, or a decimal in the resolved units. | ||
| fn length_in_format(mm: f64, units: &str, decimals: u8, format: LengthFormat, number: NumberFormat) -> String { | ||
| let (scale, _) = unit_scale(units); | ||
| let value = mm * scale; | ||
| if let LengthFormat::FractionalInch { denominator } = format | ||
| && unit_scale(units).0 == unit_scale("in").0 | ||
| && let Some(text) = fractional_inches(mm * unit_scale("in").0, denominator) | ||
| && scale == unit_scale("in").0 | ||
| && let Some(text) = fractional_inches(value, denominator) | ||
| { | ||
| return text; | ||
| } | ||
| length_as_asked(mm, units, decimals) | ||
| decimal_label(value, decimals, number) | ||
| } | ||
|
|
||
| /// What a reading says: `value`, in model millimetres or radians for an angle, in `units` with | ||
|
|
@@ -140,10 +143,17 @@ pub fn reading_label(kind: LabelKind, value: f64, units: &str, decimals: u8) -> | |
|
|
||
| /// [`reading_label`] with the drawing's [`LengthFormat`]. An angle is always a decimal. | ||
| pub fn reading_label_in(kind: LabelKind, value: f64, units: &str, decimals: u8, format: LengthFormat) -> String { | ||
| let length = || length_in_format(value, units, decimals, format); | ||
| profiled_label(kind, value, units, decimals, format, NumberFormat::default()) | ||
| } | ||
|
|
||
| fn profiled_label(kind: LabelKind, value: f64, units: &str, decimals: u8, format: LengthFormat, number: NumberFormat) -> String { | ||
| let length = || length_in_format(value, units, decimals, format, number); | ||
| match kind { | ||
| LabelKind::Length => length(), | ||
| LabelKind::Angle => format!("{:.*}°", usize::from(decimals), value.to_degrees()), | ||
| LabelKind::Angle => { | ||
| let number = NumberFormat { trailing_zeros: true, ..number }; | ||
| format!("{}°", decimal_label(value.to_degrees(), decimals, number)) | ||
| } | ||
| LabelKind::Radius => format!("R{}", length()), | ||
| LabelKind::Diameter => format!("{DIAMETER_SIGN}{}", length()), | ||
| LabelKind::SphericalRadius => format!("SR{}", length()), | ||
|
|
@@ -1247,13 +1257,14 @@ impl Document { | |
| /// drawing doesn't have, or a damaged record. | ||
| pub fn resolve_dimensions(&self, model: &Model, drawing: &Drawing, wanted: &[u64]) -> Result<Vec<Resolved>> { | ||
| let units = self.drawing_units(drawing); | ||
| let number = drawing.dimension_number_format(units); | ||
| let mut lookup = Lookup::new(self, model); | ||
| wanted | ||
| .iter() | ||
| .map(|id| { | ||
| let d = drawing.dimension(*id).ok_or_else(|| DocError::Unknown(format!("dimension {}", ids::encode(*id))))?; | ||
| let basis = drawing.resolve_view(d.view)?.basis; | ||
| Ok(lookup.resolve(d, &basis, units, drawing.length_format)) | ||
| Ok(lookup.resolve(d, &basis, units, drawing.length_format, number)) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
@@ -1513,7 +1524,7 @@ impl<'a> Lookup<'a> { | |
| Lookup { doc, model, state: model.state(), named: BTreeMap::new(), curved: BTreeMap::new(), leads: BTreeMap::new() } | ||
| } | ||
|
|
||
| fn resolve(&mut self, d: &Dimension, basis: &Plane, units: &str, format: LengthFormat) -> Resolved { | ||
| fn resolve(&mut self, d: &Dimension, basis: &Plane, units: &str, format: LengthFormat, number: NumberFormat) -> Resolved { | ||
| let (status, found) = match self.measure(d, basis) { | ||
| // A text that shows the measured number follows the model, as a plain dimension does: | ||
| // only one that hides the number is typed over it. | ||
|
|
@@ -1524,8 +1535,8 @@ impl<'a> Lookup<'a> { | |
| }; | ||
| let measured = found.as_ref().map(|f| f.measured); | ||
| let label = found.as_ref().and_then(|f| f.label.or_else(|| label_of(&d.kind))); | ||
| let length = |m: Measured| length_in_format(m.value, units, d.decimals, format); | ||
| let number = measured.zip(label).map(|(m, kind)| reading_label_in(kind, m.value, units, d.decimals, format)); | ||
| let length = |m: Measured| length_in_format(m.value, units, d.decimals, format, number); | ||
| let number = measured.zip(label).map(|(m, kind)| profiled_label(kind, m.value, units, d.decimals, format, number)); | ||
| let (members, points, exact) = found.map_or_else(Default::default, |f| (f.members, f.points, f.exact)); | ||
| Resolved { | ||
| status, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| //! A drawing can save its own copy of a drafting profile. Older drawings without one use the | ||
| //! built-in profile for their existing drawing standard. The last release opens such a drawing | ||
| //! with a newer-format warning and preserves the profile it cannot read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes a default: Keep legacy dimension formatting until a profile is selected.
For an existing ANSI B metric drawing without a saved profile, this fallback selects ASME automatically. An 80 mm dimension with
decimals=2previously displayed80.00. It now displays80because the ASME profile disables trailing zeros.An explicitly saved legacy number format can retain the previous presentation, but existing drawings receive no migration or opt-in. The supplied PR description has no
Changes a default:line. Preserve legacy formatting when the profile is absent, and apply ASME formatting when users select it.As per path instructions, flag changes to existing UI behavior for users who did not opt in.
Source: Path instructions