Sort PCAD layers

Better fix for 11750.  Instead of figeting with layer values, we sort
our map based on the layer numbers in the PCAD file.  F_Cu is always
layer 1 and B_Cu is always layer 2.

Fixes https://gitlab.com/kicad/code/kicad/issues/11750
This commit is contained in:
Seth Hillbrand 2022-06-09 11:08:49 -07:00
parent b712c2c0da
commit ac0f95683f
2 changed files with 20 additions and 20 deletions

View File

@ -102,9 +102,6 @@ PCB::PCB( BOARD* aBoard ) :
m_LayersMap[3].KiCadLayer = Eco2_User;
m_LayersMap[6].KiCadLayer = F_SilkS;
m_LayersMap[7].KiCadLayer = B_SilkS;
m_mappedBottom = false;
m_mappedTop = false;
}
@ -459,7 +456,7 @@ int PCB::FindLayer( const wxString& aLayerName ) const
{
for( int i = 0; i < (int) m_layersStackup.size(); ++i )
{
if( m_layersStackup[i] == aLayerName )
if( m_layersStackup[i].first == aLayerName )
return i;
}
@ -495,12 +492,10 @@ void PCB::MapLayer( XNODE* aNode )
else if( lName == wxT( "TOP" ) )
{
KiCadLayer = F_Cu;
m_mappedTop = true;
}
else if( lName == wxT( "BOTTOM" ) )
{
KiCadLayer = B_Cu;
m_mappedBottom = true;
}
else if( lName == wxT( "BOT MASK" ) )
{
@ -529,14 +524,6 @@ void PCB::MapLayer( XNODE* aNode )
if( layernum == -1 )
KiCadLayer = Dwgs_User; // default
else
// Account for ordering (leave room for F.Cu and B.Cu
// TODO: Add layer mapping widget
if( !m_mappedTop )
++layernum;
if( m_mappedBottom )
--layernum;
KiCadLayer = ToLAYER_ID( layernum );
}
@ -750,15 +737,20 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
{
if( FindNode( aNode, wxT( "layerType" ) ) )
{
long num = -1;
if( FindNode( aNode, wxT( "layerNum" ) ) )
FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim(
false );
if( layerType.IsSameAs( wxT( "Signal" ), false )
|| layerType.IsSameAs( wxT( "Plane" ), false ) )
if( num > 0 && ( layerType.IsSameAs( wxT( "Signal" ), false )
|| layerType.IsSameAs( wxT( "Plane" ), false ) ) )
{
aNode->GetAttribute( wxT( "Name" ), &layerName );
layerName = layerName.MakeUpper();
m_layersStackup.emplace_back( layerName );
m_layersStackup.emplace_back( layerName, num );
if( m_layersStackup.size() > 32 )
THROW_IO_ERROR( _( "KiCad only supports 32 signal layers." ) );
@ -768,6 +760,16 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
aNode = aNode->GetNext();
}
// Ensure that the layers are properly mapped to their order with the bottom
// copper (layer 2 in PCAD) at the end
std::sort( m_layersStackup.begin(), m_layersStackup.end(),
[&]( const std::pair<wxString, long>& a, const std::pair<wxString, long>& b ) {
long lhs = a.second == 2 ? std::numeric_limits<long>::max() : a.second;
long rhs = b.second == 2 ? std::numeric_limits<long>::max() : b.second;
return lhs < rhs;
} );
}
// Layers mapping

View File

@ -83,9 +83,7 @@ private:
double GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const;
void GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConversion );
std::vector<wxString> m_layersStackup;
bool m_mappedTop;
bool m_mappedBottom;
std::vector<std::pair<wxString, long>> m_layersStackup;
};
} // namespace PCAD2KICAD