Sort nets in netlist by name; generate ordered net codes
This commit is contained in:
parent
ef00fa6008
commit
41725e6b07
|
@ -954,7 +954,8 @@ void CONNECTION_GRAPH::buildConnectionGraph()
|
|||
subgraph->AddItem( pin );
|
||||
subgraph->ResolveDrivers();
|
||||
|
||||
m_net_code_to_subgraphs_map[ code ].push_back( subgraph );
|
||||
auto key = std::make_pair( subgraph->GetNetName(), code );
|
||||
m_net_code_to_subgraphs_map[ key ].push_back( subgraph );
|
||||
m_subgraphs.push_back( subgraph );
|
||||
m_driver_subgraphs.push_back( subgraph );
|
||||
|
||||
|
@ -1409,8 +1410,9 @@ void CONNECTION_GRAPH::buildConnectionGraph()
|
|||
if( subgraph->m_driver_connection->IsBus() )
|
||||
continue;
|
||||
|
||||
int code = subgraph->m_driver_connection->NetCode();
|
||||
m_net_code_to_subgraphs_map[ code ].push_back( subgraph );
|
||||
auto key = std::make_pair( subgraph->GetNetName(),
|
||||
subgraph->m_driver_connection->NetCode() );
|
||||
m_net_code_to_subgraphs_map[ key ].push_back( subgraph );
|
||||
}
|
||||
|
||||
// Clean up and deallocate stale subgraphs
|
||||
|
|
|
@ -198,6 +198,11 @@ public:
|
|||
CONNECTION_SUBGRAPH* m_hier_parent;
|
||||
};
|
||||
|
||||
/// Associates a net code with the final name of a net
|
||||
typedef std::pair<wxString, int> NET_NAME_CODE;
|
||||
|
||||
/// Associates a NET_CODE_NAME with all the subgraphs in that net
|
||||
typedef std::map<NET_NAME_CODE, std::vector<CONNECTION_SUBGRAPH*>> NET_MAP;
|
||||
|
||||
/**
|
||||
* Calculates the connectivity of a schematic and generates netlists
|
||||
|
@ -255,12 +260,11 @@ public:
|
|||
*/
|
||||
int RunERC( const ERC_SETTINGS& aSettings, bool aCreateMarkers = true );
|
||||
|
||||
const NET_MAP& GetNetMap() const { return m_net_code_to_subgraphs_map; }
|
||||
|
||||
// TODO(JE) Remove this when pressure valve is removed
|
||||
static bool m_allowRealTime;
|
||||
|
||||
// TODO(JE) firm up API and move to private
|
||||
std::map<int, std::vector<CONNECTION_SUBGRAPH*> > m_net_code_to_subgraphs_map;
|
||||
|
||||
private:
|
||||
|
||||
std::unordered_set<SCH_ITEM*> m_items;
|
||||
|
@ -291,6 +295,8 @@ private:
|
|||
std::unordered_map<wxString,
|
||||
std::vector<CONNECTION_SUBGRAPH*>> m_net_name_to_subgraphs_map;
|
||||
|
||||
NET_MAP m_net_code_to_subgraphs_map;
|
||||
|
||||
int m_last_net_code;
|
||||
|
||||
int m_last_bus_code;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2013-2017 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -503,26 +503,45 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( bool aUseGraph )
|
|||
if( aUseGraph )
|
||||
{
|
||||
wxASSERT( m_graph );
|
||||
int code = 0;
|
||||
|
||||
for( const auto& it : m_graph->m_net_code_to_subgraphs_map )
|
||||
for( const auto& it : m_graph->GetNetMap() )
|
||||
{
|
||||
bool added = false;
|
||||
|
||||
auto code = it.first;
|
||||
wxString net_name = it.first.first;
|
||||
auto subgraphs = it.second;
|
||||
auto net_name = subgraphs[0]->GetNetName();
|
||||
|
||||
// Code starts at 1
|
||||
code++;
|
||||
|
||||
XNODE* xnode;
|
||||
std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items;
|
||||
|
||||
for( auto subgraph : subgraphs )
|
||||
{
|
||||
auto sheet = subgraph->m_sheet;
|
||||
|
||||
for( auto item : subgraph->m_items )
|
||||
{
|
||||
if( item->Type() == SCH_PIN_T )
|
||||
sorted_items.emplace_back(
|
||||
std::make_pair( static_cast<SCH_PIN*>( item ), sheet ) );
|
||||
}
|
||||
|
||||
// Netlist ordering: Net name, then ref des, then pin name
|
||||
std::sort( sorted_items.begin(), sorted_items.end(), []( auto a, auto b ) {
|
||||
auto ref_a = a.first->GetParentComponent()->GetRef( &a.second );
|
||||
auto ref_b = b.first->GetParentComponent()->GetRef( &b.second );
|
||||
|
||||
if( ref_a == ref_b )
|
||||
return a.first->GetNumber() < b.first->GetNumber();
|
||||
|
||||
return ref_a < ref_b;
|
||||
} );
|
||||
|
||||
for( const auto& pair : sorted_items )
|
||||
{
|
||||
auto pin = static_cast<SCH_PIN*>( item );
|
||||
SCH_PIN* pin = pair.first;
|
||||
SCH_SHEET_PATH sheet = pair.second;
|
||||
|
||||
auto refText = pin->GetParentComponent()->GetRef( &sheet );
|
||||
const auto& pinText = pin->GetNumber();
|
||||
|
@ -552,8 +571,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( bool aUseGraph )
|
|||
|
||||
if( !pinName.IsEmpty() )
|
||||
xnode->AddAttribute( "pinfunction", pinName );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,11 +319,16 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const
|
|||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), UnescapeString( Name() ), BROWN ) );
|
||||
|
||||
// NOTE(JE) Disabling this for now, because net codes are generated in the netlist exporter
|
||||
// in order to avoid sort costs. It may make sense to just tear out net codes from the
|
||||
// CONNECTION_GRAPH entirely in the future, as they are mostly only useful for netlist exports.
|
||||
#if 0
|
||||
if( !IsBus() )
|
||||
{
|
||||
msg.Printf( "%d", m_net_code );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), msg, BROWN ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( auto alias = g_ConnectionGraph->GetBusAlias( m_name ) )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue