Make PCAD import case-insensitive

According to the PCAD specification, all tags are case insensitive.
Most exporters honor the defaults but there is always an outlier or two

Fixes https://gitlab.com/kicad/code/kicad/issues/11652
This commit is contained in:
Seth Hillbrand 2022-05-27 10:08:27 -07:00
parent e9e1878d96
commit 35b79c2ec9
4 changed files with 47 additions and 55 deletions

View File

@ -304,21 +304,21 @@ TTEXT_JUSTIFY GetJustifyIdentificator( const wxString& aJustify )
{ {
TTEXT_JUSTIFY id; TTEXT_JUSTIFY id;
if( aJustify == wxT( "LowerCenter" ) ) if( aJustify.IsSameAs( wxT( "LowerCenter" ), false ) )
id = LowerCenter; id = LowerCenter;
else if( aJustify == wxT( "LowerRight" ) ) else if( aJustify.IsSameAs( wxT( "LowerRight" ), false ) )
id = LowerRight; id = LowerRight;
else if( aJustify == wxT( "UpperLeft" ) ) else if( aJustify.IsSameAs( wxT( "UpperLeft" ), false ) )
id = UpperLeft; id = UpperLeft;
else if( aJustify == wxT( "UpperCenter" ) ) else if( aJustify.IsSameAs( wxT( "UpperCenter" ), false ) )
id = UpperCenter; id = UpperCenter;
else if( aJustify == wxT( "UpperRight" ) ) else if( aJustify.IsSameAs( wxT( "UpperRight" ), false ) )
id = UpperRight; id = UpperRight;
else if( aJustify == wxT( "Left" ) ) else if( aJustify.IsSameAs( wxT( "Left" ), false ) )
id = Left; id = Left;
else if( aJustify == wxT( "Center" ) ) else if( aJustify.IsSameAs( wxT( "Center" ), false ) )
id = Center; id = Center;
else if( aJustify == wxT( "Right" ) ) else if( aJustify.IsSameAs( wxT( "Right" ), false ) )
id = Right; id = Right;
else else
id = LowerLeft; id = LowerLeft;
@ -354,7 +354,7 @@ void SetTextParameters( XNODE* aNode, TTEXTVALUE* aTextValue,
str = FindNodeGetContent( aNode, wxT( "isVisible" ) ); str = FindNodeGetContent( aNode, wxT( "isVisible" ) );
if( str == wxT( "True" ) ) if( str.IsSameAs( wxT( "True" ), false ) )
aTextValue->textIsVisible = 1; aTextValue->textIsVisible = 1;
else else
aTextValue->textIsVisible = 0; aTextValue->textIsVisible = 0;
@ -364,7 +364,7 @@ void SetTextParameters( XNODE* aNode, TTEXTVALUE* aTextValue,
str = FindNodeGetContent( aNode, wxT( "isFlipped" ) ); str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
if( str == wxT( "True" ) ) if( str.IsSameAs( wxT( "True" ), false ) )
aTextValue->mirror = 1; aTextValue->mirror = 1;
else else
aTextValue->mirror = 0; aTextValue->mirror = 0;
@ -408,13 +408,13 @@ void SetFontProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aDef
wxString fontType; wxString fontType;
propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) ); propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) );
aTextValue->isTrueType = ( propValue == wxT( "True" ) ); aTextValue->isTrueType = ( propValue.IsSameAs( wxT( "True" ), false ) );
aNode = FindNode( aNode, wxT( "font" ) ); aNode = FindNode( aNode, wxT( "font" ) );
fontType = FindNodeGetContent( aNode, wxT( "fontType" ) ); fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
if( ( aTextValue->isTrueType && ( fontType != wxT( "TrueType" ) ) ) || if( ( aTextValue->isTrueType && !fontType.IsSameAs( wxT( "TrueType" ), false ) ) ||
( !aTextValue->isTrueType && ( fontType != wxT( "Stroke" ) ) ) ) ( !aTextValue->isTrueType && !fontType.IsSameAs( wxT( "Stroke" ), false ) ) )
aNode = aNode->GetNext(); aNode = aNode->GetNext();
if( aNode ) if( aNode )
@ -422,7 +422,7 @@ void SetFontProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aDef
if( aTextValue->isTrueType ) if( aTextValue->isTrueType )
{ {
propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) ); propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
aTextValue->isItalic = ( propValue == wxT( "True" ) ); aTextValue->isItalic = propValue.IsSameAs( wxT( "True" ), false );
propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) ); propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) );
@ -562,7 +562,7 @@ XNODE* FindNode( XNODE* aChild, const wxString& aTag )
while( aChild ) while( aChild )
{ {
if( aChild->GetName() == aTag ) if( aChild->GetName().IsSameAs( aTag, false ) )
return aChild; return aChild;
aChild = aChild->GetNext(); aChild = aChild->GetNext();

View File

@ -147,7 +147,7 @@ XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const
while( lNode ) while( lNode )
{ {
if( lNode->GetName() == wxT( "compDef" ) ) if( lNode->GetName().IsSameAs( wxT( "compDef" ), false ) )
{ {
lNode->GetAttribute( wxT( "Name" ), &propValue ); lNode->GetAttribute( wxT( "Name" ), &propValue );
@ -189,7 +189,7 @@ void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString&
while( tNode ) while( tNode )
{ {
if( tNode->GetName() == wxT( "patternGraphicsRef" ) ) if( tNode->GetName().IsSameAs( wxT( "patternGraphicsRef" ), false ) )
{ {
if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) ) if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
{ {
@ -251,7 +251,7 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString&
{ {
fp = nullptr; fp = nullptr;
if( lNode->GetName() == wxT( "pattern" ) ) if( lNode->GetName().IsSameAs( wxT( "pattern" ), false ) )
{ {
FindNode( lNode, wxT( "patternRef" ) )->GetAttribute( wxT( "Name" ), FindNode( lNode, wxT( "patternRef" ) )->GetAttribute( wxT( "Name" ),
&cn ); &cn );
@ -308,7 +308,7 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString&
str = FindNodeGetContent( lNode, wxT( "isFlipped" ) ); str = FindNodeGetContent( lNode, wxT( "isFlipped" ) );
if( str == wxT( "True" ) ) if( str.IsSameAs( wxT( "True" ), false ) )
fp->m_Mirror = 1; fp->m_Mirror = 1;
tNode = aNode; tNode = aNode;
@ -369,7 +369,7 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString&
while( mNode ) while( mNode )
{ {
if( mNode->GetName() == wxT( "padNum" ) ) if( mNode->GetName().IsSameAs( wxT( "padNum" ), false ) )
{ {
str = mNode->GetNodeContent(); str = mNode->GetNodeContent();
mNode = mNode->GetNext(); mNode = mNode->GetNext();
@ -397,19 +397,19 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString&
m_PcbComponents.Add( fp ); m_PcbComponents.Add( fp );
} }
} }
else if( lNode->GetName() == wxT( "pad" ) ) else if( lNode->GetName().IsSameAs( wxT( "pad" ), false ) )
{ {
pad = new PCB_PAD( this, m_board ); pad = new PCB_PAD( this, m_board );
pad->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ); pad->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
m_PcbComponents.Add( pad ); m_PcbComponents.Add( pad );
} }
else if( lNode->GetName() == wxT( "via" ) ) else if( lNode->GetName().IsSameAs( wxT( "via" ), false ) )
{ {
via = new PCB_VIA( this, m_board ); via = new PCB_VIA( this, m_board );
via->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ); via->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
m_PcbComponents.Add( via ); m_PcbComponents.Add( via );
} }
else if( lNode->GetName() == wxT( "polyKeepOut" ) ) else if( lNode->GetName().IsSameAs( wxT( "polyKeepOut" ), false ) )
{ {
keepOut = new PCB_KEEPOUT( m_callbacks, m_board, 0 ); keepOut = new PCB_KEEPOUT( m_callbacks, m_board, 0 );
@ -544,13 +544,13 @@ void PCB::MapLayer( XNODE* aNode )
{ {
layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false ); layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false );
if( layerType == wxT( "NonSignal" ) ) if( layerType.IsSameAs( wxT( "NonSignal" ), false ) )
newlayer.layerType = LAYER_TYPE_NONSIGNAL; newlayer.layerType = LAYER_TYPE_NONSIGNAL;
if( layerType == wxT( "Signal" ) ) if( layerType.IsSameAs( wxT( "Signal" ), false ) )
newlayer.layerType = LAYER_TYPE_SIGNAL; newlayer.layerType = LAYER_TYPE_SIGNAL;
if( layerType == wxT( "Plane" ) ) if( layerType.IsSameAs( wxT( "Plane" ), false ) )
newlayer.layerType = LAYER_TYPE_PLANE; newlayer.layerType = LAYER_TYPE_PLANE;
} }
@ -577,15 +577,6 @@ int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint )
} }
/*int cmpFunc( wxRealPoint **first, wxRealPoint **second )
{
return sqrt( pow( (double) aPointA.x - (double) aPointB.x, 2 ) +
pow( (double) aPointA.y - (double) aPointB.y, 2 ) );
return 0;
}*/
double PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const double PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const
{ {
return sqrt( ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) + return sqrt( ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) +
@ -610,7 +601,7 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver
while( iNode ) while( iNode )
{ {
// objects // objects
if( iNode->GetName() == wxT( "layerContents" ) ) if( iNode->GetName().IsSameAs( wxT( "layerContents" ), false ) )
{ {
if( FindNode( iNode, wxT( "layerNumRef" ) ) ) if( FindNode( iNode, wxT( "layerNumRef" ) ) )
FindNode( iNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &PCadLayer ); FindNode( iNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &PCadLayer );
@ -621,7 +612,7 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver
while( lNode ) while( lNode )
{ {
if( lNode->GetName() == wxT( "line" ) ) if( lNode->GetName().IsSameAs( wxT( "line" ), false ) )
{ {
pNode = FindNode( lNode, wxT( "pt" ) ); pNode = FindNode( lNode, wxT( "pt" ) );
@ -746,14 +737,15 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
while( aNode ) while( aNode )
{ {
if( aNode->GetName() == wxT( "layerDef" ) ) if( aNode->GetName().IsSameAs( wxT( "layerDef" ), false ) )
{ {
if( FindNode( aNode, wxT( "layerType" ) ) ) if( FindNode( aNode, wxT( "layerType" ) ) )
{ {
layerType = FindNode( aNode, layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim(
wxT( "layerType" ) )->GetNodeContent().Trim( false ); false );
if( layerType == wxT( "Signal" ) || layerType == wxT( "Plane" ) ) if( layerType.IsSameAs( wxT( "Signal" ), false )
|| layerType.IsSameAs( wxT( "Plane" ), false ) )
{ {
aNode->GetAttribute( wxT( "Name" ), &layerName ); aNode->GetAttribute( wxT( "Name" ), &layerName );
layerName = layerName.MakeUpper(); layerName = layerName.MakeUpper();
@ -778,7 +770,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
while( aNode ) while( aNode )
{ {
if( aNode->GetName() == wxT( "layerDef" ) ) if( aNode->GetName().IsSameAs( wxT( "layerDef" ), false ) )
MapLayer( aNode ); MapLayer( aNode );
aNode = aNode->GetNext(); aNode = aNode->GetNext();
@ -821,11 +813,11 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
while( aNode ) while( aNode )
{ {
// Components/footprints // Components/footprints
if( aNode->GetName() == wxT( "multiLayer" ) ) if( aNode->GetName().IsSameAs( wxT( "multiLayer" ), false ) )
DoPCBComponents( aNode, aXmlDoc, aActualConversion, aStatusBar ); DoPCBComponents( aNode, aXmlDoc, aActualConversion, aStatusBar );
// objects // objects
if( aNode->GetName() == wxT( "layerContents" ) ) if( aNode->GetName().IsSameAs( wxT( "layerContents" ), false ) )
DoLayerContentsObjects( aNode, nullptr, &m_PcbComponents, aStatusBar, DoLayerContentsObjects( aNode, nullptr, &m_PcbComponents, aStatusBar,
m_DefaultMeasurementUnit, aActualConversion ); m_DefaultMeasurementUnit, aActualConversion );
@ -923,7 +915,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
{ {
// aStatusBar->SetStatusText( wxT( "Processing COMPONENTS " ) ); // aStatusBar->SetStatusText( wxT( "Processing COMPONENTS " ) );
if( aNode->GetName() == wxT( "compDef" ) ) if( aNode->GetName().IsSameAs( wxT( "compDef" ), false ) )
{ {
footprint = new PCB_FOOTPRINT( this, m_board ); footprint = new PCB_FOOTPRINT( this, m_board );
footprint->Parse( aNode, aStatusBar, m_DefaultMeasurementUnit, footprint->Parse( aNode, aStatusBar, m_DefaultMeasurementUnit,

View File

@ -153,14 +153,14 @@ void PCB_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits,
if( cNode ) if( cNode )
SetWidth( cNode->GetNodeContent(), aDefaultUnits, &m_Hole, aActualConversion ); SetWidth( cNode->GetNodeContent(), aDefaultUnits, &m_Hole, aActualConversion );
if( FindNodeGetContent( lNode, wxT( "isHolePlated" ) ) == wxT( "False" ) ) if( FindNodeGetContent( lNode, wxT( "isHolePlated" ) ).IsSameAs( wxT( "False" ), false ) )
m_IsHolePlated = false; m_IsHolePlated = false;
cNode = FindNode( lNode, wxT( "padShape" ) ); cNode = FindNode( lNode, wxT( "padShape" ) );
while( cNode ) while( cNode )
{ {
if( cNode->GetName() == wxT( "padShape" ) ) if( cNode->GetName().IsSameAs( wxT( "padShape" ), false ) )
{ {
// we support only Pads on specific layers...... // we support only Pads on specific layers......
// we do not support pads on "Plane", "NonSignal" , "Signal" ... layerr // we do not support pads on "Plane", "NonSignal" , "Signal" ... layerr
@ -215,7 +215,7 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation,
// Mounting Hole: Solder Mask Margin from Top Layer Width size. // Mounting Hole: Solder Mask Margin from Top Layer Width size.
// Used the default zone clearance (simplify) // Used the default zone clearance (simplify)
if( m_Shapes.GetCount() && m_Shapes[0]->m_Shape == wxT( "MtHole" ) ) if( m_Shapes.GetCount() && m_Shapes[0]->m_Shape.IsSameAs( wxT( "MtHole" ), false ) )
{ {
int sm_margin = ( m_Shapes[0]->m_Width - m_Hole ) / 2; int sm_margin = ( m_Shapes[0]->m_Width - m_Hole ) / 2;
pad->SetLocalSolderMaskMargin( sm_margin ); pad->SetLocalSolderMaskMargin( sm_margin );
@ -265,24 +265,24 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation,
pad->SetNumber( m_name.text ); pad->SetNumber( m_name.text );
if( padShapeName == wxT( "Oval" ) if( padShapeName.IsSameAs( wxT( "Oval" ), false )
|| padShapeName == wxT( "Ellipse" ) || padShapeName.IsSameAs( wxT( "Ellipse" ), false )
|| padShapeName == wxT( "MtHole" ) ) || padShapeName.IsSameAs( wxT( "MtHole" ), false ) )
{ {
if( width != height ) if( width != height )
pad->SetShape( PAD_SHAPE::OVAL ); pad->SetShape( PAD_SHAPE::OVAL );
else else
pad->SetShape( PAD_SHAPE::CIRCLE ); pad->SetShape( PAD_SHAPE::CIRCLE );
} }
else if( padShapeName == wxT( "Rect" ) ) else if( padShapeName.IsSameAs( wxT( "Rect" ), false ) )
{ {
pad->SetShape( PAD_SHAPE::RECT ); pad->SetShape( PAD_SHAPE::RECT );
} }
else if( padShapeName == wxT( "RndRect" ) ) else if( padShapeName.IsSameAs( wxT( "RndRect" ), false ) )
{ {
pad->SetShape( PAD_SHAPE::ROUNDRECT ); pad->SetShape( PAD_SHAPE::ROUNDRECT );
} }
else if( padShapeName == wxT( "Polygon" ) ) else if( padShapeName.IsSameAs( wxT( "Polygon" ), false ) )
{ {
pad->SetShape( PAD_SHAPE::RECT ); // approximation pad->SetShape( PAD_SHAPE::RECT ); // approximation
} }

View File

@ -82,7 +82,7 @@ void PCB_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
str = FindNodeGetContent( aNode, wxT( "isFlipped" ) ); str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
if( str == wxT( "True" ) ) if( str.IsSameAs( wxT( "True" ), false ) )
m_name.mirror = 1; m_name.mirror = 1;
lNode = FindNode( aNode, wxT( "textStyleRef" ) ); lNode = FindNode( aNode, wxT( "textStyleRef" ) );