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
|
2020-10-07 13:15:31 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-01-03 15:29:45 +00:00
|
|
|
* Copyright (C) 1992-2023 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
|
|
|
|
*/
|
|
|
|
|
2022-11-26 04:40:01 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <numeric>
|
|
|
|
|
2020-08-30 19:25:31 +00:00
|
|
|
#include "connection_graph.h"
|
2023-08-13 23:44:10 +00:00
|
|
|
#include <advanced_config.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <common.h> // for ExpandEnvVarSubstitutions
|
2020-08-30 19:25:31 +00:00
|
|
|
#include <erc.h>
|
2023-01-21 23:25:40 +00:00
|
|
|
#include <erc_sch_pin_context.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_pin.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2023-11-04 13:58:24 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-08-30 19:25:31 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_marker.h>
|
2018-01-19 15:12:36 +00:00
|
|
|
#include <sch_reference_list.h>
|
2020-08-30 19:25:31 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <sch_textbox.h>
|
2022-03-17 20:23:14 +00:00
|
|
|
#include <sch_line.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2020-08-30 19:25:31 +00:00
|
|
|
#include <wx/ffile.h>
|
2023-01-02 22:47:46 +00:00
|
|
|
#include <sim/sim_lib_mgr.h>
|
2023-08-14 00:31:19 +00:00
|
|
|
#include <progress_reporter.h>
|
2022-11-12 19:45:56 +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 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" ),
|
2021-01-24 22:25:32 +00:00
|
|
|
_( "Free Pin" ),
|
2018-04-06 13:46:16 +00:00
|
|
|
_( "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" ),
|
2021-01-24 22:25:32 +00:00
|
|
|
_( "Free Pin" ),
|
2011-10-07 14:41:30 +00:00
|
|
|
_( "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-11-02 11:41:58 +00:00
|
|
|
// List of pin types that are considered drivers for usual input pins
|
|
|
|
// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
|
|
|
|
// that need only a PT_POWER_OUT pin type to be driven
|
2020-10-22 01:35:09 +00:00
|
|
|
const std::set<ELECTRICAL_PINTYPE> DrivingPinTypes =
|
|
|
|
{
|
|
|
|
ELECTRICAL_PINTYPE::PT_OUTPUT,
|
2020-11-02 11:41:58 +00:00
|
|
|
ELECTRICAL_PINTYPE::PT_POWER_OUT,
|
|
|
|
ELECTRICAL_PINTYPE::PT_PASSIVE,
|
|
|
|
ELECTRICAL_PINTYPE::PT_TRISTATE,
|
|
|
|
ELECTRICAL_PINTYPE::PT_BIDI
|
|
|
|
};
|
|
|
|
|
|
|
|
// List of pin types that are considered drivers for power pins
|
|
|
|
// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
|
|
|
|
// power input pins
|
|
|
|
const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
|
|
|
|
{
|
2020-10-22 01:35:09 +00:00
|
|
|
ELECTRICAL_PINTYPE::PT_POWER_OUT
|
|
|
|
};
|
|
|
|
|
|
|
|
// List of pin types that require a driver elsewhere on the net
|
|
|
|
const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
|
|
|
|
{
|
|
|
|
ELECTRICAL_PINTYPE::PT_INPUT,
|
|
|
|
ELECTRICAL_PINTYPE::PT_POWER_IN
|
|
|
|
};
|
|
|
|
|
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
|
2023-05-05 13:21:56 +00:00
|
|
|
if( sheet->GetShownName( false ).CmpNoCase( test_item->GetShownName( false ) ) == 0 )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2010-06-28 13:11:14 +00:00
|
|
|
if( aCreateMarker )
|
|
|
|
{
|
2023-10-12 13:36:28 +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
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void ERC_TESTER::TestTextVars( DS_PROXY_VIEW_ITEM* aDrawingSheet )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-06-12 21:33:55 +00:00
|
|
|
DS_DRAW_ITEM_LIST wsItems( schIUScale );
|
2020-05-28 13:36:54 +00:00
|
|
|
|
2020-07-31 22:56:42 +00:00
|
|
|
auto unresolved = [this]( wxString str )
|
|
|
|
{
|
|
|
|
str = ExpandEnvVarSubstitutions( str, &m_schematic->Prj() );
|
2023-10-12 13:36:28 +00:00
|
|
|
return str.Matches( wxS( "*${*}*" ) );
|
2020-07-31 22:56:42 +00:00
|
|
|
};
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
if( aDrawingSheet )
|
2020-05-28 13:36:54 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wsItems.SetPageNumber( wxS( "1" ) );
|
2020-09-04 20:37:23 +00:00
|
|
|
wsItems.SetSheetCount( 1 );
|
2023-01-17 04:14:38 +00:00
|
|
|
wsItems.SetFileName( wxS( "dummyFilename" ) );
|
|
|
|
wsItems.SetSheetName( wxS( "dummySheet" ) );
|
|
|
|
wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
|
2020-09-04 20:37:23 +00:00
|
|
|
wsItems.SetProject( &m_schematic->Prj() );
|
2023-10-12 13:36:28 +00:00
|
|
|
wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
|
2020-05-28 13:36:54 +00:00
|
|
|
}
|
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
for( SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2020-08-23 21:41:52 +00:00
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
|
2020-03-29 01:12:29 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
for( SCH_FIELD& field : symbol->GetFields() )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( unresolved( field.GetShownText( &sheet, true ) ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
auto 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
|
|
|
|
2023-03-07 00:37:33 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
|
2020-03-29 01:12:29 +00:00
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
2020-08-24 00:51:23 +00:00
|
|
|
SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
|
2020-03-29 01:12:29 +00:00
|
|
|
|
2020-08-24 00:51:23 +00:00
|
|
|
for( SCH_FIELD& field : subSheet->GetFields() )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( unresolved( field.GetShownText( &sheet, true ) ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
auto 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
SCH_SHEET_PATH subSheetPath = sheet;
|
|
|
|
subSheetPath.push_back( subSheet );
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : subSheet->GetPins() )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( pin->GetShownText( &subSheetPath, true ).Matches( wxS( "*${*}*" ) ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
auto 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 ) )
|
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( text->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
|
2020-03-29 01:12:29 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
auto 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 );
|
|
|
|
}
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
|
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( textBox->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2022-01-25 22:33:37 +00:00
|
|
|
ercItem->SetItems( textBox );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, textBox->GetPosition() );
|
|
|
|
screen->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 01:12:29 +00:00
|
|
|
}
|
2020-05-28 13:36:54 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
|
2020-05-28 13:36:54 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
|
2020-05-28 13:36:54 +00:00
|
|
|
{
|
2023-11-12 23:42:36 +00:00
|
|
|
if( text->GetShownText( true ).Matches( wxS( "*${*}*" ) ) )
|
2020-05-28 13:36:54 +00:00
|
|
|
{
|
2022-02-28 18:02:00 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> erc = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
|
2022-09-15 22:43:00 +00:00
|
|
|
erc->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
|
2020-05-28 13:36:54 +00:00
|
|
|
|
2022-02-28 18:02:00 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( erc, text->GetPosition() );
|
2020-05-28 13:36:54 +00:00
|
|
|
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
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-07-21 16:02:38 +00:00
|
|
|
const auto& 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
|
|
|
{
|
2022-08-21 19:35:02 +00:00
|
|
|
std::vector<wxString> aliasMembers = alias->Members();
|
|
|
|
std::sort( aliasMembers.begin(), aliasMembers.end() );
|
|
|
|
|
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
|
|
|
{
|
2022-08-21 19:35:02 +00:00
|
|
|
std::vector<wxString> testMembers = test->Members();
|
|
|
|
std::sort( testMembers.begin(), testMembers.end() );
|
|
|
|
|
|
|
|
if( alias->GetName() == test->GetName() && aliasMembers != testMembers )
|
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 );
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, VECTOR2I() );
|
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;
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP refMap;
|
2020-11-15 16:08:31 +00:00
|
|
|
sheets.GetMultiUnitSymbols( refMap, true );
|
2018-01-19 15:12:36 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : refMap )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
SCH_REFERENCE_LIST& refList = symbol.second;
|
2018-01-19 15:12:36 +00:00
|
|
|
|
|
|
|
if( refList.GetCount() == 0 )
|
|
|
|
{
|
|
|
|
wxFAIL; // it should not happen
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reference footprint
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* unit = nullptr;
|
|
|
|
wxString unitName;
|
|
|
|
wxString unitFP;
|
2018-01-19 15:12:36 +00:00
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
for( unsigned i = 0; i < refList.GetCount(); ++i )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
|
2020-08-29 13:41:47 +00:00
|
|
|
unitFP = refList.GetItem( i ).GetFootprint();
|
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-11-15 16:08:31 +00:00
|
|
|
unit = refList.GetItem( i ).GetSymbol();
|
2020-03-16 11:05:01 +00:00
|
|
|
unitName = unit->GetRef( &sheetPath, true );
|
2018-01-19 15:12:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
for( unsigned i = 0; i < refList.GetCount(); ++i )
|
2018-01-19 15:12:36 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_REFERENCE& secondRef = refList.GetItem( i );
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
|
2020-04-24 13:36:10 +00:00
|
|
|
wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
|
2020-08-29 13:41:47 +00:00
|
|
|
const wxString secondFp = secondRef.GetFootprint();
|
2020-04-24 13:36:10 +00:00
|
|
|
wxString msg;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-09-20 01:20:41 +00:00
|
|
|
if( unit && !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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-26 04:40:01 +00:00
|
|
|
int ERC_TESTER::TestMissingUnits()
|
|
|
|
{
|
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic->GetSheets();
|
|
|
|
|
|
|
|
int errors = 0;
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP refMap;
|
|
|
|
sheets.GetMultiUnitSymbols( refMap, true );
|
|
|
|
|
|
|
|
for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : refMap )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE_LIST& refList = symbol.second;
|
|
|
|
|
|
|
|
wxCHECK2( refList.GetCount(), continue );
|
|
|
|
|
|
|
|
// Reference unit
|
|
|
|
SCH_REFERENCE& base_ref = refList.GetItem( 0 );
|
|
|
|
SCH_SYMBOL* unit = base_ref.GetSymbol();
|
|
|
|
LIB_SYMBOL* libSymbol = base_ref.GetLibPart();
|
|
|
|
|
|
|
|
if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol->GetUnitCount() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::set<int> lib_units;
|
|
|
|
std::set<int> instance_units;
|
|
|
|
std::set<int> missing_units;
|
|
|
|
|
2023-10-12 13:36:28 +00:00
|
|
|
auto report_missing = [&]( std::set<int>& aMissingUnits, wxString aErrorMsg,
|
|
|
|
int aErrorCode )
|
2022-11-26 04:40:01 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2023-10-12 13:36:28 +00:00
|
|
|
wxString missing_pin_units = wxS( "[ " );
|
2022-11-26 04:40:01 +00:00
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
for( int missing_unit : aMissingUnits )
|
|
|
|
{
|
|
|
|
if( ii++ == 3 )
|
|
|
|
{
|
2023-10-12 13:36:28 +00:00
|
|
|
missing_pin_units += wxS( "....." );
|
2022-11-26 04:40:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
missing_pin_units += libSymbol->GetUnitDisplayName( missing_unit ) + ", " ;
|
|
|
|
}
|
|
|
|
|
|
|
|
missing_pin_units.Truncate( missing_pin_units.length() - 2 );
|
2023-10-12 13:36:28 +00:00
|
|
|
missing_pin_units += wxS( " ]" );
|
2022-11-26 04:40:01 +00:00
|
|
|
|
|
|
|
msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
|
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
ercItem->SetItems( unit );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, unit->GetPosition() );
|
|
|
|
base_ref.GetSheetPath().LastScreen()->Append( marker );
|
|
|
|
|
|
|
|
++errors;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
|
|
|
|
lib_units.insert( lib_units.end(), ii );
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < refList.GetCount(); ++ii )
|
|
|
|
instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
|
|
|
|
|
|
|
|
std::set_difference( lib_units.begin(), lib_units.end(),
|
|
|
|
instance_units.begin(), instance_units.end(),
|
|
|
|
std::inserter( missing_units, missing_units.begin() ) );
|
|
|
|
|
|
|
|
if( !missing_units.empty() && settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
|
|
|
|
{
|
|
|
|
report_missing( missing_units, _( "Symbol %s has unplaced units %s" ),
|
2023-10-12 13:36:28 +00:00
|
|
|
ERCE_MISSING_UNIT );
|
2022-11-26 04:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::set<int> missing_power;
|
|
|
|
std::set<int> missing_input;
|
|
|
|
std::set<int> missing_bidi;
|
|
|
|
|
|
|
|
for( int missing_unit : missing_units )
|
|
|
|
{
|
|
|
|
LIB_PINS pins;
|
|
|
|
int convert = 0;
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < refList.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
if( refList.GetItem( ii ).GetUnit() == missing_unit )
|
|
|
|
{
|
|
|
|
convert = refList.GetItem( ii ).GetSymbol()->GetConvert();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
libSymbol->GetPins( pins, missing_unit, convert );
|
|
|
|
|
|
|
|
for( auto pin : pins )
|
|
|
|
{
|
|
|
|
switch( pin->GetType() )
|
|
|
|
{
|
|
|
|
case ELECTRICAL_PINTYPE::PT_POWER_IN:
|
|
|
|
missing_power.insert( missing_unit );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ELECTRICAL_PINTYPE::PT_BIDI:
|
|
|
|
missing_bidi.insert( missing_unit );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ELECTRICAL_PINTYPE::PT_INPUT:
|
|
|
|
missing_input.insert( missing_unit );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !missing_power.empty() && settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
|
|
|
|
{
|
2023-10-12 13:36:28 +00:00
|
|
|
report_missing( missing_power,
|
|
|
|
_( "Symbol %s has input power pins in units %s that are not placed." ),
|
|
|
|
ERCE_MISSING_POWER_INPUT_PIN );
|
2022-11-26 04:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !missing_input.empty() && settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
|
|
|
|
{
|
2023-10-12 13:36:28 +00:00
|
|
|
report_missing( missing_input,
|
|
|
|
_( "Symbol %s has input pins in units %s that are not placed." ),
|
|
|
|
ERCE_MISSING_INPUT_PIN );
|
2022-11-26 04:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !missing_bidi.empty() && settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
|
|
|
|
{
|
2023-10-12 13:36:28 +00:00
|
|
|
report_missing( missing_bidi,
|
|
|
|
_( "Symbol %s has bidirectional pins in units %s that are not "
|
|
|
|
"placed." ),
|
|
|
|
ERCE_MISSING_BIDI_PIN );
|
2022-11-26 04:40:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-04 13:58:24 +00:00
|
|
|
int ERC_TESTER::TestMissingNetclasses()
|
|
|
|
{
|
|
|
|
int err_count = 0;
|
|
|
|
std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Prj().GetProjectFile().NetSettings();
|
|
|
|
|
|
|
|
auto logError =
|
|
|
|
[&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
|
|
|
|
{
|
|
|
|
err_count++;
|
|
|
|
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
|
|
|
|
|
|
|
|
ercItem->SetItems( item );
|
|
|
|
ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ),
|
|
|
|
netclass ) );
|
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
|
|
|
|
sheet.LastScreen()->Append( marker );
|
|
|
|
};
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
|
|
|
{
|
|
|
|
item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
if( aChild->Type() == SCH_FIELD_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
|
|
|
|
|
|
|
|
if( field->GetCanonicalName() == wxT( "Netclass" ) )
|
|
|
|
{
|
|
|
|
wxString netclass = field->GetText();
|
|
|
|
|
|
|
|
if( settings->m_NetClasses.count( netclass ) == 0 )
|
|
|
|
logError( sheet, item, netclass );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2023-09-04 16:27:12 +00:00
|
|
|
std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
|
|
|
|
|
|
|
|
auto addOther =
|
|
|
|
[&]( const VECTOR2I& pt, SCH_ITEM* aOther )
|
|
|
|
{
|
|
|
|
if( pinMap.count( pt ) )
|
|
|
|
pinMap[pt].emplace_back( aOther );
|
|
|
|
};
|
2020-07-07 00:10:08 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
2020-07-07 00:10:08 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2020-07-07 00:10:08 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
for( SCH_PIN* pin : symbol->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
|
|
|
}
|
|
|
|
|
2023-09-04 16:27:12 +00:00
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
|
|
|
|
{
|
|
|
|
if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
|
|
|
|
addOther( pin->GetPosition(), pin );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->IsConnectable() )
|
|
|
|
{
|
|
|
|
for( const VECTOR2I& pt : item->GetConnectionPoints() )
|
|
|
|
addOther( pt, item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
|
2020-07-07 00:10:08 +00:00
|
|
|
{
|
|
|
|
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 );
|
2023-09-04 16:27:12 +00:00
|
|
|
ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
|
2020-07-07 00:10:08 +00:00
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
|
|
|
|
sheet.LastScreen()->Append( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 19:25:31 +00:00
|
|
|
int ERC_TESTER::TestPinToPin()
|
|
|
|
{
|
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
|
|
|
const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
|
|
|
|
|
|
|
|
int errors = 0;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
2023-01-21 23:25:40 +00:00
|
|
|
std::vector<ERC_SCH_PIN_CONTEXT> pins;
|
2020-08-30 19:25:31 +00:00
|
|
|
std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
|
2022-04-07 16:29:02 +00:00
|
|
|
bool has_noconnect = false;
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph: net.second )
|
|
|
|
{
|
2023-03-03 22:06:41 +00:00
|
|
|
if( subgraph->GetNoConnect() )
|
2022-04-07 16:29:02 +00:00
|
|
|
has_noconnect = true;
|
|
|
|
|
2023-03-03 22:06:41 +00:00
|
|
|
for( SCH_ITEM* item : subgraph->GetItems() )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_PIN_T )
|
|
|
|
{
|
2023-03-03 22:06:41 +00:00
|
|
|
pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
|
|
|
|
pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
|
2020-08-30 19:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
ERC_SCH_PIN_CONTEXT needsDriver;
|
|
|
|
bool hasDriver = false;
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2020-11-02 11:41:58 +00:00
|
|
|
// We need different drivers for power nets and normal nets.
|
|
|
|
// A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
|
|
|
|
// and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
|
|
|
|
bool ispowerNet = false;
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
for( ERC_SCH_PIN_CONTEXT& refPin : pins )
|
2020-11-02 11:41:58 +00:00
|
|
|
{
|
2023-01-21 23:25:40 +00:00
|
|
|
if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
|
2020-11-02 11:41:58 +00:00
|
|
|
{
|
|
|
|
ispowerNet = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 16:05:39 +00:00
|
|
|
for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
2023-10-06 16:05:39 +00:00
|
|
|
ERC_SCH_PIN_CONTEXT& refPin = *refIt;
|
2023-01-21 23:25:40 +00:00
|
|
|
ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
|
2020-08-30 19:25:31 +00:00
|
|
|
|
2020-10-22 01:47:00 +00:00
|
|
|
if( DrivenPinTypes.count( refType ) )
|
|
|
|
{
|
|
|
|
// needsDriver will be the pin shown in the error report eventually, so try to
|
2021-01-25 03:17:56 +00:00
|
|
|
// upgrade to a "better" pin if possible: something visible and only a power symbol
|
|
|
|
// if this net needs a power driver
|
2023-01-21 23:25:40 +00:00
|
|
|
if( !needsDriver.Pin()
|
|
|
|
|| ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
|
|
|
|
|| ( ispowerNet
|
|
|
|
!= ( needsDriver.Pin()->GetType()
|
|
|
|
== ELECTRICAL_PINTYPE::PT_POWER_IN )
|
|
|
|
&& ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
|
2021-01-25 03:17:56 +00:00
|
|
|
{
|
2020-10-22 01:47:00 +00:00
|
|
|
needsDriver = refPin;
|
2021-01-25 03:17:56 +00:00
|
|
|
}
|
2020-10-22 01:47:00 +00:00
|
|
|
}
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2020-11-02 11:41:58 +00:00
|
|
|
if( ispowerNet )
|
|
|
|
hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
|
|
|
|
else
|
|
|
|
hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2023-10-06 16:05:39 +00:00
|
|
|
for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
2023-10-06 16:05:39 +00:00
|
|
|
ERC_SCH_PIN_CONTEXT& testPin = *testIt;
|
2020-08-30 19:25:31 +00:00
|
|
|
|
2022-07-30 20:10:14 +00:00
|
|
|
// Multiple pins in the same symbol that share a type,
|
|
|
|
// name and position are considered
|
|
|
|
// "stacked" and shouldn't trigger ERC errors
|
2023-03-07 00:37:33 +00:00
|
|
|
if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
|
2022-07-30 20:10:14 +00:00
|
|
|
continue;
|
2020-08-30 19:25:31 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
|
2020-08-30 19:25:31 +00:00
|
|
|
|
2020-11-02 11:41:58 +00:00
|
|
|
if( ispowerNet )
|
|
|
|
hasDriver |= ( DrivingPowerPinTypes.count( testType ) != 0 );
|
|
|
|
else
|
|
|
|
hasDriver |= ( DrivingPinTypes.count( testType ) != 0 );
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2020-08-30 19:25:31 +00:00
|
|
|
PIN_ERROR erc = settings.GetPinMapValue( refType, testType );
|
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
if( erc != PIN_ERROR::OK && settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem =
|
|
|
|
ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING :
|
|
|
|
ERCE_PIN_TO_PIN_ERROR );
|
2023-01-21 23:25:40 +00:00
|
|
|
ercItem->SetItems( refPin.Pin(), testPin.Pin() );
|
|
|
|
ercItem->SetSheetSpecificPath( refPin.Sheet() );
|
|
|
|
ercItem->SetItemsSheetPaths( refPin.Sheet(), testPin.Sheet() );
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
ercItem->SetErrorMessage(
|
|
|
|
wxString::Format( _( "Pins of type %s and %s are connected" ),
|
2021-11-04 16:23:25 +00:00
|
|
|
ElectricalPinTypeGetText( refType ),
|
|
|
|
ElectricalPinTypeGetText( testType ) ) );
|
2020-08-30 19:25:31 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
SCH_MARKER* marker =
|
|
|
|
new SCH_MARKER( ercItem, refPin.Pin()->GetTransformedPosition() );
|
|
|
|
pinToScreenMap[refPin.Pin()]->Append( marker );
|
2020-08-30 19:25:31 +00:00
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
if( needsDriver.Pin() && !hasDriver && !has_noconnect )
|
2020-10-22 01:35:09 +00:00
|
|
|
{
|
2020-11-02 11:41:58 +00:00
|
|
|
int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
|
|
|
|
|
2021-11-04 16:23:25 +00:00
|
|
|
if( settings.IsTestEnabled( err_code ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
ercItem->SetItems( needsDriver.Pin() );
|
2023-03-07 00:37:33 +00:00
|
|
|
ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
|
|
|
|
ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
|
2020-10-22 01:35:09 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
SCH_MARKER* marker =
|
|
|
|
new SCH_MARKER( ercItem, needsDriver.Pin()->GetTransformedPosition() );
|
|
|
|
pinToScreenMap[needsDriver.Pin()]->Append( marker );
|
2021-11-04 16:23:25 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2020-10-22 01:35:09 +00:00
|
|
|
}
|
2020-08-30 19:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ERC_TESTER::TestMultUnitPinConflicts()
|
|
|
|
{
|
|
|
|
const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
|
|
|
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
const wxString& netName = net.first.Name;
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : net.second )
|
|
|
|
{
|
2023-03-03 22:06:41 +00:00
|
|
|
for( SCH_ITEM* item : subgraph->GetItems() )
|
2020-08-30 19:25:31 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( item );
|
2023-03-03 22:06:41 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
if( !pin->GetLibPin()->GetParent()->IsMulti() )
|
|
|
|
continue;
|
|
|
|
|
2023-03-03 22:06:41 +00:00
|
|
|
wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
|
2021-06-17 09:37:13 +00:00
|
|
|
+ ":" + pin->GetShownNumber();
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
if( !pinToNetMap.count( name ) )
|
|
|
|
{
|
|
|
|
pinToNetMap[name] = std::make_pair( netName, pin );
|
|
|
|
}
|
|
|
|
else if( pinToNetMap[name].first != netName )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem =
|
|
|
|
ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
|
|
|
|
|
|
|
|
ercItem->SetErrorMessage( wxString::Format(
|
|
|
|
_( "Pin %s is connected to both %s and %s" ),
|
2021-06-17 09:37:13 +00:00
|
|
|
pin->GetShownNumber(),
|
|
|
|
netName,
|
|
|
|
pinToNetMap[name].first ) );
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
ercItem->SetItems( pin, pinToNetMap[name].second );
|
2023-03-03 22:06:41 +00:00
|
|
|
ercItem->SetSheetSpecificPath( sheet );
|
|
|
|
ercItem->SetItemsSheetPaths( sheet, sheet );
|
2020-08-30 19:25:31 +00:00
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem,
|
|
|
|
pin->GetTransformedPosition() );
|
2023-03-03 22:06:41 +00:00
|
|
|
sheet.LastScreen()->Append( marker );
|
2020-10-07 13:15:31 +00:00
|
|
|
errors += 1;
|
2020-08-30 19:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
int ERC_TESTER::TestSimilarLabels()
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-08-30 19:42:46 +00:00
|
|
|
const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
int errors = 0;
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2023-03-07 00:37:33 +00:00
|
|
|
std::unordered_map<wxString, std::pair<SCH_LABEL_BASE*, SCH_SHEET_PATH>> labelMap;
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-08-30 19:42:46 +00:00
|
|
|
for( CONNECTION_SUBGRAPH* subgraph : net.second )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
|
|
|
|
|
2023-03-03 22:06:41 +00:00
|
|
|
for( SCH_ITEM* item : subgraph->GetItems() )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2020-08-30 19:42:46 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
{
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
wxString normalized = label->GetShownText( &sheet, false ).Lower();
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
if( !labelMap.count( normalized ) )
|
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
labelMap[normalized] = std::make_pair( label, sheet );
|
|
|
|
break;
|
2020-08-30 19:42:46 +00:00
|
|
|
}
|
2023-11-12 14:14:41 +00:00
|
|
|
|
|
|
|
auto& [ otherLabel, otherSheet ] = labelMap.at( normalized );
|
|
|
|
|
|
|
|
if( otherLabel->GetShownText( &otherSheet, false )
|
|
|
|
!= label->GetShownText( &sheet, false ) )
|
2020-08-30 19:42:46 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
|
2023-03-07 00:37:33 +00:00
|
|
|
ercItem->SetItems( label, labelMap.at( normalized ).first );
|
2023-11-12 14:14:41 +00:00
|
|
|
ercItem->SetSheetSpecificPath( sheet );
|
|
|
|
ercItem->SetItemsSheetPaths( sheet, labelMap.at( normalized ).second );
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
|
2023-11-12 14:14:41 +00:00
|
|
|
sheet.LastScreen()->Append( marker );
|
2020-10-07 13:15:31 +00:00
|
|
|
errors += 1;
|
2020-08-30 19:42:46 +00:00
|
|
|
}
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-30 19:42:46 +00:00
|
|
|
return errors;
|
2015-12-20 12:40:17 +00:00
|
|
|
}
|
2020-10-07 13:15:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
int ERC_TESTER::TestLibSymbolIssues()
|
|
|
|
{
|
|
|
|
wxCHECK( m_schematic, 0 );
|
|
|
|
|
2023-09-28 03:04:53 +00:00
|
|
|
SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
|
2020-12-18 12:47:10 +00:00
|
|
|
wxString msg;
|
|
|
|
int err_count = 0;
|
2020-10-07 13:15:31 +00:00
|
|
|
|
|
|
|
SCH_SCREENS screens( m_schematic->Root() );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
|
2020-10-07 13:15:31 +00:00
|
|
|
{
|
2020-10-19 14:32:30 +00:00
|
|
|
std::vector<SCH_MARKER*> markers;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
|
2020-10-07 13:15:31 +00:00
|
|
|
{
|
2022-03-17 20:23:14 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
|
2020-10-07 13:15:31 +00:00
|
|
|
|
|
|
|
wxCHECK2( libSymbolInSchematic, continue );
|
|
|
|
|
2020-12-18 12:47:10 +00:00
|
|
|
wxString libName = symbol->GetLibId().GetLibNickname();
|
2021-01-10 22:55:30 +00:00
|
|
|
LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
|
2020-10-07 13:15:31 +00:00
|
|
|
|
2020-12-18 12:47:10 +00:00
|
|
|
if( !libTableRow )
|
2020-10-07 13:15:31 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
|
|
|
|
ercItem->SetItems( symbol );
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "The current configuration does not include the library '%s'" ),
|
2021-07-28 17:36:13 +00:00
|
|
|
UnescapeString( libName ) );
|
2020-10-07 13:15:31 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
|
2020-10-19 14:32:30 +00:00
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
|
2021-06-17 21:15:02 +00:00
|
|
|
continue;
|
2020-10-07 13:15:31 +00:00
|
|
|
}
|
2020-12-18 12:47:10 +00:00
|
|
|
else if( !libTable->HasLibrary( libName, true ) )
|
2020-10-07 13:15:31 +00:00
|
|
|
{
|
2020-12-18 12:47:10 +00:00
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
|
|
|
|
ercItem->SetItems( symbol );
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
|
2021-07-28 17:36:13 +00:00
|
|
|
UnescapeString( libName ) );
|
2020-12-18 12:47:10 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
2020-10-07 13:15:31 +00:00
|
|
|
|
2020-12-18 12:47:10 +00:00
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
|
2021-06-17 21:15:02 +00:00
|
|
|
continue;
|
2020-12-18 12:47:10 +00:00
|
|
|
}
|
2020-10-19 14:34:59 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString symbolName = symbol->GetLibId().GetLibItemName();
|
2021-06-17 21:22:10 +00:00
|
|
|
LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
|
2020-12-18 12:47:10 +00:00
|
|
|
|
|
|
|
if( libSymbol == nullptr )
|
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
|
|
|
|
ercItem->SetItems( symbol );
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
|
2021-07-28 17:36:13 +00:00
|
|
|
UnescapeString( symbolName ),
|
|
|
|
UnescapeString( libName ) );
|
2020-12-18 12:47:10 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
|
2021-06-17 21:15:02 +00:00
|
|
|
continue;
|
2020-12-18 12:47:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
|
2022-03-03 12:20:30 +00:00
|
|
|
constexpr int flags = LIB_ITEM::COMPARE_FLAGS::EQUALITY | LIB_ITEM::COMPARE_FLAGS::ERC;
|
2020-12-18 12:47:10 +00:00
|
|
|
|
2022-03-03 12:20:30 +00:00
|
|
|
if( flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
|
2020-12-18 12:47:10 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
|
|
|
|
ercItem->SetItems( symbol );
|
2022-09-15 22:43:00 +00:00
|
|
|
msg.Printf( _( "Symbol '%s' has been modified in library '%s'" ),
|
2021-07-28 17:36:13 +00:00
|
|
|
UnescapeString( symbolName ),
|
|
|
|
UnescapeString( libName ) );
|
2020-12-18 12:47:10 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
|
2020-10-07 13:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-19 14:32:30 +00:00
|
|
|
|
|
|
|
for( SCH_MARKER* marker : markers )
|
|
|
|
{
|
|
|
|
screen->Append( marker );
|
|
|
|
err_count += 1;
|
|
|
|
}
|
2020-10-07 13:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
2022-03-17 20:23:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 19:46:39 +00:00
|
|
|
int ERC_TESTER::TestOffGridEndpoints()
|
2022-03-17 20:23:14 +00:00
|
|
|
{
|
2023-10-14 19:46:39 +00:00
|
|
|
const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
|
2022-03-17 20:23:14 +00:00
|
|
|
|
|
|
|
SCH_SCREENS screens( m_schematic->Root() );
|
|
|
|
int err_count = 0;
|
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
|
|
|
|
{
|
|
|
|
std::vector<SCH_MARKER*> markers;
|
|
|
|
|
2022-03-20 22:16:20 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
2022-03-17 20:23:14 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T && item->IsConnectable() )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
2023-10-14 19:46:39 +00:00
|
|
|
if( ( line->GetStartPoint().x % gridSize ) != 0
|
|
|
|
|| ( line->GetStartPoint().y % gridSize ) != 0 )
|
2022-03-17 20:23:14 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
|
|
|
|
ercItem->SetItems( line );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
|
|
|
|
}
|
2023-10-14 19:46:39 +00:00
|
|
|
else if( ( line->GetEndPoint().x % gridSize ) != 0
|
|
|
|
|| ( line->GetEndPoint().y % gridSize ) != 0 )
|
2022-03-17 20:23:14 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
|
|
|
|
ercItem->SetItems( line );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
|
|
|
|
{
|
|
|
|
VECTOR2I pinPos = pin->GetTransformedPosition();
|
|
|
|
|
2023-10-14 19:46:39 +00:00
|
|
|
if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
|
2022-03-17 20:23:14 +00:00
|
|
|
{
|
2023-10-14 19:46:39 +00:00
|
|
|
auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
|
2022-03-17 20:23:14 +00:00
|
|
|
ercItem->SetItems( pin );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_MARKER* marker : markers )
|
|
|
|
{
|
|
|
|
screen->Append( marker );
|
|
|
|
err_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
2022-08-26 02:51:11 +00:00
|
|
|
}
|
2022-11-07 12:27:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
int ERC_TESTER::TestSimModelIssues()
|
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic->GetSheets();
|
|
|
|
int err_count = 0;
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIB_MGR libMgr( &m_schematic->Prj() );
|
2022-11-07 12:27:58 +00:00
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : sheets )
|
|
|
|
{
|
|
|
|
std::vector<SCH_MARKER*> markers;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
2023-04-01 08:16:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
2023-04-14 18:40:41 +00:00
|
|
|
// Power symbols and other symbols which have the reference starting with "#" are
|
|
|
|
// not included in simulation
|
2023-08-08 16:32:08 +00:00
|
|
|
if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
|
2023-04-01 08:16:44 +00:00
|
|
|
continue;
|
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
// Reset for each symbol
|
|
|
|
msg.Clear();
|
2022-11-07 12:27:58 +00:00
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
|
2023-01-02 22:47:46 +00:00
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
2022-11-07 12:27:58 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
|
2023-04-01 08:16:44 +00:00
|
|
|
|
|
|
|
//Remove \n and \r at e.o.l if any:
|
|
|
|
msg.Trim();
|
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
ercItem->SetErrorMessage( msg );
|
2022-11-07 12:27:58 +00:00
|
|
|
ercItem->SetItems( symbol );
|
|
|
|
|
|
|
|
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_MARKER* marker : markers )
|
|
|
|
{
|
|
|
|
sheet.LastScreen()->Append( marker );
|
|
|
|
err_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err_count;
|
|
|
|
}
|
2023-08-13 23:44:10 +00:00
|
|
|
|
|
|
|
|
2023-08-14 00:31:19 +00:00
|
|
|
void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aEditFrame,
|
|
|
|
PROGRESS_REPORTER* aProgressReporter )
|
2023-08-13 23:44:10 +00:00
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
ERC_SETTINGS& settings = m_schematic->ErcSettings();
|
2023-08-13 23:44:10 +00:00
|
|
|
|
|
|
|
// Test duplicate sheet names inside a given sheet. While one can have multiple references
|
|
|
|
// to the same file, each must have a unique name.
|
|
|
|
if( settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
|
|
|
|
{
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestDuplicateSheetNames( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_BUS_ALIAS_CONFLICT ) )
|
|
|
|
{
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestConflictingBusAliases();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The connection graph has a whole set of ERC checks it can run
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
|
|
|
|
|
|
|
|
// If we are using the new connectivity, make sure that we do a full-rebuild
|
|
|
|
if( aEditFrame )
|
|
|
|
{
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
|
|
|
|
aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
|
|
|
|
else
|
|
|
|
aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
|
|
|
|
}
|
|
|
|
|
2023-08-14 00:31:19 +00:00
|
|
|
m_schematic->ConnectionGraph()->RunERC();
|
2023-08-13 23:44:10 +00:00
|
|
|
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking units..." ) );
|
|
|
|
|
|
|
|
// Test is all units of each multiunit symbol have the same footprint assigned.
|
|
|
|
if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
|
|
|
|
{
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestMultiunitFootprints();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_MISSING_UNIT )
|
|
|
|
|| settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN )
|
|
|
|
|| settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN )
|
|
|
|
|| settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
|
|
|
|
{
|
|
|
|
TestMissingUnits();
|
|
|
|
}
|
|
|
|
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
|
2023-08-13 23:44:10 +00:00
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
|
|
|
|
TestMultUnitPinConflicts();
|
|
|
|
|
|
|
|
// Test pins on each net against the pin connection table
|
|
|
|
if( settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
|
|
|
|
|| settings.IsTestEnabled( ERCE_POWERPIN_NOT_DRIVEN )
|
|
|
|
|| settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
|
|
|
|
{
|
|
|
|
TestPinToPin();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test similar labels (i;e. labels which are identical when
|
|
|
|
// using case insensitive comparisons)
|
|
|
|
if( settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestSimilarLabels();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestTextVars( aDrawingSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestSimModelIssues();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestNoConnectPins();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-08-13 23:44:10 +00:00
|
|
|
TestLibSymbolIssues();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
|
|
|
|
{
|
2023-08-14 00:31:19 +00:00
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
|
2023-10-12 13:36:28 +00:00
|
|
|
|
2023-10-14 19:46:39 +00:00
|
|
|
TestOffGridEndpoints();
|
2023-08-13 23:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-11-04 13:58:24 +00:00
|
|
|
if( settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
|
|
|
|
{
|
|
|
|
if( aProgressReporter )
|
|
|
|
aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
|
|
|
|
|
|
|
|
TestMissingNetclasses();
|
|
|
|
}
|
|
|
|
|
2023-08-14 00:31:19 +00:00
|
|
|
m_schematic->ResolveERCExclusionsPostUpdate();
|
2023-10-12 13:36:28 +00:00
|
|
|
}
|