TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
tmk::crules Namespace Reference

Namespaces

namespace  imp

Classes

struct  Detector
struct  RuleSpec
struct  Category
struct  Catalogue
struct  CriticalNet
struct  CriticalRole
 The table itself, for the docs and the tests: (category id, role, tier). More...
struct  Role
struct  RuleOverride
 What the user override file (doc 15 §6.3) changed for one rule of one instance. More...
struct  Instance
struct  Detection
struct  Measure
struct  EffectiveRule
struct  Evaluation
struct  ProximityPairs
 A proximity rule bound to pads (doc 15 §4 proximity): each pair is (pad of the part that should move close, pad it should be close to). More...
struct  PlacementAffinity
 Placement pseudo-nets for every applicable proximity rule (mode soft or on; confidence >= suggest). More...
struct  EdgeAttraction
 Connector edge pull for the placer (doc 15 §5.2 edge; CONN-01, USB2-11, DISP-02), opt-in (tracemaker-place –edge-attraction): the anchor of every instance with a connector edge rule (mode soft/on, not advisory, not disabled by the user), once per footprint, never a locked part and never a pin header or socket (board-to-board and jumper headers, CONN-01 note). More...
struct  GeneratedKeepout
 Keep-out rule areas (doc 15 §5.5, P2) for instances at confidence >= apply: crystal + load caps (XTAL-04), switching-regulator inductor (BUCK-06/BOOST-04), discrete Ethernet magnetics (ETH-05: tracks, vias and zones on the magnetics' side and the adjacent layer only). More...
struct  SyntheticClass
 Net classes from rules (doc 15 §5.3-5.4 and §16, P5): impedance rules with a computed width/gap, and width rules with a current or a minimum width, become synthetic net classes for the nets bound to the rule's roles. More...
struct  LayerGeometry
 One copper layer's line geometry from the stackup. More...
struct  LineSolution
 The width (and gap) that meets one target on one layer. More...
struct  ImpedancePlan
struct  CurrentPlan
 Width for a rule that names a current (doc 15 §5.4, IPC-2221). More...
struct  LayerDelay
 Propagation delay per copper layer used to turn ps skew budgets into mm (doc 15 §4): from the stackup (eps_eff of a 50 ohm line on outer layers, er on inner layers) or the catalogue's FR-4 defaults. More...
struct  OverrideEntry
struct  Overrides
class  BoardIndex
struct  DecapTie
 Decision D25 (doc 04 §2): a two-pad capacitor (C*) between a supply net and a ground net is tied to the nearest pad, in the input placement, of an IC (U*, IC*) on the same supply; ties keep the lowest pad index. More...
struct  Point

Enumerations

enum class  Signal : std::uint8_t {
  RefPrefix , LibId , Value , Keywords ,
  PinName , NetName , Topology
}
 What a detector looks at (doc 15 §3.1). More...
enum class  Severity : std::uint8_t { Hard , Soft , Advisory }
enum class  Mode : std::uint8_t { Off , Report , Soft , On }
 –component-rules (doc 15 §3.5): off = nothing; report = detect and check only; soft = rules as costs, no hard constraints; on = catalogue severities (generated keep-outs become router/DRC rule areas). More...
enum class  Status : std::uint8_t { Applied , SatisfiedByBoard , NotApplied , Advisory }

Functions

const char * signal_name (Signal s)
const char * severity_name (Severity s)
Catalogue parse_catalogue (std::string_view json_text)
 Parses the catalogue JSON.
Catalogue load_catalogue_file (const std::string &path)
const Catalogue & builtin_catalogue ()
 The catalogue embedded at build time (src/crules/catalogue.json), parsed once.
std::string_view builtin_catalogue_json ()
std::vector< CriticalNet > critical_nets (const model::Board &b, const Catalogue &cat, const Detection &det, const std::vector< std::pair< model::NetId, model::NetId > > &diff_pairs)
 The nets playing a critical role in a detected category instance, and diff_pairs (named pairs, tier 2) that no role claimed.
const std::vector< CriticalRole > & critical_roles ()
const nlohmann::ordered_json & rule_params (const Instance &in, const RuleSpec &r)
 The parameters of rule r for instance in: the catalogue's, or the user's after set entries (doc 15 §6.3).
Detection detect (const model::Board &b, const Catalogue &cat, const Overrides *ov=nullptr)
 With ov (the user override file, doc 15 §3.5 level 1): references are checked against the board (throws on unknown ones); deny removes a category from a part (listed as possible, so a competing category can win); assert forces one (confidence 100, wins conflicts; bound by the category's binder, or to the anchor alone when the binder rejects the part); disable and set are attached to the instances: entries for one reference (@REF) take precedence over global ones, and among equals the later entry wins.
Mode parse_mode (std::string_view s)
 throws std::invalid_argument
const char * mode_name (Mode m)
const char * status_name (Status s)
std::vector< ProximityPairs > proximity_pairs (const model::Board &b, const Catalogue &cat, const Detection &det)
Evaluation evaluate (const model::Board &b, const model::DesignRules *rules, const Catalogue &cat, const Detection &det, Mode mode)
std::vector< PlacementAffinity > placement_affinities (const model::Board &b, const Catalogue &cat, const Detection &det, Mode mode)
std::vector< EdgeAttraction > edge_attractions (const model::Board &b, const Catalogue &cat, const Detection &det, Mode mode)
std::vector< GeneratedKeepout > generate_keepouts (const model::Board &b, const Catalogue &cat, const Detection &det, std::vector< std::string > *not_generated=nullptr)
std::string dru_sidecar (const model::Board &b, const Catalogue &cat, const Detection &det)
 The same intent as KiCad custom rules with net exemptions (which rule areas cannot express), for the user to review or merge: "\<output\>.tracemaker.kicad_dru".
std::vector< std::pair< model::NetId, model::NetId > > usb_pairs (const model::Board &b, const Catalogue &cat, const Detection &det)
 USB 2.0 D+/D- pairs to route coupled first (USB2-02, doc 15 P3): one (dp, dm) per usb2 instance whose dp and dm roles each bind exactly one net, in instance order, without duplicates.
std::vector< SyntheticClass > synthetic_net_classes (const model::Board &b, const model::DesignRules &rules, const Catalogue &cat, const Detection &det, const Evaluation &ev)
model::DesignRules with_synthetic_classes (const model::Board &b, model::DesignRules rules, const std::vector< SyntheticClass > &sc)
 rules with the synthetic classes added and their nets assigned to them (in memory only, rule 8).
std::string report_text (const model::Board &b, const Catalogue &cat, const Detection &det, const Evaluation &ev)
 Report (doc 15 §7).
nlohmann::json report_json (const model::Board &b, const Catalogue &cat, const Detection &det, const Evaluation &ev)
std::vector< LayerGeometry > stackup_geometry (const model::Board &b)
ImpedancePlan plan_impedance (const model::Board &b, const model::DesignRules *rules, const RuleSpec &r)
 Board bounds used for solving: the narrowest width and the pair / coplanar gap (see impedance_rules.cpp).
std::string impedance_text (const ImpedancePlan &p)
double pair_impedance (const model::Board &b, int copper, Coord width, Coord gap)
 Differential impedance of an existing width/gap on a copper layer (to compare a board net class with the target); < 0 when the layer has no complete stackup geometry.
nlohmann::json impedance_json (const ImpedancePlan &p)
CurrentPlan plan_current (const model::Board &b, const RuleSpec &r)
std::string current_text (const CurrentPlan &p)
nlohmann::json current_json (const CurrentPlan &p)
std::vector< LayerDelay > prop_delays (const model::Board &b, const Catalogue &cat)
std::string stackup_summary (const model::Board &b, const Catalogue &cat)
 One line for the report header: the stackup summary and the delays, or why defaults are used.
nlohmann::json stackup_json (const model::Board &b, const Catalogue &cat)
std::string upper (std::string_view s)
std::string lower (std::string_view s)
std::string ref_letters (std::string_view ref)
 Leading letters of a reference, upper case: "C12" -> "C", "IC3" -> "IC", "FB1" -> "FB", "REF**" -> "REF".
bool natural_less (std::string_view a, std::string_view b)
 Natural order of references: "C2" < "C10" < "D1"; ties broken by plain string comparison.
std::string_view net_leaf (std::string_view name)
 The last hierarchical component of a net name: "/mcu/XTAL_IN" -> "XTAL_IN".
bool power_like_name (std::string_view name)
 Supply-like net names (+3V3, VCC, VDD_IO, 5V, VBUS, GND, ...), including grounds.
bool ground_like_name (std::string_view name)
bool analog_supply_name (std::string_view name)
 Analog supplies, references and core-regulator outputs that power_like_name misses (VREF, AREF, VCAP, ...).
std::optional< int > net_millivolts (std::string_view name)
 Voltage in millivolts from a supply name: "+5V" 5000, "3V3" 3300, "+3.3V" 3300, "1V8" 1800, "VCC_12V" 12000.
std::optional< std::int64_t > capacitance_pf (std::string_view value)
 Capacitance in picofarads from a value field: "100nF" 100000, "4u7" 4700000, "10uF/16V" 10000000, "22p" 22.
Overrides parse_overrides (std::string_view json_text, const Catalogue &cat, const std::string &source="rules override")
 Parses and validates an override file.
Overrides load_overrides_file (const std::string &path, const Catalogue &cat)
 Reads a JSON file; a .yaml/.yml file is refused with the conversion command.
void check_override_refs (const Overrides &ov, const model::Board &b)
 Every reference must name a footprint of the board (throws otherwise, listing the unknown ones).
std::vector< DecapTie > decap_ties (const model::Board &b, const std::function< bool(int)> &usable, bool generalised)

Variables

constexpr int kNoPinNameCap = 60
 Confidence cap when the board carries no pad pin names (KiCad 5 files): doc 15 §3.6.
constexpr int kPossibleMin = 20
 Instances below this confidence are not even listed as "possible" (they would list every J* and U*).

Enumeration Type Documentation

◆ Mode

enum class tmk::crules::Mode : std::uint8_t
strong

–component-rules (doc 15 §3.5): off = nothing; report = detect and check only; soft = rules as costs, no hard constraints; on = catalogue severities (generated keep-outs become router/DRC rule areas).

Enumerator
Off 
Report 
Soft 
On 

Definition at line 27 of file engine.hpp.

◆ Severity

enum class tmk::crules::Severity : std::uint8_t
strong
Enumerator
Hard 
Soft 
Advisory 

Definition at line 20 of file catalogue.hpp.

◆ Signal

enum class tmk::crules::Signal : std::uint8_t
strong

What a detector looks at (doc 15 §3.1).

Enumerator
RefPrefix 
LibId 
Value 
Keywords 
PinName 
NetName 
Topology 

Definition at line 19 of file catalogue.hpp.

◆ Status

enum class tmk::crules::Status : std::uint8_t
strong
Enumerator
Applied 
SatisfiedByBoard 
NotApplied 
Advisory 

Definition at line 31 of file engine.hpp.

Function Documentation

◆ analog_supply_name()

bool tmk::crules::analog_supply_name ( std::string_view name)

Analog supplies, references and core-regulator outputs that power_like_name misses (VREF, AREF, VCAP, ...).

◆ builtin_catalogue()

const Catalogue & tmk::crules::builtin_catalogue ( )

The catalogue embedded at build time (src/crules/catalogue.json), parsed once.

◆ builtin_catalogue_json()

std::string_view tmk::crules::builtin_catalogue_json ( )

◆ capacitance_pf()

std::optional< std::int64_t > tmk::crules::capacitance_pf ( std::string_view value)

Capacitance in picofarads from a value field: "100nF" 100000, "4u7" 4700000, "10uF/16V" 10000000, "22p" 22.

◆ check_override_refs()

void tmk::crules::check_override_refs ( const Overrides & ov,
const model::Board & b )

Every reference must name a footprint of the board (throws otherwise, listing the unknown ones).

◆ critical_nets()

std::vector< CriticalNet > tmk::crules::critical_nets ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
const std::vector< std::pair< model::NetId, model::NetId > > & diff_pairs )

The nets playing a critical role in a detected category instance, and diff_pairs (named pairs, tier 2) that no role claimed.

A net found twice keeps the lower tier. Deterministic: tier, then net id.

◆ critical_roles()

const std::vector< CriticalRole > & tmk::crules::critical_roles ( )

◆ current_json()

nlohmann::json tmk::crules::current_json ( const CurrentPlan & p)

◆ current_text()

std::string tmk::crules::current_text ( const CurrentPlan & p)

◆ decap_ties()

std::vector< DecapTie > tmk::crules::decap_ties ( const model::Board & b,
const std::function< bool(int)> & usable,
bool generalised )

◆ detect()

Detection tmk::crules::detect ( const model::Board & b,
const Catalogue & cat,
const Overrides * ov = nullptr )

With ov (the user override file, doc 15 §3.5 level 1): references are checked against the board (throws on unknown ones); deny removes a category from a part (listed as possible, so a competing category can win); assert forces one (confidence 100, wins conflicts; bound by the category's binder, or to the anchor alone when the binder rejects the part); disable and set are attached to the instances: entries for one reference (@REF) take precedence over global ones, and among equals the later entry wins.

◆ dru_sidecar()

std::string tmk::crules::dru_sidecar ( const model::Board & b,
const Catalogue & cat,
const Detection & det )

The same intent as KiCad custom rules with net exemptions (which rule areas cannot express), for the user to review or merge: "\<output\>.tracemaker.kicad_dru".

Never written into the user's own files (rule 8).

◆ edge_attractions()

std::vector< EdgeAttraction > tmk::crules::edge_attractions ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
Mode mode )

◆ evaluate()

Evaluation tmk::crules::evaluate ( const model::Board & b,
const model::DesignRules * rules,
const Catalogue & cat,
const Detection & det,
Mode mode )

◆ generate_keepouts()

std::vector< GeneratedKeepout > tmk::crules::generate_keepouts ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
std::vector< std::string > * not_generated = nullptr )

◆ ground_like_name()

bool tmk::crules::ground_like_name ( std::string_view name)

◆ impedance_json()

nlohmann::json tmk::crules::impedance_json ( const ImpedancePlan & p)

◆ impedance_text()

std::string tmk::crules::impedance_text ( const ImpedancePlan & p)

◆ load_catalogue_file()

Catalogue tmk::crules::load_catalogue_file ( const std::string & path)

◆ load_overrides_file()

Overrides tmk::crules::load_overrides_file ( const std::string & path,
const Catalogue & cat )

Reads a JSON file; a .yaml/.yml file is refused with the conversion command.

◆ lower()

std::string tmk::crules::lower ( std::string_view s)

◆ mode_name()

const char * tmk::crules::mode_name ( Mode m)

◆ natural_less()

bool tmk::crules::natural_less ( std::string_view a,
std::string_view b )

Natural order of references: "C2" < "C10" < "D1"; ties broken by plain string comparison.

◆ net_leaf()

std::string_view tmk::crules::net_leaf ( std::string_view name)

The last hierarchical component of a net name: "/mcu/XTAL_IN" -> "XTAL_IN".

◆ net_millivolts()

std::optional< int > tmk::crules::net_millivolts ( std::string_view name)

Voltage in millivolts from a supply name: "+5V" 5000, "3V3" 3300, "+3.3V" 3300, "1V8" 1800, "VCC_12V" 12000.

