From 0a4ce183a47dbd492dc06fe86be6d0edf906ece6 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 25 Jul 2020 14:53:58 -0700 Subject: [PATCH] ADDED: polygon newlines every point By default KiCad will now print each polygon point on its own line. This adds to the vertical distance for large polygons but makes revision control much cleaner as single point addition to a polygon does not propagate to a diff over the full polygon. Users/developers who want to save the files using the 4-points per line have the ADVANCED_CONFIG setting 'CompactSave' which will provide the original save method --- common/advanced_config.cpp | 9 +++++++++ eeschema/sch_sexpr_plugin.cpp | 5 +++-- include/advanced_config.h | 6 ++++++ pcbnew/kicad_plugin.cpp | 25 ++++++++++++++++++------- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index fdc3946b86..72afdb6fc1 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -85,6 +85,12 @@ static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" ); */ static const wxChar ShowRouterDebugGraphics[] = wxT( "ShowRouterDebugGraphics" ); +/** + * When set to true, this will wrap polygon point sets at 4 points per line rather + * than a single point per line. Single point per line helps with version control systems + */ +static const wxChar CompactFileSave[] = wxT( "CompactSave" ); + } // namespace KEYS @@ -211,6 +217,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics, &m_ShowRouterDebugGraphics, false ) ); + configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave, + &m_CompactSave, false ) ); + wxConfigLoadSetups( &aCfg, configParams ); for( auto param : configParams ) diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 023e8cada7..29c4469978 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -1860,10 +1861,10 @@ void SCH_SEXPR_PLUGIN_CACHE::savePolyLine( LIB_POLYLINE* aPolyLine, for( const auto& pt : aPolyLine->GetPolyPoints() ) { - if( newLine == 4 ) + if( newLine == 4 || !ADVANCED_CFG::GetCfg().m_CompactSave ) { aFormatter.Print( 0, "\n" ); - aFormatter.Print( aNestLevel + 3, " (xy %s %s)", + aFormatter.Print( aNestLevel + 2, "(xy %s %s)", FormatInternalUnits( pt.x ).c_str(), FormatInternalUnits( pt.y ).c_str() ); newLine = 0; diff --git a/include/advanced_config.h b/include/advanced_config.h index d9be8f718b..192688ec5e 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -88,6 +88,12 @@ public: */ bool m_ShowRouterDebugGraphics; + /** + * Save files in compact display mode + * When is is not specified, points are written one per line + */ + bool m_CompactSave; + private: ADVANCED_CFG(); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index b6411f9160..9043f2af86 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -27,6 +27,8 @@ #include // LEGACY_BOARD_FILE_VERSION #include #include + +#include #include #include #include @@ -742,11 +744,20 @@ void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); int pointsCount = outline.PointCount(); - m_out->Print( aNestLevel, "(gr_poly (pts" ); + m_out->Print( aNestLevel, "(gr_poly (pts\n" ); for( int ii = 0; ii < pointsCount; ++ii ) { - m_out->Print( 0, " (xy %s)", FormatInternalUnits( outline.CPoint( ii ) ).c_str() ); + int nestLevel = 0; + + if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts + { + nestLevel = aNestLevel + 1; + m_out->Print( 0, "\n" ); + } + + m_out->Print( nestLevel, "%s(xy %s)", + nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() ); } m_out->Print( 0, ")" ); @@ -828,7 +839,7 @@ void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const { int nestLevel = 0; - if( ii && !( ii%4 ) ) // newline every 4 pts + if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts { nestLevel = aNestLevel + 1; m_out->Print( 0, "\n" ); @@ -1420,13 +1431,13 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const for( const VECTOR2I &pt : primitive->GetPolyShape().COutline( 0 ).CPoints() ) { if( newLine == 0 ) - m_out->Print( nested_level+1, " (xy %s)", + m_out->Print( nested_level+1, "(xy %s)", FormatInternalUnits( (wxPoint) pt ).c_str() ); else m_out->Print( 0, " (xy %s)", FormatInternalUnits( (wxPoint) pt ).c_str() ); - if( ++newLine > 4 ) + if( ++newLine > 4 || !ADVANCED_CFG::GetCfg().m_CompactSave ) { newLine = 0; m_out->Print( 0, "\n" ); @@ -1796,7 +1807,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() ); - if( newLine < 4 ) + if( newLine < 4 && ADVANCED_CFG::GetCfg().m_CompactSave ) { newLine += 1; } @@ -1867,7 +1878,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const m_out->Print( 0, " (xy %s %s)", FormatInternalUnits( it->x ).c_str(), FormatInternalUnits( it->y ).c_str() ); - if( newLine < 4 ) + if( newLine < 4 && ADVANCED_CFG::GetCfg().m_CompactSave ) { newLine += 1; }