KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_creepage_engine.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <functional>
27#include <map>
28#include <memory>
29#include <optional>
30#include <set>
31#include <vector>
32
33#include <math/box2.h>
34#include <layer_ids.h>
35#include <pcb_shape.h>
36
38
39class BOARD;
40
48{
49 int m_netA = -1;
50 int m_netB = -1;
51 double m_distance = 0.0;
52 double m_constraint = 0.0;
53 bool m_violation = false;
56 const BOARD_ITEM* m_itemA = nullptr;
57 const BOARD_ITEM* m_itemB = nullptr;
58 std::vector<PCB_SHAPE> m_path;
59};
60
61
74{
75public:
76 explicit CREEPAGE_ENGINE( BOARD& aBoard );
77
78 void SetMinGrooveWidth( int aWidth ) { m_minGrooveWidth = aWidth; }
79
86 std::optional<CREEPAGE_RESULT> SolveNetPairWholeBoard( int aNetA, int aNetB, PCB_LAYER_ID aLayer,
87 double aConstraint );
88
97 void BeginInteractive( PCB_LAYER_ID aLayer, const std::set<int>& aAffectedNets,
98 const std::set<const BOARD_ITEM*>& aMovingItems, int aMargin,
99 std::function<double( int, int )> aConstraintFn );
100
107 std::vector<CREEPAGE_RESULT> Update( int aNearMargin = 0 );
108
109 void EndInteractive();
110
111 bool IsInteractive() const { return m_interactive; }
112
113private:
117 void populateBoardEdgeGraph( CREEPAGE_GRAPH& aGraph, SHAPE_POLY_SET& aOutline );
118
120 void connectChildren( CREEPAGE_GRAPH& aGraph );
121
123 std::optional<CREEPAGE_RESULT>
124 extractResult( const std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aPath, double aDistance,
125 int aNetA, int aNetB, double aConstraint, int aNearMargin );
126
129 std::map<int, std::shared_ptr<GRAPH_NODE>> addNetsInRegion( const BOX2I& aRegion );
130
135
138 bool movingItemsHaveNPTH() const;
139
140private:
143
144 bool m_interactive = false;
145 bool m_dynamicEdges = false;
147 int m_margin = 0;
148
149 std::set<int> m_affectedNets;
150 std::set<const BOARD_ITEM*> m_movingItems;
151 std::function<double( int, int )> m_constraintFn;
152
153 // Bounding box of every non-affected net, cached once at drag start. Non-affected geometry is
154 // static during a drag, so this avoids recomputing NETINFO_ITEM::GetBoundingBox (a full
155 // connectivity sweep) for every net on every frame.
156 std::map<int, BOX2I> m_staticNetBBoxes;
157
158 std::unique_ptr<CREEPAGE_GRAPH> m_graph;
159 std::unique_ptr<SHAPE_POLY_SET> m_outline;
160
161 // The static board-edge sub-graph prefix: nodes [0, m_staticNodeCount) and connections
162 // [0, m_staticConnCount) are pure board geometry, reused every frame.
165};
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
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.
bool IsInteractive() const
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.
void SetMinGrooveWidth(int aWidth)
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.
Represent a set of closed polygons.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
Result of a single creepage query between two nets on one layer.
const BOARD_ITEM * m_itemB
const BOARD_ITEM * m_itemA
std::vector< PCB_SHAPE > m_path
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683