KiCad PCB EDA Suite
Loading...
Searching...
No Matches
CREEPAGE_ENGINE Class Reference

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_RESULTSolveNetPairWholeBoard (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_RESULTUpdate (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_RESULTextractResult (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

BOARDm_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, BOX2Im_staticNetBBoxes
 
std::unique_ptr< CREEPAGE_GRAPHm_graph
 
std::unique_ptr< SHAPE_POLY_SETm_outline
 
size_t m_staticNodeCount = 0
 
size_t m_staticConnCount = 0
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CREEPAGE_ENGINE()

CREEPAGE_ENGINE::CREEPAGE_ENGINE ( BOARD & aBoard)
explicit

Definition at line 33 of file drc_creepage_engine.cpp.

References m_board.

Member Function Documentation

◆ addNetsInRegion()

std::map< int, std::shared_ptr< GRAPH_NODE > > CREEPAGE_ENGINE::addNetsInRegion ( const BOX2I & aRegion)
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().

◆ BeginInteractive()

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().

◆ buildBoardEdgePrefix()

void CREEPAGE_ENGINE::buildBoardEdgePrefix ( )
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().

◆ connectChildren()

void CREEPAGE_ENGINE::connectChildren ( CREEPAGE_GRAPH & aGraph)
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().

◆ EndInteractive()

◆ extractResult()

std::optional< CREEPAGE_RESULT > CREEPAGE_ENGINE::extractResult ( const std::vector< std::shared_ptr< GRAPH_CONNECTION > > & aPath,
double aDistance,
int aNetA,
int aNetB,
double aConstraint,
int aNearMargin )
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().

◆ IsInteractive()

bool CREEPAGE_ENGINE::IsInteractive ( ) const
inline

Definition at line 111 of file drc_creepage_engine.h.

References m_interactive.

◆ movingItemsHaveNPTH()

bool CREEPAGE_ENGINE::movingItemsHaveNPTH ( ) const
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().

◆ populateBoardEdgeGraph()

void CREEPAGE_ENGINE::populateBoardEdgeGraph ( CREEPAGE_GRAPH & aGraph,
SHAPE_POLY_SET & aOutline )
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().

◆ SetMinGrooveWidth()

void CREEPAGE_ENGINE::SetMinGrooveWidth ( int aWidth)
inline

Definition at line 78 of file drc_creepage_engine.h.

References m_minGrooveWidth.

Referenced by DRC_TEST_PROVIDER_CREEPAGE::testCreepageV2().

◆ SolveNetPairWholeBoard()

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().

◆ Update()

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().

Member Data Documentation

◆ m_affectedNets

std::set<int> CREEPAGE_ENGINE::m_affectedNets
private

Definition at line 149 of file drc_creepage_engine.h.

Referenced by addNetsInRegion(), BeginInteractive(), EndInteractive(), and Update().

◆ m_board

◆ m_constraintFn

std::function<double( int, int )> CREEPAGE_ENGINE::m_constraintFn
private

Definition at line 151 of file drc_creepage_engine.h.

Referenced by BeginInteractive(), EndInteractive(), and Update().

◆ m_dynamicEdges

bool CREEPAGE_ENGINE::m_dynamicEdges = false
private

Definition at line 145 of file drc_creepage_engine.h.

Referenced by BeginInteractive(), EndInteractive(), and Update().

◆ m_graph

std::unique_ptr<CREEPAGE_GRAPH> CREEPAGE_ENGINE::m_graph
private

◆ m_interactive

bool CREEPAGE_ENGINE::m_interactive = false
private

Definition at line 144 of file drc_creepage_engine.h.

Referenced by BeginInteractive(), EndInteractive(), IsInteractive(), and Update().

◆ m_layer

PCB_LAYER_ID CREEPAGE_ENGINE::m_layer = UNDEFINED_LAYER
private

Definition at line 146 of file drc_creepage_engine.h.

Referenced by addNetsInRegion(), BeginInteractive(), and Update().

◆ m_margin

int CREEPAGE_ENGINE::m_margin = 0
private

◆ m_minGrooveWidth

int CREEPAGE_ENGINE::m_minGrooveWidth = 0
private

Definition at line 142 of file drc_creepage_engine.h.

Referenced by populateBoardEdgeGraph(), and SetMinGrooveWidth().

◆ m_movingItems

std::set<const BOARD_ITEM*> CREEPAGE_ENGINE::m_movingItems
private

◆ m_outline

std::unique_ptr<SHAPE_POLY_SET> CREEPAGE_ENGINE::m_outline
private

Definition at line 159 of file drc_creepage_engine.h.

Referenced by buildBoardEdgePrefix(), and EndInteractive().

◆ m_staticConnCount

size_t CREEPAGE_ENGINE::m_staticConnCount = 0
private

Definition at line 164 of file drc_creepage_engine.h.

Referenced by buildBoardEdgePrefix(), EndInteractive(), and Update().

◆ m_staticNetBBoxes

std::map<int, BOX2I> CREEPAGE_ENGINE::m_staticNetBBoxes
private

Definition at line 156 of file drc_creepage_engine.h.

Referenced by addNetsInRegion(), BeginInteractive(), and EndInteractive().

◆ m_staticNodeCount

size_t CREEPAGE_ENGINE::m_staticNodeCount = 0
private

Definition at line 163 of file drc_creepage_engine.h.

Referenced by buildBoardEdgePrefix(), EndInteractive(), and Update().


The documentation for this class was generated from the following files: