Remove Setup Dialog assignment of netclasses to buses.

Also removes the message bar display of assigned netclass for
buses and bus-to-bus entries.

Also fixes a bug where assigning a netclass via the canvas only
looked at the first level of bus members (and not any nested
members).

Also fixes a bug where the bus name validator tried to validate
a vector bus first -- which doesn't work as a vector bus may be
nested in a group bus.

Also fixes a bug where we were failing to check for illegal
chars in bus definitions which otherwise passed the bus parsers.

See additional comments in the bug report.

Fixes https://gitlab.com/kicad/code/kicad/issues/9160
This commit is contained in:
Jeff Young 2021-09-17 21:25:05 +01:00
parent d32ca5b287
commit 5c07441e24
11 changed files with 69 additions and 72 deletions

View File

@ -31,7 +31,8 @@
// const int netSettingsSchemaVersion = 0;
const int netSettingsSchemaVersion = 1; // new overbar syntax
// const int netSettingsSchemaVersion = 1; // new overbar syntax
const int netSettingsSchemaVersion = 2; // exclude buses from netclass members
static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey,
@ -193,7 +194,26 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
if( entry.contains( "nets" ) && entry["nets"].is_array() )
{
for( const auto& net : entry["nets"].items() )
nc->Add( net.value().get<wxString>() );
{
wxString netname = net.value().get<wxString>();
if( m_schemaVersion < 2 )
{
// Strip out buses from older 5.99 implementations. They were
// a world of hurt, never fully functional, and are functionally
// replaced by assigning a netclass to a bus on the canvas.
wxString unescaped = UnescapeString( netname );
wxString prefix;
std::vector<wxString> members;
if( ParseBusVector( unescaped, &prefix, &members ) )
continue;
else if( ParseBusGroup( unescaped, &prefix, &members ) )
continue;
}
nc->Add( netname );
}
}
if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
@ -211,8 +231,6 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
for( const wxString& net : *nc )
m_NetClassAssignments[ net ] = nc->GetName();
}
ResolveNetClassAssignments();
},
{} ) );
@ -519,44 +537,13 @@ bool NET_SETTINGS::ParseBusGroup( const wxString& aGroup, wxString* aName,
}
void NET_SETTINGS::ResolveNetClassAssignments( bool aRebuildFromScratch )
void NET_SETTINGS::RebuildNetClassAssignments()
{
std::map<wxString, wxString> baseList;
if( aRebuildFromScratch )
{
for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses )
{
for( const wxString& net : *netclass.second )
baseList[ net ] = netclass.second->GetName();
}
}
else
{
baseList = m_NetClassAssignments;
}
m_NetClassAssignments.clear();
for( const auto& ii : baseList )
for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses )
{
m_NetClassAssignments[ ii.first ] = ii.second;
wxString unescaped = UnescapeString( ii.first );
wxString prefix;
std::vector<wxString> members;
if( ParseBusVector( unescaped, &prefix, &members ) )
{
prefix = wxEmptyString;
}
else if( ParseBusGroup( unescaped, &prefix, &members ) )
{
if( !prefix.IsEmpty() )
prefix += wxT( "." );
}
for( wxString& member : members )
m_NetClassAssignments[ prefix + member ] = ii.second;
for( const wxString& net : *netclass.second )
m_NetClassAssignments[ net ] = netclass.second->GetName();
}
}

View File

@ -658,8 +658,6 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
if( netclass )
netclass->Add( ii.first );
}
netSettings.ResolveNetClassAssignments();
}
break;

View File

@ -115,7 +115,7 @@ void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
if( dlg.ShowQuasiModal() == wxID_OK )
{
Prj().GetProjectFile().NetSettings().ResolveNetClassAssignments( true );
Prj().GetProjectFile().NetSettings().RebuildNetClassAssignments();
SaveProjectSettings();

View File

@ -501,14 +501,17 @@ void SCH_BUS_ENTRY_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEM
{
conn->AppendInfoToMsgPanel( aList );
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
wxString netname = conn->Name();
wxString netclassName = netSettings.m_NetClasses.GetDefaultPtr()->GetName();
if( !conn->IsBus() )
{
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
wxString netname = conn->Name();
wxString netclassName = netSettings.m_NetClasses.GetDefaultPtr()->GetName();
if( netSettings.m_NetClassAssignments.count( netname ) )
netclassName = netSettings.m_NetClassAssignments[ netname ];
if( netSettings.m_NetClassAssignments.count( netname ) )
netclassName = netSettings.m_NetClassAssignments[ netname ];
aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName ) );
aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName ) );
}
}
}

