TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
copper.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Copper items with exact shapes, built from the board model, for DRC and routing obstacles.
4#include <vector>
5
6#include "geom/shape.hpp"
7#include "model/board.hpp"
8
9namespace tmk::drc {
10
11enum class ItemKind : std::uint8_t { Pad, Track, Arc, Via, Zone, Graphic };
12const char* kind_name(ItemKind k); // KiCad expression type names: Pad, Track, Arc, Via, Zone, Graphic
13
14struct CopperItem {
16 int index = -1; // index in the board's pads/tracks/arcs/vias/zones/graphics vector
17 int sub = 0; // zone fill polygon index
19 model::LayerMask layers = 0; // copper layers the shape is on
20 std::vector<geom::Shape> shapes; // copper shape (identical on every layer in `layers`)
22 int footprint = -1;
23 model::Point pos; // reporting position
24 Coord width = 0; // tracks/arcs: width; vias: diameter
25 int owner = -1; // router connection that created this item (-1 = fixed copper)
26 bool removed = false; // ripped up (router working model only)
27 bool free_via = false; // via marked (free yes): its net is fixed for KiCad's net propagation
28 // Vias and pads whose copper KiCad removes on layers nothing connects to (model::UnconnectedLayers, doc 05 §60). On those
29 // layers only the hole is left, and KiCad's clearance test takes the hole for the item's copper there. Such an item is split:
30 // the item with the copper (`layers` without the bare layers) and a second item of the same kind and index whose layers are
31 // the bare ones and whose shape is the hole. `bare_part` on the first points to the second, `bare_of` on the second to the
32 // first. The second is no node of the connectivity graph and is not reported on its own. `span` is the padstack's whole layer
33 // set (KiCad's GetLayerSet), which rule conditions see; 0 for items that are not split.
35 int bare_part = -1, bare_of = -1;
36};
37
38struct Hole {
40 int item = -1; // copper item owning the hole (-1 for NPTH pads without copper)
41 int pad = -1, via = -1;
42 bool plated = true;
45 Coord clearance = -1; // local clearance of the owning pad/footprint (applies as hole clearance), -1 = none
46 bool removed = false;
47};
48
50 std::vector<CopperItem> items;
51 std::vector<Hole> holes;
52 std::vector<geom::Shape> edges; // Edge.Cuts outline pieces (open polylines, r = 0)
53 // Margin-layer graphics: KiCad's copper_edge_clearance treats them like the board edge
54 // (drc_test_provider_edge_clearance collects Edge.Cuts and Margin), but they are no part of the outline.
55 std::vector<geom::Shape> margins;
56};
57
58// Pad copper shape in absolute coordinates.
59std::vector<geom::Shape> pad_shapes(const model::Pad& pad);
60
62
63// KiCad's ConditionallyFlashed: the layers of a via, or of a plated through-hole pad on a board of `copper_count` layers, whose
64// copper depends on what connects there.
67
68// The copper layers of each via (`vias`) and pad (`pads`) as KiCad 10.0.6 flashes them (PCB_VIA::FlashLayer, PAD::FlashLayer): a
69// layer keeps its copper unless the padstack removes unconnected copper there and neither a zone connection (zone_layers) nor a
70// track, arc, via or pad of the net (not of the pad's own footprint) touches it. Touching is CN_VISITOR's test: on such a layer an
71// item is only its hole. Items that remove nothing keep their whole span.
72struct Flashing {
73 std::vector<model::LayerMask> vias, pads;
74};
76
77// Closed loops chained from Edge.Cuts pieces whose ends meet within `tol`; pieces that close no loop are dropped
78// (`all_closed`, if given, tells whether any was).
79std::vector<std::vector<model::Point>> edge_loops(const std::vector<geom::Shape>& edges, Coord tol = 2'000, bool* all_closed = nullptr);
80
81} // namespace tmk::drc
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
model::LayerMask conditional_layers(const model::Via &v)
KiCad's ConditionallyFlashed: the layers of a via, or of a plated through-hole pad on a board of copp...
CopperModel build_copper(const model::Board &b)
std::vector< geom::Shape > pad_shapes(const model::Pad &pad)
Pad copper shape in absolute coordinates.
Flashing flash_layers(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 ...
const char * kind_name(ItemKind k)
KiCad expression type names: Pad, Track, Arc, Via, Zone, Graphic.
std::int32_t NetId
0 = no net
Definition board.hpp:21
std::uint64_t LayerMask
bit i = copper layer i in stack order (0 = F.Cu, last = B.Cu)
Definition board.hpp:22
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Exact integer geometry for clearance checks (design doc 03 §1).
bool free_via
via marked (free yes): its net is fixed for KiCad's net propagation
Definition copper.hpp:27
model::Point pos
reporting position
Definition copper.hpp:23
int owner
router connection that created this item (-1 = fixed copper)
Definition copper.hpp:25
model::NetId net
Definition copper.hpp:18
bool removed
ripped up (router working model only)
Definition copper.hpp:26
model::LayerMask span
Vias and pads whose copper KiCad removes on layers nothing connects to (model::UnconnectedLayers,...
Definition copper.hpp:34
Coord width
tracks/arcs: width; vias: diameter
Definition copper.hpp:24
int index
index in the board's pads/tracks/arcs/vias/zones/graphics vector
Definition copper.hpp:16
std::vector< geom::Shape > shapes
copper shape (identical on every layer in layers)
Definition copper.hpp:20
model::LayerMask layers
copper layers the shape is on
Definition copper.hpp:19
int sub
zone fill polygon index
Definition copper.hpp:17
std::vector< Hole > holes
Definition copper.hpp:51
std::vector< CopperItem > items
Definition copper.hpp:50
std::vector< geom::Shape > edges
Edge.Cuts outline pieces (open polylines, r = 0).
Definition copper.hpp:52
std::vector< geom::Shape > margins
Margin-layer graphics: KiCad's copper_edge_clearance treats them like the board edge (drc_test_provid...
Definition copper.hpp:55
The copper layers of each via (vias) and pad (pads) as KiCad 10.0.6 flashes them (PCB_VIA::FlashLayer...
Definition copper.hpp:72
std::vector< model::LayerMask > vias
Definition copper.hpp:73
std::vector< model::LayerMask > pads
Definition copper.hpp:73
int item
copper item owning the hole (-1 for NPTH pads without copper)
Definition copper.hpp:40
model::Point pos
Definition copper.hpp:44
model::NetId net
Definition copper.hpp:43
geom::Shape shape
Definition copper.hpp:39
Coord clearance
local clearance of the owning pad/footprint (applies as hole clearance), -1 = none
Definition copper.hpp:45