Fix minor symbol library s-expression formatter and parser bugs.

This commit is contained in:
Wayne Stambaugh 2020-02-28 11:12:08 -05:00
parent 9d6f64da9a
commit 18f9ba110d
2 changed files with 46 additions and 33 deletions

View File

@ -560,20 +560,21 @@ void SCH_SEXPR_PARSER::parsePinNames( std::unique_ptr<LIB_PART>& aSymbol )
aSymbol->SetPinNameOffset( parseInternalUnits( "pin name offset" ) ); aSymbol->SetPinNameOffset( parseInternalUnits( "pin name offset" ) );
NeedRIGHT(); NeedRIGHT();
token = NextTok(); // Either ) or hide
} }
else if( token == T_hide )
if( token == T_hide )
{ {
aSymbol->SetShowPinNames( false ); aSymbol->SetShowPinNames( false );
NeedRIGHT();
} }
else else if( token != T_RIGHT )
{ {
error.Printf( error.Printf(
_( "Invalid symbol names definition in\nfile: \"%s\"\nline: %d\noffset: %d" ), _( "Invalid symbol names definition in\nfile: \"%s\"\nline: %d\noffset: %d" ),
CurSource().c_str(), CurLineNumber(), CurOffset() ); CurSource().c_str(), CurLineNumber(), CurOffset() );
THROW_IO_ERROR( error ); THROW_IO_ERROR( error );
} }
NeedRIGHT();
} }
@ -693,6 +694,7 @@ void SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol )
{ {
case T_at: case T_at:
field->SetPosition( parseXY() ); field->SetPosition( parseXY() );
field->SetTextAngle( static_cast<int>( parseDouble( "text angle" ) * 10.0 ) );
NeedRIGHT(); NeedRIGHT();
break; break;
@ -1120,6 +1122,10 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin()
pin->SetName( FromUTF8() ); pin->SetName( FromUTF8() );
token = NextTok(); token = NextTok();
if( token != T_RIGHT )
{
token = NextTok();
if( token == T_effects ) if( token == T_effects )
{ {
// The EDA_TEXT font effects formatting is used so use and EDA_TEXT object // The EDA_TEXT font effects formatting is used so use and EDA_TEXT object
@ -1130,9 +1136,10 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin()
pin->SetNameTextSize( text.GetTextHeight() ); pin->SetNameTextSize( text.GetTextHeight() );
NeedRIGHT(); NeedRIGHT();
} }
else if( token != T_RIGHT ) else
{ {
Expecting( ") or effects" ); Expecting( "effects" );
}
} }
break; break;
@ -1150,6 +1157,10 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin()
pin->SetNumber( FromUTF8() ); pin->SetNumber( FromUTF8() );
token = NextTok(); token = NextTok();
if( token != T_RIGHT )
{
token = NextTok();
if( token == T_effects ) if( token == T_effects )
{ {
// The EDA_TEXT font effects formatting is used so use and EDA_TEXT object // The EDA_TEXT font effects formatting is used so use and EDA_TEXT object
@ -1160,9 +1171,10 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin()
pin->SetNumberTextSize( text.GetTextHeight(), false ); pin->SetNumberTextSize( text.GetTextHeight(), false );
NeedRIGHT(); NeedRIGHT();
} }
else if( token != T_RIGHT ) else
{ {
Expecting( ") or effects" ); Expecting( "effects" );
}
} }
break; break;

View File

@ -728,10 +728,10 @@ void SCH_SEXPR_PLUGIN::saveComponent( SCH_COMPONENT* aComponent )
static wxString delimiters( wxT( " " ) ); static wxString delimiters( wxT( " " ) );
// This is redundant with the AR entries below, but it makes the files backwards-compatible. // This is redundant with the AR entries below, but it makes the files backwards-compatible.
if( aComponent->GetPathsAndReferences().GetCount() > 0 ) if( aComponent->GetInstanceReferences().size() > 0 )
{ {
reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters ); const COMPONENT_INSTANCE_REFERENCE& instance = aComponent->GetInstanceReferences()[0];
name1 = toUTFTildaText( reference_fields[1] ); name1 = toUTFTildaText( instance.m_Reference );
} }
else else
{ {
@ -1224,12 +1224,12 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
if( !aSymbol->ShowPinNumbers() ) if( !aSymbol->ShowPinNumbers() )
aFormatter.Print( 0, " (pin_numbers hide)" ); aFormatter.Print( 0, " (pin_numbers hide)" );
if( aSymbol->GetPinNameOffset() != Iu2Mils( DEFAULT_PIN_NAME_OFFSET ) if( aSymbol->GetPinNameOffset() != Mils2iu( DEFAULT_PIN_NAME_OFFSET )
|| !aSymbol->ShowPinNames() ) || !aSymbol->ShowPinNames() )
{ {
aFormatter.Print( 0, " (pin_names" ); aFormatter.Print( 0, " (pin_names" );
if( aSymbol->GetPinNameOffset() != Iu2Mils( DEFAULT_PIN_NAME_OFFSET ) ) if( aSymbol->GetPinNameOffset() != Mils2iu( DEFAULT_PIN_NAME_OFFSET ) )
aFormatter.Print( 0, " (offset %s)", aFormatter.Print( 0, " (offset %s)",
FormatInternalUnits( aSymbol->GetPinNameOffset() ).c_str() ); FormatInternalUnits( aSymbol->GetPinNameOffset() ).c_str() );
@ -1575,11 +1575,12 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField,
if( aField->IsMandatory() && !fieldName.StartsWith( "ki_" ) ) if( aField->IsMandatory() && !fieldName.StartsWith( "ki_" ) )
fieldName = "ki_" + fieldName.Lower(); fieldName = "ki_" + fieldName.Lower();
aFormatter.Print( aNestLevel, "(property %s %s (at %s %s)", aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
aFormatter.Quotew( fieldName ).c_str(), aFormatter.Quotew( fieldName ).c_str(),
aFormatter.Quotew( aField->GetText() ).c_str(), aFormatter.Quotew( aField->GetText() ).c_str(),
FormatInternalUnits( aField->GetPosition().x ).c_str(), FormatInternalUnits( aField->GetPosition().x ).c_str(),
FormatInternalUnits( aField->GetPosition().y ).c_str() ); FormatInternalUnits( aField->GetPosition().y ).c_str(),
static_cast<double>( aField->GetTextAngle() ) / 10.0 );
if( aField->IsDefaultFormatting() ) if( aField->IsDefaultFormatting() )
{ {