2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-07-29 12:18:53 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2016-03-06 21:22:01 +00:00
|
|
|
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-07 14:41:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file erc.cpp
|
|
|
|
* @brief Electrical Rules Check implementation.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <kicad_string.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <erc.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_sheet.h>
|
2018-01-19 15:12:36 +00:00
|
|
|
#include <sch_reference_list.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2015-07-29 12:18:53 +00:00
|
|
|
#include <wx/ffile.h>
|
2020-05-28 13:36:54 +00:00
|
|
|
#include <ws_draw_item.h>
|
|
|
|
#include <ws_proxy_view_item.h>
|
2015-07-29 12:18:53 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
/* ERC tests :
|
|
|
|
* 1 - conflicts between connected pins ( example: 2 connected outputs )
|
2009-11-03 13:26:31 +00:00
|
|
|
* 2 - minimal connections requirements ( 1 input *must* be connected to an
|
|
|
|
* output, or a passive pin )
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
/*
|
2020-01-18 20:51:28 +00:00
|
|
|
* Minimal ERC requirements:
|
|
|
|
* All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
|
2009-11-03 13:26:31 +00:00
|
|
|
* When a pin is not connected in schematic, the user must place a "non
|
|
|
|
* connected" symbol to this pin.
|
2009-07-07 17:50:02 +00:00
|
|
|
* This ensures a forgotten connection will be detected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Messages for conflicts :
|
2020-01-18 20:51:28 +00:00
|
|
|
* ELECTRICAL_PINTYPE::PT_INPUT, ELECTRICAL_PINTYPE::PT_OUTPUT, ELECTRICAL_PINTYPE:PT_:BIDI, ELECTRICAL_PINTYPE::PT_TRISTATE, ELECTRICAL_PINTYPE::PT_PASSIVE,
|
|
|
|
* ELECTRICAL_PINTYPE::PT_UNSPECIFIED, ELECTRICAL_PINTYPE::PT_POWER_IN, ELECTRICAL_PINTYPE::PT_POWER_OUT, ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR,
|
|
|
|
* ELECTRICAL_PINTYPE::PT_OPENEMITTER, ELECTRICAL_PINTYPE::PT_NC
|
2009-07-07 17:50:02 +00:00
|
|
|
* These messages are used to show the ERC matrix in ERC dialog
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
// Messages for matrix rows:
|
2014-01-18 09:07:05 +00:00
|
|
|
const wxString CommentERC_H[] =
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-04-06 13:46:16 +00:00
|
|
|
_( "Input Pin" ),
|
|
|
|
_( "Output Pin" ),
|
|
|
|
_( "Bidirectional Pin" ),
|
|
|
|
_( "Tri-State Pin" ),
|
|
|
|
_( "Passive Pin" ),
|
|
|
|
_( "Unspecified Pin" ),
|
|
|
|
_( "Power Input Pin" ),
|
|
|
|
_( "Power Output Pin" ),
|
|
|
|
_( "Open Collector" ),
|
|
|
|
_( "Open Emitter" ),
|
|
|
|
_( "No Connection" )
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
2009-07-07 17:50:02 +00:00
|
|
|
|
|
|
|
// Messages for matrix columns
|
2014-01-18 09:07:05 +00:00
|
|
|
const wxString CommentERC_V[] =
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
_( "Input Pin" ),
|
|
|
|
_( "Output Pin" ),
|
|
|
|
_( "Bidirectional Pin" ),
|
|
|
|
_( "Tri-State Pin" ),
|
|
|
|
_( "Passive Pin" ),
|
|
|
|
_( "Unspecified Pin" ),
|
|
|
|
_( "Power Input Pin" ),
|
|
|
|
_( "Power Output Pin" ),
|
|
|
|
_( "Open Collector" ),
|
|
|
|
_( "Open Emitter" ),
|
2014-01-18 09:07:05 +00:00
|
|
|
_( "No Connection" )
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_SCREEN* screen;
|
2010-10-26 20:25:48 +00:00
|
|
|
int err_count = 0;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
SCH_SCREENS screenList( m_schematic->Root() );
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
for( screen = screenList.GetFirst(); screen != nullptr; screen = screenList.GetNext() )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
std::vector<SCH_SHEET*> list;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
list.push_back( static_cast<SCH_SHEET*>( item ) );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < list.size(); i++ )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2020-05-28 13:36:54 +00:00
|
|
|
SCH_SHEET* sheet = list[i];
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( size_t j = i + 1; j < list.size(); j++ )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_SHEET* test_item = list[j];
|
2009-07-09 17:02:15 +00:00
|
|
|
|
|
|
|
// We have found a second sheet: compare names
|
2015-12-20 12:40:17 +00:00
|
|
|
// we are using case insensitive comparison to avoid mistakes between
|
|
|
|
// similar names like Mysheet and mysheet
|
2020-05-28 13:36:54 +00:00
|
|
|
if( sheet->GetName().CmpNoCase( test_item->GetName() ) == 0 )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2010-06-28 13:11:14 +00:00
|
|
|
if( aCreateMarker )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_SHEET_NAME );
|
2020-05-28 13:36:54 +00:00
|
|
|
ercItem->SetItems( sheet, test_item );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-05-28 13:36:54 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() );
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Append( marker );
|
2010-06-28 13:11:14 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-09 17:02:15 +00:00
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
void ERC_TESTER::TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-05-28 13:36:54 +00:00
|
|
|
WS_DRAW_ITEM_LIST wsItems;
|
|
|
|
|
2020-07-31 22:56:42 +00:00
|
|
|
auto unresolved = [this]( wxString str )
|
|
|
|
{
|
|
|
|
str = ExpandEnvVarSubstitutions( str, &m_schematic->Prj() );
|
|
|
|
return str.Matches( wxT( "*${*}*" ) );
|
|
|
|
};
|
|
|
|
|
2020-05-28 13:36:54 +00:00
|
|
|
if( aWorksheet )
|
|
|
|
{
|
|
|
|
wsItems.SetMilsToIUfactor( IU_PER_MILS );
|
|
|
|
wsItems.BuildWorkSheetGraphicList( aWorksheet->GetPageInfo(), aWorksheet->GetTitleBlock() );
|
|
|
|
}
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
SCH_SCREENS screens( m_schematic->Root() );
|
2020-03-29 01:12:29 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : component->GetFields() )
|
|
|
|
{
|
2020-07-31 22:56:42 +00:00
|
|
|
if( unresolved( field.GetShownText() ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
wxPoint pos = field.GetPosition() - component->GetPosition();
|
|
|
|
pos = component->GetTransform().TransformCoordinate( pos );
|
|
|
|
pos += component->GetPosition();
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( &field );
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
|
2020-03-29 01:12:29 +00:00
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : sheet->GetFields() )
|
|
|
|
{
|
2020-07-31 22:56:42 +00:00
|
|
|
if( unresolved( field.GetShownText() ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( &field );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
|
2020-03-29 01:12:29 +00:00
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
|
|
|
|
{
|
|
|
|
if( pin->GetShownText().Matches( wxT( "*${*}*" ) ) )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( pin );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
|
2020-03-29 01:12:29 +00:00
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
|
|
|
|
{
|
|
|
|
if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( text );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
|
2020-03-29 01:12:29 +00:00
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 13:36:54 +00:00
|
|
|
|
|
|
|
for( WS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
|
|
|
|
{
|
|
|
|
if( WS_DRAW_ITEM_TEXT* text = dynamic_cast<WS_DRAW_ITEM_TEXT*>( item ) )
|
|
|
|
{
|
|
|
|
if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2020-05-28 13:36:54 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
|
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
int ERC_TESTER::TestConflictingBusAliases()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
wxString msg;
|
|
|
|
int err_count = 0;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
SCH_SCREENS screens( m_schematic->Root() );
|
2019-08-07 18:23:59 +00:00
|
|
|
std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-03-29 01:12:29 +00:00
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
std::unordered_set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
if( alias->GetName() == test->GetName() && alias->Members() != test->Members() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
|
|
|
|
alias->GetName(),
|
|
|
|
alias->GetParent()->GetFileName(),
|
|
|
|
test->GetParent()->GetFileName() );
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, wxPoint() );
|
2020-03-16 11:05:01 +00:00
|
|
|
test->GetParent()->Append( marker );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
++err_count;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 18:23:59 +00:00
|
|
|
|
|
|
|
aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
int ERC_TESTER::TestMultiunitFootprints()
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
SCH_SHEET_LIST sheets = m_schematic->GetSheets();
|
|
|
|
|
2018-01-19 15:12:36 +00:00
|
|
|
int errors = 0;
|
|
|
|
std::map<wxString, LIB_ID> footprints;
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP refMap;
|
2020-07-03 21:08:17 +00:00
|
|
|
sheets.GetMultiUnitComponents( refMap, true );
|
2018-01-19 15:12:36 +00:00
|
|
|
|
|
|
|
for( auto& component : refMap )
|
|
|
|
{
|
|
|
|
auto& refList = component.second;
|
|
|
|
|
|
|
|
if( refList.GetCount() == 0 )
|
|
|
|
{
|
|
|
|
wxFAIL; // it should not happen
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reference footprint
|
2020-04-24 13:36:10 +00:00
|
|
|
SCH_COMPONENT* unit = nullptr;
|
|
|
|
wxString unitName;
|
|
|
|
wxString unitFP;
|
2018-01-19 15:12:36 +00:00
|
|
|
|
2019-08-10 07:18:19 +00:00
|
|
|
for( unsigned i = 0; i < component.second.GetCount(); ++i )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
|
2020-04-24 13:36:10 +00:00
|
|
|
unitFP = refList.GetItem( i ).GetComp()->GetField( FOOTPRINT )->GetText();
|
2018-01-19 15:12:36 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
if( !unitFP.IsEmpty() )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
unit = refList.GetItem( i ).GetComp();
|
2020-03-16 11:05:01 +00:00
|
|
|
unitName = unit->GetRef( &sheetPath, true );
|
2018-01-19 15:12:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 07:18:19 +00:00
|
|
|
for( unsigned i = 0; i < component.second.GetCount(); ++i )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_REFERENCE& secondRef = refList.GetItem( i );
|
|
|
|
SCH_COMPONENT* secondUnit = secondRef.GetComp();
|
2020-04-24 13:36:10 +00:00
|
|
|
wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
|
2020-03-16 11:05:01 +00:00
|
|
|
const wxString secondFp = secondUnit->GetField( FOOTPRINT )->GetText();
|
2020-04-24 13:36:10 +00:00
|
|
|
wxString msg;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
if( !secondFp.IsEmpty() && unitFP != secondFp )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2020-04-24 13:36:10 +00:00
|
|
|
msg.Printf( _( "Different footprints assigned to %s and %s" ),
|
|
|
|
unitName, secondName );
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
ercItem->SetItems( unit, secondUnit );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, secondUnit->GetPosition() );
|
2020-03-16 11:05:01 +00:00
|
|
|
secondRef.GetSheetPath().LastScreen()->Append( marker );
|
2018-01-19 15:12:36 +00:00
|
|
|
|
|
|
|
++errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
void ERC_TESTER::diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, int aMinConn,
|
|
|
|
PIN_ERROR aDiag )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
if( aDiag == PIN_ERROR::OK || aMinConn < 1 || aNetItemRef->m_Type != NETLIST_ITEM::PIN )
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-03 21:51:20 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aNetItemRef->m_Comp );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( aNetItemTst == NULL)
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
if( aMinConn == NOD ) /* Nothing driving the net. */
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-07-03 21:51:20 +00:00
|
|
|
if( settings.GetSeverity( ERCE_PIN_NOT_DRIVEN ) != RPT_SEVERITY_IGNORE )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_NOT_DRIVEN );
|
2020-07-03 21:51:20 +00:00
|
|
|
ercItem->SetItems( pin );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-07-03 21:51:20 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, aNetItemRef->m_Start );
|
|
|
|
aNetItemRef->m_SheetPath.LastScreen()->Append( marker );
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( aNetItemTst && aNetItemTst->m_Type == NETLIST_ITEM::PIN ) /* Error between 2 pins */
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-07-03 21:51:20 +00:00
|
|
|
if( settings.GetSeverity( ERCE_PIN_TO_PIN_WARNING ) != RPT_SEVERITY_IGNORE )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create(
|
2020-07-04 15:51:00 +00:00
|
|
|
aDiag == PIN_ERROR::PP_ERROR ? ERCE_PIN_TO_PIN_ERROR : ERCE_PIN_TO_PIN_WARNING );
|
2020-07-03 21:51:20 +00:00
|
|
|
ercItem->SetItems( pin, static_cast<SCH_PIN*>( aNetItemTst->m_Comp ) );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-07-03 21:51:20 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, aNetItemRef->m_Start );
|
|
|
|
aNetItemRef->m_SheetPath.LastScreen()->Append( marker );
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
void ERC_TESTER::TestOthersItems( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef,
|
|
|
|
unsigned aNetStart, int* aMinConnexion )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
unsigned netItemTst = aNetStart;
|
2016-02-28 17:33:29 +00:00
|
|
|
ELECTRICAL_PINTYPE jj;
|
2020-07-03 21:08:17 +00:00
|
|
|
PIN_ERROR erc = PIN_ERROR::OK;
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Analysis of the table of connections. */
|
2016-02-19 16:51:23 +00:00
|
|
|
ELECTRICAL_PINTYPE ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalPinType;
|
2013-09-27 12:30:35 +00:00
|
|
|
int local_minconn = NOC;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( ref_elect_type == ELECTRICAL_PINTYPE::PT_NC )
|
2010-10-22 07:52:55 +00:00
|
|
|
local_minconn = NPI;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Test pins connected to NetItemRef */
|
2013-09-27 12:30:35 +00:00
|
|
|
for( ; ; netItemTst++ )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
if( aNetItemRef == netItemTst )
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
// We examine only a given net. We stop the search if the net changes
|
2013-09-27 12:30:35 +00:00
|
|
|
if( ( netItemTst >= aList->size() ) // End of list
|
|
|
|
|| ( aList->GetItemNet( aNetItemRef ) !=
|
|
|
|
aList->GetItemNet( netItemTst ) ) ) // End of net
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* End net code found: minimum connection test. */
|
2013-09-27 12:30:35 +00:00
|
|
|
if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Not connected or not driven pin. */
|
2009-07-10 12:29:31 +00:00
|
|
|
bool seterr = true;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( local_minconn == NOC && aList->GetItemType( aNetItemRef ) == NETLIST_ITEM::PIN )
|
2009-07-10 12:29:31 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* This pin is not connected: for multiple part per
|
|
|
|
* package, and duplicated pin,
|
2018-04-08 10:28:59 +00:00
|
|
|
* search for another instance of this pin
|
2011-10-07 14:41:30 +00:00
|
|
|
* this will be flagged only if all instances of this pin
|
2009-11-03 13:26:31 +00:00
|
|
|
* are not connected
|
|
|
|
* TODO test also if instances connected are connected to
|
|
|
|
* the same net
|
|
|
|
*/
|
2013-09-27 12:30:35 +00:00
|
|
|
for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
|
2009-07-10 12:29:31 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( aList->GetItemType( duplicate ) != NETLIST_ITEM::PIN )
|
2009-07-10 12:29:31 +00:00
|
|
|
continue;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( duplicate == aNetItemRef )
|
2009-07-10 12:29:31 +00:00
|
|
|
continue;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( aList->GetItem( aNetItemRef )->m_PinNum !=
|
|
|
|
aList->GetItem( duplicate )->m_PinNum )
|
2009-07-10 12:29:31 +00:00
|
|
|
continue;
|
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
|
2016-02-15 20:17:51 +00:00
|
|
|
m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
|
2013-09-27 12:30:35 +00:00
|
|
|
( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
|
2016-02-15 20:17:51 +00:00
|
|
|
->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
|
2009-07-10 12:29:31 +00:00
|
|
|
continue;
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
// Same component and same pin. Do dot create error for this pin
|
2018-04-08 10:28:59 +00:00
|
|
|
// if the other pin is connected (i.e. if duplicate net has another
|
2011-10-07 14:41:30 +00:00
|
|
|
// item)
|
|
|
|
if( (duplicate > 0)
|
2013-09-27 12:30:35 +00:00
|
|
|
&& ( aList->GetItemNet( duplicate ) ==
|
|
|
|
aList->GetItemNet( duplicate - 1 ) ) )
|
2009-07-10 12:29:31 +00:00
|
|
|
seterr = false;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( (duplicate < aList->size() - 1)
|
|
|
|
&& ( aList->GetItemNet( duplicate ) ==
|
|
|
|
aList->GetItemNet( duplicate + 1 ) ) )
|
2009-07-10 12:29:31 +00:00
|
|
|
seterr = false;
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( seterr )
|
2020-07-03 21:08:17 +00:00
|
|
|
{
|
|
|
|
diagnose( aList->GetItem( aNetItemRef ), nullptr, local_minconn,
|
|
|
|
PIN_ERROR::WARNING );
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
*aMinConnexion = DRV; // inhibiting other messages of this
|
2009-11-03 13:26:31 +00:00
|
|
|
// type for the net.
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
switch( aList->GetItemType( netItemTst ) )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
case NETLIST_ITEM::ITEM_UNSPECIFIED:
|
|
|
|
case NETLIST_ITEM::SEGMENT:
|
|
|
|
case NETLIST_ITEM::BUS:
|
|
|
|
case NETLIST_ITEM::JUNCTION:
|
|
|
|
case NETLIST_ITEM::LABEL:
|
|
|
|
case NETLIST_ITEM::HIERLABEL:
|
|
|
|
case NETLIST_ITEM::BUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::HIERBUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::SHEETBUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::SHEETLABEL:
|
|
|
|
case NETLIST_ITEM::GLOBLABEL:
|
|
|
|
case NETLIST_ITEM::GLOBBUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::PINLABEL:
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case NETLIST_ITEM::NOCONNECT:
|
2012-09-22 11:19:37 +00:00
|
|
|
local_minconn = std::max( NET_NC, local_minconn );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case NETLIST_ITEM::PIN:
|
|
|
|
jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
|
2020-07-03 21:08:17 +00:00
|
|
|
local_minconn = std::max( settings.GetPinMinDrive( ref_elect_type, jj ),
|
|
|
|
local_minconn );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( netItemTst <= aNetItemRef )
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
if( erc == PIN_ERROR::OK )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
erc = settings.GetPinMapValue( ref_elect_type, jj );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
if( erc != PIN_ERROR::OK )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
if( aList->GetConnectionType( netItemTst ) == NET_CONNECTION::UNCONNECTED )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
aList->SetConnectionType( netItemTst,
|
|
|
|
NET_CONNECTION::NOCONNECT_SYMBOL_PRESENT );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2020-07-03 21:51:20 +00:00
|
|
|
|
|
|
|
diagnose( aList->GetItem( aNetItemRef ), aList->GetItem( netItemTst ), 1, erc );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 00:10:08 +00:00
|
|
|
|
|
|
|
int ERC_TESTER::TestNoConnectPins()
|
|
|
|
{
|
|
|
|
int err_count = 0;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
|
|
|
|
{
|
|
|
|
std::map<wxPoint, std::vector<SCH_PIN*>> pinMap;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
for( SCH_PIN* pin : comp->GetPins( &sheet ) )
|
2020-07-07 21:08:07 +00:00
|
|
|
{
|
|
|
|
if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
|
|
|
|
pinMap[pin->GetPosition()].emplace_back( pin );
|
|
|
|
}
|
2020-07-07 00:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& pair : pinMap )
|
|
|
|
{
|
|
|
|
if( pair.second.size() > 1 )
|
|
|
|
{
|
|
|
|
err_count++;
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
|
2020-07-07 00:10:08 +00:00
|
|
|
|
|
|
|
ercItem->SetItems( pair.second[0], pair.second[1],
|
|
|
|
pair.second.size() > 2 ? pair.second[2] : nullptr,
|
|
|
|
pair.second.size() > 3 ? pair.second[3] : nullptr );
|
|
|
|
ercItem->SetErrorMessage( _( "Pins with \"no connection\" type are connected" ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
|
|
|
|
sheet.LastScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
// this code try to detect similar labels, i.e. labels which are identical
|
|
|
|
// when they are compared using case insensitive coparisons.
|
|
|
|
|
|
|
|
|
|
|
|
// A helper struct to compare NETLIST_OBJECT items by sheetpath and label texts
|
|
|
|
// for a std::set<NETLIST_OBJECT*> container
|
|
|
|
// the full text is "sheetpath+label" for local labels and "label" for global labels
|
|
|
|
struct compare_labels
|
|
|
|
{
|
2019-11-24 17:31:44 +00:00
|
|
|
bool operator() ( const NETLIST_OBJECT* lab1, const NETLIST_OBJECT* lab2 ) const
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
wxString str1 = lab1->m_SheetPath.PathAsString() + lab1->m_Label;
|
|
|
|
wxString str2 = lab2->m_SheetPath.PathAsString() + lab2->m_Label;
|
2015-12-20 12:40:17 +00:00
|
|
|
|
|
|
|
return str1.Cmp( str2 ) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compare_label_names
|
|
|
|
{
|
2019-11-24 17:31:44 +00:00
|
|
|
bool operator() ( const NETLIST_OBJECT* lab1, const NETLIST_OBJECT* lab2 ) const
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
return lab1->m_Label.Cmp( lab2->m_Label ) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compare_paths
|
|
|
|
{
|
2019-11-24 17:31:44 +00:00
|
|
|
bool operator() ( const NETLIST_OBJECT* lab1, const NETLIST_OBJECT* lab2 ) const
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
return lab1->m_SheetPath.Path() < lab2->m_SheetPath.Path();
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper functions to build the warning messages about Similar Labels:
|
2019-08-07 18:23:59 +00:00
|
|
|
static int countIndenticalLabels( std::vector<NETLIST_OBJECT*>& aList, NETLIST_OBJECT* aRef );
|
2015-12-20 12:40:17 +00:00
|
|
|
static void SimilarLabelsDiagnose( NETLIST_OBJECT* aItemA, NETLIST_OBJECT* aItemB );
|
|
|
|
|
|
|
|
|
|
|
|
void NETLIST_OBJECT_LIST::TestforSimilarLabels()
|
|
|
|
{
|
|
|
|
// Similar labels which are different when using case sensitive comparisons
|
|
|
|
// but are equal when using case insensitive comparisons
|
|
|
|
|
|
|
|
// list of all labels (used the better item to build diag messages)
|
|
|
|
std::vector<NETLIST_OBJECT*> fullLabelList;
|
|
|
|
// list of all labels , each label appears only once (used to to detect similar labels)
|
|
|
|
std::set<NETLIST_OBJECT*, compare_labels> uniqueLabelList;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Build a list of differents labels. If inside a given sheet there are
|
|
|
|
// more than one given label, only one label is stored.
|
|
|
|
// not also the sheet labels are not taken in account for 2 reasons:
|
|
|
|
// * they are in the root sheet but they are seen only from the child sheet
|
|
|
|
// * any mismatch between child sheet hierarchical labels and the sheet label
|
|
|
|
// already detected by ERC
|
|
|
|
for( unsigned netItem = 0; netItem < size(); ++netItem )
|
|
|
|
{
|
|
|
|
switch( GetItemType( netItem ) )
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
case NETLIST_ITEM::LABEL:
|
|
|
|
case NETLIST_ITEM::BUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::PINLABEL:
|
|
|
|
case NETLIST_ITEM::GLOBBUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::HIERLABEL:
|
|
|
|
case NETLIST_ITEM::HIERBUSLABELMEMBER:
|
|
|
|
case NETLIST_ITEM::GLOBLABEL:
|
2015-12-20 12:40:17 +00:00
|
|
|
// add this label in lists
|
|
|
|
uniqueLabelList.insert( GetItem( netItem ) );
|
|
|
|
fullLabelList.push_back( GetItem( netItem ) );
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case NETLIST_ITEM::SHEETLABEL:
|
|
|
|
case NETLIST_ITEM::SHEETBUSLABELMEMBER:
|
2015-12-20 12:40:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build global labels and compare
|
|
|
|
std::set<NETLIST_OBJECT*, compare_label_names> loc_labelList;
|
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
for( NETLIST_OBJECT* label : uniqueLabelList )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-03-29 12:22:22 +00:00
|
|
|
if( label->IsLabelGlobal() )
|
|
|
|
loc_labelList.insert( label );
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// compare global labels (same label names appears only once in list)
|
2019-08-06 03:03:29 +00:00
|
|
|
for( auto it = loc_labelList.begin(); it != loc_labelList.end(); ++it )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2019-08-06 03:03:29 +00:00
|
|
|
auto it_aux = it;
|
2015-12-20 12:40:17 +00:00
|
|
|
|
|
|
|
for( ++it_aux; it_aux != loc_labelList.end(); ++it_aux )
|
|
|
|
{
|
|
|
|
if( (*it)->m_Label.CmpNoCase( (*it_aux)->m_Label ) == 0 )
|
|
|
|
{
|
|
|
|
// Create new marker for ERC.
|
|
|
|
int cntA = countIndenticalLabels( fullLabelList, *it );
|
|
|
|
int cntB = countIndenticalLabels( fullLabelList, *it_aux );
|
|
|
|
|
|
|
|
if( cntA <= cntB )
|
|
|
|
SimilarLabelsDiagnose( (*it), (*it_aux) );
|
|
|
|
else
|
|
|
|
SimilarLabelsDiagnose( (*it_aux), (*it) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build paths list
|
|
|
|
std::set<NETLIST_OBJECT*, compare_paths> pathsList;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( NETLIST_OBJECT* label : uniqueLabelList )
|
|
|
|
pathsList.insert( label );
|
2015-12-20 12:40:17 +00:00
|
|
|
|
|
|
|
// Examine each label inside a sheet path:
|
2020-03-16 11:05:01 +00:00
|
|
|
for( NETLIST_OBJECT* candidate : pathsList )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
loc_labelList.clear();
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( NETLIST_OBJECT* uniqueLabel : uniqueLabelList)
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( candidate->m_SheetPath.Path() == uniqueLabel->m_SheetPath.Path() )
|
|
|
|
loc_labelList.insert( uniqueLabel );
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// at this point, loc_labelList contains labels of the current sheet path.
|
|
|
|
// Detect similar labels (same label names appears only once in list)
|
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
for( auto ref_it = loc_labelList.begin(); ref_it != loc_labelList.end(); ++ref_it )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
NETLIST_OBJECT* ref_item = *ref_it;
|
2019-08-06 03:03:29 +00:00
|
|
|
auto it_aux = ref_it;
|
2015-12-20 12:40:17 +00:00
|
|
|
|
|
|
|
for( ++it_aux; it_aux != loc_labelList.end(); ++it_aux )
|
|
|
|
{
|
|
|
|
// global label versus global label was already examined.
|
|
|
|
// here, at least one label must be local
|
2019-08-06 03:03:29 +00:00
|
|
|
if( ref_item->IsLabelGlobal() && ( *it_aux )->IsLabelGlobal() )
|
2015-12-20 12:40:17 +00:00
|
|
|
continue;
|
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
if( ref_item->m_Label.CmpNoCase( ( *it_aux )->m_Label ) == 0 )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
// Create new marker for ERC.
|
|
|
|
int cntA = countIndenticalLabels( fullLabelList, ref_item );
|
|
|
|
int cntB = countIndenticalLabels( fullLabelList, *it_aux );
|
|
|
|
|
|
|
|
if( cntA <= cntB )
|
2019-08-06 03:03:29 +00:00
|
|
|
SimilarLabelsDiagnose( ref_item, ( *it_aux ) );
|
2015-12-20 12:40:17 +00:00
|
|
|
else
|
2019-08-06 03:03:29 +00:00
|
|
|
SimilarLabelsDiagnose( ( *it_aux ), ref_item );
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
// Helper function: count the number of labels identical to aLabel
|
|
|
|
// for global label: global labels in the full project
|
|
|
|
// for local label: all labels in the current sheet
|
2019-08-07 18:23:59 +00:00
|
|
|
static int countIndenticalLabels( std::vector<NETLIST_OBJECT*>& aList, NETLIST_OBJECT* aRef )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
if( aRef->IsLabelGlobal() )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-03-29 12:22:22 +00:00
|
|
|
for( NETLIST_OBJECT* i : aList )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
if( i->IsLabelGlobal() && i->m_Label == aRef->m_Label )
|
2015-12-20 12:40:17 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-29 12:22:22 +00:00
|
|
|
for( NETLIST_OBJECT* i : aList )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
if( i->m_Label == aRef->m_Label && i->m_SheetPath.Path() == aRef->m_SheetPath.Path() )
|
2015-12-20 12:40:17 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
// Helper function: creates a marker for similar labels ERC warning
|
|
|
|
static void SimilarLabelsDiagnose( NETLIST_OBJECT* aItemA, NETLIST_OBJECT* aItemB )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
|
2020-04-24 13:36:10 +00:00
|
|
|
ercItem->SetItems( aItemA->m_Comp, aItemB->m_Comp );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, aItemA->m_Start );
|
2020-03-16 11:05:01 +00:00
|
|
|
aItemA->m_SheetPath.LastScreen()->Append( marker );
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|