use std::collections::{BTreeMap, BTreeSet};
use serde::Serialize;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Impact {
Incomplete,
Decision,
Readability,
Advisory,
}
#[derive(Clone, Copy)]
enum Group {
Code,
Feature,
Requirement,
Crossing,
Source,
Shape,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Tier {
FixBeforePrinting,
Tidy,
Information,
}
impl Tier {
pub const ALL: [Self; 3] = [Self::FixBeforePrinting, Self::Tidy, Self::Information];
pub fn as_str(self) -> &'static str {
match self {
Self::FixBeforePrinting => "fix_before_printing",
Self::Tidy => "tidy",
Self::Information => "information",
}
}
}
#[derive(Clone, Copy)]
enum TierRule {
FixBeforePrinting,
Tidy,
Information,
Requirement,
}
impl TierRule {
fn resolve(self, info: bool) -> Tier {
match self {
Self::FixBeforePrinting => Tier::FixBeforePrinting,
Self::Tidy => Tier::Tidy,
Self::Information => Tier::Information,
Self::Requirement => {
if info {
Tier::Information
} else {
Tier::FixBeforePrinting
}
}
}
}
#[cfg(test)]
fn documented(self) -> &'static str {
match self {
Self::FixBeforePrinting => "fix_before_printing",
Self::Tidy => "tidy",
Self::Information => "information",
Self::Requirement => "fix_before_printing (information when severity=info)",
}
}
}
struct Classification {
code: &'static str,
impact: Impact,
kind: RegisteredCode,
group: Group,
#[cfg_attr(not(test), allow(dead_code))]
reason: &'static str,
}
macro_rules! catalogue {
($($code:ident => $impact:ident, $tier:ident, $group:ident, $reason:literal;)*) => {
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
enum RegisteredCode { $($code),* }
impl RegisteredCode {
fn tier_rule(self) -> TierRule {
match self { $(Self::$code => TierRule::$tier),* }
}
}
const CODES: &[Classification] = &[$(Classification {
code: stringify!($code), impact: Impact::$impact, kind: RegisteredCode::$code, group: Group::$group, reason: $reason,
}),*];
};
}
catalogue! {
angled_step_requirement_unsupported => Incomplete, Requirement, Requirement, "No supported drawing grammar states this feature requirement.";
angular_dimension_dropped => Advisory, Tidy, Code, "An automatic profile-corner angle found no clear place and is not drawn; lint still reports the corner.";
angular_geometry_mismatch => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
angular_label_vs_geometry => Incomplete, Requirement, Code, "The printed angle does not state the measured angular sector.";
angular_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
angular_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
angular_support_mismatch => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
annotation_edit_unapplied => Decision, FixBeforePrinting, Code, "A saved annotation edit has no current item; its intent is retained.";
annotation_ink_overlap => Readability, FixBeforePrinting, Code, "Annotation ink impairs the legibility of another annotation; leader-through-text is included.";
annotation_leader_crossing => Readability, Tidy, Crossing, "Leader, dimension-line or arrow crossings impair reading; extension-only crossings are advisory.";
annotation_leader_long => Readability, Tidy, Code, "The leader is longer than the preferred reading distance.";
annotation_leader_search_capped => Advisory, Information, Code, "The bounded leader search stopped; this reports search provenance.";
annotation_line_over_view => Readability, Tidy, Code, "Annotation linework overlaps a view.";
annotation_off_sheet => Readability, FixBeforePrinting, Code, "Annotation ink extends outside the sheet.";
annotation_out_of_bounds => Readability, FixBeforePrinting, Code, "Rendered annotation ink extends outside the drawing bounds.";
annotation_outside_area => Readability, Tidy, Code, "The annotation leaves its reserved view area.";
annotation_over_title_block => Readability, FixBeforePrinting, Code, "Annotation ink overlaps the title block.";
annotation_over_view => Readability, FixBeforePrinting, Code, "An annotation overlaps view geometry.";
annotation_overlap => Readability, FixBeforePrinting, Code, "Annotation labels overlap each other.";
annular_groove_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
annular_groove_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
assembly_drawn_whole => Advisory, Information, Code, "The complete assembly was selected for drawing.";
assembly_principal_drawn => Advisory, Information, Code, "The assembly's largest part, holding the others, was drawn alone; the others are not drawn.";
authored_dimension_invalid => Decision, FixBeforePrinting, Code, "The authored dimension needs a valid user definition.";
automatic_scale_limited => Advisory, Information, Code, "Larger automatic scales were refused for the reported fit or readability reasons.";
axial_length_missing => Incomplete, Requirement, Code, "The drawing does not state the axial length.";
balloon_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
blend_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
blend_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
boss_height_missing => Incomplete, Requirement, Code, "The drawing does not state the boss height.";
boss_height_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
boss_height_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
break_anchor_removed => Incomplete, Requirement, Code, "An annotation anchors in the removed span; its attachment needs an unbroken region.";
break_not_applied => Decision, Tidy, Code, "The requested break has no proven uniform span or carrying view.";
callout_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
chamfer_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The chamfer leader points at the wrong geometry.";
chamfer_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The chamfer leader target cannot be verified.";
chamfer_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
chamfer_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
channel_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
channel_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
characteristic_balloon_missing => Incomplete, Requirement, Source, "A numbered characteristic has no inspection balloon while inspection is enabled.";
characteristic_id_ambiguous => Incomplete, Requirement, Source, "Duplicate requirement ids leave its inspection number unknown.";
characteristic_not_drawn => Incomplete, Requirement, Source, "A numbered characteristic has no drawn carrier.";
characteristic_number_conflict => Decision, Information, Source, "The requirement id and legacy UDA disagree; the id supplies the inspection number.";
circular_blind_step_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
circular_blind_step_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
circular_channel_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
circular_channel_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
claimed_value_absent => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
closed_dimension_chain => Advisory, Tidy, Code, "A closed chain is redundant dimension information.";
coincident_bodies => Advisory, Information, Code, "The file holds bodies that coincide with another; one of each is drawn when every body does.";
correlated_set_conflict => Decision, FixBeforePrinting, Code, "The authored choice splits a set that must be kept together.";
correlated_set_whole => Advisory, Information, Code, "A correlated dimension set was kept together.";
cross_reference_missing => Incomplete, Requirement, Code, "A required cross-sheet or derived-view reference is absent.";
datum_leader_not_normal => Readability, Tidy, Code, "The datum leader does not leave its triangle square to the face.";
datum_leader_remote => Readability, Tidy, Code, "The datum symbol is too far from its referenced surface.";
datum_not_drawn => Advisory, Information, Code, "A declared datum no frame cites and no dimension measures from is not drawn.";
datum_not_identified => Incomplete, Requirement, Code, "A referenced datum lacks its identifying symbol.";
datum_origin_unusable => Advisory, Information, Code, "The datum cannot define this origin; the documented fallback is used.";
datum_symbol_overlap => Readability, FixBeforePrinting, Code, "Datum symbols overlap other annotations.";
datum_undeclared => Decision, FixBeforePrinting, Code, "A control references a datum the user must declare.";
declared_units => Advisory, Information, Code, "Printed units default to the part's declared inch length unit; the Spec retains the omitted preference.";
derived_view_identifier_reused => Readability, FixBeforePrinting, Code, "A reused view identifier makes references ambiguous.";
detail_caption_clearance => Readability, Tidy, Code, "The detail caption is too close to other ink.";
detail_unplaceable => Readability, Tidy, Code, "A detail has no room; its dimensions remain on the parent view.";
diameter_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The diameter leader points at the wrong geometry.";
diameter_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The diameter leader target cannot be verified.";
dimension_edit_unapplied => Decision, FixBeforePrinting, Code, "A saved dimension or precision edit has no current printed item; its intent is retained.";
dimension_line_crossing => Readability, Tidy, Code, "Dimension lines cross each other.";
dimension_line_shared => Readability, Tidy, Code, "Dimension strokes share a line and are harder to distinguish.";
dimension_not_authored => Incomplete, Requirement, Code, "Authored-only dimensioning leaves this required dimension absent.";
dimension_scheme_invalid => Decision, FixBeforePrinting, Code, "The authored dimension scheme needs a valid user definition.";
dimension_text_stray => Readability, FixBeforePrinting, Code, "Dimension text is displaced from its own span.";
dimension_view_not_shown => Incomplete, Requirement, Code, "The dimension requires a view that is not drawn.";
dimension_witness_detached => Incomplete, Requirement, Code, "A detached witness or depth leader misstates where the dimension applies; the required measurement cannot be verified on the drawing.";
dimensions_not_ported => Incomplete, Tidy, Feature, "An unimplemented dimension grammar is a drafting-quality hint for this feature.";
duplicate_measurement => Advisory, Tidy, Code, "The same measurement is repeated on the drawing.";
edges_not_drawn => Incomplete, Requirement, Code, "Failed projection left model edges absent from the drawing.";
engine_pins_partly_retained => Decision, Tidy, Code, "Missing or changed annotation pins were released while surviving placements were retained.";
engine_pins_replanned => Decision, Tidy, Code, "Stale or incompatible engine placement pins were released and the drawing was re-planned.";
extension_off_centreline => Readability, FixBeforePrinting, Code, "An extension line lies just beside a centre line, so it reads as locating that centre.";
extension_through_feature => Advisory, Tidy, Code, "Extension lines crossing geometry are normal drafting practice.";
feature_count_mismatch => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
feature_located_twice => Advisory, Tidy, Code, "Repeated location information is reported for review.";
feature_no_centermark => Incomplete, Requirement, Code, "The required hole centre mark is absent from the drawing.";
feature_not_dimensioned => Incomplete, Requirement, Feature, "The feature has no drawn dimension that states its requirement.";
feature_not_located => Incomplete, Requirement, Feature, "The drawing does not state the feature location.";
feature_not_sized => Incomplete, Requirement, Feature, "The drawing does not state the feature size.";
features_not_recognised => Incomplete, Tidy, Code, "Unsupported recognition is a drafting-quality hint; unowned faces need not be a problem.";
fillet_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
fillet_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
fit_deviations_unavailable => Advisory, Information, Code, "The valid fit class states the requirement; optional numerical deviations are unavailable.";
flat_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The flat leader points at the wrong geometry.";
flat_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The flat leader target cannot be verified.";
flat_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
flat_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
frame_datum_not_drawn => Incomplete, Requirement, Source, "A drawn feature control frame cites a datum the drawing does not show.";
gdt_position_changed => Decision, Tidy, Code, "Dimension placement moved an unrelated GD&T item; the warning names the item and cause.";
gear_axis_mismatch => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
gear_correspondence_unverifiable => Incomplete, Requirement, Code, "The source gear requirement cannot be matched to the depicted gear.";
gear_repeat_count_mismatch => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
gear_requirement_ambiguous => Decision, FixBeforePrinting, Requirement, "Several authored gear definitions compete for the same feature.";
gear_requirement_mismatch => Incomplete, Requirement, Requirement, "The drawn evidence does not correctly state the required source information.";
gear_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
gear_semantics_missing => Decision, FixBeforePrinting, Code, "Gear manufacturing semantics must be supplied by the user.";
general_tolerance_missing => Decision, FixBeforePrinting, Code, "Only the user can choose the general tolerance.";
geometry_below_resolution => Readability, Tidy, Code, "Geometry projected below normal drawing resolution is a drafting-quality concern.";
groove_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
groove_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
gusset_rib_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
gusset_rib_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
hex_pocket_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
hex_pocket_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
hole_bottom_unknown => Incomplete, Requirement, Code, "The hole termination needed for a complete callout is unknown.";
hole_exit_obstructed => Advisory, Information, Code, "A through hole has a partly obstructed exit; covering geometry and fraction are reported.";
hole_pattern_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
hole_pattern_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
hole_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
hole_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
hole_table_entry_invalid => Incomplete, Requirement, Code, "The drawn evidence does not correctly state the required source information.";
hole_table_escalated => Advisory, Information, Code, "A hole table replaced crowded individual callouts.";
hole_table_tag_order_retained => Advisory, Information, Code, "Legacy tags retain the finished geometry when spatial relabelling would collide or detach a row leader.";
hole_table_unavailable => Decision, Tidy, Code, "An explicit table request was not met; individual dimensions remain.";
id_not_migrated => Advisory, Information, Code, "A saved legacy identity has no exact current match; its key and intent are retained.";
inch_design_detected => Advisory, Information, Code, "Model sizes closely follow sixteenth-inch or decimal-inch grids; units remain unchanged.";
incremental_basis_kept => Advisory, Information, Code, "Existing dimension basis retained; explicit datum re-base available.";
incremental_placement_constrained => Readability, Tidy, Code, "New annotation ink does not fit cleanly in the retained layout.";
interior_void => Advisory, Information, Feature, "A factual inventory of an internal cavity; its faces do not establish a hole opening.";
iso_layout_overflow => Readability, Tidy, Code, "The requested isometric scale exceeds its reserved layout area.";
iso_projection_empty => Incomplete, Requirement, Code, "The requested isometric view has no projected geometry.";
label_centerline_overlap => Readability, FixBeforePrinting, Code, "A centreline crosses label ink.";
label_crowded => Readability, Tidy, Code, "Text lies within 0.5 mm of another label or of foreign line-work; it stays legible but reads as touching.";
label_section_furniture_overlap => Readability, FixBeforePrinting, Code, "Section furniture touches label ink, or annotation ink runs through a section mark.";
label_vs_measured => Incomplete, Requirement, Code, "The printed label does not state the measured requirement.";
layout_recovery_exhausted => Readability, Tidy, Code, "No recovery removed all reported layout defects.";
layout_replanned => Advisory, Information, Code, "A successful sheet or scale recovery is reported.";
leader_across_view => Readability, Tidy, Code, "A long leader crosses more of its own view's lines than a leader leaving the other way would.";
leader_along_centreline => Readability, Tidy, Code, "A leader runs along a centre line, so the two read as one line.";
leader_centerline_overlap => Readability, Tidy, Code, "A leader overlaps a centreline.";
leader_crosses_silhouette => Advisory, Tidy, Code, "The informational audit reports leader re-entry into the silhouette.";
leader_line_through_text => Readability, FixBeforePrinting, Code, "A leader runs through text.";
leader_through_feature => Readability, Tidy, Code, "A leader crosses feature material on its way to its target.";
leader_to_hidden_edge => Readability, Tidy, Code, "A leader ends on an edge its view shows hidden.";
legibility_floor_breached => Readability, Tidy, Code, "The selected geometry scale is below the requested legibility floor.";
location_on_axis => Advisory, Information, Code, "The turning axis already fixes this centred location; no tangent dimension is needed.";
location_on_datum => Advisory, Information, Code, "The datum already states this zero location.";
location_ref_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
manufacturing_reference_unresolved => Incomplete, Requirement, Code, "A manufacturing requirement reference has no resolved drawn requirement.";
manufacturing_table_fallback => Advisory, Information, Code, "The callouts state the manufacturing requirements in full because their table has no place.";
missing_principal_dimension => Incomplete, Requirement, Code, "A principal overall size is absent from the drawing.";
modelled_thread_not_depicted => Incomplete, Requirement, Feature, "The thread depiction or requirement could not be drawn.";
modelled_thread_refused => Incomplete, Requirement, Code, "A refused thread recognition leaves the thread size and designation unstated.";
nominal_rounded => Advisory, Information, Code, "The printed nominal uses the documented display precision.";
notch_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
notch_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
note_duplicated_in_spec => Advisory, Information, Code, "The same note is already supplied by the authored settings.";
notes_not_placed => Incomplete, Requirement, Code, "Required notes have no drawn placement.";
oblique_witness_crossing => Readability, Tidy, Code, "An oblique witness crosses another dimension stroke.";
off_axis_location_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
oriented_slot_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
oriented_slot_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
over_dimensioned_pattern => Advisory, Tidy, Code, "Repeated pattern dimensions are redundant information.";
pack_bom_suggestion => Advisory, Information, Code, "Stored BOM suggestions retain their provenance and remain reviewable guesses.";
pack_buy_guess => Advisory, Information, Code, "A purchased-part candidate is listed with its detection reason and can be overridden.";
pack_compound => Advisory, Information, Code, "One product contains multiple solids; the pack reports the upstream part-definition limit.";
pack_duplicate_item => Advisory, Information, Code, "Conflicting file find numbers are reported and replaced by automatic allocation.";
pack_ga_balloon_unplaced => Incomplete, Requirement, Code, "A visible assembly item has no clear item-reference route.";
pack_ga_failed => Incomplete, Requirement, Code, "The requested general assembly front sheet could not be drawn.";
pack_ga_not_visible => Advisory, Information, Code, "No face of this listed assembly item has proven visibility; no leader is fabricated.";
pack_geometry_merge => Advisory, Information, Code, "Products with identical resolved geometry share one drawing and a summed quantity.";
pack_make_guess => Advisory, Information, Code, "The default manufacturing decision and its evidence are reported and can be overridden.";
pack_single_product => Advisory, Information, Code, "A single product has multiple placements, counted in its drawing quantity.";
pad_footprint_not_defined => Incomplete, Requirement, Code, "The pad footprint is not fully defined by dimensions.";
pad_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
pad_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
page_fit_uncertain => Readability, Tidy, Code, "The composed view and annotation zones may not fit.";
paired_ramp_step_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
paired_ramp_step_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
part_squared_to_axes => Advisory, Information, Code, "The part lay a fraction of a degree off the file's axes and is drawn square, in its own frame.";
passage_requirement_unsupported => Incomplete, Requirement, Requirement, "No supported drawing grammar states this feature requirement.";
pictorial_placement_unresolved => Decision, Tidy, Code, "The authored pictorial placement or scale cannot fit; its intent is retained for a user choice.";
pinned_item_not_drawn => Decision, Tidy, Code, "The requested pin targets an item that is not drawn.";
pinned_reference_chain_changed => Decision, Tidy, Code, "The authored pin conflicts with the recovered reference chain.";
pinned_view_off_sheet => Readability, FixBeforePrinting, Code, "The explicitly placed view extends outside the drawing area; an error offers removal of its placement.";
pinned_view_overlap => Readability, FixBeforePrinting, Code, "The pinned view overlaps another view.";
placement_anchor_not_shown => Decision, Tidy, Code, "The requested anchor is absent from the drawing.";
placement_displaced => Decision, Tidy, Code, "The final layout displaced an explicit placement; the warning names the requested fields and cause.";
placement_side_not_applicable => Decision, Tidy, Code, "The authored side does not apply to this dimension.";
placement_unapplied => Decision, Tidy, Code, "The requested placement cannot be applied; an available drawing placement is retained.";
plate_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
plate_requirement_suppressed => Advisory, Information, Requirement, "Other geometry already supplies the suppressed plate requirement.";
plate_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
pmi_datum_suppressed => Advisory, Information, Code, "The datum was deliberately suppressed by policy.";
pmi_dimensions_not_ported => Incomplete, Requirement, Code, "The source dimension has no implemented drawing grammar.";
pmi_graphical_not_drawn => Incomplete, Requirement, Source, "A graphical source annotation has no resolved semantic PMI coverage.";
pmi_hole_depth_mismatch => Decision, Requirement, Source, "The authored PMI hole depth disagrees with the recognised geometry; the authored depth is drawn.";
pmi_ignored => Advisory, Information, Code, "The selected dimension-source policy ignores this PMI.";
pmi_not_drawn => Incomplete, Requirement, Source, "The planned PMI annotation is absent from the sheet.";
pmi_not_extracted => Incomplete, Requirement, Source, "A source PMI record was not extracted into a drawable requirement.";
pmi_not_lowered => Incomplete, Requirement, Source, "A read PMI requirement has no supported drawing representation.";
pmi_not_read => Incomplete, Requirement, Code, "The PMI reading cannot supply the required annotation.";
pmi_not_rendered => Incomplete, Requirement, Source, "The rendered drawing does not state the source PMI requirement.";
pmi_note_unattached => Incomplete, FixBeforePrinting, Source, "The note is stated in the notes block but its feature attachment has no supported flag leader.";
pmi_presentation_not_read => Incomplete, Information, Code, "The source presentation PMI is not available as drawing information.";
pmi_read_fact => Advisory, Information, Source, "A source PMI statement is preserved or measured drawing information is identified.";
pmi_read_nonconformance => Advisory, Information, Source, "A source PMI nonconformance was read through an explicit interpretation.";
pmi_source_site_mismatch => Incomplete, Requirement, Source, "The drawn evidence does not correctly state the required source information.";
pmi_source_text_mismatch => Incomplete, Requirement, Source, "The drawn evidence does not correctly state the required source information.";
pmi_source_unknown => Incomplete, Requirement, Source, "The claimed PMI provenance cannot be found in the source document.";
pmi_unreconciled => Incomplete, Requirement, Code, "The source PMI and drawing evidence cannot be reconciled.";
pmi_value_mismatch => Incomplete, Requirement, Source, "The drawn evidence does not correctly state the required source information.";
pocket_corner_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
pocket_corner_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
pocket_not_located => Incomplete, Requirement, Code, "The drawing does not state the pocket location.";
pocket_pattern_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
pocket_pattern_requirement_suppressed => Advisory, Information, Requirement, "The pattern already supplies this individual requirement.";
pocket_pattern_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
pocket_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
pocket_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
polygonal_boss_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
polygonal_boss_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
polygonal_stock_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
polygonal_stock_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
possible_thread => Incomplete, Information, Feature, "A smooth cylinder at a named metric size may be an unstated thread.";
prismatic_pocket_requirement_unsupported => Incomplete, Requirement, Requirement, "No supported drawing grammar states this feature requirement.";
profile_corner_unlocated => Incomplete, Requirement, Requirement, "An outer-profile corner's angle is drawn but no linear dimension locates its edge.";
profiled_bore_not_dimensioned => Incomplete, Requirement, Code, "The profiled bore requirements have no complete drawn dimension.";
projection_relation_infeasible => Decision, Tidy, Code, "The authored projected-view relationship cannot be satisfied.";
radius_leader_not_radial => Readability, Tidy, Code, "The radius leader does not meet its arc radially from either side.";
radius_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The radius leader points at the wrong geometry.";
radius_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The radius leader target cannot be verified.";
recess_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The recess leader points at the wrong geometry.";
recess_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The recess leader target cannot be verified.";
rectangular_blind_slot_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
rectangular_blind_slot_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
relief_profile_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
relief_profiles_per_model => Advisory, Information, Code, "The drawing deliberately refers to model-defined relief profiles.";
round_bottom_blind_slot_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
round_bottom_blind_slot_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
scale_fallback_applied => Advisory, Information, Code, "The documented feasible scale fallback was applied.";
scale_not_stated => Incomplete, Requirement, Code, "The drawing does not state its scale.";
section_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
section_not_shown => Incomplete, Requirement, Code, "The requested section is not shown.";
section_recess_recognition_refused => Incomplete, Requirement, Code, "Refused recess recognition leaves the recess requirements unstated.";
section_recess_requirement_unsupported => Incomplete, Requirement, Requirement, "No supported drawing grammar states this feature requirement.";
semicircular_blind_slot_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
semicircular_blind_slot_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
shaded_view_unresolved => Decision, Tidy, Code, "The requested shaded style could not be resolved; ordinary pictorial lines preserve the drawing.";
shape_not_recognised => Incomplete, Tidy, Shape, "A recognisable shape among unexplained faces is a drafting-quality hint.";
sheet_assignment_unused => Advisory, Information, Code, "A sheet assignment has no corresponding drawing item.";
sheet_below_smallest_scale => Readability, Tidy, Code, "The sheet uses views below the requested legibility scale.";
sheet_label_replaced => Advisory, Information, Code, "Automatic document numbering replaces the authored sheet label.";
sheet_preference_exceeded => Advisory, Information, Code, "A usable drawing needs larger paper or more sheets than preferred.";
sheet_renumbered => Advisory, Information, Code, "The document sheets were renumbered consecutively.";
sheet_zones_kept => Advisory, Information, Code, "Section cross-references cite the grid zones, so they stay on the sheet.";
slot_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The slot leader points at the wrong geometry.";
slot_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The slot leader target cannot be verified.";
slot_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
slot_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
spec_entries_inactive => Decision, Information, Code, "Authored settings do not apply to any current item.";
spec_from_other_revision => Decision, FixBeforePrinting, Code, "The user must decide whether to rebind settings from another revision.";
spec_overrides_pmi => Decision, Information, Code, "The deliberate user-authored override of PMI is informational.";
spec_refines_pmi => Advisory, Information, Code, "The authored designation refines a Specify-written thread.";
step_diameter_leader_target_mismatch => Readability, FixBeforePrinting, Code, "The turned diameter leader points at the wrong geometry.";
step_diameter_leader_target_unverifiable => Readability, FixBeforePrinting, Code, "The turned diameter leader target cannot be verified.";
step_general_tolerance_disagreement => Decision, FixBeforePrinting, Code, "The authored and PMI general tolerances disagree.";
step_length_witness_target_mismatch => Readability, FixBeforePrinting, Code, "The turned length's extension lines are off the band's shoulders.";
step_length_witness_target_unverifiable => Readability, FixBeforePrinting, Code, "The turned length's extension lines cannot be verified.";
step_level_support_missing => Incomplete, Requirement, Code, "Missing shoulder support prevents the step level being stated.";
step_material_ambiguous => Decision, FixBeforePrinting, Code, "The STEP records do not identify one material to use.";
step_material_disagreement => Decision, FixBeforePrinting, Code, "The authored and STEP materials disagree.";
step_material_unavailable => Decision, FixBeforePrinting, Code, "The user must supply a usable material statement.";
step_position_coincident_with_datum => Advisory, Information, Code, "The datum already states this shoulder location.";
table_dropped => Incomplete, Requirement, Code, "A required drawing item was dropped before it could be stated.";
table_not_placed => Incomplete, Requirement, Code, "The required item has no drawn placement.";
text_glyph_missing => Readability, FixBeforePrinting, Code, "A character in a label is in none of the bundled fonts, so it is drawn as an empty box.";
thread_designation_measured => Advisory, Information, Code, "Measured diameter and pitch are stated without an inferred designation.";
through_step_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
through_step_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
title_field_overflow => Readability, FixBeforePrinting, Code, "The title value overflows its reserved cell.";
tolerance_not_shown => Incomplete, Requirement, Code, "The authored tolerance is absent from the drawing.";
tolerance_withheld => Incomplete, Requirement, Code, "The authored tolerance is absent from the drawing.";
toleranced_reference => Decision, FixBeforePrinting, Code, "A reference-only dimension carries a controlling tolerance; choose its intended role.";
turned_chain_no_clear_lane => Readability, Tidy, Code, "The turned dimension chain has no clear annotation lane.";
turned_profile_superimposed => Readability, Tidy, Code, "Superimposed turned profiles make dimensions harder to read.";
turned_step_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
turned_step_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
unclaimed_geometry => Advisory, Information, Code, "Unclaimed faces can be ordinary stock faces, not missing requirements.";
unrecognised_defining_geometry => Incomplete, Tidy, Code, "Unrecognised principal geometry is a drafting-quality hint.";
v_channel_requirement_missing => Incomplete, Requirement, Requirement, "The drawing does not state this required feature parameter.";
v_channel_requirement_unverifiable => Incomplete, Requirement, Requirement, "The drawing does not prove this required feature parameter.";
view_annotation_inside_extents => Advisory, Information, Code, "An annotation inside a view extent is informational.";
view_annotation_overlap => Readability, FixBeforePrinting, Code, "An annotation overlaps a view boundary or view geometry.";
view_on_title_block => Readability, FixBeforePrinting, Code, "A view overlaps the title block.";
view_out_of_bounds => Readability, FixBeforePrinting, Code, "A rendered view extends outside the drawing bounds.";
view_overlap => Readability, FixBeforePrinting, Code, "Rendered view extents overlap.";
view_plan_incomplete => Incomplete, Requirement, Code, "Dimensions require views that are absent, so they remain undrawn.";
views_do_not_fit => Readability, FixBeforePrinting, Code, "The selected views do not fit the drawing area.";
views_overlap => Readability, Tidy, Code, "Planned view zones overlap.";
}
fn classification(code: &str) -> Option<&'static Classification> {
CODES
.binary_search_by_key(&code, |entry| entry.code)
.ok()
.map(|i| &CODES[i])
}
pub(crate) fn explanation(name: &str) -> Option<&'static str> {
classification(name).map(|entry| entry.reason)
}
#[derive(Clone, Debug, Serialize)]
pub struct Labels {
pub tier: Tier,
pub impact: Impact,
pub group: String,
}
fn source_kind(id: &str) -> Option<String> {
let (kind, tail) = id.strip_prefix("pmi:").unwrap_or(id).split_once(':')?;
if !(tail.starts_with('#')
|| id.starts_with("pmi:")
|| id.starts_with("spec:")
|| (kind == "material" && tail.bytes().all(|b| b.is_ascii_digit() || b == b':')))
{
return None;
}
let kind = kind.split('.').next()?;
(!kind.is_empty() && kind.bytes().all(|c| c.is_ascii_lowercase() || c == b'_'))
.then(|| kind.to_owned())
}
pub fn labels(
code: &str,
info: bool,
subjects: &[String],
parameters: impl IntoIterator<Item = impl AsRef<str>>,
sources: &[String],
crossing_kinds: &[String],
ink_is_leader: Option<bool>,
) -> Labels {
let entry = classification(code);
let mut impact = entry.map_or(Impact::Advisory, |c| c.impact);
let kinds: BTreeSet<_> = crossing_kinds.iter().map(String::as_str).collect();
if code == "annotation_leader_crossing" && kinds == BTreeSet::from(["extension_line"]) {
impact = Impact::Advisory;
}
if code == "annotation_ink_overlap" && ink_is_leader == Some(true) {
impact = Impact::Readability;
}
if info {
impact = Impact::Advisory;
}
let cause: BTreeSet<String> = match entry.map(|c| c.group) {
Some(Group::Feature) => subjects
.iter()
.filter_map(|id| {
id.strip_prefix("f:")
.and_then(|s| s.split(':').next())
.map(String::from)
})
.collect(),
Some(Group::Requirement) => parameters
.into_iter()
.map(|p| p.as_ref().to_owned())
.collect(),
Some(Group::Source) => sources
.iter()
.filter_map(|s| source_kind(s))
.chain(subjects.iter().filter_map(|s| source_kind(s)))
.collect(),
Some(Group::Crossing) => kinds.into_iter().map(String::from).collect(),
Some(Group::Shape) => sources
.iter()
.filter_map(|s| s.strip_prefix("shape:").map(String::from))
.collect(),
_ => BTreeSet::new(),
};
let group = if cause.is_empty() {
code.to_owned()
} else {
format!("{code}:{}", cause.into_iter().collect::<Vec<_>>().join("+"))
};
Labels {
tier: entry.map_or(Tier::Information, |c| c.kind.tier_rule().resolve(info)),
impact,
group,
}
}
#[derive(Clone, Debug, Default, Serialize)]
pub struct Count {
pub findings: usize,
pub groups: usize,
}
#[derive(Clone, Debug, Serialize)]
pub struct Summary {
pub impacts: BTreeMap<Impact, Count>,
pub groups: BTreeMap<String, usize>,
}
impl Summary {
pub fn new(labels: impl IntoIterator<Item = Labels>) -> Self {
let mut impacts: BTreeMap<_, _> = [
Impact::Incomplete,
Impact::Decision,
Impact::Readability,
Impact::Advisory,
]
.into_iter()
.map(|i| (i, Count::default()))
.collect();
let mut groups = BTreeMap::<String, usize>::new();
let mut seen = BTreeSet::new();
for label in labels {
let count = impacts.get_mut(&label.impact).unwrap();
count.findings += 1;
if seen.insert((label.impact, label.group.clone())) {
count.groups += 1;
}
*groups.entry(label.group).or_default() += 1;
}
Self { impacts, groups }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unknown_external_codes_remain_informational_and_advisory() {
let code = "external_unregistered_diagnostic";
assert!(classification(code).is_none());
for info in [false, true] {
let label = labels(code, info, &[], std::iter::empty::<&str>(), &[], &[], None);
assert_eq!(label.tier, Tier::Information);
assert_eq!(label.impact, Impact::Advisory);
assert_eq!(label.group, code);
assert_eq!(serde_json::to_value(label).unwrap()["tier"], "information");
}
}
#[test]
fn every_registered_code_resolves_both_contexts() {
for entry in CODES {
for info in [false, true] {
let label = labels(
entry.code,
info,
&[],
std::iter::empty::<&str>(),
&[],
&[],
None,
);
assert!(Tier::ALL.contains(&label.tier));
assert_eq!(label.tier, entry.kind.tier_rule().resolve(info));
assert_eq!(
serde_json::to_value(&label).unwrap()["tier"],
label.tier.as_str()
);
}
}
}
#[test]
fn catalogue_is_sorted_and_documented() {
let docs = include_str!("../docs/finding-impact.md");
for pair in CODES.windows(2) {
assert!(pair[0].code < pair[1].code);
}
for c in CODES {
let impact = serde_json::to_value(c.impact).unwrap();
assert!(
docs.contains(&format!(
"| `{}` | {} | {} | {} |",
c.code,
impact.as_str().unwrap(),
c.kind.tier_rule().documented(),
c.reason
)),
"{}",
c.code
);
}
assert_eq!(
docs.lines().filter(|l| l.starts_with("| `")).count(),
CODES.len()
);
}
#[test]
fn every_info_instance_is_advisory_without_changing_the_code_mapping() {
for code in CODES {
assert_eq!(
labels(
code.code,
true,
&[],
std::iter::empty::<&str>(),
&[],
&[],
None
)
.impact,
Impact::Advisory
);
}
}
#[test]
fn stroke_metadata_classifies_crossings_and_leader_text_contacts() {
let crossing = |kinds: &[&str]| {
labels(
"annotation_leader_crossing",
false,
&[],
std::iter::empty::<&str>(),
&[],
&kinds.iter().map(|s| (*s).to_owned()).collect::<Vec<_>>(),
None,
)
};
assert_eq!(crossing(&["extension_line"]).impact, Impact::Advisory);
for kinds in [
vec!["leader"],
vec!["dimension_line"],
vec!["arrow"],
vec!["extension_line", "leader"],
vec![],
vec!["future_kind"],
] {
assert_eq!(crossing(&kinds).impact, Impact::Readability);
}
assert_eq!(
crossing(&["arrow", "leader"]).group,
crossing(&["leader", "arrow", "leader"]).group
);
for ink in [Some(true), Some(false), None] {
assert_eq!(
labels(
"annotation_ink_overlap",
false,
&[],
std::iter::empty::<&str>(),
&[],
&[],
ink
)
.impact,
Impact::Readability
);
}
}
#[test]
fn groups_ignore_occurrences_but_retain_causes() {
let feature = |id: &str| {
labels(
"dimensions_not_ported",
false,
&[id.into()],
std::iter::empty::<&str>(),
&[],
&[],
None,
)
.group
};
assert_eq!(
feature("f:section_recess:1"),
feature("f:section_recess:999")
);
assert_ne!(feature("f:section_recess:1"), feature("f:through_step:1"));
let requirements = |roles: &[&str]| {
labels(
"hole_requirement_missing",
false,
&[],
roles,
&[],
&[],
None,
)
.group
};
assert_ne!(
requirements(&["bore.diameter"]),
requirements(&["location.length.x"])
);
assert_eq!(
requirements(&["bore.diameter", "bore.through"]),
requirements(&["bore.through", "bore.diameter"])
);
}
#[test]
fn pmi_groups_use_source_kinds_and_never_refusal_prose() {
let group = |source: &str, why: &str| {
labels(
"pmi_not_lowered",
false,
&[],
std::iter::empty::<&str>(),
&[source.into(), why.into()],
&[],
None,
)
.group
};
assert_eq!(
group("geometric_tolerance:#123", "Why: first explanation"),
group("geometric_tolerance:#999", "Different: second explanation")
);
assert_ne!(
group("geometric_tolerance:#123", "why"),
group("dimensional_size:#123", "why")
);
assert_eq!(source_kind("reason:unsupported"), None);
}
}