2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-09-11 21:50:53 +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
|
|
|
|
|
|
|
#include <kiway.h>
|
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
Layout-versus-schematic (LVS) test.
|
|
|
|
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_MISSING_FOOTPRINT
|
|
|
|
- DRCE_DUPLICATE_FOOTPRINT
|
|
|
|
- DRCE_EXTRA_FOOTPRINT
|
|
|
|
|
|
|
|
TODO:
|
|
|
|
- cross-check PCB netlist against SCH netlist
|
|
|
|
- cross-check PCB fields against SCH fields
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_LVS : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRC_TEST_PROVIDER_LVS()
|
|
|
|
{
|
|
|
|
m_isRuleDriven = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_LVS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
|
|
|
return "LVS";
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
|
|
|
return "Performs layout-vs-schematics integity check";
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_T> GetConstraintTypes() const override;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int GetNumPhases() const override;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
private:
|
2020-08-25 17:42:52 +00:00
|
|
|
void testFootprints( NETLIST& aNetlist );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
void DRC_TEST_PROVIDER_LVS::testFootprints( NETLIST& aNetlist )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
auto compare = []( const FOOTPRINT* x, const FOOTPRINT* y )
|
2020-09-12 19:28:22 +00:00
|
|
|
{
|
|
|
|
return x->GetReference().CmpNoCase( y->GetReference() ) < 0;
|
|
|
|
};
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
auto footprints = std::set<FOOTPRINT*, decltype( compare )>( compare );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
// Search for duplicate footprints on the board
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_DUPLICATE_FOOTPRINT ) )
|
|
|
|
break;
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
auto ins = footprints.insert( footprint );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
if( !ins.second )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DUPLICATE_FOOTPRINT );
|
2020-11-12 23:50:33 +00:00
|
|
|
drcItem->SetItems( footprint, *ins.first );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search for component footprints in the netlist but not on the board.
|
|
|
|
for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
COMPONENT* component = aNetlist.GetComponent( ii );
|
2020-11-24 22:16:41 +00:00
|
|
|
FOOTPRINT* footprint = board->FindFootprintByReference( component->GetReference() );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint == nullptr )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_MISSING_FOOTPRINT ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
m_msg.Printf( _( "Missing footprint %s (%s)" ),
|
|
|
|
component->GetReference(),
|
|
|
|
component->GetValue() );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MISSING_FOOTPRINT );
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-10-23 16:02:18 +00:00
|
|
|
reportViolation( drcItem, wxPoint() );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
2020-09-11 21:50:53 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-09-11 21:50:53 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_NET_CONFLICT ) )
|
|
|
|
break;
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
const COMPONENT_NET& sch_net = component->GetNet( pad->GetName() );
|
|
|
|
const wxString& pcb_netname = pad->GetNetname();
|
|
|
|
|
|
|
|
if( !pcb_netname.IsEmpty() && sch_net.GetPinName().IsEmpty() )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "No corresponding pin found in schematic." ) );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_NET_CONFLICT );
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( pad );
|
2020-11-12 23:50:33 +00:00
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
else if( pcb_netname.IsEmpty() && !sch_net.GetNetName().IsEmpty() )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "Pad missing net given by schematic (%s)." ),
|
|
|
|
sch_net.GetNetName() );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_NET_CONFLICT );
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( pad );
|
2020-11-12 23:50:33 +00:00
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
else if( pcb_netname != sch_net.GetNetName() )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "Pad net (%s) doesn't match net given by schematic (%s)." ),
|
|
|
|
pcb_netname,
|
|
|
|
sch_net.GetNetName() );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_NET_CONFLICT );
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( pad );
|
2020-11-12 23:50:33 +00:00
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned jj = 0; jj < component->GetNetCount(); ++jj )
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_NET_CONFLICT ) )
|
|
|
|
break;
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
const COMPONENT_NET& sch_net = component->GetNet( jj );
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !footprint->FindPadByName( sch_net.GetPinName() ) )
|
2020-09-11 21:50:53 +00:00
|
|
|
{
|
|
|
|
m_msg.Printf( _( "No pad found for pin %s in schematic." ),
|
|
|
|
sch_net.GetPinName() );
|
|
|
|
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_NET_CONFLICT );
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-11-12 23:50:33 +00:00
|
|
|
drcItem->SetItems( footprint );
|
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
// Search for component footprints found on board but not in netlist.
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_EXTRA_FOOTPRINT ) )
|
|
|
|
break;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_BOARD_ONLY )
|
2020-10-23 16:02:18 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !aNetlist.GetComponentByReference( footprint->GetReference() ) )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_EXTRA_FOOTPRINT );
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
drcItem->SetItems( footprint );
|
|
|
|
reportViolation( drcItem, footprint->GetPosition() );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
bool DRC_TEST_PROVIDER_LVS::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
if( m_drcEngine->GetTestFootprints() )
|
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking PCB to schematic parity..." ) ) )
|
|
|
|
return false;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-18 14:23:26 +00:00
|
|
|
auto netlist = m_drcEngine->GetSchematicNetlist();
|
|
|
|
|
|
|
|
if( !netlist )
|
|
|
|
{
|
|
|
|
reportAux( _("No netlist provided, skipping LVS.") );
|
2020-10-01 16:47:35 +00:00
|
|
|
return true;
|
2020-09-18 14:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testFootprints( *netlist );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
reportRuleStatistics();
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
return true;
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_LVS::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return m_drcEngine->GetTestFootprints() ? 1 : 0;
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_LVS::GetConstraintTypes() const
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_LVS> dummy;
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|