Generalize fill parsing and add support for sheet background R/W.
Also fixes a bug in colour parsing (the alpha channel is a float).
This commit is contained in:
parent
0248abed6e
commit
6aaee01f1c
|
@ -433,10 +433,10 @@ void SCH_SEXPR_PARSER::parseStroke( STROKE_PARAMS& aStroke )
|
||||||
|
|
||||||
case T_color:
|
case T_color:
|
||||||
aStroke.m_Color =
|
aStroke.m_Color =
|
||||||
COLOR4D( wxColour( static_cast<unsigned char>( parseInt( "red" ) ),
|
COLOR4D( parseInt( "red" ) / 255.0,
|
||||||
static_cast<unsigned char>( parseInt( "green" ) ),
|
parseInt( "green" ) / 255.0,
|
||||||
static_cast<unsigned char>( parseInt( "blue" ) ),
|
parseInt( "blue" ) / 255.0,
|
||||||
static_cast<unsigned char>( parseInt( "alpha" ) ) ) );
|
parseDouble( "alpha" ) );
|
||||||
NeedRIGHT();
|
NeedRIGHT();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -448,43 +448,56 @@ void SCH_SEXPR_PARSER::parseStroke( STROKE_PARAMS& aStroke )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FILL_T SCH_SEXPR_PARSER::parseFillMode()
|
void SCH_SEXPR_PARSER::parseFill( FILL_PARAMS& aFill )
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( CurTok() == T_fill, NO_FILL,
|
wxCHECK_RET( CurTok() == T_fill,
|
||||||
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as fill." ) );
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as fill." ) );
|
||||||
|
|
||||||
NeedLEFT();
|
aFill.m_FillType = NO_FILL;
|
||||||
T token = NextTok();
|
aFill.m_Color = COLOR4D::UNSPECIFIED;
|
||||||
|
|
||||||
if( token != T_type )
|
T token;
|
||||||
Expecting( "type" );
|
|
||||||
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
||||||
|
{
|
||||||
|
if( token != T_LEFT )
|
||||||
|
Expecting( T_LEFT );
|
||||||
|
|
||||||
token = NextTok();
|
token = NextTok();
|
||||||
|
|
||||||
FILL_T fillType = NO_FILL;
|
switch( token )
|
||||||
|
{
|
||||||
|
case T_type:
|
||||||
|
{
|
||||||
|
token = NextTok();
|
||||||
|
|
||||||
switch( token )
|
switch( token )
|
||||||
{
|
{
|
||||||
case T_none:
|
case T_none: aFill.m_FillType = NO_FILL; break;
|
||||||
fillType = NO_FILL;
|
case T_outline: aFill.m_FillType = FILLED_SHAPE; break;
|
||||||
break;
|
case T_background: aFill.m_FillType = FILLED_WITH_BG_BODYCOLOR; break;
|
||||||
|
|
||||||
case T_outline:
|
|
||||||
fillType = FILLED_SHAPE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case T_background:
|
|
||||||
fillType = FILLED_WITH_BG_BODYCOLOR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Expecting( "none, outline, or background" );
|
Expecting( "none, outline, or background" );
|
||||||
}
|
}
|
||||||
|
|
||||||
NeedRIGHT(); // Closes type token.
|
NeedRIGHT();
|
||||||
NeedRIGHT(); // Closes fill token.
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return fillType;
|
case T_color:
|
||||||
|
aFill.m_Color =
|
||||||
|
COLOR4D( parseInt( "red" ) / 255.0,
|
||||||
|
parseInt( "green" ) / 255.0,
|
||||||
|
parseInt( "blue" ) / 255.0,
|
||||||
|
parseDouble( "alpha" ) );
|
||||||
|
|
||||||
|
NeedRIGHT();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Expecting( "type or color" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -794,6 +807,7 @@ LIB_ARC* SCH_SEXPR_PARSER::parseArc()
|
||||||
wxPoint midPoint;
|
wxPoint midPoint;
|
||||||
wxPoint endPoint;
|
wxPoint endPoint;
|
||||||
wxPoint pos;
|
wxPoint pos;
|
||||||
|
FILL_PARAMS fill;
|
||||||
bool hasMidPoint = false;
|
bool hasMidPoint = false;
|
||||||
std::unique_ptr<LIB_ARC> arc( new LIB_ARC( nullptr ) );
|
std::unique_ptr<LIB_ARC> arc( new LIB_ARC( nullptr ) );
|
||||||
|
|
||||||
|
@ -878,7 +892,8 @@ LIB_ARC* SCH_SEXPR_PARSER::parseArc()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_fill:
|
case T_fill:
|
||||||
arc->SetFillMode( parseFillMode() );
|
parseFill( fill );
|
||||||
|
arc->SetFillMode( fill.m_FillType );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -911,6 +926,7 @@ LIB_BEZIER* SCH_SEXPR_PARSER::parseBezier()
|
||||||
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a bezier." ) );
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a bezier." ) );
|
||||||
|
|
||||||
T token;
|
T token;
|
||||||
|
FILL_PARAMS fill;
|
||||||
std::unique_ptr<LIB_BEZIER> bezier( new LIB_BEZIER( nullptr ) );
|
std::unique_ptr<LIB_BEZIER> bezier( new LIB_BEZIER( nullptr ) );
|
||||||
|
|
||||||
bezier->SetUnit( m_unit );
|
bezier->SetUnit( m_unit );
|
||||||
|
@ -956,7 +972,8 @@ LIB_BEZIER* SCH_SEXPR_PARSER::parseBezier()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_fill:
|
case T_fill:
|
||||||
bezier->SetFillMode( parseFillMode() );
|
parseFill( fill );
|
||||||
|
bezier->SetFillMode( fill.m_FillType );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -974,6 +991,7 @@ LIB_CIRCLE* SCH_SEXPR_PARSER::parseCircle()
|
||||||
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle token." ) );
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle token." ) );
|
||||||
|
|
||||||
T token;
|
T token;
|
||||||
|
FILL_PARAMS fill;
|
||||||
std::unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( nullptr ) );
|
std::unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( nullptr ) );
|
||||||
|
|
||||||
circle->SetUnit( m_unit );
|
circle->SetUnit( m_unit );
|
||||||
|
@ -1011,7 +1029,8 @@ LIB_CIRCLE* SCH_SEXPR_PARSER::parseCircle()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_fill:
|
case T_fill:
|
||||||
circle->SetFillMode( parseFillMode() );
|
parseFill( fill );
|
||||||
|
circle->SetFillMode( fill.m_FillType );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1269,6 +1288,7 @@ LIB_POLYLINE* SCH_SEXPR_PARSER::parsePolyLine()
|
||||||
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a polyline." ) );
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a polyline." ) );
|
||||||
|
|
||||||
T token;
|
T token;
|
||||||
|
FILL_PARAMS fill;
|
||||||
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( nullptr ) );
|
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( nullptr ) );
|
||||||
|
|
||||||
polyLine->SetUnit( m_unit );
|
polyLine->SetUnit( m_unit );
|
||||||
|
@ -1314,7 +1334,8 @@ LIB_POLYLINE* SCH_SEXPR_PARSER::parsePolyLine()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_fill:
|
case T_fill:
|
||||||
polyLine->SetFillMode( parseFillMode() );
|
parseFill( fill );
|
||||||
|
polyLine->SetFillMode( fill.m_FillType );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1332,6 +1353,7 @@ LIB_RECTANGLE* SCH_SEXPR_PARSER::parseRectangle()
|
||||||
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a rectangle token." ) );
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a rectangle token." ) );
|
||||||
|
|
||||||
T token;
|
T token;
|
||||||
|
FILL_PARAMS fill;
|
||||||
std::unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( nullptr ) );
|
std::unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( nullptr ) );
|
||||||
|
|
||||||
rectangle->SetUnit( m_unit );
|
rectangle->SetUnit( m_unit );
|
||||||
|
@ -1369,7 +1391,8 @@ LIB_RECTANGLE* SCH_SEXPR_PARSER::parseRectangle()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_fill:
|
case T_fill:
|
||||||
rectangle->SetFillMode( parseFillMode() );
|
parseFill( fill );
|
||||||
|
rectangle->SetFillMode( fill.m_FillType );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -2096,6 +2119,7 @@ SCH_SHEET* SCH_SEXPR_PARSER::parseSheet()
|
||||||
|
|
||||||
T token;
|
T token;
|
||||||
STROKE_PARAMS stroke;
|
STROKE_PARAMS stroke;
|
||||||
|
FILL_PARAMS fill;
|
||||||
SCH_FIELD* field;
|
SCH_FIELD* field;
|
||||||
std::vector<SCH_FIELD> fields;
|
std::vector<SCH_FIELD> fields;
|
||||||
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET() );
|
std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET() );
|
||||||
|
@ -2128,7 +2152,11 @@ SCH_SHEET* SCH_SEXPR_PARSER::parseSheet()
|
||||||
parseStroke( stroke );
|
parseStroke( stroke );
|
||||||
sheet->SetBorderWidth( stroke.m_Width );
|
sheet->SetBorderWidth( stroke.m_Width );
|
||||||
sheet->SetBorderColor( stroke.m_Color );
|
sheet->SetBorderColor( stroke.m_Color );
|
||||||
NeedRIGHT();
|
break;
|
||||||
|
|
||||||
|
case T_fill:
|
||||||
|
parseFill( fill );
|
||||||
|
sheet->SetBackgroundColor( fill.m_Color );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_uuid:
|
case T_uuid:
|
||||||
|
@ -2166,7 +2194,7 @@ SCH_SHEET* SCH_SEXPR_PARSER::parseSheet()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Expecting( "at, size, stroke, uuid, property, or pin" );
|
Expecting( "at, size, stroke, background, uuid, property, or pin" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple container to manage fill parameters.
|
||||||
|
*/
|
||||||
|
class FILL_PARAMS
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FILL_T m_FillType;
|
||||||
|
COLOR4D m_Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to parser s-expression symbol library and schematic file formats.
|
* Object to parser s-expression symbol library and schematic file formats.
|
||||||
*/
|
*/
|
||||||
|
@ -175,7 +186,7 @@ class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER
|
||||||
*/
|
*/
|
||||||
void parseStroke( STROKE_PARAMS& aStroke );
|
void parseStroke( STROKE_PARAMS& aStroke );
|
||||||
|
|
||||||
FILL_T parseFillMode();
|
void parseFill( FILL_PARAMS& aFill );
|
||||||
|
|
||||||
void parseEDA_TEXT( EDA_TEXT* aText );
|
void parseEDA_TEXT( EDA_TEXT* aText );
|
||||||
void parsePinNames( std::unique_ptr<LIB_PART>& aSymbol );
|
void parsePinNames( std::unique_ptr<LIB_PART>& aSymbol );
|
||||||
|
|
|
@ -299,9 +299,9 @@ static void formatStroke( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aWidt
|
||||||
|
|
||||||
if( !( aColor == COLOR4D::UNSPECIFIED ) )
|
if( !( aColor == COLOR4D::UNSPECIFIED ) )
|
||||||
aFormatter->Print( 0, " (color %d %d %d %0.4f)",
|
aFormatter->Print( 0, " (color %d %d %d %0.4f)",
|
||||||
static_cast<int>( aColor.r * 255.0 + 0.5 ),
|
KiROUND( aColor.r * 255.0 ),
|
||||||
static_cast<int>( aColor.g * 255.0 + 0.5 ),
|
KiROUND( aColor.g * 255.0 ),
|
||||||
static_cast<int>( aColor.b * 255.0 + 0.5 ),
|
KiROUND( aColor.b * 255.0 ),
|
||||||
aColor.a );
|
aColor.a );
|
||||||
|
|
||||||
aFormatter->Print( 0, ")" );
|
aFormatter->Print( 0, ")" );
|
||||||
|
@ -961,11 +961,20 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel )
|
||||||
aSheet->GetBorderColor() );
|
aSheet->GetBorderColor() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( !( aSheet->GetBackgroundColor() == COLOR4D::UNSPECIFIED ) )
|
||||||
|
{
|
||||||
|
m_out->Print( 0, " (fill (color %d %d %d %0.4f))",
|
||||||
|
KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
|
||||||
|
KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
|
||||||
|
KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
|
||||||
|
aSheet->GetBackgroundColor().a );
|
||||||
|
}
|
||||||
|
|
||||||
m_out->Print( 0, "\n" );
|
m_out->Print( 0, "\n" );
|
||||||
m_out->Print( aNestLevel + 1, "(uuid %s)", TO_UTF8( aSheet->m_Uuid.AsString() ) );
|
m_out->Print( aNestLevel + 1, "(uuid %s)", TO_UTF8( aSheet->m_Uuid.AsString() ) );
|
||||||
m_out->Print( 0, "\n" );
|
m_out->Print( 0, "\n" );
|
||||||
|
|
||||||
for( auto field : aSheet->GetFields() )
|
for( const SCH_FIELD& field : aSheet->GetFields() )
|
||||||
{
|
{
|
||||||
SCH_FIELD tmp = field;
|
SCH_FIELD tmp = field;
|
||||||
|
|
||||||
|
@ -977,7 +986,7 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel )
|
||||||
saveField( &tmp, aNestLevel + 1 );
|
saveField( &tmp, aNestLevel + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( const auto pin : aSheet->GetPins() )
|
for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
|
||||||
{
|
{
|
||||||
m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)",
|
m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)",
|
||||||
EscapedUTF8( pin->GetText() ).c_str(),
|
EscapedUTF8( pin->GetText() ).c_str(),
|
||||||
|
|
|
@ -40,14 +40,11 @@
|
||||||
* is the set of fill types used in plotting or drawing enclosed areas.
|
* is the set of fill types used in plotting or drawing enclosed areas.
|
||||||
*/
|
*/
|
||||||
enum FILL_T {
|
enum FILL_T {
|
||||||
NO_FILL, // Poly, Square, Circle, Arc = option No Fill
|
NO_FILL,
|
||||||
FILLED_SHAPE, /* Poly, Square, Circle, Arc = option Fill
|
FILLED_SHAPE, // Fill with object color ("Solid shape")
|
||||||
* with current color ("Solid shape") */
|
FILLED_WITH_BG_BODYCOLOR, // Fill with background body color
|
||||||
FILLED_WITH_BG_BODYCOLOR /* Poly, Square, Circle, Arc = option Fill
|
// (not filled in B&W mode when plotting or printing)
|
||||||
* with background body color, translucent
|
FILLED_WITH_COLOR // Fill with a user-defined color (currently sheets only)
|
||||||
* (texts inside this shape can be seen)
|
|
||||||
* not filled in B&W mode when plotting or
|
|
||||||
* printing */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue