Avoid unnecessary newlines and extra spaces when saving polygon shapes

Also minor formatting / code style fixes.
This commit is contained in:
Roberto Fernandez Bautista 2021-12-03 18:56:24 +00:00
parent c463818b57
commit 8caf62803d
1 changed files with 19 additions and 20 deletions

View File

@ -845,40 +845,30 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const
const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
m_out->Print( aNestLevel, "(gr_poly%s\n", locked.c_str() ); m_out->Print( aNestLevel, "(gr_poly%s\n", locked.c_str() );
m_out->Print( aNestLevel+1, "(pts\n" ); m_out->Print( aNestLevel + 1, "(pts\n" );
bool need_newline = false; bool needNewline = false;
int nestLevel = aNestLevel + 2;
int shapesAdded = 0;
for( int ii = 0; ii < outline.PointCount(); ++ii ) for( int ii = 0; ii < outline.PointCount(); ++ii )
{ {
int nestLevel = 0;
if( !( ii % 4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave )
{
// newline every 4 pts.
nestLevel = aNestLevel + 2;
m_out->Print( 0, "\n" );
need_newline = false;
}
int ind = outline.ArcIndex( ii ); int ind = outline.ArcIndex( ii );
if( ind < 0 ) if( ind < 0 )
{ {
m_out->Print( nestLevel, "%s(xy %s)", m_out->Print( nestLevel, "(xy %s)",
nestLevel ? "" : " ",
FormatInternalUnits( outline.CPoint( ii ) ).c_str() ); FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
need_newline = true; needNewline = true;
} }
else else
{ {
const SHAPE_ARC& arc = outline.Arc( ind ); const SHAPE_ARC& arc = outline.Arc( ind );
m_out->Print( nestLevel, "%s(arc (start %s) (mid %s) (end %s))", m_out->Print( nestLevel, "(arc (start %s) (mid %s) (end %s))",
nestLevel ? "" : " ",
FormatInternalUnits( arc.GetP0() ).c_str(), FormatInternalUnits( arc.GetP0() ).c_str(),
FormatInternalUnits( arc.GetArcMid() ).c_str(), FormatInternalUnits( arc.GetArcMid() ).c_str(),
FormatInternalUnits( arc.GetP1() ).c_str() ); FormatInternalUnits( arc.GetP1() ).c_str() );
need_newline = true; needNewline = true;
do do
{ {
@ -887,12 +877,21 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const
--ii; --ii;
} }
++shapesAdded;
if( !( shapesAdded % 4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave )
{
// newline every 4 shapes if compact save
m_out->Print( 0, "\n" );
needNewline = false;
}
} }
if( need_newline ) if( needNewline )
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
m_out->Print( aNestLevel+1, ")" ); m_out->Print( aNestLevel + 1, ")" );
} }
else else
{ {