44 bool hasOutline =
m_board.GetBoardPolygonOutlines( aOutline,
false,
nullptr,
false,
true );
57 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
59 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
60 [](
const std::shared_ptr<GRAPH_NODE>& aNode )
62 return !!aNode && aNode->m_parent && !aNode->m_parent->IsConductive()
63 && !aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
67 [&](
const std::shared_ptr<GRAPH_NODE>& aN1,
68 const std::shared_ptr<GRAPH_NODE>& aN2 )
70 if( aN1 == aN2 || !aN1 || !aN2 )
73 if( !aN1->m_parent || !aN2->m_parent )
76 if( aN1->m_parent != aN2->m_parent )
79 aN1->m_parent->ConnectChildren( const_cast<std::shared_ptr<GRAPH_NODE>&>( aN1 ),
80 const_cast<std::shared_ptr<GRAPH_NODE>&>( aN2 ),
86std::optional<CREEPAGE_RESULT>
88 double aDistance,
int aNetA,
int aNetB,
double aConstraint,
91 if( aPath.empty() || aPath.size() < 4 )
96 if( !( aDistance - aConstraint < aNearMargin ) )
102 result.m_distance = aDistance;
103 result.m_constraint = aConstraint;
104 result.m_violation = aDistance < aConstraint;
106 std::shared_ptr<GRAPH_CONNECTION> gc1 = aPath[1];
107 std::shared_ptr<GRAPH_CONNECTION> gc2 = aPath[aPath.size() - 2];
109 result.m_start = gc1->m_path.a2;
110 result.m_end = gc2->m_path.a2;
114 if( gc1->n1 && gc1->n1->m_parent )
115 result.m_itemA = gc1->n1->m_parent->GetParent();
117 if( gc2->n2 && gc2->n2->m_parent )
118 result.m_itemB = gc2->n2->m_parent->GetParent();
120 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : aPath )
121 gc->GetShapes(
result.m_path );
131 if( aConstraint <= 0 )
150 std::shared_ptr<GRAPH_NODE> nodeA = graph.
AddNetElements( aNetA, aLayer, aConstraint );
151 std::shared_ptr<GRAPH_NODE> nodeB = graph.
AddNetElements( aNetB, aLayer, aConstraint );
157 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
166 std::map<int, std::shared_ptr<GRAPH_NODE>> added;
169 for(
const auto& [netCode, net] :
m_board.GetNetInfo().NetsByNetcode() )
171 if( !net || netCode <= 0 )
190 const std::set<const BOARD_ITEM*>& aMovingItems,
int aMargin,
191 std::function<
double(
int,
int )> aConstraintFn )
202 for(
const auto& [netCode, net] :
m_board.GetNetInfo().NetsByNetcode() )
217 m_outline = std::make_unique<SHAPE_POLY_SET>();
234 auto isNPTH = [](
const PAD* aPad )
244 if( item->Type() ==
PCB_PAD_T && isNPTH(
static_cast<const PAD*
>( item ) ) )
263 std::vector<CREEPAGE_RESULT> results;
278 roi.
Merge( item->GetBoundingBox() );
283 std::map<int, std::shared_ptr<GRAPH_NODE>> netNodes =
addNetsInRegion( roi );
288 auto solve = [&](
int aNetA, std::shared_ptr<GRAPH_NODE>& aNodeA,
int aNetB,
289 std::shared_ptr<GRAPH_NODE>& aNodeB )
291 if( !aNodeA || !aNodeB )
296 if( constraint <= 0 )
299 std::vector<std::shared_ptr<GRAPH_CONNECTION>>
path;
302 std::optional<CREEPAGE_RESULT> r =
306 results.push_back( *r );
311 auto itA = netNodes.find( affected );
313 if( itA == netNodes.end() )
316 for(
auto& [netB, nodeB] : netNodes )
318 if( netB == affected )
325 solve( affected, itA->second, netB, nodeB );
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
ecoord_type Distance(const Vec &aP) const
std::map< int, BOX2I > m_staticNetBBoxes
bool movingItemsHaveNPTH() const
True when any dragged item carries an NPTH hole, making the board-edge graph position dependent and t...
std::function< double(int, int)> m_constraintFn
std::set< int > m_affectedNets
void populateBoardEdgeGraph(CREEPAGE_GRAPH &aGraph, SHAPE_POLY_SET &aOutline)
Build the board-edge geometry into aGraph: groove width, outline (NPTH-subtracted),...
std::set< const BOARD_ITEM * > m_movingItems
std::vector< CREEPAGE_RESULT > Update(int aNearMargin=0)
Recompute creepage for the dragged nets at the items' current board positions.
CREEPAGE_ENGINE(BOARD &aBoard)
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 th...
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::unique_ptr< SHAPE_POLY_SET > m_outline
std::unique_ptr< CREEPAGE_GRAPH > m_graph
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.
A graph with nodes and connections for creepage calculation.
void SetTarget(double aTarget)
double Solve(std::shared_ptr< GRAPH_NODE > &aFrom, std::shared_ptr< GRAPH_NODE > &aTo, std::vector< std::shared_ptr< GRAPH_CONNECTION > > &aResult)
std::vector< CREEP_SHAPE * > m_shapeCollection
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, const std::set< int > *aRelevantNets=nullptr)
Generate creepage paths between graph nodes.
void TransformEdgeToCreepShapes()
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
SHAPE_POLY_SET * m_boardOutline
void RemoveDuplicatedShapes()
std::vector< BOARD_ITEM * > m_boardEdge
std::vector< std::shared_ptr< GRAPH_NODE > > m_nodes
std::shared_ptr< GRAPH_NODE > AddNetElements(int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage)
std::vector< std::unique_ptr< PCB_SHAPE > > m_ownedBoardEdges
Handle the data for a net.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Represent a set of closed polygons.
void BuildCreepageBoardEdges(BOARD &aBoard, std::vector< BOARD_ITEM * > &aVector, std::vector< std::unique_ptr< PCB_SHAPE > > &aOwned, const std::set< const BOARD_ITEM * > *aExclude)
Collect the board-edge items used by the creepage graph.
PCB_LAYER_ID
A quick note on layer IDs:
void for_all_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every possible pair of elements of a sequence.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
Result of a single creepage query between two nets on one layer.
wxString result
Test unit parsing edge cases and error handling.
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint