TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
route_job.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// One `tracemaker route` run as a reusable function, shared by the CLI (src/app/main.cpp) and the Python bindings
4// (bindings/), so both take exactly the same code path (design doc 08 §5).
5#include <functional>
6#include <string>
7
8#include <nlohmann/json.hpp>
9
12#include "route/bus.hpp"
13#include "route/router.hpp"
14
15namespace tmk::app {
16
17struct RouteJob {
18 std::string in; // input .kicad_pcb (its project files supply the design rules)
19 std::string out; // output .kicad_pcb; empty = do not write a board
20 route::RouterOptions opt; // `sink` is set here when viewing or recording
21 int threads = 8; // worker threads for the portfolio variants
22 // Portfolio size (1 = single router). 0 = automatic: all variants (route::portfolio_size()) with a work budget,
23 // so the output does not depend on `threads` (D47); otherwise `threads` (wall-clock mode: one variant per thread).
24 int variants = 0;
25 std::string kb_path; // knowledge base file; empty = none
26 std::string items_out; // --emit-items file; empty = none
27 std::string json_out; // --json summary file; empty = none
28 bool view = false; // stream to the browser viewer
29 // Reference-return audit of selected nets on the routed board (issue #7, doc 05 §42): off unless a selector is given. Read-only; the
30 // report goes to the log and the summary, and each net's return path to the viewer.
32 // Critical nets (issue #24, doc 05 §44, D117): route critical signals first, give them dearer vias, keep them over solid reference copper. Off
33 // unless asked; `si_rules` turns the three on with the settings below unless they were given.
34 std::vector<std::string> critical_nets; // KiCad wildcards: nets that are critical whatever their role (tier 1)
35 bool critical_auto = false; // also the nets the component rules' roles make critical, and differential pairs
36 bool critical_first = false; // route them before all other nets, tier by tier
37 double critical_via_mult = 1; // a via costs them this many times as much
38 bool critical_via_given = false; // set by the command line: with si_rules, a value that was given is kept (else x3)
39 int critical_via_max = 0; // warn when a critical net has more vias than this (0 = no limit)
40 double split_cost = 0; // pitches per lattice step over a void of the reference plane
41 bool split_cost_given = false; // as critical_via_given (else +4 with si_rules)
42 bool split_hard = false; // such cells are closed to critical nets
43 bool si_rules = false;
44 // --footprint-refs (issue #5, doc 05 §43): every footprint is checked against the datasheet land patterns of a reference library before the first track is
45 // routed; a discrepancy is an error and stops the job unless footprint_warn_only.
46 std::string footprint_refs; // the library: a directory or a JSON file; empty = no check
47 std::string footprint_trusted; // trusted brand list; empty = trusted_brands.txt beside the references
48 bool footprint_trust_all = false;
49 bool footprint_warn_only = false;
51 bool view_freeze = true; // the viewer holds the scene on a routing stall (issue #8); --no-freeze says false in the board snapshot
52 std::string view_host; // "" = $TM_VIEW_HOST, else loopback: a viewer on any other address needs a token (issue #4, D116)
53 std::string view_token; // the token for a non-loopback viewer (empty = a random one)
54 bool view_insecure = false; // a non-loopback viewer without a token (--view-insecure)
55 std::string view_embed; // pages that may frame the viewer (--view-embed); empty = none
56 int view_port = 8766;
57 bool hold = false; // keep serving the viewer after routing; never returns (CLI only)
58 std::string record; // events file for replay (ignored while viewing)
59 // --component-rules (doc 15 §3.5): "off" (default), "report" or "soft" (detect; write the sidecar .kicad_dru next
60 // to the output), "on" (also route with the generated keep-outs as in-memory rule areas; never written into the
61 // output board).
62 std::string component_rules = "off";
63 // --reroute: remove every unlocked track and via first and route the whole board again (locked copper, arcs and
64 // zones stay; rule 6).
65 bool reroute = false;
66 std::string warm_pcb; // --warm-pcb: a routed board whose tracks and vias are the starting point (kept where legal under the input's rules; nets of one connection)
67 std::string rules_override; // --rules-override: user override file (JSON, doc 15 §6.3); empty = none
68 // Advice (doc 17, issue #26). The engine never talks to a model: it reads an advice file, and an advisor (any program
69 // that turns a stuck report into an advice file) is consulted only when the deterministic route leaves connections open.
70 std::string advice; // --advice FILE: typed hints (src/advice/advice.hpp); advised variants run next to the unadvised ones
71 int advice_variants = 0; // --advice-variants N: advised variants (0 = the file's "variants", else 4)
72 std::string advisor; // --advisor CMD: a shell command that reads the stuck report on stdin and writes advice on stdout
73 double advisor_timeout_s = 120; // --advisor-timeout S: the advisor's time limit (its wall time is not routing work)
74 int advisor_rounds = 1; // --advisor-rounds N: consult again with the result of the advised run while connections are left
75 bool advisor_redact = false; // --advisor-redact: the report names nets and parts by alias (N1, P3); the advice is mapped back
76 std::string advice_out; // --advice-out FILE: where the advice that was used is saved (default: <out>.advice.json)
77 std::string stuck_report_out; // --stuck-report FILE: write the stuck report (of the run the advisor saw, else the final one)
78 // With soft zones: refill the zones after routing and route what the refill left unconnected (doc 05 §36).
79 bool refill_repair = true;
80 // --no-tracks-on / --layer-cost (doc 05 §29): copper layer names, and "LAYER=FACTOR" entries. Resolved against
81 // the board into opt.no_track_layers / opt.layer_cost_pm; an unknown layer or a bad factor throws.
82 std::vector<std::string> no_tracks_on;
83 std::vector<std::string> layer_costs;
84 // Buses (doc 05 §38): "NAME=PATTERN" groups (--bus), automatic detection (--buses) and the skew limit of the
85 // command-line groups in mm (--bus-skew-mm; 0 = none). A custom skew rule of the board wins over the option.
86 std::vector<std::string> buses;
87 bool detect_buses = false;
88 double bus_skew_mm = 0;
89 // After-route passes (doc 05 §39), all off by default. Each changes the new copper only through the router's
90 // exact check and is kept only if no net has more unconnected items with it than without (rule 4).
91 // --widen-power: new tracks narrower than their net class width go back up to it where there is room; nets with
92 // a target (--widen-net "PATTERN=WIDTH_MM", or a width the component rules computed) are widened towards it.
93 bool widen_power = false;
94 std::vector<std::string> widen_nets;
95 // --stitch-vias: "planes" (vias of a plane's net on a grid where its fills overlap on two or more layers),
96 // "return" (a plane via near each via of the signals that need a reference plane: component rules of kind
97 // reference_plane, and --stitch-return "PATTERN=PLANE_NET"), or "all". Empty = off.
98 std::string stitch_vias;
99 double stitch_pitch_mm = 0; // 0 = the catalogue's stitch_via_within_mm
100 double stitch_distance_mm = 0; // 0 = the rule's stitch_via_mm, else the catalogue value
101 std::vector<std::string> stitch_returns;
102 long pass_work = 2'000'000; // work budget of each pass, in exact checks (rule 5)
103 // Progress lines (the CLI's stdout text, one line per call, no trailing newline). Empty = silent.
104 std::function<void(const std::string&)> log;
105};
106
109 nlohmann::json items; // new copper in the --emit-items layout (layer and net by name, nm)
110 nlohmann::json summary; // the --json layout
111 std::string viewer_url; // empty when not viewing
112 int unconnected_after_refill = -1; // with soft zones: what KiCad's refill would leave unconnected
113 // 0 when everything planned was routed (and, with soft zones, nothing is unconnected after the refill).
114 int exit_code() const { return unconnected_after_refill >= 0 ? (unconnected_after_refill == 0 ? 0 : 3) : result.routed == result.connections ? 0 : 3; }
115};
116
117// Reads the board and its rules, routes (a portfolio when more than one variant runs), writes the requested outputs.
118// Throws std::exception on unreadable input.
120
121// Buses (doc 05 §38): the groups `specs` ("NAME=PATTERN") name on the board, then, with `detect`, the groups found in
122// the net names that share no net with an earlier group. Each group gets the skew limit of the board's custom
123// rules, else, for groups from `specs`, `skew_mm` (0 = none). `notes` receives warnings. Throws on a bad spec.
124std::vector<route::BusGroup> resolve_buses(const model::Board& b, const model::DesignRules& rules, const std::vector<std::string>& specs,
125 bool detect, double skew_mm, std::vector<std::string>* notes = nullptr);
126// A group measured on the copper of `b` (`joined`: route::nets_joined of the same board), as the JSON object of the
127// route summary's `buses` array and of `tracemaker buses --json`; `line`, if given, gets the one-line text form.
128// Lengths are KiCad's: tracks plus the stackup height of the vias (`rules` says whether the project counts it).
129nlohmann::json bus_report(const model::Board& b, const model::DesignRules& rules, const std::vector<std::uint8_t>& joined, const route::BusGroup& g,
130 std::string* line = nullptr);
131
132// The GPU device used for cost-to-go fields: the first listed device, or -1 (none, or `use_gpu` false).
133int default_gpu_device(bool use_gpu);
134
135} // namespace tmk::app
Buses (design doc 05 §38): groups of nets that belong together (a data bus, an address bus,...
Footprint check against datasheet land patterns (issue #5, docs/05-routing.md §43,...
std::vector< route::BusGroup > resolve_buses(const model::Board &b, const model::DesignRules &rules, const std::vector< std::string > &specs, bool detect, double skew_mm, std::vector< std::string > *notes=nullptr)
Buses (doc 05 §38): the groups specs ("NAME=PATTERN") name on the board, then, with detect,...
RouteJobResult run_route_job(RouteJob job)
Reads the board and its rules, routes (a portfolio when more than one variant runs),...
int default_gpu_device(bool use_gpu)
The GPU device used for cost-to-go fields: the first listed device, or -1 (none, or use_gpu false).
nlohmann::json bus_report(const model::Board &b, const model::DesignRules &rules, const std::vector< std::uint8_t > &joined, const route::BusGroup &g, std::string *line=nullptr)
A group measured on the copper of b (joined: route::nets_joined of the same board),...
Reference-return audit of high-speed nets (issue #7, docs/05-routing.md §42, D114).
TraceMaker's detailed router, version 1 (roadmap M4; design doc 05 §2, §5).
std::string viewer_url
empty when not viewing
int exit_code() const
0 when everything planned was routed (and, with soft zones, nothing is unconnected after the refill).
int unconnected_after_refill
with soft zones: what KiCad's refill would leave unconnected
route::RouteResult result
nlohmann::json items
new copper in the –emit-items layout (layer and net by name, nm)
nlohmann::json summary
the –json layout
std::string rules_override
–rules-override: user override file (JSON, doc 15 §6.3); empty = none
Definition route_job.hpp:67
std::string warm_pcb
–warm-pcb: a routed board whose tracks and vias are the starting point (kept where legal under the in...
Definition route_job.hpp:66
std::vector< std::string > widen_nets
Definition route_job.hpp:94
std::string footprint_trusted
trusted brand list; empty = trusted_brands.txt beside the references
Definition route_job.hpp:47
std::vector< std::string > buses
Buses (doc 05 §38): "NAME=PATTERN" groups (–bus), automatic detection (–buses) and the skew limit of ...
Definition route_job.hpp:86
bool hold
keep serving the viewer after routing; never returns (CLI only)
Definition route_job.hpp:57
std::string stitch_vias
–stitch-vias: "planes" (vias of a plane's net on a grid where its fills overlap on two or more layers...
Definition route_job.hpp:98
std::string advisor
–advisor CMD: a shell command that reads the stuck report on stdin and writes advice on stdout
Definition route_job.hpp:72
double stitch_pitch_mm
0 = the catalogue's stitch_via_within_mm
Definition route_job.hpp:99
std::vector< std::string > stitch_returns
bool reroute
–reroute: remove every unlocked track and via first and route the whole board again (locked copper,...
Definition route_job.hpp:65
std::function< void(const std::string &)> log
Progress lines (the CLI's stdout text, one line per call, no trailing newline). Empty = silent.
std::vector< std::string > layer_costs
Definition route_job.hpp:83
std::string advice
Advice (doc 17, issue #26).
Definition route_job.hpp:70
std::string component_rules
–component-rules (doc 15 §3.5): "off" (default), "report" or "soft" (detect; write the sidecar ....
Definition route_job.hpp:62
std::string record
events file for replay (ignored while viewing)
Definition route_job.hpp:58
int advice_variants
–advice-variants N: advised variants (0 = the file's "variants", else 4)
Definition route_job.hpp:71
int variants
Portfolio size (1 = single router).
Definition route_job.hpp:24
analysis::FootprintCheckOptions footprint_opt
Definition route_job.hpp:50
double split_cost
pitches per lattice step over a void of the reference plane
Definition route_job.hpp:40
std::string json_out
–json summary file; empty = none
Definition route_job.hpp:27
long pass_work
work budget of each pass, in exact checks (rule 5)
std::string kb_path
knowledge base file; empty = none
Definition route_job.hpp:25
int critical_via_max
warn when a critical net has more vias than this (0 = no limit)
Definition route_job.hpp:39
std::string view_host
"" = $TM_VIEW_HOST, else loopback: a viewer on any other address needs a token (issue #4,...
Definition route_job.hpp:52
double advisor_timeout_s
–advisor-timeout S: the advisor's time limit (its wall time is not routing work)
Definition route_job.hpp:73
bool advisor_redact
–advisor-redact: the report names nets and parts by alias (N1, P3); the advice is mapped back
Definition route_job.hpp:75
std::string items_out
–emit-items file; empty = none
Definition route_job.hpp:26
int threads
worker threads for the portfolio variants
Definition route_job.hpp:21
double stitch_distance_mm
0 = the rule's stitch_via_mm, else the catalogue value
std::string view_token
the token for a non-loopback viewer (empty = a random one)
Definition route_job.hpp:53
route::RouterOptions opt
sink is set here when viewing or recording
Definition route_job.hpp:20
std::string out
output .kicad_pcb; empty = do not write a board
Definition route_job.hpp:19
analysis::ReturnPathOptions return_paths
Reference-return audit of selected nets on the routed board (issue #7, doc 05 §42): off unless a sele...
Definition route_job.hpp:31
bool view_insecure
a non-loopback viewer without a token (–view-insecure)
Definition route_job.hpp:54
bool widen_power
After-route passes (doc 05 §39), all off by default.
Definition route_job.hpp:93
std::string view_embed
pages that may frame the viewer (–view-embed); empty = none
Definition route_job.hpp:55
std::vector< std::string > no_tracks_on
–no-tracks-on / –layer-cost (doc 05 §29): copper layer names, and "LAYER=FACTOR" entries.
Definition route_job.hpp:82
int advisor_rounds
–advisor-rounds N: consult again with the result of the advised run while connections are left
Definition route_job.hpp:74
bool split_cost_given
as critical_via_given (else +4 with si_rules)
Definition route_job.hpp:41
std::vector< std::string > critical_nets
Critical nets (issue #24, doc 05 §44, D117): route critical signals first, give them dearer vias,...
Definition route_job.hpp:34
bool split_hard
such cells are closed to critical nets
Definition route_job.hpp:42
std::string footprint_refs
–footprint-refs (issue #5, doc 05 §43): every footprint is checked against the datasheet land pattern...
Definition route_job.hpp:46
bool refill_repair
With soft zones: refill the zones after routing and route what the refill left unconnected (doc 05 §3...
Definition route_job.hpp:79
std::string advice_out
–advice-out FILE: where the advice that was used is saved (default: <out>.advice.json)
Definition route_job.hpp:76
bool critical_auto
also the nets the component rules' roles make critical, and differential pairs
Definition route_job.hpp:35
std::string in
input .kicad_pcb (its project files supply the design rules)
Definition route_job.hpp:18
double critical_via_mult
a via costs them this many times as much
Definition route_job.hpp:37
bool view_freeze
the viewer holds the scene on a routing stall (issue #8); –no-freeze says false in the board snapshot
Definition route_job.hpp:51
bool critical_first
route them before all other nets, tier by tier
Definition route_job.hpp:36
bool critical_via_given
set by the command line: with si_rules, a value that was given is kept (else x3)
Definition route_job.hpp:38
bool view
stream to the browser viewer
Definition route_job.hpp:28
std::string stuck_report_out
–stuck-report FILE: write the stuck report (of the run the advisor saw, else the final one)
Definition route_job.hpp:77