SCH textboxes start/end -> at/size.

The at token can handle an angle; start/end does not.

Fixes https://gitlab.com/kicad/code/kicad/issues/11252
This commit is contained in:
Jeff Young 2022-03-28 10:32:07 +01:00
parent 343b2681d4
commit 47f4503564
4 changed files with 86 additions and 22 deletions

View File

@ -43,7 +43,8 @@
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20211014 // Arc formatting. //#define SEXPR_SYMBOL_LIB_FILE_VERSION 20211014 // Arc formatting.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220101 // Class flags. //#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220101 // Class flags.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220102 // Fonts. //#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220102 // Fonts.
#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220126 // Text boxes. //#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220126 // Text boxes.
#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220328 // Text box start/end -> at/size.
/** /**
@ -75,4 +76,5 @@
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220103 // Label fields //#define SEXPR_SCHEMATIC_FILE_VERSION 20220103 // Label fields
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220104 // Fonts //#define SEXPR_SCHEMATIC_FILE_VERSION 20220104 // Fonts
//#define SEXPR_SCHEMATIC_FILE_VERSION 20220124 // netclass_flag -> directive_label //#define SEXPR_SCHEMATIC_FILE_VERSION 20220124 // netclass_flag -> directive_label
#define SEXPR_SCHEMATIC_FILE_VERSION 20220126 // Text boxes //#define SEXPR_SCHEMATIC_FILE_VERSION 20220126 // Text boxes
#define SEXPR_SCHEMATIC_FILE_VERSION 20220328 // Text box start/end -> at/size

View File

@ -473,11 +473,15 @@ void SCH_SEXPR_PLUGIN_CACHE::saveTextBox( LIB_TEXTBOX* aTextBox, OUTPUTFORMATTER
aTextBox->IsPrivate() ? " private" : "", aTextBox->IsPrivate() ? " private" : "",
aFormatter.Quotew( aTextBox->GetText() ).c_str() ); aFormatter.Quotew( aTextBox->GetText() ).c_str() );
aFormatter.Print( aNestLevel + 1, "(start %s %s) (end %s %s)\n", VECTOR2I pos = aTextBox->GetStart();
FormatInternalUnits( aTextBox->GetStart().x ).c_str(), VECTOR2I size = aTextBox->GetEnd() - pos;
FormatInternalUnits( aTextBox->GetStart().y ).c_str(),
FormatInternalUnits( aTextBox->GetEnd().x ).c_str(), aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
FormatInternalUnits( aTextBox->GetEnd().y ).c_str() ); FormatInternalUnits( pos.x ).c_str(),
FormatInternalUnits( pos.y ).c_str(),
FormatAngle( aTextBox->GetTextAngle() ).c_str(),
FormatInternalUnits( size.x ).c_str(),
FormatInternalUnits( size.y ).c_str() );
aTextBox->GetStroke().Format( &aFormatter, aNestLevel + 1 ); aTextBox->GetStroke().Format( &aFormatter, aNestLevel + 1 );
aFormatter.Print( 0, "\n" ); aFormatter.Print( 0, "\n" );

View File

@ -1613,6 +1613,11 @@ LIB_TEXTBOX* SCH_SEXPR_PARSER::parseTextBox()
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a text box." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a text box." ) );
T token; T token;
VECTOR2I pos;
VECTOR2I end;
VECTOR2I size;
bool foundEnd = false;
bool foundSize = false;
STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT );
FILL_PARAMS fill; FILL_PARAMS fill;
std::unique_ptr<LIB_TEXTBOX> textBox = std::make_unique<LIB_TEXTBOX>( nullptr ); std::unique_ptr<LIB_TEXTBOX> textBox = std::make_unique<LIB_TEXTBOX>( nullptr );
@ -1642,13 +1647,26 @@ LIB_TEXTBOX* SCH_SEXPR_PARSER::parseTextBox()
switch( token ) switch( token )
{ {
case T_start: case T_start: // Legacy token during 6.99 development; fails to handle angle
textBox->SetPosition( parseXY() ); pos = parseXY();
NeedRIGHT(); NeedRIGHT();
break; break;
case T_end: case T_end: // Legacy token during 6.99 development; fails to handle angle
textBox->SetEnd( parseXY() ); end = parseXY();
foundEnd = true;
NeedRIGHT();
break;
case T_at:
pos = parseXY();
textBox->SetTextAngle( EDA_ANGLE( parseDouble( "textbox angle" ), DEGREES_T ) );
NeedRIGHT();
break;
case T_size:
size = parseXY();
foundSize = true;
NeedRIGHT(); NeedRIGHT();
break; break;
@ -1668,10 +1686,19 @@ LIB_TEXTBOX* SCH_SEXPR_PARSER::parseTextBox()
break; break;
default: default:
Expecting( "start, end, stroke, fill or effects" ); Expecting( "at, size, stroke, fill or effects" );
} }
} }
textBox->SetPosition( pos );
if( foundEnd )
textBox->SetEnd( end );
else if( foundSize )
textBox->SetEnd( pos + size );
else
Expecting( "size" );
return textBox.release(); return textBox.release();
} }
@ -3516,6 +3543,11 @@ SCH_TEXTBOX* SCH_SEXPR_PARSER::parseSchTextBox()
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a text box." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a text box." ) );
T token; T token;
VECTOR2I pos;
VECTOR2I end;
VECTOR2I size;
bool foundEnd = false;
bool foundSize = false;
STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT ); STROKE_PARAMS stroke( Mils2iu( DEFAULT_LINE_WIDTH_MILS ), PLOT_DASH_TYPE::DEFAULT );
FILL_PARAMS fill; FILL_PARAMS fill;
std::unique_ptr<SCH_TEXTBOX> textBox = std::make_unique<SCH_TEXTBOX>(); std::unique_ptr<SCH_TEXTBOX> textBox = std::make_unique<SCH_TEXTBOX>();
@ -3533,13 +3565,26 @@ SCH_TEXTBOX* SCH_SEXPR_PARSER::parseSchTextBox()
switch( token ) switch( token )
{ {
case T_start: case T_start: // Legacy token during 6.99 development; fails to handle angle
textBox->SetPosition( parseXY() ); pos = parseXY();
NeedRIGHT(); NeedRIGHT();
break; break;
case T_end: case T_end: // Legacy token during 6.99 development; fails to handle angle
textBox->SetEnd( parseXY() ); end = parseXY();
foundEnd = true;
NeedRIGHT();
break;
case T_at:
pos = parseXY();
textBox->SetTextAngle( EDA_ANGLE( parseDouble( "textbox angle" ), DEGREES_T ) );
NeedRIGHT();
break;
case T_size:
size = parseXY();
foundSize = true;
NeedRIGHT(); NeedRIGHT();
break; break;
@ -3565,10 +3610,19 @@ SCH_TEXTBOX* SCH_SEXPR_PARSER::parseSchTextBox()
break; break;
default: default:
Expecting( "start, end, stroke, fill or uuid" ); Expecting( "at, size, stroke, fill, effects or uuid" );
} }
} }
textBox->SetPosition( pos );
if( foundEnd )
textBox->SetEnd( end );
else if( foundSize )
textBox->SetEnd( pos + size );
else
Expecting( "size" );
return textBox.release(); return textBox.release();
} }

View File

@ -1134,11 +1134,15 @@ void SCH_SEXPR_PLUGIN::saveTextBox( SCH_TEXTBOX* aTextBox, int aNestLevel )
m_out->Print( aNestLevel, "(text_box %s\n", m_out->Print( aNestLevel, "(text_box %s\n",
m_out->Quotew( aTextBox->GetText() ).c_str() ); m_out->Quotew( aTextBox->GetText() ).c_str() );
m_out->Print( aNestLevel + 1, "(start %s %s) (end %s %s)\n", VECTOR2I pos = aTextBox->GetStart();
FormatInternalUnits( aTextBox->GetStart().x ).c_str(), VECTOR2I size = aTextBox->GetEnd() - pos;
FormatInternalUnits( aTextBox->GetStart().y ).c_str(),
FormatInternalUnits( aTextBox->GetEnd().x ).c_str(), m_out->Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
FormatInternalUnits( aTextBox->GetEnd().y ).c_str() ); FormatInternalUnits( pos.x ).c_str(),
FormatInternalUnits( pos.y ).c_str(),
FormatAngle( aTextBox->GetTextAngle() ).c_str(),
FormatInternalUnits( size.x ).c_str(),
FormatInternalUnits( size.y ).c_str() );
aTextBox->GetStroke().Format( m_out, aNestLevel + 1 ); aTextBox->GetStroke().Format( m_out, aNestLevel + 1 );
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );