TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
footprint_ref.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Datasheet land-pattern references and the list of brands whose datasheets are trusted (issue #5, docs/05-routing.md §43, D115).
4//
5// TraceMaker does not read datasheets: a PDF drawing is not data. A reference is a record somebody made from a datasheet (typed in from its
6// recommended land pattern, or the manufacturer's own KiCad footprint) together with where it came from: the brand, the document, the page. The check
7// (footprint_check.hpp) compares a board's footprints with these records, and only with the ones whose brand is on the trusted list: a record
8// from a source nobody vouched for gives no verdict, it is reported as unverified.
9//
10// A reference library is a directory (or one file) of JSON:
11// { "format": "tracemaker-footprint-refs/1",
12// "references": [ { "brand": "Example Semiconductor", "part": "EX1234", "package": "SOIC-8",
13// "datasheet": { "document": "EX1234 datasheet", "revision": "C", "page": 21, "figure": "Land pattern", "url": "..." },
14// "match": { "mpn": ["EX1234*"], "lib_id": ["*SOIC-8*"], "value": ["EX1234"], "ref": ["U*"] },
15// "pads": [ { "number": "1", "type": "smd", "shape": "rect", "at": [-2.7, -1.905], "size": [1.55, 0.6], "angle": 0 }, ... ]
16// or "footprint": "path/to/RGT0016C.kicad_mod" (relative to the JSON file),
17// "tolerance_mm": { "position": 0.05, "size": 0.05, "drill": 0.05 } } ] }
18// Millimetres, KiCad's y-down footprint frame. Unknown keys are errors (a misspelt tolerance must not be ignored by a verification tool).
19#include <string>
20#include <vector>
21
22#include "model/board.hpp"
23
24namespace tmk::analysis {
25
26struct RefPad {
27 std::string number;
30 double x = 0, y = 0; // footprint-local centre, nm (the datasheet's own frame)
31 double angle = 0; // degrees
32 double w = 0, h = 0; // nm
33 double drill_w = 0, drill_h = 0; // nm, 0 = no hole
34};
35
37 std::string id; // "file#index" or "file#part": what messages call it
38 std::string brand, part, package;
39 std::string document, revision, url, figure;
40 int page = 0;
41 // Which board footprints the record is for: every non-empty list must be satisfied by one of its patterns (KiCad wildcards; mpn and value
42 // ignore case, lib_id and the designator do not).
43 std::vector<std::string> mpn, lib_id, value, ref;
44 std::vector<RefPad> pads;
45 double position_tol_nm = -1, size_tol_nm = -1, drill_tol_nm = -1; // -1 = the run's default
46 std::string source; // the file it came from
47 int specificity() const { return (mpn.empty() ? 0 : 1) + (lib_id.empty() ? 0 : 1) + (value.empty() ? 0 : 1) + (ref.empty() ? 0 : 1); }
48};
49
50// Brands whose datasheets are trusted. One line per brand in the file: `Canonical name | alias | alias`, `#` starts a comment. Names are compared
51// without case, punctuation or corporate suffixes ("Texas Instruments Inc." = "texas instruments").
53 bool trust_all = false; // --trust-all: no list, everything counts (a deliberate choice, said so in the report)
54 std::vector<std::vector<std::string>> groups; // normalised names, canonical first
55 std::string source; // the file, "" = none given
56 bool trusts(const std::string& brand) const;
57};
58
59struct RefLibrary {
60 std::vector<FootprintRef> refs; // files in name order, entries in file order: the order is part of the result
62 std::vector<std::string> files; // what was read
63};
64
65// `path` is a directory (every *.json below it, in path order; a trusted_brands.txt beside the references is the trusted list unless one is given) or one
66// JSON file. Throws std::runtime_error with the file and the key on anything it cannot take.
67RefLibrary load_references(const std::string& path, const std::string& trusted_brands_file = "");
68TrustedBrands load_trusted_brands(const std::string& file);
69TrustedBrands parse_trusted_brands(const std::string& text, const std::string& source);
70// The pads of a footprint file (.kicad_mod, or the text of one) in its own frame.
71std::vector<RefPad> pads_from_kicad_mod(const std::string& text);
72// "Texas Instruments Inc." -> "texas instruments"
73std::string normalise_brand(const std::string& brand);
74
75} // namespace tmk::analysis
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
RefLibrary load_references(const std::string &path, const std::string &trusted_brands_file="")
path is a directory (every *.json below it, in path order; a trusted_brands.txt beside the references...
TrustedBrands load_trusted_brands(const std::string &file)
TrustedBrands parse_trusted_brands(const std::string &text, const std::string &source)
std::string normalise_brand(const std::string &brand)
"Texas Instruments Inc." -> "texas instruments"
std::vector< RefPad > pads_from_kicad_mod(const std::string &text)
The pads of a footprint file (.kicad_mod, or the text of one) in its own frame.
std::string id
"file#index" or "file#part": what messages call it
std::vector< std::string > value
double drill_tol_nm
-1 = the run's default
std::vector< RefPad > pads
std::vector< std::string > mpn
Which board footprints the record is for: every non-empty list must be satisfied by one of its patter...
std::vector< std::string > lib_id
std::string source
the file it came from
std::vector< std::string > ref
std::vector< FootprintRef > refs
files in name order, entries in file order: the order is part of the result
std::vector< std::string > files
what was read
double drill_h
nm, 0 = no hole
model::PadShape shape
double y
footprint-local centre, nm (the datasheet's own frame)
Brands whose datasheets are trusted.
bool trust_all
–trust-all: no list, everything counts (a deliberate choice, said so in the report)
std::vector< std::vector< std::string > > groups
normalised names, canonical first
bool trusts(const std::string &brand) const
std::string source
the file, "" = none given