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

Classes

struct  UnionFind
struct  Connectivity
struct  ItemGraph
 KiCad 10's item graph (pcbnew/connectivity, CN_VISITOR): items of any nets are linked when their copper touches on a common layer, except two items that cannot change net (pads, zone fills, free vias) on different nets. More...
struct  ZoneFills
 Edge buckets of every zone fill (geom::PolygonIndex), so the zone questions below cost the nearby edges only. More...
struct  CopperItem
struct  Hole
struct  CopperModel
struct  ViolationItem
struct  Violation
struct  DrcOptions
struct  DrcReport
struct  RefillResult
class  RuleEngine
 compiled custom-rule condition More...
struct  CourtyardRegion
struct  CourtyardEntry
struct  CourtyardCache

Enumerations

enum class  ItemKind : std::uint8_t {
  Pad , Track , Arc , Via ,
  Zone , Graphic
}

Functions

Connectivity compute_connectivity (const model::Board &b, const CopperModel &cm, index::UniformGrid &grid, bool overlap_links=false, const ZoneFills *fills=nullptr)
bool in_item_graph (const CopperItem &it)
bool can_change_net (const CopperItem &it)
ItemGraph item_graph (const model::Board &b, const CopperModel &cm, index::UniformGrid &grid)
std::vector< int > zones_touching (const CopperModel &cm, const ZoneFills &zf, index::UniformGrid &grid, const geom::Shape &s, model::LayerMask layers, Coord clearance=0)
 Zone-fill items on layers whose copper is closer than clearance to s (0, the default: overlap only, as KiCad's SHAPE::Collide; 1: touching counts), ascending item indices.
std::vector< model::NetId > propagate_nets (const CopperModel &cm, const ItemGraph &g, const ZoneFills &zf, index::UniformGrid &grid)
 The nets KiCad's DRC sees after loading a board (CN_CONNECTIVITY_ALGO::PropagateNets, run by every connectivity build): a via touching only zone fills takes a zone's net (its own if one of the zones has it, else the lowest); then in every cluster of the graph without zones whose pads carry one net only, tracks, arcs, vias and board graphics take that net (a stray via on a track joins the track's net; a track bridging two nets keeps its own).
const char * kind_name (ItemKind k)
 KiCad expression type names: Pad, Track, Arc, Via, Zone, Graphic.
std::vector< geom::Shape > pad_shapes (const model::Pad &pad)
 Pad copper shape in absolute coordinates.
CopperModel build_copper (const model::Board &b)
std::vector< std::vector< model::Point > > edge_loops (const std::vector< geom::Shape > &edges, Coord tol=2 '000, bool *all_closed=nullptr)
 Closed loops chained from Edge.Cuts pieces whose ends meet within tol; pieces that close no loop are dropped (all_closed, if given, tells whether any was).
DrcReport run_drc (const model::Board &b, const model::DesignRules &r, const DrcOptions &opt={})
void write_drc_json (const DrcReport &rep, const std::string &path)
 Writes the report in kicad-cli's JSON layout (violations, unconnected_items; positions in mm).
RefillResult refill_zones (const model::Board &b, const model::DesignRules &r)
 Follows ZONE_FILLER::fillCopperZone: outline within the board, thermal gaps around same-net pads, every other item knocked out at its clearance, spokes that reach the fill, minimum-width pruning, then islands without a pad removed by each zone's island_removal_mode.
bool area_matches (const CopperItem &item, const model::Zone &area, bool enclosed)
 Requires a common copper layer.
CourtyardCache build_courtyards (const model::Board &board)
 Build once per board; invalid/unclosed contours leave the corresponding side empty and marked unreadable.
bool footprint_selected (const std::string &selector, const std::string &reference, const std::string &lib_id)
 KiCad's footprint selector (testFootprintSelector): a reference wildcard, or, when the selector contains ':', a library-id wildcard.
bool courtyard_matches (const CopperItem &item, const CourtyardCache &courtyards, const std::string &selector, const std::string &function)
 Function is intersectsCourtyard/intersectsFrontCourtyard/intersectsBackCourtyard.
std::vector< int > courtyard_entries (const CourtyardCache &courtyards, const std::string &selector)
 The entries a footprint selector picks, in entry order, and the same test against them.
bool courtyard_matches (const CopperItem &item, const CourtyardCache &courtyards, const std::vector< int > &entries, const std::string &function)

Enumeration Type Documentation

◆ ItemKind

enum class tmk::drc::ItemKind : std::uint8_t
strong
Enumerator
Pad 
Track 
Arc 
Via 
Zone 
Graphic 

Definition at line 11 of file copper.hpp.

Function Documentation

◆ area_matches()

bool tmk::drc::area_matches ( const CopperItem & item,
const model::Zone & area,
bool enclosed )

Requires a common copper layer.

Outline rings use even/odd filling (holes and disjoint contours); enclosed requires every copper shape to be wholly inside. The caller selects/caches zones; insideArea and intersectsArea both pass false.

◆ build_copper()

CopperModel tmk::drc::build_copper ( const model::Board & b)

◆ build_courtyards()

CourtyardCache tmk::drc::build_courtyards ( const model::Board & board)

Build once per board; invalid/unclosed contours leave the corresponding side empty and marked unreadable.

◆ can_change_net()

bool tmk::drc::can_change_net ( const CopperItem & it)

◆ compute_connectivity()

Connectivity tmk::drc::compute_connectivity ( const model::Board & b,
const CopperModel & cm,
index::UniformGrid & grid,
bool overlap_links = false,
const ZoneFills * fills = nullptr )

◆ courtyard_entries()

std::vector< int > tmk::drc::courtyard_entries ( const CourtyardCache & courtyards,
const std::string & selector )

The entries a footprint selector picks, in entry order, and the same test against them.

The rule engine resolves each selector once when the rules are compiled (Condition::bind): a rule is evaluated for every pair of items the DRC compares and for every lattice point the router visits, and matching the selector against every footprint each time made a courtyard clearance rule dominate the DRC of a large board.

◆ courtyard_matches() [1/2]

bool tmk::drc::courtyard_matches ( const CopperItem & item,
const CourtyardCache & courtyards,
const std::string & selector,
const std::string & function )

Function is intersectsCourtyard/intersectsFrontCourtyard/intersectsBackCourtyard.

Front and back are the footprint's own sides (KiCad: GetCourtyard(fp->IsFlipped() ? B_Cu : F_Cu)): the front courtyard of a flipped footprint is its B.CrtYd outline. The item's copper side does not matter. This overload matches the selector against every footprint for each query: the reference path.

◆ courtyard_matches() [2/2]

bool tmk::drc::courtyard_matches ( const CopperItem & item,
const CourtyardCache & courtyards,
const std::vector< int > & entries,
const std::string & function )

◆ edge_loops()

std::vector< std::vector< model::Point > > tmk::drc::edge_loops ( const std::vector< geom::Shape > & edges,
Coord tol = 2 '000,
bool * all_closed = nullptr )

Closed loops chained from Edge.Cuts pieces whose ends meet within tol; pieces that close no loop are dropped (all_closed, if given, tells whether any was).

◆ footprint_selected()

bool tmk::drc::footprint_selected ( const std::string & selector,
const std::string & reference,
const std::string & lib_id )

KiCad's footprint selector (testFootprintSelector): a reference wildcard, or, when the selector contains ':', a library-id wildcard.

Case-sensitive, like wxString::Matches.

◆ in_item_graph()

bool tmk::drc::in_item_graph ( const CopperItem & it)

◆ item_graph()

ItemGraph tmk::drc::item_graph ( const model::Board & b,
const CopperModel & cm,
index::UniformGrid & grid )

◆ kind_name()

const char * tmk::drc::kind_name ( ItemKind k)

KiCad expression type names: Pad, Track, Arc, Via, Zone, Graphic.

◆ pad_shapes()

std::vector< geom::Shape > tmk::drc::pad_shapes ( const model::Pad & pad)

Pad copper shape in absolute coordinates.

◆ propagate_nets()

std::vector< model::NetId > tmk::drc::propagate_nets ( const CopperModel & cm,
const ItemGraph & g,
const ZoneFills & zf,
index::UniformGrid & grid )

The nets KiCad's DRC sees after loading a board (CN_CONNECTIVITY_ALGO::PropagateNets, run by every connectivity build): a via touching only zone fills takes a zone's net (its own if one of the zones has it, else the lowest); then in every cluster of the graph without zones whose pads carry one net only, tracks, arcs, vias and board graphics take that net (a stray via on a track joins the track's net; a track bridging two nets keeps its own).

Clusters without pads take the net of their first item with a net. Returns one net per copper item.

◆ refill_zones()

RefillResult tmk::drc::refill_zones ( const model::Board & b,
const model::DesignRules & r )

Follows ZONE_FILLER::fillCopperZone: outline within the board, thermal gaps around same-net pads, every other item knocked out at its clearance, spokes that reach the fill, minimum-width pruning, then islands without a pad removed by each zone's island_removal_mode.

Teardrop zones lose their fill: kicad-cli's refill first rebuilds teardrops (TEARDROP_MANAGER::UpdateTeardrops), and a rebuilt teardrop joins a pad to a track that already touches it. Hatched zones are not redrawn: their stored fill is kept where the new solid fill still is (warning).

◆ run_drc()

DrcReport tmk::drc::run_drc ( const model::Board & b,
const model::DesignRules & r,
const DrcOptions & opt = {} )

◆ write_drc_json()

void tmk::drc::write_drc_json ( const DrcReport & rep,
const std::string & path )

Writes the report in kicad-cli's JSON layout (violations, unconnected_items; positions in mm).

◆ zones_touching()

std::vector< int > tmk::drc::zones_touching ( const CopperModel & cm,
const ZoneFills & zf,
index::UniformGrid & grid,
const geom::Shape & s,
model::LayerMask layers,
Coord clearance = 0 )

Zone-fill items on layers whose copper is closer than clearance to s (0, the default: overlap only, as KiCad's SHAPE::Collide; 1: touching counts), ascending item indices.