|
KiCad PCB EDA Suite
|
Reusable creepage solver shared by the batch DRC provider and the realtime drag overlay. More...
#include <drc_creepage_engine.h>
Public Member Functions | |
| CREEPAGE_ENGINE (BOARD &aBoard) | |
| void | SetMinGrooveWidth (int aWidth) |
| std::optional< CREEPAGE_RESULT > | SolveNetPairWholeBoard (int aNetA, int aNetB, PCB_LAYER_ID aLayer, double aConstraint) |
| Solve a single net pair against the whole board on one layer, building a fresh graph. | |
| void | BeginInteractive (PCB_LAYER_ID aLayer, const std::set< int > &aAffectedNets, const std::set< const BOARD_ITEM * > &aMovingItems, int aMargin, std::function< double(int, int)> aConstraintFn) |
| Begin an interactive drag session. | |
| std::vector< CREEPAGE_RESULT > | Update (int aNearMargin=0) |
| Recompute creepage for the dragged nets at the items' current board positions. | |
| void | EndInteractive () |
| bool | IsInteractive () const |
Private Member Functions | |
| void | populateBoardEdgeGraph (CREEPAGE_GRAPH &aGraph, SHAPE_POLY_SET &aOutline) |
| Build the board-edge geometry into aGraph: groove width, outline (NPTH-subtracted), edge shapes, and the node decomposition. | |
| void | connectChildren (CREEPAGE_GRAPH &aGraph) |
| Run the same-parent ConnectChildren pass the legacy solver runs before Dijkstra. | |
| std::optional< CREEPAGE_RESULT > | extractResult (const std::vector< std::shared_ptr< GRAPH_CONNECTION > > &aPath, double aDistance, int aNetA, int aNetB, double aConstraint, int aNearMargin) |
| Extract a CREEPAGE_RESULT from a solved shortest path, or nullopt if not a violation. | |
| std::map< int, std::shared_ptr< GRAPH_NODE > > | addNetsInRegion (const BOX2I &aRegion) |
| Add net elements for the affected nets plus every other net whose bbox intersects aRegion. | |
| void | buildBoardEdgePrefix () |
| (Re)build the board-edge visibility sub-graph from the board at its current state and record it as the prefix. | |
| bool | movingItemsHaveNPTH () const |
| True when any dragged item carries an NPTH hole, making the board-edge graph position dependent and therefore not cacheable across frames. | |
Private Attributes | |
| BOARD & | m_board |
| int | m_minGrooveWidth = 0 |
| bool | m_interactive = false |
| bool | m_dynamicEdges = false |
| PCB_LAYER_ID | m_layer = UNDEFINED_LAYER |
| int | m_margin = 0 |
| std::set< int > | m_affectedNets |
| std::set< const BOARD_ITEM * > | m_movingItems |
| std::function< double(int, int)> | m_constraintFn |
| std::map< int, BOX2I > | m_staticNetBBoxes |
| std::unique_ptr< CREEPAGE_GRAPH > | m_graph |
| std::unique_ptr< SHAPE_POLY_SET > | m_outline |
| size_t | m_staticNodeCount = 0 |
| size_t | m_staticConnCount = 0 |
Reusable creepage solver shared by the batch DRC provider and the realtime drag overlay.
In whole-board mode (SolveNetPairWholeBoard) the engine rebuilds a graph for one net pair and is the reference used to prove exact parity with the legacy inline path.
In interactive mode the engine builds the static board-edge plus other-net sub-graph once inside a constraint-bounded ROI (BeginInteractive), then per frame truncates back to that static prefix, re-adds only the dragged item's geometry at its current board position, links just the moving geometry, and solves the dragged nets against their neighbours (Update).
Definition at line 73 of file drc_creepage_engine.h.
|
explicit |
Definition at line 33 of file drc_creepage_engine.cpp.
References m_board.
|
private |
Add net elements for the affected nets plus every other net whose bbox intersects aRegion.
Returns the per-net virtual node keyed by net code.
Definition at line 164 of file drc_creepage_engine.cpp.
References m_affectedNets, m_board, m_graph, m_layer, m_margin, and m_staticNetBBoxes.
Referenced by Update().
| void CREEPAGE_ENGINE::BeginInteractive | ( | PCB_LAYER_ID | aLayer, |
| const std::set< int > & | aAffectedNets, | ||
| const std::set< const BOARD_ITEM * > & | aMovingItems, | ||
| int | aMargin, | ||
| std::function< double(int, int)> | aConstraintFn ) |
Begin an interactive drag session.
Builds the static board-edge sub-graph once and records it as the immutable graph prefix. aAffectedNets are the nets carried by the dragged items; aMargin bounds the search radius (the largest creepage constraint plus a near-violation band). Other nets' geometry and the copper paths are rebuilt each frame within that margin of the dragged items.
Definition at line 189 of file drc_creepage_engine.cpp.
References buildBoardEdgePrefix(), m_affectedNets, m_board, m_constraintFn, m_dynamicEdges, m_interactive, m_layer, m_margin, m_movingItems, m_staticNetBBoxes, and movingItemsHaveNPTH().
Referenced by BOOST_FIXTURE_TEST_CASE().
|
private |
(Re)build the board-edge visibility sub-graph from the board at its current state and record it as the prefix.
Called once at drag start, or every frame when a dragged item carries NPTH holes (which are moving board-edge obstacles).
Definition at line 214 of file drc_creepage_engine.cpp.
References connectChildren(), Edge_Cuts, m_board, m_graph, m_margin, m_outline, m_staticConnCount, m_staticNodeCount, and populateBoardEdgeGraph().
Referenced by BeginInteractive(), and Update().
|
private |
Run the same-parent ConnectChildren pass the legacy solver runs before Dijkstra.
Definition at line 55 of file drc_creepage_engine.cpp.
References alg::for_all_pairs(), and CREEPAGE_GRAPH::m_nodes.
Referenced by buildBoardEdgePrefix(), SolveNetPairWholeBoard(), and Update().
| void CREEPAGE_ENGINE::EndInteractive | ( | ) |
Definition at line 333 of file drc_creepage_engine.cpp.
References m_affectedNets, m_constraintFn, m_dynamicEdges, m_graph, m_interactive, m_movingItems, m_outline, m_staticConnCount, m_staticNetBBoxes, and m_staticNodeCount.
Referenced by BOOST_FIXTURE_TEST_CASE().
|
private |
Extract a CREEPAGE_RESULT from a solved shortest path, or nullopt if not a violation.
Definition at line 87 of file drc_creepage_engine.cpp.
References result.
Referenced by SolveNetPairWholeBoard(), and Update().
|
inline |
Definition at line 111 of file drc_creepage_engine.h.
References m_interactive.
|
private |
True when any dragged item carries an NPTH hole, making the board-edge graph position dependent and therefore not cacheable across frames.
Definition at line 232 of file drc_creepage_engine.cpp.
References m_movingItems, NPTH, pad, PCB_FOOTPRINT_T, and PCB_PAD_T.
Referenced by BeginInteractive().
|
private |
Build the board-edge geometry into aGraph: groove width, outline (NPTH-subtracted), edge shapes, and the node decomposition.
aOutline must outlive aGraph as its boardOutline. Shared by the whole-board solve and the interactive prefix so they stay in lockstep.
Definition at line 39 of file drc_creepage_engine.cpp.
References BuildCreepageBoardEdges(), m_board, CREEPAGE_GRAPH::m_boardEdge, CREEPAGE_GRAPH::m_boardOutline, m_minGrooveWidth, CREEPAGE_GRAPH::m_minGrooveWidth, CREEPAGE_GRAPH::m_ownedBoardEdges, CREEPAGE_GRAPH::m_shapeCollection, CREEPAGE_GRAPH::RemoveDuplicatedShapes(), CREEPAGE_GRAPH::TransformCreepShapesToNodes(), and CREEPAGE_GRAPH::TransformEdgeToCreepShapes().
Referenced by buildBoardEdgePrefix(), and SolveNetPairWholeBoard().
|
inline |
Definition at line 78 of file drc_creepage_engine.h.
References m_minGrooveWidth.
Referenced by DRC_TEST_PROVIDER_CREEPAGE::testCreepageV2().
| std::optional< CREEPAGE_RESULT > CREEPAGE_ENGINE::SolveNetPairWholeBoard | ( | int | aNetA, |
| int | aNetB, | ||
| PCB_LAYER_ID | aLayer, | ||
| double | aConstraint ) |
Solve a single net pair against the whole board on one layer, building a fresh graph.
Returns the creepage result when a path shorter than the constraint exists (a violation), otherwise std::nullopt. This is the parity reference for the batch provider.
Definition at line 127 of file drc_creepage_engine.cpp.
References CREEPAGE_GRAPH::AddNetElements(), connectChildren(), BOX2< Vec >::Distance(), distance(), Edge_Cuts, extractResult(), CREEPAGE_GRAPH::GeneratePaths(), NETINFO_ITEM::GetBoundingBox(), m_board, populateBoardEdgeGraph(), CREEPAGE_GRAPH::SetTarget(), and CREEPAGE_GRAPH::Solve().
Referenced by BOOST_FIXTURE_TEST_CASE(), and BOOST_FIXTURE_TEST_CASE().
| std::vector< CREEPAGE_RESULT > CREEPAGE_ENGINE::Update | ( | int | aNearMargin = 0 | ) |
Recompute creepage for the dragged nets at the items' current board positions.
Returns the nearest creepage path per affected net pair whose distance is below constraint + aNearMargin. Reuses the static board-edge prefix; rebuilds the copper paths.
Definition at line 261 of file drc_creepage_engine.cpp.
References addNetsInRegion(), buildBoardEdgePrefix(), connectChildren(), distance(), extractResult(), BOX2< Vec >::Inflate(), m_affectedNets, m_constraintFn, m_dynamicEdges, m_graph, m_interactive, m_layer, m_margin, m_movingItems, m_staticConnCount, m_staticNodeCount, BOX2< Vec >::Merge(), and path.
Referenced by BOOST_FIXTURE_TEST_CASE().
|
private |
Definition at line 149 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), BeginInteractive(), EndInteractive(), and Update().
|
private |
Definition at line 141 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), BeginInteractive(), buildBoardEdgePrefix(), CREEPAGE_ENGINE(), populateBoardEdgeGraph(), and SolveNetPairWholeBoard().
|
private |
Definition at line 151 of file drc_creepage_engine.h.
Referenced by BeginInteractive(), EndInteractive(), and Update().
|
private |
Definition at line 145 of file drc_creepage_engine.h.
Referenced by BeginInteractive(), EndInteractive(), and Update().
|
private |
Definition at line 158 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), buildBoardEdgePrefix(), EndInteractive(), and Update().
|
private |
Definition at line 144 of file drc_creepage_engine.h.
Referenced by BeginInteractive(), EndInteractive(), IsInteractive(), and Update().
|
private |
Definition at line 146 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), BeginInteractive(), and Update().
|
private |
Definition at line 147 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), BeginInteractive(), buildBoardEdgePrefix(), and Update().
|
private |
Definition at line 142 of file drc_creepage_engine.h.
Referenced by populateBoardEdgeGraph(), and SetMinGrooveWidth().
|
private |
Definition at line 150 of file drc_creepage_engine.h.
Referenced by BeginInteractive(), EndInteractive(), movingItemsHaveNPTH(), and Update().
|
private |
Definition at line 159 of file drc_creepage_engine.h.
Referenced by buildBoardEdgePrefix(), and EndInteractive().
|
private |
Definition at line 164 of file drc_creepage_engine.h.
Referenced by buildBoardEdgePrefix(), EndInteractive(), and Update().
|
private |
Definition at line 156 of file drc_creepage_engine.h.
Referenced by addNetsInRegion(), BeginInteractive(), and EndInteractive().
|
private |
Definition at line 163 of file drc_creepage_engine.h.
Referenced by buildBoardEdgePrefix(), EndInteractive(), and Update().