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>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2015-07-29 12:18:53 +00:00
|
|
|
#include <wx/ffile.h>
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Electrical type of pins:
|
|
|
|
* PIN_INPUT = usual pin input: must be connected
|
|
|
|
* PIN_OUTPUT = usual output
|
|
|
|
* PIN_BIDI = input or output (like port for a microprocessor)
|
|
|
|
* PIN_TRISTATE = tris state bus pin
|
2009-11-03 13:26:31 +00:00
|
|
|
* PIN_PASSIVE = pin for passive components: must be connected, and can be
|
|
|
|
* connected to any pin
|
|
|
|
* PIN_UNSPECIFIED = unknown electrical properties: creates always a warning
|
|
|
|
* when connected
|
|
|
|
* PIN_POWER_IN = power input (GND, VCC for ICs). Must be connected to a power
|
|
|
|
* output.
|
|
|
|
* PIN_POWER_OUT = output of a regulator: intended to be connected to power
|
|
|
|
* input pins
|
2009-07-07 17:50:02 +00:00
|
|
|
* PIN_OPENCOLLECTOR = pin type open collector
|
|
|
|
* PIN_OPENEMITTER = pin type open emitter
|
|
|
|
* PIN_NC = not connected (must be left open)
|
|
|
|
*
|
|
|
|
* Minimal requirements:
|
|
|
|
* All pins *must* be connected (except PIN_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 :
|
2007-09-20 21:06:49 +00:00
|
|
|
* PIN_INPUT, PIN_OUTPUT, PIN_BIDI, PIN_TRISTATE, PIN_PASSIVE,
|
|
|
|
* PIN_UNSPECIFIED, PIN_POWER_IN, PIN_POWER_OUT, PIN_OPENCOLLECTOR,
|
|
|
|
* PIN_OPENEMITTER, PIN_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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Look up table which gives the diag for a pair of connected pins
|
2007-09-20 21:06:49 +00:00
|
|
|
* Can be modified by ERC options.
|
|
|
|
* at start up: must be loaded by DefaultDiagErc
|
2015-12-20 12:40:17 +00:00
|
|
|
* Can be modified in dialog ERC
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2016-02-28 17:33:29 +00:00
|
|
|
int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT];
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* Default Look up table which gives the ERC error level for a pair of connected pins
|
|
|
|
* Same as DiagErc, but cannot be modified.
|
2007-09-20 21:06:49 +00:00
|
|
|
* Used to init or reset DiagErc
|
2010-10-22 07:52:55 +00:00
|
|
|
* note also, to avoid inconsistancy:
|
|
|
|
* DefaultDiagErc[i][j] = DefaultDiagErc[j][i]
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2016-02-28 17:33:29 +00:00
|
|
|
int DefaultDiagErc[PINTYPE_COUNT][PINTYPE_COUNT] =
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* I, O, Bi, 3S, Pas, UnS, PwrI, PwrO, OC, OE, NC */
|
2010-10-22 07:52:55 +00:00
|
|
|
/* I */ { OK, OK, OK, OK, OK, WAR, OK, OK, OK, OK, ERR },
|
|
|
|
/* O */ { OK, ERR, OK, WAR, OK, WAR, OK, ERR, ERR, ERR, ERR },
|
|
|
|
/* Bi*/ { OK, OK, OK, OK, OK, WAR, OK, WAR, OK, WAR, ERR },
|
|
|
|
/* 3S*/ { OK, WAR, OK, OK, OK, WAR, WAR, ERR, WAR, WAR, ERR },
|
|
|
|
/*Pas*/ { OK, OK, OK, OK, OK, WAR, OK, OK, OK, OK, ERR },
|
|
|
|
/*UnS */ { WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, ERR },
|
2009-11-03 13:26:31 +00:00
|
|
|
/*PwrI*/ { OK, OK, OK, WAR, OK, WAR, OK, OK, OK, OK, ERR },
|
2010-10-22 07:52:55 +00:00
|
|
|
/*PwrO*/ { OK, ERR, WAR, ERR, OK, WAR, OK, ERR, ERR, ERR, ERR },
|
|
|
|
/* OC */ { OK, ERR, OK, WAR, OK, WAR, OK, ERR, OK, OK, ERR },
|
|
|
|
/* OE */ { OK, ERR, WAR, WAR, OK, WAR, OK, ERR, OK, OK, ERR },
|
|
|
|
/* NC */ { ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR }
|
2007-09-20 21:06:49 +00:00
|
|
|
};
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* Look up table which gives the minimal drive for a pair of connected pins on
|
|
|
|
* a net.
|
|
|
|
* <p>
|
|
|
|
* The initial state of a net is NOC (Net with No Connection). It can be updated to
|
|
|
|
* NPI (Pin Isolated), NET_NC (Net with a no connect symbol), NOD (Not Driven) or DRV
|
|
|
|
* (DRIven). It can be updated to NET_NC with no error only if there is only one pin
|
|
|
|
* in net. Nets are OK when their final state is NET_NC or DRV. Nets with the state
|
|
|
|
* NOD have no valid source signal.
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2016-02-28 17:33:29 +00:00
|
|
|
static int MinimalReq[PINTYPE_COUNT][PINTYPE_COUNT] =
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* In Out, Bi, 3S, Pas, UnS, PwrI,PwrO,OC, OE, NC */
|
2010-10-22 07:52:55 +00:00
|
|
|
/* In*/ { NOD, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/*Out*/ { DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, NPI },
|
|
|
|
/* Bi*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/* 3S*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/*Pas*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/*UnS*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/*PwrI*/ { NOD, DRV, NOD, NOD, NOD, NOD, NOD, DRV, NOD, NOD, NPI },
|
|
|
|
/*PwrO*/ { DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, NPI },
|
|
|
|
/* OC*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/* OE*/ { DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
|
|
|
|
/* NC*/ { NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI }
|
2007-09-20 21:06:49 +00:00
|
|
|
};
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
int TestDuplicateSheetNames( bool aCreateMarker )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_SCREEN* screen;
|
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* test_item;
|
2010-10-26 20:25:48 +00:00
|
|
|
int err_count = 0;
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_SCREENS screenList; // Created the list of screen
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
for( screen = screenList.GetFirst(); screen != NULL; screen = screenList.GetNext() )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
// search for a sheet;
|
2011-10-07 14:41:30 +00:00
|
|
|
if( item->Type() != SCH_SHEET_T )
|
2009-07-09 17:02:15 +00:00
|
|
|
continue;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
for( test_item = item->Next(); test_item != NULL; test_item = test_item->Next() )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
if( test_item->Type() != SCH_SHEET_T )
|
2009-07-09 17:02:15 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// 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
|
2011-12-08 15:45:01 +00:00
|
|
|
if( ( (SCH_SHEET*) item )->GetName().CmpNoCase(
|
|
|
|
( ( SCH_SHEET* ) test_item )->GetName() ) == 0 )
|
2009-07-09 17:02:15 +00:00
|
|
|
{
|
2010-06-28 13:11:14 +00:00
|
|
|
if( aCreateMarker )
|
|
|
|
{
|
|
|
|
/* Create a new marker type ERC error*/
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER();
|
2011-12-12 08:37:05 +00:00
|
|
|
marker->SetTimeStamp( GetNewTimeStamp() );
|
2011-10-07 14:41:30 +00:00
|
|
|
marker->SetData( ERCE_DUPLICATE_SHEET_NAME,
|
2011-12-08 15:45:01 +00:00
|
|
|
( (SCH_SHEET*) test_item )->GetPosition(),
|
2011-10-07 14:41:30 +00:00
|
|
|
_( "Duplicate sheet name" ),
|
2011-12-08 15:45:01 +00:00
|
|
|
( (SCH_SHEET*) test_item )->GetPosition() );
|
2015-07-29 12:18:53 +00:00
|
|
|
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
|
2015-07-29 18:06:45 +00:00
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
|
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
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
int TestConflictingBusAliases( bool aCreateMarker )
|
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
wxString msg;
|
|
|
|
wxPoint dummyPos( 0, 0 );
|
|
|
|
int err_count = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
SCH_SCREENS screens;
|
2019-08-07 18:23:59 +00:00
|
|
|
std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
for( auto screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
|
|
|
{
|
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
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
if( aCreateMarker )
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "Bus alias %s has conflicting definitions on"
|
2019-08-12 10:52:49 +00:00
|
|
|
" multiple sheets: %s and %s" ),
|
2019-08-07 18:23:59 +00:00
|
|
|
alias->GetName(),
|
|
|
|
alias->GetParent()->GetFileName(),
|
|
|
|
test->GetParent()->GetFileName() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
SCH_MARKER* marker = new SCH_MARKER();
|
|
|
|
marker->SetData( ERCE_BUS_ALIAS_CONFLICT, dummyPos, msg, dummyPos );
|
|
|
|
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
|
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-08-07 18:23:59 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-19 15:12:36 +00:00
|
|
|
int TestMultiunitFootprints( SCH_SHEET_LIST& aSheetList )
|
|
|
|
{
|
|
|
|
int errors = 0;
|
|
|
|
std::map<wxString, LIB_ID> footprints;
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP refMap;
|
|
|
|
aSheetList.GetMultiUnitComponents( refMap, true );
|
|
|
|
|
|
|
|
for( auto& component : refMap )
|
|
|
|
{
|
|
|
|
auto& refList = component.second;
|
|
|
|
|
|
|
|
if( refList.GetCount() == 0 )
|
|
|
|
{
|
|
|
|
wxFAIL; // it should not happen
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reference footprint
|
|
|
|
wxString fp;
|
|
|
|
wxString unitName;
|
|
|
|
|
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_COMPONENT* cmp = refList.GetItem( i ).GetComp();
|
|
|
|
SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
|
|
|
|
fp = cmp->GetField( FOOTPRINT )->GetText();
|
|
|
|
|
|
|
|
if( !fp.IsEmpty() )
|
|
|
|
{
|
|
|
|
unitName = cmp->GetRef( &sheetPath )
|
|
|
|
+ LIB_PART::SubReference( cmp->GetUnit(), false );
|
|
|
|
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
|
|
|
{
|
|
|
|
SCH_REFERENCE& ref = refList.GetItem( i );
|
|
|
|
SCH_COMPONENT* unit = ref.GetComp();
|
|
|
|
SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
|
2019-04-03 18:35:25 +00:00
|
|
|
const wxString curFp = unit->GetField( FOOTPRINT )->GetText();
|
2018-01-19 15:12:36 +00:00
|
|
|
|
|
|
|
if( !curFp.IsEmpty() && fp != curFp )
|
|
|
|
{
|
|
|
|
wxString curUnitName = unit->GetRef( &sheetPath )
|
|
|
|
+ LIB_PART::SubReference( unit->GetUnit(), false );
|
2019-04-03 18:35:25 +00:00
|
|
|
wxString msg = wxString::Format( _( "Unit %s has '%s' assigned, "
|
|
|
|
"whereas unit %s has '%s' assigned" ),
|
|
|
|
unitName,
|
|
|
|
fp,
|
|
|
|
curUnitName,
|
|
|
|
curFp );
|
|
|
|
wxPoint pos = unit->GetPosition();
|
2018-01-19 15:12:36 +00:00
|
|
|
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER();
|
|
|
|
marker->SetTimeStamp( GetNewTimeStamp() );
|
2019-04-03 18:35:25 +00:00
|
|
|
marker->SetData( ERCE_DIFFERENT_UNIT_FP, pos, msg, pos );
|
2018-01-19 15:12:36 +00:00
|
|
|
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
|
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_WARNING );
|
|
|
|
ref.GetSheetPath().LastScreen()->Append( marker );
|
|
|
|
|
|
|
|
++errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, int aMinConn, int aDiag )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2016-02-28 17:33:29 +00:00
|
|
|
SCH_MARKER* marker = NULL;
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
ELECTRICAL_PINTYPE ii, jj;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2019-04-12 01:22:19 +00:00
|
|
|
if( aDiag == OK || aMinConn < 1 )
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Create new marker for ERC error. */
|
2011-10-07 14:41:30 +00:00
|
|
|
marker = new SCH_MARKER();
|
2011-12-12 08:37:05 +00:00
|
|
|
marker->SetTimeStamp( GetNewTimeStamp() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
|
2015-07-29 18:06:45 +00:00
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_WARNING );
|
2013-09-29 18:24:38 +00:00
|
|
|
screen = aNetItemRef->m_SheetPath.LastScreen();
|
2012-02-26 18:39:39 +00:00
|
|
|
screen->Append( marker );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
wxString msg;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2016-02-19 16:51:23 +00:00
|
|
|
ii = aNetItemRef->m_ElectricalPinType;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2017-11-21 17:39:59 +00:00
|
|
|
wxString cmp_ref( "?" );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
|
2016-02-15 20:17:51 +00:00
|
|
|
cmp_ref = aNetItemRef->GetComponentParent()->GetRef( &aNetItemRef->m_SheetPath );
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2009-07-05 12:09:41 +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
|
|
|
{
|
2009-07-07 17:50:02 +00:00
|
|
|
if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
|
2013-09-30 06:36:40 +00:00
|
|
|
cmp_ref = aNetItemRef->GetComponentParent()->GetRef(
|
2016-02-15 20:17:51 +00:00
|
|
|
&aNetItemRef->m_SheetPath );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ),
|
2017-11-21 17:39:59 +00:00
|
|
|
aNetItemRef->m_PinNum,
|
2016-02-28 17:33:29 +00:00
|
|
|
GetChars( GetText( ii ) ),
|
2015-04-02 18:51:47 +00:00
|
|
|
GetChars( cmp_ref ),
|
2011-10-07 14:41:30 +00:00
|
|
|
aNetItemRef->GetNet() );
|
2019-08-07 18:23:59 +00:00
|
|
|
marker->SetData( ERCE_PIN_NOT_DRIVEN, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( aNetItemTst ) /* Error between 2 pins */
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2016-02-19 16:51:23 +00:00
|
|
|
jj = aNetItemTst->m_ElectricalPinType;
|
2009-07-08 15:42:45 +00:00
|
|
|
int errortype = ERCE_PIN_TO_PIN_WARNING;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-05 12:09:41 +00:00
|
|
|
if( aDiag == ERR )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2015-07-29 18:06:45 +00:00
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
|
2009-07-08 15:42:45 +00:00
|
|
|
errortype = ERCE_PIN_TO_PIN_ERROR;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 17:39:59 +00:00
|
|
|
wxString alt_cmp( "?" );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
if( aNetItemTst->m_Type == NET_PIN && aNetItemTst->m_Link )
|
2016-02-15 20:17:51 +00:00
|
|
|
alt_cmp = aNetItemTst->GetComponentParent()->GetRef( &aNetItemTst->m_SheetPath );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
|
2017-11-21 17:39:59 +00:00
|
|
|
aNetItemRef->m_PinNum,
|
2016-02-28 17:33:29 +00:00
|
|
|
GetChars( GetText( ii ) ),
|
2015-04-02 18:51:47 +00:00
|
|
|
GetChars( cmp_ref ) );
|
2011-10-07 14:41:30 +00:00
|
|
|
marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
|
|
|
|
msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
|
2017-11-21 17:39:59 +00:00
|
|
|
aNetItemTst->m_PinNum,
|
2016-02-28 17:33:29 +00:00
|
|
|
GetChars( GetText( jj ) ),
|
2015-04-02 18:51:47 +00:00
|
|
|
GetChars( alt_cmp ),
|
2009-11-03 13:26:31 +00:00
|
|
|
aNetItemRef->GetNet() );
|
2011-10-07 14:41:30 +00:00
|
|
|
marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
void TestOthersItems( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aNetStart,
|
2015-06-09 10:40:34 +00:00
|
|
|
int* aMinConnexion )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
unsigned netItemTst = aNetStart;
|
2016-02-28 17:33:29 +00:00
|
|
|
ELECTRICAL_PINTYPE jj;
|
2013-09-27 12:30:35 +00:00
|
|
|
int erc = 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
|
|
|
|
2010-10-22 07:52:55 +00:00
|
|
|
if( ref_elect_type == PIN_NC )
|
|
|
|
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
|
|
|
|
2013-09-27 12:30:35 +00:00
|
|
|
if( local_minconn == NOC &&
|
|
|
|
aList->GetItemType( aNetItemRef ) == NET_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
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
if( aList->GetItemType( duplicate ) != NET_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 )
|
2013-09-27 12:30:35 +00:00
|
|
|
Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );
|
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
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
case NET_ITEM_UNSPECIFIED:
|
2007-09-20 21:06:49 +00:00
|
|
|
case NET_SEGMENT:
|
|
|
|
case NET_BUS:
|
2011-10-07 14:41:30 +00:00
|
|
|
case NET_JUNCTION:
|
2007-09-20 21:06:49 +00:00
|
|
|
case NET_LABEL:
|
2008-02-12 21:12:46 +00:00
|
|
|
case NET_HIERLABEL:
|
2007-09-20 21:06:49 +00:00
|
|
|
case NET_BUSLABELMEMBER:
|
2008-02-12 21:12:46 +00:00
|
|
|
case NET_HIERBUSLABELMEMBER:
|
2007-09-20 21:06:49 +00:00
|
|
|
case NET_SHEETBUSLABELMEMBER:
|
|
|
|
case NET_SHEETLABEL:
|
2008-03-13 05:04:59 +00:00
|
|
|
case NET_GLOBLABEL:
|
|
|
|
case NET_GLOBBUSLABELMEMBER:
|
2007-09-20 21:06:49 +00:00
|
|
|
case NET_PINLABEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_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;
|
|
|
|
|
|
|
|
case NET_PIN:
|
2016-02-19 16:51:23 +00:00
|
|
|
jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
|
2012-09-22 11:19:37 +00:00
|
|
|
local_minconn = std::max( MinimalReq[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
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( erc == OK )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
erc = DiagErc[ref_elect_type][jj];
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( erc != OK )
|
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
if( aList->GetConnectionType( netItemTst ) == UNCONNECTED )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
Diagnose( aList->GetItem( aNetItemRef ),
|
|
|
|
aList->GetItem( netItemTst ),
|
|
|
|
0, erc );
|
|
|
|
aList->SetConnectionType( netItemTst, NOCONNECT_SYMBOL_PRESENT );
|
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
|
|
|
}
|
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
int NETLIST_OBJECT_LIST::CountPinsInNet( unsigned aNetStart )
|
2015-06-09 10:40:34 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
2015-12-20 12:40:17 +00:00
|
|
|
int curr_net = GetItemNet( aNetStart );
|
2015-06-09 10:40:34 +00:00
|
|
|
|
|
|
|
/* Test pins connected to NetItemRef */
|
2015-12-20 12:40:17 +00:00
|
|
|
for( unsigned item = aNetStart; item < size(); item++ )
|
2015-06-09 10:40:34 +00:00
|
|
|
{
|
|
|
|
// We examine only a given net. We stop the search if the net changes
|
2015-12-20 12:40:17 +00:00
|
|
|
if( curr_net != GetItemNet( item ) ) // End of net
|
2015-06-09 10:40:34 +00:00
|
|
|
break;
|
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
if( GetItemType( item ) == NET_PIN )
|
2015-06-09 10:40:34 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
bool WriteDiagnosticERC( EDA_UNITS aUnits, const wxString& aFullFileName )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2015-07-29 12:18:53 +00:00
|
|
|
wxFFile file( aFullFileName, wxT( "wt" ) );
|
|
|
|
|
|
|
|
if( !file.IsOpened() )
|
2012-01-22 17:20:22 +00:00
|
|
|
return false;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
wxString msg = wxString::Format( _( "ERC report (%s, Encoding UTF8)\n" ), DateAndTime() );
|
2015-07-29 12:18:53 +00:00
|
|
|
int err_count = 0;
|
|
|
|
int warn_count = 0;
|
|
|
|
int total_count = 0;
|
2016-03-06 21:22:01 +00:00
|
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2016-03-06 21:22:01 +00:00
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2015-07-29 12:18:53 +00:00
|
|
|
msg << wxString::Format( _( "\n***** Sheet %s\n" ),
|
2016-03-06 21:22:01 +00:00
|
|
|
GetChars( sheetList[i].PathHumanReadable() ) );
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2016-03-06 21:22:01 +00:00
|
|
|
for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
if( item->Type() != SCH_MARKER_T )
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
SCH_MARKER* marker = (SCH_MARKER*) item;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
|
2011-10-07 14:41:30 +00:00
|
|
|
continue;
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
total_count++;
|
|
|
|
|
2015-07-29 18:06:45 +00:00
|
|
|
if( marker->GetErrorLevel() == MARKER_BASE::MARKER_SEVERITY_ERROR )
|
2015-07-29 12:18:53 +00:00
|
|
|
err_count++;
|
|
|
|
|
2015-07-29 18:06:45 +00:00
|
|
|
if( marker->GetErrorLevel() == MARKER_BASE::MARKER_SEVERITY_WARNING )
|
2015-07-29 12:18:53 +00:00
|
|
|
warn_count++;
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2018-06-15 04:49:50 +00:00
|
|
|
msg << marker->GetReporter().ShowReport( aUnits );
|
2008-03-13 05:04:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
|
|
|
|
total_count, err_count, warn_count );
|
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
// Currently: write report using UTF8 (as usual in Kicad).
|
2015-07-29 12:18:53 +00:00
|
|
|
// TODO: see if we can use the current encoding page (mainly for Windows users),
|
|
|
|
// Or other format (HTML?)
|
|
|
|
file.Write( msg );
|
|
|
|
|
|
|
|
// wxFFile dtor will close the file.
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
return true;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-03-13 05:04:59 +00:00
|
|
|
|
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
void NETLIST_OBJECT_LIST::TestforNonOrphanLabel( unsigned aNetItemRef, unsigned aStartNet )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2013-09-27 12:30:35 +00:00
|
|
|
unsigned netItemTst = aStartNet;
|
2009-11-03 13:26:31 +00:00
|
|
|
int erc = 1;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2015-07-29 12:18:53 +00:00
|
|
|
// Review the list of labels 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( netItemTst == aNetItemRef )
|
2007-09-20 21:06:49 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Is always in the same net? */
|
2015-12-20 12:40:17 +00:00
|
|
|
if( ( netItemTst == size() )
|
|
|
|
|| ( GetItemNet( aNetItemRef ) != GetItemNet( netItemTst ) ) )
|
2008-03-13 05:04:59 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* End Netcode found. */
|
2008-03-13 05:04:59 +00:00
|
|
|
if( erc )
|
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Glabel or SheetLabel orphaned. */
|
2015-12-20 12:40:17 +00:00
|
|
|
Diagnose( GetItem( aNetItemRef ), NULL, -1, WAR );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2015-12-20 12:40:17 +00:00
|
|
|
if( GetItem( aNetItemRef )->IsLabelConnected( GetItem( netItemTst ) ) )
|
2008-03-13 05:04:59 +00:00
|
|
|
erc = 0;
|
|
|
|
|
|
|
|
//same thing, different order.
|
2015-12-20 12:40:17 +00:00
|
|
|
if( GetItem( netItemTst )->IsLabelConnected( GetItem( aNetItemRef ) ) )
|
2008-03-13 05:04:59 +00:00
|
|
|
erc = 0;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
wxString str1 = lab1->m_SheetPath.Path() + lab1->m_Label;
|
|
|
|
wxString str2 = lab2->m_SheetPath.Path() + lab2->m_Label;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return lab1->m_SheetPath.Path().Cmp( lab2->m_SheetPath.Path() ) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 ) )
|
|
|
|
{
|
|
|
|
case NET_LABEL:
|
|
|
|
case NET_BUSLABELMEMBER:
|
|
|
|
case NET_PINLABEL:
|
|
|
|
case NET_GLOBBUSLABELMEMBER:
|
|
|
|
case NET_HIERLABEL:
|
|
|
|
case NET_HIERBUSLABELMEMBER:
|
|
|
|
case NET_GLOBLABEL:
|
|
|
|
// add this label in lists
|
|
|
|
uniqueLabelList.insert( GetItem( netItem ) );
|
|
|
|
fullLabelList.push_back( GetItem( netItem ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_SHEETLABEL:
|
|
|
|
case NET_SHEETBUSLABELMEMBER:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build global labels and compare
|
|
|
|
std::set<NETLIST_OBJECT*, compare_label_names> loc_labelList;
|
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
for( auto it = uniqueLabelList.begin(); it != uniqueLabelList.end(); ++it )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
if( (*it)->IsLabelGlobal() )
|
|
|
|
loc_labelList.insert( *it );
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
for( auto it = uniqueLabelList.begin(); it != uniqueLabelList.end(); ++it )
|
2015-12-20 12:40:17 +00:00
|
|
|
pathsList.insert( *it );
|
|
|
|
|
|
|
|
// Examine each label inside a sheet path:
|
2019-08-06 03:03:29 +00:00
|
|
|
for( auto it = pathsList.begin(); it != pathsList.end(); ++it )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
|
|
|
loc_labelList.clear();
|
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
auto it_uniq = uniqueLabelList.begin();
|
2015-12-20 12:40:17 +00:00
|
|
|
|
2019-08-06 03:03:29 +00:00
|
|
|
for( ; it_uniq != uniqueLabelList.end(); ++it_uniq )
|
2015-12-20 12:40:17 +00:00
|
|
|
{
|
2019-08-06 03:03:29 +00:00
|
|
|
if( ( *it )->m_SheetPath.Path() == ( *it_uniq )->m_SheetPath.Path() )
|
|
|
|
loc_labelList.insert( *it_uniq );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
for( auto 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
|
|
|
|
{
|
2019-08-07 18:23:59 +00:00
|
|
|
for( auto 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function: creates a marker for similar labels ERC warning
|
|
|
|
static void SimilarLabelsDiagnose( NETLIST_OBJECT* aItemA, NETLIST_OBJECT* aItemB )
|
|
|
|
{
|
|
|
|
// Create new marker for ERC.
|
|
|
|
SCH_MARKER* marker = new SCH_MARKER();
|
|
|
|
|
|
|
|
marker->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
|
|
|
|
marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_WARNING );
|
|
|
|
SCH_SCREEN* screen = aItemA->m_SheetPath.LastScreen();
|
|
|
|
screen->Append( marker );
|
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
wxString fmt = aItemA->IsLabelGlobal() ? _( "Global label '%s' (sheet '%s') looks like:" ) :
|
|
|
|
_( "Local label '%s' (sheet '%s') looks like:" );
|
2015-12-20 12:40:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2019-08-07 18:23:59 +00:00
|
|
|
msg.Printf( fmt, aItemA->m_Label, aItemA->m_SheetPath.PathHumanReadable() );
|
2015-12-20 12:40:17 +00:00
|
|
|
marker->SetData( aItemA->IsLabelGlobal() && aItemB->IsLabelGlobal() ?
|
|
|
|
ERCE_SIMILAR_GLBL_LABELS : ERCE_SIMILAR_LABELS,
|
|
|
|
aItemA->m_Start, msg, aItemA->m_Start );
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
fmt = aItemB->IsLabelGlobal() ? _( "Global label \"%s\" (sheet \"%s\")" ) :
|
|
|
|
_( "Local label \"%s\" (sheet \"%s\")" );
|
2019-08-07 18:23:59 +00:00
|
|
|
msg.Printf( fmt, aItemB->m_Label, aItemB->m_SheetPath.PathHumanReadable() );
|
2015-12-20 12:40:17 +00:00
|
|
|
marker->SetAuxiliaryData( msg, aItemB->m_Start );
|
|
|
|
}
|