Pcbnew: fix board file formatting issues.

This does not required a board file version change.  All of the changes
are white space formatting fixes and improvements.
This commit is contained in:
Wayne Stambaugh 2021-04-20 10:18:31 -04:00
parent ce3a84f579
commit a7f956581c
1 changed files with 59 additions and 46 deletions

View File

@ -615,6 +615,7 @@ void PCB_IO::formatProperties( const BOARD* aBoard, int aNestLevel ) const
m_out->Quotew( prop.second ).c_str() ); m_out->Quotew( prop.second ).c_str() );
} }
if( !aBoard->GetProperties().empty() )
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
} }
@ -622,6 +623,7 @@ void PCB_IO::formatProperties( const BOARD* aBoard, int aNestLevel ) const
void PCB_IO::formatHeader( const BOARD* aBoard, int aNestLevel ) const void PCB_IO::formatHeader( const BOARD* aBoard, int aNestLevel ) const
{ {
formatGeneral( aBoard, aNestLevel ); formatGeneral( aBoard, aNestLevel );
// Layers list. // Layers list.
formatBoardLayers( aBoard, aNestLevel ); formatBoardLayers( aBoard, aNestLevel );
@ -648,7 +650,6 @@ void PCB_IO::format( const BOARD* aBoard, int aNestLevel ) const
aBoard->Zones().end() ); aBoard->Zones().end() );
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(), std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(),
aBoard->Groups().end() ); aBoard->Groups().end() );
formatHeader( aBoard, aNestLevel ); formatHeader( aBoard, aNestLevel );
// Save the footprints. // Save the footprints.
@ -822,14 +823,16 @@ void PCB_IO::format( const PCB_SHAPE* aShape, int aNestLevel ) const
{ {
int nestLevel = 0; int nestLevel = 0;
if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) )
{ {
// newline every 4 pts.
nestLevel = aNestLevel + 1; nestLevel = aNestLevel + 1;
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
} }
m_out->Print( nestLevel, "%s(xy %s)", m_out->Print( nestLevel, "%s(xy %s)",
nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() ); nestLevel ? "" : " ",
FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
} }
m_out->Print( 0, ")" ); m_out->Print( 0, ")" );
@ -921,14 +924,16 @@ void PCB_IO::format( const FP_SHAPE* aFPShape, int aNestLevel ) const
{ {
int nestLevel = 0; int nestLevel = 0;
if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) ) // newline every 4 pts if( ii && ( !( ii%4 ) || !ADVANCED_CFG::GetCfg().m_CompactSave ) )
{ {
// newline every 4 pts.
nestLevel = aNestLevel + 1; nestLevel = aNestLevel + 1;
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
} }
m_out->Print( nestLevel, "%s(xy %s)", m_out->Print( nestLevel, "%s(xy %s)",
nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() ); nestLevel ? "" : " ",
FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
} }
m_out->Print( 0, ")" ); m_out->Print( 0, ")" );
@ -1038,7 +1043,8 @@ void PCB_IO::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
if( !( m_ctl & CTL_OMIT_AT ) ) if( !( m_ctl & CTL_OMIT_AT ) )
{ {
m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aFootprint->GetPosition() ).c_str() ); m_out->Print( aNestLevel+1, "(at %s",
FormatInternalUnits( aFootprint->GetPosition() ).c_str() );
if( aFootprint->GetOrientation() != 0.0 ) if( aFootprint->GetOrientation() != 0.0 )
m_out->Print( 0, " %s", FormatAngle( aFootprint->GetOrientation() ).c_str() ); m_out->Print( 0, " %s", FormatAngle( aFootprint->GetOrientation() ).c_str() );
@ -1124,12 +1130,13 @@ void PCB_IO::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
m_out->Print( 0, ")\n" ); m_out->Print( 0, ")\n" );
} }
Format((BOARD_ITEM*) &aFootprint->Reference(), aNestLevel + 1 ); Format( (BOARD_ITEM*) &aFootprint->Reference(), aNestLevel + 1 );
Format((BOARD_ITEM*) &aFootprint->Value(), aNestLevel + 1 ); Format( (BOARD_ITEM*) &aFootprint->Value(), aNestLevel + 1 );
std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->Pads().begin(), std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->Pads().begin(),
aFootprint->Pads().end() ); aFootprint->Pads().end() );
std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings( aFootprint->GraphicalItems().begin(), std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings(
aFootprint->GraphicalItems().begin(),
aFootprint->GraphicalItems().end() ); aFootprint->GraphicalItems().end() );
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aFootprint->Zones().begin(), std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aFootprint->Zones().begin(),
aFootprint->Zones().end() ); aFootprint->Zones().end() );
@ -1185,6 +1192,7 @@ void PCB_IO::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
m_out->Print( aNestLevel+1, ")\n" ); m_out->Print( aNestLevel+1, ")\n" );
} }
++bs3D; ++bs3D;
} }
@ -1207,7 +1215,7 @@ void PCB_IO::formatLayers( LSET aLayerMask, int aNestLevel ) const
static const LSET paste( 2, B_Paste, F_Paste ); static const LSET paste( 2, B_Paste, F_Paste );
static const LSET silks( 2, B_SilkS, F_SilkS ); static const LSET silks( 2, B_SilkS, F_SilkS );
static const LSET mask( 2, B_Mask, F_Mask ); static const LSET mask( 2, B_Mask, F_Mask );
static const LSET crt_yd(2, B_CrtYd, F_CrtYd ); static const LSET crt_yd( 2, B_CrtYd, F_CrtYd );
static const LSET fab( 2, B_Fab, F_Fab ); static const LSET fab( 2, B_Fab, F_Fab );
LSET cu_mask = cu_all; LSET cu_mask = cu_all;
@ -1262,7 +1270,6 @@ void PCB_IO::formatLayers( LSET aLayerMask, int aNestLevel ) const
} }
// output any individual layers not handled in wildcard combos above // output any individual layers not handled in wildcard combos above
wxString layerName; wxString layerName;
for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer ) for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
@ -1314,7 +1321,7 @@ void PCB_IO::format( const PAD* aPad, int aNestLevel ) const
switch( aPad->GetProperty() ) switch( aPad->GetProperty() )
{ {
case PAD_PROP_NONE: break; // could be also "none" case PAD_PROP_NONE: break; // could be "none"
case PAD_PROP_BGA: property = "pad_prop_bga"; break; case PAD_PROP_BGA: property = "pad_prop_bga"; break;
case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break; case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break; case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
@ -1343,7 +1350,7 @@ void PCB_IO::format( const PAD* aPad, int aNestLevel ) const
m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() ); m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) ) if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() ); m_out->Print( 0, " (rect_delta %s)", FormatInternalUnits( aPad->GetDelta() ).c_str() );
wxSize sz = aPad->GetDrillSize(); wxSize sz = aPad->GetDrillSize();
wxPoint shapeoffset = aPad->GetOffset(); wxPoint shapeoffset = aPad->GetOffset();
@ -1663,8 +1670,8 @@ void PCB_IO::format( const PCB_GROUP* aGroup, int aNestLevel ) const
for( const wxString& memberId : memberIds ) for( const wxString& memberId : memberIds )
m_out->Print( aNestLevel + 2, "%s\n", TO_UTF8( memberId ) ); m_out->Print( aNestLevel + 2, "%s\n", TO_UTF8( memberId ) );
m_out->Print( 0, " )\n" ); m_out->Print( aNestLevel + 1, ")\n" ); // Close `members` token.
m_out->Print( aNestLevel, ")\n" ); m_out->Print( aNestLevel, ")\n" ); // Close `group` token.
} }
@ -1739,8 +1746,8 @@ void PCB_IO::format( const TRACK* aTrack, int aNestLevel ) const
const VIA* via = static_cast<const VIA*>( aTrack ); const VIA* via = static_cast<const VIA*>( aTrack );
BOARD* board = (BOARD*) via->GetParent(); BOARD* board = (BOARD*) via->GetParent();
wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( EDA_UNITS::MILLIMETRES ) wxCHECK_RET( board != 0, wxT( "Via " ) +
+ wxT( " has no parent." ) ); via->GetSelectMenuText( EDA_UNITS::MILLIMETRES ) + wxT( " has no parent." ) );
m_out->Print( aNestLevel, "(via" ); m_out->Print( aNestLevel, "(via" );
@ -1902,7 +1909,9 @@ void PCB_IO::format( const ZONE* aZone, int aNestLevel ) const
if( aZone->GetIsRuleArea() ) if( aZone->GetIsRuleArea() )
{ {
m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (pads %s ) (copperpour %s) (footprints %s))\n", m_out->Print( aNestLevel + 1,
"(keepout (tracks %s) (vias %s) (pads %s ) (copperpour %s) "
"(footprints %s))\n",
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed", aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed", aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed", aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
@ -1910,7 +1919,7 @@ void PCB_IO::format( const ZONE* aZone, int aNestLevel ) const
aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" ); aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
} }
m_out->Print( aNestLevel+1, "(fill" ); m_out->Print( aNestLevel + 1, "(fill" );
// Default is not filled. // Default is not filled.
if( aZone->IsFilled() ) if( aZone->IsFilled() )
@ -2427,7 +2436,8 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFoot
footprint->SetParent( nullptr ); footprint->SetParent( nullptr );
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath ); wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
footprints.insert( footprintName, new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) ); footprints.insert( footprintName,
new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) );
m_cache->Save( footprint ); m_cache->Save( footprint );
} }
@ -2487,7 +2497,8 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( !fn.IsDirWritable() ) if( !fn.IsDirWritable() )
{ {
THROW_IO_ERROR( wxString::Format( _( "User does not have permission to delete directory \"%s\"." ), THROW_IO_ERROR( wxString::Format( _( "User does not have permission to delete directory "
"\"%s\"." ),
aLibraryPath.GetData() ) ); aLibraryPath.GetData() ) );
} }
@ -2495,7 +2506,8 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( dir.HasSubDirs() ) if( dir.HasSubDirs() )
{ {
THROW_IO_ERROR( wxString::Format( _( "Library directory \"%s\" has unexpected sub-directories." ), THROW_IO_ERROR( wxString::Format( _( "Library directory \"%s\" has unexpected "
"sub-directories." ),
aLibraryPath.GetData() ) ); aLibraryPath.GetData() ) );
} }
@ -2514,7 +2526,8 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( tmp.GetExt() != KiCadFootprintFileExtension ) if( tmp.GetExt() != KiCadFootprintFileExtension )
{ {
THROW_IO_ERROR( wxString::Format( _( "Unexpected file \"%s\" was found in library path \"%s\"." ), THROW_IO_ERROR( wxString::Format( _( "Unexpected file \"%s\" was found in "
"library path \"%s\"." ),
files[i].GetData(), aLibraryPath.GetData() ) ); files[i].GetData(), aLibraryPath.GetData() ) );
} }
} }