2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-11 21:16:52 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers.
|
2020-08-25 17:42:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
#include <common.h>
|
|
|
|
|
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <connectivity/connectivity_algo.h>
|
2023-03-25 10:44:46 +00:00
|
|
|
#include <zone.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Connectivity test provider. Not rule-driven.
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_DANGLING_TRACK
|
|
|
|
- DRCE_DANGLING_VIA
|
2022-03-01 11:56:17 +00:00
|
|
|
- DRCE_ISOLATED_COPPER
|
2020-08-25 17:42:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_CONNECTIVITY : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRC_TEST_PROVIDER_CONNECTIVITY()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_CONNECTIVITY()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "connectivity" );
|
2020-08-25 17:42:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests board connectivity" );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_CONNECTIVITY::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-23 10:46:41 +00:00
|
|
|
if( !reportPhase( _( "Checking pad, via and zone connections..." ) ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2023-03-25 10:44:46 +00:00
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
int progressDelta = 250;
|
2020-09-23 10:46:41 +00:00
|
|
|
int ii = 0;
|
2023-03-25 10:44:46 +00:00
|
|
|
int count = board->Tracks().size() + board->m_ZoneIsolatedIslandsMap.size();
|
2020-09-23 10:46:41 +00:00
|
|
|
|
|
|
|
ii += count; // We gave half of this phase to CONNECTIVITY_DATA::Build()
|
|
|
|
count += count;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : board->Tracks() )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
bool exceedT = m_drcEngine->IsErrorLimitExceeded( DRCE_DANGLING_TRACK );
|
|
|
|
bool exceedV = m_drcEngine->IsErrorLimitExceeded( DRCE_DANGLING_VIA );
|
2020-09-11 21:50:53 +00:00
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
if( exceedV && exceedT )
|
|
|
|
break;
|
|
|
|
else if( track->Type() == PCB_VIA_T && exceedV )
|
2020-08-25 17:42:52 +00:00
|
|
|
continue;
|
|
|
|
else if( track->Type() == PCB_TRACE_T && exceedT )
|
|
|
|
continue;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
2022-03-01 11:56:17 +00:00
|
|
|
return false; // DRC cancelled
|
2020-09-12 19:28:22 +00:00
|
|
|
|
|
|
|
// Test for dangling items
|
|
|
|
int code = track->Type() == PCB_VIA_T ? DRCE_DANGLING_VIA : DRCE_DANGLING_TRACK;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2020-08-25 17:42:52 +00:00
|
|
|
if( connectivity->TestTrackEndpointDangling( track, &pos ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
|
|
|
|
drcItem->SetItems( track );
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drcItem, pos, track->GetLayer() );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test starved zones */
|
2023-03-25 10:44:46 +00:00
|
|
|
for( const auto& [ zone, zoneIslands ] : board->m_ZoneIsolatedIslandsMap )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2022-03-01 11:56:17 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_ISOLATED_COPPER ) )
|
2020-09-12 19:28:22 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2023-03-25 10:44:46 +00:00
|
|
|
for( const auto& [ layer, layerIslands ] : zoneIslands )
|
2020-09-11 21:50:53 +00:00
|
|
|
{
|
2023-03-25 10:44:46 +00:00
|
|
|
for( int polyIdx : layerIslands.m_IsolatedOutlines )
|
2022-03-01 11:56:17 +00:00
|
|
|
{
|
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_ISOLATED_COPPER ) )
|
|
|
|
break;
|
|
|
|
|
2023-03-25 10:44:46 +00:00
|
|
|
std::shared_ptr<SHAPE_POLY_SET> poly = zone->GetFilledPolysList( layer );
|
|
|
|
|
2022-03-01 11:56:17 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ISOLATED_COPPER );
|
2023-03-25 10:44:46 +00:00
|
|
|
drcItem->SetItems( zone );
|
|
|
|
reportViolation( drcItem, poly->Outline( polyIdx ).CPoint( 0 ), layer );
|
2022-03-01 11:56:17 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_UNCONNECTED_ITEMS ) )
|
|
|
|
return true; // continue with other tests
|
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking net connections..." ) ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-23 10:46:41 +00:00
|
|
|
ii = 0;
|
2022-09-29 16:07:42 +00:00
|
|
|
count = connectivity->GetUnconnectedCount( false );
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-09-29 16:07:42 +00:00
|
|
|
connectivity->RunOnUnconnectedEdges(
|
|
|
|
[&]( CN_EDGE& edge )
|
|
|
|
{
|
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_UNCONNECTED_ITEMS ) )
|
|
|
|
return false;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2022-09-29 16:07:42 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-09-29 16:07:42 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
|
|
|
|
drcItem->SetItems( edge.GetSourceNode()->Parent(), edge.GetTargetNode()->Parent() );
|
|
|
|
reportViolation( drcItem, edge.GetSourceNode()->Pos(), UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_CONNECTIVITY> dummy;
|
2021-12-15 01:17:43 +00:00
|
|
|
}
|