◆ pair_impedance()

double tmk::crules::pair_impedance ( const model::Board & b,
int copper,
Coord width,
Coord gap )

Differential impedance of an existing width/gap on a copper layer (to compare a board net class with the target); < 0 when the layer has no complete stackup geometry.

◆ parse_catalogue()

Catalogue tmk::crules::parse_catalogue ( std::string_view json_text)

Parses the catalogue JSON.

Throws std::runtime_error naming the offending entry on schema errors (an unknown signal, a weight outside 0..100, a bad regex, a missing rule id/kind/severity).

◆ parse_mode()

Mode tmk::crules::parse_mode ( std::string_view s)

throws std::invalid_argument

◆ parse_overrides()

Overrides tmk::crules::parse_overrides ( std::string_view json_text,
const Catalogue & cat,
const std::string & source = "rules override" )

Parses and validates an override file.

Throws std::runtime_error with a message that names the source and the offending entry.

◆ placement_affinities()

std::vector< PlacementAffinity > tmk::crules::placement_affinities ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
Mode mode )

◆ plan_current()

CurrentPlan tmk::crules::plan_current ( const model::Board & b,
const RuleSpec & r )

◆ plan_impedance()

ImpedancePlan tmk::crules::plan_impedance ( const model::Board & b,
const model::DesignRules * rules,
const RuleSpec & r )

