Now that we allow open-text netclass references we need to ERC check them.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/12442
This commit is contained in:
parent
98d59f99ab
commit
23063fa976
|
@ -35,6 +35,8 @@
|
|||
#include <string_utils.h>
|
||||
#include <lib_pin.h>
|
||||
#include <project_sch.h>
|
||||
#include <project/project_file.h>
|
||||
#include <project/net_settings.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <sch_marker.h>
|
||||
#include <sch_reference_list.h>
|
||||
|
@ -554,6 +556,55 @@ int ERC_TESTER::TestMissingUnits()
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int ERC_TESTER::TestNoConnectPins()
|
||||
{
|
||||
int err_count = 0;
|
||||
|
@ -1202,5 +1253,13 @@ void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aE
|
|||
TestOffGridEndpoints();
|
||||
}
|
||||
|
||||
if( settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
|
||||
{
|
||||
if( aProgressReporter )
|
||||
aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
|
||||
|
||||
TestMissingNetclasses();
|
||||
}
|
||||
|
||||
m_schematic->ResolveERCExclusionsPostUpdate();
|
||||
}
|
||||
|
|
|
@ -51,19 +51,6 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform ERC testing for electrical conflicts between \a NetItemRef and other items
|
||||
* (mainly pin) on the same net.
|
||||
*
|
||||
* @param aList = a reference to the list of connected objects
|
||||
* @param aNetItemRef = index in list of the current object
|
||||
* @param aNetStart = index in list of net objects of the first item
|
||||
* @param aMinConnexion = a pointer to a variable to store the minimal connection
|
||||
* found( NOD, DRV, NPI, NET_NC)
|
||||
*/
|
||||
void TestOthersItems( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aNetStart,
|
||||
int* aMinConnexion );
|
||||
|
||||
/**
|
||||
* Inside a given sheet, one cannot have sheets with duplicate names (file
|
||||
* names can be duplicated).
|
||||
|
@ -142,6 +129,12 @@ public:
|
|||
*/
|
||||
int TestMissingUnits();
|
||||
|
||||
/**
|
||||
* Tests for netclasses that are referenced but not defined.
|
||||
* @return
|
||||
*/
|
||||
int TestMissingNetclasses();
|
||||
|
||||
void RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aEditFrame,
|
||||
PROGRESS_REPORTER* aProgressReporter );
|
||||
|
||||
|
|
|
@ -135,6 +135,10 @@ ERC_ITEM ERC_ITEM::unresolvedVariable( ERCE_UNRESOLVED_VARIABLE,
|
|||
_( "Unresolved text variable" ),
|
||||
wxT( "unresolved_variable" ) );
|
||||
|
||||
ERC_ITEM ERC_ITEM::undefinedNetclass( ERCE_UNDEFINED_NETCLASS,
|
||||
_( "Undefined netclass" ),
|
||||
wxT( "undefined_netclass" ) );
|
||||
|
||||
ERC_ITEM ERC_ITEM::simulationModelIssues( ERCE_SIMULATION_MODEL,
|
||||
_( "SPICE model issue" ),
|
||||
wxT( "simulation_model_issue" ) );
|
||||
|
@ -256,6 +260,7 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
|
|||
case ERCE_NETCLASS_CONFLICT: return std::make_shared<ERC_ITEM>( netclassConflict );
|
||||
case ERCE_GLOBLABEL: return std::make_shared<ERC_ITEM>( globalLabelDangling );
|
||||
case ERCE_UNRESOLVED_VARIABLE: return std::make_shared<ERC_ITEM>( unresolvedVariable );
|
||||
case ERCE_UNDEFINED_NETCLASS: return std::make_shared<ERC_ITEM>( undefinedNetclass );
|
||||
case ERCE_SIMULATION_MODEL: return std::make_shared<ERC_ITEM>( simulationModelIssues );
|
||||
case ERCE_WIRE_DANGLING: return std::make_shared<ERC_ITEM>( wireDangling );
|
||||
case ERCE_LIB_SYMBOL_ISSUES: return std::make_shared<ERC_ITEM>( libSymbolIssues );
|
||||
|
|
|
@ -206,6 +206,7 @@ private:
|
|||
static ERC_ITEM busToBusConflict;
|
||||
static ERC_ITEM busToNetConflict;
|
||||
static ERC_ITEM unresolvedVariable;
|
||||
static ERC_ITEM undefinedNetclass;
|
||||
static ERC_ITEM simulationModelIssues;
|
||||
static ERC_ITEM wireDangling;
|
||||
static ERC_ITEM libSymbolIssues;
|
||||
|
|
|
@ -68,6 +68,7 @@ enum ERCE_T
|
|||
ERCE_NETCLASS_CONFLICT, ///< Multiple labels assign different netclasses to same net.
|
||||
ERCE_GLOBLABEL, ///< A global label is unique.
|
||||
ERCE_UNRESOLVED_VARIABLE, ///< A text variable could not be resolved.
|
||||
ERCE_UNDEFINED_NETCLASS, ///< A netclass was referenced by not defined.
|
||||
ERCE_SIMULATION_MODEL, ///< An error was found in the simulation model.
|
||||
ERCE_WIRE_DANGLING, ///< Some wires are not connected to anything else.
|
||||
ERCE_LIB_SYMBOL_ISSUES, ///< Library symbol changed from current symbol in schematic or
|
||||
|
|
Loading…
Reference in New Issue