KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_connectivity.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 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#include <board.h>
25#include <common.h>
26
29#include <zone.h>
30#include <drc/drc_item.h>
32
33
34/*
35 Connectivity test provider. Not rule-driven.
36 Errors generated:
37 - DRCE_DANGLING_TRACK
38 - DRCE_DANGLING_VIA
39 - DRCE_ISOLATED_COPPER
40*/
41
43{
44public:
46 {}
47
49
50 virtual bool Run() override;
51
52 virtual const wxString GetName() const override { return wxT( "connectivity" ); };
53};
54
55
57{
58 if( !reportPhase( _( "Checking pad, via and zone connections..." ) ) )
59 return false; // DRC cancelled
60
61 BOARD* board = m_drcEngine->GetBoard();
62 std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
63
64 int progressDelta = 250;
65 int ii = 0;
66 int count = board->Tracks().size() + board->m_ZoneIsolatedIslandsMap.size();
67
68 ii += count; // We gave half of this phase to CONNECTIVITY_DATA::Build()
69 count += count;
70
71 for( PCB_TRACK* track : board->Tracks() )
72 {
75
76 if( exceedV && exceedT )
77 break;
78 else if( track->Type() == PCB_VIA_T && exceedV )
79 continue;
80 else if( track->Type() == PCB_TRACE_T && exceedT )
81 continue;
82
83 if( !reportProgress( ii++, count, progressDelta ) )
84 return false; // DRC cancelled
85
86 // Test for dangling items
87 int code = track->Type() == PCB_VIA_T ? DRCE_DANGLING_VIA : DRCE_DANGLING_TRACK;
88 VECTOR2I pos;
89
90 if( connectivity->TestTrackEndpointDangling( track, true, &pos ) )
91 {
92 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
93 drcItem->SetItems( track );
94 reportViolation( drcItem, pos, track->GetLayer() );
95 }
96 }
97
98 /* test starved zones */
99 for( const auto& [ zone, zoneIslands ] : board->m_ZoneIsolatedIslandsMap )
100 {
102 break;
103
104 if( !reportProgress( ii++, count, progressDelta ) )
105 return false; // DRC cancelled
106
107 for( const auto& [ layer, layerIslands ] : zoneIslands )
108 {
109 for( int polyIdx : layerIslands.m_IsolatedOutlines )
110 {
112 break;
113
114 std::shared_ptr<SHAPE_POLY_SET> poly = zone->GetFilledPolysList( layer );
115
116 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ISOLATED_COPPER );
117 drcItem->SetItems( zone );
118 reportViolation( drcItem, poly->Outline( polyIdx ).CPoint( 0 ), layer );
119 }
120 }
121 }
122
124 return true; // continue with other tests
125
126 if( !reportPhase( _( "Checking net connections..." ) ) )
127 return false; // DRC cancelled
128
129 ii = 0;
130 count = connectivity->GetUnconnectedCount( false );
131
132 connectivity->RunOnUnconnectedEdges(
133 [&]( CN_EDGE& edge )
134 {
136 return false;
137
138 if( !reportProgress( ii++, count, progressDelta ) )
139 return false; // DRC cancelled
140
141 wxCHECK( edge.GetSourceNode() && !edge.GetSourceNode()->Dirty(), true );
142 wxCHECK( edge.GetTargetNode() && !edge.GetTargetNode()->Dirty(), true );
143
144 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
145 drcItem->SetItems( edge.GetSourceNode()->Parent(), edge.GetTargetNode()->Parent() );
146 reportViolation( drcItem, edge.GetSourceNode()->Pos(), UNDEFINED_LAYER );
147
148 return true;
149 } );
150
151 return !m_drcEngine->IsCancelled();
152}
153
154
155namespace detail
156{
158}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > m_ZoneIsolatedIslandsMap
Definition: board.h:1386
const TRACKS & Tracks() const
Definition: board.h:356
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:522
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
std::shared_ptr< const CN_ANCHOR > GetSourceNode() const
std::shared_ptr< const CN_ANCHOR > GetTargetNode() const
BOARD * GetBoard() const
Definition: drc_engine.h:100
bool IsErrorLimitExceeded(int error_code)
bool IsCancelled() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:393
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual ~DRC_TEST_PROVIDER_CONNECTIVITY()=default
virtual const wxString GetName() const override
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, DRC_CUSTOM_MARKER_HANDLER *aCustomHandler=nullptr)
DRC_ENGINE * m_drcEngine
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
The common library.
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_ISOLATED_COPPER
Definition: drc_item.h:48
@ DRCE_DANGLING_VIA
Definition: drc_item.h:50
@ DRCE_DANGLING_TRACK
Definition: drc_item.h:51
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96