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 The 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#include <pgm_base.h>
29
31DRC_TEST_PROVIDER_CLEARANCE_BASE::GetGraphicsHandler( const std::vector<PCB_SHAPE>& aShapes,
32 const VECTOR2I& aStart, const VECTOR2I& aEnd,
33 int aLength )
34{
35 // todo: Move this to a board-level object instead of getting it from the DRC Engine
36 PGM_BASE* pgm = PgmOrNull();
37 COLOR4D errorColor = COLOR4D( RED );
38
39 if( pgm )
40 {
41 COLOR_SETTINGS* colorSettings = pgm->GetSettingsManager().GetColorSettings();
42 errorColor = colorSettings->GetColor( LAYER_DRC_ERROR );
43 }
44
45 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
46
47 // Add the path and its outlined area
48 for( PCB_SHAPE sh : aShapes )
49 {
50 sh.SetStroke( false );
51 sh.SetFilled( false );
52 sh.SetLineColor( WHITE );
53 shortestPathShapes1.push_back( sh );
54
55 sh.SetFilled( true );
56 sh.SetFillColor( errorColor.WithAlpha( 0.5 ) );
57 sh.SetWidth( aLength / 10 );
58 shortestPathShapes2.push_back( sh );
59 }
60
61 if( shortestPathShapes1.size() > 0 )
62 {
63 PCB_SHAPE s1, s2;
64 s1.SetFilled( false );
65 s2.SetFilled( false );
66 VECTOR2I V1 = shortestPathShapes1[0].GetStart() - shortestPathShapes1[0].GetEnd();
67 V1 = V1.Perpendicular().Resize( aLength / 30 );
68
69 s1.SetStart( aStart + V1 );
70 s1.SetEnd( aStart - V1 );
71 s1.SetWidth( 0 );
72 s1.SetLineColor( WHITE );
73
74
75 VECTOR2I V2 = shortestPathShapes1.back().GetStart() - shortestPathShapes1.back().GetEnd();
76 V2 = V2.Perpendicular().Resize( aLength / 30 );
77
78 s2.SetStart( aEnd + V2 );
79 s2.SetEnd( aEnd - V2 );
80 s2.SetWidth( 0 );
81 s2.SetLineColor( WHITE );
82
83 shortestPathShapes1.push_back( s1 );
84 shortestPathShapes1.push_back( s2 );
85 }
86
87 return [shortestPathShapes1, shortestPathShapes2]( PCB_MARKER* aMarker )
88 {
89 if( !aMarker )
90 return;
91
92 aMarker->SetShapes1( std::move( shortestPathShapes1 ) );
93 aMarker->SetShapes2( std::move( shortestPathShapes2 ) );
94 };
95}
96
97
99 std::shared_ptr<DRC_ITEM>& aDrce, const VECTOR2I& aMarkerPos, int aMarkerLayer,
100 const BOARD_ITEM* aItem1, const BOARD_ITEM* aItem2, PCB_LAYER_ID layer, int aDistance )
101{
102 CREEPAGE_GRAPH graph( *m_board );
103 std::shared_ptr<GRAPH_NODE> NetA = graph.AddNodeVirtual();
104 std::shared_ptr<GRAPH_NODE> NetB = graph.AddNodeVirtual();
105
106 // They need to be different or the algorithm won't compute the path.
107 NetA->m_net = 1;
108 NetB->m_net = 2;
109
110 graph.Addshape( *( aItem1->GetEffectiveShape( layer ) ), NetA, nullptr );
111 graph.Addshape( *( aItem2->GetEffectiveShape( layer ) ), NetB, nullptr );
112
113 graph.GeneratePaths( aDistance * 2, layer, true );
114
115 double minValue = aDistance * 2;
116 GRAPH_CONNECTION* minGc = nullptr;
117
118 for( std::shared_ptr<GRAPH_CONNECTION> gc : graph.m_connections )
119 {
120 if( ( gc->m_path.weight < minValue ) && ( gc->m_path.weight > 0 ) )
121 {
122 minValue = gc->m_path.weight;
123 minGc = gc.get();
124 }
125 }
126
127 if( minGc )
128 {
129 PATH_CONNECTION pc = minGc->m_path;
131 GetGraphicsHandler( minGc->GetShapes(), pc.a1, pc.a2, aDistance );
132 reportViolation( aDrce, aMarkerPos, aMarkerLayer, &handler );
133 }
134 else
135 {
136 reportViolation( aDrce, aMarkerPos, aMarkerLayer );
137 }
138}
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:278
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
void Addshape(const SHAPE &aShape, std::shared_ptr< GRAPH_NODE > &aConnectTo, BOARD_ITEM *aParent=nullptr)
std::shared_ptr< GRAPH_NODE > AddNodeVirtual()
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, bool aClearance)
std::vector< std::shared_ptr< GRAPH_CONNECTION > > m_connections
DRC_CUSTOM_MARKER_HANDLER GetGraphicsHandler(const std::vector< PCB_SHAPE > &aShapes, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aLength)
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)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, DRC_CUSTOM_MARKER_HANDLER *aCustomHandler=nullptr)
virtual void SetFilled(bool aFlag)
Definition: eda_shape.h:108
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:141
void SetLineColor(const COLOR4D &aColor)
Definition: eda_shape.h:128
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:178
void SetWidth(int aWidth)
Definition: eda_shape.h:121
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
Container for data for KiCad programs.
Definition: pgm_base.h:103
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieve a color settings object that applications can read colors from.
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
@ RED
Definition: color4d.h:59
std::function< void(PCB_MARKER *aMarker)> DRC_CUSTOM_MARKER_HANDLER
Definition: drc_engine.h:69
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition: layer_ids.h:239
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
Definition: pgm_base.cpp:1081
see class PGM_BASE