Don't generate -1 width non-filled splines.

They serve no purpose, and will get replaced with
default-line-width non-filled splines.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20138
This commit is contained in:
Jeff Young 2025-03-02 11:32:57 +00:00
parent 8d096590dc
commit 1a10b5fb64
6 changed files with 36 additions and 23 deletions

View File

@ -201,7 +201,9 @@ public:
IMPORTED_POLYGON( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke, IMPORTED_POLYGON( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke,
bool aFilled, const COLOR4D& aFillColor ) : bool aFilled, const COLOR4D& aFillColor ) :
m_vertices( aVertices ), m_vertices( aVertices ),
m_stroke( aStroke ), m_filled( aFilled ), m_fillColor( aFillColor ) m_stroke( aStroke ),
m_filled( aFilled ),
m_fillColor( aFillColor )
{ {
} }

View File

@ -195,8 +195,12 @@ bool SVG_IMPORT_PLUGIN::Import()
// *not* closed so create a filled, closed shape for the fill, and an unfilled, // *not* closed so create a filled, closed shape for the fill, and an unfilled,
// open shape for the outline // open shape for the outline
static IMPORTED_STROKE noStroke( -1, LINE_STYLE::SOLID, COLOR4D::UNSPECIFIED ); static IMPORTED_STROKE noStroke( -1, LINE_STYLE::SOLID, COLOR4D::UNSPECIFIED );
DrawPath( path->pts, path->npts, true, noStroke, true, fillColor ); const bool closed = true;
DrawPath( path->pts, path->npts, false, stroke, false, COLOR4D::UNSPECIFIED );
DrawPath( path->pts, path->npts, closed, noStroke, true, fillColor );
if( stroke.GetWidth() > 0 )
DrawPath( path->pts, path->npts, !closed, stroke, false, COLOR4D::UNSPECIFIED );
} }
else else
{ {

View File

@ -64,10 +64,10 @@ int GRAPHICS_IMPORTER_LIB_SYMBOL::MapLineWidth( double aLineWidth )
STROKE_PARAMS GRAPHICS_IMPORTER_LIB_SYMBOL::MapStrokeParams( const IMPORTED_STROKE& aStroke ) STROKE_PARAMS GRAPHICS_IMPORTER_LIB_SYMBOL::MapStrokeParams( const IMPORTED_STROKE& aStroke )
{ {
double width = aStroke.GetWidth(); // Historicaly -1 meant no-stroke in Eeschema.
int width = ( aStroke.GetWidth() == -1 ) ? -1 : MapLineWidth( aStroke.GetWidth() );
return STROKE_PARAMS( width != -1 ? MapLineWidth( width ) : -1, aStroke.GetPlotStyle(), return STROKE_PARAMS( width, aStroke.GetPlotStyle(), aStroke.GetColor() );
aStroke.GetColor() );
} }

View File

@ -65,10 +65,10 @@ int GRAPHICS_IMPORTER_SCH::MapLineWidth( double aLineWidth )
STROKE_PARAMS GRAPHICS_IMPORTER_SCH::MapStrokeParams( const IMPORTED_STROKE& aStroke ) STROKE_PARAMS GRAPHICS_IMPORTER_SCH::MapStrokeParams( const IMPORTED_STROKE& aStroke )
{ {
double width = aStroke.GetWidth(); // Historicaly -1 meant no-stroke in Eeschema.
int width = ( aStroke.GetWidth() == -1 ) ? -1 : MapLineWidth( aStroke.GetWidth() );
return STROKE_PARAMS( width != -1 ? MapLineWidth( width ) : -1, aStroke.GetPlotStyle(), return STROKE_PARAMS( width, aStroke.GetPlotStyle(), aStroke.GetColor() );
aStroke.GetColor() );
} }

View File

@ -67,10 +67,12 @@ int GRAPHICS_IMPORTER_PCBNEW::MapLineWidth( double aLineWidth )
STROKE_PARAMS GRAPHICS_IMPORTER_PCBNEW::MapStrokeParams( const IMPORTED_STROKE& aStroke ) STROKE_PARAMS GRAPHICS_IMPORTER_PCBNEW::MapStrokeParams( const IMPORTED_STROKE& aStroke )
{ {
double width = aStroke.GetWidth(); // Historicaly -1 meant no-stroke in Eeschema, but this has never been the case for
// PCBNew. (The importer, which doesn't know which program it's creating content for,
// also uses -1 for no-stroke.)
int width = ( aStroke.GetWidth() == -1 ) ? 0 : MapLineWidth( aStroke.GetWidth() );
return STROKE_PARAMS( width != -1 ? MapLineWidth( width ) : -1, aStroke.GetPlotStyle(), return STROKE_PARAMS( width, aStroke.GetPlotStyle(), aStroke.GetColor() );
aStroke.GetColor() );
} }

View File

@ -3030,7 +3030,7 @@ PCB_SHAPE* PCB_IO_KICAD_SEXPR_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent )
case T_gr_vector: case T_gr_vector:
case T_gr_line: case T_gr_line:
case T_fp_line: case T_fp_line:
// Default PCB_SHAPE type is S_SEGMENT. shape->SetShape( SHAPE_T::SEGMENT );
token = NextTok(); token = NextTok();
if( token == T_locked ) if( token == T_locked )
@ -3094,7 +3094,15 @@ PCB_SHAPE* PCB_IO_KICAD_SEXPR_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent )
} }
default: default:
Expecting( "gr_arc, gr_circle, gr_curve, gr_line, gr_poly, gr_rect or gr_bbox" ); if( aParent && aParent->Type() == PCB_FOOTPRINT_T )
{
Expecting( "fp_arc, fp_circle, fp_curve, fp_line, fp_poly or fp_rect" );
}
else
{
Expecting( "gr_arc, gr_circle, gr_curve, gr_vector, gr_line, gr_poly, gr_rect or "
"gr_bbox" );
}
} }
bool foundFill = false; bool foundFill = false;
@ -3159,8 +3167,8 @@ PCB_SHAPE* PCB_IO_KICAD_SEXPR_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent )
switch( token ) switch( token )
{ {
// T_yes was used to indicate filling when first introduced, // T_yes was used to indicate filling when first introduced, so treat it like a
// so treat it like a solid fill since that was the only fill available // solid fill since that was the only fill available at the time.
case T_yes: case T_yes:
case T_solid: shape->SetFillMode( FILL_T::FILLED_SHAPE ); break; case T_solid: shape->SetFillMode( FILL_T::FILLED_SHAPE ); break;
@ -3177,19 +3185,15 @@ PCB_SHAPE* PCB_IO_KICAD_SEXPR_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent )
break; break;
// We continue to parse the status field but it is no longer written case T_status: // legacy token; ignore value
case T_status:
parseHex(); parseHex();
NeedRIGHT(); NeedRIGHT();
break; break;
// Handle (locked) from 5.99 development, and (locked yes) from modern times // Handle "(locked)" from 5.99 development, and "(locked yes)" from modern times
case T_locked: case T_locked:
{ shape->SetLocked( parseMaybeAbsentBool( true ) );
bool locked = parseMaybeAbsentBool( true );
shape->SetLocked( locked );
break; break;
}
case T_net: case T_net:
if( !shape->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) ) if( !shape->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
@ -3197,6 +3201,7 @@ PCB_SHAPE* PCB_IO_KICAD_SEXPR_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent )
wxLogError( _( "Invalid net ID in\nfile: '%s'\nline: %d\noffset: %d." ), wxLogError( _( "Invalid net ID in\nfile: '%s'\nline: %d\noffset: %d." ),
CurSource(), CurLineNumber(), CurOffset() ); CurSource(), CurLineNumber(), CurOffset() );
} }
NeedRIGHT(); NeedRIGHT();
break; break;