gerber: Fracture footprint polygons before exporting

Footprint polygons can be degenerate and need
to be simplified before exporting
This commit is contained in:
Seth Hillbrand 2019-08-05 21:23:57 -07:00
parent 7ed4d11f0c
commit e985e10eec
2 changed files with 32 additions and 7 deletions

View File

@ -127,6 +127,17 @@ public:
m_points[i] = *aV++;
}
SHAPE_LINE_CHAIN( const std::vector<wxPoint>& aV ) :
SHAPE( SH_LINE_CHAIN ),
m_closed( false )
{
m_points.reserve( aV.size() );
for( auto pt : aV )
m_points.emplace_back( pt.x, pt.y );
}
SHAPE_LINE_CHAIN( const ClipperLib::Path& aPath ) :
SHAPE( SH_LINE_CHAIN ),
m_closed( true )

View File

@ -505,13 +505,13 @@ void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge )
case S_POLYGON:
if( aEdge->IsPolyShapeValid() )
{
const std::vector<wxPoint>& polyPoints = aEdge->BuildPolyPointsList();
const std::vector<wxPoint> &polyPoints = aEdge->BuildPolyPointsList();
// We must compute true coordinates from m_PolyList
// which are relative to module position, orientation 0
MODULE* module = aEdge->GetParentModule();
MODULE *module = aEdge->GetParentModule();
std::vector< wxPoint > cornerList;
std::vector<wxPoint> cornerList;
cornerList.reserve( polyPoints.size() );
@ -530,17 +530,31 @@ void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge )
{
for( size_t i = 1; i < cornerList.size(); i++ )
{
m_plotter->ThickSegment( cornerList[i-1], cornerList[i], thickness,
GetPlotMode(), &gbr_metadata );
m_plotter->ThickSegment( cornerList[i - 1], cornerList[i], thickness,
GetPlotMode(), &gbr_metadata );
}
m_plotter->ThickSegment( cornerList.back(), cornerList.front(), thickness,
GetPlotMode(), &gbr_metadata );
GetPlotMode(), &gbr_metadata );
}
else
{
m_plotter->PlotPoly( cornerList, FILLED_SHAPE, thickness, &gbr_metadata );
// This must be simplified and fractured to prevent overlapping polygons
// from generating invalid Gerber files
SHAPE_LINE_CHAIN line( cornerList );
SHAPE_POLY_SET tmpPoly;
line.SetClosed( true );
tmpPoly.AddOutline( line );
tmpPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
for( int jj = 0; jj < tmpPoly.OutlineCount(); ++jj )
{
SHAPE_LINE_CHAIN &poly = tmpPoly.Outline( jj );
m_plotter->PlotPoly( poly, FILLED_SHAPE, thickness, &gbr_metadata );
}
}
}
break;