Board bounds used for solving: the narrowest width and the pair / coplanar gap (see impedance_rules.cpp).

◆ power_like_name()

bool tmk::crules::power_like_name ( std::string_view name)

Supply-like net names (+3V3, VCC, VDD_IO, 5V, VBUS, GND, ...), including grounds.

Decision D25's test, shared with the placer (place::power_like_name forwards here).

◆ prop_delays()

std::vector< LayerDelay > tmk::crules::prop_delays ( const model::Board & b,
const Catalogue & cat )

◆ proximity_pairs()

std::vector< ProximityPairs > tmk::crules::proximity_pairs ( const model::Board & b,
const Catalogue & cat,
const Detection & det )

◆ ref_letters()

std::string tmk::crules::ref_letters ( std::string_view ref)

Leading letters of a reference, upper case: "C12" -> "C", "IC3" -> "IC", "FB1" -> "FB", "REF**" -> "REF".

◆ report_json()

nlohmann::json tmk::crules::report_json ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
const Evaluation & ev )

◆ report_text()

std::string tmk::crules::report_text ( const model::Board & b,
const Catalogue & cat,
const Detection & det,
const Evaluation & ev )

Report (doc 15 §7).

◆ rule_params()

const nlohmann::ordered_json & tmk::crules::rule_params ( const Instance & in,
const RuleSpec & r )

