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 <wx/app.h>
28
29
30std::vector<PCB_SHAPE> DRC_TEST_PROVIDER_CLEARANCE_BASE::GetShapes( const std::vector<PCB_SHAPE>& aShapes,
31 const VECTOR2I& aStart, const VECTOR2I& aEnd,
32 int aLength )
33{
34 STROKE_PARAMS hairline( 1.0 ); // Segments of width 1.0 will get drawn as lines by PCB_PAINTER
35 std::vector<PCB_SHAPE> shortestPathShapes;
36
37 // Add the path
38 for( PCB_SHAPE shape : aShapes )
39 {
40 shape.SetStroke( hairline );
41 shortestPathShapes.push_back( std::move( shape ) );
42 }
43
44 // Draw perpendicular begin/end stops
45 if( shortestPathShapes.size() > 0 )
46 {
47 VECTOR2I V1 = shortestPathShapes[0].GetStart() - shortestPathShapes[0].GetEnd();
48 VECTOR2I V2 = shortestPathShapes.back().GetStart() - shortestPathShapes.back().GetEnd();
49 V1 = V1.Perpendicular().Resize( aLength / 30 );
50 V2 = V2.Perpendicular().Resize( aLength / 30 );
51
52 PCB_SHAPE s( nullptr, SHAPE_T::SEGMENT );
53 s.SetStroke( hairline );
54
55 s.SetStart( aStart + V1 );
56 s.SetEnd( aStart - V1 );
57 shortestPathShapes.push_back( s );
58
59 s.SetStart( aEnd + V2 );
60 s.SetEnd( aEnd - V2 );
61 shortestPathShapes.push_back( s );
62 }
63
64 // Add outlined areas
65 for( PCB_SHAPE shape : aShapes )
66 {
67 shape.SetWidth( aLength / 10 );
68 shortestPathShapes.push_back( std::move( shape ) );
69 }
70
71 return shortestPathShapes;
72}
73
74
75void DRC_TEST_PROVIDER_CLEARANCE_BASE::ReportAndShowPathCuToCu( std::shared_ptr<DRC_ITEM>& aDrce,
76 const VECTOR2I& aMarkerPos,
77 int aMarkerLayer,
78 const BOARD_ITEM* aItem1,
79 const BOARD_ITEM* aItem2,
80 PCB_LAYER_ID layer, int aDistance )
81{
82 std::shared_ptr<SHAPE> aShape1 = aItem1->GetEffectiveShape( layer );
83 std::shared_ptr<SHAPE> aShape2 = aItem2->GetEffectiveShape( layer );
84
85 VECTOR2I ptA, ptB;
86
87 // Don't try showing graphics if we don't have a GUI instance
88 if( wxApp::GetGUIInstance() && aShape1->NearestPoints( aShape2.get(), ptA, ptB ) )
89 {
90 PCB_SHAPE ptAShape( nullptr, SHAPE_T::SEGMENT );
91 ptAShape.SetStart( ptA );
92 ptAShape.SetEnd( ptB );
93 reportViolation( aDrce, aMarkerPos, aMarkerLayer, GetShapes( { ptAShape }, ptA, ptB, aDistance ) );
94 }
95 else
96 {
97 reportViolation( aDrce, aMarkerPos, aMarkerLayer );
98 }
99}
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.
std::vector< PCB_SHAPE > GetShapes(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, const std::vector< PCB_SHAPE > &aShapes={})
void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:177
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:219
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition pcb_shape.h:92
Simple container to manage line stroke parameters.
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
@ SEGMENT
Definition eda_shape.h:45
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695