TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
length.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Net length and propagation delay as KiCad 10.0.6 measures them for its `length` and `skew` checks (design doc 05
4// §59; KiCad's LENGTH_DELAY_CALCULATION with the DRC's options: via spans, merged tracks, tracks clipped in pads).
5#include <cstdint>
6#include <vector>
7
8#include "model/board.hpp"
9#include "model/rules.hpp"
10
11namespace tmk::drc {
12
13// The length a via adds to its net in KiCad's length calculation (KiCad 10, BOARD_STACKUP::GetLayerDistance): the
14// stackup between the two copper layers the via joins, with the copper of an outer layer in full and of an inner
15// layer by half. A board without a stackup block gets KiCad's default one (35 um copper, 10 um per solder mask, the
16// rest of the board thickness shared evenly between the dielectrics). Empty (every via 0) when the project turns
17// "use height for length calculations" off.
18struct ViaHeights {
19 std::vector<Coord> from, to; // per copper layer: where a via starting / ending on it begins / ends, nm from the top
20 Coord between(int a, int b) const; // copper indices, either order; 0 for a == b
21};
23
24// The items of one net that a length or skew rule matched: indices into the board's pads, tracks, arcs and vias.
26 std::vector<int> pads, tracks, arcs, vias;
27};
28
29// KiCad's LENGTH_DELAY_STATS. Lengths in nm, delays in attoseconds.
30struct NetLength {
31 std::int64_t track = 0; // tracks and arcs, joined into chains and clipped in vias and pads
32 Coord via = 0; // via heights (0 when the project does not use heights)
33 Coord die = 0; // pad-to-die lengths
34 int vias = 0, pads = 0;
35 std::int64_t track_delay = 0, via_delay = 0, die_delay = 0;
36 double total() const { return static_cast<double>(track) + static_cast<double>(via) + static_cast<double>(die); }
37 double total_delay() const {
38 return static_cast<double>(track_delay) + static_cast<double>(via_delay) + static_cast<double>(die_delay);
39 }
40};
41
42// Length and delay of `items`, all of one net. `profile` is the tuning profile of the net's class (null: every
43// delay is 0, as in KiCad).
44NetLength net_length(const model::Board& b, const model::DesignRules& rules, const ViaHeights& vh, const LengthItems& items,
45 const model::TuningProfile* profile);
46
47} // namespace tmk::drc
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
NetLength net_length(const model::Board &b, const model::DesignRules &rules, const ViaHeights &vh, const LengthItems &items, const model::TuningProfile *profile)
Length and delay of items, all of one net.
ViaHeights via_heights(const model::Board &b, const model::DesignRules &rules)
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Design rules as KiCad defines them (design doc 08 §3–4): board minimums and net classes from the ....
The items of one net that a length or skew rule matched: indices into the board's pads,...
Definition length.hpp:25
std::vector< int > tracks
Definition length.hpp:26
std::vector< int > arcs
Definition length.hpp:26
std::vector< int > vias
Definition length.hpp:26
std::vector< int > pads
Definition length.hpp:26
KiCad's LENGTH_DELAY_STATS. Lengths in nm, delays in attoseconds.
Definition length.hpp:30
double total_delay() const
Definition length.hpp:37
std::int64_t via_delay
Definition length.hpp:35
std::int64_t track
tracks and arcs, joined into chains and clipped in vias and pads
Definition length.hpp:31
double total() const
Definition length.hpp:36
std::int64_t track_delay
Definition length.hpp:35
Coord via
via heights (0 when the project does not use heights)
Definition length.hpp:32
std::int64_t die_delay
Definition length.hpp:35
Coord die
pad-to-die lengths
Definition length.hpp:33
The length a via adds to its net in KiCad's length calculation (KiCad 10, BOARD_STACKUP::GetLayerDist...
Definition length.hpp:18
std::vector< Coord > from
Definition length.hpp:19
std::vector< Coord > to
per copper layer: where a via starting / ending on it begins / ends, nm from the top
Definition length.hpp:19
Coord between(int a, int b) const
copper indices, either order; 0 for a == b