The parameters of rule r for instance in: the catalogue's, or the user's after set entries (doc 15 §6.3).

◆ severity_name()

const char * tmk::crules::severity_name ( Severity s)

◆ signal_name()

const char * tmk::crules::signal_name ( Signal s)

◆ stackup_geometry()

std::vector< LayerGeometry > tmk::crules::stackup_geometry ( const model::Board & b)

◆ stackup_json()

nlohmann::json tmk::crules::stackup_json ( const model::Board & b,
const Catalogue & cat )

◆ stackup_summary()

std::string tmk::crules::stackup_summary ( const model::Board & b,
const Catalogue & cat )

One line for the report header: the stackup summary and the delays, or why defaults are used.

◆ status_name()

const char * tmk::crules::status_name ( Status s)

◆ synthetic_net_classes()

std::vector< SyntheticClass > tmk::crules::synthetic_net_classes ( const model::Board & b,
const model::DesignRules & rules,
const Catalogue & cat,
const Detection & det,
const Evaluation & ev )

◆ upper()

std::string tmk::crules::upper ( std::string_view s)

◆ usb_pairs()

std::vector< std::pair< model::NetId, model::NetId > > tmk::crules::usb_pairs ( const model::Board & b,
const Catalogue & cat,
const Detection & det )

USB 2.0 D+/D- pairs to route coupled first (USB2-02, doc 15 P3): one (dp, dm) per usb2 instance whose dp and dm roles each bind exactly one net, in instance order, without duplicates.

◆ with_synthetic_classes()

model::DesignRules tmk::crules::with_synthetic_classes ( const model::Board & b,
model::DesignRules rules,
const std::vector< SyntheticClass > & sc )

rules with the synthetic classes added and their nets assigned to them (in memory only, rule 8).

Variable Documentation

◆ kNoPinNameCap

int tmk::crules::kNoPinNameCap = 60
inlineconstexpr

Confidence cap when the board carries no pad pin names (KiCad 5 files): doc 15 §3.6.

Definition at line 65 of file detect.hpp.

◆ kPossibleMin

int tmk::crules::kPossibleMin = 20
inlineconstexpr

Instances below this confidence are not even listed as "possible" (they would list every J* and U*).

Definition at line 67 of file detect.hpp.