View File

@ -898,14 +898,17 @@ void SCH_LINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
{
conn->AppendInfoToMsgPanel( aList );
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
wxString netname = conn->Name();
wxString netclassName = netSettings.m_NetClasses.GetDefaultPtr()->GetName();
if( !conn->IsBus() )
{
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
wxString netname = conn->Name();
wxString netclassName = netSettings.m_NetClasses.GetDefaultPtr()->GetName();
if( netSettings.m_NetClassAssignments.count( netname ) )
netclassName = netSettings.m_NetClassAssignments[ netname ];
if( netSettings.m_NetClassAssignments.count( netname ) )
netclassName = netSettings.m_NetClassAssignments[ netname ];
aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName ) );
aList.push_back( MSG_PANEL_ITEM( _( "Assigned Netclass" ), netclassName ) );
}
}
}

View File

@ -791,14 +791,14 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
msg = MessageTextFromValue( aFrame->GetUserUnits(), GetTextWidth() );
aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg ) );
SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
SCH_CONNECTION* conn = dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) ? Connection() : nullptr;
if( frame )
if( conn )
{
if( SCH_CONNECTION* conn = Connection() )
{
conn->AppendInfoToMsgPanel( aList );
conn->AppendInfoToMsgPanel( aList );
if( !conn->IsBus() )
{
NET_SETTINGS& netSettings = Schematic()->Prj().GetProjectFile().NetSettings();
const wxString& netname = conn->Name( true );

View File

@ -241,8 +241,11 @@ std::vector<wxString> SCHEMATIC::GetNetClassAssignmentCandidates()
{
CONNECTION_SUBGRAPH* subgraph = pair.second[0];
if( subgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN )
if( !subgraph->m_driver_connection->IsBus()
&& subgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN )
{
names.emplace_back( pair.first.first );
}
}
return names;

View File

@ -992,9 +992,17 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
if( conn->IsBus() )
{
for( const std::shared_ptr<SCH_CONNECTION>& member : conn->Members() )
netNames.Add( member->Name() );
netNames.Add( conn->Name() );
{
if( member->IsBus() )
{
for( const std::shared_ptr<SCH_CONNECTION>& subMember : member->Members() )
netNames.Add( subMember->Name() );
}
else
{
netNames.Add( member->Name() );
}
}
}
else
{
@ -1046,7 +1054,6 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
newNetclass->Add( netName );
netSettings.m_NetClassAssignments[netName] = netclassName;
netSettings.ResolveNetClassAssignments();
}
}
}

View File

@ -79,13 +79,9 @@ public:
std::vector<wxString>* aMemberList );
/**
* Explode the list of netclass assignments to include atomic members of composite labels
* (buses).
*
* @param aRebuildFromScratch indicates the assignments should be rebuilt from the netclass
* membership lists before resolving.
* Rebuild netclass assignments from the netclass membership lists.
*/
void ResolveNetClassAssignments( bool aRebuildFromScratch = false );
void RebuildNetClassAssignments();
private:
bool migrateSchema0to1();

View File

@ -753,7 +753,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
{
Prj().SetReadOnly( false );
Prj().GetProjectFile().NetSettings().ResolveNetClassAssignments( true );
Prj().GetProjectFile().NetSettings().RebuildNetClassAssignments();
// Before we had a copper edge clearance setting, the edge line widths could be used
// as a kludge to control them. So if there's no setting then infer it from the

View File

@ -904,7 +904,7 @@ void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
if( dlg.ShowQuasiModal() == wxID_OK )
{
Prj().GetProjectFile().NetSettings().ResolveNetClassAssignments( true );
Prj().GetProjectFile().NetSettings().RebuildNetClassAssignments();
GetBoard()->SynchronizeNetsAndNetClasses();
SaveProjectSettings();