TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
footprint_check.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Footprint check against datasheet land patterns (issue #5, docs/05-routing.md §43, D115).
4//
5// For each footprint of a board the check finds the reference (footprint_ref.hpp) made for it: by manufacturer part number, library id, value or
6// designator. A reference from a brand that is not on the trusted list gives no verdict (the footprint is reported as `untrusted`: nobody vouched for
7// that datasheet). With a trusted reference the footprint's pads are compared with the datasheet's: the pattern is first aligned to the footprint
8// (a rotation by a multiple of 90 degrees, a mirror, and a translation: the footprint's origin and orientation are the library's choice, not
9// a property of the land pattern), then every pad is checked for number, position, size, drill and type. Whatever differs is an error.
10//
11// A mirror is not free: the pads of a footprint on the front must match the datasheet as drawn, those of a footprint on the back mirrored (that is
12// what flipping a footprint does). A pattern that fits only the other way round is reported as mirrored: the pin numbers run the wrong way.
13//
14// The check is read-only and geometric. It verifies the footprint against the record somebody made from the datasheet; it does not read the datasheet.
15#include <string>
16#include <vector>
17
18#include <nlohmann/json.hpp>
19
21#include "geom/point.hpp"
22#include "model/board.hpp"
23
24namespace tmk::analysis {
25
26enum class Severity { Info, Warning, Error };
27
30 std::string kind; // pad_count, missing_pad, extra_pad, position, size, drill, pad_type, orientation, mirrored, pattern, no_reference, untrusted_source
31 std::string pad; // the pad number, "" = the footprint as a whole
32 std::string message;
33 std::string label; // a few words for a mark on the board ("pad 3: 0.15 mm off")
34 geom::Point at; // where to look on the board (nm)
35 double actual_mm = -1; // the measured value where there is one (the deviation of a position, a size ...)
36 double expected_mm = -1;
37};
38
40
42 int footprint = -1;
43 std::string ref, lib_id, value;
44 std::vector<std::string> mpn;
47 // The reference that was used (Ok, Mismatch) or found but not trusted (Untrusted).
49 int page = 0;
50 int other_matches = 0; // further references that also matched and were not used
51 int rotation = 0; // the alignment found: degrees the datasheet pattern is turned to meet the footprint
52 bool mirrored = false;
53 int pads_board = 0, pads_ref = 0, pads_matched = 0;
54 double max_position_mm = 0; // the largest deviation of a matched pad after alignment
55 std::vector<FootprintIssue> issues;
56 int errors() const;
57 int warnings() const;
58};
59
61 double position_tol_mm = 0.05; // a reference may set its own
62 double size_tol_mm = 0.05;
63 double drill_tol_mm = 0.05;
64 std::vector<std::string> only; // designator patterns to check (empty = all)
65 std::vector<std::string> require; // designator patterns that must have a trusted reference: without one it is an error
66 std::vector<std::string> mpn_fields; // property names (besides the usual MPN ones) that hold the manufacturer part number
67};
68
70 std::vector<FootprintResult> results; // board order
71 int checked = 0, ok = 0, mismatched = 0, unverified = 0, untrusted = 0, skipped = 0;
72 int errors = 0, warnings = 0;
73 std::vector<std::string> notes; // what the run could not do or chose to do (trust everything, ambiguous matches ...)
75 int references = 0;
76 std::string trusted_source; // the trusted list's file, "" = none
77 bool trust_all = false;
78};
79
80// Deterministic: board order, reference order, no hash iteration.
82
83// The report as JSON (millimetres), one `footprint_check` viewer message (docs/13-viewer-protocol.md), and the text lines (problems first; `all` adds
84// the footprints that are fine or have no reference).
85nlohmann::json footprint_check_json(const model::Board& b, const FootprintCheckReport& r);
87std::vector<std::string> footprint_check_lines(const FootprintCheckReport& r, bool all);
88
89} // namespace tmk::analysis
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
Datasheet land-pattern references and the list of brands whose datasheets are trusted (issue #5,...
std::vector< std::string > footprint_check_lines(const FootprintCheckReport &r, bool all)
std::string footprint_check_message(const FootprintCheckReport &r)
nlohmann::json footprint_check_json(const model::Board &b, const FootprintCheckReport &r)
The report as JSON (millimetres), one footprint_check viewer message (docs/13-viewer-protocol....
FootprintCheckReport check_footprints(const model::Board &b, const RefLibrary &lib, const FootprintCheckOptions &opt)
Deterministic: board order, reference order, no hash iteration.
Integer-nanometre points and KiCad-compatible rotation.
double position_tol_mm
a reference may set its own
std::vector< std::string > require
designator patterns that must have a trusted reference: without one it is an error
std::vector< std::string > only
designator patterns to check (empty = all)
std::vector< std::string > mpn_fields
property names (besides the usual MPN ones) that hold the manufacturer part number
std::vector< FootprintResult > results
board order
std::vector< std::string > notes
what the run could not do or chose to do (trust everything, ambiguous matches ...)
std::string trusted_source
the trusted list's file, "" = none
std::string label
a few words for a mark on the board ("pad 3: 0.15 mm off")
double actual_mm
the measured value where there is one (the deviation of a position, a size ...)
geom::Point at
where to look on the board (nm)
std::string kind
pad_count, missing_pad, extra_pad, position, size, drill, pad_type, orientation, mirrored,...
std::string pad
the pad number, "" = the footprint as a whole
std::vector< std::string > mpn
std::vector< FootprintIssue > issues
int other_matches
further references that also matched and were not used
std::string ref_id
The reference that was used (Ok, Mismatch) or found but not trusted (Untrusted).
double max_position_mm
the largest deviation of a matched pad after alignment
int rotation
the alignment found: degrees the datasheet pattern is turned to meet the footprint