177 lines
5.2 KiB
C++
177 lines
5.2 KiB
C++
|
/*
|
||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||
|
*
|
||
|
* Copyright (C) 2004-2020 KiCad Developers.
|
||
|
*
|
||
|
* 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
|
||
|
*/
|
||
|
|
||
|
#include <class_board.h>
|
||
|
#include <common.h>
|
||
|
|
||
|
#include <connectivity/connectivity_data.h>
|
||
|
#include <connectivity/connectivity_algo.h>
|
||
|
|
||
|
#include <drc_proto/drc_engine.h>
|
||
|
#include <drc_proto/drc_item.h>
|
||
|
#include <drc_proto/drc_rule.h>
|
||
|
#include <drc_proto/drc_test_provider.h>
|
||
|
|
||
|
|
||
|
/*
|
||
|
Connectivity test provider. Not rule-driven.
|
||
|
Errors generated:
|
||
|
- DRCE_DANGLING_TRACK
|
||
|
- DRCE_DANGLING_VIA
|
||
|
- DRCE_ZONE_HAS_EMPTY_NET
|
||
|
*/
|
||
|
|
||
|
namespace test
|
||
|
{
|
||
|
|
||
|
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
|
||
|
{
|
||
|
return "connectivity";
|
||
|
};
|
||
|
|
||
|
virtual const wxString GetDescription() const override
|
||
|
{
|
||
|
return "Tests board connectivity";
|
||
|
}
|
||
|
|
||
|
virtual std::set<test::DRC_CONSTRAINT_TYPE_T> GetMatchingConstraintIds() const override;
|
||
|
};
|
||
|
|
||
|
}; // namespace test
|
||
|
|
||
|
|
||
|
bool test::DRC_TEST_PROVIDER_CONNECTIVITY::Run()
|
||
|
{
|
||
|
ReportStage( ( "Testing dangling pads/vias" ), 0, 2 );
|
||
|
|
||
|
BOARD* board = m_drcEngine->GetBoard();
|
||
|
|
||
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
||
|
connectivity->Clear();
|
||
|
connectivity->Build( board ); // just in case. This really needs to be reliable.
|
||
|
|
||
|
|
||
|
for( auto track : board->Tracks() )
|
||
|
{
|
||
|
bool exceedT = isErrorLimitExceeded( DRCE_DANGLING_TRACK );
|
||
|
bool exceedV = isErrorLimitExceeded( DRCE_DANGLING_VIA );
|
||
|
// Test for dangling items
|
||
|
int code = track->Type() == PCB_VIA_T ? DRCE_DANGLING_VIA : DRCE_DANGLING_TRACK;
|
||
|
wxPoint pos;
|
||
|
|
||
|
if( track->Type() == PCB_VIA_T && exceedV )
|
||
|
continue;
|
||
|
else if( track->Type() == PCB_TRACE_T && exceedT )
|
||
|
continue;
|
||
|
|
||
|
if( connectivity->TestTrackEndpointDangling( track, &pos ) )
|
||
|
{
|
||
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
|
||
|
wxString msg;
|
||
|
|
||
|
msg.Printf( drcItem->GetErrorText() );
|
||
|
drcItem->SetErrorMessage( msg );
|
||
|
drcItem->SetItems( track );
|
||
|
ReportWithMarker( drcItem, pos );
|
||
|
}
|
||
|
|
||
|
if( exceedV && exceedT )
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
ReportStage( ( "Testing starved zones" ), 0, 2 );
|
||
|
|
||
|
/* test starved zones */
|
||
|
for( auto zone : board->Zones() )
|
||
|
{
|
||
|
if( !zone->IsOnCopperLayer() )
|
||
|
continue;
|
||
|
|
||
|
int netcode = zone->GetNetCode();
|
||
|
// a netcode < 0 or > 0 and no pad in net is a error or strange
|
||
|
// perhaps a "dead" net, which happens when all pads in this net were removed
|
||
|
// Remark: a netcode < 0 should not happen (this is more a bug somewhere)
|
||
|
int pads_in_net = ( netcode > 0 ) ? connectivity->GetPadCount( netcode ) : 1;
|
||
|
|
||
|
if( ( netcode < 0 ) || pads_in_net == 0 )
|
||
|
{
|
||
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ZONE_HAS_EMPTY_NET );
|
||
|
wxString msg;
|
||
|
|
||
|
msg.Printf( drcItem->GetErrorText() );
|
||
|
drcItem->SetErrorMessage( msg );
|
||
|
drcItem->SetItems( zone );
|
||
|
ReportWithMarker( drcItem, zone->GetPosition() );
|
||
|
|
||
|
if( isErrorLimitExceeded( DRCE_ZONE_HAS_EMPTY_NET ) )
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ReportStage( ( "Testing unconnected ratlines" ), 0, 2 );
|
||
|
|
||
|
connectivity->RecalculateRatsnest();
|
||
|
std::vector<CN_EDGE> edges;
|
||
|
connectivity->GetUnconnectedEdges( edges );
|
||
|
|
||
|
for( const CN_EDGE& edge : edges )
|
||
|
{
|
||
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
|
||
|
|
||
|
drcItem->SetItems( edge.GetSourceNode()->Parent(), edge.GetTargetNode()->Parent() );
|
||
|
ReportWithMarker( drcItem, edge.GetSourceNode()->Pos() );
|
||
|
|
||
|
if( isErrorLimitExceeded( DRCE_UNCONNECTED_ITEMS ) )
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
reportRuleStatistics();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
std::set<test::DRC_CONSTRAINT_TYPE_T>
|
||
|
test::DRC_TEST_PROVIDER_CONNECTIVITY::GetMatchingConstraintIds() const
|
||
|
{
|
||
|
return {};
|
||
|
}
|
||
|
|
||
|
|
||
|
namespace detail
|
||
|
{
|
||
|
static test::DRC_REGISTER_TEST_PROVIDER<test::DRC_TEST_PROVIDER_CONNECTIVITY> dummy;
|
||
|
}
|