TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
legalize.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Gridless legalisation of routed copper (doc 05 §41.3, D104).
4//
5// The lattice router places every track on a lattice point and cannot move one it has committed, so a solution found under
6// looser rules (smaller clearances) usually has room to spare that the lattice cannot use. This module takes such routes and
7// moves the vertices of their tracks and vias (the topology, layers and order along every channel stay as they are) until
8// every clearance of the board's real rules holds, or as many as it can: a vertex is pushed along the normal of each pair of
9// copper items that are too close, by Gauss-Seidel sweeps over the pairs (position-based dynamics, Müller, Heidelberger,
10// Hennix and Ratcliff, J. Vis. Commun. Image Represent. 18(2), 2007). A prototype that solved the same problem by sequential
11// linear programming (HiGHS, minimum total movement) did about as well (6 stuck srj20 boards, 0.06 mm solutions to 0.10 mm: LP 3
12// legal and 3-11 pairs left on the others, projection 2 legal and 2-9 left). What remains
13// violated is dropped and routed again by the caller, and every route that is kept passes the router's exact check, so the
14// heuristic can lose work but never legality.
15#include <cstdint>
16#include <vector>
17
18#include "geom/point.hpp"
19#include "model/board.hpp"
20#include "model/rules.hpp"
21#include "route/router.hpp"
22
23namespace tmk::route {
24
26 double box_mm = 0.25; // a vertex stays within this distance of where it started
27 double margin_mm = 0.003; // clearance asked for beyond the rule (rounding to nanometres, the pairs between sweeps)
28 int sweeps = 300; // projection sweeps at most
29 double edge_mm = 0.035; // copper stays this far inside the board outline (plus the rule's edge clearance)
30 // > 0: every unlocked route track is cut into pieces of at most this length (at the vertices of same-net copper that lie on it, and evenly
31 // in between), so that a long straight track can bend where its neighbours are too close, instead of only moving as a whole; after the
32 // sweeps the vertices that stayed on a straight line are merged again. 0 = the vertices the routes have (unchanged behaviour).
33 double subdivide_mm = 0;
34 std::uint64_t seed = 0; // != 0: the pairs are visited in another (seeded) order, which leaves other pinches unresolved: portfolio variants differ
35 std::vector<geom::Point> outline; // board outline polygon (Obstacles::outline()); empty = unbounded
36};
37
39 int nodes = 0; // vertices of the routes (tracks and vias merged by net and position)
40 int moved = 0; // vertices that ended up elsewhere
41 int pairs_before = 0; // pairs of copper items closer than the rules allow, before and after
42 int pairs_after = 0;
43 double max_move_mm = 0;
44 int sweeps_used = 0;
45};
46
47// Moves the vertices of `routes` (tracks and vias of the connections) so that the clearances of `rules` hold between nets, to
48// the pads of `board` and to its fixed tracks and vias. Locked or foreign copper never moves; track ends at the centre of
49// their own pad stay. Deterministic.
50LegalizeResult legalize_routes(const model::Board& board, const model::DesignRules& rules, std::vector<ConnRoute>& routes,
51 const LegalizeOptions& opt = {});
52
53} // namespace tmk::route
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
LegalizeResult legalize_routes(const model::Board &board, const model::DesignRules &rules, std::vector< ConnRoute > &routes, const LegalizeOptions &opt={})
Moves the vertices of routes (tracks and vias of the connections) so that the clearances of rules hol...
Integer-nanometre points and KiCad-compatible rotation.
TraceMaker's detailed router, version 1 (roadmap M4; design doc 05 §2, §5).
Design rules as KiCad defines them (design doc 08 §3–4): board minimums and net classes from the ....
double box_mm
a vertex stays within this distance of where it started
Definition legalize.hpp:26
double subdivide_mm
> 0: every unlocked route track is cut into pieces of at most this length (at the vertices of same-ne...
Definition legalize.hpp:33
std::uint64_t seed
!= 0: the pairs are visited in another (seeded) order, which leaves other pinches unresolved: portfol...
Definition legalize.hpp:34
double edge_mm
copper stays this far inside the board outline (plus the rule's edge clearance)
Definition legalize.hpp:29
std::vector< geom::Point > outline
board outline polygon (Obstacles::outline()); empty = unbounded
Definition legalize.hpp:35
double margin_mm
clearance asked for beyond the rule (rounding to nanometres, the pairs between sweeps)
Definition legalize.hpp:27
int sweeps
projection sweeps at most
Definition legalize.hpp:28
int nodes
vertices of the routes (tracks and vias merged by net and position)
Definition legalize.hpp:39
int pairs_before
pairs of copper items closer than the rules allow, before and after
Definition legalize.hpp:41
int moved
vertices that ended up elsewhere
Definition legalize.hpp:40