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 COLOR4D errorColor = COLOR4D( RED );
37
38 if( PgmOrNull() )
39 {
41 errorColor = colorSettings->GetColor( LAYER_DRC_ERROR );
42 }
43
44 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
45
46 // Add the path and its outlined area
47 for( PCB_SHAPE sh : aShapes )
48 {
49 sh.SetStroke( false );
50 sh.SetFilled( false );
51 sh.SetLineColor( WHITE );
52 shortestPathShapes1.push_back( sh );
53
54 sh.SetFilled( true );
55 sh.SetFillColor( errorColor.WithAlpha( 0.5 ) );
56 sh.SetWidth( aLength / 10 );
57 shortestPathShapes2.push_back( sh );
58 }
59
60 if( shortestPathShapes1.size() > 0 )
61 {
62 PCB_SHAPE s1, s2;
63 s1.SetFilled( false );
64 s2.SetFilled( false );
65 VECTOR2I V1 = shortestPathShapes1[0].GetStart() - shortestPathShapes1[0].GetEnd();
66 V1 = V1.Perpendicular().Resize( aLength / 30 );
67
68 s1.SetStart( aStart + V1 );
69 s1.SetEnd( aStart - V1 );
70 s1.SetWidth( 0 );
71 s1.SetLineColor( WHITE );
72
73
74 VECTOR2I V2 = shortestPathShapes1.back().GetStart() - shortestPathShapes1.back().GetEnd();
75 V2 = V2.Perpendicular().Resize( aLength / 30 );
76
77 s2.SetStart( aEnd + V2 );
78 s2.SetEnd( aEnd - V2 );
79 s2.SetWidth( 0 );
80 s2.SetLineColor( WHITE );
81
82 shortestPathShapes1.push_back( s1 );
83 shortestPathShapes1.push_back( s2 );
84 }
85
86 return [shortestPathShapes1, shortestPathShapes2]( PCB_MARKER* aMarker )
87 {
88 if( !aMarker )
89 return;
90
91 aMarker->SetShapes1( std::move( shortestPathShapes1 ) );
92 aMarker->SetShapes2( std::move( shortestPathShapes2 ) );
93 };
94}
95
96
97void DRC_TEST_PROVIDER_CLEARANCE_BASE::ReportAndShowPathCuToCu( std::shared_ptr<DRC_ITEM>& aDrce,
98 const VECTOR2I& aMarkerPos,
99 int aMarkerLayer,
100 const BOARD_ITEM* aItem1,
101 const BOARD_ITEM* aItem2,
102 PCB_LAYER_ID layer, int aDistance )
103{
104 std::shared_ptr<SHAPE> aShape1 = aItem1->GetEffectiveShape( layer );
105 std::shared_ptr<SHAPE> aShape2 = aItem2->GetEffectiveShape( layer );
106
107 VECTOR2I ptA, ptB;
108
109 if( aShape1->NearestPoints( aShape2.get(), ptA, ptB ) )
110 {
111 PCB_SHAPE ptAShape( nullptr, SHAPE_T::SEGMENT );
112 ptAShape.SetStart( ptA );
113 ptAShape.SetEnd( ptB );
114 DRC_CUSTOM_MARKER_HANDLER handler = GetGraphicsHandler( { ptAShape }, ptA, ptB, aDistance );
115 reportViolation( aDrce, aMarkerPos, aMarkerLayer, &handler );
116 }
117 else
118 {
119 reportViolation( aDrce, aMarkerPos, aMarkerLayer );
120 }
121}
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:326
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
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:136
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:177
void SetLineColor(const COLOR4D &aColor)
Definition: eda_shape.h:164
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:219
void SetWidth(int aWidth)
Definition: eda_shape.cpp:2375
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
@ RED
Definition: color4d.h:59
std::function< void(PCB_MARKER *aMarker)> DRC_CUSTOM_MARKER_HANDLER
Definition: drc_engine.h:68
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition: layer_ids.h:276
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:910
see class PGM_BASE
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)