KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_clearance_base.cpp
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 (C) 2004-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2007 Dick Hollenbeck, [email protected]
6 * Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27
28void DRC_TEST_PROVIDER_CLEARANCE_BASE::ShowPathDRC( const std::vector<PCB_SHAPE>& aShapes,
29 const VECTOR2I& aStart, const VECTOR2I& aEnd,
30 int aLength )
31{
33 COLOR_SETTINGS* defaultSettings = colorSettings->CreateBuiltinColorSettings()[0];
34 COLOR4D errorColor = defaultSettings->GetColor( LAYER_DRC_ERROR );
35 delete colorSettings;
36
37 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
38
39 // m_commit is protected and cannot be sent to the lambda function
40 BOARD_COMMIT* aCommit = m_commit;
41
42 if( !m_commit )
43 return;
44
45 // Add the path and its outlined area
46 for( PCB_SHAPE sh : aShapes )
47 {
48 sh.SetStroke( false );
49 sh.SetFilled( false );
50 sh.SetLineColor( WHITE );
51 shortestPathShapes1.push_back( sh );
52
53 sh.SetFilled( true );
54 sh.SetFillColor( errorColor.WithAlpha( 0.5 ) );
55 sh.SetWidth( aLength / 10 );
56 shortestPathShapes2.push_back( sh );
57 }
58
59 if( shortestPathShapes1.size() > 0 )
60 {
61 PCB_SHAPE s1, s2;
62 s1.SetFilled( false );
63 s2.SetFilled( false );
64 VECTOR2I V1 = shortestPathShapes1[0].GetStart() - shortestPathShapes1[0].GetEnd();
65 V1 = V1.Perpendicular().Resize( aLength / 30 );
66
67 s1.SetStart( aStart + V1 );
68 s1.SetEnd( aStart - V1 );
69 s1.SetWidth( 0 );
70 s1.SetLineColor( WHITE );
71
72
73 VECTOR2I V2 = shortestPathShapes1.back().GetStart() - shortestPathShapes1.back().GetEnd();
74 V2 = V2.Perpendicular().Resize( aLength / 30 );
75
76 s2.SetStart( aEnd + V2 );
77 s2.SetEnd( aEnd - V2 );
78 s2.SetWidth( 0 );
79 s2.SetLineColor( WHITE );
80
81 shortestPathShapes1.push_back( s1 );
82 shortestPathShapes1.push_back( s2 );
83 }
84
86 [aCommit, shortestPathShapes1, shortestPathShapes2]( PCB_MARKER* aMarker )
87 {
88 if( !aCommit || !aMarker )
89 return;
90
91 aMarker->SetShapes1( std::move( shortestPathShapes1 ) );
92 aMarker->SetShapes2( std::move( shortestPathShapes2 ) );
93 };
94
96}
97
98
100 std::shared_ptr<DRC_ITEM>& aDrce, const VECTOR2I& aMarkerPos, int aMarkerLayer,
101 const BOARD_ITEM* aItem1, const BOARD_ITEM* aItem2, PCB_LAYER_ID layer, int aDistance )
102{
103 CreepageGraph graph( *m_board );
104 std::shared_ptr<GraphNode> NetA = graph.AddNodeVirtual();
105 std::shared_ptr<GraphNode> NetB = graph.AddNodeVirtual();
106
107 // They need to be different or the algorithm won't compute the path.
108 NetA->m_net = 1;
109 NetB->m_net = 2;
110
111 graph.Addshape( *( aItem1->GetEffectiveShape( layer ) ), NetA, nullptr );
112 graph.Addshape( *( aItem2->GetEffectiveShape( layer ) ), NetB, nullptr );
113
114 graph.GeneratePaths( aDistance * 2, layer );
115
116 double minValue = aDistance * 2;
117 GraphConnection* minGc = nullptr;
118
119 for( std::shared_ptr<GraphConnection> gc : graph.m_connections )
120 {
121 if( ( gc->m_path.weight < minValue ) && ( gc->m_path.weight > 0 ) )
122 {
123 minValue = gc->m_path.weight;
124 minGc = gc.get();
125 }
126 }
127
128 if( minGc )
129 {
130 PATH_CONNECTION pc = minGc->m_path;
131 ShowPathDRC( minGc->GetShapes(), pc.a1, pc.a2, aDistance );
132 reportViolation( aDrce, aMarkerPos, aMarkerLayer );
133 // After a ShowPathDRC() call, restore the handler
135 }
136 else
137 {
138 reportViolation( aDrce, aMarkerPos, aMarkerLayer );
139 }
140}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:279
Color settings are a bit different than most of the settings objects in that there can be more than o...
static std::vector< COLOR_SETTINGS * > CreateBuiltinColorSettings()
Constructs and returns a list of color settings objects based on the built-in color themes.
static const wxString COLOR_BUILTIN_DEFAULT
COLOR4D GetColor(int aLayer) const
A graph with nodes and connections for creepage calculation.
std::shared_ptr< GraphNode > AddNodeVirtual()
std::vector< std::shared_ptr< GraphConnection > > m_connections
void Addshape(const SHAPE &aShape, std::shared_ptr< GraphNode > &aConnectTo, BOARD_ITEM *aParent=nullptr)
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, bool aGenerateBoardEdges=true)
DRC_GRAPHICS_HANDLER m_graphicsHandler
Definition: drc_engine.h:276
void ReportAndShowPathCuToCu(std::shared_ptr< DRC_ITEM > &aDrce, const VECTOR2I &aMarkerPos, int aMarkerLayer, const BOARD_ITEM *aItem1, const BOARD_ITEM *aItem2, PCB_LAYER_ID layer, int aDistance)
void ShowPathDRC(const std::vector< PCB_SHAPE > &aShapes, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aLength)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
BOARD_COMMIT * m_commit
DRC_ENGINE * m_drcEngine
void SetFilled(bool aFlag)
Definition: eda_shape.h:101
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:134
void SetLineColor(const COLOR4D &aColor)
Definition: eda_shape.h:121
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:171
void SetWidth(int aWidth)
Definition: eda_shape.h:114
a connection in a
std::vector< PCB_SHAPE > GetShapes()
PATH_CONNECTION m_path
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:311
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:314
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
@ WHITE
Definition: color4d.h:48
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:218
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60