diff --git a/pcbnew/action_plugin.cpp b/pcbnew/action_plugin.cpp
index f2ec024e6b..24f299dc5d 100644
--- a/pcbnew/action_plugin.cpp
+++ b/pcbnew/action_plugin.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -67,7 +67,7 @@ ACTION_PLUGIN* ACTION_PLUGINS::GetActionByMenu( int aMenu )
             return m_actionsList[i];
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -87,7 +87,7 @@ ACTION_PLUGIN* ACTION_PLUGINS::GetActionByButton( int aButton )
             return m_actionsList[i];
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -107,7 +107,7 @@ ACTION_PLUGIN* ACTION_PLUGINS::GetActionByPath(const wxString& aPath)
         }
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -125,7 +125,7 @@ ACTION_PLUGIN* ACTION_PLUGINS::GetAction( const wxString& aName )
             return action;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -190,6 +190,7 @@ bool ACTION_PLUGINS::deregister_object( void* aObject )
         if( action->GetObject() == aObject )
         {
             m_actionsList.erase( m_actionsList.begin() + i );
+
             //m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
             delete action;
             return true;
diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp
index 5ba5ff4fb2..16e66dce1b 100644
--- a/pcbnew/array_creator.cpp
+++ b/pcbnew/array_creator.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Created on: 11 Mar 2016, author John Beard
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -64,7 +64,7 @@ void ARRAY_CREATOR::Invoke()
 
     int ret = dialog.ShowModal();
 
-    if( ret != wxID_OK || array_opts == NULL )
+    if( ret != wxID_OK || array_opts == nullptr )
         return;
 
     BOARD_COMMIT commit( &m_parent );
diff --git a/pcbnew/autorouter/ar_autoplacer.cpp b/pcbnew/autorouter/ar_autoplacer.cpp
index 30134a5c0f..0a4da8d05d 100644
--- a/pcbnew/autorouter/ar_autoplacer.cpp
+++ b/pcbnew/autorouter/ar_autoplacer.cpp
@@ -3,9 +3,9 @@
  *
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
+ * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  *
- * Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -139,6 +139,7 @@ int AR_AUTOPLACER::genPlacementRoutingMatrix()
                 m_matrix.TraceSegmentPcb( (PCB_SHAPE*) drawing, CELL_IS_HOLE | CELL_IS_EDGE,
                                           m_matrix.m_GridRouting, AR_MATRIX::WRITE_CELL );
             }
+
             break;
 
         default:
@@ -272,7 +273,7 @@ bool AR_AUTOPLACER::fillMatrix()
 
 void AR_AUTOPLACER::rotateFootprint( FOOTPRINT* aFootprint, double angle, bool incremental )
 {
-    if( aFootprint == NULL )
+    if( aFootprint == nullptr )
         return;
 
     if( incremental )
@@ -296,6 +297,7 @@ void AR_AUTOPLACER::addFpBody( wxPoint aStart, wxPoint aEnd, LSET aLayerMask )
         m_fpAreaTop.Append( aEnd.x, aEnd.y );
         m_fpAreaTop.Append( aStart.x, aEnd.y );
     }
+
     if( aLayerMask[ B_Cu ] )
     {
         m_fpAreaBottom.NewOutline();
@@ -320,6 +322,7 @@ void AR_AUTOPLACER::addPad( PAD* aPad, int aClearance )
         m_fpAreaTop.Append( bbox.GetRight(), bbox.GetBottom() );
         m_fpAreaTop.Append( bbox.GetLeft(), bbox.GetBottom() );
     }
+
     if( aPad->IsOnLayer( B_Cu ) )
     {
         m_fpAreaBottom.NewOutline();
@@ -407,7 +410,7 @@ void AR_AUTOPLACER::genModuleOnRoutingMatrix( FOOTPRINT* Module )
         layerMask.set( B_Cu );
 
     m_matrix.TraceFilledRectangle( ox, oy, fx, fy, layerMask,
-                          CELL_IS_MODULE, AR_MATRIX::WRITE_OR_CELL );
+                                   CELL_IS_MODULE, AR_MATRIX::WRITE_OR_CELL );
 
     // Trace pads + clearance areas.
     for( PAD* pad : Module->Pads() )
@@ -429,12 +432,6 @@ void AR_AUTOPLACER::genModuleOnRoutingMatrix( FOOTPRINT* Module )
 }
 
 
-/* Test if the rectangular area (ux, ux .. y0, y1):
- * - is a free zone (except OCCUPED_By_MODULE returns)
- * - is on the working surface of the board (otherwise returns OUT_OF_BOARD)
- *
- * Returns OUT_OF_BOARD, or OCCUPED_By_MODULE or FREE_CELL if OK
- */
 int AR_AUTOPLACER::testRectangle( const EDA_RECT& aRect, int side )
 {
     EDA_RECT rect = aRect;
@@ -488,10 +485,6 @@ int AR_AUTOPLACER::testRectangle( const EDA_RECT& aRect, int side )
 }
 
 
-/* Calculates and returns the clearance area of the rectangular surface
- * aRect):
- * (Sum of cells in terms of distance)
- */
 unsigned int AR_AUTOPLACER::calculateKeepOutArea( const EDA_RECT& aRect, int side )
 {
     wxPoint start   = aRect.GetOrigin();
@@ -541,10 +534,6 @@ unsigned int AR_AUTOPLACER::calculateKeepOutArea( const EDA_RECT& aRect, int sid
 }
 
 
-/* Test if the footprint can be placed on the board.
- * Returns the value TstRectangle().
- * Module is known by its bounding box
- */
 int AR_AUTOPLACER::testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide,
                                          const wxPoint& aOffset )
 {
@@ -693,7 +682,8 @@ const PAD* AR_AUTOPLACER::nearestPad( FOOTPRINT *aRefFP, PAD* aRefPad, const wxP
             if( pad->GetNetCode() != aRefPad->GetNetCode() || pad->GetNetCode() <= 0 )
                 continue;
 
-            auto dist = (VECTOR2I( aRefPad->GetPosition() - aOffset ) - VECTOR2I( pad->GetPosition() ) ).EuclideanNorm();
+            auto dist = ( VECTOR2I( aRefPad->GetPosition() - aOffset ) -
+                          VECTOR2I( pad->GetPosition() ) ).EuclideanNorm();
 
             if ( dist < nearestDist )
             {
@@ -737,7 +727,7 @@ double AR_AUTOPLACER::computePlacementRatsnestCost( FOOTPRINT *aFootprint, const
         dx  = abs( dx );
         dy  = abs( dy );
 
-        // ttry to have always dx >= dy to calculate the cost of the rastsnet
+        // ttry to have always dx >= dy to calculate the cost of the ratsnest
         if( dx < dy )
             std::swap( dx, dy );
 
@@ -776,7 +766,7 @@ static bool sortFootprintsByRatsnestSize( FOOTPRINT* ref, FOOTPRINT* compare )
 }
 
 
-FOOTPRINT* AR_AUTOPLACER::pickFootprint( )
+FOOTPRINT* AR_AUTOPLACER::pickFootprint()
 {
     std::vector<FOOTPRINT*> fpList;
 
@@ -947,8 +937,8 @@ AR_RESULT AR_AUTOPLACER::AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprin
         //m_frame->SetStatusText( msg );
 
         if( m_progressReporter )
-            m_progressReporter->SetTitle( wxString::Format(
-                    _( "Autoplacing %s" ), footprint->GetReference() ) );
+            m_progressReporter->SetTitle( wxString::Format( _( "Autoplacing %s" ),
+                                                            footprint->GetReference() ) );
 
         double initialOrient = footprint->GetOrientation();
 
@@ -1061,6 +1051,7 @@ end_of_tst:
                 break;
             }
         }
+
         cnt++;
     }
 
diff --git a/pcbnew/board_connected_item.cpp b/pcbnew/board_connected_item.cpp
index c6f6ec71da..38c94a2367 100644
--- a/pcbnew/board_connected_item.cpp
+++ b/pcbnew/board_connected_item.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -60,14 +60,10 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
     if( !aNoAssert )
         wxASSERT( m_netinfo );
 
-    return ( m_netinfo != NULL );
+    return ( m_netinfo != nullptr );
 }
 
 
-/*
- * This method returns the Default netclass for nets which don't have their own, and the
- * Orphaned netclass for unassigned nets (netCode == 0)
- */
 NETCLASS* BOARD_CONNECTED_ITEM::GetEffectiveNetclass() const
 {
     // NB: we must check the net first, as when it is 0 GetNetClass() will return the
@@ -79,9 +75,6 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetEffectiveNetclass() const
 }
 
 
-/*
- * Returns the item's "own" clearance (ie: that not affected by other items).
- */
 int BOARD_CONNECTED_ITEM::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
 {
     DRC_CONSTRAINT constraint;
diff --git a/pcbnew/board_connected_item.h b/pcbnew/board_connected_item.h
index 8faab2fa65..ac92448116 100644
--- a/pcbnew/board_connected_item.h
+++ b/pcbnew/board_connected_item.h
@@ -46,7 +46,7 @@ public:
 
     static inline bool ClassOf( const EDA_ITEM* aItem )
     {
-        if( aItem == NULL )
+        if( aItem == nullptr )
             return false;
 
         switch( aItem->Type() )
diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp
index 93d2f8db3a..f61a27fdbe 100644
--- a/pcbnew/board_item.cpp
+++ b/pcbnew/board_item.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -57,7 +57,7 @@ BOARD* BOARD_ITEM::GetBoard() const
     if( parent )
         return parent->GetBoard();
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -135,7 +135,8 @@ void BOARD_ITEM::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBu
                                                        int aError, ERROR_LOC aErrorLoc,
                                                        bool ignoreLineWidth ) const
 {
-    wxASSERT_MSG( false, "Called TransformShapeWithClearanceToPolygon() on unsupported BOARD_ITEM." );
+    wxASSERT_MSG( false,
+                  "Called TransformShapeWithClearanceToPolygon() on unsupported BOARD_ITEM." );
 };
 
 
@@ -147,7 +148,7 @@ bool BOARD_ITEM::ptr_cmp::operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b
     if( a->GetLayer() != b->GetLayer() )
         return a->GetLayer() < b->GetLayer();
 
-    if( a->m_Uuid != b->m_Uuid )    // shopuld be always the case foer valid boards
+    if( a->m_Uuid != b->m_Uuid )    // should be always the case for valid boards
         return a->m_Uuid < b->m_Uuid;
 
     return a < b;
diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp
index 47f4d8f046..6451a684f0 100644
--- a/pcbnew/board_items_to_polygon_shape_transform.cpp
+++ b/pcbnew/board_items_to_polygon_shape_transform.cpp
@@ -55,6 +55,7 @@ struct TSEGM_2_POLY_PRMS
     SHAPE_POLY_SET* m_cornerBuffer;
 };
 
+
 TSEGM_2_POLY_PRMS prms;
 
 
@@ -67,7 +68,8 @@ static void addTextSegmToPoly( int x0, int y0, int xf, int yf, void* aData )
 }
 
 
-void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines ) const
+void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer,
+                                                SHAPE_POLY_SET& aOutlines ) const
 {
     int maxError = GetDesignSettings().m_MaxError;
 
@@ -120,16 +122,16 @@ void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_
             const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( item );
             shape->TransformShapeWithClearanceToPolygon( aOutlines, aLayer, 0, maxError,
                                                          ERROR_INSIDE );
-        }
             break;
+        }
 
         case PCB_TEXT_T:
         {
             const PCB_TEXT* text = static_cast<const PCB_TEXT*>( item );
             text->TransformTextShapeWithClearanceToPolygon( aOutlines, aLayer, 0, maxError,
                                                             ERROR_INSIDE );
-        }
             break;
+        }
 
         default:
             break;
@@ -164,11 +166,13 @@ void FOOTPRINT::TransformPadsWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuff
                 case PAD_SHAPE::CIRCLE:
                     if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
                         continue;
+
                     break;
 
                 case PAD_SHAPE::OVAL:
                     if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
                         continue;
+
                     break;
 
                 default:
@@ -283,12 +287,6 @@ void FOOTPRINT::TransformFPShapesWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
 }
 
 
-/**
- * Convert the text to a polygonSet describing the actual character strokes (one per segment).
- * @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
- * @aClearanceValue = the clearance around the text
- * @aError = the maximum error to allow when approximating curves
- */
 void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
                                                         PCB_LAYER_ID aLayer, int aClearance,
                                                         int aError, ERROR_LOC aErrorLoc ) const
@@ -302,8 +300,9 @@ void FP_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerB
     if( IsMirrored() )
         size.x = -size.x;
 
-    GRText( NULL, GetTextPos(), BLACK, GetShownText(), GetDrawRotation(), size, GetHorizJustify(),
-            GetVertJustify(), penWidth, IsItalic(), IsBold(), addTextSegmToPoly, &prms );
+    GRText( nullptr, GetTextPos(), BLACK, GetShownText(), GetDrawRotation(), size,
+            GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(),
+            addTextSegmToPoly, &prms );
 }
 
 
@@ -383,15 +382,9 @@ void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCorn
 }
 
 
-/**
- * Convert the text to a polygonSet describing the actual character strokes (one per segment).
- * @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
- * @aClearanceValue = the clearance around the text
- * @aError = the maximum error to allow when approximating curves
- */
 void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
-                                                     PCB_LAYER_ID aLayer, int aClearanceValue,
-                                                     int aError, ERROR_LOC aErrorLoc ) const
+                                                         PCB_LAYER_ID aLayer, int aClearanceValue,
+                                                         int aError, ERROR_LOC aErrorLoc ) const
 {
     wxSize size = GetTextSize();
 
@@ -405,15 +398,15 @@ void PCB_TEXT::TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCorner
     prms.m_error = aError;
     COLOR4D color;  // not actually used, but needed by GRText
 
-    GRText( NULL, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
+    GRText( nullptr, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
             GetVertJustify(), penWidth, IsItalic(), IsBold(), addTextSegmToPoly, &prms );
 }
 
 
 void PCB_TEXT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
-                                                    PCB_LAYER_ID aLayer, int aClearance,
-                                                    int aError, ERROR_LOC aErrorLoc,
-                                                    bool aIgnoreLineWidth ) const
+                                                     PCB_LAYER_ID aLayer, int aClearance,
+                                                     int aError, ERROR_LOC aErrorLoc,
+                                                     bool aIgnoreLineWidth ) const
 {
     EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( &aCornerBuffer, aClearance );
 }
@@ -441,6 +434,7 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
             TransformRingToPolygon( aCornerBuffer, GetCenter(), GetRadius(), width, aError,
                                     aErrorLoc );
         }
+
         break;
 
     case PCB_SHAPE_TYPE::RECT:
@@ -463,8 +457,9 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
             TransformOvalToPolygon( aCornerBuffer, pts[2], pts[3], width, aError, aErrorLoc );
             TransformOvalToPolygon( aCornerBuffer, pts[3], pts[0], width, aError, aErrorLoc );
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::ARC:
         TransformArcToPolygon( aCornerBuffer, GetArcStart(), GetArcMid(), GetArcEnd(), width,
@@ -518,8 +513,9 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
                 pt1 = pt2;
             }
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::CURVE: // Bezier curve
     {
@@ -530,10 +526,12 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
 
         for( unsigned ii = 1; ii < poly.size(); ii++ )
         {
-            TransformOvalToPolygon( aCornerBuffer, poly[ii - 1], poly[ii], width, aError, aErrorLoc );
+            TransformOvalToPolygon( aCornerBuffer, poly[ii - 1], poly[ii], width, aError,
+                                    aErrorLoc );
         }
-    }
+
         break;
+    }
 
     default:
         wxFAIL_MSG( "PCB_SHAPE::TransformShapeWithClearanceToPolygon no implementation for "
@@ -557,8 +555,8 @@ void PCB_TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
     {
         int radius = ( m_Width / 2 ) + aClearanceValue;
         TransformCircleToPolygon( aCornerBuffer, m_Start, radius, aError, aErrorLoc );
-    }
         break;
+    }
 
     case PCB_ARC_T:
     {
@@ -567,17 +565,17 @@ void PCB_TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
 
         TransformArcToPolygon( aCornerBuffer, arc->GetStart(), arc->GetMid(),
                                arc->GetEnd(), width, aError, aErrorLoc );
-    }
         break;
+    }
 
     default:
     {
         int width = m_Width + ( 2 * aClearanceValue );
 
         TransformOvalToPolygon( aCornerBuffer, m_Start, m_End, width, aError, aErrorLoc );
-    }
         break;
     }
+    }
 }
 
 
@@ -633,8 +631,8 @@ void PAD::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
         TransformTrapezoidToPolygon( outline, padShapePos, m_size, angle, ddx, ddy,
                                      aClearanceValue, aError, aErrorLoc );
         aCornerBuffer.Append( outline );
-    }
         break;
+    }
 
     case PAD_SHAPE::CHAMFERED_RECT:
     case PAD_SHAPE::ROUNDRECT:
@@ -648,8 +646,8 @@ void PAD::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
                                               doChamfer ? GetChamferPositions() : 0,
                                               aClearanceValue, aError, aErrorLoc );
         aCornerBuffer.Append( outline );
-    }
         break;
+    }
 
     case PAD_SHAPE::CUSTOM:
     {
@@ -676,8 +674,8 @@ void PAD::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
         }
 
         aCornerBuffer.Append( outline );
-    }
         break;
+    }
 
     default:
         wxFAIL_MSG( "PAD::TransformShapeWithClearanceToPolygon no implementation for "
@@ -748,7 +746,8 @@ void PCB_DIMENSION_BASE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& a
         }
         else
         {
-            wxFAIL_MSG( "PCB_DIMENSION_BASE::TransformShapeWithClearanceToPolygon unexpected shape type." );
+            wxFAIL_MSG( "PCB_DIMENSION_BASE::TransformShapeWithClearanceToPolygon unexpected "
+                        "shape type." );
         }
     }
 }
diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp
index 9e7a6dd7f2..d8f954c96c 100644
--- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp
+++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp
@@ -210,7 +210,9 @@ void PANEL_SETUP_BOARD_STACKUP::onAdjustDielectricThickness( wxCommandEvent& eve
         }
     }
     else
+    {
         wxMessageBox( _( "All dielectric  thickness layers are locked" ) );
+    }
 
     computeBoardThickness();
 }
@@ -227,7 +229,7 @@ void PANEL_SETUP_BOARD_STACKUP::disconnectEvents()
         {
             cb->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED,
                             wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onColorSelected ),
-                            NULL, this );
+                            nullptr, this );
         }
 
         wxButton* matButt = dynamic_cast<wxButton*>( item );
@@ -236,7 +238,7 @@ void PANEL_SETUP_BOARD_STACKUP::disconnectEvents()
         {
             matButt->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
                                  wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onMaterialChange ),
-                                 NULL, this );
+                                 nullptr, this );
         }
 
         wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( item );
@@ -245,7 +247,7 @@ void PANEL_SETUP_BOARD_STACKUP::disconnectEvents()
         {
             textCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED,
                                   wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onThicknessChange ),
-                                  NULL, this );
+                                  nullptr, this );
         }
     }
 }
@@ -391,7 +393,7 @@ void PANEL_SETUP_BOARD_STACKUP::onExportToClipboard( wxCommandEvent& event )
     if( !transferDataFromUIToStackup() )
         return;
 
-    // Build a ascii representation of stackup and copy it in the clipboard
+    // Build a ASCII representation of stackup and copy it in the clipboard
     wxString report = BuildStackupReport( m_stackup, m_units );
 
     wxLogNull doNotLog; // disable logging of failed clipboard actions
@@ -631,8 +633,7 @@ void PANEL_SETUP_BOARD_STACKUP::showOnlyActiveLayers()
 }
 
 
-void PANEL_SETUP_BOARD_STACKUP::addMaterialChooser( wxWindowID aId,
-                                                    const wxString * aMaterialName,
+void PANEL_SETUP_BOARD_STACKUP::addMaterialChooser( wxWindowID aId, const wxString* aMaterialName,
                                                     BOARD_STACKUP_ROW_UI_ITEM& aUiRowItem )
 {
 	wxBoxSizer* bSizerMat = new wxBoxSizer( wxHORIZONTAL );
@@ -651,12 +652,12 @@ void PANEL_SETUP_BOARD_STACKUP::addMaterialChooser( wxWindowID aId,
 	bSizerMat->Add( textCtrl, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
 
 	wxButton* m_buttonMat = new wxButton( m_scGridWin, aId, _( "..." ), wxDefaultPosition,
-                                         wxDefaultSize, wxBU_EXACTFIT );
+                                          wxDefaultSize, wxBU_EXACTFIT );
 	bSizerMat->Add( m_buttonMat, 0, wxALIGN_CENTER_VERTICAL, 2 );
 
     m_buttonMat->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
                           wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onMaterialChange ),
-                          NULL, this );
+                          nullptr, this );
     m_controlItemsList.push_back( m_buttonMat );
 
     aUiRowItem.m_MaterialCtrl = textCtrl;
@@ -761,7 +762,7 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow,
         m_controlItemsList.push_back( textCtrl );
         textCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED,
                            wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onThicknessChange ),
-                           NULL, this );
+                           nullptr, this );
         ui_row_item.m_ThicknessCtrl = textCtrl;
 
         if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
@@ -1021,7 +1022,8 @@ bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup()
             else
             {
                 success = false;
-                error_msg << _( "Incorrect value for Epsilon R (Epsilon R must be positive or null if not used)" );
+                error_msg << _( "Incorrect value for Epsilon R (Epsilon R must be positive or "
+                                "null if not used)" );
             }
         }
 
@@ -1041,7 +1043,8 @@ bool PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup()
                 if( !error_msg.IsEmpty() )
                     error_msg << "\n";
 
-                error_msg << _( "Incorrect value for Loss tg (Loss tg must be positive or null if not used)" );
+                error_msg << _( "Incorrect value for Loss tg (Loss tg must be positive or null "
+                                "if not used)" );
             }
         }
 
@@ -1266,8 +1269,7 @@ void PANEL_SETUP_BOARD_STACKUP::onColorSelected( wxCommandEvent& event )
             combo->SetString( idx, label );
 
             wxBitmap layerbmp( m_colorSwatchesSize.x, m_colorSwatchesSize.y );
-            LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ),
-                                             COLOR4D( color ) );
+            LAYER_SELECTOR::DrawColorSwatch( layerbmp, COLOR4D( 0, 0, 0, 0 ), COLOR4D( color ) );
             combo->SetItemBitmap( combo->GetCount()-1, layerbmp );
         }
     }
@@ -1506,7 +1508,7 @@ wxBitmapComboBox* PANEL_SETUP_BOARD_STACKUP::createBmComboBox( BOARD_STACKUP_ITE
 
     combo->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED,
                     wxCommandEventHandler( PANEL_SETUP_BOARD_STACKUP::onColorSelected ),
-                    NULL, this );
+                    nullptr, this );
 
     return combo;
 }
@@ -1530,7 +1532,7 @@ void drawBitmap( wxBitmap& aBitmap, wxColor aColor )
         }
 
         p = rowStart;
-        p.OffsetY(data, 1);
+        p.OffsetY( data, 1 );
     }
 }
 
diff --git a/pcbnew/build_BOM_from_board.cpp b/pcbnew/build_BOM_from_board.cpp
index 68ee01e80a..484067884a 100644
--- a/pcbnew/build_BOM_from_board.cpp
+++ b/pcbnew/build_BOM_from_board.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2009-2014 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -64,6 +64,7 @@ public:
     int      m_Id;
     int      m_Count;
 };
+
 WX_DECLARE_LIST( BOM_ENTRY, BOM_ENTRY_LIST );
 
 WX_DEFINE_LIST( BOM_ENTRY_LIST )
@@ -97,7 +98,7 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent )
 
     fp_bom = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
 
-    if( fp_bom == NULL )
+    if( fp_bom == nullptr )
     {
         msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
         DisplayError( this, msg );
@@ -169,7 +170,7 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent )
 
         // We do not need this object, now: remove it from list and delete it
         list.DeleteObject( curEntry );
-        delete (curEntry);
+        delete curEntry;
     }
 
     fclose( fp_bom );
diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp
index dfd6684e92..2728810292 100644
--- a/pcbnew/collectors.cpp
+++ b/pcbnew/collectors.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -231,7 +231,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
 
 #endif
 
-
     switch( item->Type() )
     {
     case PCB_PAD_T:
@@ -243,8 +242,8 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
         // for through pads: pads on Front or Back board sides must be visible
         pad = static_cast<PAD*>( item );
 
-        if( (pad->GetAttribute() != PAD_ATTRIB::SMD) &&
-            (pad->GetAttribute() != PAD_ATTRIB::CONN) )   // a hole is present, so multiple layers
+        if( ( pad->GetAttribute() != PAD_ATTRIB::SMD ) &&
+            ( pad->GetAttribute() != PAD_ATTRIB::CONN ) )  // a hole is present, so multiple layers
         {
             // proceed to the common tests below, but without the parent footprint test,
             // by leaving footprint==NULL, but having pad != null
@@ -265,6 +264,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
     case PCB_ARC_T:
         if( m_Guide->IgnoreTracks() )
             goto exit;
+
         break;
 
     case PCB_FP_ZONE_T:
@@ -295,46 +295,50 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
         break;
 
     case PCB_FP_TEXT_T:
+    {
+        FP_TEXT *text = static_cast<FP_TEXT*>( item );
+
+        if( m_Guide->IgnoreHiddenFPText() && !text->IsVisible() )
+            goto exit;
+
+        if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( text->GetLayer() ) )
+            goto exit;
+
+        if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( text->GetLayer() ) )
+            goto exit;
+
+        /* The three text types have different criteria: reference
+         * and value have their own ignore flags; user text instead
+         * follows their layer visibility. Checking this here is
+         * simpler than later (when layer visibility is checked for
+         * other entities) */
+
+        switch( text->GetType() )
         {
-            FP_TEXT *text = static_cast<FP_TEXT*>( item );
-            if( m_Guide->IgnoreHiddenFPText() && !text->IsVisible() )
+        case FP_TEXT::TEXT_is_REFERENCE:
+            if( m_Guide->IgnoreFPReferences() )
                 goto exit;
 
-            if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( text->GetLayer() ) )
+            break;
+
+        case FP_TEXT::TEXT_is_VALUE:
+            if( m_Guide->IgnoreFPValues() )
                 goto exit;
 
-            if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( text->GetLayer() ) )
+            break;
+
+        case FP_TEXT::TEXT_is_DIVERS:
+            if( !m_Guide->IsLayerVisible( text->GetLayer() )
+              && m_Guide->IgnoreNonVisibleLayers() )
                 goto exit;
 
-            /* The three text types have different criteria: reference
-             * and value have their own ignore flags; user text instead
-             * follows their layer visibility. Checking this here is
-             * simpler than later (when layer visibility is checked for
-             * other entities) */
-
-            switch( text->GetType() )
-            {
-            case FP_TEXT::TEXT_is_REFERENCE:
-                if( m_Guide->IgnoreFPReferences() )
-                    goto exit;
-                break;
-
-            case FP_TEXT::TEXT_is_VALUE:
-                if( m_Guide->IgnoreFPValues() )
-                    goto exit;
-                break;
-
-            case FP_TEXT::TEXT_is_DIVERS:
-                if( !m_Guide->IsLayerVisible( text->GetLayer() )
-                        && m_Guide->IgnoreNonVisibleLayers() )
-                    goto exit;
-                break;
-            }
-
-            // Extract the footprint since it could be hidden
-            footprint = static_cast<FOOTPRINT*>( item->GetParent() );
+            break;
         }
+
+        // Extract the footprint since it could be hidden
+        footprint = static_cast<FOOTPRINT*>( item->GetParent() );
         break;
+    }
 
     case PCB_FP_SHAPE_T:
         shape = static_cast<FP_SHAPE*>( item );
@@ -360,10 +364,10 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
 
     if( footprint )    // true from case PCB_PAD_T, PCB_FP_TEXT_T, or PCB_FOOTPRINT_T
     {
-        if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu) )
+        if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu ) )
             goto exit;
 
-        if( m_Guide->IgnoreFootprintsOnFront() && ( footprint->GetLayer() == F_Cu) )
+        if( m_Guide->IgnoreFootprintsOnFront() && ( footprint->GetLayer() == F_Cu ) )
             goto exit;
     }
 
@@ -579,7 +583,7 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
     // the Inspect() function.
     SetRefPos( aRefPos );
 
-    aItem->Visit( m_inspector, NULL, m_scanTypes );
+    aItem->Visit( m_inspector, nullptr, m_scanTypes );
 
     // record the length of the primary list before concatenating on to it.
     m_PrimaryLength = m_list.size();
@@ -606,7 +610,7 @@ void PCB_TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[]
 {
     Empty();        // empty any existing collection
 
-    aBoard->Visit( m_inspector, NULL, aScanList );
+    aBoard->Visit( m_inspector, nullptr, aScanList );
 }
 
 
@@ -625,5 +629,5 @@ void PCB_LAYER_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[]
 {
     Empty();
 
-    aBoard->Visit( m_inspector, NULL, aScanList );
+    aBoard->Visit( m_inspector, nullptr, aScanList );
 }
diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp
index 450a8cff82..29ff27b920 100644
--- a/pcbnew/cross-probing.cpp
+++ b/pcbnew/cross-probing.cpp
@@ -85,9 +85,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
     line[sizeof(line) - 1] = 0;
 
     idcmd = strtok( line, " \n\r" );
-    text  = strtok( NULL, "\"\n\r" );
+    text  = strtok( nullptr, "\"\n\r" );
 
-    if( idcmd == NULL )
+    if( idcmd == nullptr )
         return;
 
     if( strcmp( idcmd, "$NET:" ) == 0 )
@@ -108,6 +108,7 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
             SetMsgPanel( items );
         }
     }
+
     if( strcmp( idcmd, "$NETS:" ) == 0 )
     {
         if( !crossProbingSettings.auto_highlight )
@@ -148,10 +149,10 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
     {
         wxString pinName = FROM_UTF8( text );
 
-        text = strtok( NULL, " \n\r" );
+        text = strtok( nullptr, " \n\r" );
 
         if( text && strcmp( text, "$PART:" ) == 0 )
-            text = strtok( NULL, "\"\n\r" );
+            text = strtok( nullptr, "\"\n\r" );
 
         modName = FROM_UTF8( text );
 
@@ -163,9 +164,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
         if( pad )
             netcode = pad->GetNetCode();
 
-        if( footprint == NULL )
+        if( footprint == nullptr )
             msg.Printf( _( "%s not found" ), modName );
-        else if( pad == NULL )
+        else if( pad == nullptr )
             msg.Printf( _( "%s pin %s not found" ), modName, pinName );
         else
             msg.Printf( _( "%s pin %s found" ), modName, pinName );
@@ -284,7 +285,8 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
             // The "fabs" on x ensures the right answer when the view is flipped
             screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
             screenSize.y = std::max( 10.0, screenSize.y );
-            double ratio = std::max( fabs( bbSize.x / screenSize.x ), fabs( bbSize.y / screenSize.y ) );
+            double ratio = std::max( fabs( bbSize.x / screenSize.x ),
+                                     fabs( bbSize.y / screenSize.y ) );
 
             // Try not to zoom on every cross-probe; it gets very noisy
             if( crossProbingSettings.zoom_to_fit && ( ratio < 0.5 || ratio > 1.0 ) )
@@ -309,19 +311,23 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
             double currTextHeight = Millimeter2iu( DEFAULT_TEXT_SIZE );
 
             double compRatio     = bbSize.y / currTextHeight; // Ratio of component to text height
-            double compRatioBent = 1.0; // This will end up as the scaling factor we apply to "ratio"
 
-            // This is similar to the original KiCad code that scaled the zoom to make sure components
-            // were visible on screen.  It's simply a ratio of screen size to component size, and its
-            // job is to zoom in to make the component fullscreen.  Earlier in the code the
-            // component BBox is given a 20% margin to add some breathing room. We compare
-            // the height of this enlarged component bbox to the default text height.  If a component
-            // will end up with the sides clipped, we adjust later to make sure it fits on screen.
+            // This will end up as the scaling factor we apply to "ratio".
+            double compRatioBent = 1.0;
+
+            // This is similar to the original KiCad code that scaled the zoom to make sure
+            // components were visible on screen.  It's simply a ratio of screen size to
+            // component size, and its job is to zoom in to make the component fullscreen.
+            // Earlier in the code the component BBox is given a 20% margin to add some
+            // breathing room. We compare the height of this enlarged component bbox to the
+            // default text height.  If a component will end up with the sides clipped, we
+            // adjust later to make sure it fits on screen.
             //
             // The "fabs" on x ensures the right answer when the view is flipped
             screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
             screenSize.y = std::max( 10.0, screenSize.y );
             double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
+
             // Original KiCad code for how much to scale the zoom
             double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
                                           fabs( bbSize.y / screenSize.y ) );
@@ -369,19 +375,23 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
                 }
             }
             else
+            {
                 compRatioBent = lut.front().second; // Small component default
+            }
 
             // If the width of the part we're probing is bigger than what the screen width will be
             // after the zoom, then punt and use the KiCad zoom algorithm since it guarantees the
-            // part's width will be encompassed within the screen.  This will apply to parts that are
-            // much wider than they are tall.
+            // part's width will be encompassed within the screen.  This will apply to parts that
+            // are much wider than they are tall.
 
             if( bbSize.x > screenSize.x * ratio * compRatioBent )
             {
-                ratio = kicadRatio; // Use standard KiCad zoom algorithm for parts too wide to fit screen
+                // Use standard KiCad zoom algorithm for parts too wide to fit screen/
+                ratio = kicadRatio;
                 compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
                 wxLogTrace( "CROSS_PROBE_SCALE",
-                        "Part TOO WIDE for screen.  Using normal KiCad zoom ratio: %1.5f", ratio );
+                            "Part TOO WIDE for screen.  Using normal KiCad zoom ratio: %1.5f",
+                            ratio );
             }
 
             // Now that "compRatioBent" holds our final scaling factor we apply it to the original
@@ -389,15 +399,18 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
             ratio *= compRatioBent;
 
             bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
+
             // Try not to zoom on every cross-probe; it gets very noisy
             if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
                 view->SetScale( view->GetScale() / ratio );
 #endif // ifndef DEFAULT_PCBNEW_CODE
         }
+
         view->SetCenter( bbox.Centre() );
     }
 
     view->UpdateAllLayersColor();
+
     // Ensure the display is refreshed, because in some installs the refresh is done only
     // when the gal canvas has the focus, and that is not the case when crossprobing from
     // Eeschema:
@@ -419,36 +432,33 @@ std::string FormatProbeItem( BOARD_ITEM* aItem )
         return StrPrintf( "$PART: \"%s\"", TO_UTF8( footprint->GetReference() ) );
 
     case PCB_PAD_T:
-        {
-            footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
-            wxString pad = static_cast<PAD*>( aItem )->GetName();
+    {
+        footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
+        wxString pad = static_cast<PAD*>( aItem )->GetName();
 
-            return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"",
-                              TO_UTF8( footprint->GetReference() ),
-                              TO_UTF8( pad ) );
-        }
+        return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"", TO_UTF8( footprint->GetReference() ),
+                          TO_UTF8( pad ) );
+    }
 
     case PCB_FP_TEXT_T:
-        {
-            footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
+    {
+        footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
 
-            FP_TEXT*    text = static_cast<FP_TEXT*>( aItem );
-            const char* text_key;
+        FP_TEXT*    text = static_cast<FP_TEXT*>( aItem );
+        const char* text_key;
 
-            /* This can't be a switch since the break need to pull out
-             * from the outer switch! */
-            if( text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
-                text_key = "$REF:";
-            else if( text->GetType() == FP_TEXT::TEXT_is_VALUE )
-                text_key = "$VAL:";
-            else
-                break;
+        /* This can't be a switch since the break need to pull out
+         * from the outer switch! */
+        if( text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
+            text_key = "$REF:";
+        else if( text->GetType() == FP_TEXT::TEXT_is_VALUE )
+            text_key = "$VAL:";
+        else
+            break;
 
-            return StrPrintf( "$PART: \"%s\" %s \"%s\"",
-                              TO_UTF8( footprint->GetReference() ),
-                              text_key,
-                              TO_UTF8( text->GetText() ) );
-        }
+        return StrPrintf( "$PART: \"%s\" %s \"%s\"", TO_UTF8( footprint->GetReference() ), text_key,
+                          TO_UTF8( text->GetText() ) );
+    }
 
     default:
         break;
@@ -458,14 +468,6 @@ std::string FormatProbeItem( BOARD_ITEM* aItem )
 }
 
 
-/* Send a remote command to Eeschema via a socket,
- * aSyncItem = item to be located on schematic (footprint, pin or text)
- * Commands are
- * $PART: "reference"   put cursor on component anchor
- * $PART: "reference" $PAD: "pad number" put cursor on the component pin
- * $PART: "reference" $REF: "reference" put cursor on the component ref
- * $PART: "reference" $VAL: "value" put cursor on the component value
- */
 void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
 {
     std::string packet = FormatProbeItem( aSyncItem );
@@ -473,7 +475,9 @@ void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
     if( !packet.empty() )
     {
         if( Kiface().IsSingle() )
+        {
             SendCommand( MSG_TO_SCH, packet );
+        }
         else
         {
             // Typically ExpressMail is going to be s-expression packets, but since
@@ -492,7 +496,9 @@ void PCB_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
     if( !packet.empty() )
     {
         if( Kiface().IsSingle() )
+        {
             SendCommand( MSG_TO_SCH, packet );
+        }
         else
         {
             // Typically ExpressMail is going to be s-expression packets, but since
@@ -539,8 +545,8 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
 
         netlist.Format( "pcb_netlist", &sf, 0, CTL_OMIT_FILTERS );
         payload = sf.GetString();
-    }
         break;
+    }
 
     case MAIL_PCB_UPDATE_LINKS:
         try
@@ -564,6 +570,7 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
             assert( false ); // should never happen
             return;
         }
+
         break;
 
     case MAIL_CROSS_PROBE:
@@ -596,8 +603,9 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
 
         if( importFormat >= 0 )
             importFile( path, importFormat );
-    }
+
         break;
+    }
 
     // many many others.
     default:
diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp
index 43710c5c11..f4b159646e 100644
--- a/pcbnew/dialogs/dialog_board_setup.cpp
+++ b/pcbnew/dialogs/dialog_board_setup.cpp
@@ -48,6 +48,7 @@
 
 using std::placeholders::_1;
 
+
 DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
         PAGED_DIALOG( aFrame, _( "Board Setup" ), false,
                       _( "Import Settings from Another Board..." ) ),
@@ -88,6 +89,7 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
     m_treebook->AddSubPage( m_layers,  _( "Board Editor Layers" ) );
     m_layerSetupPage = 1;
     m_treebook->AddSubPage( m_physicalStackup,  _( "Physical Stackup" ) );
+
     // Change this value if m_physicalStackup is not the page 2 of m_treebook
     m_physicalStackupPage = 2;  // The page number (from 0) to select the m_physicalStackup panel
     m_treebook->AddSubPage( m_boardFinish, _( "Board Finish" ) );
@@ -111,7 +113,8 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
 
 	// Connect Events
 	m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
-                         wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
+                         wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ),
+                         nullptr, this );
 
     finishDialogSettings();
 }
@@ -120,7 +123,8 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
 DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
 {
 	m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
-                         wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
+                            wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ),
+                            nullptr, this );
 }
 
 
@@ -160,7 +164,6 @@ void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
 }
 
 
-// Run Import Settings... action
 void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
 {
     DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
diff --git a/pcbnew/dialogs/dialog_board_statistics.cpp b/pcbnew/dialogs/dialog_board_statistics.cpp
index 6bd52f57be..e19e5776fb 100644
--- a/pcbnew/dialogs/dialog_board_statistics.cpp
+++ b/pcbnew/dialogs/dialog_board_statistics.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com
- * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -45,8 +45,9 @@
 #define ROW_BOARD_HEIGHT 1
 #define ROW_BOARD_AREA 2
 
+
 /**
- * Struct containing the dialog last saved state
+ * The dialog last saved state.
  */
 struct DIALOG_BOARD_STATISTICS_SAVED_STATE
 {
@@ -69,6 +70,7 @@ struct DIALOG_BOARD_STATISTICS_SAVED_STATE
                                     // used to reinit last state after a project change
 };
 
+
 static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState;
 
 DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame ) :
@@ -81,7 +83,9 @@ DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame )
     m_parentFrame = aParentFrame;
 
     m_gridDrills->UseNativeColHeader();
-    m_gridDrills->Connect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_BOARD_STATISTICS::drillGridSort ), NULL, this );
+    m_gridDrills->Connect( wxEVT_GRID_COL_SORT,
+                           wxGridEventHandler( DIALOG_BOARD_STATISTICS::drillGridSort ),
+                           nullptr, this );
 
     m_checkBoxExcludeComponentsNoPins->SetValue( s_savedDialogState.excludeNoPins );
     m_checkBoxSubtractHoles->SetValue( s_savedDialogState.subtractHoles );
@@ -103,6 +107,7 @@ DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame )
     m_gridBoard->SetCellAlignment( 2, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
 
     wxGrid* grids[] = { m_gridComponents, m_gridPads, m_gridVias, m_gridBoard };
+
     for( auto& grid : grids )
     {
         // Remove wxgrid's selection boxes
@@ -130,6 +135,7 @@ DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame )
     m_sdbControlSizerCancel->SetLabel( _( "Close" ) );
 }
 
+
 void DIALOG_BOARD_STATISTICS::refreshItemsTypes()
 {
     m_componentsTypes.clear();
@@ -167,6 +173,7 @@ void DIALOG_BOARD_STATISTICS::refreshItemsTypes()
         m_gridVias->AppendRows( appendRows );
 }
 
+
 bool DIALOG_BOARD_STATISTICS::TransferDataToWindow()
 {
     refreshItemsTypes();
@@ -178,6 +185,7 @@ bool DIALOG_BOARD_STATISTICS::TransferDataToWindow()
     return true;
 }
 
+
 void DIALOG_BOARD_STATISTICS::getDataFromPCB()
 {
     BOARD* board = m_parentFrame->GetBoard();
@@ -348,6 +356,7 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB()
     }
 }
 
+
 void DIALOG_BOARD_STATISTICS::updateWidets()
 {
     int totalPads  = 0;
@@ -356,8 +365,8 @@ void DIALOG_BOARD_STATISTICS::updateWidets()
     for( const auto& type : m_padsTypes )
     {
         m_gridPads->SetCellValue( currentRow, COL_LABEL, type.title );
-        m_gridPads->SetCellValue(
-                currentRow, COL_AMOUNT, wxString::Format( wxT( "%i " ), type.qty ) );
+        m_gridPads->SetCellValue( currentRow, COL_AMOUNT,
+                                  wxString::Format( wxT( "%i " ), type.qty ) );
         totalPads += type.qty;
         currentRow++;
     }
@@ -371,8 +380,7 @@ void DIALOG_BOARD_STATISTICS::updateWidets()
     for( const auto& type : m_viasTypes )
     {
         m_gridVias->SetCellValue( currentRow, COL_LABEL, type.title );
-        m_gridVias->SetCellValue(
-                currentRow, COL_AMOUNT, wxString::Format( "%i ", type.qty ) );
+        m_gridVias->SetCellValue( currentRow, COL_AMOUNT, wxString::Format( "%i ", type.qty ) );
         totalVias += type.qty;
         currentRow++;
     }
@@ -416,7 +424,8 @@ void DIALOG_BOARD_STATISTICS::updateWidets()
         m_gridBoard->SetCellValue( ROW_BOARD_HEIGHT, COL_AMOUNT,
                                    MessageTextFromValue( GetUserUnits(), m_boardHeight ) + " " );
         m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT,
-                                   MessageTextFromValue( GetUserUnits(), m_boardArea, true, EDA_DATA_TYPE::AREA ) );
+                                   MessageTextFromValue( GetUserUnits(), m_boardArea, true,
+                                                         EDA_DATA_TYPE::AREA ) );
     }
     else
     {
@@ -436,6 +445,7 @@ void DIALOG_BOARD_STATISTICS::updateWidets()
     adjustDrillGridColumns();
 }
 
+
 void DIALOG_BOARD_STATISTICS::updateDrillGrid()
 {
     BOARD* board = m_parentFrame->GetBoard();
@@ -488,8 +498,10 @@ void DIALOG_BOARD_STATISTICS::updateDrillGrid()
     }
 }
 
+
 void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString& aStr,
-        bool aUseRowLabels, bool aUseColLabels, bool aUseFirstColAsLabel )
+                                                        bool aUseRowLabels, bool aUseColLabels,
+                                                        bool aUseFirstColAsLabel )
 {
     std::vector<int> widths( aGrid->GetNumberCols(), 0 );
     int              rowLabelsWidth = 0;
@@ -530,6 +542,7 @@ void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString&
             tmp.Printf( " %*s |", widths[col], aGrid->GetColLabelValue( col ) );
         else
             tmp.Printf( " %*s |", widths[col], aGrid->GetCellValue( 0, col ) );
+
         aStr << tmp;
     }
 
@@ -572,6 +585,7 @@ void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString&
             tmp.Printf( "|%-*s  |", widths[0], aGrid->GetCellValue( row, 0 ) );
         else
             tmp.Printf( "|" );
+
         aStr << tmp;
 
         for( int col = firstCol; col < aGrid->GetNumberCols(); col++ )
@@ -579,10 +593,12 @@ void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString&
             tmp.Printf( " %*s |", widths[col], aGrid->GetCellValue( row, col ) );
             aStr << tmp;
         }
+
         aStr << "\n";
     }
 }
 
+
 void DIALOG_BOARD_STATISTICS::adjustDrillGridColumns()
 {
     int newTotalWidth = m_gridDrills->GetClientSize().GetWidth();
@@ -605,7 +621,7 @@ void DIALOG_BOARD_STATISTICS::adjustDrillGridColumns()
     m_gridDrills->Refresh();
 }
 
-// If any checkbox clicked, we have to refresh dialog data
+
 void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& aEvent )
 {
     s_savedDialogState.excludeNoPins = m_checkBoxExcludeComponentsNoPins->GetValue();
@@ -617,6 +633,7 @@ void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& aEvent )
     drillsPanel->Layout();
 }
 
+
 void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
 {
     FILE*    outFile;
@@ -639,7 +656,7 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
 
     outFile = wxFopen( saveFileDialog.GetPath(), "wt" );
 
-    if( outFile == NULL )
+    if( outFile == nullptr )
     {
         msg.Printf( _( "Failed to create file '%s'." ), saveFileDialog.GetPath() );
         DisplayErrorMessage( this, msg );
@@ -656,9 +673,12 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
 
     if( m_hasOutline )
     {
-        msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) << MessageTextFromValue( GetUserUnits(), m_boardWidth ) << "\n";
-        msg << wxS( "- " ) << _( "Height" ) << wxS( ": " )<< MessageTextFromValue( GetUserUnits(), m_boardHeight ) << "\n";
-        msg << wxS( "- " ) << _( "Area" ) + wxS( ": " )  << MessageTextFromValue( GetUserUnits(), m_boardArea, true, EDA_DATA_TYPE::AREA );
+        msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) <<
+               MessageTextFromValue( GetUserUnits(), m_boardWidth ) << "\n";
+        msg << wxS( "- " ) << _( "Height" ) << wxS( ": " ) <<
+               MessageTextFromValue( GetUserUnits(), m_boardHeight ) << "\n";
+        msg << wxS( "- " ) << _( "Area" ) + wxS( ": " ) <<
+               MessageTextFromValue( GetUserUnits(), m_boardArea, true, EDA_DATA_TYPE::AREA );
         msg << "\n";
     }
     else
@@ -687,6 +707,7 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
     wxString tmp;
 
     widths.reserve( labels.size() );
+
     for( const auto& label : labels )
         widths.push_back( label.size() );
 
@@ -731,6 +752,7 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
     fclose( outFile );
 }
 
+
 void DIALOG_BOARD_STATISTICS::drillGridSize( wxSizeEvent& aEvent )
 {
     aEvent.Skip();
@@ -748,6 +770,7 @@ void DIALOG_BOARD_STATISTICS::drillGridSort( wxGridEvent& aEvent )
     updateDrillGrid();
 }
 
+
 DIALOG_BOARD_STATISTICS::~DIALOG_BOARD_STATISTICS()
 {
 }
diff --git a/pcbnew/dialogs/dialog_constraints_reporter.cpp b/pcbnew/dialogs/dialog_constraints_reporter.cpp
index a7a015c63d..c182742d2b 100644
--- a/pcbnew/dialogs/dialog_constraints_reporter.cpp
+++ b/pcbnew/dialogs/dialog_constraints_reporter.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -65,15 +65,17 @@ WX_HTML_REPORT_BOX* DIALOG_CONSTRAINTS_REPORTER::AddPage( const wxString& aTitle
 
     WX_HTML_REPORT_BOX* reporter = new WX_HTML_REPORT_BOX( panel, wxID_ANY, wxDefaultPosition,
                                                            wxDefaultSize,
-                                                           wxHW_SCROLLBAR_AUTO|wxBORDER_SIMPLE );
+                                                           wxHW_SCROLLBAR_AUTO | wxBORDER_SIMPLE );
 
-   	sizer->Add( reporter, 1, wxEXPAND|wxALL, 5 );
+   	sizer->Add( reporter, 1, wxEXPAND | wxALL, 5 );
    	panel->SetSizer( sizer );
    	panel->Layout();
     m_notebook->AddPage( panel, aTitle );
 
     reporter->SetUnits( m_frame->GetUserUnits() );
-    reporter->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_CONSTRAINTS_REPORTER::OnErrorLinkClicked ), NULL, this );
+    reporter->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
+                       wxHtmlLinkEventHandler( DIALOG_CONSTRAINTS_REPORTER::OnErrorLinkClicked ),
+                       nullptr, this );
 
     return reporter;
 }
diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp
index 3a6b14d908..ed781982de 100644
--- a/pcbnew/dialogs/dialog_drc.cpp
+++ b/pcbnew/dialogs/dialog_drc.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2009-2016 Dick Hollenbeck, dick@softplc.com
- * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -153,8 +153,6 @@ void DIALOG_DRC::initValues()
 }
 
 
-// PROGRESS_REPORTER calls
-
 bool DIALOG_DRC::updateUI()
 {
     double cur = (double) m_progress.load() / m_maxProgress;
@@ -502,8 +500,9 @@ void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent )
             static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
             modified = true;
         }
-    }
+
         break;
+    }
 
     case 2:
     {
@@ -522,8 +521,9 @@ void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent )
 
             modified = true;
         }
-    }
+
         break;
+    }
 
     case 3:
     {
@@ -531,8 +531,8 @@ void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent )
         BOARD_INSPECTION_TOOL* inspectionTool = toolMgr->GetTool<BOARD_INSPECTION_TOOL>();
 
         inspectionTool->InspectDRCError( node->m_RcItem );
-    }
         break;
+    }
 
     case 4:
         bds().m_DRCSeverities[ rcItem->GetErrorCode() ] = RPT_SEVERITY_ERROR;
@@ -582,8 +582,8 @@ void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent )
         // Rebuild model and view
         static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->SetProvider( m_markersProvider );
         modified = true;
-    }
         break;
+    }
 
     case 7:
         m_frame->ShowBoardSetupDialog( _( "Violation Severity" ) );
@@ -786,7 +786,7 @@ bool DIALOG_DRC::writeReport( const wxString& aFullFileName )
 {
     FILE* fp = wxFopen( aFullFileName, wxT( "w" ) );
 
-    if( fp == NULL )
+    if( fp == nullptr )
         return false;
 
     std::map<KIID, EDA_ITEM*> itemMap;
@@ -959,7 +959,9 @@ void DIALOG_DRC::updateDisplayedCounts()
         m_Notebook->SetPageText( 1, msg );
 
         if( m_footprintTestsRun )
+        {
             msg.sprintf( m_footprintsTitleTemplate, numFootprints );
+        }
         else
         {
             msg = m_footprintsTitleTemplate;
diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp
index 0bc9729c79..3b947b1d65 100644
--- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp
+++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -49,15 +49,19 @@
 #include <fp_lib_table.h>
 
 
-int DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::m_page = 0;     // remember the last open page during session
+// Remember the last open page during session.
+int DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::m_page = 0;
 
 
-DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( FOOTPRINT_EDIT_FRAME* aParent,
-                                                                              FOOTPRINT* aFootprint ) :
+DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(
+        FOOTPRINT_EDIT_FRAME* aParent,
+        FOOTPRINT* aFootprint ) :
     DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE( aParent ),
     m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits ),
-    m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
-    m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
+    m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl,
+                  m_SolderMaskMarginUnits ),
+    m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl,
+                   m_SolderPasteMarginUnits ),
     m_inSelect( false )
 {
     m_frame = aParent;
@@ -89,6 +93,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( FO
     m_itemsGrid->ShowHideColumns( m_frame->GetSettings()->m_FootprintTextShownColumns );
 
     PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
+
     if( cfg->m_lastFootprint3dDir.IsEmpty() )
     {
         wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir );
@@ -158,7 +163,9 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( FO
     m_button3DShapeRemove->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
 
     // wxFormBuilder doesn't include this event...
-    m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnGridCellChanging ), NULL, this );
+    m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING,
+                          wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnGridCellChanging ),
+                          nullptr, this );
 
     finishDialogSettings();
 }
@@ -172,7 +179,9 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR()
     // Prevents crash bug in wxGrid's d'tor
     m_itemsGrid->DestroyTable( m_texts );
 
-    m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnGridCellChanging ), NULL, this );
+    m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
+                             wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnGridCellChanging ),
+                             nullptr, this );
 
     // Delete the GRID_TRICKS.
     m_itemsGrid->PopEventHandler( true );
@@ -283,6 +292,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow()
 
     wxString default_path;
     wxGetEnv( KICAD6_3DMODEL_DIR, &default_path );
+
 #ifdef __WINDOWS__
     default_path.Replace( wxT( "/" ), wxT( "\\" ) );
 #endif
@@ -396,7 +406,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::On3DModelCellChanged( wxGridEvent& a
             filename.insert( 0, wxT( ":" ) );
 
 #ifdef __WINDOWS__
-        // In Kicad files, filenames and paths are stored using Unix notation
+        // In KiCad files, filenames and paths are stored using Unix notation
         filename.Replace( wxT( "\\" ), wxT( "/" ) );
 #endif
 
@@ -482,7 +492,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAdd3DModel( wxCommandEvent&  )
         filename = alias + wxT( ":" ) + shortPath;
 
 #ifdef __WINDOWS__
-    // In Kicad files, filenames and paths are stored using Unix notation
+    // In KiCad files, filenames and paths are stored using Unix notation
     model.m_Filename.Replace( "\\", "/" );
 #endif
 
@@ -690,6 +700,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow()
     // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
     if( dtmp < -50.0 )
         dtmp = -50.0;
+
     // A margin ratio is always <= 0
     // 0 means use full pad copper area
     if( dtmp > 0.0 )
@@ -832,7 +843,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event )
 
     if( m_itemsGrid->IsCellEditControlShown() )
     {
-        // Currently: nonthing to do
+        // Currently: nothing to do
     }
 
     // Handle a delayed focus.  The delay allows us to:
diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp
index 0fdcb4248c..d6af31dc4e 100644
--- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp
+++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2009-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -33,6 +33,7 @@
 #include <tools/global_edit_tool.h>
 #include "dialog_global_edit_tracks_and_vias_base.h"
 
+
 // Columns of netclasses grid
 enum {
     GRID_NAME = 0,
@@ -133,7 +134,9 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS( PCB_EDIT
     m_netclassGrid->SetCellHighlightPenWidth( 0 );
     m_sdbSizerOK->SetDefault();
 
-    m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
+    m_netFilter->Connect( NET_SELECTED,
+                          wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ),
+                          nullptr, this );
 
     finishDialogSettings();
 }
@@ -151,7 +154,9 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::~DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS()
     g_layerFilter = m_layerFilter->GetLayerSelection();
     g_filterSelected = m_selectedItemsFilter->GetValue();
 
-    m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
+    m_netFilter->Disconnect( NET_SELECTED,
+                             wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ),
+                             nullptr, this );
 
     delete[] m_originalColWidths;
 }
@@ -210,6 +215,7 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildNetclassesGrid()
     SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
 
     int row = 2;
+
     for( const auto& netclass : netclasses )
     {
         m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
@@ -237,7 +243,7 @@ bool DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow()
     else if( item )
         m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClassName() );
 
-    if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
+    if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
     {
         m_netFilter->SetSelectedNet( g_netFilter );
         m_netFilterOpt->SetValue( true );
diff --git a/pcbnew/dialogs/dialog_pad_basicshapes_properties.cpp b/pcbnew/dialogs/dialog_pad_basicshapes_properties.cpp
index 165a15198e..9f05be3abe 100644
--- a/pcbnew/dialogs/dialog_pad_basicshapes_properties.cpp
+++ b/pcbnew/dialogs/dialog_pad_basicshapes_properties.cpp
@@ -7,7 +7,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -67,9 +67,10 @@ DIALOG_PAD_PRIMITIVES_PROPERTIES::DIALOG_PAD_PRIMITIVES_PROPERTIES( wxWindow* aP
     finishDialogSettings();
 }
 
+
 bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow()
 {
-    if( m_shape == NULL )
+    if( m_shape == nullptr )
         return false;
 
     m_thickness.SetValue( m_shape->GetWidth() );
@@ -169,6 +170,7 @@ bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow()
     return true;
 }
 
+
 bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow()
 {
     if( m_thickness.GetValue() == 0 && !m_filledCtrl->GetValue() )
@@ -201,6 +203,7 @@ bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow()
         // the start point in m_End
         m_shape->SetStart( wxPoint( m_endX.GetValue(), m_endY.GetValue() ) );
         m_shape->SetEnd( wxPoint( m_startX.GetValue(), m_startY.GetValue() ) );
+
         // arc angle
         m_shape->SetAngle( m_radius.GetValue() );
         break;
@@ -249,7 +252,9 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS( wxWindow* aPar
     m_sdbSizerOK->SetDefault();
     GetSizer()->SetSizeHints( this );
 
-	m_gridCornersList->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ), NULL, this );
+	m_gridCornersList->Connect( wxEVT_GRID_CELL_CHANGING,
+                                wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ),
+                                nullptr, this );
 
     // Now all widgets have the size fixed, call FinishDialogSettings
     finishDialogSettings();
@@ -258,13 +263,15 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS( wxWindow* aPar
 
 DIALOG_PAD_PRIMITIVE_POLY_PROPS::~DIALOG_PAD_PRIMITIVE_POLY_PROPS()
 {
-	m_gridCornersList->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ), NULL, this );
+	m_gridCornersList->Disconnect( wxEVT_GRID_CELL_CHANGING,
+                                   wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ),
+                                   nullptr, this );
 }
 
 
 bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow()
 {
-    if( m_shape == NULL )
+    if( m_shape == nullptr )
         return false;
 
     m_thickness.SetValue( m_shape->GetWidth() );
@@ -285,6 +292,7 @@ bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow()
 
     // enter others corner coordinates
     wxString msg;
+
     for( unsigned row = 0; row < m_currPoints.size(); ++row )
     {
         // Row label is "Corner x"
@@ -321,7 +329,6 @@ bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate()
 }
 
 
-// test for a valid polygon (a not self intersectiong polygon)
 bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate( bool aRemoveRedundantCorners )
 {
     if( !m_gridCornersList->CommitPendingChanges() )
@@ -413,6 +420,7 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonAdd( wxCommandEvent& event )
     m_panelPoly->Refresh();
 }
 
+
 void DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonDelete( wxCommandEvent& event )
 {
     if( !m_gridCornersList->CommitPendingChanges() )
@@ -442,12 +450,14 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonDelete( wxCommandEvent& event )
     TransferDataToWindow();
 
     m_gridCornersList->ForceRefresh();
+
     // select the row previous to the last deleted row
     m_gridCornersList->SelectRow( std::max( 0, selections[ 0 ] - 1 ) );
 
     m_panelPoly->Refresh();
 }
 
+
 void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel( wxPaintEvent& event )
 {
     wxPaintDC dc( m_panelPoly );
@@ -476,8 +486,8 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel( wxPaintEvent& event )
     // Draw X and Y axis. This is particularly useful to show the
     // reference position of basic shape
     // Axis are drawn before the polygon to avoid masking segments on axis
-    GRLine( NULL, &dc, -dc_size.x, 0, dc_size.x, 0, 0, LIGHTBLUE );   // X axis
-    GRLine( NULL, &dc, 0, -dc_size.y, 0, dc_size.y, 0, LIGHTBLUE );   // Y axis
+    GRLine( nullptr, &dc, -dc_size.x, 0, dc_size.x, 0, 0, LIGHTBLUE );   // X axis
+    GRLine( nullptr, &dc, 0, -dc_size.y, 0, dc_size.y, 0, LIGHTBLUE );   // Y axis
 
     // Draw polygon.
     // The selected edge(s) are shown in selectcolor, the others in normalcolor.
@@ -498,23 +508,27 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel( wxPaintEvent& event )
         if( jj >= m_currPoints.size() )
             jj = 0;
 
-        GRLine( NULL, &dc, m_currPoints[ii] * scale, m_currPoints[jj] * scale, m_thickness.GetValue() * scale, color );
+        GRLine( nullptr, &dc, m_currPoints[ii] * scale, m_currPoints[jj] * scale,
+                m_thickness.GetValue() * scale, color );
     }
 
     event.Skip();
 }
 
+
 void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPolyPanelResize( wxSizeEvent& event )
 {
     m_panelPoly->Refresh();
     event.Skip();
 }
 
+
 void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onGridSelect( wxGridRangeSelectEvent& event )
 {
     m_panelPoly->Refresh();
 }
 
+
 void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging( wxGridEvent& event )
 {
     int      row = event.GetRow();
@@ -535,8 +549,6 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging( wxGridEvent& event )
 }
 
 
-// A dialog to apply geometry transforms to a shape or set of shapes
-// (move, rotate around origin, scaling factor, duplication).
 DIALOG_PAD_PRIMITIVES_TRANSFORM::DIALOG_PAD_PRIMITIVES_TRANSFORM( wxWindow* aParent,
                                                                   PCB_BASE_FRAME* aFrame,
                                                                   std::vector<std::shared_ptr<PCB_SHAPE>>& aList,
@@ -597,8 +609,10 @@ void DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform( std::vector<std::shared_ptr<PCB
         {
             std::shared_ptr<PCB_SHAPE> shape;
 
-            if( aList == NULL )
+            if( aList == nullptr )
+            {
                 shape = m_list[idx];
+            }
             else
             {
                 aList->emplace_back( std::make_shared<PCB_SHAPE>( *m_list[idx] ) );
diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp
index 0afa471c44..465db432c0 100644
--- a/pcbnew/dialogs/dialog_pad_properties.cpp
+++ b/pcbnew/dialogs/dialog_pad_properties.cpp
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
- * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -66,6 +66,7 @@ static PAD_SHAPE code_shape[] =
     PAD_SHAPE::CUSTOM           // choice = PAD_SHAPE::CUSTOM_RECT_ANCHOR
 };
 
+
 // the ordered index of the pad shape wxChoice in dialog.
 // keep it consistent with code_shape[] and dialog strings
 enum CODE_CHOICE
@@ -81,6 +82,7 @@ enum CODE_CHOICE
     CHOICE_SHAPE_CUSTOM_RECT_ANCHOR
 };
 
+
 static PAD_ATTRIB code_type[] =
 {
     PAD_ATTRIB::PTH,
@@ -91,13 +93,15 @@ static PAD_ATTRIB code_type[] =
                                     // only on tech layers (usually only on paste layer
 };
 
-// Thse define have the same value as the m_PadType wxChoice GetSelected() return value
+
+// These define have the same value as the m_PadType wxChoice GetSelected() return value
 #define PTH_DLG_TYPE 0
 #define SMD_DLG_TYPE 1
 #define CONN_DLG_TYPE 2
 #define NPTH_DLG_TYPE 3
 #define APERTURE_DLG_TYPE 4
 
+
 void PCB_BASE_FRAME::ShowPadPropertiesDialog( PAD* aPad )
 {
     DIALOG_PAD_PROPERTIES dlg( this, aPad );
@@ -164,7 +168,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
     m_nonCopperWarningIcon->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
 
     m_padMaster  = m_parent->GetDesignSettings().m_Pad_Master.get();
-    m_dummyPad   = new PAD( (FOOTPRINT*) NULL );
+    m_dummyPad   = new PAD( (FOOTPRINT*) nullptr );
 
     if( aPad )
     {
@@ -209,7 +213,9 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
     m_sdbSizerOK->SetDefault();
     m_canUpdate = true;
 
-    m_PadNetSelector->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ), NULL, this );
+    m_PadNetSelector->Connect( NET_SELECTED,
+                               wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ),
+                               nullptr, this );
 
     // Now all widgets have the size fixed, call FinishDialogSettings
     finishDialogSettings();
@@ -221,14 +227,17 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
 
 DIALOG_PAD_PROPERTIES::~DIALOG_PAD_PROPERTIES()
 {
-    m_PadNetSelector->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ), NULL, this );
+    m_PadNetSelector->Disconnect( NET_SELECTED,
+                                  wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ),
+                                  nullptr, this );
 
     delete m_dummyPad;
     delete m_axisOrigin;
 }
 
 
-bool DIALOG_PAD_PROPERTIES::m_sketchPreview = false;   // Stores the pad draw option during a session
+// Store the pad draw option during a session.
+bool DIALOG_PAD_PROPERTIES::m_sketchPreview = false;
 
 
 void DIALOG_PAD_PROPERTIES::OnInitDialog( wxInitDialogEvent& event )
@@ -308,6 +317,7 @@ void DIALOG_PAD_PROPERTIES::prepareCanvas()
     // gives a non null grid size (0.001mm) because GAL layer does not like a 0 size grid:
     double gridsize = 0.001 * IU_PER_MM;
     view->GetGAL()->SetGridSize( VECTOR2D( gridsize, gridsize ) );
+
     // And do not show the grid:
     view->GetGAL()->SetGridVisibility( false );
     view->Add( m_dummyPad );
@@ -691,7 +701,8 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
         for( wxString& s : bs_info )
             s.Empty();
 
-        bs_info[4] = _( "width" ) + wxS( " " )+ MessageTextFromValue( m_units, primitive->GetWidth() );
+        bs_info[4] = _( "width" ) + wxS( " " )+ MessageTextFromValue( m_units,
+                                                                      primitive->GetWidth() );
 
         switch( primitive->GetShape() )
         {
@@ -710,7 +721,8 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
         case PCB_SHAPE_TYPE::ARC: // Arc with rounded ends
             bs_info[0] = _( "Arc" );
             bs_info[1] = _( "center" ) + wxS( " " )+ formatCoord( m_units, primitive->GetCenter() );
-            bs_info[2] = _( "start" ) + wxS( " " )+ formatCoord( m_units, primitive->GetArcStart() );
+            bs_info[2] = _( "start" ) + wxS( " " )+ formatCoord( m_units,
+                                                                 primitive->GetArcStart() );
             bs_info[3] = _( "angle" ) + wxS( " " )+ FormatAngle( primitive->GetAngle() );
             break;
 
@@ -721,7 +733,8 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
                 bs_info[0] = _( "circle" );
 
             bs_info[1] = formatCoord( m_units, primitive->GetStart() );
-            bs_info[2] = _( "radius" ) + wxS( " " )+ MessageTextFromValue( m_units, primitive->GetRadius() );
+            bs_info[2] = _( "radius" ) + wxS( " " )+ MessageTextFromValue( m_units,
+                                                                           primitive->GetRadius() );
             break;
 
         case PCB_SHAPE_TYPE::POLYGON: // polygon
@@ -747,6 +760,7 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
         m_listCtrlPrimitives->SetColumnWidth( ii, wxLIST_AUTOSIZE );
 }
 
+
 void DIALOG_PAD_PROPERTIES::OnResize( wxSizeEvent& event )
 {
     redraw();
@@ -776,7 +790,6 @@ void DIALOG_PAD_PROPERTIES::onChangePadMode( wxCommandEvent& event )
 }
 
 
-
 void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
 {
     switch( m_PadShapeSelector->GetSelection() )
@@ -798,8 +811,9 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
         // A reasonable default (from  IPC-7351C)
         if( m_dummyPad->GetRoundRectRadiusRatio() == 0.0 )
             m_tcCornerSizeRatio->ChangeValue( "25" );
-    }
+
         break;
+    }
 
     case CHOICE_SHAPE_CHAMFERED_RECT:
         m_shapePropsBook->SetSelection( 3 );
@@ -820,8 +834,8 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
             m_cbTopRight->SetValue( false );
             m_cbBottomLeft->SetValue( false );
             m_cbBottomRight->SetValue( false );
+            break;
         }
-        break;
 
     case CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT:
         m_shapePropsBook->SetSelection( 4 );
@@ -1197,7 +1211,6 @@ void DIALOG_PAD_PROPERTIES::OnSetCopperLayers( wxCommandEvent& event )
 }
 
 
-// Called when select/deselect a layer.
 void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event )
 {
     transferDataToPad( m_dummyPad );
@@ -1205,7 +1218,6 @@ void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event )
 }
 
 
-// test if all values are acceptable for the pad
 bool DIALOG_PAD_PROPERTIES::padValuesOK()
 {
     bool error = transferDataToPad( m_dummyPad );
@@ -1292,7 +1304,7 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK()
 
     // Some pads need a positive solder paste clearance (mainly for BGA with small pads)
     // However, a positive value can create issues if the resulting shape is too big.
-    // (like a solder paste creating a solder paste area on a neighbour pad or on the solder mask)
+    // (like a solder paste creating a solder paste area on a neighbor pad or on the solder mask)
     // So we could ask for user to confirm the choice
     // For now we just check for disappearing paste
     wxSize paste_size;
@@ -1541,6 +1553,7 @@ bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow()
         return false;
 
     transferDataToPad( m_padMaster );
+
     // m_padMaster is a pattern: ensure there is no net for this pad:
     m_padMaster->SetNetCode( NETINFO_LIST::UNCONNECTED );
 
@@ -2035,8 +2048,8 @@ void DIALOG_PAD_PROPERTIES::OnValuesChanged( wxCommandEvent& event )
     if( m_canUpdate )
     {
         transferDataToPad( m_dummyPad );
-        // If the pad size has changed, update the displayed values
-        // for rounded rect pads
+
+        // If the pad size has changed, update the displayed values for rounded rect pads.
         updateRoundRectCornerValues();
 
         redraw();
@@ -2093,20 +2106,18 @@ void DIALOG_PAD_PROPERTIES::OnPrimitiveSelection( wxListEvent& event )
 }
 
 
-/// Called on a double click on the basic shapes list
 void DIALOG_PAD_PROPERTIES::onPrimitiveDClick( wxMouseEvent& event )
 {
     editPrimitive();
 }
 
 
-// Called on a click on basic shapes list panel button
 void DIALOG_PAD_PROPERTIES::onEditPrimitive( wxCommandEvent& event )
 {
     editPrimitive();
 }
 
-// Called on a click on basic shapes list panel button
+
 void DIALOG_PAD_PROPERTIES::onDeletePrimitive( wxCommandEvent& event )
 {
     long select = m_listCtrlPrimitives->GetFirstSelected();
diff --git a/pcbnew/dialogs/dialog_print_pcbnew.cpp b/pcbnew/dialogs/dialog_print_pcbnew.cpp
index 864f08a6f7..707e2b6599 100644
--- a/pcbnew/dialogs/dialog_print_pcbnew.cpp
+++ b/pcbnew/dialogs/dialog_print_pcbnew.cpp
@@ -280,7 +280,6 @@ void DIALOG_PRINT_PCBNEW::createLeftPanel()
     sizerLeft->Add( copperLabel, 0, wxRIGHT, 5 );
     sizerLeft->Add( m_listCopperLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
 
-
     // Technical layer list
     auto technicalLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY,
                                             _( "Technical layers:" ) );
@@ -290,22 +289,22 @@ void DIALOG_PRINT_PCBNEW::createLeftPanel()
     sizerRight->Add( technicalLabel, 0, wxLEFT, 5 );
     sizerRight->Add( m_listTechLayers, 1, wxEXPAND | wxBOTTOM | wxLEFT, 5 );
 
-
     // Layer list layout
     wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
     bLayerListsSizer->Add( sizerLeft, 1, wxEXPAND, 5 );
     bLayerListsSizer->Add( sizerRight, 1, wxEXPAND, 5 );
 
-
     // Select/Unselect all buttons
     m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
     m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY,
                                         _( "Deselect all" ) );
 
     m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
-            wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ), NULL, this );
+                                wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ),
+                                nullptr, this );
     m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
-            wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ), NULL, this );
+                                  wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ),
+                                  nullptr, this );
 
     wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
     buttonSizer->Add( m_buttonSelectAll, 1, wxRIGHT | wxTOP | wxBOTTOM, 5 );
diff --git a/pcbnew/dialogs/dialog_rule_area_properties.cpp b/pcbnew/dialogs/dialog_rule_area_properties.cpp
index 9b7a968049..133a8a1314 100644
--- a/pcbnew/dialogs/dialog_rule_area_properties.cpp
+++ b/pcbnew/dialogs/dialog_rule_area_properties.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,6 +36,7 @@
 #define LAYER_LIST_COLUMN_NAME 2
 #define LAYER_LIST_ROW_ALL_INNER_LAYERS 1
 
+
 class DIALOG_RULE_AREA_PROPERTIES : public DIALOG_RULE_AREA_PROPERTIES_BASE
 {
 public:
@@ -150,15 +151,21 @@ bool DIALOG_RULE_AREA_PROPERTIES::TransferDataFromWindow()
 
     if( m_zonesettings.m_Layers.count() == 0 )
     {
-        DisplayError( NULL, _( "No layers selected." ) );
+        DisplayError( this, _( "No layers selected." ) );
         return false;
     }
 
     switch( m_OutlineDisplayCtrl->GetSelection() )
     {
-    case 0: m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;      break;
-    case 1: m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
-    case 2: m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
+    case 0:
+        m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
+        break;
+    case 1:
+        m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
+        break;
+    case 2:
+        m_zonesettings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL;
+        break;
     }
 
     auto cfg = m_parent->GetPcbNewSettings();
diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp
index 5e281b33f9..bebbf09468 100644
--- a/pcbnew/dialogs/dialog_text_properties.cpp
+++ b/pcbnew/dialogs/dialog_text_properties.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2004-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
- * Copyright (C) 2010-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2010-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -38,6 +38,7 @@
 #include <math/util.h>      // for KiROUND
 #include <scintilla_tricks.h>
 
+
 DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ) :
     DIALOG_TEXT_PROPERTIES_BASE( aParent ),
     m_Parent( aParent ),
@@ -158,7 +159,8 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO
 
     // wxTextCtrls fail to generate wxEVT_CHAR events when the wxTE_MULTILINE flag is set,
     // so we have to listen to wxEVT_CHAR_HOOK events instead.
-    Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ), NULL, this );
+    Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ),
+             nullptr, this );
 
     finishDialogSettings();
 }
@@ -166,13 +168,13 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO
 
 DIALOG_TEXT_PROPERTIES::~DIALOG_TEXT_PROPERTIES()
 {
-    Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ), NULL, this );
+    Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ),
+                nullptr, this );
 
     delete m_scintillaTricks;
 }
 
 
-// Launch the text properties dialog in quasi modal mode.
 void PCB_BASE_EDIT_FRAME::ShowTextPropertiesDialog( BOARD_ITEM* aText )
 {
     DIALOG_TEXT_PROPERTIES dlg( this, aText );
diff --git a/pcbnew/drc/drc_rule_parser.cpp b/pcbnew/drc/drc_rule_parser.cpp
index 7f8973ce52..0af540d988 100644
--- a/pcbnew/drc/drc_rule_parser.cpp
+++ b/pcbnew/drc/drc_rule_parser.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2020 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 2020-2021 KiCad Developers, see change_log.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -57,19 +57,14 @@ void DRC_RULES_PARSER::reportError( const wxString& aMessage )
 
     if( m_reporter )
     {
-        wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
-                                         CurLineNumber(),
-                                         CurOffset(),
-                                         first,
-                                         rest );
+        wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ), CurLineNumber(),
+                                         CurOffset(), first, rest );
 
         m_reporter->Report( msg, RPT_SEVERITY_ERROR );
     }
     else
     {
-        wxString msg = wxString::Format( _( "ERROR: %s%s" ),
-                                         first,
-                                         rest );
+        wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
 
         THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
     }
@@ -128,7 +123,7 @@ void DRC_RULES_PARSER::Parse( std::vector<DRC_RULE*>& aRules, REPORTER* aReporte
 
             if( (int) token == DSN_NUMBER )
             {
-                m_requiredVersion = (int)strtol( CurText(), NULL, 10 );
+                m_requiredVersion = (int)strtol( CurText(), nullptr, 10 );
                 m_tooRecent = ( m_requiredVersion > DRC_RULE_FILE_VERSION );
                 token = NextTok();
             }
@@ -158,8 +153,7 @@ void DRC_RULES_PARSER::Parse( std::vector<DRC_RULE*>& aRules, REPORTER* aReporte
             break;
 
         default:
-            msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
-                        FromUTF8(),
+            msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
                         "'rule', 'version'" );
             reportError( msg );
             parseUnknown();
@@ -220,8 +214,7 @@ DRC_RULE* DRC_RULES_PARSER::parseDRC_RULE()
 
             if( (int) NextTok() != DSN_RIGHT )
             {
-                reportError( wxString::Format( _( "Unrecognized item '%s'." ),
-                                               FromUTF8() ) );
+                reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
                 parseUnknown();
             }
 
@@ -237,8 +230,7 @@ DRC_RULE* DRC_RULES_PARSER::parseDRC_RULE()
             return rule;
 
         default:
-            msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
-                           FromUTF8(),
+            msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
                            "'constraint', 'condition', 'disallow'" );
             reportError( msg );
             parseUnknown();
@@ -264,10 +256,10 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
     if( (int) token == DSN_RIGHT || token == T_EOF )
     {
         msg.Printf( _( "Missing constraint type.|  Expected %s." ),
-                        "'clearance', 'hole_clearance', 'edge_clearance', 'hole', 'hole_to_hole', "
-                        "'courtyard_clearance', 'silk_clearance', 'track_width', 'annular_width', "
-                        "'disallow', 'length', 'skew', 'via_count', 'diff_pair_gap' or "
-                        "'diff_pair_uncoupled'" );
+                    "'clearance', 'hole_clearance', 'edge_clearance', 'hole', 'hole_to_hole', "
+                    "'courtyard_clearance', 'silk_clearance', 'track_width', 'annular_width', "
+                    "'disallow', 'length', 'skew', 'via_count', 'diff_pair_gap' or "
+                    "'diff_pair_uncoupled'" );
         reportError( msg );
         return;
     }
@@ -290,8 +282,7 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
     case T_diff_pair_gap:       constraint.m_Type = DIFF_PAIR_GAP_CONSTRAINT;            break;
     case T_diff_pair_uncoupled: constraint.m_Type = DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT;  break;
     default:
-        msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
-                    FromUTF8(),
+        msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
                     "'clearance', 'hole_clearance', 'edge_clearance', 'hole', hole_to_hole',"
                     "'courtyard_clearance', 'silk_clearance', 'track_width', 'annular_width', "
                     "'disallow', 'length', 'skew', 'diff_pair_gap' or 'diff_pair_uncoupled'." );
@@ -323,8 +314,7 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
                 return;
 
             default:
-                msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
-                            FromUTF8(),
+                msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
                             "'track', 'via', 'micro_via', 'buried_via', 'pad', 'zone', 'text', "
                             "'graphic', 'hole' or 'footprint'." );
                 reportError( msg );
@@ -441,18 +431,13 @@ void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult
         if( m_reporter )
         {
             wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
-                                             CurLineNumber(),
-                                             CurOffset() + aOffset,
-                                             first,
-                                             rest );
+                                             CurLineNumber(), CurOffset() + aOffset, first, rest );
 
             m_reporter->Report( msg, RPT_SEVERITY_ERROR );
         }
         else
         {
-            wxString msg = wxString::Format( _( "ERROR: %s%s" ),
-                                             first,
-                                             rest );
+            wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
 
             THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(),
                                CurOffset() + aOffset );
@@ -508,8 +493,7 @@ LSET DRC_RULES_PARSER::parseLayer()
 
     if( (int) NextTok() != DSN_RIGHT )
     {
-        reportError( wxString::Format( _( "Unrecognized item '%s'." ),
-                                       FromUTF8() ) );
+        reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
         parseUnknown();
     }
 
diff --git a/pcbnew/exporters/export_footprint_associations.cpp b/pcbnew/exporters/export_footprint_associations.cpp
index c3109ba2e1..2757c67c02 100644
--- a/pcbnew/exporters/export_footprint_associations.cpp
+++ b/pcbnew/exporters/export_footprint_associations.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -37,7 +37,7 @@ bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
 {
     FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
 
-    if( cmpFile == NULL )
+    if( cmpFile == nullptr )
         return false;
 
     fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew   date = %s\n", TO_UTF8( DateAndTime() ) );
diff --git a/pcbnew/exporters/export_idf.cpp b/pcbnew/exporters/export_idf.cpp
index d865c14f37..3f8d42ff07 100644
--- a/pcbnew/exporters/export_idf.cpp
+++ b/pcbnew/exporters/export_idf.cpp
@@ -6,6 +6,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013  Cirilo Bernardo
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -48,16 +49,17 @@
 #endif
 #include <convert_to_biu.h>     // to define Millimeter2iu(x)
 
+
 // assumed default graphical line thickness: == 0.1mm
 #define LINE_WIDTH (Millimeter2iu( 0.1 ))
 
+
 static FILENAME_RESOLVER* resolver;
 
+
 /**
- * Function idf_export_outline
- * retrieves line segment information from the edge layer and compiles
- * the data into a form which can be output as an IDFv3 compliant
- * BOARD_OUTLINE section.
+ * Retrieve line segment information from the edge layer and compiles the data into a form
+ * which can be output as an IDFv3 compliant #BOARD_OUTLINE section.
  */
 static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard )
 {
@@ -67,7 +69,7 @@ static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard )
     IDF_POINT sp, ep;                   // start and end points from KiCad item
 
     std::list< IDF_SEGMENT* > lines;    // IDF intermediate form of KiCad graphical item
-    IDF_OUTLINE* outline = NULL;        // graphical items forming an outline or cutout
+    IDF_OUTLINE* outline = nullptr;        // graphical items forming an outline or cutout
 
     // NOTE: IMPLEMENTATION
     // If/when component cutouts are allowed, we must implement them separately. Cutouts
@@ -88,86 +90,90 @@ static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard )
         switch( graphic->GetShape() )
         {
         case PCB_SHAPE_TYPE::SEGMENT:
+        {
+            if( ( graphic->GetStart().x == graphic->GetEnd().x )
+                && ( graphic->GetStart().y == graphic->GetEnd().y ) )
             {
-                if( ( graphic->GetStart().x == graphic->GetEnd().x )
-                    && ( graphic->GetStart().y == graphic->GetEnd().y ) )
-                {
-                    break;
-                }
-
-                sp.x    = graphic->GetStart().x * scale + offX;
-                sp.y    = -graphic->GetStart().y * scale + offY;
-                ep.x    = graphic->GetEnd().x * scale + offX;
-                ep.y    = -graphic->GetEnd().y * scale + offY;
-                IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep );
-
-                if( seg )
-                    lines.push_back( seg );
+                break;
             }
+
+            sp.x = graphic->GetStart().x * scale + offX;
+            sp.y = -graphic->GetStart().y * scale + offY;
+            ep.x = graphic->GetEnd().x * scale + offX;
+            ep.y = -graphic->GetEnd().y * scale + offY;
+            IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep );
+
+            if( seg )
+                lines.push_back( seg );
+
             break;
+        }
 
         case PCB_SHAPE_TYPE::RECT:
+        {
+            if( ( graphic->GetStart().x == graphic->GetEnd().x )
+                && ( graphic->GetStart().y == graphic->GetEnd().y ) )
             {
-                if( ( graphic->GetStart().x == graphic->GetEnd().x )
-                    && ( graphic->GetStart().y == graphic->GetEnd().y ) )
-                {
-                    break;
-                }
-
-                double top = graphic->GetStart().y * scale + offY;
-                double left = graphic->GetStart().x * scale + offX;
-                double bottom = graphic->GetEnd().y * scale + offY;
-                double right = graphic->GetEnd().x * scale + offX;
-
-                IDF_POINT corners[4];
-                corners[0] = IDF_POINT( left, top );
-                corners[1] = IDF_POINT( right, top );
-                corners[2] = IDF_POINT( right, bottom );
-                corners[3] = IDF_POINT( left, bottom );
-
-                lines.push_back( new IDF_SEGMENT( corners[0], corners[1] ) );
-                lines.push_back( new IDF_SEGMENT( corners[1], corners[2] ) );
-                lines.push_back( new IDF_SEGMENT( corners[2], corners[3] ) );
-                lines.push_back( new IDF_SEGMENT( corners[3], corners[0] ) );
+                break;
             }
+
+            double top = graphic->GetStart().y * scale + offY;
+            double left = graphic->GetStart().x * scale + offX;
+            double bottom = graphic->GetEnd().y * scale + offY;
+            double right = graphic->GetEnd().x * scale + offX;
+
+            IDF_POINT corners[4];
+            corners[0] = IDF_POINT( left, top );
+            corners[1] = IDF_POINT( right, top );
+            corners[2] = IDF_POINT( right, bottom );
+            corners[3] = IDF_POINT( left, bottom );
+
+            lines.push_back( new IDF_SEGMENT( corners[0], corners[1] ) );
+            lines.push_back( new IDF_SEGMENT( corners[1], corners[2] ) );
+            lines.push_back( new IDF_SEGMENT( corners[2], corners[3] ) );
+            lines.push_back( new IDF_SEGMENT( corners[3], corners[0] ) );
             break;
+        }
 
         case PCB_SHAPE_TYPE::ARC:
+        {
+            if( ( graphic->GetCenter().x == graphic->GetArcStart().x )
+                && ( graphic->GetCenter().y == graphic->GetArcStart().y ) )
             {
-                if( ( graphic->GetCenter().x == graphic->GetArcStart().x )
-                    && ( graphic->GetCenter().y == graphic->GetArcStart().y ) )
-                {
-                    break;
-                }
-
-                sp.x = graphic->GetCenter().x * scale + offX;
-                sp.y = -graphic->GetCenter().y * scale + offY;
-                ep.x = graphic->GetArcStart().x * scale + offX;
-                ep.y = -graphic->GetArcStart().y * scale + offY;
-                IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep, -graphic->GetAngle() / 10.0, true );
-
-                if( seg )
-                    lines.push_back( seg );
+                break;
             }
+
+            sp.x = graphic->GetCenter().x * scale + offX;
+            sp.y = -graphic->GetCenter().y * scale + offY;
+            ep.x = graphic->GetArcStart().x * scale + offX;
+            ep.y = -graphic->GetArcStart().y * scale + offY;
+            IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep, -graphic->GetAngle() / 10.0, true );
+
+            if( seg )
+                lines.push_back( seg );
+
             break;
+        }
 
         case PCB_SHAPE_TYPE::CIRCLE:
-            {
-                if( graphic->GetRadius() == 0 )
-                    break;
+        {
+            if( graphic->GetRadius() == 0 )
+                break;
 
-                sp.x = graphic->GetCenter().x * scale + offX;
-                sp.y = -graphic->GetCenter().y * scale + offY;
-                ep.x = sp.x - graphic->GetRadius() * scale;
-                ep.y = sp.y;
-                // Circles must always have an angle of +360 deg. to appease
-                // quirky MCAD implementations of IDF.
-                IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep, 360.0, true );
+            sp.x = graphic->GetCenter().x * scale + offX;
+            sp.y = -graphic->GetCenter().y * scale + offY;
+            ep.x = sp.x - graphic->GetRadius() * scale;
+            ep.y = sp.y;
+
+            // Circles must always have an angle of +360 deg. to appease
+            // quirky MCAD implementations of IDF.
+            IDF_SEGMENT* seg = new IDF_SEGMENT( sp, ep, 360.0, true );
+
+            if( seg )
+                lines.push_back( seg );
 
-                if( seg )
-                    lines.push_back( seg );
-            }
             break;
+        }
 
         default:
             break;
@@ -191,7 +197,7 @@ static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard )
         goto UseBoundingBox;
 
     aIDFBoard.AddBoardOutline( outline );
-    outline = NULL;
+    outline = nullptr;
 
     // get all cutouts and write them out
     while( !lines.empty() )
@@ -208,7 +214,7 @@ static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard )
         }
 
         aIDFBoard.AddBoardOutline( outline );
-        outline = NULL;
+        outline = nullptr;
     }
 
     return;
@@ -275,11 +281,9 @@ UseBoundingBox:
 
 
 /**
- * Function idf_export_footprint
- * retrieves information from all board footprints, adds drill holes to
- * the DRILLED_HOLES or BOARD_OUTLINE section as appropriate,
- * compiles data for the PLACEMENT section and compiles data for
- * the library ELECTRICAL section.
+ * Retrieve information from all board footprints, adds drill holes to the DRILLED_HOLES or
+ * BOARD_OUTLINE section as appropriate,  Compiles data for the PLACEMENT section and compiles
+ * data for the library ELECTRICAL section.
  */
 static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD& aIDFBoard )
 {
@@ -407,7 +411,7 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD
     // add any valid models to the library item list
     std::string refdes;
 
-    IDF3_COMPONENT* comp = NULL;
+    IDF3_COMPONENT* comp = nullptr;
 
     auto sM = aFootprint->Models().begin();
     auto eM = aFootprint->Models().end();
@@ -474,14 +478,14 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD
                 while( rotz <= -360.0 ) rotz += 360.0;
         }
 
-        if( comp == NULL )
+        if( comp == nullptr )
             comp = aIDFBoard.FindComponent( refdes );
 
-        if( comp == NULL )
+        if( comp == nullptr )
         {
             comp = new IDF3_COMPONENT( &aIDFBoard );
 
-            if( comp == NULL )
+            if( comp == nullptr )
                 throw( std::runtime_error( aIDFBoard.GetError() ) );
 
             comp->SetRefDes( refdes );
@@ -570,7 +574,6 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD
             }
         }
 
-
         // create the local data ...
         IDF3_COMP_OUTLINE_DATA* data = new IDF3_COMP_OUTLINE_DATA( comp, outline );
 
@@ -582,9 +585,8 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD
 
 
 /**
- * Function Export_IDF3
- * generates IDFv3 compliant board (*.emn) and library (*.emp)
- * files representing the user's PCB design.
+ * Generate IDFv3 compliant board (*.emn) and library (*.emp) files representing the user's
+ * PCB design.
  */
 bool PCB_EDIT_FRAME::Export_IDF3( BOARD* aPcb, const wxString& aFullFileName,
                                   bool aUseThou, double aXRef, double aYRef )
diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp
index 689b6a55f3..b16c47166d 100644
--- a/pcbnew/exporters/export_vrml.cpp
+++ b/pcbnew/exporters/export_vrml.cpp
@@ -56,7 +56,7 @@
 
 
 EXPORTER_PCB_VRML::EXPORTER_PCB_VRML() :
-        m_OutputPCB( (SGNODE*) NULL )
+        m_OutputPCB( nullptr )
 {
     m_ReuseDef = true;
     m_precision = 6;
@@ -101,10 +101,10 @@ EXPORTER_PCB_VRML::~EXPORTER_PCB_VRML()
     // destroy any unassociated material appearances
     for( int j = 0; j < VRML_COLOR_LAST; ++j )
     {
-        if( m_sgmaterial[j] && NULL == S3D::GetSGNodeParent( m_sgmaterial[j] ) )
+        if( m_sgmaterial[j] && nullptr == S3D::GetSGNodeParent( m_sgmaterial[j] ) )
             S3D::DestroyNode( m_sgmaterial[j] );
 
-        m_sgmaterial[j] = NULL;
+        m_sgmaterial[j] = nullptr;
     }
 
     if( !m_components.empty() )
@@ -114,7 +114,7 @@ EXPORTER_PCB_VRML::~EXPORTER_PCB_VRML()
         for( auto i : m_components )
         {
             tmp.Attach( i );
-            tmp.SetParent( NULL );
+            tmp.SetParent( nullptr );
         }
 
         m_components.clear();
@@ -176,6 +176,7 @@ bool EXPORTER_PCB_VRML::GetLayer3D( LAYER_NUM layer, VRML_LAYER** vlayer )
 void EXPORTER_PCB_VRML::ExportVrmlSolderMask()
 {
     SHAPE_POLY_SET holes, outlines = m_pcbOutlines;
+
     // holes is the solder mask opening.
     // the actual shape is the negative shape of mask opening.
     PCB_LAYER_ID pcb_layer = F_Mask;
@@ -198,7 +199,6 @@ void EXPORTER_PCB_VRML::ExportVrmlSolderMask()
 }
 
 
-// Build and export the 4 layers F_Cu, B_Cu, F_silk, B_Silk
 void EXPORTER_PCB_VRML::ExportStandardLayers()
 {
     SHAPE_POLY_SET outlines;
@@ -227,16 +227,15 @@ void EXPORTER_PCB_VRML::ExportStandardLayers()
     }
 }
 
-// static var. for dealing with text
+
 static EXPORTER_PCB_VRML* model_vrml;
 
 
 void EXPORTER_PCB_VRML::write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor,
-                                VRML_LAYER* aLayer, bool aPlane, bool aTop,
-                                double aTop_z, double aBottom_z )
+                                            VRML_LAYER* aLayer, bool aPlane, bool aTop,
+                                            double aTop_z, double aBottom_z )
 {
-    /* A lot of nodes are not required, but blender sometimes chokes
-     * without them */
+    // A lot of nodes are not required, but blender sometimes chokes without them.
     static const char* shape_boiler[] =
     {
         "Transform {\n",
@@ -273,7 +272,9 @@ void EXPORTER_PCB_VRML::write_triangle_bag( std::ostream& aOut_file, const VRML_
     while( marker_found < 4 )
     {
         if( shape_boiler[lineno] )
+        {
             aOut_file << shape_boiler[lineno];
+        }
         else
         {
             marker_found++;
@@ -335,8 +336,7 @@ void EXPORTER_PCB_VRML::write_triangle_bag( std::ostream& aOut_file, const VRML_
 }
 
 
-void EXPORTER_PCB_VRML::writeLayers( const char* aFileName,
-                              OSTREAM* aOutputFile )
+void EXPORTER_PCB_VRML::writeLayers( const char* aFileName, OSTREAM* aOutputFile )
 {
     // VRML_LAYER board;
     m_3D_board.Tesselate( &m_holes );
@@ -374,13 +374,15 @@ void EXPORTER_PCB_VRML::writeLayers( const char* aFileName,
     {
         write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
                             &m_top_paste, true, true,
-                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                            m_BoardToVrmlScale,
                             0 );
     }
     else
     {
         create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_top_paste,
-                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale,
                            true );
     }
 
@@ -391,13 +393,15 @@ void EXPORTER_PCB_VRML::writeLayers( const char* aFileName,
     {
         write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SOLDMASK ),
                             &m_top_soldermask, true, true,
-                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                            m_BoardToVrmlScale,
                             0 );
     }
     else
     {
         create_vrml_plane( m_OutputPCB, VRML_COLOR_SOLDMASK, &m_top_soldermask,
-                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale,
                            true );
     }
 
@@ -429,7 +433,8 @@ void EXPORTER_PCB_VRML::writeLayers( const char* aFileName,
     else
     {
         create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_bot_paste,
-                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale,
                            false );
     }
 
@@ -440,31 +445,37 @@ void EXPORTER_PCB_VRML::writeLayers( const char* aFileName,
     {
         write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SOLDMASK ),
                             &m_bot_soldermask, true, false,
-                            GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                            GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) *
+                            m_BoardToVrmlScale,
                             0 );
     }
     else
     {
         create_vrml_plane( m_OutputPCB, VRML_COLOR_SOLDMASK, &m_bot_soldermask,
-                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
+                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale,
                            false );
     }
 
     // VRML_LAYER PTH;
-    m_plated_holes.Tesselate( NULL, true );
+    m_plated_holes.Tesselate( nullptr, true );
 
     if( m_UseInlineModelsInBrdfile )
     {
         write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
                             &m_plated_holes, false, false,
-                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
-                            GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale );
+                            GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                            m_BoardToVrmlScale,
+                            GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) *
+                            m_BoardToVrmlScale );
     }
     else
     {
         create_vrml_shell( m_OutputPCB, VRML_COLOR_PASTE, &m_plated_holes,
-                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
-                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale );
+                           GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale,
+                           GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) *
+                           m_BoardToVrmlScale );
     }
 
     // VRML_LAYER m_top_silk;
@@ -559,7 +570,6 @@ void EXPORTER_PCB_VRML::ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_P
 }
 
 
-// board edges and cutouts
 void EXPORTER_PCB_VRML::ExportVrmlBoard()
 {
     if( !m_Pcb->GetBoardPolygonOutlines( m_pcbOutlines ) )
@@ -578,7 +588,7 @@ void EXPORTER_PCB_VRML::ExportVrmlBoard()
         for( int j = 0; j < outline.PointCount(); j++ )
         {
             m_3D_board.AddVertex( seg, (double)outline.CPoint(j).x * m_BoardToVrmlScale,
-                                    -((double)outline.CPoint(j).y * m_BoardToVrmlScale ) );
+                                  -((double)outline.CPoint(j).y * m_BoardToVrmlScale ) );
 
         }
 
@@ -600,7 +610,7 @@ void EXPORTER_PCB_VRML::ExportVrmlBoard()
             for( int j = 0; j < hole.PointCount(); j++ )
             {
                 m_holes.AddVertex( seg, (double) hole.CPoint(j).x * m_BoardToVrmlScale,
-                                          -( (double) hole.CPoint(j).y * m_BoardToVrmlScale ) );
+                                   -( (double) hole.CPoint(j).y * m_BoardToVrmlScale ) );
             }
 
             m_holes.EnsureWinding( seg, true );
@@ -608,9 +618,10 @@ void EXPORTER_PCB_VRML::ExportVrmlBoard()
     }
 }
 
-// Max error allowed to approximate a circle by segments, in mm
+
 static const double err_approx_max = 0.005;
 
+
 void EXPORTER_PCB_VRML::ExportVrmlViaHoles()
 {
     PCB_LAYER_ID top_layer, bottom_layer;
@@ -784,7 +795,7 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream
     {
         SGNODE* mod3d = (SGNODE*) m_Cache3Dmodels->Load( sM->m_Filename );
 
-        if( NULL == mod3d )
+        if( nullptr == mod3d )
         {
             ++sM;
             continue;
@@ -830,8 +841,8 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream
 
         if( isFlipped )
             offsetz = -offsetz;
-        else // In normal mode, Y axis is reversed in Pcbnew.
-            offsety = -offsety;
+        else
+            offsety = -offsety;  // In normal mode, Y axis is reversed in Pcbnew.
 
         RotatePoint( &offsetx, &offsety, aFootprint->GetOrientation() );
 
@@ -923,7 +934,7 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream
             modelShape->SetTranslation( trans );
             modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
 
-            if( NULL == S3D::GetSGNodeParent( mod3d ) )
+            if( nullptr == S3D::GetSGNodeParent( mod3d ) )
             {
                 m_components.push_back( mod3d );
                 modelShape->AddChildNode( mod3d );
@@ -1003,10 +1014,10 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt
         {
             // merge footprints in the .vrml board file
             for( FOOTPRINT* footprint : pcb->Footprints() )
-                model3d.ExportVrmlFootprint( footprint, NULL );
+                model3d.ExportVrmlFootprint( footprint, nullptr );
 
             // write out the board and all layers
-            model3d.writeLayers( TO_UTF8( aFullFileName ), NULL );
+            model3d.writeLayers( TO_UTF8( aFullFileName ), nullptr );
         }
     }
     catch( const std::exception& e )
@@ -1075,12 +1086,12 @@ SGNODE* EXPORTER_PCB_VRML::getSGColor( VRML_COLOR_INDEX colorIdx )
     if( colorIdx == -1 )
         colorIdx = VRML_COLOR_PCB;
     else if( colorIdx == VRML_COLOR_LAST )
-        return NULL;
+        return nullptr;
 
     if( m_sgmaterial[colorIdx] )
         return m_sgmaterial[colorIdx];
 
-    IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
+    IFSG_APPEARANCE vcolor( (SGNODE*) nullptr );
     VRML_COLOR* cp = &vrml_colors_list[colorIdx];
 
     vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
@@ -1098,7 +1109,7 @@ SGNODE* EXPORTER_PCB_VRML::getSGColor( VRML_COLOR_INDEX colorIdx )
 
 
 void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
-                                    VRML_LAYER* layer, double top_z, bool aTopPlane )
+                                           VRML_LAYER* layer, double top_z, bool aTopPlane )
 {
     std::vector< double > vertices;
     std::vector< int > idxPlane;
@@ -1110,7 +1121,8 @@ void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
 
     if( ( idxPlane.size() % 3 ) )
     {
-        throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
+        throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle "
+                                   "list)" ) );
     }
 
     std::vector< SGPOINT > vlist;
@@ -1122,7 +1134,7 @@ void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
 
     // create the intermediate scenegraph
     IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() );    // tx0 = Transform for this outline
-    IFSG_SHAPE shape( tx0 );            // shape will hold (a) all vertices and (b) a local list of normals
+    IFSG_SHAPE shape( tx0 );    // shape will hold (a) all vertices and (b) a local list of normals
     IFSG_FACESET face( shape );         // this face shall represent the top and bottom planes
     IFSG_COORDS cp( face );             // coordinates for all faces
     cp.SetCoordsList( nvert, &vlist[0] );
@@ -1145,9 +1157,9 @@ void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
     // assign a color from the palette
     SGNODE* modelColor = getSGColor( colorID );
 
-    if( NULL != modelColor )
+    if( nullptr != modelColor )
     {
-        if( NULL == S3D::GetSGNodeParent( modelColor ) )
+        if( nullptr == S3D::GetSGNodeParent( modelColor ) )
             shape.AddChildNode( modelColor );
         else
             shape.AddRefNode( modelColor );
@@ -1156,7 +1168,7 @@ void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
 
 
 void EXPORTER_PCB_VRML::create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
-                                    VRML_LAYER* layer, double top_z, double bottom_z )
+                                           VRML_LAYER* layer, double top_z, double bottom_z )
 {
     std::vector< double > vertices;
     std::vector< int > idxPlane;
@@ -1190,7 +1202,7 @@ void EXPORTER_PCB_VRML::create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
 
     // create the intermediate scenegraph
     IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() );    // tx0 = Transform for this outline
-    IFSG_SHAPE shape( tx0 );            // shape will hold (a) all vertices and (b) a local list of normals
+    IFSG_SHAPE shape( tx0 );    // shape will hold (a) all vertices and (b) a local list of normals
     IFSG_FACESET face( shape );         // this face shall represent the top and bottom planes
     IFSG_COORDS cp( face );             // coordinates for all faces
     cp.SetCoordsList( nvert, &vlist[0] );
@@ -1212,9 +1224,9 @@ void EXPORTER_PCB_VRML::create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR
     // assign a color from the palette
     SGNODE* modelColor = getSGColor( colorID );
 
-    if( NULL != modelColor )
+    if( nullptr != modelColor )
     {
-        if( NULL == S3D::GetSGNodeParent( modelColor ) )
+        if( nullptr == S3D::GetSGNodeParent( modelColor ) )
             shape.AddChildNode( modelColor );
         else
             shape.AddRefNode( modelColor );
diff --git a/pcbnew/exporters/gen_drill_report_files.cpp b/pcbnew/exporters/gen_drill_report_files.cpp
index 0249413f7a..c4c3620b17 100644
--- a/pcbnew/exporters/gen_drill_report_files.cpp
+++ b/pcbnew/exporters/gen_drill_report_files.cpp
@@ -7,7 +7,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 1992-2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
- * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -44,6 +44,7 @@
 #include <gendrill_file_writer_base.h>
 #include <pcb_painter.h>
 
+
 /* Conversion utilities - these will be used often in there... */
 inline double diameter_in_inches( double ius )
 {
@@ -72,7 +73,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
 
     double    scale = 1.0;
     wxPoint   offset = GetOffset();
-    PLOTTER*  plotter = NULL;
+    PLOTTER*  plotter = nullptr;
     PAGE_INFO dummy( PAGE_INFO::A4, false );
     int       bottom_limit = 0;        // Y coord limit of page. 0 mean do not use
 
@@ -157,8 +158,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
 
         plotter->SetPageSettings( pageA4 );
         plotter->SetViewport( offset, IU_PER_MILS / 10, scale, false );
+        break;
     }
-    break;
 
     case PLOT_FORMAT::DXF:
     {
@@ -172,8 +173,8 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
         plotter = dxf_plotter;
         plotter->SetPageSettings( page_info );
         plotter->SetViewport( offset, IU_PER_MILS / 10, scale, false );
+        break;
     }
-    break;
     }
 
     plotter->SetCreator( wxT( "PCBNEW" ) );
@@ -233,6 +234,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
 
     // Print a list of symbols used.
     int    charSize = Millimeter2iu( 2 );  // text size in IUs
+
     // real char scale will be 1/scale, because the global plot scale is scale
     // for scale < 1.0 ( plot bigger actual size)
     // Therefore charScale = 1.0 / scale keep the initial charSize
@@ -276,6 +278,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
         }
 
         int plot_diam = KiROUND( tool.m_Diameter );
+
         // For markers plotted with the comment, keep marker size <= text height
         plot_diam = std::min( plot_diam, KiROUND( charSize * charScale ) );
         int x = KiROUND( plotX - textmarginaftersymbol * charScale - plot_diam / 2.0 );
@@ -302,7 +305,7 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
             sprintf( line, "(%d holes + 1 slot)", tool.m_TotalCount - 1 );
         else // if ( toolm_OvalCount > 1 )
             sprintf( line, "(%d holes + %d slots)", tool.m_TotalCount - tool.m_OvalCount,
-                    tool.m_OvalCount );
+                     tool.m_OvalCount );
 
         msg += FROM_UTF8( line );
 
@@ -452,7 +455,7 @@ bool GENDRILL_WRITER_BASE::plotDrillMarks( PLOTTER* aPlotter )
         if( hole.m_Hole_Shape != 0 )
         {
             wxSize oblong_size = hole.m_Hole_Size;
-            aPlotter->FlashPadOval( pos, oblong_size, hole.m_Hole_Orient, SKETCH, NULL );
+            aPlotter->FlashPadOval( pos, oblong_size, hole.m_Hole_Orient, SKETCH, nullptr );
         }
     }
 
diff --git a/pcbnew/exporters/gen_footprints_placefile.cpp b/pcbnew/exporters/gen_footprints_placefile.cpp
index fc60069b9c..e5310d09c2 100644
--- a/pcbnew/exporters/gen_footprints_placefile.cpp
+++ b/pcbnew/exporters/gen_footprints_placefile.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -22,7 +22,7 @@
  */
 
 /*
- *  1 - create ascii files for automatic placement of smd components
+ *  1 - create ASCII files for automatic placement of smd components
  *  2 - create a footprint report (pos and footprint descr) (ascii file)
  */
 
@@ -75,15 +75,6 @@ public:
     }
 
 private:
-    PCB_EDIT_FRAME* m_parent;
-    PCB_PLOT_PARAMS m_plotOpts;
-    REPORTER* m_reporter;
-
-    static int m_unitsOpt;
-    static int m_fileOpt;
-    static int m_fileFormat;
-    static bool m_includeBoardEdge;
-
     void initDialog();
     void OnOutputDirectoryBrowseClicked( wxCommandEvent& event ) override;
     void OnGenerate( wxCommandEvent& event ) override;
@@ -116,11 +107,13 @@ private:
         m_cbIncludeBoardEdge->Enable( m_rbFormat->GetSelection() == 2 );
     }
 
-    /** Creates files in text or csv format
+    /**
+     * Creates files in text or csv format
      */
     bool CreateAsciiFiles();
 
-    /** Creates placement files in gerber format
+    /**
+     * Creates placement files in gerber format
      */
     bool CreateGerberFiles();
 
@@ -139,6 +132,15 @@ private:
     {
         return m_excludeTH->GetValue();
     }
+
+    PCB_EDIT_FRAME* m_parent;
+    PCB_PLOT_PARAMS m_plotOpts;
+    REPORTER* m_reporter;
+
+    static int m_unitsOpt;
+    static int m_fileOpt;
+    static int m_fileFormat;
+    static bool m_includeBoardEdge;
 };
 
 
@@ -148,7 +150,6 @@ int DIALOG_GEN_FOOTPRINT_POSITION::m_fileFormat = 0;
 bool DIALOG_GEN_FOOTPRINT_POSITION::m_includeBoardEdge = false;
 
 
-
 void DIALOG_GEN_FOOTPRINT_POSITION::initDialog()
 {
     m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
@@ -197,13 +198,15 @@ void DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked( wxCommandEve
         wxString boardFilePath = ( (wxFileName) m_parent->GetBoard()->GetFileName() ).GetPath();
 
         if( !dirName.MakeRelativeTo( boardFilePath ) )
-            wxMessageBox( _( "Cannot make path relative (target volume different from board file volume)!" ),
+            wxMessageBox( _( "Cannot make path relative (target volume different from board "
+                             "file volume)!" ),
                           _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
     }
 
     m_outputDirectoryName->SetValue( dirName.GetFullPath() );
 }
 
+
 void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
 {
     m_fileOpt = m_radioBoxFilesCount->GetSelection();
@@ -234,6 +237,7 @@ void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
         CreateAsciiFiles();
 }
 
+
 bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles()
 {
     BOARD*     brd = m_parent->GetBoard();
@@ -364,10 +368,12 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
     if( singleFile )
     {
         bottomSide = true;
-        fn.SetName( fn.GetName() + wxT( "-" ) + wxT("all") );
+        fn.SetName( fn.GetName() + wxT( "-" ) + wxT( "all" ) );
     }
     else
+    {
         fn.SetName( fn.GetName() + wxT( "-" ) + PLACE_FILE_EXPORTER::GetFrontSideName().c_str() );
+    }
 
 
     if( useCSVfmt )
@@ -376,7 +382,9 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
         fn.SetExt( wxT( "csv" ) );
     }
     else
+    {
         fn.SetExt( FootprintPlaceFileExtension );
+    }
 
     int fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
                                                          ExcludeAllTH(), topSide, bottomSide,
@@ -419,7 +427,9 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
         fn.SetExt( wxT( "csv" ) );
     }
     else
+    {
         fn.SetExt( FootprintPlaceFileExtension );
+    }
 
     fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(), ExcludeAllTH(),
                                                      topSide, bottomSide, useCSVfmt, useAuxOrigin );
@@ -470,13 +480,13 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName,
                                                  bool aBottomSide, bool aFormatCSV,
                                                  bool aUseAuxOrigin )
 {
-    FILE * file = NULL;
+    FILE * file = nullptr;
 
     if( !aFullFileName.IsEmpty() )
     {
         file = wxFopen( aFullFileName, wxT( "wt" ) );
 
-        if( file == NULL )
+        if( file == nullptr )
             return -1;
     }
 
@@ -519,6 +529,7 @@ void PCB_EDIT_FRAME::GenFootprintsReport( wxCommandEvent& event )
     bool success = DoGenFootprintsReport( fn.GetFullPath(), unitMM );
 
     wxString msg;
+
     if( success )
     {
         msg.Printf( _( "Footprint report file created:\n'%s'." ), fn.GetFullPath() );
@@ -532,13 +543,12 @@ void PCB_EDIT_FRAME::GenFootprintsReport( wxCommandEvent& event )
     }
 }
 
-/* Print a footprint report.
- */
+
 bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool aUnitsMM )
 {
     FILE* rptfile = wxFopen( aFullFilename, wxT( "wt" ) );
 
-    if( rptfile == NULL )
+    if( rptfile == nullptr )
         return false;
 
     std::string data;
diff --git a/pcbnew/exporters/gendrill_Excellon_writer.cpp b/pcbnew/exporters/gendrill_Excellon_writer.cpp
index 163064b8a0..1780f4d8b7 100644
--- a/pcbnew/exporters/gendrill_Excellon_writer.cpp
+++ b/pcbnew/exporters/gendrill_Excellon_writer.cpp
@@ -51,16 +51,18 @@
 #include <reporter.h>
 #include <gbr_metadata.h>
 
+
 // Oblong holes can be drilled by a "canned slot" command (G85) or a routing command
 // a linear routing command (G01) is perhaps more usual for drill files
 //
 // set m_useRouteModeForOval to false to use a canned slot hole (old way)
 // set m_useRouteModeForOval to true (preferred mode) to use a linear routed hole (new way)
 
+
 EXCELLON_WRITER::EXCELLON_WRITER( BOARD* aPcb )
     : GENDRILL_WRITER_BASE( aPcb )
 {
-    m_file = NULL;
+    m_file = nullptr;
     m_zeroFormat      = DECIMAL_FORMAT;
     m_conversionUnits = 0.0001;
     m_mirror = false;
@@ -108,13 +110,14 @@ void EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
 
                 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
 
-                if( file == NULL )
+                if( file == nullptr )
                 {
                     if( aReporter )
                     {
                         msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
                         aReporter->Report( msg, RPT_SEVERITY_ERROR );
                     }
+
                     break;
                 }
                 else
@@ -205,6 +208,7 @@ int EXCELLON_WRITER::createDrillFile( FILE* aFile, DRILL_LAYER_PAIR aLayerPair,
 #if USE_ATTRIB_FOR_HOLES
         writeHoleAttribute( tool_descr.m_HoleAttribute );
 #endif
+
         // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
         // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
         if( m_unitsMetric )
@@ -344,10 +348,8 @@ int EXCELLON_WRITER::createDrillFile( FILE* aFile, DRILL_LAYER_PAIR aLayerPair,
 }
 
 
-void EXCELLON_WRITER::SetFormat( bool      aMetric,
-                                 ZEROS_FMT aZerosFmt,
-                                 int       aLeftDigits,
-                                 int       aRightDigits )
+void EXCELLON_WRITER::SetFormat( bool aMetric, ZEROS_FMT aZerosFmt, int aLeftDigits,
+                                 int aRightDigits )
 {
     m_unitsMetric = aMetric;
     m_zeroFormat   = aZerosFmt;
@@ -477,8 +479,7 @@ void EXCELLON_WRITER::writeCoordinates( char* aLine, double aCoordX, double aCoo
 }
 
 
-void EXCELLON_WRITER::writeEXCELLONHeader( DRILL_LAYER_PAIR aLayerPair,
-                                           TYPE_FILE aHolesType )
+void EXCELLON_WRITER::writeEXCELLONHeader( DRILL_LAYER_PAIR aLayerPair, TYPE_FILE aHolesType )
 {
     fputs( "M48\n", m_file );    // The beginning of a header
 
@@ -567,7 +568,7 @@ void EXCELLON_WRITER::writeEXCELLONHeader( DRILL_LAYER_PAIR aLayerPair,
 
 void EXCELLON_WRITER::writeEXCELLONEndOfFile()
 {
-    //add if minimal here
+    // add if minimal here
     fputs( "T0\nM30\n", m_file );
     fclose( m_file );
 }
diff --git a/pcbnew/exporters/gendrill_gerber_writer.cpp b/pcbnew/exporters/gendrill_gerber_writer.cpp
index fc8ec0a2f9..72c52f7731 100644
--- a/pcbnew/exporters/gendrill_gerber_writer.cpp
+++ b/pcbnew/exporters/gendrill_gerber_writer.cpp
@@ -84,8 +84,9 @@ void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, b
 
         // The file is created if it has holes, or if it is the non plated drill file
         // to be sure the NPTH file is up to date in separate files mode.
-        // Also a PTH drill/map file is always created, to be sure at least one plated hole drill file
-        // is created (do not create any PTH drill file can be seen as not working drill generator).
+        // Also a PTH drill/map file is always created, to be sure at least one plated hole drill
+        // file is created (do not create any PTH drill file can be seen as not working drill
+        // generator).
         if( getHolesCount() > 0 || doing_npth || pair == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
         {
             fn = getDrillFileName( pair, doing_npth, false );
@@ -104,6 +105,7 @@ void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, b
                         msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
                         aReporter->Report( msg, RPT_SEVERITY_ERROR );
                     }
+
                     break;
                 }
                 else
@@ -123,11 +125,13 @@ void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, b
         CreateMapFilesSet( aPlotDirectory, aReporter );
 }
 
+
 #if !FLASH_OVAL_HOLE
 // A helper class to transform an oblong hole to a segment
 static void convertOblong2Segment( wxSize aSize, double aOrient, wxPoint& aStart, wxPoint& aEnd );
 #endif
 
+
 int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
                                     DRILL_LAYER_PAIR aLayerPair )
 {
@@ -145,6 +149,7 @@ int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
     // Add the standard X2 header, without FileFunction
     AddGerberX2Header( &plotter, m_pcb );
     plotter.SetViewport( m_offset, IU_PER_MILS/10, /* scale */ 1.0, /* mirror */false );
+
     // has meaning only for gerber plotter. Must be called only after SetViewport
     plotter.SetGerberCoordinatesFormat( 6 );
     plotter.SetCreator( wxT( "PCBNEW" ) );
@@ -189,7 +194,7 @@ int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
             if( !last_item_is_via )
             {
                 // be sure the current object attribute is cleared for vias
-                plotter.EndBlock( NULL );
+                plotter.EndBlock( nullptr );
             }
 
             last_item_is_via = true;
@@ -200,11 +205,13 @@ int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
             const PAD* pad = dyn_cast<const PAD*>( hole_descr.m_ItemParent );
 
             if( pad->GetProperty() == PAD_PROP::CASTELLATED )
+            {
                 gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CASTELLATEDDRILL );
+            }
             else
             {
-                // Good practice of oblong pad holes (slots) is to use a specific aperture for routing, not used
-                // in drill commands
+                // Good practice of oblong pad holes (slots) is to use a specific aperture for
+                // routing, not used in drill commands.
                 if( hole_descr.m_Hole_Shape )
                     gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CMP_OBLONG_DRILL );
                 else
@@ -220,23 +227,21 @@ int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
 
         if( hole_descr.m_Hole_Shape )
         {
-            #if FLASH_OVAL_HOLE     // set to 1 to use flashed oblong holes,
+#if FLASH_OVAL_HOLE     // set to 1 to use flashed oblong holes,
                                     // 0 to draw them as a line.
             plotter.FlashPadOval( hole_pos, hole_descr.m_Hole_Size,
                                   hole_descr.m_Hole_Orient, FILLED, &gbr_metadata );
-            #else
+#else
             // Use routing for oblong hole (Slots)
             wxPoint start, end;
-            convertOblong2Segment( hole_descr.m_Hole_Size,
-                                   hole_descr.m_Hole_Orient, start, end );
+            convertOblong2Segment( hole_descr.m_Hole_Size, hole_descr.m_Hole_Orient, start, end );
             int width = std::min( hole_descr.m_Hole_Size.x, hole_descr.m_Hole_Size.y );
 
             if ( width == 0 )
                 continue;
 
-            plotter.ThickSegment( start+hole_pos, end+hole_pos,
-                                  width, FILLED, &gbr_metadata );
-            #endif
+            plotter.ThickSegment( start+hole_pos, end+hole_pos, width, FILLED, &gbr_metadata );
+#endif
         }
         else
         {
@@ -280,6 +285,7 @@ void convertOblong2Segment( wxSize aSize, double aOrient, wxPoint& aStart, wxPoi
 }
 #endif
 
+
 void GERBER_WRITER::SetFormat( int aRightDigits )
 {
     /* Set conversion scale depending on drill file units */
diff --git a/pcbnew/exporters/gendrill_gerber_writer.h b/pcbnew/exporters/gendrill_gerber_writer.h
index 596089d2f9..dbb88f9074 100644
--- a/pcbnew/exporters/gendrill_gerber_writer.h
+++ b/pcbnew/exporters/gendrill_gerber_writer.h
@@ -7,7 +7,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 1992-2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
- * Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -47,17 +47,18 @@ public:
     }
 
     /**
-     * Function SetFormat
-     * Initialize internal parameters to match the given format
-     * @param aRightDigits = number of digits for mantissa part of coordinates (5 or 6)
+     * Initialize internal parameters to match the given format.
+     *
+     * @param aRightDigits is the number of digits for mantissa part of coordinates (5 or 6).
      */
     void SetFormat( int aRightDigits = 6 );
 
     /**
-     * Function SetOptions
-     * Initialize internal parameters to match drill options
-     * note: PTH and NPTH are always separate files in Gerber format
-     * @param aOffset = drill coordinates offset
+     * Initialize internal parameters to match drill options.
+     *
+     * @note PTH and NPTH are always separate files in Gerber format.
+     *
+     * @param aOffset is the drill coordinates offset.
      */
     void SetOptions( wxPoint aOffset )
     {
@@ -66,38 +67,38 @@ public:
     }
 
     /**
-     * Function CreateDrillandMapFilesSet
-     * Creates the full set of Excellon drill file for the board
-     * filenames are computed from the board name, and layers id
-     * @param aPlotDirectory = the output folder
-     * @param aGenDrill = true to generate the EXCELLON drill file
-     * @param aGenMap = true to generate a drill map file
-     * @param aReporter = a REPORTER to return activity or any message (can be NULL)
+     * Create the full set of Excellon drill file for the board filenames are computed from
+     * the board name, and layers id.
+     *
+     * @param aPlotDirectory is the output folder.
+     * @param aGenDrill set to true to generate the EXCELLON drill file.
+     * @param aGenMap set to true to generate a drill map file.
+     * @param aReporter is a #REPORTER to return activity or any message (can be NULL).
      */
     void CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
                                     bool aGenDrill, bool aGenMap,
-                                    REPORTER * aReporter = NULL );
+                                    REPORTER * aReporter = nullptr );
 
 private:
     /**
-     * Function createDrillFile
-     * Creates an Excellon drill file
-     * @param aFullFilename = the full filename
-     * @param aIsNpth = true for a NPTH file, false for a PTH file
-     * @param aLayerPair = first board layer and the last board layer for this drill file
-     * for blind buried vias, they are not always top and bottom layers
-     * @return hole count, or -1 if the file cannot be created
+     * Create an Excellon drill file.
+     *
+     * @param aFullFilename is the full file name.
+     * @param aIsNpth set to true for a NPTH file or false for a PTH file.
+     * @param aLayerPair is the first board layer and the last board layer for this drill file
+     *                   for blind buried vias, they are not always top and bottom layers/
+     * @return hole count or -1 if the file cannot be created.
      */
-    int  createDrillFile( wxString& aFullFilename, bool aIsNpth, DRILL_LAYER_PAIR aLayerPair );
+    int createDrillFile( wxString& aFullFilename, bool aIsNpth, DRILL_LAYER_PAIR aLayerPair );
 
     /**
-     * @return a filename which identify the drill file function.
-     * it is the board name with the layer pair names added, and for separate
-     * (PTH and NPTH) files, "-NPH" or "-NPTH" added
-     * @param aPair = the layer pair
-     * @param aNPTH = true to generate the filename of NPTH holes
-     * @param aMerge_PTH_NPTH = true to generate the filename of a file which containd both
-     * NPH and NPTH holes
+     * @param aPair is the layer pair.
+     * @param aNPTH set to true to generate the filename of NPTH holes.
+     * @param aMerge_PTH_NPTH set to true to generate the filename of a file which contains both
+     *                        NPH and NPTH holes
+     * @return a filename which identify the drill file function.  It is the board name with the
+     *         layer pair names added, and for separate (PTH and NPTH) files, "-NPH" or "-NPTH"
+     *         added.
      */
     virtual const wxString getDrillFileName( DRILL_LAYER_PAIR aPair, bool aNPTH,
                                              bool aMerge_PTH_NPTH ) const override;
diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp
index 8f71f6cd4e..97b9839d2f 100644
--- a/pcbnew/files.cpp
+++ b/pcbnew/files.cpp
@@ -197,7 +197,9 @@ bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, int* aCtl, wxString* aFileNa
         return true;
     }
     else
+    {
         return false;
+    }
 }
 
 
@@ -694,7 +696,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
             unsigned startTime = GetRunningMicroSecs();
 #endif
 
-            loadedBoard = pi->Load( fullFileName, NULL, &props, &Prj(), &progressReporter );
+            loadedBoard = pi->Load( fullFileName, nullptr, &props, &Prj(), &progressReporter );
 
 #if USE_INSTRUMENTATION
             unsigned stopTime = GetRunningMicroSecs();
@@ -1007,7 +1009,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
 
         wxASSERT( tempFile.IsAbsolute() );
 
-        pi->Save( tempFile.GetFullPath(), GetBoard(), NULL );
+        pi->Save( tempFile.GetFullPath(), GetBoard(), nullptr );
     }
     catch( const IO_ERROR& ioe )
     {
@@ -1108,7 +1110,7 @@ bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName, bool aCreateProject
 
         wxASSERT( pcbFileName.IsAbsolute() );
 
-        pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL );
+        pi->Save( pcbFileName.GetFullPath(), GetBoard(), nullptr );
     }
     catch( const IO_ERROR& ioe )
     {
diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h
index 61ede54166..e1cc8468de 100644
--- a/pcbnew/footprint.h
+++ b/pcbnew/footprint.h
@@ -323,7 +323,7 @@ public:
     */
 
     void SetLastEditTime( timestamp_t aTime ) { m_lastEditTime = aTime; }
-    void SetLastEditTime() { m_lastEditTime = time( NULL ); }
+    void SetLastEditTime() { m_lastEditTime = time( nullptr ); }
     timestamp_t GetLastEditTime() const { return m_lastEditTime; }
 
     /**
diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp
index aabf63e7d2..c8a1193e2e 100644
--- a/pcbnew/footprint_edit_frame.cpp
+++ b/pcbnew/footprint_edit_frame.cpp
@@ -612,7 +612,8 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
     if( IsContentModified() )
     {
         // Shutdown blocks must be determined and vetoed as early as possible
-        if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
+        if( KIPLATFORM::APP::SupportsShutdownBlockReason() &&
+            aEvent.GetId() == wxEVT_QUERY_END_SESSION )
         {
             aEvent.Veto();
             return false;
@@ -639,7 +640,7 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
 void FOOTPRINT_EDIT_FRAME::doCloseWindow()
 {
     // No more vetos
-    GetCanvas()->SetEventDispatcher( NULL );
+    GetCanvas()->SetEventDispatcher( nullptr );
     GetCanvas()->StopDrawing();
 
     // Do not show the layer manager during closing to avoid flicker
@@ -677,7 +678,7 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard( wxUpdateUIEvent& aEve
 {
     PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
 
-    aEvent.Enable( frame && frame->GetBoard()->GetFirstFootprint() != NULL );
+    aEvent.Enable( frame && frame->GetBoard()->GetFirstFootprint() != nullptr );
 }
 
 
@@ -827,7 +828,7 @@ void FOOTPRINT_EDIT_FRAME::initLibraryTree()
     if( GFootprintList.GetCount() == 0 )
         GFootprintList.ReadCacheFromFile( Prj().GetProjectPath() + "fp-info-cache" );
 
-    GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
+    GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter );
     progressReporter.Show( false );
 
     if( GFootprintList.GetErrorCount() )
@@ -851,12 +852,12 @@ void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress )
     if( aProgress )
     {
         WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
-        GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
+        GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter );
         progressReporter.Show( false );
     }
     else
     {
-        GFootprintList.ReadFootprintFiles( fpTable, NULL, NULL );
+        GFootprintList.ReadFootprintFiles( fpTable, nullptr, nullptr );
     }
 
     // Sync the LIB_TREE to the FOOTPRINT_INFO list
diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp
index 9ed872e248..a3f9218149 100644
--- a/pcbnew/footprint_editor_utils.cpp
+++ b/pcbnew/footprint_editor_utils.cpp
@@ -43,7 +43,7 @@ using namespace std::placeholders;
 
 void FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( wxCommandEvent& event )
 {
-    LoadFootprintFromBoard( NULL );
+    LoadFootprintFromBoard( nullptr );
 }
 
 
@@ -209,8 +209,9 @@ void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem )
             commit.Push( _( "Edit Zone" ) );
             zoneSettings.ExportSetting( *static_cast<ZONE*>( aItem ) );
         }
+
+        break;
     }
-    break;
 
     case PCB_GROUP_T:
         m_toolManager->RunAction( PCB_ACTIONS::groupProperties, true, aItem );
@@ -282,7 +283,8 @@ void FOOTPRINT_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
                 msg.Printf( _( "The current configuration does not include a library named '%s'.\n"
                                "Use Manage Footprint Libraries to edit the configuration." ),
                             fpFileName.GetPath() );
-                DisplayErrorMessage( this, _( "Library not found in footprint library table." ), msg );
+                DisplayErrorMessage( this, _( "Library not found in footprint library table." ),
+                                     msg );
                 break;
             }
 
diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp
index e0b824c54d..744b5f17ca 100644
--- a/pcbnew/footprint_info_impl.cpp
+++ b/pcbnew/footprint_info_impl.cpp
@@ -47,7 +47,7 @@ void FOOTPRINT_INFO_IMPL::load()
 
     const FOOTPRINT* footprint = fptable->GetEnumeratedFootprint( m_nickname, m_fpname );
 
-    if( footprint == NULL ) // Should happen only with malformed/broken libraries
+    if( footprint == nullptr ) // Should happen only with malformed/broken libraries
     {
         m_pad_count = 0;
         m_unique_pad_count = 0;
@@ -87,6 +87,7 @@ bool FOOTPRINT_LIST_IMPL::CatchErrors( const std::function<void()>& aFunc )
         {
             m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
         }
+
         return false;
     }
 
@@ -137,7 +138,6 @@ bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxStri
     loader.SetList( this );
     loader.Start( aTable, aNickname );
 
-
     while( !m_cancelled && (int)m_count_finished.load() < m_loader->m_total_libs )
     {
         if( m_progress_reporter && !m_progress_reporter->KeepRefreshing() )
@@ -166,7 +166,7 @@ bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxStri
     }
 
     if( m_cancelled )
-        m_list_timestamp = 0;       // God knows what we got before we were cancelled
+        m_list_timestamp = 0;       // God knows what we got before we were canceled
     else
         m_list_timestamp = generatedTimestamp;
 
@@ -189,7 +189,9 @@ void FOOTPRINT_LIST_IMPL::startWorkers( FP_LIB_TABLE* aTable, wxString const* aN
     m_queue_out.clear();
 
     if( aNickname )
+    {
         m_queue_in.push( *aNickname );
+    }
     else
     {
         for( auto const& nickname : aTable->GetLogicalLibs() )
@@ -204,6 +206,7 @@ void FOOTPRINT_LIST_IMPL::startWorkers( FP_LIB_TABLE* aTable, wxString const* aN
     }
 }
 
+
 void FOOTPRINT_LIST_IMPL::stopWorkers()
 {
     std::lock_guard<std::mutex> lock1( m_join );
@@ -219,11 +222,12 @@ void FOOTPRINT_LIST_IMPL::stopWorkers()
     m_queue_in.clear();
     m_count_finished.store( 0 );
 
-    // If we have cancelled in the middle of a load, clear our timestamp to re-load next time
+    // If we have canceled in the middle of a load, clear our timestamp to re-load next time
     if( m_cancelled )
         m_list_timestamp = 0;
 }
 
+
 bool FOOTPRINT_LIST_IMPL::joinWorkers()
 {
     {
@@ -242,7 +246,7 @@ bool FOOTPRINT_LIST_IMPL::joinWorkers()
     LOCALE_IO toggle_locale;
 
     // Parse the footprints in parallel. WARNING! This requires changing the locale, which is
-    // GLOBAL. It is only threadsafe to construct the LOCALE_IO before the threads are created,
+    // GLOBAL. It is only thread safe to construct the LOCALE_IO before the threads are created,
     // destroy it after they finish, and block the main (GUI) thread while they work. Any deviation
     // from this will cause nasal demons.
     //
@@ -313,11 +317,12 @@ bool FOOTPRINT_LIST_IMPL::joinWorkers()
     while( queue_parsed.pop( fpi ) )
         m_list.push_back( std::move( fpi ) );
 
-    std::sort( m_list.begin(), m_list.end(), []( std::unique_ptr<FOOTPRINT_INFO> const& lhs,
-                                                 std::unique_ptr<FOOTPRINT_INFO> const& rhs ) -> bool
-                                             {
-                                                 return *lhs < *rhs;
-                                             } );
+    std::sort( m_list.begin(), m_list.end(),
+               []( std::unique_ptr<FOOTPRINT_INFO> const& lhs,
+                   std::unique_ptr<FOOTPRINT_INFO> const& rhs ) -> bool
+               {
+                   return *lhs < *rhs;
+               } );
 
     return m_errors.empty();
 }
diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp
index b501cc35d1..bc1037aa44 100644
--- a/pcbnew/footprint_viewer_frame.cpp
+++ b/pcbnew/footprint_viewer_frame.cpp
@@ -2,8 +2,8 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -144,7 +144,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
     libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
 
     m_libList = new wxListBox( libPanel, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
-                               0, NULL, wxLB_HSCROLL | wxNO_BORDER );
+                               0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
     libSizer->Add( m_libList, 1, wxEXPAND, 5 );
 
     libPanel->SetSizer( libSizer );
@@ -163,7 +163,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
     fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
 
     m_fpList = new wxListBox( fpPanel, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
-                              0, NULL, wxLB_HSCROLL | wxNO_BORDER );
+                              0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
     fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
 
     fpPanel->SetSizer( fpSizer );
@@ -312,14 +312,18 @@ void FOOTPRINT_VIEWER_FRAME::setupUIConditions()
 
     mgr->SetConditions( ACTIONS::toggleGrid,             CHECK( cond.GridVisible() ) );
     mgr->SetConditions( ACTIONS::toggleCursorStyle,      CHECK( cond.FullscreenCursor() ) );
-    mgr->SetConditions( ACTIONS::millimetersUnits,       CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
+    mgr->SetConditions( ACTIONS::millimetersUnits,
+                        CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
     mgr->SetConditions( ACTIONS::inchesUnits,            CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
     mgr->SetConditions( ACTIONS::milsUnits,              CHECK( cond.Units( EDA_UNITS::MILS ) ) );
 
 
-    mgr->SetConditions( ACTIONS::zoomTool,               CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
-    mgr->SetConditions( ACTIONS::measureTool,            CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
-    mgr->SetConditions( ACTIONS::selectionTool,          CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
+    mgr->SetConditions( ACTIONS::zoomTool,
+                        CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
+    mgr->SetConditions( ACTIONS::measureTool,
+                        CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
+    mgr->SetConditions( ACTIONS::selectionTool,
+                        CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
 
     mgr->SetConditions( PCB_ACTIONS::showPadNumbers,     CHECK( cond.PadNumbersDisplay() ) );
     mgr->SetConditions( PCB_ACTIONS::padDisplayMode,     CHECK( !cond.PadFillDisplay() ) );
@@ -358,7 +362,9 @@ void FOOTPRINT_VIEWER_FRAME::doCloseWindow()
         // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
     }
     else
+    {
         Destroy();
+    }
 }
 
 
@@ -441,7 +447,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
 
     wxString nickname = getCurNickname();
 
-    fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
+    fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? nullptr : &nickname );
 
     if( fp_info_list->GetErrorCount() )
     {
@@ -498,7 +504,9 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
             ClickOnFootprintList( dummy );
         }
         else
+        {
             setCurFootprintName( wxEmptyString );
+        }
     }
     else
     {
@@ -564,7 +572,9 @@ void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
         AddFootprintToPCB( dummy );
     }
     else
+    {
         aEvent.Skip();
+    }
 }
 
 
@@ -656,11 +666,10 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent )
         }
         catch( const IO_ERROR& ioe )
         {
-            wxString msg = wxString::Format( _( "Could not load footprint '%s' from library '%s'."
-                                                "\n\n%s" ),
-                                             getCurFootprintName(),
-                                             getCurNickname(),
-                                             ioe.Problem() );
+            wxString msg =
+                    wxString::Format( _( "Could not load footprint '%s' from library '%s'."
+                                         "\n\n%s" ),
+                                      getCurFootprintName(), getCurNickname(), ioe.Problem() );
             DisplayError( this, msg );
         }
 
@@ -698,7 +707,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
     {
         PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
 
-        if( pcbframe == NULL )      // happens when the board editor is not active (or closed)
+        if( pcbframe == nullptr )      // happens when the board editor is not active (or closed)
         {
             DisplayErrorMessage( this, _( "No board currently open." ) );
             return;
@@ -726,7 +735,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
         // (Can be stored flipped if the lib is an archive built from a board)
         if( newFootprint->IsFlipped() )
             newFootprint->Flip( newFootprint->GetPosition(),
-                    pcbframe->Settings().m_FlipLeftRight );
+                                pcbframe->Settings().m_FlipLeftRight );
 
         KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
         VECTOR2D              cursorPos = viewControls->GetCursorPosition();
diff --git a/pcbnew/footprint_wizard.cpp b/pcbnew/footprint_wizard.cpp
index c63b8fbf8e..728e104c0f 100644
--- a/pcbnew/footprint_wizard.cpp
+++ b/pcbnew/footprint_wizard.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013 NBEE Embedded Systems SL, Miguel Angel Ajo <miguelangel@ajo.es>
- * Copyright (C) 2013 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -64,7 +64,7 @@ FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_LIST::GetWizard( const wxString& aName )
             return wizard;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp
index 9a2fd050ee..4d5ba310f9 100644
--- a/pcbnew/footprint_wizard_frame.cpp
+++ b/pcbnew/footprint_wizard_frame.cpp
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2012-2015 Miguel Angel Ajo Pelayo <miguelangel@nbee.es>
  * Copyright (C) 2012-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -79,10 +79,10 @@ END_EVENT_TABLE()
 FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent,
                                                 FRAME_T aFrameType ) :
         PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
-                        wxDefaultPosition, wxDefaultSize,
-                        aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
-                                : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
-                        FOOTPRINT_WIZARD_FRAME_NAME ),
+                             wxDefaultPosition, wxDefaultSize,
+                             aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
+                             : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
+                             FOOTPRINT_WIZARD_FRAME_NAME ),
         m_wizardListShown( false )
 {
     wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
@@ -162,7 +162,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent
     m_parametersPanel = new wxPanel( this, wxID_ANY );
 
     m_pageList = new wxListBox( m_parametersPanel, ID_FOOTPRINT_WIZARD_PAGE_LIST,
-                                wxDefaultPosition, wxDefaultSize, 0, NULL,
+                                wxDefaultPosition, wxDefaultSize, 0, nullptr,
                                 wxLB_HSCROLL | wxNO_BORDER );
 
     auto divider = new wxStaticLine( m_parametersPanel, wxID_ANY,
@@ -254,7 +254,6 @@ void FOOTPRINT_WIZARD_FRAME::doCloseWindow()
         if( !IsDismissed() )
             DismissModal( false );
     }
-    // else do nothing
 }
 
 
@@ -313,7 +312,9 @@ void FOOTPRINT_WIZARD_FRAME::UpdateMsgPanel()
         SetMsgPanel( items );
     }
     else
+    {
         ClearMsgPanel();
+    }
 }
 
 
@@ -341,13 +342,13 @@ void  FOOTPRINT_WIZARD_FRAME::initParameterGrid()
 
     m_parameterGrid->Connect( wxEVT_SIZE,
                               wxSizeEventHandler( FOOTPRINT_WIZARD_FRAME::OnGridSize ),
-                              NULL, this );
+                              nullptr, this );
 }
 
 
 void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
 {
-    if( m_pageList == NULL )
+    if( m_pageList == nullptr )
         return;
 
     FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
@@ -358,7 +359,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
     m_pageList->Clear();
     int max_page = footprintWizard->GetNumParameterPages();
 
-    for( int i = 0; i<max_page; i++ )
+    for( int i = 0; i < max_page; i++ )
     {
         wxString name = footprintWizard->GetParameterPageName( i );
         m_pageList->Append( name );
@@ -375,12 +376,12 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
 
 void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
 {
-    if( m_parameterGrid == NULL )
+    if( m_parameterGrid == nullptr )
         return;
 
     FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
 
-    if( footprintWizard == NULL )
+    if( footprintWizard == nullptr )
         return;
 
     m_parameterGrid->Freeze();
@@ -406,7 +407,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
 
     wxString designator, name, value, units, hint;
 
-    for( unsigned int i = 0; i< namesList.size(); i++ )
+    for( unsigned int i = 0; i < namesList.size(); i++ )
     {
         designator  = designatorsList[i];
         name        = namesList[i];
@@ -438,16 +439,15 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
                 options.Add( tokenizer.GetNextToken() );
             }
 
-            m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellChoiceEditor( options ) );
+            m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE,
+                                            new wxGridCellChoiceEditor( options ) );
 
             units = wxT( "" );
         }
-        // Integer parameters
-        else if( units == WIZARD_PARAM_UNITS_INTEGER )
+        else if( units == WIZARD_PARAM_UNITS_INTEGER )    // Integer parameters
         {
             m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellNumberEditor );
         }
-        // Non-integer numerical parameters
         else if( ( units == WIZARD_PARAM_UNITS_MM )      ||
                  ( units == WIZARD_PARAM_UNITS_MILS )    ||
                  ( units == WIZARD_PARAM_UNITS_FLOAT )   ||
@@ -455,6 +455,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
                  ( units == WIZARD_PARAM_UNITS_DEGREES ) ||
                  ( units == WIZARD_PARAM_UNITS_PERCENT ) )
         {
+            // Non-integer numerical parameters
             m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellFloatEditor );
 
             // Convert separators to the locale-specific character
@@ -478,7 +479,7 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
 void FOOTPRINT_WIZARD_FRAME::ResizeParamColumns()
 {
     // Parameter grid is not yet configured
-    if( ( m_parameterGrid == NULL ) || ( m_parameterGrid->GetNumberCols() == 0 ) )
+    if( ( m_parameterGrid == nullptr ) || ( m_parameterGrid->GetNumberCols() == 0 ) )
         return;
 
     // first auto-size the columns to ensure enough space around text
diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp
index 8d641aaeb0..d22d02f20f 100644
--- a/pcbnew/footprint_wizard_frame_functions.cpp
+++ b/pcbnew/footprint_wizard_frame_functions.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,6 +41,7 @@
 
 #include <tool/tool_manager.h>
 
+
 void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
 {
     wxString    msg;
@@ -70,8 +71,8 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
 
     default:
         wxFAIL_MSG( wxString::Format(
-                            "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d",
-                            event.GetId() ) );
+                "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d",
+                event.GetId() ) );
         break;
     }
 }
@@ -134,14 +135,14 @@ void FOOTPRINT_WIZARD_FRAME::DisplayBuildMessage( wxString& aMessage )
 FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
 {
     if( m_wizardName.Length() == 0 )
-        return NULL;
+        return nullptr;
 
     FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
 
     if( !footprintWizard )
     {
         wxMessageBox( _( "Couldn't reload footprint wizard" ) );
-        return NULL;
+        return nullptr;
     }
 
     return footprintWizard;
@@ -161,7 +162,7 @@ FOOTPRINT* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
         return footprint;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -205,7 +206,7 @@ void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
 {
     FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
 
-    if ( footprintWizard == NULL )
+    if ( footprintWizard == nullptr )
         return;
 
     footprintWizard->ResetParameters();
@@ -216,10 +217,12 @@ void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
     DisplayWizardInfos();
 }
 
+
 // This is a flag to avoid reentering of ParametersUpdated
 // that can happen in some cases
 static bool lock_update_prms = false;
 
+
 void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
 {
     FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
diff --git a/pcbnew/import_gfx/svg_import_plugin.cpp b/pcbnew/import_gfx/svg_import_plugin.cpp
index e87c3810a6..418ffcaee2 100644
--- a/pcbnew/import_gfx/svg_import_plugin.cpp
+++ b/pcbnew/import_gfx/svg_import_plugin.cpp
@@ -2,8 +2,8 @@
  * This program source code file is part of KICAD, a free EDA CAD application.
  *
  * Copyright (C) 2016 CERN
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Janito V. Ferreira Filho
- * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -72,12 +72,13 @@ bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName )
 
 bool SVG_IMPORT_PLUGIN::Import()
 {
-    for( NSVGshape* shape = m_parsedImage->shapes; shape != NULL; shape = shape->next )
+    for( NSVGshape* shape = m_parsedImage->shapes; shape != nullptr; shape = shape->next )
     {
         double lineWidth = shape->strokeWidth;
 
-        for( NSVGpath* path = shape->paths; path != NULL; path = path->next )
-            DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR, lineWidth );
+        for( NSVGpath* path = shape->paths; path != nullptr; path = path->next )
+            DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR,
+                      lineWidth );
     }
 
     return true;
@@ -108,7 +109,8 @@ double SVG_IMPORT_PLUGIN::GetImageWidth() const
 }
 
 
-void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth )
+void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath,
+                                  bool aFilled, double aLineWidth )
 {
     std::vector< VECTOR2D > collectedPathPoints;
 
@@ -123,7 +125,7 @@ void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aCl
 
 
 void SVG_IMPORT_PLUGIN::DrawCubicBezierPath( const float* aPoints, int aNumPoints,
-        std::vector< VECTOR2D >& aGeneratedPoints )
+                                             std::vector< VECTOR2D >& aGeneratedPoints )
 {
     const int pointsPerSegment = 4;
     const int curveSpecificPointsPerSegment = 3;
@@ -141,7 +143,7 @@ void SVG_IMPORT_PLUGIN::DrawCubicBezierPath( const float* aPoints, int aNumPoint
 
 
 void SVG_IMPORT_PLUGIN::DrawCubicBezierCurve( const float* aPoints,
-        std::vector< VECTOR2D >& aGeneratedPoints )
+                                              std::vector< VECTOR2D >& aGeneratedPoints )
 {
     auto start = getBezierPoint( aPoints, 0.0f );
     auto end = getBezierPoint( aPoints, 1.0f );
@@ -195,7 +197,7 @@ static VECTOR2D getBezierPoint( const float* aPoints, float aStep )
 
 
 static VECTOR2D getPointInLine( const VECTOR2D& aLineStart, const VECTOR2D& aLineEnd,
-        float aDistance )
+                                float aDistance )
 {
     return aLineStart + ( aLineEnd - aLineStart ) * aDistance;
 }
@@ -233,8 +235,9 @@ static VECTOR2D calculateBezierBoundingBoxExtremity( const float* aCurvePoints,
 
 
 static void segmentBezierCurve( const VECTOR2D& aStart, const VECTOR2D& aEnd, float aOffset,
-        float aStep, const float* aCurvePoints, float aSegmentationThreshold,
-        std::vector< VECTOR2D >& aGeneratedPoints )
+                                float aStep, const float* aCurvePoints,
+                                float aSegmentationThreshold,
+                                std::vector< VECTOR2D >& aGeneratedPoints )
 {
     VECTOR2D middle = getBezierPoint( aCurvePoints, aOffset + aStep );
     float distanceToPreviousSegment = distanceFromPointToLine( middle, aStart, aEnd );
@@ -242,30 +245,31 @@ static void segmentBezierCurve( const VECTOR2D& aStart, const VECTOR2D& aEnd, fl
     if( distanceToPreviousSegment > aSegmentationThreshold )
     {
         createNewBezierCurveSegments( aStart, middle, aEnd, aOffset, aStep, aCurvePoints,
-                aSegmentationThreshold, aGeneratedPoints );
+                                      aSegmentationThreshold, aGeneratedPoints );
     }
 }
 
 
 static void createNewBezierCurveSegments( const VECTOR2D& aStart, const VECTOR2D& aMiddle,
-        const VECTOR2D& aEnd, float aOffset, float aStep, const float* aCurvePoints,
-        float aSegmentationThreshold, std::vector< VECTOR2D >& aGeneratedPoints )
+                                          const VECTOR2D& aEnd, float aOffset, float aStep,
+                                          const float* aCurvePoints, float aSegmentationThreshold,
+                                          std::vector< VECTOR2D >& aGeneratedPoints )
 {
     float newStep = aStep / 2.f;
     float offsetAfterMiddle = aOffset + aStep;
 
     segmentBezierCurve( aStart, aMiddle, aOffset, newStep, aCurvePoints, aSegmentationThreshold,
-            aGeneratedPoints );
+                        aGeneratedPoints );
 
     aGeneratedPoints.push_back( aMiddle );
 
     segmentBezierCurve( aMiddle, aEnd, offsetAfterMiddle, newStep, aCurvePoints,
-            aSegmentationThreshold, aGeneratedPoints );
+                        aSegmentationThreshold, aGeneratedPoints );
 }
 
 
 static float distanceFromPointToLine( const VECTOR2D& aPoint, const VECTOR2D& aLineStart,
-        const VECTOR2D& aLineEnd )
+                                      const VECTOR2D& aLineEnd )
 {
     auto lineDirection = aLineEnd - aLineStart;
     auto lineNormal = lineDirection.Perpendicular().Resize( 1.f );
diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp
index e712a148b1..7ffec16b98 100644
--- a/pcbnew/initpcb.cpp
+++ b/pcbnew/initpcb.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -42,7 +42,7 @@
 
 bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery, bool aFinal )
 {
-    if( GetBoard() == NULL )
+    if( GetBoard() == nullptr )
         return false;
 
     if( aQuery && !GetBoard()->IsEmpty() )
@@ -96,7 +96,7 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery, bool aFinal )
 
 bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery )
 {
-    if( GetBoard() == NULL )
+    if( GetBoard() == nullptr )
         return false;
 
     bool is_last_fp_from_brd = IsCurrentFPFromBoard();
diff --git a/pcbnew/io_mgr.cpp b/pcbnew/io_mgr.cpp
index 4519457f8f..c8c5fc7504 100644
--- a/pcbnew/io_mgr.cpp
+++ b/pcbnew/io_mgr.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -111,7 +111,7 @@ const wxString IO_MGR::GetFileExtension( PCB_FILE_T aFileType )
     wxString ext = wxEmptyString;
     PLUGIN* plugin = PluginFind( aFileType );
 
-    if( plugin != NULL )
+    if( plugin != nullptr )
     {
         ext = plugin->GetFileExtension();
         PluginRelease( plugin );
diff --git a/pcbnew/microwave/microwave_footprint.cpp b/pcbnew/microwave/microwave_footprint.cpp
index 87780da7d3..32ac1ec1dd 100644
--- a/pcbnew/microwave/microwave_footprint.cpp
+++ b/pcbnew/microwave/microwave_footprint.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -80,7 +80,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
     WX_TEXT_ENTRY_DIALOG dlg( &editFrame, msg, _( "Create microwave footprint" ), value );
 
     if( dlg.ShowQuasiModal() != wxID_OK )
-        return NULL; // cancelled by user
+        return nullptr; // cancelled by user
 
     value    = dlg.GetValue();
     gap_size = ValueFromString( editFrame.GetUserUnits(), value );
@@ -95,7 +95,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
                                        _( "Create microwave footprint" ), msg );
 
         if( angledlg.ShowQuasiModal() != wxID_OK )
-            return NULL; // cancelled by user
+            return nullptr; // cancelled by user
 
         msg = angledlg.GetValue();
 
@@ -112,7 +112,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
     }
 
     if( abort )
-        return NULL;
+        return nullptr;
 
     footprint = createBaseFootprint( cmp_name, text_size, pad_count );
     auto it = footprint->Pads().begin();
@@ -145,7 +145,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
         pad->SetShape( PAD_SHAPE::CUSTOM );
         pad->SetAnchorPadShape( PAD_SHAPE::RECT );
 
-        int numPoints = (angle / 50) + 3;     // Note: angles are in 0.1 degrees
+        int numPoints = ( angle / 50 ) + 3;       // Note: angles are in 0.1 degrees
         std::vector<wxPoint> polyPoints;
         polyPoints.reserve( numPoints );
 
@@ -169,8 +169,8 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
         polyPoints.push_back( polyPoints[0] );
 
         pad->AddPrimitivePoly( polyPoints, 0, true ); // add a polygonal basic shape
-    }
         break;
+    }
 
     default:
         break;
diff --git a/pcbnew/microwave/microwave_polygon.cpp b/pcbnew/microwave/microwave_polygon.cpp
index c8923d3da4..1b125220bf 100644
--- a/pcbnew/microwave/microwave_polygon.cpp
+++ b/pcbnew/microwave/microwave_polygon.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -57,22 +57,13 @@ static int     PolyShapeType;
 
 
 
-/**************** Polygon Shapes ***********************/
-
 enum id_mw_cmd {
     ID_READ_SHAPE_FILE = 1000
 };
 
 
-/* Setting polynomial form parameters
- */
 class MWAVE_POLYGONAL_SHAPE_DLG : public wxDialog
 {
-private:
-    PCB_EDIT_FRAME*  m_Parent;
-    wxRadioBox*      m_ShapeOptionCtrl;
-    EDA_SIZE_CTRL*   m_SizeCtrl;
-
 public:
     MWAVE_POLYGONAL_SHAPE_DLG( PCB_EDIT_FRAME* parent, const wxPoint& pos );
     ~MWAVE_POLYGONAL_SHAPE_DLG() { };
@@ -82,8 +73,8 @@ private:
     void OnCancelClick( wxCommandEvent& event );
 
     /**
-     * Function ReadDataShapeDescr
-     * read a description shape file
+     * Read a description shape file.
+     *
      *  File format is
      *  Unit=MM
      *  XScale=271.501
@@ -100,6 +91,10 @@ private:
     void ReadDataShapeDescr( wxCommandEvent& event );
 
     DECLARE_EVENT_TABLE()
+
+    PCB_EDIT_FRAME*  m_Parent;
+    wxRadioBox*      m_ShapeOptionCtrl;
+    EDA_SIZE_CTRL*   m_SizeCtrl;
 };
 
 
@@ -172,7 +167,7 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
     wxString fullFileName;
     wxString mask = wxFileSelectorDefaultWildcardStr;
 
-    fullFileName = EDA_FILE_SELECTOR( _( "Read descr shape file" ), lastpath,
+    fullFileName = EDA_FILE_SELECTOR( _( "Read Shape Description File" ), lastpath,
                                       fullFileName, wxEmptyString, mask, this,
                                       wxFD_OPEN, true );
 
@@ -185,7 +180,7 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
 
     FILE* File = wxFopen( fullFileName, wxT( "rt" ) );
 
-    if( File == NULL )
+    if( File == nullptr )
     {
         DisplayError( this, _( "File not found" ) );
         return;
@@ -203,7 +198,7 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
     {
         char* Line = reader.Line();
         char* param1 = strtok( Line, " =\n\r" );
-        char* param2 = strtok( NULL, " \t\n\r" );
+        char* param2 = strtok( nullptr, " \t\n\r" );
 
         if( strncasecmp( param1, "Unit", 4 ) == 0 )
         {
@@ -223,7 +218,7 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
             {
                 Line = reader.Line();
                 param1 = strtok( Line, " \t\n\r" );
-                param2 = strtok( NULL, " \t\n\r" );
+                param2 = strtok( nullptr, " \t\n\r" );
 
                 if( strncasecmp( param1, "$ENDCOORD", 8 ) == 0 )
                     break;
@@ -265,7 +260,7 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape()
     if( ret != wxID_OK )
     {
         PolyEdges.clear();
-        return NULL;
+        return nullptr;
     }
 
     if( PolyShapeType == 2 )  // mirrored
@@ -277,13 +272,13 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape()
     if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
     {
         editFrame.ShowInfoBarError( _( "Shape has a null size." ) );
-        return NULL;
+        return nullptr;
     }
 
     if( PolyEdges.size() == 0 )
     {
         editFrame.ShowInfoBarError( _( "Shape has no points." ) );
-        return NULL;
+        return nullptr;
     }
 
     cmp_name = wxT( "muwave_polygon" );
@@ -351,8 +346,9 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape()
     }
 
     shape->SetPolyPoints( polyPoints );
+
     // Set the polygon outline thickness to 0, only the polygonal shape is filled
-    // without extra thickness
+    // without extra thickness.
     shape->SetWidth( 0 );
     PolyEdges.clear();
 
diff --git a/pcbnew/netinfo.h b/pcbnew/netinfo.h
index ce749df6b4..d5592d99b2 100644
--- a/pcbnew/netinfo.h
+++ b/pcbnew/netinfo.h
@@ -183,7 +183,7 @@ class NETINFO_MAPPING
 public:
     NETINFO_MAPPING()
     {
-        m_board = NULL;
+        m_board = nullptr;
     }
 
 
diff --git a/pcbnew/netinfo_item.cpp b/pcbnew/netinfo_item.cpp
index 7b71b523b8..5716f9902c 100644
--- a/pcbnew/netinfo_item.cpp
+++ b/pcbnew/netinfo_item.cpp
@@ -7,7 +7,7 @@
  *
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -38,10 +38,6 @@
 #include <pad.h>
 
 
-/*********************************************************/
-/* class NETINFO_ITEM: handle data relative to a given net */
-/*********************************************************/
-
 NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
         BOARD_ITEM( aParent, PCB_NETINFO_T ),
         m_netCode( aNetCode ),
@@ -80,7 +76,7 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
     aList.emplace_back( _( "Net Code" ), wxString::Format( "%d", GetNetCode() ) );
 
     // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
-    BOARD * board = m_parent ? m_parent->GetBoard() : NULL;
+    BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
 
     if( board )
     {
diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp
index a7f30ca945..f21be7f69a 100644
--- a/pcbnew/netinfo_list.cpp
+++ b/pcbnew/netinfo_list.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -67,7 +67,7 @@ NETINFO_ITEM* NETINFO_LIST::GetNetItem( int aNetCode ) const
     if( result != m_netCodes.end() )
         return (*result).second;
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -78,7 +78,7 @@ NETINFO_ITEM* NETINFO_LIST::GetNetItem( const wxString& aNetName ) const
     if( result != m_netNames.end() )
         return (*result).second;
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -135,22 +135,22 @@ void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement )
     // if there is a net with such name then just assign the correct number
     NETINFO_ITEM* sameName = GetNetItem( aNewElement->GetNetname() );
 
-    if( sameName != NULL )
+    if( sameName != nullptr )
     {
         aNewElement->m_netCode = sameName->GetNetCode();
 
         return;
     }
-    // be sure that net codes are consecutive
-    // negative net code means that it has to be auto assigned
     else if( aNewElement->m_netCode != (int) m_netCodes.size() || aNewElement->m_netCode < 0 )
     {
+        // be sure that net codes are consecutive
+        // negative net code means that it has to be auto assigned
         aNewElement->m_netCode = getFreeNetCode();
     }
 
     // net names & codes are supposed to be unique
-    assert( GetNetItem( aNewElement->GetNetname() ) == NULL );
-    assert( GetNetItem( aNewElement->GetNetCode() ) == NULL );
+    assert( GetNetItem( aNewElement->GetNetname() ) == nullptr );
+    assert( GetNetItem( aNewElement->GetNetCode() ) == nullptr );
 
     // add an entry for fast look up by a net name using a map
     m_netNames.insert( std::make_pair( aNewElement->GetNetname(), aNewElement ) );
diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp
index 9de050eb3d..3e62b871ef 100644
--- a/pcbnew/netlist_reader/board_netlist_updater.cpp
+++ b/pcbnew/netlist_reader/board_netlist_updater.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2015 CERN
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
+ * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  *
  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
@@ -438,7 +438,9 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( FOOTPRINT* aFootprint
             }
         }
         else
+        {
             cachePinFunction( pad, pinFunction );
+        }
 
         // Test if new footprint pad has no net (pads not on copper layers have no net).
         if( !net.IsValid() || !pad->IsOnCopperLayer() )
@@ -481,7 +483,9 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( FOOTPRINT* aFootprint
 
             }
             else
+            {
                 cacheNetname( pad, wxEmptyString );
+            }
         }
         else                                 // New footprint pad has a net.
         {
@@ -601,6 +605,7 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist )
     for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
     {
         const COMPONENT* component = aNetlist.GetComponent( ii );
+
         for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
         {
             const COMPONENT_NET& net = component->GetNet( jj );
@@ -776,7 +781,7 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
     int       count = 0;
     wxString  netname;
     wxString  msg;
-    PAD*      previouspad = NULL;
+    PAD*      previouspad = nullptr;
 
     // We need the pad list for next tests.
 
diff --git a/pcbnew/netlist_reader/legacy_netlist_reader.cpp b/pcbnew/netlist_reader/legacy_netlist_reader.cpp
index 918273c7a3..4d07d0ebe4 100644
--- a/pcbnew/netlist_reader/legacy_netlist_reader.cpp
+++ b/pcbnew/netlist_reader/legacy_netlist_reader.cpp
@@ -6,8 +6,8 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 1992-2011 Jean-Pierre Charras.
- * Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>.
- * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -37,7 +37,7 @@ void LEGACY_NETLIST_READER::LoadNetlist()
 {
     int state            = 0;
     bool is_comment      = false;
-    COMPONENT* component = NULL;
+    COMPONENT* component = nullptr;
 
     while( m_lineReader->ReadLine() )
     {
@@ -46,7 +46,7 @@ void LEGACY_NETLIST_READER::LoadNetlist()
         if( is_comment ) // Comments in progress
         {
             // Test for end of the current comment
-            if( ( line = strchr( line, '}' ) ) == NULL )
+            if( ( line = strchr( line, '}' ) ) == nullptr )
                 continue;
 
             is_comment = false;
@@ -63,7 +63,7 @@ void LEGACY_NETLIST_READER::LoadNetlist()
                 continue;
             }
 
-            if( ( line = strchr( line, '}' ) ) == NULL )
+            if( ( line = strchr( line, '}' ) ) == nullptr )
                 continue;
         }
 
@@ -81,7 +81,7 @@ void LEGACY_NETLIST_READER::LoadNetlist()
 
         if( state >= 3 ) // Pad descriptions are read here.
         {
-            wxASSERT( component != NULL );
+            wxASSERT( component != nullptr );
 
             loadNet( line, component );
             state--;
@@ -113,7 +113,7 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText )
     // Sample component line:   /68183921-93a5-49ac-91b0-49d05a0e1647 $noname R20 4.7K {Lib=R}
 
     // Read time stamp (first word)
-    if( ( text = strtok( line, " ()\t\n" ) ) == NULL )
+    if( ( text = strtok( line, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse time stamp in symbol section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), line, m_lineReader->LineNumber(),
@@ -123,7 +123,7 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText )
     KIID_PATH path( FROM_UTF8( text ) );
 
     // Read footprint name (second word)
-    if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
+    if( ( text = strtok( nullptr, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse footprint name in symbol section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(),
@@ -137,7 +137,7 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText )
         footprintName = wxEmptyString;
 
     // Read schematic reference designator (third word)
-    if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
+    if( ( text = strtok( nullptr, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse reference designator in symbol section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(),
@@ -147,7 +147,7 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText )
     reference = FROM_UTF8( text );
 
     // Read schematic value (forth word)
-    if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
+    if( ( text = strtok( nullptr, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse value in symbol section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(),
@@ -158,7 +158,7 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText )
 
     // Read component name (fifth word) {Lib=C}
     // This is an optional field (a comment), which does not always exists
-    if( ( text = strtok( NULL, " ()\t\n" ) ) != NULL )
+    if( ( text = strtok( nullptr, " ()\t\n" ) ) != nullptr )
     {
         name = FROM_UTF8( text ).AfterFirst( wxChar( '=' ) ).BeforeLast( wxChar( '}' ) );
     }
@@ -184,7 +184,7 @@ void LEGACY_NETLIST_READER::loadNet( char* aText, COMPONENT* aComponent )
     strncpy( line, aText, sizeof( line ) );
     line[ sizeof(line) - 1 ] = '\0';
 
-    if( ( p = strtok( line, " ()\t\n" ) ) == NULL )
+    if( ( p = strtok( line, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse pin name in symbol net section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), line, m_lineReader->LineNumber(),
@@ -193,7 +193,7 @@ void LEGACY_NETLIST_READER::loadNet( char* aText, COMPONENT* aComponent )
 
     wxString pinName = FROM_UTF8( p );
 
-    if( ( p = strtok( NULL, " ()\t\n" ) ) == NULL )
+    if( ( p = strtok( nullptr, " ()\t\n" ) ) == nullptr )
     {
         msg = _( "Cannot parse net name in symbol net section of netlist." );
         THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), line, m_lineReader->LineNumber(),
@@ -214,15 +214,15 @@ void LEGACY_NETLIST_READER::loadFootprintFilters()
     wxArrayString filters;
     wxString      cmpRef;
     char*         line;
-    COMPONENT*    component = NULL;     // Suppress compil warning
+    COMPONENT*    component = nullptr;     // Suppress compile warning
 
-    while( ( line = m_lineReader->ReadLine() ) != NULL )
+    while( ( line = m_lineReader->ReadLine() ) != nullptr )
     {
         if( strncasecmp( line, "$endlist", 8 ) == 0 )   // end of list for the current component
         {
-            wxASSERT( component != NULL );
+            wxASSERT( component != nullptr );
             component->SetFootprintFilters( filters );
-            component = NULL;
+            component = nullptr;
             filters.Clear();
             continue;
         }
@@ -240,7 +240,7 @@ void LEGACY_NETLIST_READER::loadFootprintFilters()
             component = m_netlist->GetComponentByReference( cmpRef );
 
             // Cannot happen if the netlist is valid.
-            if( component == NULL )
+            if( component == nullptr )
             {
                 wxString msg;
                 msg.Printf( _( "Cannot find symbol %s in footprint filter section of netlist." ),
@@ -259,3 +259,6 @@ void LEGACY_NETLIST_READER::loadFootprintFilters()
         }
     }
 }
+
+//  LocalWords:  EDA Charras pcb netlist noname cmp endlist
+//  LocalWords:  endfootprintlist
diff --git a/pcbnew/netlist_reader/netlist_reader.cpp b/pcbnew/netlist_reader/netlist_reader.cpp
index 5083da8f98..f2efa87577 100644
--- a/pcbnew/netlist_reader/netlist_reader.cpp
+++ b/pcbnew/netlist_reader/netlist_reader.cpp
@@ -5,8 +5,8 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 1992-2011 Jean-Pierre Charras.
- * Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>.
- * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@gmail.com>.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -51,9 +51,11 @@ NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER
     // depending on the tool which created the file
     wxRegEx reOrcad( wxT( "(?i)[ ]*\\([ \t]+{+" ), wxRE_ADVANCED );
     wxASSERT( reOrcad.IsValid() );
+
     // Our legacy netlist format starts by "# EESchema Netlist "
     wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED );
     wxASSERT( reLegacy.IsValid() );
+
     // Our new netlist format starts by "(export (version "
     wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED );
     wxASSERT( reKicad.IsValid() );
@@ -80,16 +82,17 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST*        aNetlist,
                                                   const wxString& aNetlistFileName,
                                                   const wxString& aCompFootprintFileName )
 {
-    wxASSERT( aNetlist != NULL );
+    wxASSERT( aNetlist != nullptr );
 
-    std::unique_ptr<FILE_LINE_READER> file_rdr = std::make_unique<FILE_LINE_READER>( aNetlistFileName );
+    std::unique_ptr<FILE_LINE_READER> file_rdr =
+            std::make_unique<FILE_LINE_READER>( aNetlistFileName );
 
     NETLIST_FILE_T type = GuessNetlistFileType( file_rdr.get() );
     file_rdr->Rewind();
 
     // The component footprint link reader is NULL if no file name was specified.
     std::unique_ptr<CMP_READER>  cmp_rdr( aCompFootprintFileName.IsEmpty() ?
-            NULL :
+            nullptr :
             new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) ) );
 
     switch( type )
@@ -105,13 +108,13 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST*        aNetlist,
         break;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
 bool CMP_READER::Load( NETLIST* aNetlist )
 {
-    wxCHECK_MSG( aNetlist != NULL,true, wxT( "No netlist passed to CMP_READER::Load()" ) );
+    wxCHECK_MSG( aNetlist != nullptr, true, wxT( "No netlist passed to CMP_READER::Load()" ) );
 
     wxString reference;    // Stores value read from line like Reference = BUS1;
     wxString timestamp;    // Stores value read from line like TimeStamp = /32307DE2/AA450F67;
diff --git a/pcbnew/netlist_reader/pcb_netlist.cpp b/pcbnew/netlist_reader/pcb_netlist.cpp
index f522a32462..4ac89a39de 100644
--- a/pcbnew/netlist_reader/pcb_netlist.cpp
+++ b/pcbnew/netlist_reader/pcb_netlist.cpp
@@ -45,7 +45,7 @@ void COMPONENT::SetFootprint( FOOTPRINT* aFootprint )
     if( !m_kiids.empty() )
         path.push_back( m_kiids.front() );
 
-    if( aFootprint == NULL )
+    if( aFootprint == nullptr )
         return;
 
     aFootprint->SetReference( m_reference );
@@ -150,7 +150,7 @@ void NETLIST::AddComponent( COMPONENT* aComponent )
 
 COMPONENT* NETLIST::GetComponentByReference( const wxString& aReference )
 {
-    COMPONENT* component = NULL;
+    COMPONENT* component = nullptr;
 
     for( unsigned i = 0;  i < m_components.size();  i++ )
     {
diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp
index 295b53ba1e..b9fa9c74b6 100644
--- a/pcbnew/pad.cpp
+++ b/pcbnew/pad.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
-  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -54,6 +54,7 @@
 using KIGFX::PCB_PAINTER;
 using KIGFX::PCB_RENDER_SETTINGS;
 
+
 PAD::PAD( FOOTPRINT* parent ) :
     BOARD_CONNECTED_ITEM( parent, PCB_PAD_T )
 {
@@ -67,21 +68,23 @@ PAD::PAD( FOOTPRINT* parent ) :
         m_pos = GetParent()->GetPosition();
     }
 
-    SetShape( PAD_SHAPE::CIRCLE );                   // Default pad shape is PAD_CIRCLE.
-    SetAnchorPadShape( PAD_SHAPE::CIRCLE );          // Default shape for custom shaped pads
-                                                    // is PAD_CIRCLE.
-    SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );        // Default pad drill shape is a circle.
-    m_attribute           = PAD_ATTRIB::PTH;         // Default pad type is plated through hole
-    SetProperty( PAD_PROP::NONE );                   // no special fabrication property
+    SetShape( PAD_SHAPE::CIRCLE );               // Default pad shape is PAD_CIRCLE.
+    SetAnchorPadShape( PAD_SHAPE::CIRCLE );      // Default shape for custom shaped pads
+                                                 // is PAD_CIRCLE.
+    SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );     // Default pad drill shape is a circle.
+    m_attribute           = PAD_ATTRIB::PTH;     // Default pad type is plated through hole
+    SetProperty( PAD_PROP::NONE );               // no special fabrication property
     m_localClearance      = 0;
     m_localSolderMaskMargin  = 0;
     m_localSolderPasteMargin = 0;
     m_localSolderPasteMarginRatio = 0.0;
+
     // Parameters for round rect only:
-    m_roundedCornerScale = 0.25;                    // from  IPC-7351C standard
+    m_roundedCornerScale = 0.25;                 // from IPC-7351C standard
+
     // Parameters for chamfered rect only:
-    m_chamferScale = 0.2;                           // Size of chamfer: ratio of smallest of X,Y size
-    m_chamferPositions  = RECT_NO_CHAMFER;          // No chamfered corner
+    m_chamferScale = 0.2;                        // Size of chamfer: ratio of smallest of X,Y size
+    m_chamferPositions  = RECT_NO_CHAMFER;       // No chamfered corner
 
     m_zoneConnection    = ZONE_CONNECTION::INHERITED; // Use parent setting by default
     m_thermalWidth      = 0;                        // Use parent setting by default
@@ -221,15 +224,15 @@ bool PAD::FlashLayer( int aLayer ) const
     if( GetAttribute() != PAD_ATTRIB::PTH )
         return IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
 
-    /// Heatsink pads always get copper
+    /// Heat sink pads always get copper
     if( GetProperty() == PAD_PROP::HEATSINK )
         return IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
 
     if( !m_removeUnconnectedLayer )
         return IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
 
-    /// Plated through hole pads need copper on the top/bottom layers for proper soldering
-    /// Unless the user has removed them in the pad dialog
+    // Plated through hole pads need copper on the top/bottom layers for proper soldering
+    // Unless the user has removed them in the pad dialog
     if( m_keepTopBottomLayer && ( aLayer == F_Cu || aLayer == B_Cu ) )
         return IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
 
@@ -338,7 +341,9 @@ void PAD::BuildEffectiveShapes( PCB_LAYER_ID aLayer ) const
 
     case PAD_SHAPE::OVAL:
         if( m_size.x == m_size.y ) // the oval pad is in fact a circle
+        {
             add( new SHAPE_CIRCLE( shapePos, m_size.x / 2 ) );
+        }
         else
         {
             wxSize  half_size = m_size / 2;
@@ -347,6 +352,7 @@ void PAD::BuildEffectiveShapes( PCB_LAYER_ID aLayer ) const
             RotatePoint( &half_len, m_orient );
             add( new SHAPE_SEGMENT( shapePos - half_len, shapePos + half_len, half_width * 2 ) );
         }
+
         break;
 
     case PAD_SHAPE::RECT:
@@ -460,7 +466,6 @@ void PAD::BuildEffectiveShapes( PCB_LAYER_ID aLayer ) const
                                        wxSize( bbox.GetWidth(), bbox.GetHeight() ) );
 
     // Hole shape
-    //
     wxSize  half_size = m_drill / 2;
     int     half_width = std::min( half_size.x, half_size.y );
     wxPoint half_len( half_size.x - half_width, half_size.y - half_width );
@@ -471,7 +476,6 @@ void PAD::BuildEffectiveShapes( PCB_LAYER_ID aLayer ) const
                                                             half_width * 2 );
 
     // All done
-    //
     m_shapesDirty = false;
 }
 
@@ -489,7 +493,6 @@ void PAD::BuildEffectivePolygon() const
     int    maxError = board ? board->GetDesignSettings().m_MaxError : ARC_HIGH_DEF;
 
     // Polygon
-    //
     m_effectivePolygon = std::make_shared<SHAPE_POLY_SET>();
     TransformShapeWithClearanceToPolygon( *m_effectivePolygon, UNDEFINED_LAYER, 0, maxError,
                                           ERROR_INSIDE );
@@ -498,7 +501,6 @@ void PAD::BuildEffectivePolygon() const
     //
     // PADSTACKS TODO: these will both need to cycle through all layers to get the largest
     // values....
-    //
     m_effectiveBoundingRadius = 0;
 
     for( int cnt = 0; cnt < m_effectivePolygon->OutlineCount(); ++cnt )
@@ -513,7 +515,6 @@ void PAD::BuildEffectivePolygon() const
     }
 
     // All done
-    //
     m_polyDirty = false;
 }
 
@@ -533,7 +534,7 @@ void PAD::SetDrawCoord()
 
     m_pos = m_pos0;
 
-    if( parentFootprint == NULL )
+    if( parentFootprint == nullptr )
         return;
 
     double angle = parentFootprint->GetOrientation();
@@ -549,7 +550,7 @@ void PAD::SetLocalCoord()
 {
     FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );
 
-    if( parentFootprint == NULL )
+    if( parentFootprint == nullptr )
     {
         m_pos0 = m_pos;
         return;
@@ -646,7 +647,6 @@ void PAD::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
 }
 
 
-// Flip (mirror) the basic shapes (primitives), in custom pads
 void PAD::FlipPrimitives( bool aFlipLeftRight )
 {
     for( std::shared_ptr<PCB_SHAPE>& primitive : m_editPrimitives )
@@ -656,7 +656,6 @@ void PAD::FlipPrimitives( bool aFlipLeftRight )
 }
 
 
-// Returns the position of the pad.
 wxPoint PAD::ShapePos() const
 {
     if( m_offset.x == 0 && m_offset.y == 0 )
@@ -695,8 +694,6 @@ int PAD::GetLocalClearance( wxString* aSource ) const
 }
 
 
-// Mask margins handling:
-
 int PAD::GetSolderMaskMargin() const
 {
     // The pad inherits the margin only to calculate a default shape,
@@ -897,7 +894,8 @@ void PAD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>&
 
     aList.emplace_back( ShowPadShape(), props );
 
-    if( ( GetShape() == PAD_SHAPE::CIRCLE || GetShape() == PAD_SHAPE::OVAL ) && m_size.x == m_size.y )
+    if( ( GetShape() == PAD_SHAPE::CIRCLE || GetShape() == PAD_SHAPE::OVAL ) &&
+        m_size.x == m_size.y )
     {
         aList.emplace_back( _( "Diameter" ), MessageTextFromValue( units, m_size.x ) );
     }
@@ -1012,7 +1010,8 @@ int PAD::Compare( const PAD* padref, const PAD* padcmp )
 {
     int diff;
 
-    if( ( diff = static_cast<int>( padref->GetShape() ) - static_cast<int>( padcmp->GetShape() ) ) != 0 )
+    if( ( diff = static_cast<int>( padref->GetShape() ) -
+          static_cast<int>( padcmp->GetShape() ) ) != 0 )
         return diff;
 
     if( ( diff = padref->GetDrillShape() - padcmp->GetDrillShape() ) != 0)
@@ -1042,7 +1041,7 @@ int PAD::Compare( const PAD* padref, const PAD* padcmp )
     if( ( diff = padref->m_deltaSize.y - padcmp->m_deltaSize.y ) != 0 )
         return diff;
 
-// TODO: test custom shapes
+    // TODO: test custom shapes
 
     // Dick: specctra_export needs this
     // Lorenzo: gencad also needs it to implement padstacks!
@@ -1087,7 +1086,7 @@ wxString PAD::ShowPadShape() const
     case PAD_SHAPE::ROUNDRECT:      return _( "Roundrect" );
     case PAD_SHAPE::CHAMFERED_RECT: return _( "Chamferedrect" );
     case PAD_SHAPE::CUSTOM:         return _( "CustomShape" );
-    default:                       return wxT( "???" );
+    default:                        return wxT( "???" );
     }
 }
 
@@ -1100,7 +1099,7 @@ wxString PAD::ShowPadAttr() const
     case PAD_ATTRIB::SMD:    return _( "SMD" );
     case PAD_ATTRIB::CONN:   return _( "Conn" );
     case PAD_ATTRIB::NPTH:   return _( "NPTH" );
-    default:                return wxT( "???" );
+    default:                 return wxT( "???" );
     }
 }
 
@@ -1532,7 +1531,7 @@ static struct PAD_DESC
         propMgr.AddProperty( new PROPERTY<PAD, wxString>( _HKI( "Parent" ),
                     NO_SETTER( PAD, wxString ), &PAD::GetParentAsString ) );
 
-        // TODO delta, dirill shape offset, layerset, zone connection
+        // TODO delta, drill shape offset, layer set, zone connection
     }
 } _PAD_DESC;
 
diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp
index 39cf892efb..f25cb0e24d 100644
--- a/pcbnew/pcb_base_frame.cpp
+++ b/pcbnew/pcb_base_frame.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -153,7 +153,7 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs()
         }
         catch( ... )
         {
-            DisplayErrorMessage( NULL, _( "Error loading project footprint library table." ) );
+            DisplayErrorMessage( nullptr, _( "Error loading project footprint library table." ) );
         }
     }
 
@@ -465,7 +465,6 @@ EDA_3D_VIEWER_FRAME* PCB_BASE_FRAME::CreateAndShow3D_Frame()
 }
 
 
-// Note: virtual, overridden in PCB_EDIT_FRAME;
 void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer )
 {
     PCB_LAYER_ID preslayer = GetActiveLayer();
@@ -533,9 +532,6 @@ GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide()
 }
 
 
-/*
- * Display the grid status.
- */
 void PCB_BASE_FRAME::DisplayGridMsg()
 {
     wxString line;
@@ -548,9 +544,6 @@ void PCB_BASE_FRAME::DisplayGridMsg()
 }
 
 
-/*
- * Update the status bar information.
- */
 void PCB_BASE_FRAME::UpdateStatusBar()
 {
     EDA_DRAW_FRAME::UpdateStatusBar();
@@ -691,6 +684,7 @@ FOOTPRINT_EDITOR_SETTINGS* PCB_BASE_FRAME::GetFootprintEditorSettings() const
     return Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
 }
 
+
 MAGNETIC_SETTINGS* PCB_BASE_FRAME::GetMagneticItemsSettings()
 {
     wxCHECK( m_settings, nullptr );
diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp
index 49389d6024..707e3d6911 100644
--- a/pcbnew/pcb_dimension.cpp
+++ b/pcbnew/pcb_dimension.cpp
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -289,12 +289,13 @@ void PCB_DIMENSION_BASE::Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight
 }
 
 
-void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
+void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
+                                          std::vector<MSG_PANEL_ITEM>& aList )
 {
     // for now, display only the text within the DIMENSION using class PCB_TEXT.
     wxString    msg;
 
-    wxCHECK_RET( m_parent != NULL, wxT( "PCB_TEXT::GetMsgPanelInfo() m_Parent is NULL." ) );
+    wxCHECK_RET( m_parent != nullptr, wxT( "PCB_TEXT::GetMsgPanelInfo() m_Parent is NULL." ) );
 
     aList.emplace_back( _( "Dimension" ), m_text.GetShownText() );
 
@@ -436,9 +437,7 @@ const EDA_RECT PCB_DIMENSION_BASE::GetBoundingBox() const
 
 wxString PCB_DIMENSION_BASE::GetSelectMenuText( EDA_UNITS aUnits ) const
 {
-    return wxString::Format( _( "Dimension '%s' on %s" ),
-                             GetText(),
-                             GetLayerName() );
+    return wxString::Format( _( "Dimension '%s' on %s" ), GetText(), GetLayerName() );
 }
 
 
@@ -471,6 +470,7 @@ OPT_VECTOR2I PCB_DIMENSION_BASE::segPolyIntersection( const SHAPE_POLY_SET& aPol
                 endpoint = *intersection;
         }
     }
+
     if( start == endpoint )
         return NULLOPT;
 
@@ -529,6 +529,7 @@ void PCB_DIM_ALIGNED::SwapData( BOARD_ITEM* aImage )
     Update();
 }
 
+
 BITMAPS PCB_DIM_ALIGNED::GetMenuImage() const
 {
     return BITMAPS::add_aligned_dimension;
@@ -830,6 +831,7 @@ void PCB_DIM_ORTHOGONAL::updateText()
         int textOffsetDistance = m_text.GetEffectiveTextPenWidth() + m_text.GetTextHeight();
 
         VECTOR2I textOffset;
+
         if( m_orientation == DIR::HORIZONTAL )
             textOffset.y = -textOffsetDistance;
         else
@@ -847,6 +849,7 @@ void PCB_DIM_ORTHOGONAL::updateText()
     if( m_keepTextAligned )
     {
         double textAngle;
+
         if( abs( crossbarCenter.x ) > abs( crossbarCenter.y ) )
             textAngle = 0;
         else
diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp
index 912a053138..6990f5ffb9 100644
--- a/pcbnew/pcb_draw_panel_gal.cpp
+++ b/pcbnew/pcb_draw_panel_gal.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2014-2017 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
  * This program is free software; you can redistribute it and/or
@@ -52,6 +53,7 @@
 
 using namespace std::placeholders;
 
+
 const LAYER_NUM GAL_LAYER_ORDER[] =
 {
     LAYER_GP_OVERLAY,
@@ -147,6 +149,7 @@ PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
 
     m_painter = std::make_unique<KIGFX::PCB_PAINTER>( m_gal );
     m_view->SetPainter( m_painter.get() );
+
     // This fixes the zoom in and zoom out limits:
     m_view->SetScaleLimits( ZOOM_MAX_LIMIT_PCBNEW, ZOOM_MIN_LIMIT_PCBNEW );
 
@@ -291,7 +294,8 @@ void PCB_DRAW_PANEL_GAL::SetHighContrastLayer( PCB_LAYER_ID aLayer )
                 LAYER_PAD_FR_NETNAMES, LAYER_PAD_BK_NETNAMES, LAYER_PAD_NETNAMES,
                 ZONE_LAYER_FOR( aLayer ),
                 LAYER_PADS_TH, LAYER_PAD_PLATEDHOLES, LAYER_PAD_HOLEWALLS, LAYER_NON_PLATEDHOLES,
-                LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES, LAYER_VIA_HOLEWALLS,
+                LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES,
+                LAYER_VIA_HOLEWALLS,
                 LAYER_DRC_ERROR, LAYER_DRC_WARNING, LAYER_DRC_EXCLUSION, LAYER_MARKER_SHADOWS,
                 LAYER_SELECT_OVERLAY, LAYER_GP_OVERLAY,
                 LAYER_RATSNEST, LAYER_CURSOR, LAYER_ANCHOR
@@ -325,7 +329,8 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( PCB_LAYER_ID aLayer )
 
     // Layers that should always have on-top attribute enabled
     const std::vector<LAYER_NUM> layers = {
-            LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES, LAYER_VIA_HOLEWALLS,
+            LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_HOLES,
+            LAYER_VIA_HOLEWALLS,
             LAYER_VIA_NETNAMES,
             LAYER_PADS_TH, LAYER_PAD_PLATEDHOLES, LAYER_PAD_HOLEWALLS, LAYER_NON_PLATEDHOLES,
             LAYER_PAD_NETNAMES,
@@ -348,7 +353,7 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( PCB_LAYER_ID aLayer )
         LAYER_PAD_BK_NETNAMES, NETNAMES_LAYER_INDEX( B_Cu )
     };
 
-    const std::vector<LAYER_NUM>* extraLayers = NULL;
+    const std::vector<LAYER_NUM>* extraLayers = nullptr;
 
     // Bring a few more extra layers to the top depending on the selected board side
     if( IsFrontLayer( aLayer ) )
@@ -479,7 +484,7 @@ void PCB_DRAW_PANEL_GAL::OnShow()
 
     try
     {
-        // Check if the current rendering backend can be properly initialized
+        // Check if the current rendering back end can be properly initialized
         m_view->UpdateItems();
     }
     catch( const std::runtime_error& e )
@@ -563,9 +568,13 @@ void PCB_DRAW_PANEL_GAL::setDefaultLayerDeps()
             m_view->SetRequired( GetNetnameLayer( layer ), layer );
         }
         else if( IsNonCopperLayer( layer ) )
+        {
             m_view->SetRequired( ZONE_LAYER_FOR( layer ), layer );
+        }
         else if( IsNetnameLayer( layer ) )
+        {
             m_view->SetLayerDisplayOnly( layer );
+        }
     }
 
     m_view->SetLayerTarget( LAYER_ANCHOR, KIGFX::TARGET_NONCACHED );
diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp
index 6c1c32c62c..9d47481318 100644
--- a/pcbnew/pcb_edit_frame.cpp
+++ b/pcbnew/pcb_edit_frame.cpp
@@ -176,9 +176,9 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
 {
     m_maximizeByDefault = true;
     m_showBorderAndTitleBlock = true;   // true to display sheet references
-    m_SelTrackWidthBox = NULL;
-    m_SelViaSizeBox = NULL;
-    m_SelLayerBox = NULL;
+    m_SelTrackWidthBox = nullptr;
+    m_SelViaSizeBox = nullptr;
+    m_SelLayerBox = nullptr;
     m_show_layer_manager_tools = true;
     m_hasAutoSave = true;
 
@@ -429,7 +429,7 @@ void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
 
     BASE_SCREEN* screen = GetScreen();
 
-    if( screen != NULL )
+    if( screen != nullptr )
     {
         drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
         drawingSheet->SetSheetCount( screen->GetPageCount() );
@@ -553,7 +553,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
 
     if( SCRIPTING::IsWxAvailable() )
         mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) );
-    
+
     auto enableZoneControlConition =
         [this] ( const SELECTION& )
         {
@@ -1279,6 +1279,7 @@ void PCB_EDIT_FRAME::UpdateUserInterface()
     {
         // Canonical name
         layerEnum.Map( *seq, LSET::Name( *seq ) );
+
         // User name
         layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
     }
@@ -1511,7 +1512,7 @@ void PCB_EDIT_FRAME::PythonSyncEnvironmentVariables()
     for( auto& var : vars )
         UpdatePythonEnvVar( var.first, var.second.GetValue() );
 
-    // Because the env vars can de modified by the python scripts (rewritten in UTF8),
+    // Because the env vars can be modified by the python scripts (rewritten in UTF8),
     // regenerate them (in Unicode) for our normal environment
     for( auto& var : vars )
         wxSetEnv( var.first, var.second.GetValue() );
@@ -1532,7 +1533,7 @@ void PCB_EDIT_FRAME::PythonSyncProjectName()
 
 void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( FOOTPRINT* aFootprint )
 {
-    if( aFootprint == NULL )
+    if( aFootprint == nullptr )
         return;
 
     DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h
index 89e3fea57c..04aa66aedf 100644
--- a/pcbnew/pcb_edit_frame.h
+++ b/pcbnew/pcb_edit_frame.h
@@ -412,7 +412,7 @@ public:
      *                 \a aStoreInNewLib as true.
      */
     void ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString,
-                                    wxString* aLibPath = NULL );
+                                    wxString* aLibPath = nullptr );
 
     /**
      * Create a BOM file from the current loaded board.
diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp
index 2bec8e8768..e5977e40bc 100644
--- a/pcbnew/pcb_painter.cpp
+++ b/pcbnew/pcb_painter.cpp
@@ -771,7 +771,7 @@ void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer )
 
         // Default font settings
         m_gal->ResetTextAttributes();
-        m_gal->SetStrokeColor( m_pcbSettings.GetColor( NULL, aLayer ) );
+        m_gal->SetStrokeColor( m_pcbSettings.GetColor( nullptr, aLayer ) );
 
         // Set the text position to the pad shape position (the pad position is not the best place)
         VECTOR2D textpos( 0.0, 0.0 );
@@ -1006,6 +1006,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
 
             m_gal->Restore();
         }
+
         return;
     }
     else if( aLayer == LAYER_PAD_HOLEWALLS )
@@ -1157,8 +1158,9 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
 
                     if( effectiveWidth > 0 )
                         m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B, effectiveWidth );
-                }
+
                     break;
+                }
 
                 case SH_CIRCLE:
                 {
@@ -1167,8 +1169,9 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
 
                     if( effectiveRadius > 0 )
                         m_gal->DrawCircle( circle->GetCenter(), effectiveRadius );
-                }
+
                     break;
+                }
 
                 case SH_RECT:
                 {
@@ -1207,8 +1210,9 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
                     {
                         m_gal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
                     }
-                }
+
                     break;
+                }
 
                 case SH_SIMPLE:
                 {
@@ -1242,8 +1246,9 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
                             m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 );
                         }
                     }
-                }
+
                     break;
+                }
 
                 default:
                     // Better not get here; we already pre-flighted the shapes...
@@ -1360,6 +1365,7 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
 
             m_gal->DrawSegment( start, end, thickness );
         }
+
         break;
 
     case PCB_SHAPE_TYPE::RECT:
@@ -1397,8 +1403,9 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
                 m_gal->DrawPolygon( poly );
             }
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::ARC:
         if( sketch )
@@ -1488,8 +1495,9 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
 
         if( parentFootprint )
             m_gal->Restore();
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::CURVE:
         if( sketch )
@@ -1514,6 +1522,7 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
                               VECTOR2D( aShape->GetBezierC2() ),
                               VECTOR2D( aShape->GetEnd() ), thickness );
         }
+
         break;
 
     case PCB_SHAPE_TYPE::LAST:
diff --git a/pcbnew/pcb_plot_params.cpp b/pcbnew/pcb_plot_params.cpp
index d1a8791f76..d7a08d2b7b 100644
--- a/pcbnew/pcb_plot_params.cpp
+++ b/pcbnew/pcb_plot_params.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -70,7 +70,7 @@ static bool setInt( int* aTarget, int aValue, int aMin, int aMax )
         temp = aMax;
 
     *aTarget = temp;
-    return (temp == aValue);
+    return ( temp == aValue );
 }
 
 
@@ -84,10 +84,9 @@ static bool setDouble( double* aTarget, double aValue, double aMin, double aMax
         temp = aMax;
 
     *aTarget = temp;
-    return (temp == aValue);
+    return ( temp == aValue );
 }
 
-// PCB_PLOT_PARAMS
 
 PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
 {
@@ -97,6 +96,7 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
     m_includeGerberNetlistInfo   = true;
     m_createGerberJobFile        = true;
     m_gerberPrecision            = gbrDefaultPrecision;
+
     // we used 0.1mils for SVG step before, but nm precision is more accurate, so we use nm
     m_svgPrecision               = SVG_PRECISION_DEFAULT;
     m_svgUseInch                 = false;
@@ -131,19 +131,22 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
     m_layerSelection             = LSET( 7, F_SilkS, B_SilkS, F_Mask, B_Mask,
                                          F_Paste, B_Paste, Edge_Cuts )
                                          | LSET::AllCuMask();
+
     // This parameter controls if the NPTH pads will be plotted or not
     // it is a "local" parameter
     m_skipNPTH_Pads              = false;
 
-    m_sketchPadLineWidth         = Millimeter2iu( 0.1 );    // line width to plot items in outline mode
+    // line width to plot items in outline mode.
+    m_sketchPadLineWidth         = Millimeter2iu( 0.1 );
 
     m_default_colors = std::make_shared<COLOR_SETTINGS>();
     m_colors         = m_default_colors.get();
 }
 
+
 void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )
 {
-    // Currently geber files use mm.
+    // Currently Gerber files use mm.
     // accepted precision is only 6 (max value, this is the resolution of Pcbnew)
     // or 5, min value for professional boards, when 6 creates problems
     // to board makers.
@@ -152,13 +155,14 @@ void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )
                                       gbrDefaultPrecision;
 }
 
+
 void PCB_PLOT_PARAMS::SetSvgPrecision( unsigned aPrecision, bool aUseInch )
 {
     m_svgUseInch   = aUseInch;
     m_svgPrecision = Clamp( SVG_PRECISION_MIN, aPrecision, SVG_PRECISION_MAX );
 }
 
-// PLEASE NOTE: only plot dialog options are processed
+
 void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
                               int aNestLevel, int aControl ) const
 {
@@ -185,8 +189,9 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
     aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_creategerberjobfile ),
                        GetCreateGerberJobFile() ? trueStr : falseStr );
 
-    if( m_gerberPrecision != gbrDefaultPrecision ) // save this option only if it is not the default value,
-                                                   // to avoid incompatibility with older Pcbnew version
+    // save this option only if it is not the default value,
+    // to avoid incompatibility with older Pcbnew version
+    if( m_gerberPrecision != gbrDefaultPrecision )
         aFormatter->Print( aNestLevel+1, "(%s %d)\n",
                            getTokenName( T_gerberprecision ), m_gerberPrecision );
 
@@ -262,76 +267,112 @@ bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
 {
     if( m_layerSelection != aPcbPlotParams.m_layerSelection )
         return false;
+
     if( m_useGerberProtelExtensions != aPcbPlotParams.m_useGerberProtelExtensions )
         return false;
+
     if( m_gerberDisableApertMacros != aPcbPlotParams.m_gerberDisableApertMacros )
         return false;
+
     if( m_useGerberX2format != aPcbPlotParams.m_useGerberX2format )
         return false;
+
     if( m_includeGerberNetlistInfo != aPcbPlotParams.m_includeGerberNetlistInfo )
         return false;
+
     if( m_createGerberJobFile != aPcbPlotParams.m_createGerberJobFile )
         return false;
+
     if( m_gerberPrecision != aPcbPlotParams.m_gerberPrecision )
         return false;
+
     if( m_excludeEdgeLayer != aPcbPlotParams.m_excludeEdgeLayer )
         return false;
+
     if( m_plotFrameRef != aPcbPlotParams.m_plotFrameRef )
         return false;
+
     if( m_plotViaOnMaskLayer != aPcbPlotParams.m_plotViaOnMaskLayer )
         return false;
+
     if( m_plotMode != aPcbPlotParams.m_plotMode )
         return false;
+
     if( m_DXFplotPolygonMode != aPcbPlotParams.m_DXFplotPolygonMode )
         return false;
+
     if( m_DXFplotUnits != aPcbPlotParams.m_DXFplotUnits )
         return false;
+
     if( m_svgPrecision != aPcbPlotParams.m_svgPrecision )
         return false;
+
     if( m_svgUseInch != aPcbPlotParams.m_svgUseInch )
         return false;
+
     if( m_useAuxOrigin != aPcbPlotParams.m_useAuxOrigin )
         return false;
+
     if( m_HPGLPenNum != aPcbPlotParams.m_HPGLPenNum )
         return false;
+
     if( m_HPGLPenSpeed != aPcbPlotParams.m_HPGLPenSpeed )
         return false;
+
     if( m_HPGLPenDiam != aPcbPlotParams.m_HPGLPenDiam )
         return false;
+
     if( m_negative != aPcbPlotParams.m_negative )
         return false;
+
     if( m_A4Output != aPcbPlotParams.m_A4Output )
         return false;
+
     if( m_plotReference != aPcbPlotParams.m_plotReference )
         return false;
+
     if( m_plotValue != aPcbPlotParams.m_plotValue )
         return false;
+
     if( m_plotInvisibleText != aPcbPlotParams.m_plotInvisibleText )
         return false;
+
     if( m_sketchPadsOnFabLayers != aPcbPlotParams.m_sketchPadsOnFabLayers )
         return false;
+
     if( m_subtractMaskFromSilk != aPcbPlotParams.m_subtractMaskFromSilk )
         return false;
+
     if( m_format != aPcbPlotParams.m_format )
         return false;
+
     if( m_mirror != aPcbPlotParams.m_mirror )
         return false;
+
     if( m_drillMarks != aPcbPlotParams.m_drillMarks )
         return false;
+
     if( m_scaleSelection != aPcbPlotParams.m_scaleSelection )
         return false;
+
     if( m_autoScale != aPcbPlotParams.m_autoScale )
         return false;
+
     if( m_scale != aPcbPlotParams.m_scale )
         return false;
+
     if( m_fineScaleAdjustX != aPcbPlotParams.m_fineScaleAdjustX )
         return false;
+
     if( m_fineScaleAdjustY != aPcbPlotParams.m_fineScaleAdjustY )
         return false;
+
     if( m_widthAdjust != aPcbPlotParams.m_widthAdjust )
         return false;
+
     if( m_textMode != aPcbPlotParams.m_textMode )
         return false;
+
     if( !m_outputDirectory.IsSameAs( aPcbPlotParams.m_outputDirectory ) )
         return false;
 
@@ -351,8 +392,6 @@ bool PCB_PLOT_PARAMS::SetHPGLPenSpeed( int aValue )
 }
 
 
-// PCB_PLOT_PARAMS_PARSER
-
 PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( LINE_READER* aReader ) :
     PCB_PLOT_PARAMS_LEXER( aReader )
 {
@@ -385,29 +424,31 @@ void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
         switch( token )
         {
         case T_layerselection:
+        {
+            token = NeedSYMBOLorNUMBER();
+
+            const std::string& cur = CurStr();
+
+            if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
             {
-                token = NeedSYMBOLorNUMBER();
-
-                const std::string& cur = CurStr();
-
-                if( token == T_NUMBER ) // pretty 3 format had legacy Cu stack.
-                {
-                    //  It's not possible to convert a legacy Cu layer number to a new Cu layer
-                    //  number without knowing the number or total Cu layers in the legacy board.
-                    //  We do not have that information here, so simply set all layers ON.  User
-                    //  can turn them off in the UI.
-                    aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS)
-                                                        | LSET::AllCuMask();
-                }
-                else if( cur.find_first_of( "0x" ) == 0 )   // pretty ver. 4.
-                {
-                    // skip the leading 2 0x bytes.
-                    aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str()+2, cur.size()-2 );
-                }
-                else
-                    Expecting( "integer or hex layerSelection" );
+                //  It's not possible to convert a legacy Cu layer number to a new Cu layer
+                //  number without knowing the number or total Cu layers in the legacy board.
+                //  We do not have that information here, so simply set all layers ON.  User
+                //  can turn them off in the UI.
+                aPcbPlotParams->m_layerSelection = LSET( 2, F_SilkS, B_SilkS ) | LSET::AllCuMask();
             }
+            else if( cur.find_first_of( "0x" ) == 0 ) // pretty ver. 4.
+            {
+                // skip the leading 2 0x bytes.
+                aPcbPlotParams->m_layerSelection.ParseHex( cur.c_str() + 2, cur.size() - 2 );
+            }
+            else
+            {
+                Expecting( "integer or hex layerSelection" );
+            }
+
             break;
+        }
 
         case T_disableapertmacros:
             aPcbPlotParams->m_gerberDisableApertMacros = parseBool();
@@ -430,7 +471,7 @@ void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
             break;
 
         case T_gerberprecision:
-            aPcbPlotParams->m_gerberPrecision = parseInt( gbrDefaultPrecision-1,
+            aPcbPlotParams->m_gerberPrecision = parseInt( gbrDefaultPrecision - 1,
                                                           gbrDefaultPrecision);
             break;
 
@@ -467,13 +508,11 @@ void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
             break;
 
         case T_hpglpennumber:
-            aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN,
-                                                     HPGL_PEN_NUMBER_MAX );
+            aPcbPlotParams->m_HPGLPenNum = parseInt( HPGL_PEN_NUMBER_MIN, HPGL_PEN_NUMBER_MAX );
             break;
 
         case T_hpglpenspeed:
-            aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN,
-                                                       HPGL_PEN_SPEED_MAX );
+            aPcbPlotParams->m_HPGLPenSpeed = parseInt( HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
             break;
 
         case T_hpglpendiameter:
@@ -481,7 +520,7 @@ void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
             break;
 
         case T_hpglpenoverlay:
-            // No more used. juste here for compatibility with old versions
+            // No more used. just here for compatibility with old versions
             parseInt( 0, HPGL_PEN_DIAMETER_MAX );
             break;
 
@@ -599,7 +638,7 @@ double PCB_PLOT_PARAMS_PARSER::parseDouble()
     if( token != T_NUMBER )
         Expecting( T_NUMBER );
 
-    double val = strtod( CurText(), NULL );
+    double val = strtod( CurText(), nullptr );
 
     return val;
 }
diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp
index 60b9d798ae..9cffc45509 100644
--- a/pcbnew/pcb_shape.cpp
+++ b/pcbnew/pcb_shape.cpp
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -104,7 +104,7 @@ double PCB_SHAPE::GetLength() const
 
     default:
         wxASSERT_MSG( false, "PCB_SHAPE::GetLength not implemented for shape"
-                + ShowShape( GetShape() ) );
+                    + ShowShape( GetShape() ) );
         break;
     }
 
@@ -188,8 +188,8 @@ void PCB_SHAPE::Scale( double aScale )
         }
 
         SetPolyPoints( pts );
-    }
         break;
+    }
 
     default:
         break;
@@ -400,7 +400,7 @@ wxPoint PCB_SHAPE::GetArcMid() const
     case PCB_SHAPE_TYPE::ARC:
         // rotate the starting point of the arc, given by m_End, through half
         // the angle m_Angle to get the middle of the arc.
-        // m_Start is the arc centre
+        // m_Start is the arc center
         endPoint  = m_end;         // m_End = start point of arc
         RotatePoint( &endPoint, m_start, -m_angle / 2.0 );
         break;
@@ -420,13 +420,14 @@ double PCB_SHAPE::GetArcAngleStart() const
                                      GetArcStart().x - GetCenter().x );
 
     // Normalize it to 0 ... 360 deg, to avoid discontinuity for angles near 180 deg
-    // because 180 deg and -180 are very near angles when ampping betewwen -180 ... 180 deg.
+    // because 180 deg and -180 are very near angles when mapping between -180 ... 180 deg.
     // and this is not easy to handle in calculations
     NORMALIZE_ANGLE_POS( angleStart );
 
     return angleStart;
 }
 
+
 double PCB_SHAPE::GetArcAngleEnd() const
 {
     // due to the Y axis orient atan2 needs - y value
@@ -434,7 +435,7 @@ double PCB_SHAPE::GetArcAngleEnd() const
                                      GetArcEnd().x - GetCenter().x );
 
     // Normalize it to 0 ... 360 deg, to avoid discontinuity for angles near 180 deg
-    // because 180 deg and -180 are very near angles when ampping betewwen -180 ... 180 deg.
+    // because 180 deg and -180 are very near angles when mapping between -180 ... 180 deg.
     // and this is not easy to handle in calculations
     NORMALIZE_ANGLE_POS( angleStart );
 
@@ -490,7 +491,7 @@ void PCB_SHAPE::SetAngle( double aAngle, bool aUpdateEnd )
 FOOTPRINT* PCB_SHAPE::GetParentFootprint() const
 {
     if( !m_parent || m_parent->Type() != PCB_FOOTPRINT_T )
-        return NULL;
+        return nullptr;
 
     return (FOOTPRINT*) m_parent;
 }
@@ -593,8 +594,9 @@ const EDA_RECT PCB_SHAPE::GetBoundingBox() const
 
         for( wxPoint& pt : pts )
             bbox.Merge( pt );
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::SEGMENT:
         bbox.SetEnd( m_end );
@@ -628,8 +630,9 @@ const EDA_RECT PCB_SHAPE::GetBoundingBox() const
 
             bbox.Merge( pt );
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::CURVE:
         bbox.Merge( m_bezierC1 );
@@ -671,8 +674,9 @@ bool PCB_SHAPE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
             if( abs( radius - dist ) <= maxdist )
                 return true;
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::ARC:
     {
@@ -685,7 +689,7 @@ bool PCB_SHAPE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
             // For arcs, the test point angle must be >= arc angle start
             // and <= arc angle end
             // However angle values > 360 deg are not easy to handle
-            // so we calculate the relative angle between arc start point and teast point
+            // so we calculate the relative angle between arc start point and test point
             // this relative arc should be < arc angle if arc angle > 0 (CW arc)
             // and > arc angle if arc angle < 0 (CCW arc)
             double arc_angle_start = GetArcAngleStart();    // Always 0.0 ... 360 deg, in 0.1 deg
@@ -695,7 +699,7 @@ bool PCB_SHAPE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
             // Calculate relative angle between the starting point of the arc, and the test point
             arc_hittest -= arc_angle_start;
 
-            // Normalise arc_hittest between 0 ... 360 deg
+            // Normalize arc_hittest between 0 ... 360 deg
             NORMALIZE_ANGLE_POS( arc_hittest );
 
             // Check angle: inside the arc angle when it is > 0
@@ -711,8 +715,9 @@ bool PCB_SHAPE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
                     return true;
             }
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::CURVE:
         const_cast<PCB_SHAPE*>( this )->RebuildBezierToSegmentsPointsList( m_width );
@@ -756,8 +761,9 @@ bool PCB_SHAPE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
                 return true;
             }
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::POLYGON:
         if( IsFilled() )
@@ -796,7 +802,9 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
     case PCB_SHAPE_TYPE::CIRCLE:
         // Test if area intersects or contains the circle:
         if( aContained )
+        {
             return arect.Contains( bb );
+        }
         else
         {
             // If the rectangle does not intersect the bounding box, this is a much quicker test
@@ -809,6 +817,7 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
                 return arect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() );
             }
         }
+
         break;
 
     case PCB_SHAPE_TYPE::ARC:
@@ -817,9 +826,9 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
         {
             return arect.Contains( bb );
         }
-        // Test if the rect crosses the arc
         else
         {
+            // Test if the rect crosses the arc
             arcRect = bb.Common( arect );
 
             /* All following tests must pass:
@@ -829,6 +838,7 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
             return arcRect.Intersects( arect ) &&
                    arcRect.IntersectsCircleEdge( GetCenter(), GetRadius(), GetWidth() );
         }
+
         break;
 
     case PCB_SHAPE_TYPE::RECT:
@@ -910,6 +920,7 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
                     return true;
             }
         }
+
         break;
 
     case PCB_SHAPE_TYPE::CURVE:
@@ -942,8 +953,8 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
                     return true;
             }
         }
-        break;
 
+        break;
 
     default:
         wxFAIL_MSG( "PCB_SHAPE::HitTest (rect) not implemented for "
@@ -957,9 +968,7 @@ bool PCB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
 
 wxString PCB_SHAPE::GetSelectMenuText( EDA_UNITS aUnits ) const
 {
-    return wxString::Format( _( "%s on %s" ),
-                             ShowShape( m_shape ),
-                             GetLayerName() );
+    return wxString::Format( _( "%s on %s" ), ShowShape( m_shape ), GetLayerName() );
 }
 
 
@@ -1141,8 +1150,9 @@ std::vector<SHAPE*> PCB_SHAPE::MakeEffectiveShapes() const
             effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[2], pts[3], m_width ) );
             effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[3], pts[0], m_width ) );
         }
-    }
+
         break;
+    }
 
     case PCB_SHAPE_TYPE::CIRCLE:
     {
@@ -1203,8 +1213,9 @@ std::vector<SHAPE*> PCB_SHAPE::MakeEffectiveShapes() const
             for( int i = 0; i < l.SegmentCount(); i++ )
                 effectiveShapes.emplace_back( new SHAPE_SEGMENT( l.Segment( i ), m_width ) );
         }
-    }
+
         break;
+    }
 
     default:
         wxFAIL_MSG( "PCB_SHAPE::MakeEffectiveShapes unsupported PCB_SHAPE shape: "
@@ -1285,7 +1296,8 @@ void PCB_SHAPE::SwapData( BOARD_ITEM* aImage )
 }
 
 
-bool PCB_SHAPE::cmp_drawings::operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const
+bool PCB_SHAPE::cmp_drawings::operator()( const BOARD_ITEM* aFirst,
+                                          const BOARD_ITEM* aSecond ) const
 {
     if( aFirst->Type() != aSecond->Type() )
         return aFirst->Type() < aSecond->Type();
diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h
index 477f71bdb3..9b596b5873 100644
--- a/pcbnew/pcb_shape.h
+++ b/pcbnew/pcb_shape.h
@@ -42,7 +42,7 @@ class MSG_PANEL_ITEM;
 class PCB_SHAPE : public BOARD_ITEM
 {
 public:
-    PCB_SHAPE( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_SHAPE_T );
+    PCB_SHAPE( BOARD_ITEM* aParent = nullptr, KICAD_T idtype = PCB_SHAPE_T );
 
     // Do not create a copy constructor & operator=.
     // The ones generated by the compiler are adequate.
@@ -139,8 +139,7 @@ public:
     void SetEndX( int x )                   { m_end.x = x; }
 
     /**
-     * Function GetThirdPoint
-     * returns the third point point of the graphic
+     * Return the third point of the graphic.
      */
     const wxPoint& GetThirdPoint() const           { return m_thirdPoint; }
     int GetThirdPointY()                           { return m_thirdPoint.y; }
diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp
index 46ed89f9a7..b6a1cf80f7 100644
--- a/pcbnew/pcbnew.cpp
+++ b/pcbnew/pcbnew.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -74,7 +74,8 @@ static struct IFACE : public KIFACE_I
 
     void OnKifaceEnd() override;
 
-    wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
+    wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
+                            int aCtlBits = 0 ) override
     {
         switch( aClassId )
         {
@@ -136,12 +137,14 @@ static struct IFACE : public KIFACE_I
     }
 
     /**
-     * Function IfaceOrAddress
-     * return a pointer to the requested object.  The safest way to use this is to retrieve
-     * a pointer to a static instance of an interface, similar to how the KIFACE interface
-     * is exported.  But if you know what you are doing use it to retrieve anything you want.
+     * Return a pointer to the requested object.
+     *
+     * The safest way to use this is to retrieve a pointer to a static instance of an interface,
+     * similar to how the KIFACE interface is exported.  But if you know what you are doing use
+     * it to retrieve anything you want.
+     *
      * @param aDataId identifies which object you want the address of.
-     * @return void* - and must be cast into the know type.
+     * @return the object which must be cast into the know type.
      */
     void* IfaceOrAddress( int aDataId ) override
     {
@@ -168,7 +171,6 @@ static struct IFACE : public KIFACE_I
     }
 
     /**
-     * Function SaveFileAs
      * Saving a file under a different name is delegated to the various KIFACEs because
      * the project doesn't know the internal format of the various files (which may have
      * paths in them that need updating).
@@ -181,6 +183,7 @@ static struct IFACE : public KIFACE_I
 
 } // namespace
 
+
 using namespace PCB;
 
 
@@ -198,6 +201,7 @@ MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BAS
     return &kiface;
 }
 
+
 #if defined( BUILD_KIWAY_DLL )
 PGM_BASE& Pgm()
 {
@@ -205,6 +209,7 @@ PGM_BASE& Pgm()
     return *process;
 }
 
+
 // Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from a python script.
 PGM_BASE* PgmOrNull()
 {
@@ -212,6 +217,7 @@ PGM_BASE* PgmOrNull()
 }
 #endif
 
+
 /// The global footprint library table.  This is not dynamically allocated because
 /// in a multiple project environment we must keep its address constant (since it is
 /// the fallback table for multiple projects).
@@ -223,7 +229,6 @@ FP_LIB_TABLE          GFootprintTable;
 FOOTPRINT_LIST_IMPL   GFootprintList;
 
 
-
 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
 {
     // This is process-level-initialization, not project-level-initialization of the DSO.
@@ -237,7 +242,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
 
     if( !fn.FileExists() )
     {
-        DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( NULL );
+        DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( nullptr );
 
         fpDialog.ShowModal();
     }
@@ -261,7 +266,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
                 "Please edit this global footprint library table in Preferences menu."
                 );
 
-            DisplayErrorMessage( NULL, msg, ioe.What() );
+            DisplayErrorMessage( nullptr, msg, ioe.What() );
         }
     }
 
diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp
index fd5d8b8dea..eee4683cee 100644
--- a/pcbnew/pcbplot.cpp
+++ b/pcbnew/pcbplot.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -260,10 +260,12 @@ static const wxString GetGerberFilePolarityAttribute( LAYER_NUM aLayer )
     return filePolarity;
 }
 
+
 /* Add some X2 attributes to the file header, as defined in the
  * Gerber file format specification J4 and "Revision 2015.06"
  */
 
+
 // A helper function to convert a X2 attribute string to a X1 structured comment:
 static wxString& makeStringCompatX1( wxString& aText, bool aUseX1CompatibilityMode )
 {
@@ -295,9 +297,9 @@ void AddGerberX2Header( PLOTTER* aPlotter, const BOARD* aBoard, bool aUseX1Compa
     // Creates the TF,.ProjectId. Format is (from Gerber file format doc):
     // %TF.ProjectId,<project id>,<project GUID>,<revision id>*%
     // <project id> is the name of the project, restricted to basic ASCII symbols only,
-    // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
-    // and comma not accepted
-    // All illegal chars will be replaced by underscore
+    // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in
+    // gerber files) and comma not accepted.
+    // All illegal chars will be replaced by underscore.
     //
     // <project GUID> is a string which is an unique id of a project.
     // However Kicad does not handle such a project GUID, so it is built from the board name
@@ -348,8 +350,8 @@ void AddGerberX2Header( PLOTTER* aPlotter, const BOARD* aBoard, bool aUseX1Compa
 }
 
 
-void AddGerberX2Attribute( PLOTTER* aPlotter,
-            const BOARD* aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode )
+void AddGerberX2Attribute( PLOTTER* aPlotter, const BOARD* aBoard, LAYER_NUM aLayer,
+                           bool aUseX1CompatibilityMode )
 {
     AddGerberX2Header( aPlotter, aBoard, aUseX1CompatibilityMode );
 
@@ -401,7 +403,7 @@ void BuildPlotFileName( wxFileName* aFilename, const wxString& aOutputDir,
 
 PLOT_CONTROLLER::PLOT_CONTROLLER( BOARD* aBoard )
 {
-    m_plotter = NULL;
+    m_plotter = nullptr;
     m_board = aBoard;
     m_plotLayer = UNDEFINED_LAYER;
 }
@@ -416,7 +418,6 @@ PLOT_CONTROLLER::~PLOT_CONTROLLER()
 /* IMPORTANT THING TO KNOW: the locale during plots *MUST* be kept as
  * C/POSIX using a LOCALE_IO object on the stack. This even when
  * opening/closing the plotfile, since some drivers do I/O even then */
-
 void PLOT_CONTROLLER::ClosePlot()
 {
     LOCALE_IO toggle;
@@ -428,13 +429,13 @@ void PLOT_CONTROLLER::ClosePlot()
         delete m_plotter->RenderSettings();
         delete m_plotter;
 
-        m_plotter = NULL;
+        m_plotter = nullptr;
     }
 }
 
 
-bool PLOT_CONTROLLER::OpenPlotfile(
-        const wxString& aSuffix, PLOT_FORMAT aFormat, const wxString& aSheetDesc )
+bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat,
+                                    const wxString& aSheetDesc )
 {
     LOCALE_IO toggle;
 
@@ -472,7 +473,7 @@ bool PLOT_CONTROLLER::OpenPlotfile(
                                     m_plotFile.GetFullPath(), aSheetDesc );
     }
 
-    return( m_plotter != NULL );
+    return ( m_plotter != nullptr );
 }
 
 
diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index d1c612fc3a..4b342f1b16 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -8,7 +8,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -207,11 +207,12 @@ void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
 }
 
 
-/*
+/**
  * Plot a copper layer or mask.
+ *
  * Silk screen layers are not plotted here.
  */
-void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
+void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                         const PCB_PLOT_PARAMS& aPlotOpt )
 {
     BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
@@ -240,7 +241,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
     // Plot footprint pads
     for( FOOTPRINT* footprint : aBoard->Footprints() )
     {
-        aPlotter->StartBlock( NULL );
+        aPlotter->StartBlock( nullptr );
 
         for( PAD* pad : footprint->Pads() )
         {
@@ -368,7 +369,8 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                     // which can create bad shapes if margin.x is < 0
                     int maxError = aBoard->GetDesignSettings().m_MaxError;
                     int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
-                    outline.InflateWithLinkedHoles( mask_clearance, numSegs, SHAPE_POLY_SET::PM_FAST );
+                    outline.InflateWithLinkedHoles( mask_clearance, numSegs,
+                                                    SHAPE_POLY_SET::PM_FAST );
                     dummy.DeletePrimitivesList();
                     dummy.AddPrimitivePoly( outline, 0, true );
 
@@ -391,8 +393,8 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                 pad->SetRoundRectCornerRadius( std::max( initial_radius + mask_clearance, 0 ) );
 
                 itemplotter.PlotPad( pad, color, padPlotMode );
-            }
                 break;
+            }
 
             case PAD_SHAPE::CHAMFERED_RECT:
                 if( mask_clearance == 0 )
@@ -417,7 +419,8 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                     int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
                     dummy.TransformShapeWithClearanceToPolygon( outline, UNDEFINED_LAYER, 0,
                                                                 maxError, ERROR_INSIDE );
-                    outline.InflateWithLinkedHoles( mask_clearance, numSegs, SHAPE_POLY_SET::PM_FAST );
+                    outline.InflateWithLinkedHoles( mask_clearance, numSegs,
+                                                    SHAPE_POLY_SET::PM_FAST );
 
                     // Initialize the dummy pad shape:
                     dummy.SetAnchorPadShape( PAD_SHAPE::CIRCLE );
@@ -434,6 +437,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
 
                     itemplotter.PlotPad( &dummy, color, padPlotMode );
                 }
+
                 break;
 
             case PAD_SHAPE::CUSTOM:
@@ -443,6 +447,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                 PAD dummy( *pad );
                 SHAPE_POLY_SET shape;
                 pad->MergePrimitivesAsPolygon( &shape, UNDEFINED_LAYER );
+
                 // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
                 // which can create bad shapes if margin.x is < 0
                 int maxError = aBoard->GetDesignSettings().m_MaxError;
@@ -458,9 +463,9 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                     dummy.SetSize( padPlotsSize );
 
                 itemplotter.PlotPad( &dummy, color, padPlotMode );
-            }
                 break;
             }
+            }
 
             // Restore the pad parameters modified by the plot code
             pad->SetSize( padSize );
@@ -469,7 +474,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
             pad->SetRoundRectCornerRadius( padCornerRadius );
         }
 
-        aPlotter->EndBlock( NULL );
+        aPlotter->EndBlock( nullptr );
     }
 
     // Plot vias on copper layers, and if aPlotOpt.GetPlotViaOnMaskLayer() is true,
@@ -485,7 +490,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
         gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_NET );
     }
 
-    aPlotter->StartBlock( NULL );
+    aPlotter->StartBlock( nullptr );
 
     for( const PCB_TRACK* track : aBoard->Tracks() )
     {
@@ -539,14 +544,15 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
 
         COLOR4D color = aPlotOpt.ColorSettings()->GetColor(
                 LAYER_VIAS + static_cast<int>( via->GetViaType() ) );
+
         // Set plot color (change WHITE to LIGHTGRAY because the white items are not seen on a
         // white paper or screen
         aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY );
         aPlotter->FlashPadCircle( via->GetStart(), diameter, plotMode, &gbr_metadata );
     }
 
-    aPlotter->EndBlock( NULL );
-    aPlotter->StartBlock( NULL );
+    aPlotter->EndBlock( nullptr );
+    aPlotter->StartBlock( nullptr );
     gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONDUCTOR );
 
     // Plot tracks (not vias) :
@@ -582,13 +588,12 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
             aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode,
                                     &gbr_metadata );
         }
-
     }
 
-    aPlotter->EndBlock( NULL );
+    aPlotter->EndBlock( nullptr );
 
     // Plot filled ares
-    aPlotter->StartBlock( NULL );
+    aPlotter->StartBlock( nullptr );
 
     NETINFO_ITEM nonet( aBoard );
 
@@ -622,7 +627,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
         }
     }
 
-    aPlotter->EndBlock( NULL );
+    aPlotter->EndBlock( nullptr );
 
     // Adding drill marks, if required and if the plotter is able to plot them:
     if( aPlotOpt.GetDrillMarksType() != PCB_PLOT_PARAMS::NO_DRILL_SHAPE )
@@ -689,8 +694,8 @@ static const PCB_LAYER_ID plot_seq[] = {
 };
 
 
-/*
- * Plot outlines of copper, for copper layer
+/**
+ * Plot outlines of copper layer.
  */
 void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                         const PCB_PLOT_PARAMS& aPlotOpt )
@@ -718,7 +723,8 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
             for( int kk = 0; kk <= outlines.HoleCount(ii); kk++ )
             {
                 cornerList.clear();
-                const SHAPE_LINE_CHAIN& path = (kk == 0) ? outlines.COutline( ii ) : outlines.CHole( ii, kk - 1 );
+                const SHAPE_LINE_CHAIN& path =
+                        ( kk == 0 ) ? outlines.COutline( ii ) : outlines.CHole( ii, kk - 1 );
 
                 aPlotter->PlotPoly( path, FILL_TYPE::NO_FILL );
             }
@@ -750,7 +756,7 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
                         const SHAPE_SEGMENT* seg = pad->GetEffectiveHoleShape();
                         aPlotter->ThickSegment( (wxPoint) seg->GetSeg().A,
                                                 (wxPoint) seg->GetSeg().B,
-                                                seg->GetWidth(), SKETCH, NULL );
+                                                seg->GetWidth(), SKETCH, nullptr );
                     }
                 }
             }
@@ -770,7 +776,9 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
 }
 
 
-/* Plot a solder mask layer.
+/**
+ * Plot a solder mask layer.
+ *
  * Solder mask layers have a minimum thickness value and cannot be drawn like standard layers,
  * unless the minimum thickness is 0.
  * Currently the algo is:
@@ -845,6 +853,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
     // inflate value to build final polygons
     // After calculations the remaining polygons are polygons to plot
     SHAPE_POLY_SET areas;
+
     // Will contain exact shapes of all items on solder mask
     SHAPE_POLY_SET initialPolys;
 
@@ -914,6 +923,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
 
             // add shapes inflated by aMinThickness/2 in areas
             zone->TransformSmoothedOutlineToPolygon( areas, inflate + zone_margin, boardOutline );
+
             // add shapes with their exact mask layer size in initialPolys
             zone->TransformSmoothedOutlineToPolygon( initialPolys, zone_margin, boardOutline );
         }
@@ -935,6 +945,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
     ZONE zone( aBoard );
     zone.SetMinThickness( 0 );      // trace polygons only
     zone.SetLayer( layer );
+
     // Combine the current areas to initial areas. This is mandatory because inflate/deflate
     // transform is not perfect, and we want the initial areas perfectly kept
     areas.BooleanAdd( initialPolys, SHAPE_POLY_SET::PM_FAST );
@@ -1059,8 +1070,10 @@ static void initializePlotter( PLOTTER* aPlotter, const BOARD* aBoard,
     aPlotter->SetPageSettings( *sheet_info );
 
     aPlotter->SetViewport( offset, IU_PER_MILS/10, compound_scale, aPlotOpts->GetMirror() );
+
     // Has meaning only for gerber plotter. Must be called only after SetViewport
     aPlotter->SetGerberCoordinatesFormat( aPlotOpts->GetGerberPrecision() );
+
     // Has meaning only for SVG plotter. Must be called only after SetViewport
     aPlotter->SetSvgCoordinatesFormat( aPlotOpts->GetSvgPrecision(), aPlotOpts->GetSvgUseInch() );
 
@@ -1104,13 +1117,14 @@ static void ConfigureHPGLPenSizes( HPGL_PLOTTER *aPlotter, const PCB_PLOT_PARAMS
 /**
  * Open a new plotfile using the options (and especially the format) specified in the options
  * and prepare the page for plotting.
- * Return the plotter object if OK, NULL if the file is not created (or has a problem)
+ *
+ * @return the plotter object if OK, NULL if the file is not created (or has a problem).
  */
 PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer,
                          const wxString& aFullFileName, const wxString& aSheetDesc )
 {
     // Create the plotter driver and set the few plotter specific options
-    PLOTTER*    plotter = NULL;
+    PLOTTER*    plotter = nullptr;
 
     switch( aPlotOpts->GetFormat() )
     {
@@ -1153,7 +1167,7 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL
 
     default:
         wxASSERT( false );
-        return NULL;
+        return nullptr;
     }
 
     KIGFX::PCB_RENDER_SETTINGS* renderSettings = new KIGFX::PCB_RENDER_SETTINGS();
@@ -1216,5 +1230,5 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL
 
     delete plotter->RenderSettings();
     delete plotter;
-    return NULL;
+    return nullptr;
 }
diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp
index d8c93be13a..7906b7fc7f 100644
--- a/pcbnew/plot_brditems_plotter.cpp
+++ b/pcbnew/plot_brditems_plotter.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -69,10 +69,6 @@
 #include <wx/gdicmn.h>
 
 
-/* class BRDITEMS_PLOTTER is a helper class to plot board items
- * and a group of board items
- */
-
 COLOR4D BRDITEMS_PLOTTER::getColor( LAYER_NUM aLayer ) const
 {
     COLOR4D color = ColorSettings()->GetColor( aLayer );
@@ -105,6 +101,7 @@ void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, COLOR4D aColor, OUTLINE_MODE aP
     {
         gbr_metadata.SetNetAttribType( GBR_NETINFO_ALL );
         gbr_metadata.SetCopper( true );
+
         // Gives a default attribute, for instance for pads used as tracks in net ties:
         // Connector pads and SMD pads are on external layers
         // if on internal layers, they are certainly used as net tie
@@ -160,7 +157,7 @@ void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, COLOR4D aColor, OUTLINE_MODE aP
             break;
 
         case PAD_ATTRIB::SMD:        // SMD pads (on external copper layer only)
-                                    // with solder paste and mask
+                                     // with solder paste and mask
             if( plotOnExternalCopperLayer )
                 gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_SMDPAD_CUDEF );
             break;
@@ -336,7 +333,6 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint )
 }
 
 
-// plot items like text and graphics, but not tracks and footprints
 void BRDITEMS_PLOTTER::PlotBoardGraphicItems()
 {
     for( BOARD_ITEM* item : m_board->Drawings() )
@@ -516,7 +512,6 @@ void BRDITEMS_PLOTTER::PlotPcbTarget( const PCB_TARGET* aMire )
 }
 
 
-// Plot footprints graphic items (outlines)
 void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint )
 {
     for( const BOARD_ITEM* item : aFootprint->GraphicalItems() )
@@ -529,7 +524,6 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint )
 }
 
 
-//* Plot a graphic item (outline) relative to a footprint
 void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape )
 {
     if( aShape->Type() != PCB_FP_SHAPE_T )
@@ -676,6 +670,7 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape )
                 }
             }
         }
+
         break;
 
     case PCB_SHAPE_TYPE::CURVE:
@@ -690,7 +685,6 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( const FP_SHAPE* aShape )
 }
 
 
-// Plot a PCB Text, i.e. a text found on a copper or technical layer
 void BRDITEMS_PLOTTER::PlotPcbText( const PCB_TEXT* aText )
 {
     wxString shownText( aText->GetShownText() );
@@ -818,8 +812,8 @@ void BRDITEMS_PLOTTER::PlotFilledAreas( const ZONE* aZone, const SHAPE_POLY_SET&
                     }
                 }
 
-                static_cast<GERBER_PLOTTER*>( m_plotter )->PlotGerberRegion(
-                                                    outline, &gbr_metadata );
+                static_cast<GERBER_PLOTTER*>( m_plotter )->PlotGerberRegion( outline,
+                                                                             &gbr_metadata );
             }
             else
             {
@@ -859,8 +853,6 @@ void BRDITEMS_PLOTTER::PlotFilledAreas( const ZONE* aZone, const SHAPE_POLY_SET&
 }
 
 
-/* Plot items type PCB_SHAPE on layers allowed by aLayerMask
- */
 void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape )
 {
     if( !m_layerMask[aShape->GetLayer()] )
@@ -941,6 +933,7 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape )
             if( !sketch && aShape->IsFilled() )
             {
                 m_plotter->SetCurrentLineWidth( thickness, &gbr_metadata );
+
                 // Draw the polygon: only one polygon is expected
                 // However we provide a multi polygon shape drawing
                 // ( for the future or to show a non expected shape )
@@ -979,8 +972,9 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape )
 
             m_plotter->PlotPoly( poly, FILL_TYPE::FILLED_SHAPE, -1, &gbr_metadata );
         }
-    }
+
         break;
+    }
 
     default:
         wxASSERT_MSG( false, "Unhandled PCB_SHAPE shape" );
@@ -989,9 +983,6 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape )
 }
 
 
-/** Helper function to plot a single drill mark. It compensate and clamp
- *   the drill mark size depending on the current plot options
- */
 void BRDITEMS_PLOTTER::plotOneDrillMark( PAD_DRILL_SHAPE_T aDrillShape, const wxPoint &aDrillPos,
                                          wxSize aDrillSize, const wxSize &aPadSize,
                                          double aOrientation, int aSmallDrill )
@@ -1008,11 +999,11 @@ void BRDITEMS_PLOTTER::plotOneDrillMark( PAD_DRILL_SHAPE_T aDrillShape, const wx
     {
         aDrillSize.y -= getFineWidthAdj();
         aDrillSize.y = Clamp( 1, aDrillSize.y, aPadSize.y - 1 );
-        m_plotter->FlashPadOval( aDrillPos, aDrillSize, aOrientation, GetPlotMode(), NULL );
+        m_plotter->FlashPadOval( aDrillPos, aDrillSize, aOrientation, GetPlotMode(), nullptr );
     }
     else
     {
-        m_plotter->FlashPadCircle( aDrillPos, aDrillSize.x, GetPlotMode(), NULL );
+        m_plotter->FlashPadCircle( aDrillPos, aDrillSize.x, GetPlotMode(), nullptr );
     }
 }
 
diff --git a/pcbnew/plotcontroller.h b/pcbnew/plotcontroller.h
index 13af564317..a90acab6a3 100644
--- a/pcbnew/plotcontroller.h
+++ b/pcbnew/plotcontroller.h
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2012 Lorenzo Marcantonio, <l.marcantonio@logossrl.com>
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -39,8 +39,7 @@ class BOARD;
 
 /**
  * Batch plotter state object. Keeps the plot options and handles multiple
- * plot requests
- * Especially useful in Python scripts
+ * plot requests.  Useful in Python scripts.
  */
 class PLOT_CONTROLLER
 {
@@ -48,7 +47,8 @@ public:
     /** Batch plotter constructor, nothing interesting here */
     PLOT_CONTROLLER( BOARD *aBoard );
 
-    /** Batch plotter destructor, ensures that the last plot is closed
+    /**
+     * Ensure that the last plot is closed.
      */
     ~PLOT_CONTROLLER();
 
@@ -62,24 +62,25 @@ public:
 
 
     /**
-     * @return true if a plotter is initialized and can be used
+     * @return true if a plotter is initialized and can be used.
      */
-    bool IsPlotOpen() const { return m_plotter != NULL; }
+    bool IsPlotOpen() const { return m_plotter != nullptr; }
 
-    /** Close the current plot, nothing happens if it isn't open
+    /**
+     * Close the current plot, nothing happens if it isn't open.
      */
     void ClosePlot();
 
-    /** Open a new plotfile; works as a factory for plotter objects
+    /** Open a new plotfile; works as a factory for plotter objects/
+     *
      * @param aSuffix is a string added to the base filename (derived from
-     * the board filename) to identify the plot file
-     * @param aFormat is the plot file format identifier
-     * @param aSheetDesc
+     *                the board filename) to identify the plot file.
+     * @param aFormat is the plot file format identifier.
      */
     bool OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat, const wxString& aSheetDesc );
 
-    /** Plot a single layer on the current plotfile
-     * m_plotLayer is the layer to plot
+    /**
+     * Plot a single layer on the current plotfile m_plotLayer is the layer to plot.
      */
     bool PlotLayer();
 
@@ -94,15 +95,15 @@ public:
     const wxString GetPlotDirName() { return m_plotFile.GetPathWithSep(); }
 
     /**
-     * Plotters can plot in Black and White mode or Color mode
-     * SetColorMode activate/de-actiavte the Color mode.
-     * @param aColorMode = true to activate the plot color mode
+     * Choose color or bland and white plot mode.
+     *
+     * @param aColorMode set to true to activate the plot color mode or false for black and white.
      */
-    void SetColorMode( bool  );
+    void SetColorMode( bool aColorMode );
 
     /**
-     * @return  true if the current plot color mode is Color,
-     *   false if the current plot color mode is Black and White
+     * @return true if the current plot color mode is color or false if the current plot color
+     *         mode is black and white.
      */
     bool GetColorMode();
 
diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp
index 0e90e7bf9e..4a886ced41 100644
--- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp
+++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
- * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -141,7 +141,7 @@ void CADSTAR_PCB_ARCHIVE_PARSER::LAYERDEFS::Parse( XNODE* aNode, PARSER_CONTEXT*
 {
     wxASSERT( aNode->GetName() == wxT( "LAYERDEFS" ) );
 
-    wxXmlAttribute* xmlAttribute = NULL;
+    wxXmlAttribute* xmlAttribute = nullptr;
 
     XNODE* cNode = aNode->GetChildren();
 
@@ -592,7 +592,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::COPPERCODE::Parse( XNODE* aNode, PARSER_CONTEXT
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::REASSIGN::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::SPACINGCODE::REASSIGN::Parse( XNODE* aNode,
+                                                               PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "SPACEREASSIGN" ) );
 
@@ -976,6 +977,7 @@ void CADSTAR_PCB_ARCHIVE_PARSER::TECHNOLOGY_SECTION::Parse( XNODE* aNode, PARSER
     }
 }
 
+
 CADSTAR_PCB_ARCHIVE_PARSER::PAD_SIDE CADSTAR_PCB_ARCHIVE_PARSER::GetPadSide(
         const wxString& aPadSideString )
 {
@@ -1231,7 +1233,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::ARROW::Parse( XNODE* aNode, PARSER_C
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::TEXTFORMAT::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::TEXTFORMAT::Parse( XNODE* aNode,
+                                                               PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "DIMTEXT" ) );
 
@@ -1256,7 +1259,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::TEXTFORMAT::Parse( XNODE* aNode, PAR
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::EXTENSION_LINE::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::DIMENSION::EXTENSION_LINE::Parse( XNODE* aNode,
+                                                                   PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "EXTLINE" ) );
 
@@ -1931,7 +1935,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::PIN::Parse( XNODE* aNode, PARSER_CONTE
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::JUNCTION_PCB::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::JUNCTION_PCB::Parse( XNODE* aNode,
+                                                               PARSER_CONTEXT* aContext )
 {
     ParseIdentifiers( aNode, aContext );
     XNODE* cNode = aNode->GetChildren();
@@ -1980,7 +1985,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::VIA::Parse( XNODE* aNode, PARSER_CONTE
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::COPPER_TERMINAL::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::COPPER_TERMINAL::Parse( XNODE* aNode,
+                                                                  PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "COPTERM" ) );
 
@@ -1990,7 +1996,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::COPPER_TERMINAL::Parse( XNODE* aNode,
 }
 
 
-XNODE* CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE_VERTEX::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+XNODE* CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE_VERTEX::Parse( XNODE* aNode,
+                                                                 PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "ROUTEWIDTH" ) );
 
@@ -2045,7 +2052,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE::Parse( XNODE* aNode, PARSER_CON
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::CONNECTION_PCB::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::CONNECTION_PCB::Parse( XNODE* aNode,
+                                                                 PARSER_CONTEXT* aContext )
 {
     ParseIdentifiers( aNode, aContext );
 
@@ -2267,7 +2275,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::TEMPLATE::Parse( XNODE* aNode, PARSER_CONTEXT*
 }
 
 
-void CADSTAR_PCB_ARCHIVE_PARSER::COPPER::NETREF::COPPER_TERM::Parse( XNODE* aNode, PARSER_CONTEXT* aContext )
+void CADSTAR_PCB_ARCHIVE_PARSER::COPPER::NETREF::COPPER_TERM::Parse( XNODE* aNode,
+                                                                     PARSER_CONTEXT* aContext )
 {
     wxASSERT( aNode->GetName() == wxT( "TERM" ) );
 
diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp
index 4aa754c925..077690b86b 100644
--- a/pcbnew/plugins/eagle/eagle_plugin.cpp
+++ b/pcbnew/plugins/eagle/eagle_plugin.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -116,6 +116,7 @@ static wxString makeKey( const wxString& aFirst, const wxString& aSecond )
     return key;
 }
 
+
 /// interpret special characters in Eagle text and converts them to KiCAD notation
 static wxString interpret_text( const wxString& aText )
 {
@@ -225,7 +226,6 @@ void ERULES::parse( wxXmlNode* aRules, std::function<void()> aCheckpoint )
                 psElongationLong = wxAtoi( value );
             else if( name == "psElongationOffset" )
                 psElongationOffset = wxAtoi( value );
-
             else if( name == "mvStopFrame" )
                 value.ToCDouble( &mvStopFrame );
             else if( name == "mvCreamFrame" )
@@ -238,28 +238,24 @@ void ERULES::parse( wxXmlNode* aRules, std::function<void()> aCheckpoint )
                 mlMinCreamFrame = parseEagle( value );
             else if( name == "mlMaxCreamFrame" )
                 mlMaxCreamFrame = parseEagle( value );
-
             else if( name == "srRoundness" )
                 value.ToCDouble( &srRoundness );
             else if( name == "srMinRoundness" )
                 srMinRoundness = parseEagle( value );
             else if( name == "srMaxRoundness" )
                 srMaxRoundness = parseEagle( value );
-
             else if( name == "psTop" )
                 psTop = wxAtoi( value );
             else if( name == "psBottom" )
                 psBottom = wxAtoi( value );
             else if( name == "psFirst" )
                 psFirst = wxAtoi( value );
-
             else if( name == "rvPadTop" )
                 value.ToCDouble( &rvPadTop );
             else if( name == "rlMinPadTop" )
                 rlMinPadTop = parseEagle( value );
             else if( name == "rlMaxPadTop" )
                 rlMaxPadTop = parseEagle( value );
-
             else if( name == "rvViaOuter" )
                 value.ToCDouble( &rvViaOuter );
             else if( name == "rlMinViaOuter" )
@@ -286,10 +282,10 @@ EAGLE_PLUGIN::EAGLE_PLUGIN() :
 {
     using namespace std::placeholders;
 
-    init( NULL );
+    init( nullptr );
     clear_cu_map();
-    RegisterLayerMappingCallback( std::bind(
-        &EAGLE_PLUGIN::DefaultLayerMappingCallback, this, _1 ) );
+    RegisterLayerMappingCallback( std::bind( &EAGLE_PLUGIN::DefaultLayerMappingCallback,
+                                             this, _1 ) );
 }
 
 
@@ -322,7 +318,7 @@ void EAGLE_PLUGIN::checkpoint()
         if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
         {
             m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
-                                                            / std::max( 1U, m_totalCount ) );
+                                                    / std::max( 1U, m_totalCount ) );
 
             if( !m_progressReporter->KeepRefreshing() )
                 THROW_IO_ERROR( ( "Open cancelled by user." ) );
@@ -358,7 +354,7 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
         m_board->SetFileName( aFileName );
 
     // delete on exception, if I own m_board, according to aAppendToMe
-    unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
+    unique_ptr<BOARD> deleter( aAppendToMe ? nullptr : m_board );
 
     try
     {
@@ -371,6 +367,7 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
         }
 
         wxFileName fn = aFileName;
+
         // Load the document
         wxFFileInputStream stream( fn.GetFullPath() );
         wxXmlDocument xmlDocument;
@@ -416,7 +413,6 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
         // should be empty, else missing m_xpath->pop()
         wxASSERT( m_xpath->Contents().size() == 0 );
     }
-    // Catch all exceptions thrown from the parser.
     catch( const XML_PARSER_ERROR &exc )
     {
         wxString errmsg = exc.what();
@@ -468,7 +464,7 @@ void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
     m_xpath->clear();
     m_pads_to_nets.clear();
 
-    m_board = NULL;
+    m_board = nullptr;
     m_props = aProperties;
 
 
@@ -642,6 +638,7 @@ void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
                 m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
                 m_board->SetLayerType( layer, LT_SIGNAL );
             }
+
             // could map the colors here
         }
     }
@@ -650,6 +647,7 @@ void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
 
 #define DIMENSION_PRECISION 1 // 0.001 mm
 
+
 void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
 {
     if( !aGraphics )
@@ -749,10 +747,14 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                         pcbtxt->SetTextAngle( sign * 90 * 10 );
                         align = ETEXT::TOP_RIGHT;
                     }
-                    else // Ok so text is not at 90,180 or 270 so do some funny stuff to get placement right
+                    else
                     {
+                        // Ok so text is not at 90,180 or 270 so do some funny stuff to get
+                        // placement right.
                         if( ( degrees > 0 ) &&  ( degrees < 90 ) )
+                        {
                             pcbtxt->SetTextAngle( sign * t.rot->degrees * 10 );
+                        }
                         else if( ( degrees > 90 ) && ( degrees < 180 ) )
                         {
                             pcbtxt->SetTextAngle( sign * ( t.rot->degrees + 180 ) * 10 );
@@ -814,6 +816,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                     break;
                 }
             }
+
             m_xpath->pop();
         }
         else if( grName == "circle" )
@@ -836,6 +839,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                 // approximate circle as polygon with a edge every 10 degree
                 wxPoint center( kicad_x( c.x ), kicad_y( c.y ) );
                 int     outlineRadius = radius + ( width / 2 );
+
                 for( int angle = 0; angle < 360; angle += 10 )
                 {
                     wxPoint rotatedPoint( outlineRadius, 0 );
@@ -847,6 +851,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                 {
                     zone->NewHole();
                     int innerRadius = radius - ( width / 2 );
+
                     for( int angle = 0; angle < 360; angle += 10 )
                     {
                         wxPoint rotatedPoint( innerRadius, 0 );
@@ -875,6 +880,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                     shape->SetWidth( width );
                 }
             }
+
             m_xpath->pop();
         }
         else if( grName == "rectangle" )
@@ -953,7 +959,8 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
                 if( d.dimensionType )
                 {
                     // Eagle dimension graphic arms may have different lengths, but they look
-                    // incorrect in KiCad (the graphic is tilted). Make them even length in such case.
+                    // incorrect in KiCad (the graphic is tilted). Make them even length in
+                    // such case.
                     if( *d.dimensionType == "horizontal" )
                     {
                         int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2;
@@ -970,6 +977,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
 
                 dimension->SetLayer( layer );
                 dimension->SetPrecision( DIMENSION_PRECISION );
+
                 // The origin and end are assumed to always be in this order from eagle
                 dimension->SetStart( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
                 dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
@@ -992,6 +1000,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
         // Get next graphic
         gr = gr->GetNext();
     }
+
     m_xpath->pop();
 }
 
@@ -1162,15 +1171,17 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
         footprint->SetValue( FROM_UTF8( e.value.c_str() ) );
 
         if( !e.smashed )
-        { // Not smashed so show NAME & VALUE
+        {
+            // Not smashed so show NAME & VALUE
             if( valueNamePresetInPackageLayout )
                 footprint->Value().SetVisible( true );  // Only if place holder in package layout
 
             if( refanceNamePresetInPackageLayout )
-                footprint->Reference().SetVisible( true );   // Only if place holder in package layout
+                footprint->Reference().SetVisible( true ); // Only if place holder in package layout
         }
         else if( *e.smashed == true )
-        { // Smashed so set default to no show for NAME and VALUE
+        {
+            // Smashed so set default to no show for NAME and VALUE
             footprint->Value().SetVisible( false );
             footprint->Reference().SetVisible( false );
 
@@ -1212,9 +1223,10 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
                         {
                             wxString reference = e.name;
 
-                            // EAGLE allows references to be single digits.  This breaks KiCad netlisting, which requires
-                            // parts to have non-digit + digit annotation.  If the reference begins with a number,
-                            // we prepend 'UNK' (unknown) for the symbol designator
+                            // EAGLE allows references to be single digits.  This breaks KiCad
+                            // netlisting, which requires parts to have non-digit + digit
+                            // annotation.  If the reference begins with a number, we prepend
+                            // 'UNK' (unknown) for the symbol designator.
                             if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
                                 reference.Prepend( "UNK" );
 
@@ -1226,12 +1238,14 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
 
                             break;
                         }
+
                         case EATTR::NAME :
                             if( refanceNamePresetInPackageLayout )
                             {
                                 footprint->SetReference( "NAME" );
                                 footprint->Reference().SetVisible( true );
                             }
+
                             break;
 
                         case EATTR::BOTH :
@@ -1254,8 +1268,10 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
                         }
                     }
                     else
+                    {
                         // No display, so default is visible, and show value of NAME
                         footprint->Reference().SetVisible( true );
+                    }
                 }
                 else if( a.name == "VALUE" )
                 {
@@ -1339,12 +1355,11 @@ ZONE* EAGLE_PLUGIN::loadPolygon( wxXmlNode* aPolyNode )
                           || p.layer == EAGLE_LAYER::BRESTRICT
                           || p.layer == EAGLE_LAYER::VRESTRICT );
 
-    if( layer == UNDEFINED_LAYER ) {
-        wxLogMessage( wxString::Format(
-            _( "Ignoring a polygon since Eagle layer '%s' (%d) "
-               "was not mapped" ),
-                    eagle_layer_name( p.layer ),
-                    p.layer ) );
+    if( layer == UNDEFINED_LAYER )
+    {
+        wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
+                                           "was not mapped" ),
+                                        eagle_layer_name( p.layer ), p.layer ) );
         return nullptr;
     }
 
@@ -1395,17 +1410,15 @@ ZONE* EAGLE_PLUGIN::loadPolygon( wxXmlNode* aPolyNode )
                                                wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ),
                                                *v1.curve );
             double angle = DEG2RAD( *v1.curve );
-            double end_angle = atan2( kicad_y( v2.y ) - center.y,
-                                      kicad_x( v2.x ) - center.x );
-            double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
-                                + pow( center.y - kicad_y( v1.y ), 2 ) );
+            double  end_angle = atan2( kicad_y( v2.y ) - center.y, kicad_x( v2.x ) - center.x );
+            double  radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
+                                  + pow( center.y - kicad_y( v1.y ), 2 ) );
 
             int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, *v1.curve );
             double delta_angle = angle / segCount;
 
-            for( double a = end_angle + angle;
-                    fabs( a - end_angle ) > fabs( delta_angle );
-                    a -= delta_angle )
+            for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta_angle );
+                 a -= delta_angle )
             {
                 polygon.Append( KiROUND( radius * cos( a ) ) + center.x,
                                 KiROUND( radius * sin( a ) ) + center.y );
@@ -1502,7 +1515,8 @@ void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TE
 {
     // Smashed part ?
     if( aAttr )
-    { // Yes
+    {
+        // Yes
         const EATTR& a = *aAttr;
 
         if( a.value )
@@ -1615,8 +1629,10 @@ void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TE
             ;
         }
     }
-    else    // Part is not smash so use Lib default for NAME/VALUE // the text is per the original package, sans <attribute>
+    else
     {
+        // Part is not smash so use Lib default for NAME/VALUE // the text is per the original
+        // package, sans <attribute>.
         double degrees = ( aFPText->GetTextAngle() + aFootprint->GetOrientation() ) / 10;
 
         // @todo there are a few more cases than these to contend with:
@@ -1648,28 +1664,20 @@ FOOTPRINT* EAGLE_PLUGIN::makeFootprint( wxXmlNode* aPackage, const wxString& aPk
 
         if( itemName == "description" )
             m->SetDescription( FROM_UTF8( packageItem->GetNodeContent().c_str() ) );
-
         else if( itemName == "wire" )
             packageWire( m.get(), packageItem );
-
         else if( itemName == "pad" )
             packagePad( m.get(), packageItem );
-
         else if( itemName == "text" )
             packageText( m.get(), packageItem );
-
         else if( itemName == "rectangle" )
             packageRectangle( m.get(), packageItem );
-
         else if( itemName == "polygon" )
             packagePolygon( m.get(), packageItem );
-
         else if( itemName == "circle" )
             packageCircle( m.get(), packageItem );
-
         else if( itemName == "hole" )
             packageHole( m.get(), packageItem, false );
-
         else if( itemName == "smd" )
             packageSMD( m.get(), packageItem );
 
@@ -1692,8 +1700,7 @@ void EAGLE_PLUGIN::packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
     {
         wxLogMessage( wxString::Format( _( "Ignoring a wire since Eagle layer '%s' (%d) "
                                            "was not mapped" ),
-                                        eagle_layer_name( w.layer ),
-                                        w.layer ) );
+                                        eagle_layer_name( w.layer ), w.layer ) );
         return;
     }
 
@@ -1865,8 +1872,7 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
     {
         wxLogMessage( wxString::Format( _( "Ignoring a text since Eagle layer '%s' (%d) "
                                            "was not mapped" ),
-                                        eagle_layer_name( t.layer ),
-                                        t.layer ) );
+                                        eagle_layer_name( t.layer ), t.layer ) );
         return;
     }
 
@@ -1892,7 +1898,6 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
 
     txt->SetLayer( layer );
 
-
     double ratio = t.ratio ? *t.ratio : 8;  // DTD says 8 is default
     int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
 
@@ -1912,9 +1917,13 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
         double degrees = t.rot->degrees;
 
         if( degrees == 90 || t.rot->spin )
+        {
             txt->SetTextAngle( sign * degrees * 10 );
+        }
         else if( degrees == 180 )
+        {
             align = ETEXT::TOP_RIGHT;
+        }
         else if( degrees == 270 )
         {
             align = ETEXT::TOP_RIGHT;
@@ -2003,8 +2012,7 @@ void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) c
         {
             wxLogMessage( wxString::Format( _( "Ignoring a rectangle since Eagle layer '%s' (%d) "
                                                "was not mapped" ),
-                                            eagle_layer_name( r.layer ),
-                                            r.layer ) );
+                                            eagle_layer_name( r.layer ), r.layer ) );
             return;
         }
 
@@ -2070,14 +2078,13 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con
         if( v1.curve )
         {
             EVERTEX v2 = vertices[i + 1];
-            wxPoint center = ConvertArcCenter(
-                    wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
-                    wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
+            wxPoint center =
+                    ConvertArcCenter( wxPoint( kicad_x( v1.x ), kicad_y( v1.y ) ),
+                                      wxPoint( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
             double angle = DEG2RAD( *v1.curve );
-            double end_angle = atan2( kicad_y( v2.y ) - center.y,
-                                      kicad_x( v2.x ) - center.x );
+            double end_angle = atan2( kicad_y( v2.y ) - center.y, kicad_x( v2.x ) - center.x );
             double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
-                                + pow( center.y - kicad_y( v1.y ), 2 ) );
+                                  + pow( center.y - kicad_y( v1.y ), 2 ) );
 
             // Don't allow a zero-radius curve
             if( KiROUND( radius ) == 0 )
@@ -2118,8 +2125,7 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con
         {
             wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
                                                "was not mapped" ),
-                                            eagle_layer_name( p.layer ),
-                                            p.layer ) );
+                                            eagle_layer_name( p.layer ), p.layer ) );
             return;
         }
 
@@ -2139,6 +2145,7 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con
     }
 }
 
+
 void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
 {
     ECIRCLE e( aTree );
@@ -2158,6 +2165,7 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons
         // approximate circle as polygon with a edge every 10 degree
         wxPoint center( kicad_x( e.x ), kicad_y( e.y ) );
         int     outlineRadius = radius + ( width / 2 );
+
         for( int angle = 0; angle < 360; angle += 10 )
         {
             wxPoint rotatedPoint( outlineRadius, 0 );
@@ -2169,6 +2177,7 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons
         {
             zone->NewHole();
             int innerRadius = radius - ( width / 2 );
+
             for( int angle = 0; angle < 360; angle += 10 )
             {
                 wxPoint rotatedPoint( innerRadius, 0 );
@@ -2188,8 +2197,7 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons
         {
             wxLogMessage( wxString::Format( _( "Ignoring a circle since Eagle layer '%s' (%d) "
                                                "was not mapped" ),
-                                            eagle_layer_name( e.layer ),
-                                            e.layer ) );
+                                            eagle_layer_name( e.layer ), e.layer ) );
             return;
         }
 
@@ -2294,8 +2302,9 @@ void EAGLE_PLUGIN::packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
     int minPadSize = std::min( padSize.x, padSize.y );
 
     // Rounded rectangle pads
-    int roundRadius = eagleClamp( m_rules->srMinRoundness * 2,
-            (int)( minPadSize * m_rules->srRoundness ), m_rules->srMaxRoundness * 2 );
+    int roundRadius =
+            eagleClamp( m_rules->srMinRoundness * 2, (int) ( minPadSize * m_rules->srRoundness ),
+                        m_rules->srMaxRoundness * 2 );
 
     if( e.roundness || roundRadius > 0 )
     {
@@ -2313,8 +2322,8 @@ void EAGLE_PLUGIN::packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
         pad->SetOrientation( e.rot->degrees * 10 );
 
     pad->SetLocalSolderPasteMargin( -eagleClamp( m_rules->mlMinCreamFrame,
-                (int) ( m_rules->mvCreamFrame * minPadSize ),
-                m_rules->mlMaxCreamFrame ) );
+                                                 (int) ( m_rules->mvCreamFrame * minPadSize ),
+                                                 m_rules->mlMaxCreamFrame ) );
 
     // Solder mask
     if( e.stop && *e.stop == false )         // enabled by default
@@ -2348,9 +2357,10 @@ void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const
     // Solder mask
     const wxSize& padSize( aPad->GetSize() );
 
-    aPad->SetLocalSolderMaskMargin( eagleClamp( m_rules->mlMinStopFrame,
-                                                (int)( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
-                                                m_rules->mlMaxStopFrame ) );
+    aPad->SetLocalSolderMaskMargin(
+            eagleClamp( m_rules->mlMinStopFrame,
+                        (int) ( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
+                        m_rules->mlMaxStopFrame ) );
 
     // Solid connection to copper zones
     if( aEaglePad.thermals && !*aEaglePad.thermals )
@@ -2421,15 +2431,15 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
                     wxPoint center;
 
                     int width = w.width.ToPcbUnits();
+
                     if( width < m_min_trace )
                         m_min_trace = width;
 
                     if( w.curve )
                     {
-                        center = ConvertArcCenter(
-                                wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
-                                wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
-                                *w.curve );
+                        center = ConvertArcCenter( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
+                                                   wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
+                                                   *w.curve );
 
                         angle = DEG2RAD( *w.curve );
 
@@ -2439,7 +2449,8 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
                         radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
                                        pow( center.y - kicad_y( w.y1 ), 2 ) );
 
-                        int segs = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, *w.curve );
+                        int segs = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
+                                                         *w.curve );
                         delta_angle = angle / segs;
                     }
 
@@ -2480,7 +2491,6 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
 
                 m_xpath->pop();
             }
-
             else if( itemName == "via" )
             {
                 m_xpath->push( "via" );
@@ -2489,8 +2499,7 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
                 PCB_LAYER_ID  layer_front_most = kicad_layer( v.layer_front_most );
                 PCB_LAYER_ID  layer_back_most  = kicad_layer( v.layer_back_most );
 
-                if( IsCopperLayer( layer_front_most ) &&
-                    IsCopperLayer( layer_back_most ) )
+                if( IsCopperLayer( layer_front_most ) && IsCopperLayer( layer_back_most ) )
                 {
                     int      kidiam;
                     int      drillz = v.drill.ToPcbUnits();
@@ -2519,9 +2528,10 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
 
                     if( !v.diam || via->GetWidth() <= via->GetDrill() )
                     {
-                        double annulus = eagleClamp( m_rules->rlMinViaOuter,
-                                (double)( via->GetWidth() / 2 - via->GetDrill() ),
-                                m_rules->rlMaxViaOuter );
+                        double annulus =
+                                eagleClamp( m_rules->rlMinViaOuter,
+                                            (double) ( via->GetWidth() / 2 - via->GetDrill() ),
+                                            m_rules->rlMaxViaOuter );
                         via->SetWidth( drillz + 2 * annulus );
                     }
 
@@ -2597,7 +2607,9 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
             // therefore omit this signal/net.
         }
         else
+        {
             netCode++;
+        }
 
         // Get next signal
         net = net->GetNext();
@@ -2606,6 +2618,7 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
     m_xpath->pop();     // "signals.signal"
 }
 
+
 std::map<wxString, PCB_LAYER_ID> EAGLE_PLUGIN::DefaultLayerMappingCallback(
             const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
 {
@@ -2620,6 +2633,7 @@ std::map<wxString, PCB_LAYER_ID> EAGLE_PLUGIN::DefaultLayerMappingCallback(
     return layer_map;
 }
 
+
 void EAGLE_PLUGIN::mapEagleLayersToKicad()
 {
     std::vector<INPUT_LAYER_DESC> inputDescs;
@@ -2649,18 +2663,21 @@ void EAGLE_PLUGIN::mapEagleLayersToKicad()
         dynamic_cast<wxWindow*>( m_progressReporter )->Show();
 }
 
+
 PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
 {
     auto result = m_layer_map.find( eagle_layer_name( aEagleLayer ) );
     return result == m_layer_map.end() ? UNDEFINED_LAYER : result->second;
 }
 
+
 std::tuple<PCB_LAYER_ID, LSET, bool> EAGLE_PLUGIN::defaultKicadLayer( int aEagleLayer ) const
 {
     // eagle copper layer:
     if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
     {
         LSET copperLayers;
+
         for( int copperLayer : m_cu_map )
         {
             if( copperLayer >= 0 )
@@ -2893,7 +2910,7 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
 
             m_xpath->push( "eagle.drawing.library" );
             wxXmlNode* library = drawingChildren["library"];
-            loadLibrary( library, NULL );
+            loadLibrary( library, nullptr );
             m_xpath->pop();
 
             m_mod_time = modtime;
@@ -2950,8 +2967,7 @@ void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxS
 
 
 FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
-                                        const wxString& aFootprintName,
-                                        bool  aKeepUUID,
+                                        const wxString& aFootprintName, bool aKeepUUID,
                                         const PROPERTIES* aProperties )
 {
     init( aProperties );
@@ -2959,7 +2975,7 @@ FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
     FOOTPRINT_MAP::const_iterator it = m_templates.find( aFootprintName );
 
     if( it == m_templates.end() )
-        return NULL;
+        return nullptr;
 
     // Return a copy of the template
     FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate();
@@ -2971,47 +2987,4 @@ FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
 void EAGLE_PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
 {
     PLUGIN::FootprintLibOptions( aListToAppendTo );
-
-    /*
-    (*aListToAppendTo)["ignore_duplicates"] = UTF8( _( "Ignore duplicately named footprints within "
-                                                       "the same Eagle library. "
-                                                       "Only the first similarly named footprint "
-                                                       "will be loaded." ) );
-    */
 }
-
-
-/*
-void EAGLE_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
-{
-    // Eagle lovers apply here.
-}
-
-
-void EAGLE_PLUGIN::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
-                                  const PROPERTIES* aProperties )
-{
-}
-
-
-void EAGLE_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName )
-{
-}
-
-
-void EAGLE_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
-{
-}
-
-
-bool EAGLE_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
-{
-}
-
-
-bool EAGLE_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
-{
-    return true;
-}
-
-*/
diff --git a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp
index 03a381ec9d..d6e425acef 100644
--- a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp
+++ b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 BeagleBoard Foundation
- * Copyright (C) 2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2020-2021 KiCad Developers, see CHANGELOG.TXT for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,8 +36,8 @@
 
 FABMASTER_PLUGIN::FABMASTER_PLUGIN()
 {
-    m_board = NULL;
-    m_props = NULL;
+    m_board = nullptr;
+    m_props = nullptr;
 }
 
 
diff --git a/pcbnew/plugins/fabmaster/fabmaster_plugin.h b/pcbnew/plugins/fabmaster/fabmaster_plugin.h
index e5b326ef3a..1334110c50 100644
--- a/pcbnew/plugins/fabmaster/fabmaster_plugin.h
+++ b/pcbnew/plugins/fabmaster/fabmaster_plugin.h
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,16 +36,11 @@
 class FABMASTER_PLUGIN : public PLUGIN
 {
 public:
+    const wxString PluginName() const override;
 
-    // -----<PUBLIC PLUGIN API>--------------------------------------------------
-
-    const wxString  PluginName() const override;
-
-    BOARD*          Load( const wxString&    aFileName,
-                          BOARD*             aAppendToMe,
-                          const PROPERTIES*  aProperties = NULL,
-                          PROJECT*           aProject = nullptr,
-                          PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
+    BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
+                 const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr,
+                 PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
 
     const wxString  GetFileExtension() const override;
 
@@ -55,8 +50,6 @@ public:
         return 0;
     }
 
-    // -----</PUBLIC PLUGIN API>-------------------------------------------------
-
     FABMASTER_PLUGIN();
     ~FABMASTER_PLUGIN();
 
@@ -67,4 +60,4 @@ private:
     FABMASTER           m_fabmaster;
 };
 
-#endif    // PCAD_PLUGIN_H_
+#endif    // FABMASTER_PLUGIN_H_
diff --git a/pcbnew/plugins/geda/gpcb_plugin.cpp b/pcbnew/plugins/geda/gpcb_plugin.cpp
index 7477c3ee22..6a2c6bfb31 100644
--- a/pcbnew/plugins/geda/gpcb_plugin.cpp
+++ b/pcbnew/plugins/geda/gpcb_plugin.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -98,8 +98,7 @@ static inline long parseInt( const wxString& aValue, double aScalar )
 
 
 /**
- * GPCB_FPL_CACHE_ITEM
- * is helper class for creating a footprint library cache.
+ * helper class for creating a footprint library cache.
  *
  * The new footprint library design is a file path of individual footprint files
  * that contain a single footprint per file.  This class is a helper only for the
@@ -108,14 +107,15 @@ static inline long parseInt( const wxString& aValue, double aScalar )
  */
 class GPCB_FPL_CACHE_ITEM
 {
-    WX_FILENAME m_filename; ///< The full file name and path of the footprint to cache.
-    std::unique_ptr<FOOTPRINT> m_footprint;
-
 public:
     GPCB_FPL_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName );
 
     WX_FILENAME  GetFileName() const  { return m_filename; }
     FOOTPRINT*      GetFootprint() const { return m_footprint.get(); }
+
+private:
+    WX_FILENAME m_filename;       ///< The full file name and path of the footprint to cache.
+    std::unique_ptr<FOOTPRINT> m_footprint;
 };
 
 
@@ -131,47 +131,6 @@ typedef boost::ptr_map< std::string, GPCB_FPL_CACHE_ITEM >  FOOTPRINT_MAP;
 
 class GPCB_FPL_CACHE
 {
-    GPCB_PLUGIN*    m_owner;            ///< Plugin object that owns the cache.
-    wxFileName      m_lib_path;         ///< The path of the library.
-    FOOTPRINT_MAP   m_footprints;       ///< Map of footprint file name to FOOTPRINT*.
-
-    bool            m_cache_dirty;      ///< Stored separately because it's expensive to check
-                                        ///< m_cache_timestamp against all the files.
-    long long       m_cache_timestamp;  ///< A hash of the timestamps for all the footprint
-                                        ///< files.
-
-    FOOTPRINT* parseFOOTPRINT( LINE_READER* aLineReader );
-
-    /**
-     * Function testFlags
-     * tests \a aFlag for \a aMask or \a aName.
-     * @param aFlag = List of flags to test against: can be a bit field flag or a list name flag
-     * a bit field flag is an hexadecimal value: Ox00020000
-     * a list name flag is a string list of flags, comma separated like square,option1
-     * @param aMask = flag list to test
-     * @param aName = flag name to find in list
-     * @return true if found
-     */
-    bool testFlags( const wxString& aFlag, long aMask, const wxChar* aName );
-
-    /**
-     * Function parseParameters
-     * extracts parameters and tokens from \a aLineReader and adds them to \a aParameterList.
-     *
-     * Delimiter characters are:
-     * [ ] ( )  Begin and end of parameter list and units indicator
-     * " is a string delimiter
-     * space is the param separator
-     * The first word is the keyword
-     * the second item is one of ( or [
-     * other are parameters (number or delimited string)
-     * last parameter is ) or ]
-     *
-     * @param aParameterList This list of parameters parsed.
-     * @param aLineReader    The line reader object to parse.
-     */
-    void parseParameters( wxArrayString& aParameterList, LINE_READER* aLineReader );
-
 public:
     GPCB_FPL_CACHE( GPCB_PLUGIN* aOwner, const wxString& aLibraryPath );
 
@@ -190,18 +149,58 @@ public:
     void Remove( const wxString& aFootprintName );
 
     /**
-     * Function GetTimestamp
      * Generate a timestamp representing all source files in the cache (including the
      * parent directory).
+     *
      * Timestamps should not be considered ordered.  They either match or they don't.
      */
     static long long GetTimestamp( const wxString& aLibPath );
 
     /**
-     * Function IsModified
      * Return true if the cache is not up-to-date.
      */
     bool IsModified();
+
+private:
+    FOOTPRINT* parseFOOTPRINT( LINE_READER* aLineReader );
+
+    /**
+     * Test \a aFlag for \a aMask or \a aName.
+     *
+     * @param aFlag is a list of flags to test against: can be a bit field flag or a list name flag
+     *              a bit field flag is an hexadecimal value: Ox00020000 a list name flag is a
+     *              string list of flags, comma separated like square,option1.
+     * @param aMask is the flag list to test.
+     * @param aName is the flag name to find in list.
+     * @return true if found.
+     */
+    bool testFlags( const wxString& aFlag, long aMask, const wxChar* aName );
+
+    /**
+     * Extract parameters and tokens from \a aLineReader and adds them to \a aParameterList.
+     *
+     * Delimiter characters are:
+     * [ ] ( )  Begin and end of parameter list and units indicator
+     * " is a string delimiter
+     * space is the param separator
+     * The first word is the keyword
+     * the second item is one of ( or [
+     * other are parameters (number or delimited string)
+     * last parameter is ) or ]
+     *
+     * @param aParameterList This list of parameters parsed.
+     * @param aLineReader The line reader object to parse.
+     */
+    void parseParameters( wxArrayString& aParameterList, LINE_READER* aLineReader );
+
+    GPCB_PLUGIN*    m_owner;            ///< Plugin object that owns the cache.
+    wxFileName      m_lib_path;         ///< The path of the library.
+    FOOTPRINT_MAP   m_footprints;       ///< Map of footprint file name to FOOTPRINT*.
+
+    bool            m_cache_dirty;      ///< Stored separately because it's expensive to check
+                                        ///< m_cache_timestamp against all the files.
+    long long       m_cache_timestamp;  ///< A hash of the timestamps for all the footprint
+                                        ///< files.
 };
 
 
@@ -317,14 +316,15 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader )
     #define NEW_GPCB_UNIT_CONV ( 0.01*IU_PER_MILS )
 
     int                        paramCnt;
-    double                     conv_unit = NEW_GPCB_UNIT_CONV; // GPCB unit = 0.01 mils and Pcbnew 0.1
+
+    // GPCB unit = 0.01 mils and Pcbnew 0.1.
+    double                     conv_unit = NEW_GPCB_UNIT_CONV;
     wxPoint                    textPos;
     wxString                   msg;
     wxArrayString              parameters;
     std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( nullptr );
 
-
-    if( aLineReader->ReadLine() == NULL )
+    if( aLineReader->ReadLine() == nullptr )
     {
         msg = aLineReader->GetSource() + ": empty file";
         THROW_IO_ERROR( msg );
@@ -374,6 +374,7 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader )
     // Read value
     if( paramCnt > 10 )
         footprint->SetValue( parameters[5] );
+
     // With gEDA/pcb, value is meaningful after instantiation, only, so it's
     // often empty in bare footprints.
     if( footprint->Value().GetText().IsEmpty() )
@@ -449,8 +450,8 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader )
                 conv_unit = NEW_GPCB_UNIT_CONV;
         }
 
-        wxLogTrace(
-                traceGedaPcbPlugin, wxT( "%s parameter count = %d." ), parameters[0], paramCnt );
+        wxLogTrace( traceGedaPcbPlugin, wxT( "%s parameter count = %d." ),
+                    parameters[0], paramCnt );
 
         // Parse a line with format: ElementLine [X1 Y1 X2 Y2 Thickness]
         if( parameters[0].CmpNoCase( wxT( "ElementLine" ) ) == 0 )
@@ -590,8 +591,7 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader )
 
             wxPoint padPos( (x1 + x2) / 2, (y1 + y2) / 2 );
 
-            pad->SetSize( wxSize( KiROUND( EuclideanNorm( delta ) ) + width,
-                                  width ) );
+            pad->SetSize( wxSize( KiROUND( EuclideanNorm( delta ) ) + width, width ) );
 
             // Set the relative position before adjusting the absolute position
             pad->SetPos0( padPos );
diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp
index fb44b32599..ec93243c7d 100644
--- a/pcbnew/plugins/kicad/pcb_parser.cpp
+++ b/pcbnew/plugins/kicad/pcb_parser.cpp
@@ -429,16 +429,16 @@ void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
                 switch( token )
                 {
                 case T_size:
-                    {
-                        wxSize sz;
-                        sz.SetHeight( parseBoardUnits( "text height" ) );
-                        sz.SetWidth( parseBoardUnits( "text width" ) );
-                        aText->SetTextSize( sz );
-                        NeedRIGHT();
+                {
+                    wxSize sz;
+                    sz.SetHeight( parseBoardUnits( "text height" ) );
+                    sz.SetWidth( parseBoardUnits( "text width" ) );
+                    aText->SetTextSize( sz );
+                    NeedRIGHT();
 
-                        foundTextSize = true;
-                    }
+                    foundTextSize = true;
                     break;
+                }
 
                 case T_thickness:
                     aText->SetTextThickness( parseBoardUnits( "text thickness" ) );
@@ -492,6 +492,7 @@ void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
                 }
 
             }
+
             break;
 
         case T_hide:
@@ -516,7 +517,7 @@ void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
 
 FP_3DMODEL* PCB_PARSER::parse3DModel()
 {
-    wxCHECK_MSG( CurTok() == T_model, NULL,
+    wxCHECK_MSG( CurTok() == T_model, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as FP_3DMODEL." ) );
 
     T token;
@@ -641,7 +642,7 @@ BOARD_ITEM* PCB_PARSER::Parse()
     switch( NextTok() )
     {
     case T_kicad_pcb:
-        if( m_board == NULL )
+        if( m_board == nullptr )
             m_board = new BOARD();
 
         item = (BOARD_ITEM*) parseBOARD();
@@ -1174,63 +1175,64 @@ void PCB_PARSER::parseTITLE_BLOCK()
             break;
 
         case T_comment:
+        {
+            int commentNumber = parseInt( "comment" );
+
+            switch( commentNumber )
             {
-                int commentNumber = parseInt( "comment" );
+            case 1:
+                NextTok();
+                titleBlock.SetComment( 0, FromUTF8() );
+                break;
 
-                switch( commentNumber )
-                {
-                case 1:
-                    NextTok();
-                    titleBlock.SetComment( 0, FromUTF8() );
-                    break;
+            case 2:
+                NextTok();
+                titleBlock.SetComment( 1, FromUTF8() );
+                break;
 
-                case 2:
-                    NextTok();
-                    titleBlock.SetComment( 1, FromUTF8() );
-                    break;
+            case 3:
+                NextTok();
+                titleBlock.SetComment( 2, FromUTF8() );
+                break;
 
-                case 3:
-                    NextTok();
-                    titleBlock.SetComment( 2, FromUTF8() );
-                    break;
+            case 4:
+                NextTok();
+                titleBlock.SetComment( 3, FromUTF8() );
+                break;
 
-                case 4:
-                    NextTok();
-                    titleBlock.SetComment( 3, FromUTF8() );
-                    break;
+            case 5:
+                NextTok();
+                titleBlock.SetComment( 4, FromUTF8() );
+                break;
 
-                case 5:
-                    NextTok();
-                    titleBlock.SetComment( 4, FromUTF8() );
-                    break;
+            case 6:
+                NextTok();
+                titleBlock.SetComment( 5, FromUTF8() );
+                break;
 
-                case 6:
-                    NextTok();
-                    titleBlock.SetComment( 5, FromUTF8() );
-                    break;
+            case 7:
+                NextTok();
+                titleBlock.SetComment( 6, FromUTF8() );
+                break;
 
-                case 7:
-                    NextTok();
-                    titleBlock.SetComment( 6, FromUTF8() );
-                    break;
+            case 8:
+                NextTok();
+                titleBlock.SetComment( 7, FromUTF8() );
+                break;
 
-                case 8:
-                    NextTok();
-                    titleBlock.SetComment( 7, FromUTF8() );
-                    break;
+            case 9:
+                NextTok();
+                titleBlock.SetComment( 8, FromUTF8() );
+                break;
 
-                case 9:
-                    NextTok();
-                    titleBlock.SetComment( 8, FromUTF8() );
-                    break;
-
-                default:
-                    wxString err;
-                    err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber );
-                    THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
-                }
+            default:
+                wxString err;
+                err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber );
+                THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
             }
+
             break;
+        }
 
         default:
             Expecting( "title, date, rev, company, or comment" );
@@ -1398,7 +1400,9 @@ void PCB_PARSER::parseBoardStackup()
             stackup.Add( item );
         }
         else
+        {
             Expecting( "layer_name" );
+        }
 
         bool has_next_sublayer = true;
         int sublayer_idx = 0;       // the index of dielectric sub layers
@@ -1443,6 +1447,7 @@ void PCB_PARSER::parseBoardStackup()
 
                             NeedRIGHT();
                         }
+
                         break;
 
                     case T_material:
@@ -1498,9 +1503,9 @@ void PCB_PARSER::parseBoardStackup()
 
 void PCB_PARSER::createOldLayerMapping( std::unordered_map< std::string, std::string >& aMap )
 {
-    // N.B. This mapping only includes Italian, Polish and French as they were the only languages that
-    // mapped the layer names as of cc2022b1ac739aa673d2a0b7a2047638aa7a47b3 (kicad-i18n) when the
-    // bug was fixed in KiCad source.
+    // N.B. This mapping only includes Italian, Polish and French as they were the only languages
+    // that mapped the layer names as of cc2022b1ac739aa673d2a0b7a2047638aa7a47b3 (kicad-i18n)
+    // when the bug was fixed in KiCad source.
 
     // Italian
     aMap["Adesivo.Retro"] = "B.Adhes";
@@ -1634,8 +1639,8 @@ void PCB_PARSER::parseLayers()
                 THROW_IO_ERROR( error );
             }
 
-            // If we are here, then we have found a translated layer name.  Put it in the maps so that
-            // items on this layer get the appropriate layer ID number
+            // If we are here, then we have found a translated layer name.  Put it in the maps
+            // so that items on this layer get the appropriate layer ID number.
             m_layerIndices[ UTF8( layer.m_name ) ] = it->second;
             m_layerMasks[   UTF8( layer.m_name ) ] = it->second;
             layer.m_name = it->first;
@@ -1662,8 +1667,7 @@ void PCB_PARSER::parseLayers()
     // We need at least 2 copper layers and there must be an even number of them.
     if( copperLayerCount < 2 || (copperLayerCount % 2) != 0 )
     {
-        wxString err = wxString::Format(
-            _( "%d is not a valid layer count" ), copperLayerCount );
+        wxString err = wxString::Format( _( "%d is not a valid layer count" ), copperLayerCount );
 
         THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
     }
@@ -1849,19 +1853,19 @@ void PCB_PARSER::parseSetup()
             break;
 
         case T_user_via:
-            {
-                int viaSize = parseBoardUnits( "user via size" );
-                int viaDrill = parseBoardUnits( "user via drill" );
+        {
+            int viaSize = parseBoardUnits( "user via size" );
+            int viaDrill = parseBoardUnits( "user via drill" );
 
-                // Make room for the netclass value
-                if( designSettings.m_ViasDimensionsList.empty() )
-                    designSettings.m_ViasDimensionsList.emplace_back( VIA_DIMENSION( 0, 0 ) );
+            // Make room for the netclass value
+            if( designSettings.m_ViasDimensionsList.empty() )
+                designSettings.m_ViasDimensionsList.emplace_back( VIA_DIMENSION( 0, 0 ) );
 
-                designSettings.m_ViasDimensionsList.emplace_back( VIA_DIMENSION( viaSize, viaDrill ) );
-                m_board->m_LegacyDesignSettingsLoaded = true;
-                NeedRIGHT();
-            }
+            designSettings.m_ViasDimensionsList.emplace_back( VIA_DIMENSION( viaSize, viaDrill ) );
+            m_board->m_LegacyDesignSettingsLoaded = true;
+            NeedRIGHT();
             break;
+        }
 
         case T_uvia_size:
             defaultNetClass->SetuViaDiameter( parseBoardUnits( T_uvia_size ) );
@@ -1904,14 +1908,17 @@ void PCB_PARSER::parseSetup()
                 int width = parseBoardUnits( "user diff-pair width" );
                 int gap = parseBoardUnits( "user diff-pair gap" );
                 int viaGap = parseBoardUnits( "user diff-pair via gap" );
-                designSettings.m_DiffPairDimensionsList.emplace_back( DIFF_PAIR_DIMENSION( width, gap, viaGap ) );
+                designSettings.m_DiffPairDimensionsList.emplace_back(
+                        DIFF_PAIR_DIMENSION( width, gap, viaGap ) );
                 m_board->m_LegacyDesignSettingsLoaded = true;
                 NeedRIGHT();
             }
+
             break;
 
         case T_segment_width:   // note: legacy (pre-6.0) token
-            designSettings.m_LineThickness[ LAYER_CLASS_COPPER ] = parseBoardUnits( T_segment_width );
+            designSettings.m_LineThickness[ LAYER_CLASS_COPPER ] =
+                    parseBoardUnits( T_segment_width );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
@@ -1923,33 +1930,39 @@ void PCB_PARSER::parseSetup()
             break;
 
         case T_mod_edge_width:  // note: legacy (pre-6.0) token
-            designSettings.m_LineThickness[ LAYER_CLASS_SILK ] = parseBoardUnits( T_mod_edge_width );
+            designSettings.m_LineThickness[ LAYER_CLASS_SILK ] =
+                    parseBoardUnits( T_mod_edge_width );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
 
         case T_pcb_text_width:  // note: legacy (pre-6.0) token
-            designSettings.m_TextThickness[ LAYER_CLASS_COPPER ] = parseBoardUnits( T_pcb_text_width );
+            designSettings.m_TextThickness[ LAYER_CLASS_COPPER ] =
+                    parseBoardUnits( T_pcb_text_width );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
 
         case T_mod_text_width:  // note: legacy (pre-6.0) token
-            designSettings.m_TextThickness[ LAYER_CLASS_SILK ] = parseBoardUnits( T_mod_text_width );
+            designSettings.m_TextThickness[ LAYER_CLASS_SILK ] =
+                    parseBoardUnits( T_mod_text_width );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
 
         case T_pcb_text_size:   // note: legacy (pre-6.0) token
             designSettings.m_TextSize[ LAYER_CLASS_COPPER ].x = parseBoardUnits( "pcb text width" );
-            designSettings.m_TextSize[ LAYER_CLASS_COPPER ].y = parseBoardUnits( "pcb text height" );
+            designSettings.m_TextSize[ LAYER_CLASS_COPPER ].y =
+                    parseBoardUnits( "pcb text height" );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
 
         case T_mod_text_size:   // note: legacy (pre-6.0) token
-            designSettings.m_TextSize[ LAYER_CLASS_SILK ].x = parseBoardUnits( "footprint text width" );
-            designSettings.m_TextSize[ LAYER_CLASS_SILK ].y = parseBoardUnits( "footprint text height" );
+            designSettings.m_TextSize[ LAYER_CLASS_SILK ].x =
+                    parseBoardUnits( "footprint text width" );
+            designSettings.m_TextSize[ LAYER_CLASS_SILK ].y =
+                    parseBoardUnits( "footprint text height" );
             m_board->m_LegacyDesignSettingsLoaded = true;
             NeedRIGHT();
             break;
@@ -1960,24 +1973,24 @@ void PCB_PARSER::parseSetup()
             break;
 
         case T_pad_size:
-            {
-                wxSize sz;
-                sz.SetWidth( parseBoardUnits( "master pad width" ) );
-                sz.SetHeight( parseBoardUnits( "master pad height" ) );
-                designSettings.m_Pad_Master->SetSize( sz );
-                m_board->m_LegacyDesignSettingsLoaded = true;
-                NeedRIGHT();
-            }
+        {
+            wxSize sz;
+            sz.SetWidth( parseBoardUnits( "master pad width" ) );
+            sz.SetHeight( parseBoardUnits( "master pad height" ) );
+            designSettings.m_Pad_Master->SetSize( sz );
+            m_board->m_LegacyDesignSettingsLoaded = true;
+            NeedRIGHT();
             break;
+        }
 
         case T_pad_drill:
-            {
-                int drillSize = parseBoardUnits( T_pad_drill );
-                designSettings.m_Pad_Master->SetDrillSize( wxSize( drillSize, drillSize ) );
-                m_board->m_LegacyDesignSettingsLoaded = true;
-                NeedRIGHT();
-            }
+        {
+            int drillSize = parseBoardUnits( T_pad_drill );
+            designSettings.m_Pad_Master->SetDrillSize( wxSize( drillSize, drillSize ) );
+            m_board->m_LegacyDesignSettingsLoaded = true;
+            NeedRIGHT();
             break;
+        }
 
         case T_pad_to_mask_clearance:
             designSettings.m_SolderMaskMargin = parseBoardUnits( T_pad_to_mask_clearance );
@@ -2000,41 +2013,42 @@ void PCB_PARSER::parseSetup()
             break;
 
         case T_aux_axis_origin:
-            {
-                int x = parseBoardUnits( "auxiliary origin X" );
-                int y = parseBoardUnits( "auxiliary origin Y" );
-                designSettings.m_AuxOrigin = wxPoint( x, y );
-                // Aux origin still stored in board for the moment
-                //m_board->m_LegacyDesignSettingsLoaded = true;
-                NeedRIGHT();
-            }
+        {
+            int x = parseBoardUnits( "auxiliary origin X" );
+            int y = parseBoardUnits( "auxiliary origin Y" );
+            designSettings.m_AuxOrigin = wxPoint( x, y );
+
+            // Aux origin still stored in board for the moment
+            //m_board->m_LegacyDesignSettingsLoaded = true;
+            NeedRIGHT();
             break;
+        }
 
         case T_grid_origin:
-            {
-                int x = parseBoardUnits( "grid origin X" );
-                int y = parseBoardUnits( "grid origin Y" );
-                designSettings.m_GridOrigin = wxPoint( x, y );
-                // Grid origin still stored in board for the moment
-                //m_board->m_LegacyDesignSettingsLoaded = true;
-                NeedRIGHT();
-            }
+        {
+            int x = parseBoardUnits( "grid origin X" );
+            int y = parseBoardUnits( "grid origin Y" );
+            designSettings.m_GridOrigin = wxPoint( x, y );
+            // Grid origin still stored in board for the moment
+            //m_board->m_LegacyDesignSettingsLoaded = true;
+            NeedRIGHT();
             break;
+        }
 
         // Stored in board prior to 6.0
         case T_visible_elements:
-            {
-                // Make sure to start with DefaultVisible so all new layers are set
-                m_board->m_LegacyVisibleItems = GAL_SET::DefaultVisible();
+        {
+            // Make sure to start with DefaultVisible so all new layers are set
+            m_board->m_LegacyVisibleItems = GAL_SET::DefaultVisible();
 
-                int visible = parseHex() | MIN_VISIBILITY_MASK;
+            int visible = parseHex() | MIN_VISIBILITY_MASK;
 
-                for( size_t i = 0; i < sizeof( int ) * CHAR_BIT; i++ )
-                    m_board->m_LegacyVisibleItems.set( i, visible & ( 1u << i ) );
+            for( size_t i = 0; i < sizeof( int ) * CHAR_BIT; i++ )
+                m_board->m_LegacyVisibleItems.set( i, visible & ( 1u << i ) );
 
-                NeedRIGHT();
-            }
+            NeedRIGHT();
             break;
+        }
 
         case T_max_error:
             designSettings.m_MaxError = parseBoardUnits( T_max_error );
@@ -2049,19 +2063,19 @@ void PCB_PARSER::parseSetup()
             break;
 
         case T_pcbplotparams:
-            {
-                PCB_PLOT_PARAMS plotParams;
-                PCB_PLOT_PARAMS_PARSER parser( reader );
-                // parser must share the same current line as our current PCB parser
-                // synchronize it.
-                parser.SyncLineReaderWith( *this );
+        {
+            PCB_PLOT_PARAMS        plotParams;
+            PCB_PLOT_PARAMS_PARSER parser( reader );
+            // parser must share the same current line as our current PCB parser
+            // synchronize it.
+            parser.SyncLineReaderWith( *this );
 
-                plotParams.Parse( &parser );
-                SyncLineReaderWith( parser );
+            plotParams.Parse( &parser );
+            SyncLineReaderWith( parser );
 
-                m_board->SetPlotOptions( plotParams );
-            }
+            m_board->SetPlotOptions( plotParams );
             break;
+        }
 
         default:
             Unexpected( CurText() );
@@ -2306,9 +2320,7 @@ void PCB_PARSER::parseNETCLASS()
 
         wxString error;
         error.Printf( _( "Duplicate NETCLASS name '%s' in file '%s' at line %d, offset %d." ),
-                      nc->GetName().GetData(),
-                      CurSource().GetData(),
-                      CurLineNumber(),
+                      nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(),
                       CurOffset() );
         THROW_IO_ERROR( error );
     }
@@ -2318,7 +2330,7 @@ void PCB_PARSER::parseNETCLASS()
 PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE()
 {
     wxCHECK_MSG( CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve ||
-                 CurTok() == T_gr_rect || CurTok() == T_gr_line || CurTok() == T_gr_poly, NULL,
+                 CurTok() == T_gr_rect || CurTok() == T_gr_line || CurTok() == T_gr_poly, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_SHAPE." ) );
 
     T token;
@@ -2519,8 +2531,9 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE()
         {
             parseOutlinePoints( outline );
         }
-    }
+
         break;
+    }
 
     default:
         Expecting( "gr_arc, gr_circle, gr_curve, gr_line, gr_poly, or gp_rect" );
@@ -2583,6 +2596,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE()
                     Expecting( "yes, none, solid" );
                 }
             }
+
             break;
 
         // We continue to parse the status field but it is no longer written
@@ -2612,9 +2626,9 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE()
         {
             shape->SetFilled( true );
         }
-        // Polygons on non-Edge_Cuts layers were always filled
         else if( shape->GetShape() == PCB_SHAPE_TYPE::POLYGON && shape->GetLayer() != Edge_Cuts )
         {
+            // Polygons on non-Edge_Cuts layers were always filled.
             shape->SetFilled( true );
         }
     }
@@ -2632,7 +2646,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE()
 
 PCB_TEXT* PCB_PARSER::parsePCB_TEXT()
 {
-    wxCHECK_MSG( CurTok() == T_gr_text, NULL,
+    wxCHECK_MSG( CurTok() == T_gr_text, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TEXT." ) );
 
     T token;
@@ -2701,7 +2715,7 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT()
 
 PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION()
 {
-    wxCHECK_MSG( CurTok() == T_dimension, NULL,
+    wxCHECK_MSG( CurTok() == T_dimension, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) );
 
     T token;
@@ -3129,7 +3143,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT( wxArrayString* aInitialComments )
 
 FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments )
 {
-    wxCHECK_MSG( CurTok() == T_module || CurTok() == T_footprint, NULL,
+    wxCHECK_MSG( CurTok() == T_module || CurTok() == T_footprint, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as FOOTPRINT." ) );
 
     wxString name;
@@ -3155,9 +3169,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
     {
         wxString error;
         error.Printf( _( "Invalid footprint ID in\nfile: '%s'\nline: %d\noffset: %d." ),
-                      CurSource(),
-                      CurLineNumber(),
-                      CurOffset() );
+                      CurSource(), CurLineNumber(), CurOffset() );
         THROW_IO_ERROR( error );
     }
 
@@ -3202,9 +3214,9 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
             // acceptable layer is set for the footprint
             PCB_LAYER_ID layer = parseBoardItemLayer();
             footprint->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
-        }
             NeedRIGHT();
             break;
+        }
 
         case T_tedit:
             footprint->SetLastEditTime( parseHex() );
@@ -3268,7 +3280,8 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
             break;
 
         case T_solder_mask_margin:
-            footprint->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
+            footprint->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin "
+                                                                  "value" ) );
             NeedRIGHT();
             break;
 
@@ -3338,6 +3351,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
                                "or exclude_from_bom" );
                 }
             }
+
             break;
 
         case T_fp_text:
@@ -3366,8 +3380,9 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
             default:
                 footprint->Add( text, ADD_MODE::APPEND );
             }
-        }
+
             break;
+        }
 
         case T_fp_arc:
         {
@@ -3381,9 +3396,12 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
                 footprint->Add( shape, ADD_MODE::APPEND );
             }
             else
+            {
                 delete shape;
-        }
+            }
+
             break;
+        }
 
         case T_fp_circle:
         case T_fp_curve:
@@ -3395,8 +3413,8 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
             shape->SetParent( footprint.get() );
             shape->SetDrawCoord();
             footprint->Add( shape, ADD_MODE::APPEND );
-        }
             break;
+        }
 
         case T_pad:
         {
@@ -3406,23 +3424,23 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
             RotatePoint( &pt, footprint->GetOrientation() );
             pad->SetPosition( pt + footprint->GetPosition() );
             footprint->Add( pad, ADD_MODE::APPEND );
-        }
             break;
+        }
 
         case T_model:
         {
             FP_3DMODEL* model = parse3DModel();
             footprint->Add3DModel( model );
             delete model;
-        }
             break;
+        }
 
         case T_zone:
         {
             ZONE* zone = parseZONE( footprint.get() );
             footprint->Add( zone, ADD_MODE::APPEND );
-        }
             break;
+        }
 
         case T_group:
             parseGROUP( footprint.get() );
@@ -3464,10 +3482,9 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
 
 FP_TEXT* PCB_PARSER::parseFP_TEXT()
 {
-    wxCHECK_MSG( CurTok() == T_fp_text, NULL,
+    wxCHECK_MSG( CurTok() == T_fp_text, nullptr,
                  wxString::Format( wxT( "Cannot parse %s as FP_TEXT at line %d, offset %d." ),
-                                   GetTokenString( CurTok() ),
-                                   CurLineNumber(), CurOffset() ) );
+                                   GetTokenString( CurTok() ), CurLineNumber(), CurOffset() ) );
 
     T token = NextTok();
 
@@ -3566,7 +3583,7 @@ FP_TEXT* PCB_PARSER::parseFP_TEXT()
 FP_SHAPE* PCB_PARSER::parseFP_SHAPE()
 {
     wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve ||
-                 CurTok() == T_fp_rect || CurTok() == T_fp_line || CurTok() == T_fp_poly, NULL,
+                 CurTok() == T_fp_rect || CurTok() == T_fp_line || CurTok() == T_fp_poly, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as FP_SHAPE." ) );
 
     wxPoint pt;
@@ -3775,8 +3792,9 @@ FP_SHAPE* PCB_PARSER::parseFP_SHAPE()
 
         while( (token = NextTok() ) != T_RIGHT )
             parseOutlinePoints( outline );
-    }
+
         break;
+    }
 
     default:
         Expecting( "fp_arc, fp_circle, fp_curve, fp_line, fp_poly, or fp_rect" );
@@ -3884,7 +3902,7 @@ FP_SHAPE* PCB_PARSER::parseFP_SHAPE()
 
 PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
 {
-    wxCHECK_MSG( CurTok() == T_pad, NULL,
+    wxCHECK_MSG( CurTok() == T_pad, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PAD." ) );
 
     wxSize  sz;
@@ -4005,87 +4023,84 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
             break;
 
         case T_rect_delta:
-            {
-                wxSize delta;
-                delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
-                delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
-                pad->SetDelta( delta );
-                NeedRIGHT();
-            }
+        {
+            wxSize delta;
+            delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
+            delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
+            pad->SetDelta( delta );
+            NeedRIGHT();
             break;
+        }
 
         case T_drill:
+        {
+            bool   haveWidth = false;
+            wxSize drillSize = pad->GetDrillSize();
+
+            for( token = NextTok(); token != T_RIGHT; token = NextTok() )
             {
-                bool    haveWidth = false;
-                wxSize  drillSize = pad->GetDrillSize();
+                if( token == T_LEFT )
+                    token = NextTok();
 
-                for( token = NextTok();  token != T_RIGHT;  token = NextTok() )
+                switch( token )
                 {
-                    if( token == T_LEFT )
-                        token = NextTok();
+                case T_oval: pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG ); break;
 
-                    switch( token )
+                case T_NUMBER:
+                {
+                    if( !haveWidth )
                     {
-                    case T_oval:
-                        pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
-                        break;
+                        drillSize.SetWidth( parseBoardUnits() );
 
-                    case T_NUMBER:
-                        {
-                            if( !haveWidth )
-                            {
-                                drillSize.SetWidth( parseBoardUnits() );
-
-                                // If height is not defined the width and height are the same.
-                                drillSize.SetHeight( drillSize.GetWidth() );
-                                haveWidth = true;
-                            }
-                            else
-                            {
-                                drillSize.SetHeight( parseBoardUnits() );
-                            }
-
-                        }
-                        break;
-
-                    case T_offset:
-                        pt.x = parseBoardUnits( "drill offset x" );
-                        pt.y = parseBoardUnits( "drill offset y" );
-                        pad->SetOffset( pt );
-                        NeedRIGHT();
-                        break;
-
-                    default:
-                        Expecting( "oval, size, or offset" );
+                        // If height is not defined the width and height are the same.
+                        drillSize.SetHeight( drillSize.GetWidth() );
+                        haveWidth = true;
+                    }
+                    else
+                    {
+                        drillSize.SetHeight( parseBoardUnits() );
                     }
                 }
 
-                // This fixes a bug caused by setting the default PAD drill size to a value other
-                // than 0 used to fix a bunch of debug assertions even though it is defined as a
-                // through hole pad.  Wouldn't a though hole pad with no drill be a surface mount
-                // pad (or a conn pad which is a smd pad with no solder paste)?
-                if( ( pad->GetAttribute() != PAD_ATTRIB::SMD ) && ( pad->GetAttribute() != PAD_ATTRIB::CONN ) )
-                    pad->SetDrillSize( drillSize );
-                else
-                    pad->SetDrillSize( wxSize( 0, 0 ) );
+                break;
 
+                case T_offset:
+                    pt.x = parseBoardUnits( "drill offset x" );
+                    pt.y = parseBoardUnits( "drill offset y" );
+                    pad->SetOffset( pt );
+                    NeedRIGHT();
+                    break;
+
+                default:
+                    Expecting( "oval, size, or offset" );
+                }
             }
+
+            // This fixes a bug caused by setting the default PAD drill size to a value other
+            // than 0 used to fix a bunch of debug assertions even though it is defined as a
+            // through hole pad.  Wouldn't a though hole pad with no drill be a surface mount
+            // pad (or a conn pad which is a smd pad with no solder paste)?
+            if( ( pad->GetAttribute() != PAD_ATTRIB::SMD )
+                && ( pad->GetAttribute() != PAD_ATTRIB::CONN ) )
+                pad->SetDrillSize( drillSize );
+            else
+                pad->SetDrillSize( wxSize( 0, 0 ) );
+
             break;
+        }
 
         case T_layers:
-            {
-                LSET layerMask = parseBoardItemLayersAsMask();
-                pad->SetLayerSet( layerMask );
-            }
+        {
+            LSET layerMask = parseBoardItemLayersAsMask();
+            pad->SetLayerSet( layerMask );
             break;
+        }
 
         case T_net:
             if( ! pad->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
             {
-                wxLogError( _( "Invalid net ID in\nfile: %s\nline: %d offset: %d" ),
-                            CurSource(),
-                            CurLineNumber(),
-                            CurOffset() );
+                wxLogError( _( "Invalid net ID in\nfile: %s\nline: %d offset: %d" ), CurSource(),
+                            CurLineNumber(), CurOffset() );
             }
 
             NeedSYMBOLorNUMBER();
@@ -4104,9 +4119,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
                 {
                     pad->SetNetCode( NETINFO_LIST::ORPHANED, /* aNoAssert */ true );
                     wxLogError( _( "Net name doesn't match ID in\nfile: %s\nline: %d offset: %d" ),
-                                 CurSource(),
-                                 CurLineNumber(),
-                                 CurOffset() );
+                                CurSource(), CurLineNumber(), CurOffset() );
                 }
             }
 
@@ -4188,6 +4201,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
             while( !end_list )
             {
                 token = NextTok();
+
                 switch( token )
                 {
                 case T_top_left:
@@ -4212,14 +4226,16 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
                     break;
 
                 default:
-                    Expecting( "chamfer_top_left chamfer_top_right chamfer_bottom_left or chamfer_bottom_right" );
+                    Expecting( "chamfer_top_left chamfer_top_right chamfer_bottom_left or "
+                               "chamfer_bottom_right" );
                 }
             }
 
             if( pad->GetChamferPositions() != RECT_NO_CHAMFER )
                 pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
-        }
+
             break;
+        }
 
         case T_property:
         {
@@ -4268,8 +4284,9 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
                     break;
                 }
             }
-        }
+
             break;
+        }
 
         case T_options:
             parsePAD_option( pad.get() );
@@ -4285,7 +4302,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
                 // because they are the same as a PCB_SHAPE.
                 // However it could be better to write a specific parser, to avoid possible issues
                 // if the PCB_SHAPE parser is modified.
-                PCB_SHAPE* dummysegm = NULL;
+                PCB_SHAPE* dummysegm = nullptr;
 
                 switch( token )
                 {
@@ -4334,6 +4351,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent )
 
                 delete dummysegm;
             }
+
             break;
 
         case T_remove_unused_layers:
@@ -4424,6 +4442,7 @@ bool PCB_PARSER::parsePAD_option( PAD* aPad )
                 // just skip unknown keywords
                 break;
             }
+
             NeedRIGHT();
             break;
 
@@ -4432,6 +4451,7 @@ bool PCB_PARSER::parsePAD_option( PAD* aPad )
             // just skip unknown keywords
             while( (token = NextTok() ) != T_RIGHT )
             {}
+
             break;
         }
     }
@@ -4440,14 +4460,10 @@ bool PCB_PARSER::parsePAD_option( PAD* aPad )
 }
 
 
-// Example of group format:
-//     (group <(name “groupName”)> (id 12345679)
-//         (members id_1 id_2 … id_last )
-//     )
 void PCB_PARSER::parseGROUP( BOARD_ITEM* aParent )
 {
     wxCHECK_RET( CurTok() == T_group,
-            wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_GROUP." ) );
+                 wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_GROUP." ) );
 
     wxPoint pt;
     T       token;
@@ -4503,8 +4519,8 @@ void PCB_PARSER::parseGROUP( BOARD_ITEM* aParent )
 
 PCB_ARC* PCB_PARSER::parseARC()
 {
-    wxCHECK_MSG( CurTok() == T_arc, NULL,
-            wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as ARC." ) );
+    wxCHECK_MSG( CurTok() == T_arc, nullptr,
+                 wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as ARC." ) );
 
     wxPoint pt;
     T       token;
@@ -4555,10 +4571,8 @@ PCB_ARC* PCB_PARSER::parseARC()
         case T_net:
             if( !arc->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
                 THROW_IO_ERROR( wxString::Format(
-                        _( "Invalid net ID in\nfile: '%s'\nline: %d\noffset: %d." ),
-                        CurSource(),
-                        CurLineNumber(),
-                        CurOffset() ) );
+                        _( "Invalid net ID in\nfile: '%s'\nline: %d\noffset: %d." ), CurSource(),
+                        CurLineNumber(), CurOffset() ) );
             break;
 
         case T_tstamp:
@@ -4589,7 +4603,7 @@ PCB_ARC* PCB_PARSER::parseARC()
 
 PCB_TRACK* PCB_PARSER::parsePCB_TRACK()
 {
-    wxCHECK_MSG( CurTok() == T_segment, NULL,
+    wxCHECK_MSG( CurTok() == T_segment, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TRACK." ) );
 
     wxPoint pt;
@@ -4667,7 +4681,7 @@ PCB_TRACK* PCB_PARSER::parsePCB_TRACK()
 
 PCB_VIA* PCB_PARSER::parsePCB_VIA()
 {
-    wxCHECK_MSG( CurTok() == T_via, NULL,
+    wxCHECK_MSG( CurTok() == T_via, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_VIA." ) );
 
     wxPoint pt;
@@ -4723,8 +4737,8 @@ PCB_VIA* PCB_PARSER::parsePCB_VIA()
             layer2 = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
             via->SetLayerPair( layer1, layer2 );
             NeedRIGHT();
-        }
             break;
+        }
 
         case T_net:
             if( !via->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
@@ -4785,7 +4799,7 @@ PCB_VIA* PCB_PARSER::parsePCB_VIA()
 
 ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
 {
-    wxCHECK_MSG( CurTok() == T_zone, NULL,
+    wxCHECK_MSG( CurTok() == T_zone, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
                  wxT( " as ZONE." ) );
 
@@ -4953,12 +4967,13 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
 
                     if( token == T_segment )    // deprecated
                     {
-                        // SEGMENT fill mode no longer supported.  Make sure user is OK with converting them.
+                        // SEGMENT fill mode no longer supported.  Make sure user is OK with
+                        // converting them.
                         if( m_showLegacyZoneWarning )
                         {
                             KIDIALOG dlg( nullptr,
-                                          _( "The legacy segment fill mode is no longer supported.\n"
-                                             "Convert zones to polygon fills?"),
+                                          _( "The legacy segment fill mode is no longer supported."
+                                             "\nConvert zones to polygon fills?"),
                                           _( "Legacy Zone Warning" ),
                                           wxYES_NO | wxICON_WARNING );
 
@@ -5050,16 +5065,19 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
                     case T_chamfer:
                         if( !zone->GetIsRuleArea() ) // smoothing has meaning only for filled zones
                             zone->SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_CHAMFER );
+
                         break;
 
                     case T_fillet:
                         if( !zone->GetIsRuleArea() ) // smoothing has meaning only for filled zones
                             zone->SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_FILLET );
+
                         break;
 
                     default:
                         Expecting( "none, chamfer, or fillet" );
                     }
+
                     NeedRIGHT();
                     break;
 
@@ -5070,7 +5088,6 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
                     NeedRIGHT();
                     break;
 
-
                 case T_island_removal_mode:
                     tmp = parseInt( "island_removal_mode" );
 
@@ -5096,6 +5113,7 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
                                "island_removal_mode, or island_area_min" );
                 }
             }
+
             break;
 
         case T_keepout:
@@ -5163,27 +5181,27 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
             break;
 
         case T_polygon:
-            {
-                SHAPE_LINE_CHAIN outline;
+        {
+            SHAPE_LINE_CHAIN outline;
 
-                NeedLEFT();
-                token = NextTok();
+            NeedLEFT();
+            token = NextTok();
 
-                if( token != T_pts )
-                    Expecting( T_pts );
+            if( token != T_pts )
+                Expecting( T_pts );
 
-                for( token = NextTok(); token != T_RIGHT; token = NextTok() )
-                    parseOutlinePoints( outline );
+            for( token = NextTok(); token != T_RIGHT; token = NextTok() )
+                parseOutlinePoints( outline );
 
-                NeedRIGHT();
+            NeedRIGHT();
 
-                outline.SetClosed( true );
+            outline.SetClosed( true );
 
-                // Remark: The first polygon is the main outline.
-                // Others are holes inside the main outline.
-                zone->AddPolygon( outline );
-            }
+            // Remark: The first polygon is the main outline.
+            // Others are holes inside the main outline.
+            zone->AddPolygon( outline );
             break;
+        }
 
         case T_filled_polygon:
             {
@@ -5238,53 +5256,52 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
 
                 addedFilledPolygons |= !poly.IsEmpty();
             }
+
             break;
 
         case T_fill_segments:
-            {
-                ZONE_SEGMENT_FILL segs;
+        {
+            ZONE_SEGMENT_FILL segs;
 
-                for( token = NextTok();  token != T_RIGHT;  token = NextTok() )
+            for( token = NextTok(); token != T_RIGHT; token = NextTok() )
+            {
+                if( token != T_LEFT )
+                    Expecting( T_LEFT );
+
+                token = NextTok();
+
+                if( token == T_layer )
                 {
+                    filledLayer = parseBoardItemLayer();
+                    NeedRIGHT();
+                    token = NextTok();
+
                     if( token != T_LEFT )
                         Expecting( T_LEFT );
 
                     token = NextTok();
-
-                    if( token == T_layer )
-                    {
-                        filledLayer = parseBoardItemLayer();
-                        NeedRIGHT();
-                        token = NextTok();
-
-                        if( token != T_LEFT )
-                            Expecting( T_LEFT );
-
-                        token = NextTok();
-                    }
-                    else
-                    {
-                        filledLayer = zone->GetLayer();
-                    }
-
-                    if( token != T_pts )
-                        Expecting( T_pts );
-
-                    SEG segment( parseXY(), parseXY() );
-                    NeedRIGHT();
-                    segs.push_back( segment );
+                }
+                else
+                {
+                    filledLayer = zone->GetLayer();
                 }
 
-                zone->SetFillSegments( filledLayer, segs );
+                if( token != T_pts )
+                    Expecting( T_pts );
+
+                SEG segment( parseXY(), parseXY() );
+                NeedRIGHT();
+                segs.push_back( segment );
             }
+
+            zone->SetFillSegments( filledLayer, segs );
             break;
+        }
 
         case T_name:
-            {
-                NextTok();
-                zone->SetZoneName( FromUTF8() );
-                NeedRIGHT();
-            }
+            NextTok();
+            zone->SetZoneName( FromUTF8() );
+            NeedRIGHT();
             break;
 
         default:
@@ -5341,6 +5358,7 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
 
             // Store the new code mapping
             pushValueIntoMap( newnetcode, net->GetNetCode() );
+
             // and update the zone netcode
             zone->SetNetCode( net->GetNetCode() );
         }
@@ -5355,7 +5373,7 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
 
 PCB_TARGET* PCB_PARSER::parsePCB_TARGET()
 {
-    wxCHECK_MSG( CurTok() == T_target, NULL,
+    wxCHECK_MSG( CurTok() == T_target, nullptr,
                  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TARGET." ) );
 
     wxPoint pt;
diff --git a/pcbnew/plugins/kicad/pcb_parser.h b/pcbnew/plugins/kicad/pcb_parser.h
index 7344a6a473..b3fb0e3c13 100644
--- a/pcbnew/plugins/kicad/pcb_parser.h
+++ b/pcbnew/plugins/kicad/pcb_parser.h
@@ -211,7 +211,7 @@ private:
 
     FP_TEXT*            parseFP_TEXT();
     FP_SHAPE*           parseFP_SHAPE();
-    PAD*                parsePAD( FOOTPRINT* aParent = NULL );
+    PAD*                parsePAD( FOOTPRINT* aParent = nullptr );
 
     // Parse only the (option ...) inside a pad description
     bool                parsePAD_option( PAD* aPad );
@@ -322,7 +322,7 @@ private:
 
     inline int parseInt()
     {
-        return (int)strtol( CurText(), NULL, 10 );
+        return (int)strtol( CurText(), nullptr, 10 );
     }
 
     inline int parseInt( const char* aExpected )
@@ -334,7 +334,7 @@ private:
     inline long parseHex()
     {
         NextTok();
-        return strtol( CurText(), NULL, 16 );
+        return strtol( CurText(), nullptr, 16 );
     }
 
     bool parseBool();
diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp
index 748cb480b3..323e8a1854 100644
--- a/pcbnew/plugins/legacy/legacy_plugin.cpp
+++ b/pcbnew/plugins/legacy/legacy_plugin.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2019 Jean-Pierre Charras, jp.charras@wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -257,8 +257,10 @@ static EDA_TEXT_HJUSTIFY_T horizJustify( const char* horizontal )
 {
     if( !strcmp( "L", horizontal ) )
         return GR_TEXT_HJUSTIFY_LEFT;
+
     if( !strcmp( "R", horizontal ) )
         return GR_TEXT_HJUSTIFY_RIGHT;
+
     return GR_TEXT_HJUSTIFY_CENTER;
 }
 
@@ -266,8 +268,10 @@ static EDA_TEXT_VJUSTIFY_T vertJustify( const char* vertical )
 {
     if( !strcmp( "T", vertical ) )
         return GR_TEXT_VJUSTIFY_TOP;
+
     if( !strcmp( "B", vertical ) )
         return GR_TEXT_VJUSTIFY_BOTTOM;
+
     return GR_TEXT_VJUSTIFY_CENTER;
 }
 
@@ -307,13 +311,18 @@ PCB_LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
         // In .brd files, the layers are numbered from back to front
         // (the opposite of the .kicad_pcb files)
         if( old == LAYER_N_FRONT )
+        {
             newid = F_Cu;
+        }
         else if( old == LAYER_N_BACK )
+        {
             newid = B_Cu;
+        }
         else
         {
             newid = cu_count - 1 - old;
             wxASSERT( newid >= 0 );
+
             // This is of course incorrect, but at least it avoid crashing pcbnew:
             if( newid < 0 )
                 newid = 0;
@@ -337,7 +346,6 @@ PCB_LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
         case ECO2_N:                newid = Eco2_User;  break;
         case EDGE_N:                newid = Edge_Cuts;  break;
         default:
-//            wxASSERT( 0 );
             // Remap all illegal non copper layers to comment layer
             newid = Cmts_User;
         }
@@ -374,27 +382,29 @@ LSET LEGACY_PLUGIN::leg_mask2new( int cu_count, unsigned aMask )
  * like "man strtol()".  I can use this without casting, and its name says
  * what I am doing.
  */
-static inline int intParse( const char* next, const char** out = NULL )
+static inline int intParse( const char* next, const char** out = nullptr )
 {
     // please just compile this and be quiet, hide casting ugliness:
     return (int) strtol( next, (char**) out, 10 );
 }
 
+
 /**
  * Like #intParse but returns a LAYER_NUM.
  */
-static inline LAYER_NUM layerParse( const char* next, const char** out = NULL )
+static inline LAYER_NUM layerParse( const char* next, const char** out = nullptr )
 {
     return intParse( next, out );
 }
 
+
 /**
  * Parse an ASCII hex integer string with possible leading whitespace into
- * a long integer and updates the pointer at \a out if it is not NULL, just
+ * a long integer and updates the pointer at \a out if it is not nullptr, just
  * like "man strtol".  I can use this without casting, and its name says
  * what I am doing.
  */
-static inline long hexParse( const char* next, const char** out = NULL )
+static inline long hexParse( const char* next, const char** out = nullptr )
 {
     // please just compile this and be quiet, hide casting ugliness:
     return strtol( next, (char**) out, 16 );
@@ -466,7 +476,7 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend )
     // Then follows $EQUIPOT and all the rest
     char* line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         checkpoint();
 
@@ -491,63 +501,51 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend )
             loadFOOTPRINT( footprint.get());
             m_board->Add( footprint.release(), ADD_MODE::APPEND );
         }
-
         else if( TESTLINE( "$DRAWSEGMENT" ) )
         {
             loadPCB_LINE();
         }
-
         else if( TESTLINE( "$EQUIPOT" ) )
         {
             loadNETINFO_ITEM();
         }
-
         else if( TESTLINE( "$TEXTPCB" ) )
         {
             loadPCB_TEXT();
         }
-
         else if( TESTLINE( "$TRACK" ) )
         {
             loadTrackList( PCB_TRACE_T );
         }
-
         else if( TESTLINE( "$NCLASS" ) )
         {
             loadNETCLASS();
         }
-
         else if( TESTLINE( "$CZONE_OUTLINE" ) )
         {
             loadZONE_CONTAINER();
         }
-
         else if( TESTLINE( "$COTATION" ) )
         {
             loadDIMENSION();
         }
-
         else if( TESTLINE( "$PCB_TARGET" ) || TESTLINE( "$MIREPCB" ) )
         {
             loadPCB_TARGET();
         }
-
         else if( TESTLINE( "$ZONE" ) )
         {
             // No longer supported; discard segment fills
             loadTrackList( NOT_USED );
         }
-
         else if( TESTLINE( "$GENERAL" ) )
         {
             loadGENERAL();
         }
-
         else if( TESTLINE( "$SHEETDESCR" ) )
         {
             loadSHEET();
         }
-
         else if( TESTLINE( "$SETUP" ) )
         {
             if( !doAppend )
@@ -556,7 +554,7 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend )
             }
             else
             {
-                while( ( line = READLINE( m_reader ) ) != NULL )
+                while( ( line = READLINE( m_reader ) ) != nullptr )
                 {
                     // gobble until $EndSetup
                     if( TESTLINE( "$EndSETUP" ) )
@@ -564,9 +562,10 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend )
                 }
             }
         }
-
         else if( TESTLINE( "$EndBOARD" ) )
+        {
             return;     // preferred exit
+        }
     }
 
     THROW_IO_ERROR( "Missing '$EndBOARD'" );
@@ -611,7 +610,7 @@ void LEGACY_PLUGIN::loadGENERAL()
     char*   saveptr;
     bool    saw_LayerCount = false;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -625,7 +624,6 @@ void LEGACY_PLUGIN::loadGENERAL()
                 diskToBiu = IU_PER_MM;
             }
         }
-
         else if( TESTLINE( "LayerCount" ) )
         {
             int tmp = intParse( line + SZ( "LayerCount" ) );
@@ -638,7 +636,6 @@ void LEGACY_PLUGIN::loadGENERAL()
 
             saw_LayerCount = true;
         }
-
         else if( TESTLINE( "EnabledLayers" ) )
         {
             if( !saw_LayerCount )
@@ -656,7 +653,6 @@ void LEGACY_PLUGIN::loadGENERAL()
             // Ensure copper layers count is not modified:
             m_board->SetCopperLayerCount( m_cu_count );
         }
-
         else if( TESTLINE( "VisibleLayers" ) )
         {
         // Keep all enabled layers visible.
@@ -673,7 +669,6 @@ void LEGACY_PLUGIN::loadGENERAL()
             m_board->SetVisibleLayers( new_mask );
         #endif
         }
-
         else if( TESTLINE( "Ly" ) )    // Old format for Layer count
         {
             if( !saw_LayerCount )
@@ -686,19 +681,16 @@ void LEGACY_PLUGIN::loadGENERAL()
                 saw_LayerCount = true;
             }
         }
-
         else if( TESTLINE( "BoardThickness" ) )
         {
             BIU thickn = biuParse( line + SZ( "BoardThickness" ) );
             m_board->GetDesignSettings().SetBoardThickness( thickn );
         }
-
         else if( TESTLINE( "NoConn" ) )
         {
             // ignore
             intParse( line + SZ( "NoConn" ) );
         }
-
         else if( TESTLINE( "Di" ) )
         {
             biuParse( line + SZ( "Di" ), &data );
@@ -706,19 +698,18 @@ void LEGACY_PLUGIN::loadGENERAL()
             biuParse( data, &data );
             biuParse( data );
         }
-
         else if( TESTLINE( "Nnets" ) )
         {
             m_netCodes.resize( intParse( line + SZ( "Nnets" ) ) );
         }
-
         else if( TESTLINE( "Nn" ) )     // id "Nnets" for old .brd files
         {
             m_netCodes.resize( intParse( line + SZ( "Nn" ) ) );
         }
-
         else if( TESTLINE( "$EndGENERAL" ) )
+        {
             return;     // preferred exit
+        }
     }
 
     THROW_IO_ERROR( "Missing '$EndGENERAL'" );
@@ -732,7 +723,7 @@ void LEGACY_PLUGIN::loadSHEET()
     char*       line;
     char*       data;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         if( TESTLINE( "Sheet" ) )
         {
@@ -753,9 +744,9 @@ void LEGACY_PLUGIN::loadSHEET()
                     THROW_IO_ERROR( m_error );
                 }
 
-                char*   width  = strtok_r( NULL, delims, &data );
-                char*   height = strtok_r( NULL, delims, &data );
-                char*   orient = strtok_r( NULL, delims, &data );
+                char*   width  = strtok_r( nullptr, delims, &data );
+                char*   height = strtok_r( nullptr, delims, &data );
+                char*   orient = strtok_r( nullptr, delims, &data );
 
                 // only parse the width and height if page size is custom ("User")
                 if( wname == PAGE_INFO::Custom )
@@ -780,85 +771,71 @@ void LEGACY_PLUGIN::loadSHEET()
                 m_board->SetPageSettings( page );
             }
         }
-
         else if( TESTLINE( "Title" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetTitle( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Date" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetDate( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Rev" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetRevision( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comp" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetCompany( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment1" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 0, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment2" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 1, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment3" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 2, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment4" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 3, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment5" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 4, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment6" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 5, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment7" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 6, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment8" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 7, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Comment9" ) )
         {
             ReadDelimitedText( buf, line, sizeof(buf) );
             tb.SetComment( 8, FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "$EndSHEETDESCR" ) )
         {
             m_board->SetTitleBlock( tb );
@@ -880,7 +857,7 @@ void LEGACY_PLUGIN::loadSETUP()
 
     m_board->m_LegacyDesignSettingsLoaded = true;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -900,20 +877,8 @@ void LEGACY_PLUGIN::loadSETUP()
             BIU gx = biuParse( line + SZ( "AuxiliaryAxisOrg" ), &data );
             BIU gy = biuParse( data );
 
-            // m_board->SetAuxOrigin( wxPoint( gx, gy ) ); gets overwritten by SetDesignSettings() below
             bds.m_AuxOrigin = wxPoint( gx, gy );
         }
-
-        /* Done from $General above's "LayerCount"
-        else if( TESTLINE( "Layers" ) )
-        {
-            int tmp = intParse( line + SZ( "Layers" ) );
-            m_board->SetCopperLayerCount( tmp );
-
-            m_cu_count = tmp;
-        }
-        */
-
         else if( TESTSUBSTR( "Layer[" ) )
         {
             // eg: "Layer[n]  <a_Layer_name_with_no_spaces> <LAYER_T>"
@@ -921,22 +886,6 @@ void LEGACY_PLUGIN::loadSETUP()
             LAYER_NUM    layer_num = layerParse( line + SZ( "Layer[" ), &data );
             PCB_LAYER_ID layer_id  = leg_layer2new( m_cu_count, layer_num );
 
-            /*
-            switch( layer_num )
-            {
-            case LAYER_N_BACK:
-                layer_id = B_Cu;
-                break;
-
-            case LAYER_N_FRONT:
-                layer_id = F_Cu;
-                break;
-
-            default:
-                layer_id = PCB_LAYER_ID( layer_num );
-            }
-            */
-
             data = strtok_r( (char*) data+1, delims, &saveptr );    // +1 for ']'
 
             if( data )
@@ -944,7 +893,7 @@ void LEGACY_PLUGIN::loadSETUP()
                 wxString layerName = FROM_UTF8( data );
                 m_board->SetLayerName( layer_id, layerName );
 
-                data = strtok_r( NULL, delims, &saveptr );
+                data = strtok_r( nullptr, delims, &saveptr );
 
                 if( data )  // optional in old board files
                 {
@@ -953,67 +902,56 @@ void LEGACY_PLUGIN::loadSETUP()
                 }
             }
         }
-
         else if( TESTLINE( "TrackWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
             netclass_default->SetTrackWidth( tmp );
         }
-
         else if( TESTLINE( "TrackWidthList" ) )
         {
             BIU tmp = biuParse( line + SZ( "TrackWidthList" ) );
             bds.m_TrackWidthList.push_back( tmp );
         }
-
         else if( TESTLINE( "TrackClearence" ) )
         {
             BIU tmp = biuParse( line + SZ( "TrackClearence" ) );
             netclass_default->SetClearance( tmp );
         }
-
         else if( TESTLINE( "TrackMinWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
             bds.m_TrackMinWidth = tmp;
         }
-
         else if( TESTLINE( "ZoneClearence" ) )
         {
             BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
             zs.m_ZoneClearance = tmp;
         }
-
         else if( TESTLINE( "Zone_45_Only" ) )
         {
             bool tmp = (bool) intParse( line + SZ( "Zone_45_Only" ) );
             zs.m_Zone_45_Only = tmp;
         }
-
         else if( TESTLINE( "DrawSegmWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
             bds.m_LineThickness[ LAYER_CLASS_COPPER ] = tmp;
         }
-
         else if( TESTLINE( "EdgeSegmWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
             bds.m_LineThickness[ LAYER_CLASS_EDGES ] = tmp;
         }
-
         else if( TESTLINE( "ViaMinSize" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaMinSize" ) );
             bds.m_ViasMinSize = tmp;
         }
-
         else if( TESTLINE( "MicroViaMinSize" ) )
         {
             BIU tmp = biuParse( line + SZ( "MicroViaMinSize" ) );
             bds.m_MicroViasMinSize = tmp;
         }
-
         else if( TESTLINE( "ViaSizeList" ) )
         {
             // e.g.  "ViaSizeList DIAMETER [DRILL]"
@@ -1025,58 +963,48 @@ void LEGACY_PLUGIN::loadSETUP()
             if( data )  // DRILL may not be present ?
                 drill = biuParse( data );
 
-            bds.m_ViasDimensionsList.emplace_back( diameter,
-                                                                                        drill );
+            bds.m_ViasDimensionsList.emplace_back( diameter, drill );
         }
-
         else if( TESTLINE( "ViaSize" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaSize" ) );
             netclass_default->SetViaDiameter( tmp );
         }
-
         else if( TESTLINE( "ViaDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
             netclass_default->SetViaDrill( tmp );
         }
-
         else if( TESTLINE( "ViaMinDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
             bds.m_MinThroughDrill = tmp;
         }
-
         else if( TESTLINE( "MicroViaSize" ) )
         {
             BIU tmp = biuParse( line + SZ( "MicroViaSize" ) );
             netclass_default->SetuViaDiameter( tmp );
         }
-
         else if( TESTLINE( "MicroViaDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
             netclass_default->SetuViaDrill( tmp );
         }
-
         else if( TESTLINE( "MicroViaMinDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
             bds.m_MicroViasMinDrill = tmp;
         }
-
         else if( TESTLINE( "MicroViasAllowed" ) )
         {
             int tmp = intParse( line + SZ( "MicroViasAllowed" ) );
             bds.m_MicroViasAllowed = tmp;
         }
-
         else if( TESTLINE( "TextPcbWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
             bds.m_TextThickness[ LAYER_CLASS_COPPER ] = tmp;
         }
-
         else if( TESTLINE( "TextPcbSize" ) )
         {
             BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
@@ -1084,21 +1012,18 @@ void LEGACY_PLUGIN::loadSETUP()
 
             bds.m_TextSize[ LAYER_CLASS_COPPER ] = wxSize( x, y );
         }
-
         else if( TESTLINE( "EdgeModWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
             bds.m_LineThickness[ LAYER_CLASS_SILK ] = tmp;
             bds.m_LineThickness[ LAYER_CLASS_OTHERS ] = tmp;
         }
-
         else if( TESTLINE( "TextModWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
             bds.m_TextThickness[ LAYER_CLASS_SILK ] = tmp;
             bds.m_TextThickness[ LAYER_CLASS_OTHERS ] = tmp;
         }
-
         else if( TESTLINE( "TextModSize" ) )
         {
             BIU x = biuParse( line + SZ( "TextModSize" ), &data );
@@ -1107,7 +1032,6 @@ void LEGACY_PLUGIN::loadSETUP()
             bds.m_TextSize[ LAYER_CLASS_SILK ] = wxSize( x, y );
             bds.m_TextSize[ LAYER_CLASS_OTHERS ] = wxSize( x, y );
         }
-
         else if( TESTLINE( "PadSize" ) )
         {
             BIU x = biuParse( line + SZ( "PadSize" ), &data );
@@ -1115,31 +1039,26 @@ void LEGACY_PLUGIN::loadSETUP()
 
             bds.m_Pad_Master->SetSize( wxSize( x, y ) );
         }
-
         else if( TESTLINE( "PadDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "PadDrill" ) );
             bds.m_Pad_Master->SetDrillSize( wxSize( tmp, tmp ) );
         }
-
         else if( TESTLINE( "Pad2MaskClearance" ) )
         {
             BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
             bds.m_SolderMaskMargin = tmp;
         }
-
         else if( TESTLINE( "SolderMaskMinWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "SolderMaskMinWidth" ) );
             bds.m_SolderMaskMinWidth = tmp;
         }
-
         else if( TESTLINE( "Pad2PasteClearance" ) )
         {
             BIU tmp = biuParse( line + SZ( "Pad2PasteClearance" ) );
             bds.m_SolderPasteMargin = tmp;
         }
-
         else if( TESTLINE( "Pad2PasteClearanceRatio" ) )
         {
             double ratio = atof( line + SZ( "Pad2PasteClearanceRatio" ) );
@@ -1151,28 +1070,26 @@ void LEGACY_PLUGIN::loadSETUP()
             BIU x = biuParse( line + SZ( "GridOrigin" ), &data );
             BIU y = biuParse( data );
 
-            // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten by SetDesignSettings() below
             bds.m_GridOrigin = wxPoint( x, y );
         }
-
         else if( TESTLINE( "VisibleElements" ) )
         {
-        // Keep all elements visible.
-        // the old visibility control does not make sense in current Pcbnew version,
-        // and this code does not work.
-        #if 0
+            // Keep all elements visible.
+            // the old visibility control does not make sense in current Pcbnew version,
+            // and this code does not work.
+#if 0
             int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
 
             // Does not work: each old item should be tested one by one to set
             // visibility of new item list
             GAL_SET visibles;
+
             for( size_t i = 0; i < visibles.size(); i++ )
                 visibles.set( i, visibleElements & ( 1u << i ) );
 
             m_board->SetVisibleElements( visibles );
-        #endif
+#endif
         }
-
         else if( TESTLINE( "$EndSETUP" ) )
         {
             m_board->SetZoneSettings( zs );
@@ -1195,7 +1112,8 @@ void LEGACY_PLUGIN::loadSETUP()
      * (the first value is not tested, because it is the netclass value)
      */
     BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
-    sort( designSettings.m_ViasDimensionsList.begin() + 1, designSettings.m_ViasDimensionsList.end() );
+    sort( designSettings.m_ViasDimensionsList.begin() + 1,
+          designSettings.m_ViasDimensionsList.end() );
     sort( designSettings.m_TrackWidthList.begin() + 1, designSettings.m_TrackWidthList.end() );
 
     for( unsigned ii = 1; ii < designSettings.m_ViasDimensionsList.size() - 1; ii++ )
@@ -1222,7 +1140,7 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
 {
     char*   line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -1232,14 +1150,11 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
         {
             loadFP_SHAPE( aFootprint );
         }
-
         else if( TESTLINE( "$PAD" ) )
         {
             loadPAD( aFootprint );
         }
-
-        // Read a footprint text description (ref, value, or drawing)
-        else if( TESTSUBSTR( "T" ) )
+        else if( TESTSUBSTR( "T" ) )  // Read a footprint text description (ref, value, or drawing)
         {
             // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
             int tnum = intParse( line + SZ( "T" ) );
@@ -1264,7 +1179,6 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
 
             loadMODULE_TEXT( text );
         }
-
         else if( TESTLINE( "Po" ) )
         {
             // e.g. "Po 19120 39260 900 0 4E823D06 68183921-93a5-49ac-91b0-49d05a0e1647 ~~\r\n"
@@ -1292,44 +1206,35 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
             const_cast<KIID&>( aFootprint->m_Uuid ) = KIID( uuid );
             aFootprint->SetLastEditTime( edittime );
         }
-
-        /* footprint name set earlier, immediately after FOOTPRINT construction
-        else if( TESTLINE( "Li" ) )         // Library name of footprint
-        {
-            // There can be whitespace in the footprint name on some old libraries.
-            // Grab everything after "Li" up to end of line:
-            //aFootprint->SetFPID( FROM_UTF8( StrPurge( line + SZ( "Li" ) ) ) );
-        }
-        */
-
         else if( TESTLINE( "Sc" ) )         // timestamp
         {
             char* uuid = strtok_r( (char*) line + SZ( "Sc" ), delims, (char**) &data );
             const_cast<KIID&>( aFootprint->m_Uuid ) = KIID( uuid );
         }
-
         else if( TESTLINE( "Op" ) )         // (Op)tions for auto placement
         {
             int itmp1 = hexParse( line + SZ( "Op" ), &data );
             int itmp2 = hexParse( data );
 
             int cntRot180 = itmp2 & 0x0F;
+
             if( cntRot180 > 10 )
                 cntRot180 = 10;
 
             aFootprint->SetPlacementCost180( cntRot180 );
 
             int cntRot90  = itmp1 & 0x0F;
+
             if( cntRot90 > 10 )
                 cntRot90 = 0;
 
             itmp1 = (itmp1 >> 4) & 0x0F;
+
             if( itmp1 > 10 )
                 itmp1 = 0;
 
             aFootprint->SetPlacementCost90((itmp1 << 4) | cntRot90 );
         }
-
         else if( TESTLINE( "At" ) )         // (At)tributes of footprint
         {
             int attrs = 0;
@@ -1345,7 +1250,6 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
 
             aFootprint->SetAttributes( attrs );
         }
-
         else if( TESTLINE( "AR" ) )         // Alternate Reference
         {
             // e.g. "AR /68183921-93a5-49ac-e164-49d05a0e1647/93a549d0-49d0-e164-91b0-49d05a0e1647"
@@ -1354,73 +1258,65 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
             if( data )
                 aFootprint->SetPath( KIID_PATH( FROM_UTF8( data ) ) );
         }
-
         else if( TESTLINE( "$SHAPE3D" ) )
         {
             load3D( aFootprint );
         }
-
         else if( TESTLINE( "Cd" ) )
         {
             // e.g. "Cd Double rangee de contacts 2 x 4 pins\r\n"
             aFootprint->SetDescription( FROM_UTF8( StrPurge( line + SZ( "Cd" ) ) ) );
         }
-
         else if( TESTLINE( "Kw" ) )         // Key words
         {
             aFootprint->SetKeywords( FROM_UTF8( StrPurge( line + SZ( "Kw" ) ) ) );
         }
-
         else if( TESTLINE( ".SolderPasteRatio" ) )
         {
             double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
+
             // Due to a bug in dialog editor in Footprint Editor, fixed in BZR version 3565
             // this parameter can be broken.
             // It should be >= -50% (no solder paste) and <= 0% (full area of the pad)
 
             if( tmp < -0.50 )
                 tmp = -0.50;
+
             if( tmp > 0.0 )
                 tmp = 0.0;
+
             aFootprint->SetLocalSolderPasteMarginRatio( tmp );
         }
-
         else if( TESTLINE( ".SolderPaste" ) )
         {
             BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
             aFootprint->SetLocalSolderPasteMargin( tmp );
         }
-
         else if( TESTLINE( ".SolderMask" ) )
         {
             BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
             aFootprint->SetLocalSolderMaskMargin( tmp );
         }
-
         else if( TESTLINE( ".LocalClearance" ) )
         {
             BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
             aFootprint->SetLocalClearance( tmp );
         }
-
         else if( TESTLINE( ".ZoneConnection" ) )
         {
             int tmp = intParse( line + SZ( ".ZoneConnection" ) );
             aFootprint->SetZoneConnection((ZONE_CONNECTION) tmp );
         }
-
         else if( TESTLINE( ".ThermalWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
             aFootprint->SetThermalWidth( tmp );
         }
-
         else if( TESTLINE( ".ThermalGap" ) )
         {
             BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
             aFootprint->SetThermalGap( tmp );
         }
-
         else if( TESTLINE( "$EndMODULE" ) )
         {
             return;     // preferred exit
@@ -1439,7 +1335,7 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
     char*                line;
     char*                saveptr;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -1456,7 +1352,8 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
 
             data = line + SZ( "Sh" ) + 1;   // +1 skips trailing whitespace
 
-            data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1;  // +1 trailing whitespace
+            // +1 trailing whitespace.
+            data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1;
 
             while( isSpace( *data ) )
                 ++data;
@@ -1478,11 +1375,8 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             case 'T':   padshape = static_cast<int>( PAD_SHAPE::TRAPEZOID );   break;
             default:
                 m_error.Printf( _( "Unknown padshape '%c=0x%02x' on line: %d of footprint: '%s'." ),
-                                padchar,
-                                padchar,
-                                m_reader->LineNumber(),
-                                aFootprint->GetFPID().GetLibItemName().wx_str()
-                    );
+                                padchar, padchar, m_reader->LineNumber(),
+                                aFootprint->GetFPID().GetLibItemName().wx_str() );
                 THROW_IO_ERROR( m_error );
             }
 
@@ -1494,6 +1388,7 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
                 // add 8 bit bytes, file format 1 was KiCad font type byte,
                 // simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1)
                 const unsigned char* cp = (unsigned char*) mypadname;
+
                 while( *cp )
                 {
                     padname += *cp++;  // unsigned, ls 8 bits only
@@ -1504,6 +1399,7 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
                 // version 2, which is UTF8.
                 padname = FROM_UTF8( mypadname );
             }
+
             // chances are both were ASCII, but why take chances?
 
             pad->SetName( padname );
@@ -1512,7 +1408,6 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             pad->SetDelta( wxSize( delta_x, delta_y ) );
             pad->SetOrientation( orient );
         }
-
         else if( TESTLINE( "Dr" ) )         // (Dr)ill
         {
             // e.g. "Dr 350 0 0" or "Dr 0 0 0 O 0 0"
@@ -1524,16 +1419,17 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             PAD_DRILL_SHAPE_T drShape = PAD_DRILL_SHAPE_CIRCLE;
 
             data = strtok_r( (char*) data, delims, &saveptr );
+
             if( data )  // optional shape
             {
                 if( data[0] == 'O' )
                 {
                     drShape = PAD_DRILL_SHAPE_OBLONG;
 
-                    data    = strtok_r( NULL, delims, &saveptr );
+                    data    = strtok_r( nullptr, delims, &saveptr );
                     drill_x = biuParse( data );
 
-                    data    = strtok_r( NULL, delims, &saveptr );
+                    data    = strtok_r( nullptr, delims, &saveptr );
                     drill_y = biuParse( data );
                 }
             }
@@ -1542,7 +1438,6 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             pad->SetOffset( wxPoint( offs_x, offs_y ) );
             pad->SetDrillSize( wxSize( drill_x, drill_y ) );
         }
-
         else if( TESTLINE( "At" ) )         // (At)tribute
         {
             // e.g. "At SMD N 00888000"
@@ -1561,15 +1456,14 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             else
                 attribute = PAD_ATTRIB::PTH;
 
-            strtok_r( NULL, delims, &saveptr );  // skip unused prm
-            data = strtok_r( NULL, delims, &saveptr );
+            strtok_r( nullptr, delims, &saveptr );  // skip unused prm
+            data = strtok_r( nullptr, delims, &saveptr );
 
             LEG_MASK layer_mask = hexParse( data );
 
             pad->SetLayerSet( leg_mask2new( m_cu_count, layer_mask ) );
             pad->SetAttribute( attribute );
         }
-
         else if( TESTLINE( "Ne" ) )         // (Ne)tname
         {
             // e.g. "Ne 461 "V5.0"
@@ -1589,7 +1483,6 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
                           == ConvertToNewOverbarNotation( FROM_UTF8( StrPurge( buf ) ) ) );
             }
         }
-
         else if( TESTLINE( "Po" ) )         // (Po)sition
         {
             // e.g. "Po 500 -500"
@@ -1601,55 +1494,46 @@ void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
             pad->SetPos0( pos );
             // pad->SetPosition( pos ); set at function return
         }
-
         else if( TESTLINE( "Le" ) )
         {
             BIU tmp = biuParse( line + SZ( "Le" ) );
             pad->SetPadToDieLength( tmp );
         }
-
         else if( TESTLINE( ".SolderMask" ) )
         {
             BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
             pad->SetLocalSolderMaskMargin( tmp );
         }
-
         else if( TESTLINE( ".SolderPasteRatio" ) )
         {
             double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
             pad->SetLocalSolderPasteMarginRatio( tmp );
         }
-
         else if( TESTLINE( ".SolderPaste" ) )
         {
             BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
             pad->SetLocalSolderPasteMargin( tmp );
         }
-
         else if( TESTLINE( ".LocalClearance" ) )
         {
             BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
             pad->SetLocalClearance( tmp );
         }
-
         else if( TESTLINE( ".ZoneConnection" ) )
         {
             int tmp = intParse( line + SZ( ".ZoneConnection" ) );
             pad->SetZoneConnection( (ZONE_CONNECTION) tmp );
         }
-
         else if( TESTLINE( ".ThermalWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
             pad->SetThermalSpokeWidth( tmp );
         }
-
         else if( TESTLINE( ".ThermalGap" ) )
         {
             BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
             pad->SetThermalGap( tmp );
         }
-
         else if( TESTLINE( "$EndPAD" ) )
         {
             // pad's "Position" is not relative to the footprint's, whereas Pos0 is relative
@@ -1683,9 +1567,7 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint )
     case 'P': shape = PCB_SHAPE_TYPE::POLYGON; break;
     default:
         m_error.Printf( _( "Unknown FP_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ),
-                        (unsigned char) line[1],
-                        (unsigned char) line[1],
-                        m_reader->LineNumber(),
+                        (unsigned char) line[1], (unsigned char) line[1], m_reader->LineNumber(),
                         aFootprint->GetFPID().GetLibItemName().wx_str() );
         THROW_IO_ERROR( m_error );
     }
@@ -1701,83 +1583,83 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint )
     switch( shape )
     {
     case PCB_SHAPE_TYPE::ARC:
-        {
-            BIU     start0_x = biuParse( line + SZ( "DA" ), &data );
-            BIU     start0_y = biuParse( data, &data );
-            BIU     end0_x   = biuParse( data, &data );
-            BIU     end0_y   = biuParse( data, &data );
-            double  angle    = degParse( data, &data );
+    {
+        BIU    start0_x = biuParse( line + SZ( "DA" ), &data );
+        BIU    start0_y = biuParse( data, &data );
+        BIU    end0_x = biuParse( data, &data );
+        BIU    end0_y = biuParse( data, &data );
+        double angle = degParse( data, &data );
 
-            width   = biuParse( data, &data );
-            layer   = layerParse( data );
+        width = biuParse( data, &data );
+        layer = layerParse( data );
 
-            dwg->SetStart0( wxPoint( start0_x, start0_y ) );
-            dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
+        dwg->SetStart0( wxPoint( start0_x, start0_y ) );
+        dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
 
-            // Setting angle will set m_thirdPoint0, so must be done after setting
-            // m_start0 and m_end0
-            dwg->SetAngle( angle );
-        }
+        // Setting angle will set m_thirdPoint0, so must be done after setting
+        // m_start0 and m_end0
+        dwg->SetAngle( angle );
         break;
+    }
 
     case PCB_SHAPE_TYPE::SEGMENT:
-        case PCB_SHAPE_TYPE::CIRCLE:
-        {
-            // e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
-            BIU     start0_x = biuParse( line + SZ( "DS" ), &data );
-            BIU     start0_y = biuParse( data, &data );
-            BIU     end0_x   = biuParse( data, &data );
-            BIU     end0_y   = biuParse( data, &data );
+    case PCB_SHAPE_TYPE::CIRCLE:
+    {
+        // e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
+        BIU start0_x = biuParse( line + SZ( "DS" ), &data );
+        BIU start0_y = biuParse( data, &data );
+        BIU end0_x = biuParse( data, &data );
+        BIU end0_y = biuParse( data, &data );
 
-            width   = biuParse( data, &data );
-            layer   = layerParse( data );
+        width = biuParse( data, &data );
+        layer = layerParse( data );
 
-            dwg->SetStart0( wxPoint( start0_x, start0_y ) );
-            dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
-        }
+        dwg->SetStart0( wxPoint( start0_x, start0_y ) );
+        dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
         break;
+    }
 
     case PCB_SHAPE_TYPE::POLYGON:
+    {
+        // e.g. "DP %d %d %d %d %d %d %d\n"
+        BIU start0_x = biuParse( line + SZ( "DP" ), &data );
+        BIU start0_y = biuParse( data, &data );
+        BIU end0_x = biuParse( data, &data );
+        BIU end0_y = biuParse( data, &data );
+        int ptCount = intParse( data, &data );
+
+        width = biuParse( data, &data );
+        layer = layerParse( data );
+
+        dwg->SetStart0( wxPoint( start0_x, start0_y ) );
+        dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
+
+        std::vector<wxPoint> pts;
+        pts.reserve( ptCount );
+
+        for( int ii = 0; ii < ptCount; ++ii )
         {
-            // e.g. "DP %d %d %d %d %d %d %d\n"
-            BIU start0_x = biuParse( line + SZ( "DP" ), &data );
-            BIU start0_y = biuParse( data, &data );
-            BIU end0_x   = biuParse( data, &data );
-            BIU end0_y   = biuParse( data, &data );
-            int ptCount  = intParse( data, &data );
-
-            width   = biuParse( data, &data );
-            layer   = layerParse( data );
-
-            dwg->SetStart0( wxPoint( start0_x, start0_y ) );
-            dwg->SetEnd0( wxPoint( end0_x, end0_y ) );
-
-            std::vector<wxPoint> pts;
-            pts.reserve( ptCount );
-
-            for( int ii = 0;  ii<ptCount;  ++ii )
+            if( ( line = READLINE( m_reader ) ) == nullptr )
             {
-                if( ( line = READLINE( m_reader ) ) == NULL )
-                {
-                    THROW_IO_ERROR( "S_POLGON point count mismatch." );
-                }
-
-                // e.g. "Dl 23 44\n"
-
-                if( !TESTLINE( "Dl" ) )
-                {
-                    THROW_IO_ERROR( "Missing Dl point def" );
-                }
-
-                BIU x = biuParse( line + SZ( "Dl" ), &data );
-                BIU y = biuParse( data );
-
-                pts.emplace_back( x, y );
+                THROW_IO_ERROR( "S_POLGON point count mismatch." );
             }
 
-            dwg->SetPolyPoints( pts );
+            // e.g. "Dl 23 44\n"
+
+            if( !TESTLINE( "Dl" ) )
+            {
+                THROW_IO_ERROR( "Missing Dl point def" );
+            }
+
+            BIU x = biuParse( line + SZ( "Dl" ), &data );
+            BIU y = biuParse( data );
+
+            pts.emplace_back( x, y );
         }
+
+        dwg->SetPolyPoints( pts );
         break;
+    }
 
     default:
         // first switch code above prevents us from getting here.
@@ -1842,18 +1724,17 @@ void LEGACY_PLUGIN::loadMODULE_TEXT( FP_TEXT* aText )
     // embedded nul(s?) placed to the right of the current field.
     // (that's the reason why strtok was deprecated...)
     char*   mirror  = strtok_r( (char*) data, delims, (char**) &data );
-    char*   hide    = strtok_r( NULL, delims, (char**) &data );
-    char*   tmp     = strtok_r( NULL, delims, (char**) &data );
+    char*   hide    = strtok_r( nullptr, delims, (char**) &data );
+    char*   tmp     = strtok_r( nullptr, delims, (char**) &data );
 
     LAYER_NUM layer_num = tmp ? layerParse( tmp ) : SILKSCREEN_N_FRONT;
 
-    char*   italic  = strtok_r( NULL, delims, (char**) &data );
+    char*   italic  = strtok_r( nullptr, delims, (char**) &data );
 
     char*   hjust   = strtok_r( (char*) txt_end, delims, (char**) &data );
-    char*   vjust   = strtok_r( NULL, delims, (char**) &data );
+    char*   vjust   = strtok_r( nullptr, delims, (char**) &data );
 
-    if( type != FP_TEXT::TEXT_is_REFERENCE
-     && type != FP_TEXT::TEXT_is_VALUE )
+    if( type != FP_TEXT::TEXT_is_REFERENCE && type != FP_TEXT::TEXT_is_VALUE )
         type = FP_TEXT::TEXT_is_DIVERS;
 
     aText->SetType( static_cast<FP_TEXT::TEXT_TYPE>( type ) );
@@ -1903,7 +1784,8 @@ void LEGACY_PLUGIN::load3D( FOOTPRINT* aFootprint )
     FP_3DMODEL t3D;
 
     char*   line;
-    while( ( line = READLINE( m_reader ) ) != NULL )
+
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         if( TESTLINE( "Na" ) )     // Shape File Name
         {
@@ -1911,31 +1793,21 @@ void LEGACY_PLUGIN::load3D( FOOTPRINT* aFootprint )
             ReadDelimitedText( buf, line + SZ( "Na" ), sizeof(buf) );
             t3D.m_Filename = buf;
         }
-
         else if( TESTLINE( "Sc" ) )     // Scale
         {
-            sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n",
-                    &t3D.m_Scale.x,
-                    &t3D.m_Scale.y,
+            sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n", &t3D.m_Scale.x, &t3D.m_Scale.y,
                     &t3D.m_Scale.z );
         }
-
         else if( TESTLINE( "Of" ) )     // Offset
         {
-            sscanf( line + SZ( "Of" ), "%lf %lf %lf\n",
-                    &t3D.m_Offset.x,
-                    &t3D.m_Offset.y,
+            sscanf( line + SZ( "Of" ), "%lf %lf %lf\n", &t3D.m_Offset.x, &t3D.m_Offset.y,
                     &t3D.m_Offset.z );
         }
-
         else if( TESTLINE( "Ro" ) )     // Rotation
         {
-            sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n",
-                    &t3D.m_Rotation.x,
-                    &t3D.m_Rotation.y,
+            sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n", &t3D.m_Rotation.x, &t3D.m_Rotation.y,
                     &t3D.m_Rotation.z );
         }
-
         else if( TESTLINE( "$EndSHAPE3D" ) )
         {
             aFootprint->Models().push_back( t3D );
@@ -1961,7 +1833,7 @@ void LEGACY_PLUGIN::loadPCB_LINE()
     char*   line;
     char*   saveptr;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -1983,14 +1855,14 @@ void LEGACY_PLUGIN::loadPCB_LINE()
             dseg->SetStart( wxPoint( start_x, start_y ) );
             dseg->SetEnd( wxPoint( end_x, end_y ) );
         }
-
         else if( TESTLINE( "De" ) )
         {
             BIU     x = 0;
             BIU     y;
 
             data = strtok_r( line + SZ( "De" ), delims, &saveptr );
-            for( int i = 0;  data;  ++i, data = strtok_r( NULL, delims, &saveptr ) )
+
+            for( int i = 0;  data;  ++i, data = strtok_r( nullptr, delims, &saveptr ) )
             {
                 switch( i )
                 {
@@ -2045,7 +1917,6 @@ void LEGACY_PLUGIN::loadPCB_LINE()
                 }
             }
         }
-
         else if( TESTLINE( "$EndDRAWSEGMENT" ) )
         {
             m_board->Add( dseg.release(), ADD_MODE::APPEND );
@@ -2067,11 +1938,11 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM()
 
     char  buf[1024];
 
-    NETINFO_ITEM*   net = NULL;
+    NETINFO_ITEM*   net = nullptr;
     char*           line;
     int             netCode = 0;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -2083,7 +1954,7 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM()
 
             ReadDelimitedText( buf, data, sizeof(buf) );
 
-            if( net == NULL )
+            if( net == nullptr )
             {
                 net = new NETINFO_ITEM( m_board, ConvertToNewOverbarNotation( FROM_UTF8( buf ) ),
                                         netCode );
@@ -2093,12 +1964,11 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM()
                 THROW_IO_ERROR( "Two net definitions in  '$EQUIPOT' block" );
             }
         }
-
         else if( TESTLINE( "$EndEQUIPOT" ) )
         {
             // net 0 should be already in list, so store this net
             // if it is not the net 0, or if the net 0 does not exists.
-            if( net && ( net->GetNetCode() > 0 || m_board->FindNet( 0 ) == NULL ) )
+            if( net && ( net->GetNetCode() > 0 || m_board->FindNet( 0 ) == nullptr ) )
             {
                 m_board->Add( net );
 
@@ -2107,12 +1977,12 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM()
                     m_netCodes.resize( netCode+1 );
 
                 m_netCodes[netCode] = net->GetNetCode();
-                net = NULL;
+                net = nullptr;
             }
             else
             {
                 delete net;
-                net = NULL;     // Avoid double deletion.
+                net = nullptr;     // Avoid double deletion.
             }
 
             return;     // preferred exit
@@ -2155,7 +2025,7 @@ void LEGACY_PLUGIN::loadPCB_TEXT()
 
     char*   line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -2164,13 +2034,11 @@ void LEGACY_PLUGIN::loadPCB_TEXT()
             ReadDelimitedText( text, line + SZ( "Te" ), sizeof(text) );
             pcbtxt->SetText( ConvertToNewOverbarNotation( FROM_UTF8( text ) ) );
         }
-
         else if( TESTLINE( "nl" ) )     // next line of the current text
         {
             ReadDelimitedText( text, line + SZ( "nl" ), sizeof(text) );
             pcbtxt->SetText( pcbtxt->GetText() + wxChar( '\n' ) +  FROM_UTF8( text ) );
         }
-
         else if( TESTLINE( "Po" ) )
         {
             wxSize  size;
@@ -2188,23 +2056,24 @@ void LEGACY_PLUGIN::loadPCB_TEXT()
 
             pcbtxt->SetTextPos( wxPoint( pos_x, pos_y ) );
         }
-
         else if( TESTLINE( "De" ) )
         {
             // e.g. "De 21 1 68183921-93a5-49ac-91b0-49d05a0e1647 Normal C\r\n"
             LAYER_NUM layer_num    = layerParse( line + SZ( "De" ), &data );
             int     notMirrored    = intParse( data, &data );
             char*   uuid           = strtok_r( (char*) data, delims, (char**) &data );
-            char*   style          = strtok_r( NULL, delims, (char**) &data );
-            char*   hJustify       = strtok_r( NULL, delims, (char**) &data );
-            char*   vJustify       = strtok_r( NULL, delims, (char**) &data );
+            char*   style          = strtok_r( nullptr, delims, (char**) &data );
+            char*   hJustify       = strtok_r( nullptr, delims, (char**) &data );
+            char*   vJustify       = strtok_r( nullptr, delims, (char**) &data );
 
             pcbtxt->SetMirrored( !notMirrored );
             const_cast<KIID&>( pcbtxt->m_Uuid ) = KIID( uuid );
             pcbtxt->SetItalic( !strcmp( style, "Italic" ) );
 
             if( hJustify )
+            {
                 pcbtxt->SetHorizJustify( horizJustify( hJustify ) );
+            }
             else
             {
                 // boom, somebody changed a constructor, I was relying on this:
@@ -2225,7 +2094,6 @@ void LEGACY_PLUGIN::loadPCB_TEXT()
             else    // not perfect, but putting this text on front layer is a workaround
                 pcbtxt->SetLayer( F_Cu );
         }
-
         else if( TESTLINE( "$EndTEXTPCB" ) )
         {
             return;     // preferred exit
@@ -2240,7 +2108,7 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
 {
     char*   line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         checkpoint();
 
@@ -2341,7 +2209,9 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
                 via->SetDrill( drill );
 
             if( via->GetViaType() == VIATYPE::THROUGH )
+            {
                 via->SetLayerPair( F_Cu, B_Cu );
+            }
             else
             {
                 PCB_LAYER_ID back  = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
@@ -2349,11 +2219,13 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
 
                 if( is_leg_copperlayer_valid( m_cu_count, back ) &&
                     is_leg_copperlayer_valid( m_cu_count, front ) )
+                {
                     via->SetLayerPair( front, back );
+                }
                 else
                 {
                     delete via;
-                    newTrack = NULL;
+                    newTrack = nullptr;
                 }
             }
         }
@@ -2363,11 +2235,13 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
             // reducing the number of layers does not remove tracks on removed layers
             // If happens, skip them
             if( is_leg_copperlayer_valid( m_cu_count, layer_num ) )
+            {
                 newTrack->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
+            }
             else
             {
                 delete newTrack;
-                newTrack = NULL;
+                newTrack = nullptr;
             }
         }
 
@@ -2396,7 +2270,7 @@ void LEGACY_PLUGIN::loadNETCLASS()
     // just before returning.
     NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         if( TESTLINE( "AddNet" ) )      // most frequent type of line
         {
@@ -2405,55 +2279,46 @@ void LEGACY_PLUGIN::loadNETCLASS()
             netname = ConvertToNewOverbarNotation( FROM_UTF8( buf ) );
             nc->Add( netname );
         }
-
         else if( TESTLINE( "Clearance" ) )
         {
             BIU tmp = biuParse( line + SZ( "Clearance" ) );
             nc->SetClearance( tmp );
         }
-
         else if( TESTLINE( "TrackWidth" ) )
         {
             BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
             nc->SetTrackWidth( tmp );
         }
-
         else if( TESTLINE( "ViaDia" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaDia" ) );
             nc->SetViaDiameter( tmp );
         }
-
         else if( TESTLINE( "ViaDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
             nc->SetViaDrill( tmp );
         }
-
         else if( TESTLINE( "uViaDia" ) )
         {
             BIU tmp = biuParse( line + SZ( "uViaDia" ) );
             nc->SetuViaDiameter( tmp );
         }
-
         else if( TESTLINE( "uViaDrill" ) )
         {
             BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
             nc->SetuViaDrill( tmp );
         }
-
         else if( TESTLINE( "Name" ) )
         {
             ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
             nc->SetName( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Desc" ) )
         {
             ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
             nc->SetDescription( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "$EndNCLASS" ) )
         {
             if( !m_board->GetDesignSettings().GetNetClasses().Add( nc ) )
@@ -2485,7 +2350,7 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
     char    buf[1024];
     char*   line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -2511,7 +2376,6 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
             // intParse( data )returns 0 = usual corner, 1 = last corner of the current contour:
             endContour = intParse( data );
         }
-
         else if( TESTLINE( "ZInfo" ) )      // general info found
         {
             // e.g. 'ZInfo 68183921-93a5-49ac-91b0-49d05a0e1647 310 "COMMON"'
@@ -2522,18 +2386,17 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
                 THROW_IO_ERROR( "ZInfo netname too long" );
 
             const_cast<KIID&>( zc->m_Uuid ) = KIID( uuid );
+
             // Init the net code only, not the netname, to be sure
             // the zone net name is the name read in file.
             // (When mismatch, the user will be prompted in DRC, to fix the actual name)
             zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) );
         }
-
         else if( TESTLINE( "ZLayer" ) )     // layer found
         {
             LAYER_NUM layer_num = layerParse( line + SZ( "ZLayer" ) );
             zc->SetLayer( leg_layer2new( m_cu_count,  layer_num ) );
         }
-
         else if( TESTLINE( "ZAux" ) )       // aux info found
         {
             // e.g. "ZAux 7 E"
@@ -2562,7 +2425,6 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
 
             // Set hatch mode later, after reading corner outline data
         }
-
         else if( TESTLINE( "ZSmoothing" ) )
         {
             // e.g. "ZSmoothing 0 0"
@@ -2579,7 +2441,6 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
             zc->SetCornerSmoothingType( smoothing );
             zc->SetCornerRadius( cornerRadius );
         }
-
         else if( TESTLINE( "ZKeepout" ) )
         {
             char* token;
@@ -2594,24 +2455,23 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
             {
                 if( !strcmp( token, "tracks" ) )
                 {
-                    token = strtok_r( NULL, delims, (char**) &data );
+                    token = strtok_r( nullptr, delims, (char**) &data );
                     zc->SetDoNotAllowTracks( token && *token == 'N' );
                 }
                 else if( !strcmp( token, "vias" ) )
                 {
-                    token = strtok_r( NULL, delims, (char**) &data );
+                    token = strtok_r( nullptr, delims, (char**) &data );
                     zc->SetDoNotAllowVias( token && *token == 'N' );
                 }
                 else if( !strcmp( token, "copperpour" ) )
                 {
-                    token = strtok_r( NULL, delims, (char**) &data );
+                    token = strtok_r( nullptr, delims, (char**) &data );
                     zc->SetDoNotAllowCopperPour( token && *token == 'N' );
                 }
 
-                token = strtok_r( NULL, delims, (char**) &data );
+                token = strtok_r( nullptr, delims, (char**) &data );
             }
         }
-
         else if( TESTLINE( "ZOptions" ) )
         {
             // e.g. "ZOptions 0 32 F 200 200"
@@ -2623,7 +2483,8 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
 
             if( fillmode)
             {
-                // SEGMENT fill mode no longer supported.  Make sure user is OK with converting them.
+                // SEGMENT fill mode no longer supported.  Make sure user is OK with converting
+                // them.
                 if( m_showLegacyZoneWarning )
                 {
                     KIDIALOG dlg( nullptr,
@@ -2645,13 +2506,14 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
                 m_board->SetModified();
             }
             else
+            {
                 zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
+            }
 
             zc->SetIsFilled( fillstate == 'S' );
             zc->SetThermalReliefGap( thermalReliefGap );
             zc->SetThermalReliefSpokeWidth( thermalReliefCopperBridge );
         }
-
         else if( TESTLINE( "ZClearance" ) )     // Clearance and pad options info found
         {
             // e.g. "ZClearance 40 I"
@@ -2674,19 +2536,16 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
             zc->SetLocalClearance( clearance );
             zc->SetPadConnection( popt );
         }
-
         else if( TESTLINE( "ZMinThickness" ) )
         {
             BIU thickness = biuParse( line + SZ( "ZMinThickness" ) );
             zc->SetMinThickness( thickness );
         }
-
         else if( TESTLINE( "ZPriority" ) )
         {
             int priority = intParse( line + SZ( "ZPriority" ) );
             zc->SetPriority( priority );
         }
-
         else if( TESTLINE( "$POLYSCORNERS" ) )
         {
             // Read the PolysList (polygons that are the solid areas in the filled zone)
@@ -2694,7 +2553,7 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
 
             bool makeNewOutline = true;
 
-            while( ( line = READLINE( m_reader ) ) != NULL )
+            while( ( line = READLINE( m_reader ) ) != nullptr )
             {
                 if( TESTLINE( "$endPOLYSCORNERS" ) )
                     break;
@@ -2708,7 +2567,8 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
 
                 polysList.Append( x, y );
 
-                bool end_contour = intParse( data, &data );  // end_countour was a bool when file saved, so '0' or '1' here
+                // end_countour was a bool when file saved, so '0' or '1' here
+                bool end_contour = intParse( data, &data );
                 intParse( data ); // skip corner utility flag
 
                 makeNewOutline = end_contour;
@@ -2716,10 +2576,9 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
 
             zc->SetFilledPolysList( zc->GetLayer(), polysList );
         }
-
         else if( TESTLINE( "$FILLSEGMENTS" ) )
         {
-            while( ( line = READLINE( m_reader ) ) != NULL )
+            while( ( line = READLINE( m_reader ) ) != nullptr )
             {
                 if( TESTLINE( "$endFILLSEGMENTS" ) )
                     break;
@@ -2734,7 +2593,6 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
                         .push_back( SEG( VECTOR2I( sx, sy ), VECTOR2I( ex, ey ) ) );
             }
         }
-
         else if( TESTLINE( "$endCZONE_OUTLINE" ) )
         {
             // Ensure keepout does not have a net
@@ -2774,7 +2632,7 @@ void LEGACY_PLUGIN::loadDIMENSION()
 
     char*   line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char*  data;
 
@@ -2783,14 +2641,13 @@ void LEGACY_PLUGIN::loadDIMENSION()
             m_board->Add( dim.release(), ADD_MODE::APPEND );
             return;     // preferred exit
         }
-
         else if( TESTLINE( "Va" ) )
         {
             BIU value = biuParse( line + SZ( "Va" ) );
+
             // unused; dimension value is calculated from coordinates
             ( void )value;
         }
-
         else if( TESTLINE( "Ge" ) )
         {
             // e.g. "Ge 1 21 68183921-93a5-49ac-91b0-49d05a0e1647\r\n"
@@ -2800,10 +2657,10 @@ void LEGACY_PLUGIN::loadDIMENSION()
 
             dim->SetLayer( leg_layer2new( m_cu_count,  layer_num ) );
             const_cast<KIID&>( dim->m_Uuid ) = KIID( uuid );
+
             // not used
             ( void )shape;
         }
-
         else if( TESTLINE( "Te" ) )
         {
             char  buf[2048];
@@ -2811,7 +2668,6 @@ void LEGACY_PLUGIN::loadDIMENSION()
             ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
             dim->SetText( FROM_UTF8( buf ) );
         }
-
         else if( TESTLINE( "Po" ) )
         {
             BIU     pos_x  = biuParse( line + SZ( "Po" ), &data );
@@ -2831,7 +2687,6 @@ void LEGACY_PLUGIN::loadDIMENSION()
             dim->Text().SetTextThickness( thickn );
             dim->Text().SetTextAngle( orient );
         }
-
         else if( TESTLINE( "Sb" ) )
         {
             int ignore     = biuParse( line + SZ( "Sb" ), &data );
@@ -2846,7 +2701,6 @@ void LEGACY_PLUGIN::loadDIMENSION()
                                wxPoint( crossBarOx, crossBarOy ) );
             (void) ignore;
         }
-
         else if( TESTLINE( "Sd" ) )
         {
             int ignore         = intParse( line + SZ( "Sd" ), &data );
@@ -2860,7 +2714,6 @@ void LEGACY_PLUGIN::loadDIMENSION()
             ( void )featureLineDFx;
             ( void )featureLineDFy;
         }
-
         else if( TESTLINE( "Sg" ) )
         {
             int ignore         = intParse( line + SZ( "Sg" ), &data );
@@ -2875,9 +2728,7 @@ void LEGACY_PLUGIN::loadDIMENSION()
             ( void )featureLineGFx;
             ( void )featureLineGFy;
         }
-
-        // Arrow: no longer imported
-        else if( TESTLINE( "S1" ) )
+        else if( TESTLINE( "S1" ) )        // Arrow: no longer imported
         {
             int ignore      = intParse( line + SZ( "S1" ), &data );
             biuParse( data, &data );    // skipping excessive data
@@ -2887,9 +2738,7 @@ void LEGACY_PLUGIN::loadDIMENSION()
 
             (void) ignore;
         }
-
-        // Arrow: no longer imported
-        else if( TESTLINE( "S2" ) )
+        else if( TESTLINE( "S2" ) )        // Arrow: no longer imported
         {
             int ignore    = intParse( line + SZ( "S2" ), &data );
             biuParse( data, &data );    // skipping excessive data
@@ -2899,9 +2748,7 @@ void LEGACY_PLUGIN::loadDIMENSION()
 
             (void) ignore;
         }
-
-        // Arrow: no longer imported
-        else if( TESTLINE( "S3" ) )
+        else if( TESTLINE( "S3" ) )        // Arrow: no longer imported
         {
             int ignore    = intParse( line + SZ( "S3" ), &data );
             biuParse( data, &data );    // skipping excessive data
@@ -2911,9 +2758,7 @@ void LEGACY_PLUGIN::loadDIMENSION()
 
             (void) ignore;
         }
-
-        // Arrow: no longer imported
-        else if( TESTLINE( "S4" ) )
+        else if( TESTLINE( "S4" ) )        // Arrow: no longer imported
         {
             int ignore    = intParse( line + SZ( "S4" ), &data );
             biuParse( data, &data );    // skipping excessive data
@@ -2933,7 +2778,7 @@ void LEGACY_PLUGIN::loadPCB_TARGET()
 {
     char* line;
 
-    while( ( line = READLINE( m_reader ) ) != NULL )
+    while( ( line = READLINE( m_reader ) ) != nullptr )
     {
         const char* data;
 
@@ -2941,7 +2786,6 @@ void LEGACY_PLUGIN::loadPCB_TARGET()
         {
             return;     // preferred exit
         }
-
         else if( TESTLINE( "Po" ) )
         {
             int       shape     = intParse( line + SZ( "Po" ), &data );
@@ -2954,7 +2798,6 @@ void LEGACY_PLUGIN::loadPCB_TARGET()
 
             if( layer_num < FIRST_NON_COPPER_LAYER )
                 layer_num = FIRST_NON_COPPER_LAYER;
-
             else if( layer_num > LAST_NON_COPPER_LAYER )
                 layer_num = LAST_NON_COPPER_LAYER;
 
@@ -3048,7 +2891,7 @@ void LEGACY_PLUGIN::init( const PROPERTIES* aProperties )
 {
     m_loading_format_version = 0;
     m_cu_count = 16;
-    m_board = NULL;
+    m_board = nullptr;
     m_showLegacyZoneWarning = true;
     m_props = aProperties;
 
@@ -3090,23 +2933,11 @@ typedef boost::ptr_map< std::string, FOOTPRINT >   FOOTPRINT_MAP;
 
 
 /**
- * LP_CACHE
- * assists only for the footprint portion of the PLUGIN API, and only for the
- * LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. not placed
- * into a header.
+ * The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is
+ * private to this implementation file, i.e. not placed into a header.
  */
 struct LP_CACHE
 {
-    LEGACY_PLUGIN*  m_owner;            // my owner, I need its LEGACY_PLUGIN::loadFOOTPRINT()
-    wxString        m_lib_path;
-    FOOTPRINT_MAP   m_footprints;       // map or tuple of footprint_name vs. FOOTPRINT*
-    bool            m_writable;
-
-    bool            m_cache_dirty;      // Stored separately because it's expensive to check
-                                        // m_cache_timestamp against all the files.
-    long long       m_cache_timestamp;  // A hash of the timestamps for all the footprint
-                                        // files.
-
     LP_CACHE( LEGACY_PLUGIN* aOwner, const wxString& aLibraryPath );
 
     // Most all functions in this class throw IO_ERROR exceptions.  There are no
@@ -3123,6 +2954,16 @@ struct LP_CACHE
 
     bool IsModified();
     static long long GetTimestamp( const wxString& aLibPath );
+
+    LEGACY_PLUGIN*  m_owner;            // my owner, I need its LEGACY_PLUGIN::loadFOOTPRINT()
+    wxString        m_lib_path;
+    FOOTPRINT_MAP   m_footprints;       // map or tuple of footprint_name vs. FOOTPRINT*
+    bool            m_writable;
+
+    bool            m_cache_dirty;      // Stored separately because it's expensive to check
+                                        // m_cache_timestamp against all the files.
+    long long       m_cache_timestamp;  // A hash of the timestamps for all the footprint
+                                        // files.
 };
 
 
@@ -3178,7 +3019,7 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
     if( !TESTLINE( "PCBNEW-LibModule-V1" ) )
         THROW_IO_ERROR( wxString::Format( _( "File '%s' is not a legacy library." ), m_lib_path ) );
 
-    while( ( line = aReader->ReadLine() ) != NULL )
+    while( ( line = aReader->ReadLine() ) != nullptr )
     {
         if( TESTLINE( "Units" ) )
         {
@@ -3189,7 +3030,9 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
 
         }
         else if( TESTLINE( "$INDEX" ) )
+        {
             return;
+        }
     }
 }
 
@@ -3208,7 +3051,7 @@ void LP_CACHE::SkipIndex( LINE_READER* aReader )
         {
             exit = false;
 
-            while( ( line = aReader->ReadLine() ) != NULL )
+            while( ( line = aReader->ReadLine() ) != nullptr )
             {
                 if( TESTLINE( "$EndINDEX" ) )
                 {
@@ -3218,8 +3061,10 @@ void LP_CACHE::SkipIndex( LINE_READER* aReader )
             }
         }
         else if( exit )
+        {
             break;
-    } while( ( line = aReader->ReadLine() ) != NULL );
+        }
+    } while( ( line = aReader->ReadLine() ) != nullptr );
 }
 
 
@@ -3251,7 +3096,6 @@ void LP_CACHE::LoadModules( LINE_READER* aReader )
 
             // Not sure why this is asserting on debug builds.  The debugger shows the
             // strings are the same.  If it's not really needed maybe it can be removed.
-//            wxASSERT( footprintName == m->GetFPID().GetLibItemName() );
 
             /*
 
@@ -3275,11 +3119,10 @@ void LP_CACHE::LoadModules( LINE_READER* aReader )
                     wxFAIL_MSG( "error doing cache insert using guaranteed unique name" );
                 }
             }
-
-            // Bad library has a duplicate of this footprintName, generate a
-            // unique footprint name and load it anyway.
             else
             {
+                // Bad library has a duplicate of this footprintName, generate a
+                // unique footprint name and load it anyway.
                 bool    nameOK = false;
                 int     version = 2;
                 char    buf[48];
@@ -3309,7 +3152,7 @@ void LP_CACHE::LoadModules( LINE_READER* aReader )
             }
         }
 
-    } while( ( line = aReader->ReadLine() ) != NULL );
+    } while( ( line = aReader->ReadLine() ) != nullptr );
 }
 
 
@@ -3360,8 +3203,7 @@ void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wx
 
 
 FOOTPRINT* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
-                                         const wxString& aFootprintName,
-                                         bool aKeepUUID,
+                                         const wxString& aFootprintName, bool aKeepUUID,
                                          const PROPERTIES* aProperties )
 {
     LOCALE_IO   toggle;     // toggles on, then off, the C locale.
@@ -3375,12 +3217,7 @@ FOOTPRINT* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
 
     if( it == footprints.end() )
     {
-        /*
-        THROW_IO_ERROR( wxString::Format( _( "No \"%s\" footprint in library \"%s\"" ),
-            aFootprintName.GetData(), aLibraryPath.GetData() ) );
-        */
-
-        return NULL;
+        return nullptr;
     }
 
     // Return copy of already loaded FOOTPRINT
@@ -3423,7 +3260,7 @@ bool LEGACY_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
 #else
     LOCALE_IO   toggle;
 
-    init( NULL );
+    init( nullptr );
 
     cacheLib( aLibraryPath );
 
@@ -3443,7 +3280,7 @@ LEGACY_PLUGIN::LEGACY_PLUGIN() :
     m_fp( nullptr ),
     m_cache( nullptr )
 {
-    init( NULL );
+    init( nullptr );
 }
 
 
diff --git a/pcbnew/plugins/pcad/pcad2kicad_common.cpp b/pcbnew/plugins/pcad/pcad2kicad_common.cpp
index 780b8fa47a..a86c694dac 100644
--- a/pcbnew/plugins/pcad/pcad2kicad_common.cpp
+++ b/pcbnew/plugins/pcad/pcad2kicad_common.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
  * Copyright (C) 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,9 +41,11 @@ namespace PCAD2KICAD {
 
 // PCAD stroke font average ratio of width to size
 const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.5;
+
 // PCAD proportions of stroke font
 const double STROKE_HEIGHT_TO_SIZE = 0.656;
 const double STROKE_WIDTH_TO_SIZE = 0.69;
+
 // TrueType font
 const double TRUETYPE_HEIGHT_TO_SIZE = 0.585;
 const double TRUETYPE_WIDTH_TO_SIZE = 0.585;
@@ -51,6 +53,7 @@ const double TRUETYPE_THICK_PER_HEIGHT = 0.073;
 const double TRUETYPE_BOLD_THICK_MUL = 1.6;
 const long TRUETYPE_BOLD_MIN_WEIGHT = 700;
 
+
 wxString GetWord( wxString* aStr )
 {
     wxString result = wxEmptyString;
@@ -100,7 +103,7 @@ XNODE* FindPinMap( XNODE* aNode )
 {
     XNODE* result, * lNode;
 
-    result  = NULL;
+    result  = nullptr;
     lNode   = FindNode( aNode, wxT( "attachedPattern" ) );
 
     if( lNode )
@@ -110,7 +113,8 @@ XNODE* FindPinMap( XNODE* aNode )
 }
 
 
-double StrToDoublePrecisionUnits( const wxString& aStr, char aAxe, const wxString& aActualConversion )
+double StrToDoublePrecisionUnits( const wxString& aStr, char aAxe,
+                                  const wxString& aActualConversion )
 {
     wxString    ls;
     double      i;
@@ -145,11 +149,13 @@ double StrToDoublePrecisionUnits( const wxString& aStr, char aAxe, const wxStrin
         if( u == wxT( 'm' ) )
         {
             ls.ToCDouble( &i );
+
 #ifdef PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
             if( aActualConversion == wxT( "SCH" )
                 || aActualConversion == wxT( "SCHLIB" ) )
                 i = i * (0.0254 / 0.025);
 #endif
+
             i = Millimeter2iu( i );
         }
         else
@@ -159,7 +165,9 @@ double StrToDoublePrecisionUnits( const wxString& aStr, char aAxe, const wxStrin
         }
     }
     else
+    {
         i = 0.0;
+    }
 
     if( ( aActualConversion == wxT( "PCB" ) || aActualConversion == wxT( "SCH" ) )
         && aAxe == wxT( 'Y' ) )
@@ -243,55 +251,41 @@ wxString ValidateReference( wxString aRef )
 }
 
 
-void SetWidth( wxString        aStr,
-               const wxString& aDefaultMeasurementUnit,
-               int*            aWidth,
+void SetWidth( wxString aStr, const wxString& aDefaultMeasurementUnit, int* aWidth,
                const wxString& aActualConversion )
 {
-    *aWidth = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                            aDefaultMeasurementUnit ), wxT( ' ' ),
-                             aActualConversion );
+    *aWidth = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ),
+                             wxT( ' ' ), aActualConversion );
 }
 
 
-void SetHeight( wxString        aStr,
-                const wxString& aDefaultMeasurementUnit,
-                int*            aHeight,
+void SetHeight( wxString aStr, const wxString& aDefaultMeasurementUnit, int* aHeight,
                 const wxString& aActualConversion )
 {
-    *aHeight = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                             aDefaultMeasurementUnit ), wxT( ' ' ),
-                              aActualConversion );
+    *aHeight = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ),
+                              wxT( ' ' ), aActualConversion );
 }
 
 
-void SetPosition( wxString        aStr,
-                  const wxString& aDefaultMeasurementUnit,
-                  int*            aX,
-                  int*            aY,
+void SetPosition( wxString aStr, const wxString& aDefaultMeasurementUnit, int* aX, int* aY,
                   const wxString& aActualConversion )
 {
-    *aX = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                        aDefaultMeasurementUnit ), wxT( 'X' ),
-                         aActualConversion );
-    *aY = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                        aDefaultMeasurementUnit ), wxT( 'Y' ),
-                         aActualConversion );
+    *aX = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ),
+                         wxT( 'X' ), aActualConversion );
+    *aY = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ),
+                         wxT( 'Y' ), aActualConversion );
 }
 
 
-void SetDoublePrecisionPosition( wxString        aStr,
-                                 const wxString& aDefaultMeasurementUnit,
-                                 double*         aX,
-                                 double*         aY,
-                                 const wxString& aActualConversion )
+void SetDoublePrecisionPosition( wxString aStr, const wxString& aDefaultMeasurementUnit, double* aX,
+                                 double* aY, const wxString& aActualConversion )
 {
-    *aX = StrToDoublePrecisionUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                                    aDefaultMeasurementUnit ), wxT( 'X' ),
-                                     aActualConversion );
-    *aY = StrToDoublePrecisionUnits( GetAndCutWordWithMeasureUnits( &aStr,
-                                                                    aDefaultMeasurementUnit ), wxT( 'Y' ),
-                                     aActualConversion );
+    *aX = StrToDoublePrecisionUnits(
+            GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ), wxT( 'X' ),
+            aActualConversion );
+    *aY = StrToDoublePrecisionUnits(
+            GetAndCutWordWithMeasureUnits( &aStr, aDefaultMeasurementUnit ), wxT( 'Y' ),
+            aActualConversion );
 }
 
 
@@ -322,22 +316,17 @@ TTEXT_JUSTIFY GetJustifyIdentificator( const wxString& aJustify )
 }
 
 
-void SetTextParameters( XNODE*          aNode,
-                        TTEXTVALUE*     aTextValue,
-                        const wxString& aDefaultMeasurementUnit,
-                        const wxString& aActualConversion )
+void SetTextParameters( XNODE* aNode, TTEXTVALUE* aTextValue,
+                        const wxString& aDefaultMeasurementUnit, const wxString& aActualConversion )
 {
-    XNODE*      tNode;
-    wxString    str;
+    XNODE*   tNode;
+    wxString str;
 
     tNode = FindNode( aNode, wxT( "pt" ) );
 
     if( tNode )
-        SetPosition( tNode->GetNodeContent(),
-                     aDefaultMeasurementUnit,
-                     &aTextValue->textPositionX,
-                     &aTextValue->textPositionY,
-                     aActualConversion );
+        SetPosition( tNode->GetNodeContent(), aDefaultMeasurementUnit, &aTextValue->textPositionX,
+                     &aTextValue->textPositionY, aActualConversion );
 
     tNode = FindNode( aNode, wxT( "rotation" ) );
 
@@ -376,9 +365,7 @@ void SetTextParameters( XNODE*          aNode,
 }
 
 
-void SetFontProperty( XNODE*          aNode,
-                      TTEXTVALUE*     aTextValue,
-                      const wxString& aDefaultMeasurementUnit,
+void SetFontProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aDefaultMeasurementUnit,
                       const wxString& aActualConversion )
 {
     wxString n, propValue;
@@ -389,6 +376,7 @@ void SetFontProperty( XNODE*          aNode,
         aNode = aNode->GetParent();
 
     aNode = FindNode( aNode, wxT( "library" ) );
+
     if( aNode )
         aNode = FindNode( aNode, wxT( "textStyleDef" ) );
 
@@ -413,6 +401,7 @@ void SetFontProperty( XNODE*          aNode,
 
         aNode = FindNode( aNode, wxT( "font" ) );
         fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
+
         if( ( aTextValue->isTrueType && ( fontType != wxT( "TrueType" ) ) ) ||
             ( !aTextValue->isTrueType && ( fontType != wxT( "Stroke" ) ) ) )
             aNode = aNode->GetNext();
@@ -425,6 +414,7 @@ void SetFontProperty( XNODE*          aNode,
                 aTextValue->isItalic = ( propValue == wxT( "True" ) );
 
                 propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) );
+
                 if( propValue != wxEmptyString )
                 {
                     long fontWeight;
@@ -437,6 +427,7 @@ void SetFontProperty( XNODE*          aNode,
             XNODE* lNode;
 
             lNode = FindNode( aNode, wxT( "fontHeight" ) );
+
             if( lNode )
                 SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit,
                            &aTextValue->textHeight, aActualConversion );
@@ -444,12 +435,14 @@ void SetFontProperty( XNODE*          aNode,
             if( aTextValue->isTrueType )
             {
                 aTextValue->textstrokeWidth = TRUETYPE_THICK_PER_HEIGHT * aTextValue->textHeight;
+
                 if( aTextValue->isBold )
                     aTextValue->textstrokeWidth *= TRUETYPE_BOLD_THICK_MUL;
             }
             else
             {
                 lNode = FindNode( aNode, wxT( "strokeWidth" ) );
+
                 if( lNode )
                     SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit,
                               &aTextValue->textstrokeWidth, aActualConversion );
@@ -518,21 +511,16 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
     int posX = 0;
     int posY = 0;
 
-    if( aValue->justify == LowerLeft ||
-        aValue->justify == Left ||
-        aValue->justify == UpperLeft )
+    if( aValue->justify == LowerLeft || aValue->justify == Left || aValue->justify == UpperLeft )
         posX += cl * cm;
-    else if( aValue->justify == LowerRight ||
-             aValue->justify == Right ||
+    else if( aValue->justify == LowerRight || aValue->justify == Right ||
              aValue->justify == UpperRight )
         posX -= cl * cm;
 
-    if( aValue->justify == LowerLeft ||
-        aValue->justify == LowerCenter ||
+    if( aValue->justify == LowerLeft || aValue->justify == LowerCenter ||
         aValue->justify == LowerRight )
         posY -= ch;
-    else if( aValue->justify == UpperLeft ||
-             aValue->justify == UpperCenter ||
+    else if( aValue->justify == UpperLeft || aValue->justify == UpperCenter ||
              aValue->justify == UpperRight )
         posY += ch;
 
@@ -569,9 +557,10 @@ XNODE* FindNode( XNODE* aChild, const wxString& aTag )
         aChild = aChild->GetNext();
     }
 
-    return NULL;
+    return nullptr;
 }
 
+
 wxString FindNodeGetContent( XNODE* aChild, const wxString& aTag )
 {
     wxString str = wxEmptyString;
@@ -588,6 +577,7 @@ wxString FindNodeGetContent( XNODE* aChild, const wxString& aTag )
     return str;
 }
 
+
 void InitTTextValue( TTEXTVALUE* aTextValue )
 {
     aTextValue->text = wxEmptyString;
diff --git a/pcbnew/plugins/pcad/pcad_plugin.cpp b/pcbnew/plugins/pcad/pcad_plugin.cpp
index b87a3ee2ad..c9d5dede22 100644
--- a/pcbnew/plugins/pcad/pcad_plugin.cpp
+++ b/pcbnew/plugins/pcad/pcad_plugin.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,10 +41,11 @@
 
 using namespace PCAD2KICAD;
 
+
 PCAD_PLUGIN::PCAD_PLUGIN()
 {
-    m_board = NULL;
-    m_props = NULL;
+    m_board = nullptr;
+    m_props = nullptr;
 }
 
 
@@ -84,7 +85,7 @@ BOARD* PCAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
     LOCALE_IO toggle;    // toggles on, then off, the C locale.
 
     LoadInputFile( aFileName, &xmlDoc );
-    pcb.ParseBoard( NULL, &xmlDoc, wxT( "PCB" ) );
+    pcb.ParseBoard( nullptr, &xmlDoc, wxT( "PCB" ) );
     pcb.AddToBoard();
 
     return m_board;
diff --git a/pcbnew/plugins/pcad/pcb.cpp b/pcbnew/plugins/pcad/pcb.cpp
index 6657bb833f..a03da78613 100644
--- a/pcbnew/plugins/pcad/pcb.cpp
+++ b/pcbnew/plugins/pcad/pcb.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -42,6 +42,7 @@
 
 namespace PCAD2KICAD {
 
+
 PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer ) const
 {
     auto it = m_LayersMap.find( aPCadLayer );
@@ -52,6 +53,7 @@ PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer ) const
     return it->second.KiCadLayer;
 }
 
+
 LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer ) const
 {
     auto it = m_LayersMap.find( aPCadLayer );
@@ -62,6 +64,7 @@ LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer ) const
     return it->second.layerType;
 }
 
+
 wxString PCB::GetLayerNetNameRef( int aPCadLayer ) const
 {
     auto it = m_LayersMap.find( aPCadLayer );
@@ -72,6 +75,7 @@ wxString PCB::GetLayerNetNameRef( int aPCadLayer ) const
     return it->second.netNameRef;
 }
 
+
 PCB::PCB( BOARD* aBoard ) :
         PCB_FOOTPRINT( this, aBoard )
 {
@@ -137,7 +141,7 @@ int PCB::GetNetCode( const wxString& aNetName ) const
 
 XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const
 {
-    XNODE*      result = NULL, * lNode;
+    XNODE*      result = nullptr, * lNode;
     wxString    propValue;
 
     lNode = FindNode( aNode, wxT( "compDef" ) );
@@ -151,7 +155,7 @@ XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const
             if( propValue == aName )
             {
                 result  = lNode;
-                lNode   = NULL;
+                lNode   = nullptr;
             }
         }
 
@@ -163,10 +167,8 @@ XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const
 }
 
 
-void PCB::SetTextProperty( XNODE*   aNode, TTEXTVALUE* aTextValue,
-                           const wxString& aPatGraphRefName,
-                           const wxString& aXmlName,
-                           const wxString& aActualConversion )
+void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aPatGraphRefName,
+                           const wxString& aXmlName, const wxString& aActualConversion )
 {
     XNODE*      tNode, * t1Node;
     wxString    n, nnew, pn, propValue, str;
@@ -204,7 +206,7 @@ void PCB::SetTextProperty( XNODE*   aNode, TTEXTVALUE* aTextValue,
                         str.Trim( true );
                         nnew    = n; // new file version
                         n       = n + wxT( ' ' ) + str; // old file version
-                        tNode   = NULL;
+                        tNode   = nullptr;
                     }
                 }
             }
@@ -234,10 +236,8 @@ void PCB::SetTextProperty( XNODE*   aNode, TTEXTVALUE* aTextValue,
 }
 
 
-void PCB::DoPCBComponents( XNODE*           aNode,
-                           wxXmlDocument*   aXmlDoc,
-                           const wxString&  aActualConversion,
-                           wxStatusBar*     aStatusBar )
+void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& aActualConversion,
+                           wxStatusBar* aStatusBar )
 {
     XNODE*         lNode, * tNode, * mNode;
     PCB_FOOTPRINT* fp;
@@ -250,7 +250,7 @@ void PCB::DoPCBComponents( XNODE*           aNode,
 
     while( lNode )
     {
-        fp = NULL;
+        fp = nullptr;
 
         if( lNode->GetName() == wxT( "pattern" ) )
         {
@@ -268,6 +268,7 @@ void PCB::DoPCBComponents( XNODE*           aNode,
                     fp = new PCB_FOOTPRINT( this, m_board );
 
                     mNode = FindNode( lNode, wxT( "patternGraphicsNameRef" ) );
+
                     if( mNode )
                         mNode->GetAttribute( wxT( "Name" ), &fp->m_patGraphRefName );
 
@@ -346,10 +347,12 @@ void PCB::DoPCBComponents( XNODE*           aNode,
                                 fp->m_compRef.Trim( true );
                             }
 
-                            tNode = NULL;
+                            tNode = nullptr;
                         }
                         else
+                        {
                             tNode = tNode->GetNext();
+                        }
                     }
                 }
 
@@ -462,24 +465,6 @@ int PCB::FindLayer( const wxString& aLayerName ) const
 }
 
 
-/* KiCad layers
- *  0 Copper layer
- *  1 to 14   Inner layers
- *  15 Component layer
- *  16 Copper side adhesive layer    Technical layers
- *  17 Component side adhesive layer
- *  18 Copper side Solder paste layer
- *  19 Component Solder paste layer
- *  20 Copper side Silk screen layer
- *  21 Component Silk screen layer
- *  22 Copper side Solder mask layer
- *  23 Component Solder mask layer
- *  24 Draw layer (Used for general drawings)
- *  25 Comment layer (Other layer used for general drawings)
- *  26 ECO1 layer (Other layer used for general drawings)       // BUG
- *  26 ECO2 layer (Other layer used for general drawings)       // BUG      27
- *  27 Edge layer. Items on Edge layer are seen on all layers   // BUG     28
- */
 void PCB::MapLayer( XNODE* aNode )
 {
     wxString     lName, layerType;
@@ -490,27 +475,49 @@ void PCB::MapLayer( XNODE* aNode )
     lName = lName.MakeUpper();
 
     if( lName == wxT( "TOP ASSY" ) )
+    {
         KiCadLayer = F_Fab;
+    }
     else if( lName == wxT( "TOP SILK" ) )
+    {
         KiCadLayer = F_SilkS;
+    }
     else if( lName == wxT( "TOP PASTE" ) )
+    {
         KiCadLayer = F_Paste;
+    }
     else if( lName == wxT( "TOP MASK" ) )
+    {
         KiCadLayer = F_Mask;
+    }
     else if( lName == wxT( "TOP" ) )
+    {
         KiCadLayer = F_Cu;
+    }
     else if( lName == wxT( "BOTTOM" ) )
+    {
         KiCadLayer = B_Cu;
+    }
     else if( lName == wxT( "BOT MASK" ) )
+    {
         KiCadLayer = B_Mask;
+    }
     else if( lName == wxT( "BOT PASTE" ) )
+    {
         KiCadLayer = B_Paste;
+    }
     else if( lName == wxT( "BOT SILK" ) )
+    {
         KiCadLayer = B_SilkS;
+    }
     else if( lName == wxT( "BOT ASSY" ) )
+    {
         KiCadLayer = B_Fab;
+    }
     else if( lName == wxT( "BOARD" ) )
+    {
         KiCadLayer = Edge_Cuts;
+    }
     else
     {
         int layernum = FindLayer( lName );
@@ -540,8 +547,10 @@ void PCB::MapLayer( XNODE* aNode )
 
         if( layerType == wxT( "NonSignal" ) )
             newlayer.layerType = LAYER_TYPE_NONSIGNAL;
+
         if( layerType == wxT( "Signal" ) )
             newlayer.layerType = LAYER_TYPE_SIGNAL;
+
         if( layerType == wxT( "Plane" ) )
             newlayer.layerType = LAYER_TYPE_PLANE;
     }
@@ -560,12 +569,15 @@ int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint )
     int i;
 
     for( i = 0; i < (int) aOutline->GetCount(); i++ )
+    {
         if( *((*aOutline)[i]) == aPoint )
             return i;
+    }
 
     return -1;
 }
 
+
 /*int cmpFunc( wxRealPoint **first, wxRealPoint **second )
 {
     return sqrt( pow( (double) aPointA.x - (double) aPointB.x, 2 ) +
@@ -573,12 +585,12 @@ int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint )
 
     return 0;
 }*/
+
+
 double PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const
 {
-    return sqrt(  ( aPoint1->x - aPoint2->x ) *
-                  ( aPoint1->x - aPoint2->x ) +
-                  ( aPoint1->y - aPoint2->y ) *
-                  ( aPoint1->y - aPoint2->y ) );
+    return sqrt(  ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) +
+                  ( aPoint1->y - aPoint2->y ) * ( aPoint1->y - aPoint2->y ) );
 }
 
 void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConversion )
@@ -607,6 +619,7 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver
                 if( GetKiCadLayer( PCadLayer ) == Edge_Cuts )
                 {
                     lNode = iNode->GetChildren();
+
                     while( lNode )
                     {
                         if( lNode->GetName() == wxT( "line" ) )
@@ -650,6 +663,7 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver
                             for( j = i + 2; j < (int) m_BoardOutline.GetCount(); j++ )
                             {
                                 distance = GetDistance( m_BoardOutline[i], m_BoardOutline[j] );
+
                                 if( distance < minDistance )
                                 {
                                     minDistance = distance;
@@ -672,7 +686,9 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver
     }
 }
 
-void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, const wxString& aActualConversion )
+
+void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
+                      const wxString& aActualConversion )
 {
     XNODE*          aNode;//, *aaNode;
     PCB_NET*        net;
@@ -811,7 +827,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, const wxS
 
             // objects
             if( aNode->GetName() == wxT( "layerContents" ) )
-                DoLayerContentsObjects( aNode, NULL, &m_PcbComponents, aStatusBar,
+                DoLayerContentsObjects( aNode, nullptr, &m_PcbComponents, aStatusBar,
                                         m_DefaultMeasurementUnit, aActualConversion );
 
             aNode = aNode->GetNext();
diff --git a/pcbnew/plugins/pcad/pcb_footprint.cpp b/pcbnew/plugins/pcad/pcb_footprint.cpp
index 5f1c90767f..63564c1f9e 100644
--- a/pcbnew/plugins/pcad/pcb_footprint.cpp
+++ b/pcbnew/plugins/pcad/pcb_footprint.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -44,6 +44,7 @@
 
 namespace PCAD2KICAD {
 
+
 PCB_FOOTPRINT::PCB_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
         PCB_COMPONENT( aCallbacks, aBoard )
 {
@@ -70,7 +71,7 @@ XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aN
     XNODE*      result, * lNode;
     wxString    propValue1, propValue2;
 
-    result  = NULL;
+    result  = nullptr;
     lNode   = FindNode( aNode, wxT( "patternDef" ) );
 
     while( lNode )
@@ -81,11 +82,10 @@ XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aN
             FindNode( lNode,
                       wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue2 );
 
-            if( ValidateName( propValue1 ) == aName
-                || ValidateName( propValue2 ) == aName )
+            if( ValidateName( propValue1 ) == aName || ValidateName( propValue2 ) == aName )
             {
                 result  = lNode;
-                lNode   = NULL;
+                lNode   = nullptr;
             }
         }
 
@@ -93,7 +93,7 @@ XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aN
             lNode = lNode->GetNext();
     }
 
-    if( result == NULL )
+    if( result == nullptr )
     {
         lNode = FindNode( aNode, wxT( "patternDefExtended" ) );  // New file format
 
@@ -106,7 +106,7 @@ XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aN
                 if( ValidateName( propValue1 ) == aName )
                 {
                     result  = lNode;
-                    lNode   = NULL;
+                    lNode   = nullptr;
                 }
             }
 
@@ -124,7 +124,7 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat
     XNODE*      result, * pNode, * lNode;
     wxString    propValue, patName;
 
-    result  = NULL;
+    result  = nullptr;
     pNode   = aNode; // pattern;
     lNode   = aNode;
 
@@ -148,7 +148,7 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat
         pNode   = lNode; // pattern;
     }
 
-    lNode = NULL;
+    lNode = nullptr;
 
     if( pNode )
         lNode = FindNode( pNode, wxT( "multiLayer" ) );  // Old file format
@@ -182,7 +182,7 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat
             if( lNode )
             {
                 result  = FindNode( lNode, wxT( "multiLayer" ) );
-                lNode   = NULL;
+                lNode   = nullptr;
             }
         }
 
@@ -197,13 +197,17 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat
                 if( propValue == *aPatGraphRefName )
                 {
                     result  = FindNode( lNode, wxT( "multiLayer" ) );
-                    lNode   = NULL;
+                    lNode   = nullptr;
                 }
                 else
+                {
                     lNode = lNode->GetNext();
+                }
             }
             else
+            {
                 lNode = lNode->GetNext();
+            }
         }
     }
 
@@ -211,16 +215,14 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat
 }
 
 
-void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE*                 aNode,
-                                            PCB_FOOTPRINT*            aFootprint,
-                                            PCB_COMPONENTS_ARRAY*  aList,
-                                            wxStatusBar*           aStatusBar,
-                                            const wxString&        aDefaultMeasurementUnit,
-                                            const wxString&        aActualConversion )
+void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootprint,
+                                            PCB_COMPONENTS_ARRAY* aList, wxStatusBar* aStatusBar,
+                                            const wxString& aDefaultMeasurementUnit,
+                                            const wxString& aActualConversion )
 {
     PCB_ARC*            arc;
     PCB_POLYGON*        polygon;
-    PCB_POLYGON         *plane_layer = NULL;
+    PCB_POLYGON         *plane_layer = nullptr;
     PCB_COPPER_POUR*    copperPour;
     PCB_CUTOUT*         cutout;
     PCB_PLANE*          plane;
@@ -234,6 +236,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE*                 aNode,
     long                num = 0;
 
     i = 0;
+
     // aStatusBar->SetStatusText( wxT( "Processing LAYER CONTENT OBJECTS " ) );
     if( FindNode( aNode, wxT( "layerNumRef" ) ) )
         FindNode( aNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &num );
@@ -294,9 +297,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE*                 aNode,
                     // function CreatePCBModule(). However it is not clear whether the access is
                     // required when the function DoLayerContentsObjects() is called from
                     // function ProcessXMLtoPCBLib().
-                    SetFontProperty( tNode,
-                                     &aFootprint->m_name,
-                                     aDefaultMeasurementUnit,
+                    SetFontProperty( tNode, &aFootprint->m_name, aDefaultMeasurementUnit,
                                      aActualConversion );
                 }
             }
@@ -316,15 +317,15 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE*                 aNode,
             {
                 plane_layer_polygon = new VERTICES_ARRAY;
                 wxASSERT( plane_layer );
-                plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit, aActualConversion );
+                plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit,
+                                          aActualConversion );
                 plane_layer->m_cutouts.Add( plane_layer_polygon );
             }
             else
             {
                 polygon = new PCB_POLYGON( m_callbacks, m_board, PCadLayer );
-                if( polygon->Parse( lNode,
-                                    aDefaultMeasurementUnit,
-                                    aActualConversion ) )
+
+                if( polygon->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
                     aList->Add( polygon );
                 else
                     delete polygon;
@@ -376,15 +377,15 @@ void PCB_FOOTPRINT::SetName( const wxString& aPin, const wxString& aName )
     for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
     {
         if( m_FootprintItems[i]->m_objType == wxT( 'P' ) )
-            if(( (PCB_PAD*) m_FootprintItems[i] )->m_Number == num )
+        {
+            if( ( (PCB_PAD*) m_FootprintItems[i] )->m_Number == num )
                 ( (PCB_PAD*) m_FootprintItems[i] )->m_name.text = aName;
-
-
+        }
     }
 }
 
 
-void PCB_FOOTPRINT::Parse( XNODE*   aNode, wxStatusBar* aStatusBar,
+void PCB_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar,
                            const wxString& aDefaultMeasurementUnit,
                            const wxString& aActualConversion )
 {
@@ -393,8 +394,7 @@ void PCB_FOOTPRINT::Parse( XNODE*   aNode, wxStatusBar* aStatusBar,
     PCB_VIA*    via;
     wxString    propValue, str;
 
-    FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ),
-                                                            &propValue );
+    FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue );
     propValue.Trim( false );
     m_name.text = propValue;
 
@@ -524,6 +524,7 @@ void PCB_FOOTPRINT::AddToBoard()
     ref_text->SetType( FP_TEXT::TEXT_is_REFERENCE );
 
     ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) );
+
     if( m_name.isTrueType )
         SetTextSizeFromTrueTypeFontHeight( ref_text, m_name.textHeight );
     else
@@ -551,6 +552,7 @@ void PCB_FOOTPRINT::AddToBoard()
     val_text->SetType( FP_TEXT::TEXT_is_VALUE );
 
     val_text->SetPos0( wxPoint( m_Value.correctedPositionX, m_Value.correctedPositionY ) );
+
     if( m_Value.isTrueType )
         SetTextSizeFromTrueTypeFontHeight( val_text, m_Value.textHeight );
     else
diff --git a/pcbnew/plugins/pcad/pcb_pad.cpp b/pcbnew/plugins/pcad/pcb_pad.cpp
index 049314a2a2..7076f540b1 100644
--- a/pcbnew/plugins/pcad/pcb_pad.cpp
+++ b/pcbnew/plugins/pcad/pcb_pad.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -38,6 +38,7 @@
 
 namespace PCAD2KICAD {
 
+
 PCB_PAD::PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
         PCB_COMPONENT( aCallbacks, aBoard )
 {
@@ -118,6 +119,7 @@ void PCB_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits,
     if( lNode )
     {
         lNode->GetAttribute( wxT( "Name" ), &propValue );
+
         //propValue.Trim( false );
         m_defaultPinDes = propValue;
     }
@@ -245,6 +247,7 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, int aRotation, bool aEncaps
                         pad->SetLayerSet( LSET( 3, F_Cu, F_Paste, F_Mask ) );
                     else
                         pad->SetLayerSet( LSET( 3, B_Cu, B_Paste, B_Mask ) );
+
                     break;
                 }
             }
@@ -272,11 +275,17 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, int aRotation, bool aEncaps
                 pad->SetShape( PAD_SHAPE::CIRCLE );
         }
         else if( padShapeName == wxT( "Rect" ) )
+        {
             pad->SetShape( PAD_SHAPE::RECT );
+        }
         else if(  padShapeName == wxT( "RndRect" ) )
+        {
             pad->SetShape( PAD_SHAPE::ROUNDRECT );
+        }
         else if( padShapeName == wxT( "Polygon" ) )
+        {
             pad->SetShape( PAD_SHAPE::RECT ); // approximation
+        }
 
         pad->SetSize( wxSize( width, height ) );
         pad->SetDelta( wxSize( 0, 0 ) );
@@ -291,7 +300,7 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, int aRotation, bool aEncaps
         // Set the proper net code
         NETINFO_ITEM* netinfo = m_board->FindNet( m_net );
 
-        if( netinfo == NULL )   // I believe this should not happen, but just in case
+        if( netinfo == nullptr )   // I believe this should not happen, but just in case
         {
             // It is a new net
             netinfo = new NETINFO_ITEM( m_board, m_net );
diff --git a/pcbnew/plugins/pcad/s_expr_loader.cpp b/pcbnew/plugins/pcad/s_expr_loader.cpp
index c6ca560f33..3edffbb0de 100644
--- a/pcbnew/plugins/pcad/s_expr_loader.cpp
+++ b/pcbnew/plugins/pcad/s_expr_loader.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
- * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,11 +36,12 @@ namespace PCAD2KICAD {
 static KEYWORD empty_keywords[1] = {};
 static const char ACCEL_ASCII_KEYWORD[] = "ACCEL_ASCII";
 
-void LoadInputFile( const wxString& aFileName, wxXmlDocument* aXmlDoc )
+
+    void LoadInputFile( const wxString& aFileName, wxXmlDocument* aXmlDoc )
 {
     char      line[sizeof( ACCEL_ASCII_KEYWORD )];
     int       tok;
-    XNODE*    iNode = NULL, *cNode = NULL;
+    XNODE*    iNode = nullptr, *cNode = nullptr;
     wxString  str, propValue, content;
     wxCSConv  conv( wxT( "windows-1251" ) );
 
@@ -80,6 +81,7 @@ void LoadInputFile( const wxString& aFileName, wxXmlDocument* aXmlDoc )
         else if( cNode )
         {
             str = wxString( lexer.CurText(), conv );
+
             if( tok == DSN_STRING )
             {
                 // update attribute
@@ -89,7 +91,9 @@ void LoadInputFile( const wxString& aFileName, wxXmlDocument* aXmlDoc )
                     iNode->AddAttribute( wxT( "Name" ), propValue + wxT( ' ' ) + str );
                 }
                 else
+                {
                     iNode->AddAttribute( wxT( "Name" ), str );
+                }
             }
             else if( str != wxEmptyString )
             {
@@ -99,9 +103,7 @@ void LoadInputFile( const wxString& aFileName, wxXmlDocument* aXmlDoc )
                 if( cNode->GetChildren() )
                     cNode->GetChildren()->SetContent( content );
                 else
-                    cNode->AddChild( new wxXmlNode( wxXML_TEXT_NODE,
-                                                    wxEmptyString,
-                                                    content ) );
+                    cNode->AddChild( new wxXmlNode( wxXML_TEXT_NODE, wxEmptyString, content ) );
             }
         }
     }
diff --git a/pcbnew/python/scripting/pcbnew_action_plugins.cpp b/pcbnew/python/scripting/pcbnew_action_plugins.cpp
index 2987d534f4..8b513b54b4 100644
--- a/pcbnew/python/scripting/pcbnew_action_plugins.cpp
+++ b/pcbnew/python/scripting/pcbnew_action_plugins.cpp
@@ -57,6 +57,7 @@ PyObject* PYTHON_ACTION_PLUGIN::CallMethod( const char* aMethod, PyObject* aArgl
     PyLOCK lock;
 
     PyErr_Clear();
+
     // pFunc is a new reference to the desired method
     PyObject* pFunc = PyObject_GetAttrString( m_PyAction, aMethod );
 
@@ -67,8 +68,8 @@ PyObject* PYTHON_ACTION_PLUGIN::CallMethod( const char* aMethod, PyObject* aArgl
         if( PyErr_Occurred() )
         {
             wxMessageBox( PyErrStringWithTraceback(),
-                    _( "Exception on python action plugin code" ),
-                    wxICON_ERROR | wxOK );
+                          _( "Exception on python action plugin code" ),
+                          wxICON_ERROR | wxOK );
         }
 
         if( result )
@@ -88,7 +89,7 @@ PyObject* PYTHON_ACTION_PLUGIN::CallMethod( const char* aMethod, PyObject* aArgl
         Py_XDECREF( pFunc );
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -258,7 +259,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
     ACTION_PLUGINS::SetActionRunning( false );
 
     // Get back the undo buffer to fix some modifications
-    PICKED_ITEMS_LIST* oldBuffer = NULL;
+    PICKED_ITEMS_LIST* oldBuffer = nullptr;
 
     if( fromEmpty )
     {
@@ -313,6 +314,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
     {
         oldBuffer->PushItem( deletedItemsList.GetItemWrapper( i ) );
     }
+
     // Find new footprints
     for( FOOTPRINT* item : currentPcb->Footprints() )
     {
@@ -379,12 +381,13 @@ void PCB_EDIT_FRAME::buildActionPluginMenus( ACTION_MENU* actionMenu )
     {
         wxMenuItem* item;
         ACTION_PLUGIN* ap = ACTION_PLUGINS::GetAction( ii );
-        const wxBitmap& bitmap = ap->iconBitmap.IsOk() ? ap->iconBitmap : KiBitmap( BITMAPS::puzzle_piece );
+        const wxBitmap& bitmap = ap->iconBitmap.IsOk() ? ap->iconBitmap :
+                                                         KiBitmap( BITMAPS::puzzle_piece );
 
         item = AddMenuItem( actionMenu, wxID_ANY,  ap->GetName(), ap->GetDescription(), bitmap );
 
         Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
-                wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginMenu ) );
+                 wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginMenu ) );
 
         ACTION_PLUGINS::SetActionMenu( ii, item->GetId() );
     }
@@ -414,11 +417,11 @@ void PCB_EDIT_FRAME::AddActionPluginTools()
             else
                 bitmap = KiScaledBitmap( BITMAPS::puzzle_piece, this );
 
-            wxAuiToolBarItem* button = m_mainToolBar->AddTool(
-                    wxID_ANY, wxEmptyString, bitmap, ap->GetName() );
+            wxAuiToolBarItem* button = m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
+                                                               bitmap, ap->GetName() );
 
             Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
-                    wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginButton ) );
+                     wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginButton ) );
 
             // Link action plugin to button
             ACTION_PLUGINS::SetActionButton( ap, button->GetId() );
@@ -459,7 +462,8 @@ std::vector<ACTION_PLUGIN*> PCB_EDIT_FRAME::GetOrderedActionPlugins()
 }
 
 
-bool PCB_EDIT_FRAME::GetActionPluginButtonVisible( const wxString& aPluginPath, bool aPluginDefault )
+bool PCB_EDIT_FRAME::GetActionPluginButtonVisible( const wxString& aPluginPath,
+                                                   bool aPluginDefault )
 {
     auto& settings = m_settings->m_VisibleActionPlugins;
 
diff --git a/pcbnew/python/scripting/pcbnew_action_plugins.h b/pcbnew/python/scripting/pcbnew_action_plugins.h
index ab7266b45d..f2a35c9aaf 100644
--- a/pcbnew/python/scripting/pcbnew_action_plugins.h
+++ b/pcbnew/python/scripting/pcbnew_action_plugins.h
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -39,12 +39,6 @@
 
 class PYTHON_ACTION_PLUGIN : public ACTION_PLUGIN
 {
-    PyObject* m_PyAction;
-    PyObject* CallMethod( const char* aMethod,
-            PyObject* aArglist = NULL );
-    wxString CallRetStrMethod( const char* aMethod,
-            PyObject* aArglist = NULL );
-
 public:
     PYTHON_ACTION_PLUGIN( PyObject* action );
     ~PYTHON_ACTION_PLUGIN();
@@ -56,6 +50,11 @@ public:
     wxString    GetPluginPath() override;
     void        Run() override;
     void*       GetObject() override;
+
+private:
+    PyObject* m_PyAction;
+    PyObject* CallMethod( const char* aMethod, PyObject* aArglist = nullptr );
+    wxString CallRetStrMethod( const char* aMethod, PyObject* aArglist = nullptr );
 };
 
 
diff --git a/pcbnew/python/scripting/pcbnew_footprint_wizards.cpp b/pcbnew/python/scripting/pcbnew_footprint_wizards.cpp
index f825f6b4c1..eefcea7a07 100644
--- a/pcbnew/python/scripting/pcbnew_footprint_wizards.cpp
+++ b/pcbnew/python/scripting/pcbnew_footprint_wizards.cpp
@@ -89,7 +89,7 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA
         Py_XDECREF( pFunc );
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -127,8 +127,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod( const char*   aMet
         if( !PyList_Check( result ) )
         {
             Py_DECREF( result );
-            ret.Add( wxT(
-                         "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
+            ret.Add( wxT( "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
                      1 );
             return ret;
         }
@@ -172,7 +171,7 @@ int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages()
     PyLOCK      lock;
 
     // Time to call the callback
-    PyObject*   result = CallMethod( "GetNumParameterPages", NULL );
+    PyObject*   result = CallMethod( "GetNumParameterPages", nullptr );
 
     if( result )
     {
@@ -327,7 +326,7 @@ void PYTHON_FOOTPRINT_WIZARD::ResetParameters()
 {
     PyLOCK     lock;
 
-    CallMethod( "ResetWizard", NULL );
+    CallMethod( "ResetWizard", nullptr );
 }
 
 
@@ -339,13 +338,13 @@ FOOTPRINT* PYTHON_FOOTPRINT_WIZARD::GetFootprint( wxString * aMessages )
 {
     PyLOCK      lock;
 
-    PyObject*   result = CallMethod( "GetFootprint", NULL );
+    PyObject*   result = CallMethod( "GetFootprint", nullptr );
 
     if( aMessages )
-        *aMessages = CallRetStrMethod( "GetBuildMessages", NULL );
+        *aMessages = CallRetStrMethod( "GetBuildMessages", nullptr );
 
     if( !result )
-        return NULL;
+        return nullptr;
 
     PyObject* obj = PyObject_GetAttrString( result, "this" );
 
diff --git a/pcbnew/python/scripting/pcbnew_footprint_wizards.h b/pcbnew/python/scripting/pcbnew_footprint_wizards.h
index bbe188bf20..f7e73886f0 100644
--- a/pcbnew/python/scripting/pcbnew_footprint_wizards.h
+++ b/pcbnew/python/scripting/pcbnew_footprint_wizards.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013 NBEE Embedded Systems SL, Miguel Angel Ajo <miguelangel@ajo.es>
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -40,11 +40,6 @@
 
 class PYTHON_FOOTPRINT_WIZARD : public FOOTPRINT_WIZARD
 {
-    PyObject* m_PyWizard;
-    PyObject*       CallMethod( const char* aMethod, PyObject* aArglist = NULL );
-    wxString        CallRetStrMethod( const char* aMethod, PyObject* aArglist = NULL );
-    wxArrayString   CallRetArrayStrMethod( const char*  aMethod, PyObject* aArglist = NULL );
-
 public:
     PYTHON_FOOTPRINT_WIZARD( PyObject* wizard );
     ~PYTHON_FOOTPRINT_WIZARD();
@@ -58,14 +53,22 @@ public:
     wxArrayString   GetParameterTypes( int aPage ) override;
     wxArrayString   GetParameterValues( int aPage ) override;
     wxArrayString   GetParameterErrors( int aPage ) override;
+
     // must return an empty string or an error description:
     wxString        SetParameterValues( int aPage, wxArrayString& aValues ) override;
     FOOTPRINT*      GetFootprint( wxString * aMessages ) override;
     void*           GetObject() override;
     wxArrayString   GetParameterHints( int aPage ) override;
-    wxArrayString   GetParameterDesignators( int aPage = 0) override;
+    wxArrayString   GetParameterDesignators( int aPage = 0 ) override;
 
     void            ResetParameters() override;
+
+private:
+    PyObject*       CallMethod( const char* aMethod, PyObject* aArglist = nullptr );
+    wxString        CallRetStrMethod( const char* aMethod, PyObject* aArglist = nullptr );
+    wxArrayString   CallRetArrayStrMethod( const char* aMethod, PyObject* aArglist = nullptr );
+
+    PyObject* m_PyWizard;
 };
 
 
diff --git a/pcbnew/python/scripting/pcbnew_scripting.cpp b/pcbnew/python/scripting/pcbnew_scripting.cpp
index be60ea9f05..c92b0a68a3 100644
--- a/pcbnew/python/scripting/pcbnew_scripting.cpp
+++ b/pcbnew/python/scripting/pcbnew_scripting.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -52,8 +52,8 @@
 /**
  * Run a python method from the pcbnew module.
  *
- * @param aMethodName is the name of the method (like "pcbnew.myfunction" )
- * @param aNames will contain the returned string
+ * @param aMethodName is the name of the method (like "pcbnew.myfunction" ).
+ * @param aNames will contain the returned string.
  */
 static void pcbnewRunPythonMethodWithReturnedString( const char* aMethodName, wxString& aNames )
 {
@@ -84,13 +84,13 @@ static void pcbnewRunPythonMethodWithReturnedString( const char* aMethodName, wx
     if( pobj )
     {
         PyObject* str = PyDict_GetItemString(localDict, "result" );
-        const char* str_res = NULL;
+        const char* str_res = nullptr;
 
         if(str)
         {
             PyObject* temp_bytes = PyUnicode_AsEncodedString( str, "UTF-8", "strict" );
 
-            if( temp_bytes != NULL )
+            if( temp_bytes != nullptr )
             {
                 str_res = PyBytes_AS_STRING( temp_bytes );
                 aNames = FROM_UTF8( str_res );
@@ -98,7 +98,7 @@ static void pcbnewRunPythonMethodWithReturnedString( const char* aMethodName, wx
             }
             else
             {
-                wxLogMessage( "cannot encode unicode python string" );
+                wxLogMessage( "cannot encode Unicode python string" );
             }
         }
         else
@@ -151,6 +151,8 @@ void pcbnewGetWizardsBackTrace( wxString& aTrace )
                 aTrace << "\n**********************************\n";
         }
         else
+        {
             aTrace += traces[ii] + "\n";
+        }
     }
 }
diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp
index c0a9719c9a..13c1181a79 100644
--- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp
+++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
- * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -52,8 +52,7 @@
 #include <wx/app.h>
 
 
-static PCB_EDIT_FRAME* s_PcbEditFrame = NULL;
-
+static PCB_EDIT_FRAME* s_PcbEditFrame = nullptr;
 static SETTINGS_MANAGER* s_SettingsManager = nullptr;
 
 
@@ -62,7 +61,7 @@ BOARD* GetBoard()
     if( s_PcbEditFrame )
         return s_PcbEditFrame->GetBoard();
     else
-        return NULL;
+        return nullptr;
 }
 
 
@@ -188,7 +187,7 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat )
     aBoard->BuildConnectivity();
     aBoard->SynchronizeNetsAndNetClasses();
 
-    IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
+    IO_MGR::Save( aFormat, aFileName, aBoard, nullptr );
 
     wxFileName pro = aFileName;
     pro.SetExt( ProjectFileExtension );
@@ -267,10 +266,8 @@ bool ExportSpecctraDSN( wxString& aFullFilename )
     }
 }
 
-bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit,
-                 bool aExport3DFiles, bool aUseRelativePaths,
-                 const wxString& a3D_Subdir,
-                 double aXRef, double aYRef )
+bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles,
+                 bool aUseRelativePaths, const wxString& a3D_Subdir, double aXRef, double aYRef )
 {
     if( s_PcbEditFrame )
     {
diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.h b/pcbnew/python/scripting/pcbnew_scripting_helpers.h
index 5b3c383a3d..bf7260379d 100644
--- a/pcbnew/python/scripting/pcbnew_scripting_helpers.h
+++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013 NBEE Embedded Systems SL, Miguel Angel Ajo <miguelangel@ajo.es>
- * Copyright (C) 2013-2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -48,73 +48,73 @@ BOARD*  LoadBoard( wxString& aFileName );
 SETTINGS_MANAGER* GetSettingsManager();
 
 /**
- * Constructs a default BOARD with a tempoary (no filename) project
- * @return the created board
+ * Construct a default BOARD with a temporary (no filename) project.
+ *
+ * @return the created board.
  */
 BOARD* CreateEmptyBoard();
 
 // Boards can be saved only as .kicad_pcb file format,
 // so no option to choose the file format.
-bool    SaveBoard( wxString& aFileName, BOARD* aBoard );
+bool SaveBoard( wxString& aFileName, BOARD* aBoard );
 
 /**
- * will get the nicknames of all of the footprint libraries configured in
- * pcbnew in both the project and global library tables
- * @return the list of footprint library nicknames, empty on error
+ * Get the nicknames of all of the footprint libraries configured in
+ * pcbnew in both the project and global library tables.
+ *
+ * @return the list of footprint library nicknames, empty on error.
  */
 wxArrayString GetFootprintLibraries();
 
 /**
- * will get the names of all of the footprints available in a footprint library
- * @param aNickName is the nickname specifying which footprint library to fetch
- * from
- * @return the list of footprint names, empty on error
+ * Get the names of all of the footprints available in a footprint library.
+ *
+ * @param aNickName is the nickname specifying which footprint library to fetch from.
+ * @return the list of footprint names, empty on error.
  */
 wxArrayString GetFootprints( const wxString& aNickName );
 
 /**
- * will export the current BOARD to a specctra dsn file.
- * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the
- * specification.
+ * Will export the current BOARD to a specctra dsn file.
+ *
+ * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.
+ *
  * @return true if OK
  */
 bool ExportSpecctraDSN( wxString& aFullFilename );
 
 /**
- * will export the current BOARD to a VRML (wrl) file.
+ * Export the current BOARD to a VRML (wrl) file.
+ *
  * See ExportVRML_File in pcb_edit_frame.h for detailed documentation.
- * @return true if OK
+ * @return true if OK.
  */
-bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit,
-                 bool aExport3DFiles, bool aUseRelativePaths,
-                 const wxString& a3D_Subdir,
-                 double aXRef, double aYRef );
+bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles,
+                 bool aUseRelativePaths, const wxString& a3D_Subdir, double aXRef, double aYRef );
 
 /**
- * will import a specctra *.ses file and use it to relocate MODULEs and
- * to replace all vias and tracks in an existing and loaded BOARD.
- * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the
- * specification.
+ * Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and
+ * tracks in an existing and loaded #BOARD.
+ *
+ * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.
+ *
  * @return true if OK
  */
 bool ImportSpecctraSES( wxString& aFullFilename );
 
 /**
- * Function ExportFootprintsToLibrary
  * Save footprints in a library:
- * @param aStoreInNewLib:
- *              true : save footprints in a existing lib. Existing footprints will be kept
- *              or updated.
- *              This lib should be in fp lib table, and is type is .pretty
- *              false: save footprints in a new lib. It it is an existing lib,
- *              previous footprints will be removed
  *
- * @param aLibName:
- *              optional library name to create, stops dialog call.
- *              must be called with aStoreInNewLib as true
+ * @param aStoreInNewLib set to true to save footprints in a existing lib. Existing footprints
+ *                       will be kept or updated.  This lib should be in fp lib table, and is
+ *                       type is .pretty.  Set to false to save footprints in a new lib.  If it
+ *                       is an existing lib, previous footprints will be removed.
+ *
+ * @param aLibName is the optional library name to create, stops dialog call.  Must be called
+ *                 with \a aStoreInNewLib as true.
  */
 bool ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString,
-                                wxString* aLibPath = NULL );
+                                wxString* aLibPath = nullptr );
 
 /**
  * Update the board display after modifying it by a python script
@@ -124,7 +124,7 @@ bool ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName =
  * Could be deprecated because modifying a board (especially deleting items) outside
  * a action plugin can crash Pcbnew.
  */
-void    Refresh();
+void Refresh();
 
 /**
  * Update the layer manager and other widgets from the board setup
@@ -135,7 +135,8 @@ void    Refresh();
 void UpdateUserInterface();
 
 /**
- * Returns the currently selected user unit value for the interface
+ * Return the currently selected user unit value for the interface.
+ *
  * @return 0 = Inches, 1=mm, -1 if the frame isn't set
  */
 int GetUserUnits();
@@ -146,16 +147,16 @@ int GetUserUnits();
 bool IsActionRunning();
 
 /**
- * Runs the DRC check on the given board and writes the results to a report file.
+ * Run the DRC check on the given board and writes the results to a report file.
  * Requires that the project for the board be loaded, and note that unlike the DRC dialog
  * this does not attempt to fill zones, so zones must be valid before calling.
  *
- * @param aBoard is a valid loaded board
- * @param aFileName is the full path and name of the report file to write
- * @param aUnits is the units to use in the report
+ * @param aBoard is a valid loaded board.
+ * @param aFileName is the full path and name of the report file to write.
+ * @param aUnits is the units to use in the report.
  * @param aReportAllTrackErrors controls whether all errors or just the first error is reported
- *                              for each track
- * @return true if successful, false if not
+ *                              for each track.
+ * @return true if successful, false if not.
  */
 bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
                      bool aReportAllTrackErrors );
diff --git a/pcbnew/python/swig/footprint.i b/pcbnew/python/swig/footprint.i
index 2177b7721f..8b970f84f3 100644
--- a/pcbnew/python/swig/footprint.i
+++ b/pcbnew/python/swig/footprint.i
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
- * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -139,21 +139,22 @@
 
 %{
 
+
 // called from pcbnew/swig/pcbnew_footprint_wizards.cpp
-FOOTPRINT* PyFootprint_to_FOOTPRINT(PyObject *obj0)
+FOOTPRINT* PyFootprint_to_FOOTPRINT( PyObject *obj0 )
 {
     void* argp;
-    int res1 = SWIG_ConvertPtr(obj0, &argp,SWIGTYPE_p_FOOTPRINT, 0 |  0 );
+    int res1 = SWIG_ConvertPtr( obj0, &argp,SWIGTYPE_p_FOOTPRINT, 0 |  0 );
 
-    if (!SWIG_IsOK(res1))
+    if( !SWIG_IsOK( res1 ) )
     {
-        SWIG_exception_fail(SWIG_ArgError(res1), "Converting object to FOOTPRINT*");
+        SWIG_exception_fail( SWIG_ArgError( res1 ), "Converting object to FOOTPRINT*" );
     }
 
     return ( FOOTPRINT *) argp;
 
 fail:
-    return NULL;
+    return nullptr;
 }
 
 %}
diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp
index 711ba88601..0c298eab93 100644
--- a/pcbnew/router/length_tuner_tool.cpp
+++ b/pcbnew/router/length_tuner_tool.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2017 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -81,7 +81,7 @@ static TOOL_ACTION ACT_AmplDecrease( "pcbnew.LengthTuner.AmplDecrease",
 LENGTH_TUNER_TOOL::LENGTH_TUNER_TOOL() :
     TOOL_BASE( "pcbnew.LengthTuner" )
 {
-    // set the initial tune mode for the settings dialog, 
+    // set the initial tune mode for the settings dialog,
     // in case the dialog is opened before the tool is activated the first time
     m_lastTuneMode = PNS::ROUTER_MODE::PNS_MODE_TUNE_SINGLE;
 }
@@ -113,6 +113,7 @@ bool LENGTH_TUNER_TOOL::Init()
     return true;
 }
 
+
 void LENGTH_TUNER_TOOL::Reset( RESET_REASON aReason )
 {
     if( aReason == RUN )
@@ -166,12 +167,12 @@ void LENGTH_TUNER_TOOL::performTuning()
     PNS_TUNE_STATUS_POPUP statusPopup( frame() );
     statusPopup.Popup();
 
-    m_router->Move( end, NULL );
+    m_router->Move( end, nullptr );
     updateStatusPopup( statusPopup );
 
-    auto setCursor = 
-            [&]() 
-            { 
+    auto setCursor =
+            [&]()
+            {
                 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
             };
 
@@ -189,12 +190,12 @@ void LENGTH_TUNER_TOOL::performTuning()
         else if( evt->IsMotion() )
         {
             end = evt->Position();
-            m_router->Move( end, NULL );
+            m_router->Move( end, nullptr );
             updateStatusPopup( statusPopup );
         }
         else if( evt->IsClick( BUT_LEFT ) )
         {
-            if( m_router->FixRoute( evt->Position(), NULL ) )
+            if( m_router->FixRoute( evt->Position(), nullptr ) )
                 break;
         }
         else if( evt->IsClick( BUT_RIGHT ) )
@@ -203,31 +204,31 @@ void LENGTH_TUNER_TOOL::performTuning()
         }
         else if( evt->IsAction( &ACT_EndTuning ) )
         {
-            if( m_router->FixRoute( end, NULL ) )
+            if( m_router->FixRoute( end, nullptr ) )
                 break;
         }
         else if( evt->IsAction( &ACT_AmplDecrease ) )
         {
             placer->AmplitudeStep( -1 );
-            m_router->Move( end, NULL );
+            m_router->Move( end, nullptr );
             updateStatusPopup( statusPopup );
         }
         else if( evt->IsAction( &ACT_AmplIncrease ) )
         {
             placer->AmplitudeStep( 1 );
-            m_router->Move( end, NULL );
+            m_router->Move( end, nullptr );
             updateStatusPopup( statusPopup );
         }
         else if(evt->IsAction( &ACT_SpacingDecrease ) )
         {
             placer->SpacingStep( -1 );
-            m_router->Move( end, NULL );
+            m_router->Move( end, nullptr );
             updateStatusPopup( statusPopup );
         }
         else if( evt->IsAction( &ACT_SpacingIncrease ) )
         {
             placer->SpacingStep( 1 );
-            m_router->Move( end, NULL );
+            m_router->Move( end, nullptr );
             updateStatusPopup( statusPopup );
         }
         else if( evt->IsAction( &PCB_ACTIONS::lengthTunerSettingsDialog ) )
@@ -253,10 +254,12 @@ void LENGTH_TUNER_TOOL::setTransitions()
 {
     Go( &LENGTH_TUNER_TOOL::MainLoop,              PCB_ACTIONS::routerTuneSingleTrace.MakeEvent() );
     Go( &LENGTH_TUNER_TOOL::MainLoop,              PCB_ACTIONS::routerTuneDiffPair.MakeEvent() );
-    Go( &LENGTH_TUNER_TOOL::MainLoop,              PCB_ACTIONS::routerTuneDiffPairSkew.MakeEvent() );
+    Go( &LENGTH_TUNER_TOOL::MainLoop,
+        PCB_ACTIONS::routerTuneDiffPairSkew.MakeEvent() );
 
     // in case tool is inactive, otherwise the event is handled in the tool loop
-    Go( &LENGTH_TUNER_TOOL::meanderSettingsDialog, PCB_ACTIONS::lengthTunerSettingsDialog.MakeEvent() );
+    Go( &LENGTH_TUNER_TOOL::meanderSettingsDialog,
+        PCB_ACTIONS::lengthTunerSettingsDialog.MakeEvent() );
 }
 
 
@@ -274,9 +277,9 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
 
     controls()->ShowCursor( true );
 
-    auto setCursor = 
-            [&]() 
-            { 
+    auto setCursor =
+            [&]()
+            {
                 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
             };
 
@@ -332,6 +335,7 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
     return 0;
 }
 
+
 int LENGTH_TUNER_TOOL::meanderSettingsDialog( const TOOL_EVENT& aEvent )
 {
     PNS::MEANDER_PLACER_BASE* placer = static_cast<PNS::MEANDER_PLACER_BASE*>( m_router->Placer() );
diff --git a/pcbnew/router/pns_algo_base.cpp b/pcbnew/router/pns_algo_base.cpp
index b87f98a37f..db72c79c29 100644
--- a/pcbnew/router/pns_algo_base.cpp
+++ b/pcbnew/router/pns_algo_base.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -33,9 +33,10 @@ ROUTING_SETTINGS& ALGO_BASE::Settings() const
 
 LOGGER* ALGO_BASE::Logger()
 {
-    return NULL;
+    return nullptr;
 }
 
+
 const BOX2I& ALGO_BASE::VisibleViewArea() const
 {
     return m_router->VisibleViewArea();
diff --git a/pcbnew/router/pns_diff_pair.cpp b/pcbnew/router/pns_diff_pair.cpp
index a6f5d2df46..2555859299 100644
--- a/pcbnew/router/pns_diff_pair.cpp
+++ b/pcbnew/router/pns_diff_pair.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -33,6 +33,7 @@ namespace PNS {
 
 class LINE;
 
+
 DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( ITEM* aPrimP, ITEM* aPrimN )
 {
     m_primP = aPrimP->Clone();
@@ -54,13 +55,13 @@ DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( const VECTOR2I& aAnchorP, const VECTOR2I&
 {
     m_anchorP = aAnchorP;
     m_anchorN = aAnchorN;
-    m_primP = m_primN = NULL;
+    m_primP = m_primN = nullptr;
 }
 
 
 DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( const DP_PRIMITIVE_PAIR& aOther )
 {
-    m_primP = m_primN = NULL;
+    m_primP = m_primN = nullptr;
 
     if( aOther.m_primP )
         m_primP = aOther.m_primP->Clone();
@@ -114,6 +115,7 @@ DIRECTION_45 DP_PRIMITIVE_PAIR::anchorDirection( const ITEM* aItem, const VECTOR
         return DIRECTION_45( aItem->Anchor( 1 ) - aItem->Anchor( 0 ) );
 }
 
+
 void DP_PRIMITIVE_PAIR::CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint,
                                            VECTOR2I& aDirection ) const
 {
@@ -200,10 +202,13 @@ void DP_GATEWAY::Reverse()
 }
 
 
-bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarget, bool aPrefDiagonal )
+bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarget,
+                              bool aPrefDiagonal )
 {
-    SHAPE_LINE_CHAIN p = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorP(), aTarget.AnchorP(), aPrefDiagonal );
-    SHAPE_LINE_CHAIN n = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorN(), aTarget.AnchorN(), aPrefDiagonal );
+    SHAPE_LINE_CHAIN p = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorP(), aTarget.AnchorP(),
+                                                            aPrefDiagonal );
+    SHAPE_LINE_CHAIN n = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorN(), aTarget.AnchorN(),
+                                                            aPrefDiagonal );
 
     int mask = aEntry.AllowedAngles() | DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_OBTUSE;
 
@@ -275,7 +280,9 @@ bool DIFF_PAIR::CheckConnectionAngle( const DIFF_PAIR& aOther, int aAllowedAngle
     }
 
     if( m_n.SegmentCount() == 0 || aOther.m_n.SegmentCount() == 0 )
+    {
         checkN = true;
+    }
     else
     {
         DIRECTION_45 n0( m_n.CSegment( -1 ) );
@@ -294,8 +301,8 @@ const DIFF_PAIR DP_GATEWAY::Entry() const
 }
 
 
-void DP_GATEWAYS::BuildOrthoProjections( DP_GATEWAYS& aEntries,
-        const VECTOR2I& aCursorPos, int aOrthoScore )
+void DP_GATEWAYS::BuildOrthoProjections( DP_GATEWAYS& aEntries, const VECTOR2I& aCursorPos,
+                                         int aOrthoScore )
 {
     for( const DP_GATEWAY& g : aEntries.Gateways() )
     {
@@ -309,7 +316,6 @@ void DP_GATEWAYS::BuildOrthoProjections( DP_GATEWAYS& aEntries,
         int dist_s = ( proj_s - aCursorPos ).EuclideanNorm();
         int dist_d = ( proj_d - aCursorPos ).EuclideanNorm();
 
-
         VECTOR2I proj = ( dist_s < dist_d ? proj_s : proj_d );
 
         DP_GATEWAYS targets( m_gap );
@@ -329,8 +335,8 @@ void DP_GATEWAYS::BuildOrthoProjections( DP_GATEWAYS& aEntries,
 }
 
 
-bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget,
-        bool aPrefDiagonal, DIFF_PAIR& aDp )
+bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool aPrefDiagonal,
+                               DIFF_PAIR& aDp )
 {
     DP_CANDIDATE best;
 
@@ -355,7 +361,8 @@ bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget,
 
                 DIFF_PAIR l( m_gap );
 
-                if( l.BuildInitial( g_entry, g_target, aPrefDiagonal ^ ( attempt ? true : false ) ) )
+                if( l.BuildInitial( g_entry, g_target,
+                                    aPrefDiagonal ^ ( attempt ? true : false ) ) )
                 {
                     best.p = l.CP();
                     best.n = l.CN();
@@ -389,11 +396,13 @@ bool DP_GATEWAYS::checkDiagonalAlignment( const VECTOR2I& a, const VECTOR2I& b )
 void DP_GATEWAYS::FilterByOrientation ( int aAngleMask, DIRECTION_45 aRefOrientation )
 {
     m_gateways.erase(
-        std::remove_if( m_gateways.begin(), m_gateways.end(), [aAngleMask, aRefOrientation]( const DP_GATEWAY& dp) {
-            DIRECTION_45 orient( dp.AnchorP() - dp.AnchorN() );
-            return ( orient.Angle( aRefOrientation ) & aAngleMask );
-        } ), m_gateways.end()
-    );
+        std::remove_if( m_gateways.begin(), m_gateways.end(),
+                        [aAngleMask, aRefOrientation]( const DP_GATEWAY& dp)
+                        {
+                            DIRECTION_45 orient( dp.AnchorP() - dp.AnchorN() );
+                            return ( orient.Angle( aRefOrientation ) & aAngleMask );
+                        } ), m_gateways.end()
+        );
 }
 
 static VECTOR2I makeGapVector( VECTOR2I dir, int length )
@@ -419,9 +428,9 @@ void DP_GATEWAYS::BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool a
     VECTOR2I p0_p, p0_n;
     int orthoFanDistance;
     int diagFanDistance;
-    const SHAPE* shP = NULL;
+    const SHAPE* shP = nullptr;
 
-    if( aPair.PrimP() == NULL )
+    if( aPair.PrimP() == nullptr )
     {
         BuildGeneric( aPair.AnchorP(), aPair.AnchorN(), true );
         return;
@@ -445,7 +454,7 @@ void DP_GATEWAYS::BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool a
 
     majorDirection = ( p0_p - p0_n ).Perpendicular();
 
-    if( shP == NULL )
+    if( shP == nullptr )
         return;
 
     switch( shP->Type() )
@@ -555,8 +564,8 @@ void DP_GATEWAYS::BuildForCursor( const VECTOR2I& aCursorPos )
             if( m_fitVias )
                 BuildGeneric( aCursorPos + dir, aCursorPos - dir, true, true );
             else
-                m_gateways.emplace_back( aCursorPos + dir,
-                                      aCursorPos - dir, attempt ? true : false );
+                m_gateways.emplace_back( aCursorPos + dir, aCursorPos - dir,
+                                         attempt ? true : false );
 
         }
     }
@@ -569,8 +578,10 @@ void DP_GATEWAYS::buildEntries( const VECTOR2I& p0_p, const VECTOR2I& p0_n )
     {
         if( !g.HasEntryLines() )
         {
-            SHAPE_LINE_CHAIN lead_p = DIRECTION_45().BuildInitialTrace ( g.AnchorP(), p0_p, g.IsDiagonal() ).Reverse();
-            SHAPE_LINE_CHAIN lead_n = DIRECTION_45().BuildInitialTrace ( g.AnchorN(), p0_n, g.IsDiagonal() ).Reverse();
+            SHAPE_LINE_CHAIN lead_p = DIRECTION_45().BuildInitialTrace ( g.AnchorP(), p0_p,
+                                                                         g.IsDiagonal() ).Reverse();
+            SHAPE_LINE_CHAIN lead_n = DIRECTION_45().BuildInitialTrace ( g.AnchorN(), p0_n,
+                                                                         g.IsDiagonal() ).Reverse();
             g.SetEntryLines( lead_p, lead_n );
         }
     }
@@ -628,7 +639,8 @@ void DP_GATEWAYS::buildDpContinuation( const DP_PRIMITIVE_PAIR& aPair, bool aIsD
 }
 
 
-void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool aBuildEntries, bool aViaMode )
+void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool aBuildEntries,
+                                bool aViaMode )
 {
     SEG st_p[2], st_n[2];
     SEG d_n[2], d_p[2];
@@ -659,7 +671,8 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
 
             if( !aViaMode )
             {
-                m_gateways.emplace_back( m - dir, m + dir, diagColl, DIRECTION_45::ANG_RIGHT, prio );
+                m_gateways.emplace_back( m - dir, m + dir, diagColl, DIRECTION_45::ANG_RIGHT,
+                                         prio );
 
                 dir = makeGapVector( p0_n - p0_p, 2 * m_gap );
                 m_gateways.emplace_back( p0_p - dir, p0_p - dir + dir.Perpendicular(), diagColl );
@@ -681,6 +694,7 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
 
             if( d_n[i].Collinear( d_p[j] ) )
                 ips[0] = OPT_VECTOR2I();
+
             if( st_p[i].Collinear( st_p[j] ) )
                 ips[1] = OPT_VECTOR2I();
 
@@ -698,7 +712,8 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
                         VECTOR2I g_p( ( p0_p - m ).Resize( ceil( (double) m_gap * M_SQRT1_2 ) ) );
                         VECTOR2I g_n( ( p0_n - m ).Resize( ceil( (double) m_gap * M_SQRT1_2 ) ) );
 
-                        m_gateways.emplace_back( m + g_p, m + g_n, k == 0 ? true : false, DIRECTION_45::ANG_OBTUSE, prio );
+                        m_gateways.emplace_back( m + g_p, m + g_n, k == 0 ? true : false,
+                                                 DIRECTION_45::ANG_OBTUSE, prio );
                     }
                 }
             }
@@ -742,7 +757,9 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
 DP_PRIMITIVE_PAIR DIFF_PAIR::EndingPrimitives()
 {
     if( m_hasVias )
+    {
         return DP_PRIMITIVE_PAIR( &m_via_p, &m_via_n );
+    }
     else
     {
         const LINE lP( PLine() );
@@ -826,7 +843,8 @@ void DIFF_PAIR::CoupledSegmentPairs( COUPLED_SEGMENTS_VEC& aPairs ) const
 
             int64_t dist = std::abs( sp.Distance( sn ) - m_width );
 
-            if( sp.ApproxParallel( sn ) && m_gapConstraint.Matches( dist ) && commonParallelProjection( sp, sn, p_clip, n_clip ) )
+            if( sp.ApproxParallel( sn ) && m_gapConstraint.Matches( dist ) &&
+                commonParallelProjection( sp, sn, p_clip, n_clip ) )
             {
                 const COUPLED_SEGMENTS spair( p_clip, sp, i, n_clip, sn, j );
                 aPairs.push_back( spair );
@@ -852,7 +870,7 @@ int64_t DIFF_PAIR::CoupledLength( const SHAPE_LINE_CHAIN& aP, const SHAPE_LINE_C
             int64_t dist = std::abs( sp.Distance(sn) - m_width );
 
             if( sp.ApproxParallel( sn ) && m_gapConstraint.Matches( dist ) &&
-                    commonParallelProjection( sp, sn, p_clip, n_clip ) )
+                commonParallelProjection( sp, sn, p_clip, n_clip ) )
                 total += p_clip.Length();
         }
     }
@@ -868,6 +886,7 @@ double DIFF_PAIR::CoupledLength() const
     CoupledSegmentPairs( pairs );
 
     double l = 0.0;
+
     for( unsigned int i = 0; i < pairs.size(); i++ )
         l += pairs[i].coupledP.Length();
 
@@ -901,7 +920,7 @@ int DIFF_PAIR::CoupledLength ( const SEG& aP, const SEG& aN ) const
     int64_t dist = std::abs( aP.Distance( aN ) - m_width );
 
     if( aP.ApproxParallel( aN ) && m_gapConstraint.Matches( dist ) &&
-            commonParallelProjection ( aP, aN, p_clip, n_clip ) )
+        commonParallelProjection ( aP, aN, p_clip, n_clip ) )
         return p_clip.Length();
 
     return 0;
diff --git a/pcbnew/router/pns_diff_pair.h b/pcbnew/router/pns_diff_pair.h
index b4d56e6c1c..b10e068396 100644
--- a/pcbnew/router/pns_diff_pair.h
+++ b/pcbnew/router/pns_diff_pair.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -36,24 +36,18 @@ namespace PNS {
 class DIFF_PAIR;
 
 /**
- * DP_GATEWAY
- *
- * Defines a "gateway" for routing a differential pair - e.g. a pair of points (anchors) with certain
- * orientation, spacing and (optionally) predefined entry paths. The routing algorithm connects such
- * gateways with parallel lines, thus creating a difrerential pair.
- **/
-class DP_GATEWAY {
+ * Define a "gateway" for routing a differential pair - e.g. a pair of points (anchors) with
+ * certain orientation, spacing and (optionally) predefined entry paths.  The routing algorithm
+ * connects such gateways with parallel lines, thus creating a differential pair.
+ */
+class DP_GATEWAY
+{
 public:
-    DP_GATEWAY( const VECTOR2I& aAnchorP,
-                    const VECTOR2I& aAnchorN,
-                    bool aIsDiagonal,
-                    int aAllowedEntryAngles = DIRECTION_45::ANG_OBTUSE,
-                    int aPriority = 0 )
-        : m_anchorP( aAnchorP ),
-          m_anchorN( aAnchorN ),
-          m_isDiagonal( aIsDiagonal ),
-          m_allowedEntryAngles( aAllowedEntryAngles ),
-          m_priority( aPriority )
+    DP_GATEWAY( const VECTOR2I& aAnchorP, const VECTOR2I& aAnchorN, bool aIsDiagonal,
+                int aAllowedEntryAngles = DIRECTION_45::ANG_OBTUSE, int aPriority = 0 ) :
+            m_anchorP( aAnchorP ),
+            m_anchorN( aAnchorN ), m_isDiagonal( aIsDiagonal ),
+            m_allowedEntryAngles( aAllowedEntryAngles ), m_priority( aPriority )
     {
         m_hasEntryLines = false;
     }
@@ -63,9 +57,7 @@ public:
     }
 
     /**
-     * Function IsDiagonal()
-     *
-     * @return true, if the gateway anchors lie on a diagonal line
+     * @return true if the gateway anchors lie on a diagonal line.
      */
     bool IsDiagonal() const
     {
@@ -77,17 +69,12 @@ public:
     const VECTOR2I& AnchorN() const { return m_anchorN; }
 
     /**
-     * Function AllowedAngles()
-     *
-     * @return a mask of 45-degree entry directoins allowed for the
-     * gateway.
-    */
+     * @return a mask of 45-degree entry directions allowed for the gateway.
+     */
     int AllowedAngles () const { return m_allowedEntryAngles; }
 
     /**
-     * Function Priority()
-     *
-     * @return priority/score value for gateway matching
+     * @return priority/score value for gateway matching.
      */
     int Priority() const
     {
@@ -127,15 +114,13 @@ private:
 };
 
 /**
- * DP_PRIMITIVE_PAIR
- *
- * Stores staring/ending primitives (pads, vias or segments) for a differential pair.
- **/
+ * Store starting/ending primitives (pads, vias or segments) for a differential pair.
+ */
 class DP_PRIMITIVE_PAIR
 {
 public:
     DP_PRIMITIVE_PAIR():
-        m_primP( NULL ), m_primN( NULL ) {};
+        m_primP( nullptr ), m_primN( nullptr ) {};
 
     DP_PRIMITIVE_PAIR( const DP_PRIMITIVE_PAIR& aOther );
     DP_PRIMITIVE_PAIR( ITEM* aPrimP, ITEM* aPrimN );
@@ -159,7 +144,8 @@ public:
     DIRECTION_45 DirN() const;
 
 
-    void CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint, VECTOR2I& aDirection ) const;
+    void CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint,
+                            VECTOR2I& aDirection ) const;
 
     void dump()
     {
@@ -176,86 +162,75 @@ private:
 };
 
 /**
- * DP_GATEWAYS
- *
  * A set of gateways calculated for the cursor or starting/ending primitive pair.
- **/
-
+ */
 class DP_GATEWAYS
 {
-    public:
-        DP_GATEWAYS( int aGap ):
-            m_gap( aGap ),
-            m_viaGap( aGap )
-        {
-            // Do not leave uninitialized members, and keep static analyser quiet:
-            m_viaDiameter = 0;
-            m_fitVias = true;
-        }
+public:
+    DP_GATEWAYS( int aGap ):
+        m_gap( aGap ),
+        m_viaGap( aGap )
+    {
+        // Do not leave uninitialized members, and keep static analyzer quiet:
+        m_viaDiameter = 0;
+        m_fitVias = true;
+    }
 
-        void Clear()
-        {
-            m_gateways.clear();
-        }
+    void Clear() { m_gateways.clear(); }
 
-        void SetFitVias( bool aEnable, int aDiameter = 0, int aViaGap = -1 )
-        {
-            m_fitVias = aEnable;
-            m_viaDiameter = aDiameter;
+    void SetFitVias( bool aEnable, int aDiameter = 0, int aViaGap = -1 )
+    {
+        m_fitVias = aEnable;
+        m_viaDiameter = aDiameter;
 
-            if( aViaGap < 0 )
-                m_viaGap = m_gap;
-            else
-                m_viaGap = aViaGap;
-        }
+        if( aViaGap < 0 )
+            m_viaGap = m_gap;
+        else
+            m_viaGap = aViaGap;
+    }
 
 
-        void BuildForCursor( const VECTOR2I& aCursorPos );
-        void BuildOrthoProjections( DP_GATEWAYS &aEntries, const VECTOR2I& aCursorPos, int aOrthoScore );
-        void BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool aBuildEntries = false, bool aViaMode = false );
-        void BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool aPreferDiagonal );
+    void BuildForCursor( const VECTOR2I& aCursorPos );
+    void BuildOrthoProjections( DP_GATEWAYS& aEntries, const VECTOR2I& aCursorPos,
+                                int aOrthoScore );
+    void BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool aBuildEntries = false,
+                       bool aViaMode = false );
+    void BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool aPreferDiagonal );
 
-        bool FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool aPrefDiagonal, DIFF_PAIR& aDp );
+    bool FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool aPrefDiagonal,
+                      DIFF_PAIR& aDp );
 
-        std::vector<DP_GATEWAY>& Gateways()
-        {
-            return m_gateways;
-        }
+    std::vector<DP_GATEWAY>& Gateways() { return m_gateways; }
 
-        const std::vector<DP_GATEWAY>& CGateways() const
-        {
-            return m_gateways;
-        }
+    const std::vector<DP_GATEWAY>& CGateways() const { return m_gateways; }
 
-        void FilterByOrientation( int aAngleMask, DIRECTION_45 aRefOrientation );
+    void FilterByOrientation( int aAngleMask, DIRECTION_45 aRefOrientation );
 
-    private:
-        struct DP_CANDIDATE
-        {
-            SHAPE_LINE_CHAIN p, n;
-            VECTOR2I gw_p, gw_n;
-            int score;
-        };
+private:
+    struct DP_CANDIDATE
+    {
+        SHAPE_LINE_CHAIN p, n;
+        VECTOR2I         gw_p, gw_n;
+        int              score;
+    };
 
-        bool checkDiagonalAlignment( const VECTOR2I& a, const VECTOR2I& b ) const;
-        void buildDpContinuation( const DP_PRIMITIVE_PAIR& aPair, bool aIsDiagonal );
-        void buildEntries( const VECTOR2I& p0_p, const VECTOR2I& p0_n );
+    bool checkDiagonalAlignment( const VECTOR2I& a, const VECTOR2I& b ) const;
+    void buildDpContinuation( const DP_PRIMITIVE_PAIR& aPair, bool aIsDiagonal );
+    void buildEntries( const VECTOR2I& p0_p, const VECTOR2I& p0_n );
 
-        int m_gap;
-        int m_viaGap;
-        int m_viaDiameter;
-        bool m_fitVias;
+    int  m_gap;
+    int  m_viaGap;
+    int  m_viaDiameter;
+    bool m_fitVias;
 
-        std::vector<DP_GATEWAY> m_gateways;
+    std::vector<DP_GATEWAY> m_gateways;
 };
 
 
 /**
- * DIFF_PAIR
- *
  * Basic class for a differential pair. Stores two PNS_LINEs (for positive and negative nets,
  * respectively), the gap and coupling constraints.
- **/
+ */
 class DIFF_PAIR : public LINK_HOLDER
 {
 public:
@@ -341,7 +316,7 @@ public:
         m_p = aLineP.CLine();
         m_n = aLineN.CLine();
 
-        // Do not leave uninitialized members, and keep static analyser quiet:
+        // Do not leave uninitialized members, and keep static analyzer quiet:
         m_width  = 0;
         m_gap  = 0;
         m_viaGap  = 0;
@@ -354,7 +329,11 @@ public:
         return aItem && ITEM::DIFF_PAIR_T == aItem->Kind();
     }
 
-    DIFF_PAIR* Clone() const override { assert( false ); return NULL; }
+    DIFF_PAIR* Clone() const override
+    {
+        assert( false );
+        return nullptr;
+    }
 
     virtual void ClearLinks() override
     {
diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp
index 32102c2ca5..d02b88d7c7 100644
--- a/pcbnew/router/pns_diff_pair_placer.cpp
+++ b/pcbnew/router/pns_diff_pair_placer.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -40,10 +40,10 @@ DIFF_PAIR_PLACER::DIFF_PAIR_PLACER( ROUTER* aRouter ) :
     m_netP = 0;
     m_netN = 0;
     m_iteration = 0;
-    m_world = NULL;
-    m_shove = NULL;
-    m_currentNode = NULL;
-    m_lastNode = NULL;
+    m_world = nullptr;
+    m_shove = nullptr;
+    m_currentNode = nullptr;
+    m_lastNode = nullptr;
     m_placingVia = false;
     m_viaDiameter = 0;
     m_viaDrill = 0;
@@ -53,7 +53,7 @@ DIFF_PAIR_PLACER::DIFF_PAIR_PLACER( ROUTER* aRouter ) :
     m_startsOnVia = false;
     m_orthoMode = false;
     m_snapOnTarget = false;
-    m_currentEndItem = NULL;
+    m_currentEndItem = nullptr;
     m_currentMode = RM_MarkObstacles;
     m_currentTraceOk = false;
     m_idle = true;
@@ -71,6 +71,7 @@ void DIFF_PAIR_PLACER::setWorld( NODE* aWorld )
     m_world = aWorld;
 }
 
+
 const VIA DIFF_PAIR_PLACER::makeVia( const VECTOR2I& aP, int aNet )
 {
     const LAYER_RANGE layers( m_sizes.GetLayerTop(), m_sizes.GetLayerBottom() );
@@ -87,7 +88,7 @@ void DIFF_PAIR_PLACER::SetOrthoMode ( bool aOrthoMode )
     m_orthoMode = aOrthoMode;
 
     if( !m_idle )
-        Move( m_currentEnd, NULL );
+        Move( m_currentEnd, nullptr );
 }
 
 
@@ -96,7 +97,7 @@ bool DIFF_PAIR_PLACER::ToggleVia( bool aEnabled )
     m_placingVia = aEnabled;
 
     if( !m_idle )
-        Move( m_currentEnd, NULL );
+        Move( m_currentEnd, nullptr );
 
     return true;
 }
@@ -121,7 +122,9 @@ bool DIFF_PAIR_PLACER::propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNe
     VIA virtHead = makeVia( aP, -1 );
 
     if( m_placingVia )
+    {
         virtHead.SetDiameter( viaGap() + 2 * virtHead.Diameter() );
+    }
     else
     {
         virtHead.SetLayer( m_currentLayer );
@@ -186,8 +189,8 @@ bool DIFF_PAIR_PLACER::propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNe
 }
 
 
-bool DIFF_PAIR_PLACER::attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent,
-        DIFF_PAIR& aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly )
+bool DIFF_PAIR_PLACER::attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& aWalk,
+                                    bool aPFirst, bool aWindCw, bool aSolidsOnly )
 {
     WALKAROUND walkaround( aNode, Router() );
     WALKAROUND::WALKAROUND_STATUS wf1;
@@ -393,7 +396,7 @@ void DIFF_PAIR_PLACER::FlipPosture()
     m_startDiagonal = !m_startDiagonal;
 
     if( !m_idle )
-        Move( m_currentEnd, NULL );
+        Move( m_currentEnd, nullptr );
 }
 
 
@@ -423,7 +426,7 @@ bool DIFF_PAIR_PLACER::SetLayer( int aLayer )
         m_currentLayer = aLayer;
         m_start = *m_prevPair;
         initPlacement();
-        Move( m_currentEnd, NULL );
+        Move( m_currentEnd, nullptr );
         return true;
     }
 
@@ -494,6 +497,7 @@ bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, IT
                             "from an existing differential pair make sure you are "
                             "at the end." );
         }
+
         return false;
     }
 
@@ -508,6 +512,7 @@ bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, IT
         if( item->Kind() == aItem->Kind() )
         {
             OPT_VECTOR2I anchor = getDanglingAnchor( aWorld, item );
+
             if( !anchor )
                 continue;
 
@@ -547,6 +552,7 @@ bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, IT
                                               "for coupled net \"%s\"." ),
                                            aWorld->GetRuleResolver()->NetName( coupledNet ) );
         }
+
         return false;
     }
 
@@ -598,7 +604,7 @@ void DIFF_PAIR_PLACER::initPlacement()
 {
     m_idle = false;
     m_orthoMode = false;
-    m_currentEndItem = NULL;
+    m_currentEndItem = nullptr;
     m_startDiagonal = m_initialDiagonal;
 
     NODE* world = Router()->GetWorld();
@@ -608,14 +614,14 @@ void DIFF_PAIR_PLACER::initPlacement()
 
     setWorld( rootNode );
 
-    m_lastNode = NULL;
+    m_lastNode = nullptr;
     m_currentNode = rootNode;
     m_currentMode = Settings().Mode();
 
     if( m_shove )
         delete m_shove;
 
-    m_shove = NULL;
+    m_shove = nullptr;
 
     if( m_currentMode == RM_Shove || m_currentMode == RM_Smart )
     {
@@ -666,10 +672,10 @@ bool DIFF_PAIR_PLACER::routeHead( const VECTOR2I& aP )
         {
             gwsTarget.BuildForCursor( fp );
         }
-        // close to the initial segment extension line -> keep straight part only, project as close
-        // as possible to the cursor
         else
         {
+            // close to the initial segment extension line -> keep straight part only, project
+            // as close as possible to the cursor.
             gwsTarget.BuildForCursor( fpProj );
             gwsTarget.FilterByOrientation( DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_HALF_FULL,
                                            DIRECTION_45( dirV ) );
@@ -709,14 +715,14 @@ bool DIFF_PAIR_PLACER::Move( const VECTOR2I& aP , ITEM* aEndItem )
     m_fitOk = false;
 
     delete m_lastNode;
-    m_lastNode = NULL;
+    m_lastNode = nullptr;
 
     bool retval = route( aP );
 
     NODE* latestNode = m_currentNode;
     m_lastNode = latestNode->Branch();
 
-    assert( m_lastNode != NULL );
+    assert( m_lastNode != nullptr );
     m_currentEnd = aP;
 
     updateLeadingRatLine();
@@ -818,8 +824,7 @@ bool DIFF_PAIR_PLACER::AbortPlacement()
 
 bool DIFF_PAIR_PLACER::HasPlacedAnything() const
 {
-     return m_currentTrace.CP().SegmentCount() > 0 ||
-             m_currentTrace.CN().SegmentCount() > 0;
+     return m_currentTrace.CP().SegmentCount() > 0 || m_currentTrace.CN().SegmentCount() > 0;
 }
 
 
@@ -828,8 +833,8 @@ bool DIFF_PAIR_PLACER::CommitPlacement()
     if( m_lastNode )
         Router()->CommitRouting( m_lastNode );
 
-    m_lastNode = NULL;
-    m_currentNode = NULL;
+    m_lastNode = nullptr;
+    m_currentNode = nullptr;
     return true;
 }
 
diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp
index 50cf3077d7..d56aff44b1 100644
--- a/pcbnew/router/pns_dp_meander_placer.cpp
+++ b/pcbnew/router/pns_dp_meander_placer.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -36,14 +36,14 @@ namespace PNS {
 DP_MEANDER_PLACER::DP_MEANDER_PLACER( ROUTER* aRouter ) :
     MEANDER_PLACER_BASE( aRouter )
 {
-    m_world       = NULL;
-    m_currentNode = NULL;
+    m_world       = nullptr;
+    m_currentNode = nullptr;
 
     m_padToDieP = 0;
     m_padToDieN = 0;
 
     // Init temporary variables (do not leave uninitialized members)
-    m_initialSegment = NULL;
+    m_initialSegment = nullptr;
     m_lastLength     = 0;
     m_lastStatus     = TOO_SHORT;
 }
@@ -88,16 +88,16 @@ bool DP_MEANDER_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
     if( !topo.AssembleDiffPair( m_initialSegment, m_originPair ) )
     {
         Router()->SetFailureReason( _( "Unable to find complementary differential pair "
-                                       "net for length tuning. Make sure the names of the nets belonging "
-                                       "to a differential pair end with either _N/_P or +/-." ) );
+                                       "net for length tuning. Make sure the names of the nets "
+                                       "belonging to a differential pair end with either _N/_P "
+                                       "or +/-." ) );
         return false;
     }
 
     if( m_originPair.Gap() < 0 )
         m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
 
-    if( !m_originPair.PLine().SegmentCount() ||
-        !m_originPair.NLine().SegmentCount() )
+    if( !m_originPair.PLine().SegmentCount() || !m_originPair.NLine().SegmentCount() )
         return false;
 
     SOLID* padA = nullptr;
@@ -274,7 +274,8 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
 
         m_lastLength += std::max( tunedP.Length(), tunedN.Length() );
 
-        int comp = compareWithTolerance( m_lastLength - m_settings.m_targetLength, 0, m_settings.m_lengthTolerance );
+        int comp = compareWithTolerance( m_lastLength - m_settings.m_targetLength, 0,
+                                         m_settings.m_lengthTolerance );
 
         if( comp > 0 )
             m_lastStatus = TOO_LONG;
@@ -323,8 +324,7 @@ bool DP_MEANDER_PLACER::AbortPlacement()
 
 bool DP_MEANDER_PLACER::HasPlacedAnything() const
 {
-     return m_originPair.CP().SegmentCount() > 0 ||
-             m_originPair.CN().SegmentCount() > 0;
+     return m_originPair.CP().SegmentCount() > 0 || m_originPair.CN().SegmentCount() > 0;
 }
 
 
@@ -333,7 +333,7 @@ bool DP_MEANDER_PLACER::CommitPlacement()
     if( m_currentNode )
         Router()->CommitRouting( m_currentNode );
 
-    m_currentNode = NULL;
+    m_currentNode = nullptr;
     return true;
 }
 
diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp
index b33e8af826..6d3750d717 100644
--- a/pcbnew/router/pns_dragger.cpp
+++ b/pcbnew/router/pns_dragger.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -34,8 +34,8 @@ DRAGGER::DRAGGER( ROUTER* aRouter ) :
     m_initialVia( {} ),
     m_draggedVia( {} )
 {
-    m_world = NULL;
-    m_lastNode = NULL;
+    m_world = nullptr;
+    m_lastNode = nullptr;
     m_mode = DM_SEGMENT;
     m_draggedSegmentIndex = 0;
     m_dragStatus = false;
@@ -211,7 +211,7 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
 
     ITEM* startItem = aPrimitives[0];
 
-    m_lastNode = NULL;
+    m_lastNode = nullptr;
     m_draggedItems.Clear();
     m_currentMode = Settings().Mode();
     m_freeAngleMode = (m_mode & DM_FREE_ANGLE);
@@ -229,7 +229,8 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
 
     startItem->Unmark( MK_LOCKED );
 
-    PNS_DBG( Dbg(), Message, wxString::Format( "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() ) );
+    PNS_DBG( Dbg(), Message, wxString::Format( "StartDragging: item %p [kind %d]",
+                                               startItem, (int) startItem->Kind() ) );
 
     switch( startItem->Kind() )
     {
@@ -411,7 +412,8 @@ bool DRAGGER::dragViaWalkaround( const VIA_HANDLE& aHandle, NODE* aNode, const V
             LINE draggedLine( *l );
             LINE walkLine( *l );
 
-            draggedLine.DragCorner( viaTargetPos, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
+            draggedLine.DragCorner( viaTargetPos, origLine.CLine().Find( aHandle.pos ),
+                                    m_freeAngleMode );
             draggedLine.ClearLinks();
 
             if ( m_world->CheckColliding( &draggedLine ) )
@@ -526,7 +528,8 @@ bool DRAGGER::tryWalkaround( NODE* aNode, LINE& aOrig, LINE& aWalk )
 bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
 {
     bool ok = false;
-// fixme: rewrite using shared_ptr...
+
+    // fixme: rewrite using shared_ptr...
     if( m_lastNode )
     {
         delete m_lastNode;
@@ -569,7 +572,8 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
             m_lastNode->Remove( origLine );
             optimizeAndUpdateDraggedLine( draggedWalk, origLine, aP );
         }
-    break;
+
+        break;
     }
     case DM_VIA: // fixme...
     {
@@ -591,7 +595,7 @@ bool DRAGGER::dragShove( const VECTOR2I& aP )
     if( m_lastNode )
     {
         delete m_lastNode;
-        m_lastNode = NULL;
+        m_lastNode = nullptr;
     }
 
     switch( m_mode )
@@ -614,7 +618,9 @@ bool DRAGGER::dragShove( const VECTOR2I& aP )
         SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged );
 
         if( st == SHOVE::SH_OK )
+        {
             ok = true;
+        }
         else if( st == SHOVE::SH_HEAD_MODIFIED )
         {
             dragged = m_shove->NewHead();
diff --git a/pcbnew/router/pns_index.cpp b/pcbnew/router/pns_index.cpp
index f9e1315b99..a216f41f1d 100644
--- a/pcbnew/router/pns_index.cpp
+++ b/pcbnew/router/pns_index.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -71,7 +71,7 @@ void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
 INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet )
 {
     if( m_netMap.find( aNet ) == m_netMap.end() )
-        return NULL;
+        return nullptr;
 
     return &m_netMap[aNet];
 }
diff --git a/pcbnew/router/pns_item.h b/pcbnew/router/pns_item.h
index cbcca0b7b1..a2cbe52b55 100644
--- a/pcbnew/router/pns_item.h
+++ b/pcbnew/router/pns_item.h
@@ -75,8 +75,8 @@ public:
         m_net = UnusedNet;
         m_movable = true;
         m_kind = aKind;
-        m_parent = NULL;
-        m_owner = NULL;
+        m_parent = nullptr;
+        m_owner = nullptr;
         m_marker = 0;
         m_rank = -1;
         m_routable = true;
diff --git a/pcbnew/router/pns_itemset.h b/pcbnew/router/pns_itemset.h
index 26e4a6c932..03ef01ee3e 100644
--- a/pcbnew/router/pns_itemset.h
+++ b/pcbnew/router/pns_itemset.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -29,11 +29,8 @@
 namespace PNS {
 
 /**
- * ITEM_SET
- *
- * Holds a list of board items, that can be filtered against net, kinds,
- * layers, etc.
- **/
+ * Hold a list of board items, that can be filtered against net, kinds, layers, etc.
+ */
 class LINE;
 
 class ITEM_SET
@@ -95,7 +92,7 @@ public:
 
     typedef std::vector<ENTRY> ENTRIES;
 
-    ITEM_SET( ITEM* aInitialItem = NULL, bool aBecomeOwner = false )
+    ITEM_SET( ITEM* aInitialItem = nullptr, bool aBecomeOwner = false )
     {
         if( aInitialItem )
             m_items.emplace_back( ENTRY( aInitialItem, aBecomeOwner ) );
@@ -224,7 +221,7 @@ public:
             }
         }
 
-        return NULL;
+        return nullptr;
     }
 
 private:
diff --git a/pcbnew/router/pns_joint.h b/pcbnew/router/pns_joint.h
index 4826939c34..09a6756b0f 100644
--- a/pcbnew/router/pns_joint.h
+++ b/pcbnew/router/pns_joint.h
@@ -34,11 +34,11 @@
 namespace PNS {
 
 /**
- * Represents a 2D point on a given set of layers and belonging to a certain net, that links
+ * A 2D point on a given set of layers and belonging to a certain net, that links
  * together a number of board items.
  *
  * A hash table of joints is used by the router to follow connectivity between the items.
- **/
+ */
 class JOINT : public ITEM
 {
 public:
@@ -92,7 +92,7 @@ public:
     ITEM* Clone( ) const override
     {
         assert( false );
-        return NULL;
+        return nullptr;
     }
 
     ///< Return true if the joint is a trivial line corner, connecting two
@@ -159,7 +159,7 @@ public:
     LINKED_ITEM* NextSegment( ITEM* aCurrent ) const
     {
         if( !IsLineCorner() )
-            return NULL;
+            return nullptr;
 
         return static_cast<LINKED_ITEM*>( m_linkedItems[m_linkedItems[0] == aCurrent ? 1 : 0] );
     }
@@ -172,7 +172,7 @@ public:
                 return static_cast<VIA*>( item );
         }
 
-        return NULL;
+        return nullptr;
     }
 
 
diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp
index 5f217f1378..d907287292 100644
--- a/pcbnew/router/pns_kicad_iface.cpp
+++ b/pcbnew/router/pns_kicad_iface.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2016 CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -65,6 +65,7 @@
 
 typedef VECTOR2I::extended_type ecoord;
 
+
 class PNS_PCBNEW_RULE_RESOLVER : public PNS::RULE_RESOLVER
 {
 public:
@@ -155,6 +156,7 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM*
 
     if( aA->Net() == net_p && aB->Net() == net_n )
         return true;
+
     if( aB->Net() == net_p && aA->Net() == net_n )
         return true;
 
@@ -278,7 +280,7 @@ bool PNS_PCBNEW_RULE_RESOLVER::QueryConstraint( PNS::CONSTRAINT_TYPE aType,
 
         default:
             return false;
-       }
+    }
 }
 
 
@@ -373,7 +375,7 @@ bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedW
 {
     VECTOR2I p;
 
-    assert( aItem->Owner() != NULL );
+    assert( aItem->Owner() != nullptr );
 
     auto tryGetTrackWidth =
         []( PNS::ITEM* aPnsItem ) -> int
@@ -410,7 +412,7 @@ bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedW
 
     PNS::JOINT* jt = static_cast<PNS::NODE*>( aItem->Owner() )->FindJoint( p, aItem );
 
-    assert( jt != NULL );
+    assert( jt != nullptr );
 
     int mval = INT_MAX;
 
@@ -432,7 +434,8 @@ bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedW
 }
 
 
-bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem, int aNet )
+bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem,
+                                        int aNet )
 {
     BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
     PNS::CONSTRAINT        constraint;
@@ -539,8 +542,6 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM*
         diffPairViaGap = bds.GetCurrentDiffPairViaGap();
     }
 
-    //printf( "DPWidth: %d gap %d\n", diffPairWidth, diffPairGap );
-
     aSizes.SetDiffPairWidth( diffPairWidth );
     aSizes.SetDiffPairGap( diffPairGap );
     aSizes.SetDiffPairViaGap( diffPairViaGap );
@@ -598,30 +599,31 @@ int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix( const wxString& aNetName, wxString&
         aComplementNet = "P";
         rv = -1;
     }
-    // Match P followed by 2 digits
     else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
     {
+        // Match P followed by 2 digits
         aComplementNet = "N" + aNetName.Right( 2 );
         rv = 1;
     }
-    // Match P followed by 1 digit
     else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
     {
+        // Match P followed by 1 digit
         aComplementNet = "N" + aNetName.Right( 1 );
         rv = 1;
     }
-    // Match N followed by 2 digits
     else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
     {
+        // Match N followed by 2 digits
         aComplementNet = "P" + aNetName.Right( 2 );
         rv = -1;
     }
-    // Match N followed by 1 digit
     else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
     {
+        // Match N followed by 1 digit
         aComplementNet = "P" + aNetName.Right( 1 );
         rv = -1;
     }
+
     if( rv != 0 )
     {
         aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
@@ -696,13 +698,9 @@ bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, in
         netNameP = netNameCoupled;
     }
 
-//    wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
-
     NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
     NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
 
-    //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
-
     if( !netInfoP || !netInfoN )
         return false;
 
@@ -716,10 +714,10 @@ bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, in
 class PNS_PCBNEW_DEBUG_DECORATOR: public PNS::DEBUG_DECORATOR
 {
 public:
-    PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW* aView = NULL ) :
+    PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW* aView = nullptr ) :
             PNS::DEBUG_DECORATOR(),
-            m_view( NULL ),
-            m_items( NULL )
+            m_view( nullptr ),
+            m_items( nullptr )
     {
         SetView( aView );
     }
@@ -734,10 +732,10 @@ public:
     {
         Clear();
         delete m_items;
-        m_items = NULL;
+        m_items = nullptr;
         m_view = aView;
 
-        if( m_view == NULL )
+        if( m_view == nullptr )
             return;
 
         m_items = new KIGFX::VIEW_GROUP( m_view );
@@ -745,10 +743,9 @@ public:
         m_view->Add( m_items );
     }
 
-    virtual void AddPoint( VECTOR2I aP, const COLOR4D& aColor, int aSize,
-                           const std::string        aName,
+    virtual void AddPoint( VECTOR2I aP, const COLOR4D& aColor, int aSize, const std::string aName,
                            const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
-        {
+    {
         SHAPE_LINE_CHAIN l;
 
         l.Append( aP - VECTOR2I( -aSize, -aSize ) );
@@ -763,8 +760,7 @@ public:
         AddLine( l, aColor, 10000, aName );
     }
 
-    virtual void AddBox( BOX2I aB, const COLOR4D& aColor,
-                         const std::string        aName,
+    virtual void AddBox( BOX2I aB, const COLOR4D& aColor, const std::string aName,
                          const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
     {
         SHAPE_LINE_CHAIN l;
@@ -781,8 +777,7 @@ public:
         AddLine( l, aColor, 10000, aName, aSrcLoc );
     }
 
-    virtual void AddSegment( SEG aS, const COLOR4D& aColor,
-                             const std::string        aName,
+    virtual void AddSegment( SEG aS, const COLOR4D& aColor, const std::string aName,
                              const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
     {
         SHAPE_LINE_CHAIN l;
@@ -801,11 +796,13 @@ public:
         if( !m_view )
             return;
 
-        ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_view );
+        ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( nullptr, m_view );
 
         pitem->SetColor( aColor );
         pitem->Line( aLine, aWidth );
-        m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc;
+
+        // Should not be needed, as m_items has been passed as a parent group in alloc;
+        m_items->Add( pitem );
         m_view->Update( m_items );
     }
 
@@ -872,7 +869,7 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad )
 
     // ignore non-copper pads except for those with holes
     if( ( aPad->GetLayerSet() & LSET::AllCuMask() ).none() && aPad->GetDrillSize().x == 0 )
-        return NULL;
+        return nullptr;
 
     switch( aPad->GetAttribute() )
     {
@@ -882,31 +879,32 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad )
 
     case PAD_ATTRIB::CONN:
     case PAD_ATTRIB::SMD:
+    {
+        LSET lmsk = aPad->GetLayerSet();
+        bool is_copper = false;
+
+        for( int i = 0; i < MAX_CU_LAYERS; i++ )
         {
-            LSET lmsk = aPad->GetLayerSet();
-            bool is_copper = false;
-
-            for( int i = 0; i < MAX_CU_LAYERS; i++ )
+            if( lmsk[i] )
             {
-                if( lmsk[i] )
-                {
-                    is_copper = true;
+                is_copper = true;
 
-                    if( aPad->GetAttribute() != PAD_ATTRIB::NPTH )
-                        layers = LAYER_RANGE( i );
+                if( aPad->GetAttribute() != PAD_ATTRIB::NPTH )
+                    layers = LAYER_RANGE( i );
 
-                    break;
-                }
+                break;
             }
-
-            if( !is_copper )
-                return NULL;
         }
+
+        if( !is_copper )
+            return nullptr;
+
         break;
+    }
 
     default:
         wxLogTrace( "PNS", "unsupported pad type 0x%x", aPad->GetAttribute() );
-        return NULL;
+        return nullptr;
     }
 
     std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
@@ -954,10 +952,12 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad )
     {
         // Fixme (but not urgent). For complex pad shapes, we pass a single simple polygon to the
         // router, otherwise it won't know how to correctly build walkaround 'hulls' for the pad
-        // primitives - it can recognize only simple shapes, but not COMPOUNDs made of multiple shapes.
-        // The proper way to fix this would be to implement SHAPE_COMPOUND::ConvertToSimplePolygon(),
-        // but the complexity of pad polygonization code (see PAD::GetEffectivePolygon), including
-        // approximation error handling makes me slightly scared to do it right now.
+        // primitives - it can recognize only simple shapes, but not COMPOUNDs made of multiple
+        // shapes.
+        // The proper way to fix this would be to implement
+        // SHAPE_COMPOUND::ConvertToSimplePolygon(), but the complexity of pad polygonization code
+        // (see PAD::GetEffectivePolygon), including approximation error handling makes me
+        // slightly scared to do it right now.
 
         // NOTE: PAD::GetEffectivePolygon puts the error on the inside, but we want the error on
         // the outside so that the collision hull is larger than the pad
@@ -996,9 +996,9 @@ std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( PCB_TRACK* aTrack
 
 std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( PCB_ARC* aArc )
 {
-    auto arc = std::make_unique<PNS::ARC>( SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(),
-                                                      aArc->GetWidth() ),
-                                           aArc->GetNetCode() );
+    auto arc = std::make_unique<PNS::ARC>(
+            SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), aArc->GetWidth() ),
+            aArc->GetNetCode() );
 
     arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
     arc->SetParent( aArc );
@@ -1216,8 +1216,10 @@ bool PNS_KICAD_IFACE::IsAnyLayerVisible( const LAYER_RANGE& aLayer ) const
         return false;
 
     for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
+    {
         if( m_view->IsLayerVisible( i ) )
             return true;
+    }
 
     return false;
 }
@@ -1399,11 +1401,13 @@ void PNS_KICAD_IFACE::EraseView()
         m_debugDecorator->Clear();
 }
 
+
 void PNS_KICAD_IFACE_BASE::SetDebugDecorator( PNS::DEBUG_DECORATOR *aDec )
 {
     m_debugDecorator = aDec;
 }
 
+
 void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit )
 {
     if( aItem->IsVirtual() )
@@ -1439,7 +1443,6 @@ void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool
         }
     }
 
-
     m_previewItems->Add( pitem );
     m_view->Update( m_previewItems );
 }
@@ -1471,7 +1474,6 @@ void PNS_KICAD_IFACE::HideItem( PNS::ITEM* aItem )
 
 void PNS_KICAD_IFACE_BASE::RemoveItem( PNS::ITEM* aItem )
 {
-
 }
 
 
@@ -1497,7 +1499,6 @@ void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
 
 void PNS_KICAD_IFACE_BASE::UpdateItem( PNS::ITEM* aItem )
 {
-
 }
 
 
@@ -1571,7 +1572,7 @@ void PNS_KICAD_IFACE_BASE::AddItem( PNS::ITEM* aItem )
 
 void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem )
 {
-    BOARD_CONNECTED_ITEM* newBI = NULL;
+    BOARD_CONNECTED_ITEM* newBI = nullptr;
 
     switch( aItem->Kind() )
     {
@@ -1704,6 +1705,7 @@ void PNS_KICAD_IFACE::UpdateNet( int aNetCode )
 
 }
 
+
 PNS::RULE_RESOLVER* PNS_KICAD_IFACE_BASE::GetRuleResolver()
 {
     return m_ruleResolver;
@@ -1716,6 +1718,7 @@ void PNS_KICAD_IFACE::SetHostTool( PCB_TOOL_BASE* aTool )
     m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
 }
 
+
 void PNS_KICAD_IFACE::SetDisplayOptions( const PCB_DISPLAY_OPTIONS* aDispOptions )
 {
     m_dispOptions = aDispOptions;
diff --git a/pcbnew/router/pns_meander.h b/pcbnew/router/pns_meander.h
index a926323b11..647cee11b3 100644
--- a/pcbnew/router/pns_meander.h
+++ b/pcbnew/router/pns_meander.h
@@ -74,22 +74,31 @@ public:
 
     ///< Minimum meandering amplitude.
     int m_minAmplitude;
+
     ///< Maximum meandering amplitude.
     int m_maxAmplitude;
+
     ///< Meandering period/spacing (see dialog picture for explanation).
     int m_spacing;
+
     ///< Amplitude/spacing adjustment step.
     int m_step;
+
     ///< Length PadToDie.
     int m_lenPadToDie;
+
     ///< Desired length of the tuned line/diff pair (this is in nm, so allow more than board width).
     long long int m_targetLength;
+
     ///< Type of corners for the meandered line.
     MEANDER_STYLE m_cornerStyle;
+
     ///< Rounding percentage (0 - 100).
     int m_cornerRadiusPercentage;
+
     ///< Allowable tuning error.
     int m_lengthTolerance;
+
     ///< Target skew value for diff pair de-skewing.
     int m_targetSkew;
 };
@@ -117,7 +126,7 @@ public:
         m_amplitude = 0;
         m_side = false;
         m_baseIndex = 0;
-        m_currentTarget = NULL;
+        m_currentTarget = nullptr;
         m_meanCornerRadius = 0;
     }
 
@@ -369,7 +378,7 @@ public:
     MEANDERED_LINE()
     {
         // Do not leave uninitialized members, and keep static analyzer quiet:
-        m_placer = NULL;
+        m_placer = nullptr;
         m_dual = false;
         m_width = 0;
         m_baselineOffset = 0;
diff --git a/pcbnew/router/pns_meander_placer.cpp b/pcbnew/router/pns_meander_placer.cpp
index 80d8584919..27e72b955c 100644
--- a/pcbnew/router/pns_meander_placer.cpp
+++ b/pcbnew/router/pns_meander_placer.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -34,10 +34,10 @@ namespace PNS {
 MEANDER_PLACER::MEANDER_PLACER( ROUTER* aRouter ) :
     MEANDER_PLACER_BASE( aRouter )
 {
-    m_currentNode = NULL;
+    m_currentNode = nullptr;
 
     // Init temporary variables (do not leave uninitialized members)
-    m_initialSegment = NULL;
+    m_initialSegment = nullptr;
     m_lastLength = 0;
     m_lastStatus = TOO_SHORT;
 }
@@ -168,7 +168,8 @@ bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int a
 
         m_lastLength += tuned.Length();
 
-        int comp = compareWithTolerance( m_lastLength - aTargetLength, 0, m_settings.m_lengthTolerance );
+        int comp = compareWithTolerance( m_lastLength - aTargetLength, 0,
+                                         m_settings.m_lengthTolerance );
 
         if( comp > 0 )
             m_lastStatus = TOO_LONG;
@@ -219,7 +220,7 @@ bool MEANDER_PLACER::CommitPlacement()
     if( m_currentNode )
         Router()->CommitRouting( m_currentNode );
 
-    m_currentNode = NULL;
+    m_currentNode = nullptr;
     return true;
 }
 
diff --git a/pcbnew/router/pns_meander_placer_base.cpp b/pcbnew/router/pns_meander_placer_base.cpp
index 231a44fae5..9c15fa9438 100644
--- a/pcbnew/router/pns_meander_placer_base.cpp
+++ b/pcbnew/router/pns_meander_placer_base.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -30,7 +30,7 @@ namespace PNS {
 MEANDER_PLACER_BASE::MEANDER_PLACER_BASE( ROUTER* aRouter ) :
         PLACEMENT_ALGO( aRouter )
 {
-    m_world = NULL;
+    m_world = nullptr;
     m_currentWidth = 0;
     m_padToDieLength = 0;
 }
diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h
index cc1ec654a7..c707b367a1 100644
--- a/pcbnew/router/pns_node.h
+++ b/pcbnew/router/pns_node.h
@@ -118,7 +118,7 @@ public:
     {
     }
 
-    void SetWorld( const NODE* aNode, const NODE* aOverride = NULL );
+    void SetWorld( const NODE* aNode, const NODE* aOverride = nullptr );
 
     virtual bool operator()( ITEM* aCandidate ) = 0;
 
@@ -215,7 +215,7 @@ public:
      * @return the obstacle, if found, otherwise empty.
      */
     OPT_OBSTACLE NearestObstacle( const LINE* aLine, int aKindMask = ITEM::ANY_T,
-                                  const std::set<ITEM*>* aRestrictedSet = NULL );
+                                  const std::set<ITEM*>* aRestrictedSet = nullptr );
 
     /**
      * Check if the item collides with anything else in the world, and if found, returns the
@@ -304,7 +304,7 @@ public:
      * @param aOriginSegmentIndex index of aSeg in the resulting line.
      * @return the line
      */
-    const LINE AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex = NULL,
+    const LINE AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex = nullptr,
                              bool aStopAtLockedJoints = false );
 
     ///< Print the contents and joints structure.
@@ -417,7 +417,7 @@ private:
 
     bool isRoot() const
     {
-        return m_parent == NULL;
+        return m_parent == nullptr;
     }
 
     SEGMENT* findRedundantSegment( const VECTOR2I& A, const VECTOR2I& B, const LAYER_RANGE& lr,
diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp
index 26cbfbba62..0c446c3b72 100644
--- a/pcbnew/router/pns_optimizer.cpp
+++ b/pcbnew/router/pns_optimizer.cpp
@@ -40,9 +40,6 @@
 namespace PNS {
 
 
-/**
- *  Cost Estimator Methods
- */
 int COST_ESTIMATOR::CornerCost( const SEG& aA, const SEG& aB )
 {
     DIRECTION_45 dir_a( aA ), dir_b( aB );
@@ -113,9 +110,6 @@ bool COST_ESTIMATOR::IsBetter( const COST_ESTIMATOR& aOther, double aLengthToler
 }
 
 
-/**
- *  Optimizer
- **/
 OPTIMIZER::OPTIMIZER( NODE* aWorld ) :
     m_world( aWorld ),
     m_collisionKindMask( ITEM::ANY_T ),
@@ -134,7 +128,7 @@ struct OPTIMIZER::CACHE_VISITOR
 {
     CACHE_VISITOR( const ITEM* aOurItem, NODE* aNode, int aMask ) :
         m_ourItem( aOurItem ),
-        m_collidingItem( NULL ),
+        m_collidingItem( nullptr ),
         m_node( aNode ),
         m_mask( aMask )
     {}
@@ -273,12 +267,13 @@ bool RESTRICT_VERTEX_RANGE_CONSTRAINT::Check( int aVertex1, int aVertex2, const
 
 
 bool CORNER_COUNT_LIMIT_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE* aOriginLine,
-                                                const SHAPE_LINE_CHAIN& aCurrentPath,
-                                                const SHAPE_LINE_CHAIN& aReplacement )
+                                           const SHAPE_LINE_CHAIN& aCurrentPath,
+                                           const SHAPE_LINE_CHAIN& aReplacement )
 {
     LINE newPath( *aOriginLine, aCurrentPath );
     newPath.Line().Replace( aVertex1, aVertex2, aReplacement );
     int cc = newPath.CountCorners( m_angleMask );
+
     if( cc >= m_minCorners && cc <= m_maxCorners )
         return true;
 
@@ -322,7 +317,9 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
             if( ip.x >=aP.x )
             {
                 if( ipNext.x >aP.x )
+                {
                     result = 1 - result;
+                }
                 else
                 {
                     double d = static_cast<double>( ip.x - aP.x ) *
@@ -333,7 +330,7 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
                     if( !d )
                         return true;  // pt on polyground boundary
 
-                    if( (d > 0) == (ipNext.y > ip.y) )
+                    if( ( d > 0 ) == ( ipNext.y > ip.y ) )
                         result = 1 - result;
                 }
             }
@@ -347,7 +344,7 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
                     if( !d )
                         return true;  // pt on polyground boundary
 
-                    if( (d > 0) == (ipNext.y > ip.y) )
+                    if( ( d > 0 ) == ( ipNext.y > ip.y ) )
                         result = 1 - result;
                 }
             }
@@ -508,6 +505,7 @@ bool OPTIMIZER::mergeObtuse( LINE* aLine )
                     if( !checkColliding( &opt_track ) )
                     {
                         current_path.Replace( s1.Index() + 1, s2.Index(), ip );
+
                         // removeCachedSegments(aLine, s1.Index(), s2.Index());
                         n_segs = current_path.SegmentCount();
                         found_anything = true;
@@ -627,7 +625,8 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult, LINE* aRoot )
     {
         const int angleMask = DIRECTION_45::ANG_OBTUSE;
         int rootObtuseCorners = aRoot->CountCorners( angleMask );
-        auto c = new CORNER_COUNT_LIMIT_CONSTRAINT( m_world, rootObtuseCorners, aLine->SegmentCount(), angleMask );
+        auto c = new CORNER_COUNT_LIMIT_CONSTRAINT( m_world, rootObtuseCorners,
+                                                    aLine->SegmentCount(), angleMask );
         AddConstraint( c );
     }
 
@@ -705,7 +704,7 @@ bool OPTIMIZER::mergeStep( LINE* aLine, SHAPE_LINE_CHAIN& aCurrentPath, int step
         const SEG s2    = aCurrentPath.CSegment( n + step );
 
         SHAPE_LINE_CHAIN path[2];
-        SHAPE_LINE_CHAIN* picked = NULL;
+        SHAPE_LINE_CHAIN* picked = nullptr;
         int cost[2];
 
         for( int i = 0; i < 2; i++ )
@@ -785,6 +784,7 @@ OPTIMIZER::BREAKOUT_LIST OPTIMIZER::customBreakouts( int aWidth, const ITEM* aIt
         VECTOR2I v0( p0 + VECTOR2I( length, 0 ).Rotate( angle * M_PI / 180.0 ) );
         SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
         int n = convex->Vertices().Intersect( SEG( p0, v0 ), intersections );
+
         // if n == 1 intersected a segment
         // if n == 2 intersected the common point of 2 segments
         // n == 0 can not happen I think, but...
@@ -918,7 +918,7 @@ ITEM* OPTIMIZER::findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const
     JOINT* jt = m_world->FindJoint( aP, aLayer, aNet );
 
     if( !jt )
-        return NULL;
+        return nullptr;
 
     for( ITEM* item : jt->LinkList() )
     {
@@ -926,7 +926,7 @@ ITEM* OPTIMIZER::findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const
             return item;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -1152,7 +1152,8 @@ int findCoupledVertices( const VECTOR2I& aVertex, const SEG& aOrigSeg,
 
         if( s.ApproxParallel( aOrigSeg ) )
         {
-            int64_t dist = int64_t{(( projOverCoupled - aVertex ).EuclideanNorm())} - aPair->Width();
+            int64_t dist =
+                    int64_t{ ( ( projOverCoupled - aVertex ).EuclideanNorm() ) } - aPair->Width();
 
             if( aPair->GapConstraint().Matches( dist ) )
             {
@@ -1450,8 +1451,8 @@ bool tightenSegment( bool dir, NODE *aNode, const LINE& cur, const SHAPE_LINE_CH
 
         snew.Clear();
         snew.Append( a.A );
-        snew.Append( a.B + (a.A - a.B).Resize( current ) );
-        snew.Append( b.A + (b.B - b.A).Resize( current ) );
+        snew.Append( a.B + ( a.A - a.B ).Resize( current ) );
+        snew.Append( b.A + ( b.B - b.A ).Resize( current ) );
         snew.Append( b.B );
 
         step /= 2;
@@ -1496,7 +1497,7 @@ void Tighten( NODE *aNode, const SHAPE_LINE_CHAIN& aOldLine, const LINE& aNewLin
     {
         current.Simplify();
 
-        for( int i = 0; i <= current.SegmentCount() - 3; i++)
+        for( int i = 0; i <= current.SegmentCount() - 3; i++ )
         {
             SHAPE_LINE_CHAIN l_in, l_out;
 
@@ -1507,8 +1508,8 @@ void Tighten( NODE *aNode, const SHAPE_LINE_CHAIN& aOldLine, const LINE& aNewLin
                 if( tightenSegment( dir ? true : false, aNode, aNewLine, l_in, l_out ) )
                 {
                     SHAPE_LINE_CHAIN opt = current;
-                    opt.Replace(i, i + 3, l_out);
-                    auto optArea  = std::abs( shovedArea( aOldLine, opt ) );
+                    opt.Replace( i, i + 3, l_out );
+                    auto optArea = std::abs( shovedArea( aOldLine, opt ) );
                     auto prevArea = std::abs( shovedArea( aOldLine, current ) );
 
                     if( optArea < prevArea )
@@ -1520,7 +1521,7 @@ void Tighten( NODE *aNode, const SHAPE_LINE_CHAIN& aOldLine, const LINE& aNewLin
         }
     }
 
-    aOptimized = LINE(aNewLine, current);
+    aOptimized = LINE( aNewLine, current );
 
     //auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
     //dbg->AddLine ( current, 4, 100000 );
diff --git a/pcbnew/router/pns_shove.cpp b/pcbnew/router/pns_shove.cpp
index 7a3aac7190..57586a1775 100644
--- a/pcbnew/router/pns_shove.cpp
+++ b/pcbnew/router/pns_shove.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -58,6 +58,7 @@ void SHOVE::replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew )
     m_currentNode->Replace( aOld, std::move( aNew ) );
 }
 
+
 void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NODE* aNode )
 {
     if( aIncludeInChangedArea )
@@ -71,7 +72,8 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD
                 Dbg()->AddBox( *changed_area, BLUE, "shove-changed-area" );
             }
 
-        m_affectedArea = m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
+            m_affectedArea =
+                    m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
         }
     }
 
@@ -80,12 +82,15 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD
 
     // Keep track of the 'root lines', i.e. the unmodified (pre-shove) versions
     // of the affected tracks in a map. The optimizer can then query the pre-shove shape
-    // for each shoved line and perform additional constraint checks (i.e. prevent overzealous optimizations)
+    // for each shoved line and perform additional constraint checks (i.e. prevent overzealous
+    // optimizations)
 
-    // Check if the shoved line already has an ancestor (e.g. line from a previous shove iteration/cursor movement)
+    // Check if the shoved line already has an ancestor (e.g. line from a previous shove
+    // iteration/cursor movement)
     for( auto link : aOld.Links() )
     {
         auto oldLineIter = m_rootLineHistory.find( link );
+
         if( oldLineIter != m_rootLineHistory.end() )
         {
             rootLine = oldLineIter->second;
@@ -103,6 +108,7 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD
             {
                 rootLine = aOld.Clone();
             }
+
             m_rootLineHistory[link] = rootLine;
         }
     }
@@ -124,6 +130,7 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD
     }
 }
 
+
 int SHOVE::getClearance( const ITEM* aA, const ITEM* aB ) const
 {
     if( m_forceClearance >= 0 )
@@ -132,6 +139,7 @@ int SHOVE::getClearance( const ITEM* aA, const ITEM* aB ) const
     return m_currentNode->GetClearance( aA, aB );
 }
 
+
 int SHOVE::getHoleClearance( const ITEM* aA, const ITEM* aB ) const
 {
     if( m_forceClearance >= 0 )
@@ -157,7 +165,7 @@ SHOVE::SHOVE( NODE* aWorld, ROUTER* aRouter ) :
     SetDebugDecorator( aRouter->GetInterface()->GetDebugDecorator() );
 
     // Initialize other temporary variables:
-    m_draggedVia = NULL;
+    m_draggedVia = nullptr;
     m_iter = 0;
     m_multiLineMode = false;
     m_restrictSpringbackTagId = 0;
@@ -167,9 +175,11 @@ SHOVE::SHOVE( NODE* aWorld, ROUTER* aRouter ) :
 SHOVE::~SHOVE()
 {
     std::unordered_set<LINE*> alreadyDeleted;
+
     for( auto it : m_rootLineHistory )
     {
         auto it2 = alreadyDeleted.find( it.second );
+
         if( it2 == alreadyDeleted.end() )
         {
             alreadyDeleted.insert( it.second );
@@ -184,14 +194,15 @@ LINE SHOVE::assembleLine( const LINKED_ITEM* aSeg, int* aIndex )
     return m_currentNode->AssembleLine( const_cast<LINKED_ITEM*>( aSeg ), aIndex, true );
 }
 
+
 // A dumb function that checks if the shoved line is shoved the right way, e.g. visually
 // "outwards" of the line/via applying pressure on it. Unfortunately there's no mathematical
 // concept of orientation of an open curve, so we use some primitive heuristics: if the shoved
 // line wraps around the start of the "pusher", it's likely shoved in wrong direction.
 
-// Update: there's no concept of an orientation of an open curve, but nonetheless Tom's dumb as.... (censored)
+// Update: there's no concept of an orientation of an open curve, but nonetheless Tom's dumb
+// as.... (censored)
 // Two open curves put together make a closed polygon... Tom should learn high school geometry!
-
 bool SHOVE::checkShoveDirection( const LINE& aCurLine, const LINE& aObstacleLine,
                                  const LINE& aShovedLine ) const
 {
@@ -280,9 +291,13 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
             PNS_DBG( Dbg(), AddLine, hull, YELLOW, 10000, "hull" );
             PNS_DBG( Dbg(), AddLine, path, WHITE, l.Width(), "path" );
             PNS_DBG( Dbg(), AddLine, obs, LIGHTGRAY, aObstacleLine.Width(), "obs" );
-            if( ! l.Walkaround( hull, path, clockwise ) )
+
+            if( !l.Walkaround( hull, path, clockwise ) )
             {
-                PNS_DBG( Dbg(), Message, wxString::Format( "Fail-Walk %s %s %d\n", hull.Format().c_str(), l.CLine().Format().c_str(), clockwise? 1:0) );
+                PNS_DBG( Dbg(), Message, wxString::Format( "Fail-Walk %s %s %d\n",
+                                                           hull.Format().c_str(),
+                                                           l.CLine().Format().c_str(),
+                                                           clockwise? 1 : 0) );
                 return SH_INCOMPLETE;
             }
 
@@ -300,6 +315,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
         }
 
         int k = obs.PointCount() - 1;
+
         for( int i = path.PointCount() - 1; i >= 0 && k >= 0; i--, k-- )
         {
             if( path.CPoint( i ) != obs.CPoint( k ) )
@@ -323,15 +339,16 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
 
         if( !checkShoveDirection( aCurLine, aObstacleLine, l ) )
         {
-            PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail direction-check", attempt ) );
+            PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail direction-check",
+                                                       attempt ) );
             aResultLine.SetShape( l.CLine() );
-
             continue;
         }
 
         if( path.SelfIntersecting() )
         {
-            PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail self-intersect", attempt ) );
+            PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail self-intersect",
+                                                       attempt ) );
             continue;
         }
 
@@ -413,9 +430,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveObstacleLine( const LINE& aCurLine, const LINE&
 
 #ifdef DEBUG
         Dbg()->Message( wxString::Format( "shove process-single: cur net %d obs %d cl %d",
-                                          aCurLine.Net(),
-                                          aObstacleLine.Net(),
-                                          clearance ) );
+                                          aCurLine.Net(), aObstacleLine.Net(), clearance ) );
 #endif
 
         for( int i = 0; i < currentLineSegmentCount; i++ )
@@ -485,15 +500,18 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacl
 
     if( Dbg() )
     {
-        Dbg()->BeginGroup( wxString::Format( "on-colliding-segment-iter-%d", m_iter ).ToStdString() );
+        Dbg()->BeginGroup( wxString::Format( "on-colliding-segment-iter-%d",
+                                             m_iter ).ToStdString() );
         Dbg()->AddSegment( tmp.Seg(), WHITE, "obstacle-segment" );
         Dbg()->AddLine( aCurrent.CLine(), RED, 10000, "current-line" );
         Dbg()->AddLine( obstacleLine.CLine(), GREEN, 10000, "obstacle-line" );
         Dbg()->AddLine( shovedLine.CLine(), BLUE, 10000, "shoved-line" );
+
         if( rv == SH_OK )
-            Dbg()->Message("Shove success");
+            Dbg()->Message( "Shove success" );
         else
-            Dbg()->Message("Shove FAIL");
+            Dbg()->Message( "Shove FAIL" );
+
         Dbg()->EndGroup();
     }
 
@@ -636,7 +654,7 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle )
     if( aCurrent.EndsWithVia() )
     {
         VIA vh = aCurrent.Via();
-        VIA* via = NULL;
+        VIA* via = nullptr;
         JOINT* jtStart = m_currentNode->FindJoint( vh.Pos(), &aCurrent );
 
         if( !jtStart )
@@ -720,7 +738,9 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle )
                     success = true;
                     break;
                 }
-            } else {
+            }
+            else
+            {
                 success = true;
                 break;
             }
@@ -771,7 +791,9 @@ NODE* SHOVE::reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia
             m_nodeStack.pop_back();
         }
         else
+        {
            break;
+        }
     }
 
     return m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
@@ -803,10 +825,13 @@ bool SHOVE::pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aD
             st.m_affectedArea = prev_area->Merge( *aAffectedArea );
         else
             st.m_affectedArea = aAffectedArea;
-    } else
+    }
+    else
+    {
         st.m_affectedArea = prev_area;
+    }
 
-    st.m_seq = (m_nodeStack.empty() ? 1 : m_nodeStack.back().m_seq + 1);
+    st.m_seq = ( m_nodeStack.empty() ? 1 : m_nodeStack.back().m_seq + 1 );
     st.m_locked = false;
 
     m_nodeStack.push_back( st );
@@ -834,7 +859,8 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in
 
     if( !jt )
     {
-        PNS_DBG( Dbg(), Message, wxString::Format( "weird, can't find the center-of-via joint\n" ) );
+        PNS_DBG( Dbg(), Message,
+                 wxString::Format( "weird, can't find the center-of-via joint\n" ) );
         return SH_INCOMPLETE;
     }
 
@@ -885,10 +911,8 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in
         }
     }
 
-
     pushedVia->SetRank( aCurrentRank - 1 );
 
-
     if( aVia->Marker() & MK_HEAD )      // push
     {
         m_draggedVia = pushedVia.get();
@@ -899,7 +923,6 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in
             pushLineStack( LINE( *pushedVia ) );
     }
 
-
     PNS_DBG( Dbg(), AddPoint, aVia->Pos(), LIGHTGREEN, 100000, "via-pre" );
     PNS_DBG( Dbg(), AddPoint, pushedVia->Pos(), LIGHTRED, 100000, "via-post" );
 
@@ -965,7 +988,9 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia )
         m_logger.Log( currentLine, 4, "current" );
 #endif
 
-        lineCollision = aObstacleVia->Shape()->Collide( currentLine->Shape(), clearance + currentLine->Width() / 2, &mtvLine );
+        lineCollision = aObstacleVia->Shape()->Collide( currentLine->Shape(),
+                                                        clearance + currentLine->Width() / 2,
+                                                        &mtvLine );
 
         // Check the via if present. Via takes priority.
         if( currentLine->EndsWithVia() )
@@ -973,7 +998,8 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia )
             const VIA& currentVia = currentLine->Via();
             int        viaClearance = getClearance( &currentVia, aObstacleVia );
 
-            viaCollision = aObstacleVia->Shape()->Collide( currentVia.Shape(), viaClearance, &mtvVia );
+            viaCollision = aObstacleVia->Shape()->Collide( currentVia.Shape(), viaClearance,
+                                                           &mtvVia );
         }
     }
     else if( aCurrent->OfKind( ITEM::SOLID_T ) )
@@ -1137,6 +1163,7 @@ bool SHOVE::pushLineStack( const LINE& aL, bool aKeepCurrentOnTop )
     return true;
 }
 
+
 void SHOVE::popLineStack( )
 {
     LINE& l = m_lineStack.back();
@@ -1179,8 +1206,11 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
     for( ITEM::PnsKind search_order : { ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } )
     {
          nearest = m_currentNode->NearestObstacle( &currentLine, search_order );
-         if (nearest)
-            PNS_DBG( Dbg(), Message, wxString::Format( "nearest %p %s", nearest->m_item, nearest->m_item->KindStr() ) );
+
+         if( nearest )
+             PNS_DBG( Dbg(), Message,
+                      wxString::Format( "nearest %p %s", nearest->m_item,
+                                        nearest->m_item->KindStr() ) );
 
          if( nearest )
             break;
@@ -1221,11 +1251,13 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
 
         case ITEM::SEGMENT_T:
         {
-            PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-segment ", aIter ) );
+            PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-segment ",
+                                                       aIter ) );
             LINE revLine = assembleLine( static_cast<SEGMENT*>( ni ) );
 
             popLineStack();
             st = onCollidingLine( revLine, currentLine );
+
             if( !pushLineStack( revLine ) )
                 return SH_INCOMPLETE;
 
@@ -1240,6 +1272,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
 
             popLineStack();
             st = onCollidingLine( revLine, currentLine );
+
             if( !pushLineStack( revLine ) )
                 return SH_INCOMPLETE;
 
@@ -1312,8 +1345,9 @@ SHOVE::SHOVE_STATUS SHOVE::shoveMainLoop()
 
     m_affectedArea = OPT_BOX2I();
 
-    PNS_DBG( Dbg(), Message, wxString::Format( "ShoveStart [root: %d jts, current: %d jts]", m_root->JointCount(),
-           m_currentNode->JointCount() ) );
+    PNS_DBG( Dbg(), Message, wxString::Format( "ShoveStart [root: %d jts, current: %d jts]",
+                                               m_root->JointCount(),
+                                               m_currentNode->JointCount() ) );
 
     int iterLimit = Settings().ShoveIterationLimit();
     TIME_LIMIT timeLimit = Settings().ShoveTimeLimit();
@@ -1331,7 +1365,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveMainLoop()
 
     while( !m_lineStack.empty() )
     {
-        PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: node %p stack %d ", m_iter, m_currentNode, (int) m_lineStack.size() ) );
+        PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: node %p stack %d ", m_iter,
+                                                   m_currentNode, (int) m_lineStack.size() ) );
 
         st = shoveIteration( m_iter );
 
@@ -1376,7 +1411,6 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
     }
 
     // empty head? nothing to shove...
-
     if( !aCurrentHead.SegmentCount() && !aCurrentHead.EndsWithVia() )
         return SH_INCOMPLETE;
 
@@ -1386,6 +1420,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
     m_lineStack.clear();
     m_optimizerQueue.clear();
     m_newHead = OPT_LINE();
+
 #if 0
     m_logger.Clear();
 #endif
@@ -1400,7 +1435,6 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
     NODE* parent = reduceSpringback( headSet, dummyVia );
 
     // Create a new NODE to store this version of the world
-    //
     m_currentNode = parent->Branch();
     m_currentNode->ClearRanks();
     m_currentNode->Add( head );
@@ -1413,9 +1447,8 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
     head.Mark( MK_HEAD );
     head.SetRank( 100000 );
 
-    if ( Dbg() )
+    if( Dbg() )
     {
-
         Dbg()->BeginGroup( "initial" );
         Dbg()->AddLine(head.CLine(), CYAN, head.Width(), "head" );
         Dbg()->EndGroup();
@@ -1501,6 +1534,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
 
     m_lineStack.clear();
     m_optimizerQueue.clear();
+
 #if 0
     m_logger.Clear();
 #endif
@@ -1560,6 +1594,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
     return st;
 }
 
+
 static VIA* findViaByHandle ( NODE *aNode, const VIA_HANDLE& handle )
 {
     JOINT* jt = aNode->FindJoint( handle.pos, handle.layers.Start(), handle.net );
@@ -1579,14 +1614,16 @@ static VIA* findViaByHandle ( NODE *aNode, const VIA_HANDLE& handle )
     return nullptr;
 }
 
-SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere, VIA_HANDLE& aNewVia )
+
+SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
+                                             VIA_HANDLE& aNewVia )
 {
-     SHOVE_STATUS st = SH_OK;
+    SHOVE_STATUS st = SH_OK;
 
     m_lineStack.clear();
     m_optimizerQueue.clear();
     m_newHead = OPT_LINE();
-    m_draggedVia = NULL;
+    m_draggedVia = nullptr;
 
     VIA* viaToDrag = findViaByHandle( m_currentNode, aOldVia );
 
@@ -1609,7 +1646,6 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VEC
     }
 
     // Create a new NODE to store this version of the world
-    //
     m_currentNode = parent->Branch();
     m_currentNode->ClearRanks();
 
@@ -1617,11 +1653,9 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VEC
     viaToDrag->SetRank( 100000 );
 
     // Push the via to its new location
-    //
     st = pushOrShoveVia( viaToDrag, ( aWhere - viaToDrag->Pos() ), 0 );
 
     // Shove any colliding objects out of the way
-    //
     if( st == SH_OK )
         st = shoveMainLoop();
 
@@ -1795,6 +1829,7 @@ bool SHOVE::RewindSpringbackTo( NODE* aNode )
             found = true;
             break;
         }
+
         iter++;
     }
 
@@ -1821,6 +1856,7 @@ void SHOVE::UnlockSpringbackNode( NODE* aNode )
             iter->m_locked = false;
             break;
         }
+
         iter++;
     }
 }
diff --git a/pcbnew/router/pns_shove.h b/pcbnew/router/pns_shove.h
index 036f4db92b..c3ed7c5037 100644
--- a/pcbnew/router/pns_shove.h
+++ b/pcbnew/router/pns_shove.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -40,11 +40,8 @@ class NODE;
 class ROUTER;
 
 /**
- * SHOVE
- *
  * The actual Push and Shove algorithm.
  */
-
 class SHOVE : public ALGO_BASE
 {
 public:
@@ -69,8 +66,10 @@ public:
     SHOVE_STATUS ShoveLines( const LINE& aCurrentHead );
     SHOVE_STATUS ShoveMultiLines( const ITEM_SET& aHeadSet );
 
-    SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere, VIA_HANDLE& aNewVia );
-    SHOVE_STATUS ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine, LINE& aResultLine );
+    SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
+                                   VIA_HANDLE& aNewVia );
+    SHOVE_STATUS ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine,
+                                    LINE& aResultLine );
 
     void ForceClearance ( bool aEnabled, int aClearance )
     {
@@ -145,10 +144,11 @@ private:
     bool pushLineStack( const LINE& aL, bool aKeepCurrentOnTop = false );
     void popLineStack();
 
-    LINE assembleLine( const LINKED_ITEM* aSeg, int* aIndex = NULL );
+    LINE assembleLine( const LINKED_ITEM* aSeg, int* aIndex = nullptr );
 
     void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
-    void replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea = true, NODE *aNode = nullptr );
+    void replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea = true,
+                      NODE *aNode = nullptr );
 
     LINE* findRootLine( LINE *aLine );
 
@@ -160,6 +160,8 @@ private:
     int getClearance( const ITEM* aA, const ITEM* aB ) const;
     int getHoleClearance( const ITEM* aA, const ITEM* aB ) const;
 
+    void sanityCheck( LINE* aOld, LINE* aNew );
+
     std::vector<SPRINGBACK_TAG> m_nodeStack;
     std::vector<LINE>           m_lineStack;
     std::vector<LINE>           m_optimizerQueue;
@@ -177,7 +179,6 @@ private:
     int                         m_iter;
     int m_forceClearance;
     bool m_multiLineMode;
-    void sanityCheck( LINE* aOld, LINE* aNew );
 };
 
 }
diff --git a/pcbnew/router/pns_solid.h b/pcbnew/router/pns_solid.h
index a981fd407d..8c3647bdf3 100644
--- a/pcbnew/router/pns_solid.h
+++ b/pcbnew/router/pns_solid.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013  CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -37,8 +37,8 @@ class SOLID : public ITEM
 public:
     SOLID() :
         ITEM( SOLID_T ),
-        m_shape( NULL ),
-        m_hole( NULL )
+        m_shape( nullptr ),
+        m_hole( nullptr )
     {
         m_movable = false;
         m_padToDie = 0;
diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp
index 6ec92399a5..51aa27d843 100644
--- a/pcbnew/router/pns_tool_base.cpp
+++ b/pcbnew/router/pns_tool_base.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013  CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -174,9 +174,9 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b
                 }
             }
         }
-        // Allow unconnected items as last resort in RM_MarkObstacles mode
         else if ( item->Net() == 0 && m_router->Settings().Mode() == RM_MarkObstacles )
         {
+            // Allow unconnected items as last resort in RM_MarkObstacles mode
             if( item->OfKind( ITEM::SOLID_T ) && aIgnorePads )
                 continue;
 
@@ -185,7 +185,7 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b
         }
     }
 
-    ITEM* rv = NULL;
+    ITEM* rv = nullptr;
 
     bool highContrast = ( displayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL );
 
@@ -205,7 +205,8 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b
 
     if( rv )
     {
-        wxLogTrace( "PNS", "%s, layer : %d, tl: %d", rv->KindStr().c_str(), rv->Layers().Start(), tl );
+        wxLogTrace( "PNS", "%s, layer : %d, tl: %d", rv->KindStr().c_str(), rv->Layers().Start(),
+                    tl );
     }
 
     return rv;
@@ -236,6 +237,7 @@ void TOOL_BASE::highlightNet( bool aEnabled, int aNetcode )
     getView()->UpdateAllLayersColor();
 }
 
+
 bool TOOL_BASE::checkSnap( ITEM *aItem )
 {
     // Sync PNS engine settings with the general PCB editor options.
@@ -260,6 +262,7 @@ bool TOOL_BASE::checkSnap( ITEM *aItem )
     return false;
 }
 
+
 void TOOL_BASE::updateStartItem( const TOOL_EVENT& aEvent, bool aIgnorePads )
 {
     int      tl = getView()->GetTopLayer();
@@ -381,9 +384,9 @@ const VECTOR2I TOOL_BASE::snapToItem( ITEM* aItem, VECTOR2I aP )
         {
             return ( distA_sq < distB_sq ) ? A : B;
         }
-        // TODO(snh): Clean this up
         else if( aItem->Kind() == ITEM::SEGMENT_T )
         {
+            // TODO(snh): Clean this up
             SEGMENT* seg = static_cast<SEGMENT*>( li );
             return m_gridHelper->AlignToSegment( aP, seg->Seg() );
         }
@@ -392,8 +395,9 @@ const VECTOR2I TOOL_BASE::snapToItem( ITEM* aItem, VECTOR2I aP )
             ARC* arc = static_cast<ARC*>( li );
             return m_gridHelper->AlignToArc( aP, *static_cast<const SHAPE_ARC*>( arc->Shape() ) );
         }
-    }
+
         break;
+    }
 
     default:
         break;
diff --git a/pcbnew/router/pns_topology.cpp b/pcbnew/router/pns_topology.cpp
index da2193ebae..0958655725 100644
--- a/pcbnew/router/pns_topology.cpp
+++ b/pcbnew/router/pns_topology.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -151,7 +151,7 @@ ITEM* TOPOLOGY::NearestUnconnectedItem( JOINT* aStart, int* aAnchor, int aKindMa
     }
 
     int best_dist = INT_MAX;
-    ITEM* best = NULL;
+    ITEM* best = nullptr;
 
     for( ITEM* item : disconnected )
     {
@@ -187,14 +187,14 @@ bool TOPOLOGY::followTrivialPath( LINE* aLine, bool aLeft, ITEM_SET& aSet,
     LINKED_ITEM* last   = aLeft ? aLine->Links().front() : aLine->Links().back();
     JOINT*       jt     = m_world->FindJoint( anchor, aLine );
 
-    assert( jt != NULL );
+    assert( jt != nullptr );
 
     aVisited.insert( last );
 
     if( jt->IsNonFanoutVia() || jt->IsTraceWidthChange() )
     {
-        ITEM* via = NULL;
-        SEGMENT* next_seg = NULL;
+        ITEM* via = nullptr;
+        SEGMENT* next_seg = nullptr;
 
         for( ITEM* link : jt->Links().Items() )
         {
@@ -450,22 +450,24 @@ bool TOPOLOGY::AssembleDiffPair( ITEM* aStart, DIFF_PAIR& aPair )
 
     m_world->AllItemsInNet( coupledNet, coupledItems );
 
-    SEGMENT* coupledSeg = NULL, *refSeg;
+    SEGMENT* coupledSeg = nullptr, *refSeg;
     int minDist = std::numeric_limits<int>::max();
 
-    if( ( refSeg = dyn_cast<SEGMENT*>( aStart ) ) != NULL )
+    if( ( refSeg = dyn_cast<SEGMENT*>( aStart ) ) != nullptr )
     {
         for( ITEM* item : coupledItems )
         {
             if( SEGMENT* s = dyn_cast<SEGMENT*>( item ) )
             {
-                if( s->Layers().Start() == refSeg->Layers().Start() && s->Width() == refSeg->Width() )
+                if( s->Layers().Start() == refSeg->Layers().Start() &&
+                    s->Width() == refSeg->Width() )
                 {
                     int dist = s->Seg().Distance( refSeg->Seg() );
                     bool isParallel = refSeg->Seg().ApproxParallel( s->Seg() );
                     SEG p_clip, n_clip;
 
-                    bool isCoupled = commonParallelProjection( refSeg->Seg(), s->Seg(), p_clip, n_clip );
+                    bool isCoupled = commonParallelProjection( refSeg->Seg(), s->Seg(), p_clip,
+                                                               n_clip );
 
                     if( isParallel && isCoupled && dist < minDist )
                     {
@@ -530,7 +532,8 @@ const std::set<ITEM*> TOPOLOGY::AssembleCluster( ITEM* aStart, int aLayer )
 
         for( OBSTACLE& obs : obstacles )
         {
-            if( visited.find( obs.m_item ) == visited.end() && obs.m_item->Layers().Overlaps( aLayer ) && !( obs.m_item->Marker() & MK_HEAD ) )
+            if( visited.find( obs.m_item ) == visited.end() &&
+                obs.m_item->Layers().Overlaps( aLayer ) && !( obs.m_item->Marker() & MK_HEAD ) )
             {
                 visited.insert( obs.m_item );
                 pending.push_back( obs.m_item );
diff --git a/pcbnew/router/pns_topology.h b/pcbnew/router/pns_topology.h
index b87d0ddcf7..f02a566580 100644
--- a/pcbnew/router/pns_topology.h
+++ b/pcbnew/router/pns_topology.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2015 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -47,7 +47,8 @@ public:
     ~TOPOLOGY() {};
 
     bool SimplifyLine( LINE *aLine );
-    ITEM* NearestUnconnectedItem( JOINT* aStart, int* aAnchor = NULL, int aKindMask = ITEM::ANY_T );
+    ITEM* NearestUnconnectedItem( JOINT* aStart, int* aAnchor = nullptr,
+                                  int aKindMask = ITEM::ANY_T );
     bool LeadingRatLine( const LINE* aTrack, SHAPE_LINE_CHAIN& aRatLine );
 
     const JOINT_SET ConnectedJoints( JOINT* aStart );
@@ -56,10 +57,11 @@ public:
     int64_t ShortestConnectionLength( ITEM* aFrom, ITEM* aTo );
 
     /**
-     * Assembles a trivial path between two joints given a starting item
-     * @param aStart is the item to assemble from
-     * @param aTerminalJoints will be filled with the start and end points of the assembled path
-     * @return a set of items in the path
+     * Assemble a trivial path between two joints given a starting item.
+     *
+     * @param aStart is the item to assemble from.
+     * @param aTerminalJoints will be filled with the start and end points of the assembled path.
+     * @return a set of items in the path.
      */
     const ITEM_SET AssembleTrivialPath( ITEM* aStart,
                                         std::pair<JOINT*, JOINT*>* aTerminalJoints = nullptr );
@@ -69,12 +71,12 @@ public:
      * that are fully inside pads, and truncates segments that cross into a pad (adding a straight-
      * line segment from the intersection to the pad anchor).
      *
-     * NOTE: When changing this, sync with BOARD::GetTrackLength()
+     * @note When changing this, sync with BOARD::GetTrackLength()
      *
-     * @param aStart is the item to assemble a path from
-     * @param aStartPad will be filled with the starting pad of the path, if found
-     * @param aEndPad will be filled with the ending pad of the path, if found
-     * @return an item set containing all the items in the path
+     * @param aStart is the item to assemble a path from.
+     * @param aStartPad will be filled with the starting pad of the path, if found.
+     * @param aEndPad will be filled with the ending pad of the path, if found.
+     * @return an item set containing all the items in the path.
      */
     const ITEM_SET AssembleTuningPath( ITEM* aStart, SOLID** aStartPad = nullptr,
                                        SOLID** aEndPad = nullptr );
diff --git a/pcbnew/router/pns_walkaround.cpp b/pcbnew/router/pns_walkaround.cpp
index 6b5817e756..8ef1810ebf 100644
--- a/pcbnew/router/pns_walkaround.cpp
+++ b/pcbnew/router/pns_walkaround.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -40,7 +40,8 @@ void WALKAROUND::start( const LINE& aInitialPath )
 
 NODE::OPT_OBSTACLE WALKAROUND::nearestObstacle( const LINE& aPath )
 {
-    NODE::OPT_OBSTACLE obs = m_world->NearestObstacle( &aPath, m_itemMask, m_restrictedSet.empty() ? NULL : &m_restrictedSet );
+    NODE::OPT_OBSTACLE obs = m_world->NearestObstacle(
+            &aPath, m_itemMask, m_restrictedSet.empty() ? nullptr : &m_restrictedSet );
 
     if( m_restrictedSet.empty() )
         return obs;
@@ -68,11 +69,11 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::singleStep( LINE& aPath, bool aWinding
 
     PNS_DBG( Dbg(), BeginGroup, "hull/walk" );
     char name[128];
-    snprintf(name, sizeof(name), "hull-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
-    PNS_DBG( Dbg(), AddLine, current_obs->m_hull, RED, 1, name);
-    snprintf(name, sizeof(name), "path-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
+    snprintf( name, sizeof( name ), "hull-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
+    PNS_DBG( Dbg(), AddLine, current_obs->m_hull, RED, 1, name );
+    snprintf( name, sizeof( name ), "path-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
     PNS_DBG( Dbg(), AddLine, aPath.CLine(), GREEN, 1, name );
-    snprintf(name, sizeof(name), "result-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
+    snprintf( name, sizeof( name ), "result-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
     PNS_DBG( Dbg(), AddLine, path_walk, BLUE, 10000, name );
     PNS_DBG( Dbg(), Message, wxString::Format( "Stat cw %d", !!s_cw ) );
     PNS_DBGN( Dbg(), EndGroup );
@@ -104,7 +105,8 @@ const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath )
     // special case for via-in-the-middle-of-track placement
     if( aInitialPath.PointCount() <= 1 )
     {
-        if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
+        if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(),
+                                                                   m_itemMask ) )
             return RESULT( STUCK, STUCK );
 
         return RESULT( DONE, DONE, aInitialPath, aInitialPath );
@@ -123,7 +125,9 @@ const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath )
         s_cw = m_forceCw ? IN_PROGRESS : STUCK;
         s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
         m_forceSingleDirection = true;
-    } else {
+    }
+    else
+    {
         m_forceSingleDirection = false;
     }
 
@@ -186,12 +190,14 @@ const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath )
         result.statusCw = ALMOST_DONE;
     }
 
-    if( result.lineCcw.SegmentCount() < 1 || result.lineCcw.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
+    if( result.lineCcw.SegmentCount() < 1 ||
+        result.lineCcw.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
     {
         result.statusCcw = STUCK;
     }
 
-    if( result.lineCcw.PointCount() > 0 && result.lineCcw.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
+    if( result.lineCcw.PointCount() > 0 &&
+        result.lineCcw.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
     {
         result.statusCcw = ALMOST_DONE;
     }
@@ -200,9 +206,8 @@ const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath )
 }
 
 
-
-WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
-        LINE& aWalkPath, bool aOptimize )
+WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath, LINE& aWalkPath,
+                                                 bool aOptimize )
 {
     LINE path_cw( aInitialPath ), path_ccw( aInitialPath );
     WALKAROUND_STATUS s_cw = IN_PROGRESS, s_ccw = IN_PROGRESS;
@@ -211,7 +216,8 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
     // special case for via-in-the-middle-of-track placement
     if( aInitialPath.PointCount() <= 1 )
     {
-        if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
+        if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(),
+                                                                   m_itemMask ) )
             return STUCK;
 
         aWalkPath = aInitialPath;
@@ -230,7 +236,9 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
         s_cw = m_forceCw ? IN_PROGRESS : STUCK;
         s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
         m_forceSingleDirection = true;
-    } else {
+    }
+    else
+    {
         m_forceSingleDirection = false;
     }
 
@@ -283,8 +291,10 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
 
     if( aWalkPath.SegmentCount() < 1 )
         return STUCK;
+
     if( aWalkPath.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
         return ALMOST_DONE;
+
     if( aWalkPath.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
         return STUCK;
 
@@ -298,5 +308,4 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::Route( const LINE& aInitialPath,
 
     return st;
 }
-
 }
diff --git a/pcbnew/router/router_preview_item.cpp b/pcbnew/router/router_preview_item.cpp
index bd383f8b4e..5ffd08b4cb 100644
--- a/pcbnew/router/router_preview_item.cpp
+++ b/pcbnew/router/router_preview_item.cpp
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
 
 using namespace KIGFX;
 
+
 ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* aView ) :
     EDA_ITEM( NOT_USED )
 {
@@ -50,7 +51,7 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
     m_showViaClearance = false;
 
     // initialize variables, overwritten by Update( aItem ), if aItem != NULL
-    m_router = NULL;
+    m_router = nullptr;
     m_type = PR_SHAPE;
     m_style = 0;
     m_width = 0;
@@ -299,6 +300,7 @@ void ROUTER_PREVIEW_ITEM::drawShape( const SHAPE* aShape, KIGFX::GAL* gal ) cons
         {
             gal->SetIsStroke( true );
             gal->SetLineWidth( 2 * m_clearance );
+
             // need the implicit last segment to be explicit for DrawPolyline
             polygon.push_back( c->CDPoint( 0 ) );
             gal->DrawPolyline( polygon );
@@ -365,6 +367,7 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
         // Cairo doesn't current support z-ordering, so we need
         // to draw the clearance first to ensure it is in the background
         gal->SetLayerDepth( ClearanceOverlayDepth );
+
         //TODO(snh) Add configuration option for the color/alpha here
         gal->SetStrokeColor( COLOR4D( DARKDARKGRAY ).WithAlpha( 0.9 ) );
         gal->SetFillColor( COLOR4D( DARKDARKGRAY ).WithAlpha( 0.7 ) );
diff --git a/pcbnew/router/router_preview_item.h b/pcbnew/router/router_preview_item.h
index 0e3bee24a0..163f2081dd 100644
--- a/pcbnew/router/router_preview_item.h
+++ b/pcbnew/router/router_preview_item.h
@@ -2,7 +2,7 @@
  * KiRouter - a push-and-(sometimes-)shove PCB router
  *
  * Copyright (C) 2013-2014 CERN
- * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -55,7 +55,7 @@ public:
         PR_SHAPE
     };
 
-    ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem = NULL, KIGFX::VIEW* aView = NULL);
+    ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem = nullptr, KIGFX::VIEW* aView = nullptr);
     ~ROUTER_PREVIEW_ITEM();
 
     void Update( const PNS::ITEM* aItem );
diff --git a/pcbnew/specctra_import_export/specctra.cpp b/pcbnew/specctra_import_export/specctra.cpp
index c6e12ede04..1c5f102b2f 100644
--- a/pcbnew/specctra_import_export/specctra.cpp
+++ b/pcbnew/specctra_import_export/specctra.cpp
@@ -3,7 +3,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2007-2020 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 2007-2021 KiCad Developers, see change_log.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -24,27 +24,28 @@
  */
 
 
-/*  This source file implements export and import capabilities to the
-    specctra dsn file format.  The grammar for that file format is documented
-    fairly well.  There are classes for each major type of descriptor in the
-    spec.
-
-    Since there are so many classes in here, it may be helpful to generate
-    the Doxygen directory:
-
-    $ cd <kicadSourceRoot>
-    $ doxygen
-
-    Then you can view the html documentation in the <kicadSourceRoot>/doxygen
-    directory.  The main class in this file is SPECCTRA_DB and its main
-    functions are LoadPCB(), LoadSESSION(), and ExportPCB().
-
-    Wide use is made of boost::ptr_vector<> and std::vector<> template classes.
-    If the contained object is small, then std::vector tends to be used.
-    If the contained object is large, variable size, or would require writing
-    an assignment operator() or copy constructor, then boost::ptr_vector
-    cannot be beat.
-*/
+/*
+ * This source file implements export and import capabilities to the
+ * specctra dsn file format.  The grammar for that file format is documented
+ * fairly well.  There are classes for each major type of descriptor in the
+ * spec.
+ *
+ * Since there are so many classes in here, it may be helpful to generate
+ * the Doxygen directory:
+ *
+ * $ cd <kicadSourceRoot>
+ * $ doxygen
+ *
+ * Then you can view the html documentation in the <kicadSourceRoot>/doxygen
+ * directory.  The main class in this file is SPECCTRA_DB and its main
+ * functions are LoadPCB(), LoadSESSION(), and ExportPCB().
+ *
+ * Wide use is made of boost::ptr_vector<> and std::vector<> template classes.
+ * If the contained object is small, then std::vector tends to be used.
+ * If the contained object is large, variable size, or would require writing
+ * an assignment operator() or copy constructor, then boost::ptr_vector
+ * cannot be beat.
+ */
 
 
 #include <cstdarg>
@@ -71,6 +72,7 @@ const char* GetTokenText( T aTok )
     return SPECCTRA_LEXER::TokenName( aTok );
 }
 
+
 void SPECCTRA_DB::buildLayerMaps( BOARD* aBoard )
 {
     // specctra wants top physical layer first, then going down to the
@@ -83,8 +85,7 @@ void SPECCTRA_DB::buildLayerMaps( BOARD* aBoard )
     m_kicadLayer2pcb.resize( B_Cu + 1 );
 
 #if 0 // was:
-    for( LAYER_NUM kiNdx = layerCount - 1, pcbNdx=FIRST_LAYER;
-         kiNdx >= 0; --kiNdx, ++pcbNdx )
+    for( LAYER_NUM kiNdx = layerCount - 1, pcbNdx=FIRST_LAYER; kiNdx >= 0; --kiNdx, ++pcbNdx )
     {
         LAYER_NUM kilayer = (kiNdx>0 && kiNdx==layerCount-1) ? F_Cu : kiNdx;
 
@@ -123,14 +124,16 @@ void SPECCTRA_DB::buildLayerMaps( BOARD* aBoard )
 
 int SPECCTRA_DB::findLayerName( const std::string& aLayerName ) const
 {
-    for( int i=0;  i < int( m_layerIds.size()); ++i )
+    for( int i = 0; i < int( m_layerIds.size() ); ++i )
     {
         if( 0 == aLayerName.compare( m_layerIds[i] ) )
             return i;
     }
+
     return -1;
 }
 
+
 void SPECCTRA_DB::readCOMPnPIN( std::string* component_id, std::string* pin_id )
 {
     T      tok;
@@ -158,13 +161,12 @@ void SPECCTRA_DB::readCOMPnPIN( std::string* component_id, std::string* pin_id )
         while( *toktext )
             *pin_id += *toktext++;
     }
-
-    // quoted string:  "U12"-"14" or "U12"-14,  3 tokens in either case
-    else
+    else    // quoted string:  "U12"-"14" or "U12"-14,  3 tokens in either case
     {
         *component_id = CurText();
 
         tok = NextTok();
+
         if( tok!=T_DASH )
             Expecting( pin_def );
 
@@ -184,7 +186,7 @@ void SPECCTRA_DB::readTIME( time_t* time_stamp )
 
     static const char* months[] = {  // index 0 = Jan
         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
+        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", nullptr
     };
 
     NeedSYMBOL();       // month
@@ -192,7 +194,8 @@ void SPECCTRA_DB::readTIME( time_t* time_stamp )
     const char* ptok = CurText();
 
     mytime.tm_mon = 0;      // remains if we don't find a month match.
-    for( int m=0;  months[m];  ++m )
+
+    for( int m = 0; months[m]; ++m )
     {
         if( !strcasecmp( months[m], ptok ) )
         {
@@ -202,38 +205,50 @@ void SPECCTRA_DB::readTIME( time_t* time_stamp )
     }
 
     tok = NextTok();    // day
+
     if( tok != T_NUMBER )
         Expecting( time_toks );
+
     mytime.tm_mday = atoi( CurText() );
 
     tok = NextTok();    // hour
+
     if( tok != T_NUMBER )
         Expecting( time_toks );
+
     mytime.tm_hour = atoi( CurText() );
 
     // : colon
     NeedSYMBOL();
+
     if( *CurText() != ':' || strlen( CurText() )!=1 )
         Expecting( time_toks );
 
     tok = NextTok();    // minute
+
     if( tok != T_NUMBER )
         Expecting( time_toks );
+
     mytime.tm_min = atoi( CurText() );
 
     // : colon
     NeedSYMBOL();
+
     if( *CurText() != ':' || strlen( CurText() )!=1 )
         Expecting( time_toks );
 
     tok = NextTok();    // second
+
     if( tok != T_NUMBER )
         Expecting( time_toks );
+
     mytime.tm_sec = atoi( CurText() );
 
     tok = NextTok();    // year
+
     if( tok != T_NUMBER )
         Expecting( time_toks );
+
     mytime.tm_year = atoi( CurText() ) - 1900;
 
     *time_stamp = mktime( &mytime );
@@ -315,11 +330,13 @@ void SPECCTRA_DB::doPCB( PCB* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_parser:
             if( growth->parser )
                 Unexpected( tok );
+
             growth->parser = new PARSER( growth );
             doPARSER( growth->parser );
             break;
@@ -327,6 +344,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
@@ -334,6 +352,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_resolution:
             if( growth->resolution )
                 Unexpected( tok );
+
             growth->resolution = new UNIT_RES( growth, tok );
             doRESOLUTION( growth->resolution );
             break;
@@ -341,6 +360,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_structure:
             if( growth->structure )
                 Unexpected( tok );
+
             growth->structure = new STRUCTURE( growth );
             doSTRUCTURE( growth->structure );
             break;
@@ -348,6 +368,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_placement:
             if( growth->placement )
                 Unexpected( tok );
+
             growth->placement = new PLACEMENT( growth );
             doPLACEMENT( growth->placement );
             break;
@@ -355,6 +376,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_library:
             if( growth->library )
                 Unexpected( tok );
+
             growth->library = new LIBRARY( growth );
             doLIBRARY( growth->library );
             break;
@@ -362,6 +384,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_network:
             if( growth->network )
                 Unexpected( tok );
+
             growth->network = new NETWORK( growth );
             doNETWORK( growth->network );
             break;
@@ -369,6 +392,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
         case T_wiring:
             if( growth->wiring )
                 Unexpected( tok );
+
             growth->wiring = new WIRING( growth );
             doWIRING( growth->wiring );
             break;
@@ -379,6 +403,7 @@ void SPECCTRA_DB::doPCB( PCB* growth )
     }
 
     tok = NextTok();
+
     if( tok != T_EOF )
         Expecting( T_EOF );
 }
@@ -412,12 +437,15 @@ void SPECCTRA_DB::doPARSER( PARSER* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_STRING_QUOTE:
             tok = NextTok();
+
             if( tok != T_QUOTE_DEF )
                 Expecting( T_QUOTE_DEF );
+
             SetStringDelimiter( (unsigned char) *CurText() );
             growth->string_quote = *CurText();
             m_quote_char = CurText();
@@ -426,8 +454,10 @@ void SPECCTRA_DB::doPARSER( PARSER* growth )
 
         case T_space_in_quoted_tokens:
             tok = NextTok();
+
             if( tok!=T_on && tok!=T_off )
                 Expecting( "on|off" );
+
             SetSpaceInQuotedTokens( tok==T_on );
             growth->space_in_quoted_tokens = (tok==T_on);
             NeedRIGHT();
@@ -460,11 +490,15 @@ void SPECCTRA_DB::doPARSER( PARSER* growth )
             {
                 if( tok!=T_SYMBOL )
                     Expecting( T_SYMBOL );
+
                 tok = NextTok();
+
                 if( tok!=T_NUMBER )
                     Expecting( T_NUMBER );
+
                 // @todo
             }
+
             break;
 
         case T_routes_include:  // [(routes_include {[testpoint | guides | image_conductor]})]
@@ -485,28 +519,35 @@ void SPECCTRA_DB::doPARSER( PARSER* growth )
                     Expecting( "testpoint|guides|image_conductor" );
                 }
             }
+
             break;
 
         case T_wires_include:   // [(wires_include testpoint)]
             tok = NextTok();
+
             if( tok != T_testpoint )
                 Expecting( T_testpoint );
+
             growth->routes_include_testpoint = true;
             NeedRIGHT();
             break;
 
         case T_case_sensitive:
             tok = NextTok();
+
             if( tok!=T_on && tok!=T_off )
                 Expecting( "on|off" );
+
             growth->case_sensitive = (tok==T_on);
             NeedRIGHT();
             break;
 
         case T_via_rotate_first:    // [(via_rotate_first [on | off])]
             tok = NextTok();
+
             if( tok!=T_on && tok!=T_off )
                 Expecting( "on|off" );
+
             growth->via_rotate_first = (tok==T_on);
             NeedRIGHT();
             break;
@@ -541,6 +582,7 @@ void SPECCTRA_DB::doRESOLUTION( UNIT_RES* growth )
     }
 
     tok = NextTok();
+
     if( tok != T_NUMBER )
         Expecting( T_NUMBER );
 
@@ -581,6 +623,7 @@ void SPECCTRA_DB::doSPECCTRA_LAYER_PAIR( SPECCTRA_LAYER_PAIR* growth )
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
+
     growth->layer_weight = strtod( CurText(), 0 );
 
     NeedRIGHT();
@@ -592,7 +635,7 @@ void SPECCTRA_DB::doLAYER_NOISE_WEIGHT( LAYER_NOISE_WEIGHT* growth )
 {
     T       tok;
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
@@ -611,17 +654,19 @@ void SPECCTRA_DB::doSTRUCTURE( STRUCTURE* growth )
 {
     T       tok;
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
@@ -629,6 +674,7 @@ void SPECCTRA_DB::doSTRUCTURE( STRUCTURE* growth )
         case T_resolution:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doRESOLUTION( growth->unit );
             break;
@@ -636,6 +682,7 @@ void SPECCTRA_DB::doSTRUCTURE( STRUCTURE* growth )
         case T_layer_noise_weight:
             if( growth->layer_noise_weight )
                 Unexpected( tok );
+
             growth->layer_noise_weight = new LAYER_NOISE_WEIGHT( growth );
             doLAYER_NOISE_WEIGHT( growth->layer_noise_weight );
             break;
@@ -644,6 +691,7 @@ void SPECCTRA_DB::doSTRUCTURE( STRUCTURE* growth )
 L_place:
             if( growth->place_boundary )
                 Unexpected( tok );
+
             growth->place_boundary = new BOUNDARY( growth, T_place_boundary );
             doBOUNDARY( growth->place_boundary );
             break;
@@ -653,8 +701,10 @@ L_place:
             {
                 if( growth->place_boundary )
                     Unexpected( tok );
+
                 goto L_place;
             }
+
             growth->boundary = new BOUNDARY( growth );
             doBOUNDARY( growth->boundary );
             break;
@@ -683,6 +733,7 @@ L_place:
         case T_via:
             if( growth->via )
                 Unexpected( tok );
+
             growth->via = new VIA( growth );
             doVIA( growth->via );
             break;
@@ -690,6 +741,7 @@ L_place:
         case T_control:
             if( growth->control )
                 Unexpected( tok );
+
             growth->control = new CONTROL( growth );
             doCONTROL( growth->control );
             break;
@@ -704,6 +756,7 @@ L_place:
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -711,6 +764,7 @@ L_place:
         case T_place_rule:
             if( growth->place_rules )
                 Unexpected( tok );
+
             growth->place_rules = new RULE( growth, T_place_rule );
             doRULE( growth->place_rules );
             break;
@@ -759,6 +813,7 @@ void SPECCTRA_DB::doSTRUCTURE_OUT( STRUCTURE_OUT* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_layer:
@@ -771,6 +826,7 @@ void SPECCTRA_DB::doSTRUCTURE_OUT( STRUCTURE_OUT* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -803,11 +859,13 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_sequence_number:
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->sequence_number = atoi( CurText() );
             NeedRIGHT();
             break;
@@ -815,6 +873,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -822,6 +881,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_place_rule:
             if( growth->place_rules )
                 Unexpected( tok );
+
             growth->place_rules = new RULE( growth, T_place_rule );
             doRULE( growth->place_rules );
             break;
@@ -829,6 +889,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_rect:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new RECTANGLE( growth );
             doRECTANGLE( (RECTANGLE*) growth->shape );
             break;
@@ -836,6 +897,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_circle:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new CIRCLE( growth );
             doCIRCLE( (CIRCLE*) growth->shape );
             break;
@@ -848,6 +910,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_polygon:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new PATH( growth, tok );
             doPATH( (PATH*) growth->shape );
             break;
@@ -855,6 +918,7 @@ void SPECCTRA_DB::doKEEPOUT( KEEPOUT* growth )
         case T_qarc:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new QARC( growth );
             doQARC( (QARC*) growth->shape );
             break;
@@ -896,7 +960,7 @@ void SPECCTRA_DB::doCONNECT( CONNECT* growth )
         switch( tok )
         {
         case T_terminal:
-            // since we do not use the terminal information, simlpy toss it.
+            // since we do not use the terminal information, simply toss it.
             while( ( tok = NextTok() ) != T_RIGHT && tok != T_EOF )
                 ;
             break;
@@ -920,11 +984,13 @@ void SPECCTRA_DB::doWINDOW( WINDOW* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_rect:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new RECTANGLE( growth );
             doRECTANGLE( (RECTANGLE*) growth->shape );
             break;
@@ -932,6 +998,7 @@ void SPECCTRA_DB::doWINDOW( WINDOW* growth )
         case T_circle:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new CIRCLE( growth );
             doCIRCLE( (CIRCLE*) growth->shape );
             break;
@@ -944,6 +1011,7 @@ void SPECCTRA_DB::doWINDOW( WINDOW* growth )
         case T_polygon:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new PATH( growth, tok );
             doPATH( (PATH*) growth->shape );
             break;
@@ -951,6 +1019,7 @@ void SPECCTRA_DB::doWINDOW( WINDOW* growth )
         case T_qarc:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new QARC( growth );
             doQARC( (QARC*) growth->shape );
             break;
@@ -972,6 +1041,7 @@ void SPECCTRA_DB::doBOUNDARY( BOUNDARY* growth )
         Expecting( T_LEFT );
 
     tok = NextTok();
+
     if( tok == T_rect )
     {
         if( growth->paths.size() )
@@ -1007,7 +1077,9 @@ void SPECCTRA_DB::doBOUNDARY( BOUNDARY* growth )
         }
     }
     else
+    {
         Expecting( "rect|path" );
+    }
 }
 
 
@@ -1023,7 +1095,7 @@ void SPECCTRA_DB::doPATH( PATH* growth )
     if( NextTok() != T_NUMBER )
         Expecting( "aperture_width" );
 
-    growth->aperture_width = strtod( CurText(), NULL );
+    growth->aperture_width = strtod( CurText(), nullptr );
 
     POINT   ptTemp;
 
@@ -1033,15 +1105,17 @@ void SPECCTRA_DB::doPATH( PATH* growth )
     {
         if( tok != T_NUMBER )
             Expecting( T_NUMBER );
-        ptTemp.x = strtod( CurText(), NULL );
+
+        ptTemp.x = strtod( CurText(), nullptr );
 
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
-        ptTemp.y = strtod( CurText(), NULL );
+
+        ptTemp.y = strtod( CurText(), nullptr );
 
         growth->points.push_back( ptTemp );
 
-    } while( (tok = NextTok())!=T_RIGHT && tok!=T_LEFT );
+    } while( ( tok = NextTok() ) != T_RIGHT && tok != T_LEFT );
 
     if( tok == T_LEFT )
     {
@@ -1049,6 +1123,7 @@ void SPECCTRA_DB::doPATH( PATH* growth )
             Expecting( T_aperture_type );
 
         tok = NextTok();
+
         if( tok!=T_round && tok!=T_square )
             Expecting( "round|square" );
 
@@ -1066,19 +1141,23 @@ void SPECCTRA_DB::doRECTANGLE( RECTANGLE* growth )
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
-    growth->point0.x = strtod( CurText(), NULL );
+
+    growth->point0.x = strtod( CurText(), nullptr );
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
-    growth->point0.y = strtod( CurText(), NULL );
+
+    growth->point0.y = strtod( CurText(), nullptr );
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
-    growth->point1.x = strtod( CurText(), NULL );
+
+    growth->point1.x = strtod( CurText(), nullptr );
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
-    growth->point1.y = strtod( CurText(), NULL );
+
+    growth->point1.y = strtod( CurText(), nullptr );
 
     NeedRIGHT();
 }
@@ -1093,15 +1172,18 @@ void SPECCTRA_DB::doCIRCLE( CIRCLE* growth )
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
+
     growth->diameter = strtod( CurText(), 0 );
 
     tok = NextTok();
+
     if( tok == T_NUMBER )
     {
         growth->vertex.x = strtod( CurText(), 0 );
 
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
+
         growth->vertex.y = strtod( CurText(), 0 );
 
         tok = NextTok();
@@ -1119,16 +1201,19 @@ void SPECCTRA_DB::doQARC( QARC* growth )
 
     if( NextTok() != T_NUMBER )
         Expecting( T_NUMBER );
+
     growth->aperture_width = strtod( CurText(), 0 );
 
-    for( int i=0;  i<3;  ++i )
+    for( int i = 0; i < 3; ++i )
     {
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
+
         growth->vertex[i].x = strtod( CurText(), 0 );
 
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
+
         growth->vertex[i].y = strtod( CurText(), 0 );
     }
 
@@ -1161,7 +1246,7 @@ void SPECCTRA_DB::doVIA( VIA* growth )
 {
     T       tok;
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok == T_LEFT )
         {
@@ -1181,7 +1266,9 @@ void SPECCTRA_DB::doVIA( VIA* growth )
             growth->padstacks.push_back( CurText() );
         }
         else
+        {
             Unexpected( CurText() );
+        }
     }
 }
 
@@ -1196,12 +1283,15 @@ void SPECCTRA_DB::doCONTROL( CONTROL* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_via_at_smd:
             tok = NextTok();
+
             if( tok!=T_on && tok!=T_off )
                 Expecting( "on|off" );
+
             growth->via_at_smd = (tok==T_on);
             NeedRIGHT();
             break;
@@ -1238,7 +1328,7 @@ void SPECCTRA_DB::doPROPERTIES( PROPERTIES* growth )
     T           tok;
     PROPERTY    property;  // construct it once here, append multiple times.
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
@@ -1260,26 +1350,31 @@ void SPECCTRA_DB::doLAYER( LAYER* growth )
 {
     T       tok = NextTok();
 
-    if( !IsSymbol(tok) )
-        Expecting(T_SYMBOL);
+    if( !IsSymbol( tok ) )
+        Expecting( T_SYMBOL );
 
     growth->name = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_type:
             tok = NextTok();
-            if( tok!=T_signal && tok!=T_power && tok!=T_mixed && tok!=T_jumper )
+
+            if( tok != T_signal && tok != T_power && tok != T_mixed && tok != T_jumper )
                 Expecting( "signal|power|mixed|jumper" );
+
             growth->layer_type = tok;
+
             if( NextTok()!=T_RIGHT )
                 Expecting(T_RIGHT);
+
             break;
 
         case T_rule:
@@ -1293,6 +1388,7 @@ void SPECCTRA_DB::doLAYER( LAYER* growth )
 
         case T_direction:
             tok = NextTok();
+
             switch( tok )
             {
             case T_horizontal:
@@ -1316,14 +1412,19 @@ void SPECCTRA_DB::doLAYER( LAYER* growth )
                     growth->direction = T_vertical;
                     break;
                 }
-                Expecting( "horizontal|vertical|orthogonal|positive_diagonal|negative_diagonal|diagonal|off" );
+
+                Expecting( "horizontal|vertical|orthogonal|positive_diagonal|negative_diagonal|"
+                           "diagonal|off" );
             }
-            if( NextTok()!=T_RIGHT )
-                Expecting(T_RIGHT);
+
+            if( NextTok() != T_RIGHT )
+                Expecting( T_RIGHT );
+
             break;
 
         case T_cost:
             tok = NextTok();
+
             switch( tok )
             {
             case T_forbidden:
@@ -1341,34 +1442,41 @@ void SPECCTRA_DB::doLAYER( LAYER* growth )
             default:
                 Expecting( "forbidden|high|medium|low|free|<positive_integer>|-1" );
             }
+
             tok = NextTok();
+
             if( tok == T_LEFT )
             {
                 if( NextTok() != T_type )
                     Unexpected( CurText() );
 
                 tok = NextTok();
+
                 if( tok!=T_length && tok!=T_way )
                     Expecting( "length|way" );
 
                 growth->cost_type = tok;
+
                 if( NextTok()!=T_RIGHT )
-                    Expecting(T_RIGHT);
+                    Expecting( T_RIGHT );
 
                 tok = NextTok();
             }
-            if( tok!=T_RIGHT )
-                Expecting(T_RIGHT);
+
+            if( tok != T_RIGHT )
+                Expecting( T_RIGHT );
+
             break;
 
         case T_use_net:
-            while( (tok = NextTok()) != T_RIGHT )
+            while( ( tok = NextTok() ) != T_RIGHT )
             {
-                if( !IsSymbol(tok) )
+                if( !IsSymbol( tok ) )
                     Expecting( T_SYMBOL );
 
                 growth->use_net.push_back( CurText() );
             }
+
             break;
 
         default:
@@ -1384,27 +1492,26 @@ void SPECCTRA_DB::doRULE( RULE* growth )
     int             bracketNesting = 1; // we already saw the opening T_LEFT
     T               tok = T_NONE;
 
-    while( bracketNesting!=0 && tok!=T_EOF )
+    while( bracketNesting != 0 && tok != T_EOF )
     {
         tok = NextTok();
 
         if( tok==T_LEFT)
             ++bracketNesting;
-
         else if( tok==T_RIGHT )
             --bracketNesting;
 
         if( bracketNesting >= 1 )
         {
-            if( PrevTok()!=T_LEFT && tok!=T_RIGHT && (tok!=T_LEFT || bracketNesting>2) )
+            if( PrevTok() != T_LEFT && tok != T_RIGHT && ( tok != T_LEFT || bracketNesting > 2 ) )
                 builder += ' ';
 
-            if( tok==T_STRING )
+            if( tok == T_STRING )
                 builder += m_quote_char;
 
             builder += CurText();
 
-            if( tok==T_STRING )
+            if( tok == T_STRING )
                 builder += m_quote_char;
         }
 
@@ -1436,11 +1543,12 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type )
 
     T       tok = NextTok();
 
-    if( tok!=T_LEFT )
+    if( tok != T_LEFT )
         Expecting( T_LEFT );
 
     tok = NextTok();
-    if( tok==T_object_type )
+
+    if( tok == T_object_type )
     {
         if( !expect_object_type )
             Unexpected( tok );
@@ -1453,6 +1561,7 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type )
         */
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_pcb:
@@ -1461,6 +1570,7 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type )
 
         case T_image_set:
             tok = NextTok();
+
             switch( tok )
             {
             case T_large:
@@ -1473,6 +1583,7 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type )
             default:
                 Unexpected( CurText() );
             }
+
             break;
 
         default:
@@ -1480,13 +1591,16 @@ void SPECCTRA_DB::doPLACE_RULE( PLACE_RULE* growth, bool expect_object_type )
         }
 
         tok = NextTok();
+
         if( tok == T_LEFT )
         {
             tok = NextTok();
+
             if( tok != T_image_type )
                 Expecting( T_image_type );
 
             tok = NextTok();
+
             if( tok!=T_smd && tok!=T_pin )
                 Expecting( "smd|pin" );
 
@@ -1514,7 +1628,7 @@ void SPECCTRA_DB::doREGION( REGION* growth )
 {
     T     tok = NextTok();
 
-    if( IsSymbol(tok) )
+    if( IsSymbol( tok ) )
     {
         growth->region_id = CurText();
         tok = NextTok();
@@ -1526,11 +1640,13 @@ void SPECCTRA_DB::doREGION( REGION* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_rect:
             if( growth->rectangle )
                 Unexpected( tok );
+
             growth->rectangle = new RECTANGLE( growth );
             doRECTANGLE( growth->rectangle );
             break;
@@ -1538,6 +1654,7 @@ void SPECCTRA_DB::doREGION( REGION* growth )
         case T_polygon:
             if( growth->polygon )
                 Unexpected( tok );
+
             growth->polygon = new PATH( growth, T_polygon );
             doPATH( growth->polygon );
             break;
@@ -1560,6 +1677,7 @@ void SPECCTRA_DB::doREGION( REGION* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -1569,10 +1687,12 @@ void SPECCTRA_DB::doREGION( REGION* growth )
         }
 
         tok = NextTok();
+
         if( tok == T_RIGHT )
         {
             if( !growth->rules )
                 Expecting( T_rule );
+
             break;
         }
     }
@@ -1586,13 +1706,14 @@ void SPECCTRA_DB::doCLASS_CLASS( CLASS_CLASS* growth )
     if( tok != T_LEFT )
         Expecting( T_LEFT );
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         switch( tok )
         {
         case T_classes:
             if( growth->classes )
                 Unexpected( tok );
+
             growth->classes = new CLASSES( growth );
             doCLASSES( growth->classes );
             break;
@@ -1601,6 +1722,7 @@ void SPECCTRA_DB::doCLASS_CLASS( CLASS_CLASS* growth )
             // only T_class_class takes a T_rule
             if( growth->Type() == T_region_class_class )
                 Unexpected( tok );
+
             RULE* rule;
             rule = new RULE( growth, T_rule );
             growth->Append( rule );
@@ -1611,6 +1733,7 @@ void SPECCTRA_DB::doCLASS_CLASS( CLASS_CLASS* growth )
             // only T_class_class takes a T_layer_rule
             if( growth->Type() == T_region_class_class )
                 Unexpected( tok );
+
             LAYER_RULE* layer_rule;
             layer_rule = new LAYER_RULE( growth );
             growth->Append( layer_rule );
@@ -1638,12 +1761,13 @@ void SPECCTRA_DB::doCLASSES( CLASSES* growth )
     do
     {
         tok = NextTok();
+
         if( !IsSymbol( tok ) )
             Expecting( "class_id" );
 
         growth->class_ids.push_back( CurText() );
 
-    } while( (tok = NextTok()) != T_RIGHT );
+    } while( ( tok = NextTok() ) != T_RIGHT );
 }
 
 
@@ -1659,26 +1783,33 @@ void SPECCTRA_DB::doGRID( GRID* growth )
     case T_snap:
     case T_place:
         growth->grid_type = tok;
+
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
+
         growth->dimension = strtod( CurText(), 0 );
         tok = NextTok();
+
         if( tok == T_LEFT )
         {
-            while( (tok=NextTok()) != T_RIGHT )
+            while( ( tok = NextTok() ) != T_RIGHT )
             {
-                if( tok==T_direction )
+                if( tok == T_direction )
                 {
                     if( growth->grid_type == T_place )
                         Unexpected( tok );
+
                     tok = NextTok();
-                    if( tok!=T_x && tok!=T_y )
+
+                    if( tok != T_x && tok != T_y )
                         Unexpected( CurText() );
+
                     growth->direction = tok;
+
                     if( NextTok() != T_RIGHT )
                         Expecting(T_RIGHT);
                 }
-                else if( tok==T_offset )
+                else if( tok == T_offset )
                 {
                     if( growth->grid_type == T_place )
                         Unexpected( tok );
@@ -1689,21 +1820,26 @@ void SPECCTRA_DB::doGRID( GRID* growth )
                     growth->offset = strtod( CurText(), 0 );
 
                     if( NextTok() != T_RIGHT )
-                        Expecting(T_RIGHT);
+                        Expecting( T_RIGHT );
                 }
-                else if( tok==T_image_type )
+                else if( tok == T_image_type )
                 {
                     if( growth->grid_type != T_place )
                         Unexpected( tok );
+
                     tok = NextTok();
-                    if( tok!=T_smd && tok!=T_pin )
+
+                    if( tok != T_smd && tok != T_pin )
                         Unexpected( CurText() );
+
                     growth->image_type = tok;
+
                     if( NextTok() != T_RIGHT )
-                        Expecting(T_RIGHT);
+                        Expecting( T_RIGHT );
                 }
             }
         }
+
         break;
 
     default:
@@ -1722,7 +1858,7 @@ void SPECCTRA_DB::doLAYER_RULE( LAYER_RULE* growth )
     {
         growth->layer_ids.push_back( CurText() );
 
-    }  while( IsSymbol(tok = NextTok()) );
+    } while( IsSymbol( tok = NextTok() ) );
 
     if( tok != T_LEFT )
         Expecting( T_LEFT );
@@ -1747,6 +1883,7 @@ void SPECCTRA_DB::doPLACE( PLACE* growth )
     growth->component_id = CurText();
 
     tok = NextTok();
+
     if( tok == T_NUMBER )
     {
         POINT   point;
@@ -1755,56 +1892,69 @@ void SPECCTRA_DB::doPLACE( PLACE* growth )
 
         if( NextTok() != T_NUMBER )
             Expecting( T_NUMBER );
+
         point.y = strtod( CurText(), 0 );
 
         growth->SetVertex( point );
 
         tok = NextTok();
-        if( tok!=T_front && tok!=T_back )
+
+        if( tok != T_front && tok != T_back )
             Expecting( "front|back" );
+
         growth->side = tok;
 
         if( NextTok() != T_NUMBER )
             Expecting( "rotation" );
-        growth->SetRotation( strtod( CurText(), 0)  );
+
+        growth->SetRotation( strtod( CurText(), 0 ) );
     }
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_mirror:
             tok = NextTok();
-            if( tok==T_x || tok==T_y || tok==T_xy || tok==T_off )
+
+            if( tok == T_x || tok == T_y || tok == T_xy || tok == T_off )
                 growth->mirror = tok;
             else
-                Expecting("x|y|xy|off");
+                Expecting( "x|y|xy|off" );
+
             break;
 
         case T_status:
             tok = NextTok();
+
             if( tok==T_added || tok==T_deleted || tok==T_substituted )
                 growth->status = tok;
             else
                 Expecting("added|deleted|substituted");
+
             break;
 
         case T_logical_part:
             if( growth->logical_part.size() )
                 Unexpected( tok );
+
             tok = NextTok();
+
             if( !IsSymbol( tok ) )
                 Expecting( "logical_part_id");
+
             growth->logical_part = CurText();
             break;
 
         case T_place_rule:
             if( growth->place_rules )
                 Unexpected( tok );
+
             growth->place_rules = new RULE( growth, T_place_rule );
             doRULE( growth->place_rules );
             break;
@@ -1812,20 +1962,24 @@ void SPECCTRA_DB::doPLACE( PLACE* growth )
         case T_property:
             if( growth->properties.size() )
                 Unexpected( tok );
+
             doPROPERTIES( &growth->properties );
             break;
 
         case T_lock_type:
             tok = NextTok();
-            if( tok==T_position || tok==T_gate || tok==T_subgate || tok==T_pin )
+
+            if( tok == T_position || tok == T_gate || tok == T_subgate || tok == T_pin )
                 growth->lock_type = tok;
             else
-                Expecting("position|gate|subgate|pin");
+                Expecting( "position|gate|subgate|pin" );
+
             break;
 
         case T_rule:
             if( growth->rules || growth->region )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -1833,6 +1987,7 @@ void SPECCTRA_DB::doPLACE( PLACE* growth )
         case T_region:
             if( growth->rules || growth->region )
                 Unexpected( tok );
+
             growth->region = new REGION( growth );
             doREGION( growth->region );
             break;
@@ -1840,6 +1995,7 @@ void SPECCTRA_DB::doPLACE( PLACE* growth )
         case T_pn:
             if( growth->part_number.size() )
                 Unexpected( tok );
+
             NeedSYMBOLorNUMBER();
             growth->part_number = CurText();
             NeedRIGHT();
@@ -1858,14 +2014,16 @@ void SPECCTRA_DB::doCOMPONENT( COMPONENT* growth )
 
     if( !IsSymbol( tok ) && tok != T_NUMBER )
         Expecting( "image_id" );
+
     growth->image_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_place:
@@ -1876,7 +2034,7 @@ void SPECCTRA_DB::doCOMPONENT( COMPONENT* growth )
             break;
 
         default:
-            Unexpected(tok);
+            Unexpected( tok );
         }
     }
 }
@@ -1886,7 +2044,7 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth )
 {
     T       tok;
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok == T_EOF )
             Unexpected( T_EOF );
@@ -1901,7 +2059,8 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth )
         case T_unit:
         case T_resolution:
             growth->unit = new UNIT_RES( growth, tok );
-            if( tok==T_resolution )
+
+            if( tok == T_resolution )
                 doRESOLUTION( growth->unit );
             else
                 doUNIT( growth->unit );
@@ -1910,11 +2069,13 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth )
         case T_place_control:
             NeedRIGHT();
             tok = NextTok();
+
             if( tok != T_flip_style )
                 Expecting( T_flip_style );
 
             tok = NextTok();
-            if( tok==T_mirror_first || tok==T_rotate_first )
+
+            if( tok == T_mirror_first || tok == T_rotate_first )
                 growth->flip_style = tok;
             else
                 Expecting( "mirror_first|rotate_first" );
@@ -1956,38 +2117,44 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth )
     */
 
     // padstack_id may be a number
-    if( !IsSymbol( tok ) && tok!=T_NUMBER )
+    if( !IsSymbol( tok ) && tok != T_NUMBER )
         Expecting( "padstack_id" );
 
     growth->padstack_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
 
         case T_rotate:
             tok = NextTok();
-            if( tok!=T_on && tok!=T_off )
+
+            if( tok != T_on && tok != T_off )
                 Expecting( "on|off" );
+
             growth->rotate = tok;
             NeedRIGHT();
             break;
 
         case T_absolute:
             tok = NextTok();
-            if( tok!=T_on && tok!=T_off )
+
+            if( tok != T_on && tok != T_off )
                 Expecting( "on|off" );
+
             growth->absolute = tok;
             NeedRIGHT();
             break;
@@ -2001,10 +2168,13 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth )
 
         case T_attach:
             tok = NextTok();
-            if( tok!=T_off && tok!=T_on )
+
+            if( tok != T_off && tok != T_on )
                 Expecting( "off|on" );
+
             growth->attach = tok;
             tok = NextTok();
+
             if( tok == T_LEFT )
             {
                 if( NextTok() != T_use_via )
@@ -2016,6 +2186,7 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth )
                 NeedRIGHT();
                 NeedRIGHT();
             }
+
             break;
 
         /*
@@ -2024,8 +2195,10 @@ void SPECCTRA_DB::doPADSTACK( PADSTACK* growth )
         */
 
         case T_rule:
+
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -2047,12 +2220,13 @@ void SPECCTRA_DB::doSHAPE( SHAPE* growth )
          [{<window_descriptor> }])
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_polyline_path:
@@ -2067,6 +2241,7 @@ void SPECCTRA_DB::doSHAPE( SHAPE* growth )
 L_done_that:
             if( growth->shape )
                 Unexpected( tok );
+
             break;
 
         default:
@@ -2149,25 +2324,29 @@ void SPECCTRA_DB::doIMAGE( IMAGE* growth )
 
     growth->image_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
 
         case T_side:
             tok = NextTok();
-            if( tok!=T_front && tok!=T_back && tok!=T_both )
+
+            if( tok != T_front && tok != T_back && tok != T_both )
                 Expecting( "front|back|both" );
+
             growth->side = tok;
             NeedRIGHT();
             break;
@@ -2189,6 +2368,7 @@ void SPECCTRA_DB::doIMAGE( IMAGE* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, tok );
             doRULE( growth->rules );
             break;
@@ -2196,6 +2376,7 @@ void SPECCTRA_DB::doIMAGE( IMAGE* growth )
         case T_place_rule:
             if( growth->place_rules )
                 Unexpected( tok );
+
             growth->place_rules = new RULE( growth, tok );
             doRULE( growth->place_rules );
             break;
@@ -2234,32 +2415,36 @@ void SPECCTRA_DB::doPIN( PIN* growth )
 
     growth->padstack_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok == T_LEFT )
         {
             tok = NextTok();
+
             if( tok != T_rotate )
                 Expecting( T_rotate );
 
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->SetRotation( strtod( CurText(), 0 ) );
             NeedRIGHT();
         }
         else
         {
-            if( !IsSymbol(tok) && tok!=T_NUMBER )
+            if( !IsSymbol( tok ) && tok != T_NUMBER )
                 Expecting( "pin_id" );
 
             growth->pin_id = CurText();
 
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->vertex.x = strtod( CurText(), 0 );
 
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->vertex.y = strtod( CurText(), 0 );
         }
     }
@@ -2284,17 +2469,19 @@ void SPECCTRA_DB::doLIBRARY( LIBRARY* growth )
         )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
@@ -2351,12 +2538,13 @@ void SPECCTRA_DB::doNET( NET* growth )
 
     growth->net_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unassigned:
@@ -2367,6 +2555,7 @@ void SPECCTRA_DB::doNET( NET* growth )
         case T_net_number:
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->net_number = atoi( CurText() );
             NeedRIGHT();
             break;
@@ -2400,7 +2589,8 @@ void SPECCTRA_DB::doNET( NET* growth )
 L_pins:
             {
                 PIN_REF     empty( growth );
-                while( (tok = NextTok()) != T_RIGHT )
+
+                while( ( tok = NextTok() ) != T_RIGHT )
                 {
                     // copy the empty one, then fill its copy later thru pin_ref.
                     pin_refs->push_back( empty );
@@ -2410,19 +2600,23 @@ L_pins:
                     readCOMPnPIN( &pin_ref->component_id, &pin_ref->pin_id );
                 }
             }
+
             break;
 
         case T_comp_order:
             if( growth->comp_order )
                 Unexpected( tok );
+
             growth->comp_order = new COMP_ORDER( growth );
             doCOMP_ORDER( growth->comp_order );
             break;
 
         case T_type:
             tok = NextTok();
+
             if( tok!=T_fix && tok!=T_normal )
                 Expecting( "fix|normal" );
+
             growth->type = tok;
             NeedRIGHT();
             break;
@@ -2435,6 +2629,7 @@ L_pins:
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -2469,12 +2664,13 @@ void SPECCTRA_DB::doTOPOLOGY( TOPOLOGY* growth )
         <component_order_descriptor> ]})
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_fromto:
@@ -2517,7 +2713,7 @@ void SPECCTRA_DB::doCLASS( CLASS* growth )
     growth->class_id = CurText();
 
     // do net_ids, do not support <composite_name_list>s at this time
-    while( IsSymbol(tok = NextTok()) )
+    while( IsSymbol( tok = NextTok() ) )
     {
         growth->net_ids.push_back( CurText() );
     }
@@ -2529,11 +2725,13 @@ void SPECCTRA_DB::doCLASS( CLASS* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -2548,55 +2746,56 @@ void SPECCTRA_DB::doCLASS( CLASS* growth )
         case T_topology:
             if( growth->topology )
                 Unexpected( tok );
+
             growth->topology = new TOPOLOGY( growth );
             doTOPOLOGY( growth->topology );
             break;
 
         case T_circuit:  // handle all the circuit_descriptor here as strings
+        {
+            std::string     builder;
+            int             bracketNesting = 1; // we already saw the opening T_LEFT
+            tok = T_NONE;
+
+            while( bracketNesting != 0 && tok != T_EOF )
             {
-                std::string     builder;
-                int             bracketNesting = 1; // we already saw the opening T_LEFT
-                tok = T_NONE;
+                tok = NextTok();
 
-                while( bracketNesting!=0 && tok!=T_EOF )
+                if( tok == T_LEFT )
+                    ++bracketNesting;
+                else if( tok == T_RIGHT )
+                    --bracketNesting;
+
+                if( bracketNesting >= 1 )
                 {
-                    tok = NextTok();
+                    T previousTok = (T) PrevTok();
 
-                    if( tok==T_LEFT)
-                        ++bracketNesting;
+                    if( previousTok != T_LEFT && previousTok != T_circuit && tok != T_RIGHT )
+                        builder += ' ';
 
-                    else if( tok==T_RIGHT )
-                        --bracketNesting;
+                    if( tok == T_STRING )
+                        builder += m_quote_char;
 
-                    if( bracketNesting >= 1 )
-                    {
-                        T     previousTok = (T) PrevTok();
+                    builder += CurText();
 
-                        if( previousTok!=T_LEFT && previousTok!=T_circuit && tok!=T_RIGHT )
-                            builder += ' ';
-
-                        if( tok==T_STRING )
-                            builder += m_quote_char;
-
-                        builder += CurText();
-
-                        if( tok==T_STRING )
-                            builder += m_quote_char;
-                    }
-
-                    // When the nested rule is closed with a T_RIGHT and we are back down
-                    // to bracketNesting == 0, then save the builder and break;
-                    if( bracketNesting == 0 )
-                    {
-                        growth->circuit.push_back( builder );
-                        break;
-                    }
+                    if( tok == T_STRING )
+                        builder += m_quote_char;
                 }
 
-                if( tok==T_EOF )
-                    Unexpected( T_EOF );
-            }                                   // scope bracket
+                // When the nested rule is closed with a T_RIGHT and we are back down
+                // to bracketNesting == 0, then save the builder and break;
+                if( bracketNesting == 0 )
+                {
+                    growth->circuit.push_back( builder );
+                    break;
+                }
+            }
+
+            if( tok == T_EOF )
+                Unexpected( T_EOF );
+
             break;
+        }                                   // scope bracket
 
         default:
             Unexpected( CurText() );
@@ -2624,12 +2823,13 @@ void SPECCTRA_DB::doNETWORK( NETWORK* growth )
         )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_net:
@@ -2661,7 +2861,7 @@ void SPECCTRA_DB::doCOMP_ORDER( COMP_ORDER* growth )
         (comp_order {<placement_id> })
     */
 
-    while( IsSymbol(tok = NextTok()) )
+    while( IsSymbol( tok = NextTok() ) )
     {
         growth->placement_ids.push_back( CurText() );
     }
@@ -2699,6 +2899,7 @@ void SPECCTRA_DB::doFROMTO( FROMTO* growth )
         SetStringDelimiter( old );
         Expecting( T_SYMBOL );
     }
+
     growth->fromText = CurText();
 
     if( !IsSymbol(NextTok() ) )
@@ -2706,22 +2907,26 @@ void SPECCTRA_DB::doFROMTO( FROMTO* growth )
         SetStringDelimiter( old );
         Expecting( T_SYMBOL );
     }
+
     growth->toText = CurText();
 
     SetStringDelimiter( old );
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_type:
             tok = NextTok();
-            if( tok!=T_fix && tok!=T_normal && tok!=T_soft )
+
+            if( tok != T_fix && tok != T_normal && tok != T_soft )
                 Expecting( "fix|normal|soft" );
+
             growth->fromto_type = tok;
             NeedRIGHT();
             break;
@@ -2729,6 +2934,7 @@ void SPECCTRA_DB::doFROMTO( FROMTO* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, T_rule );
             doRULE( growth->rules );
             break;
@@ -2743,6 +2949,7 @@ void SPECCTRA_DB::doFROMTO( FROMTO* growth )
         case T_net:
             if( growth->net_id.size() )
                 Unexpected( tok );
+
             NeedSYMBOL();
             growth->net_id = CurText();
             NeedRIGHT();
@@ -2778,17 +2985,19 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_rect:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new RECTANGLE( growth );
             doRECTANGLE( (RECTANGLE*) growth->shape );
             break;
@@ -2796,6 +3005,7 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         case T_circle:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new CIRCLE( growth );
             doCIRCLE( (CIRCLE*) growth->shape );
             break;
@@ -2808,6 +3018,7 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         case T_polygon:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new PATH( growth, tok );
             doPATH( (PATH*) growth->shape );
             break;
@@ -2815,6 +3026,7 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         case T_qarc:
             if( growth->shape )
                 Unexpected( tok );
+
             growth->shape = new QARC( growth );
             doQARC( (QARC*) growth->shape );
             break;
@@ -2828,22 +3040,27 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         case T_turret:
             if( NextTok() != T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->turret = atoi( CurText() );
             NeedRIGHT();
             break;
 
         case T_type:
             tok = NextTok();
-            if( tok!=T_fix && tok!=T_route && tok!=T_normal && tok!=T_protect )
+
+            if( tok != T_fix && tok != T_route && tok != T_normal && tok != T_protect )
                 Expecting( "fix|route|normal|protect" );
+
             growth->wire_type = tok;
             NeedRIGHT();
             break;
 
         case T_attr:
             tok = NextTok();
-            if( tok!=T_test && tok!=T_fanout && tok!=T_bus && tok!=T_jumper )
+
+            if( tok != T_test && tok != T_fanout && tok != T_bus && tok != T_jumper )
                 Expecting( "test|fanout|bus|jumper" );
+
             growth->attr = tok;
             NeedRIGHT();
             break;
@@ -2864,6 +3081,7 @@ void SPECCTRA_DB::doWIRE( WIRE* growth )
         case T_connect:
             if( growth->connect )
                 Unexpected( tok );
+
             growth->connect = new CONNECT( growth );
             doCONNECT( growth->connect );
             break;
@@ -2904,7 +3122,7 @@ void SPECCTRA_DB::doWIRE_VIA( WIRE_VIA* growth )
     NeedSYMBOL();
     growth->padstack_id = CurText();
 
-    while( (tok = NextTok()) == T_NUMBER )
+    while( ( tok = NextTok() ) == T_NUMBER )
     {
         point.x = strtod( CurText(), 0 );
 
@@ -2922,6 +3140,7 @@ void SPECCTRA_DB::doWIRE_VIA( WIRE_VIA* growth )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_net:
@@ -2933,41 +3152,51 @@ void SPECCTRA_DB::doWIRE_VIA( WIRE_VIA* growth )
         case T_via_number:
             if( NextTok() != T_NUMBER )
                 Expecting( "<via#>" );
+
             growth->via_number = atoi( CurText() );
             NeedRIGHT();
             break;
 
         case T_type:
             tok = NextTok();
-            if( tok!=T_fix && tok!=T_route && tok!=T_normal && tok!=T_protect )
+
+            if( tok != T_fix && tok != T_route && tok != T_normal && tok != T_protect )
                 Expecting( "fix|route|normal|protect" );
+
             growth->via_type = tok;
             NeedRIGHT();
             break;
 
         case T_attr:
             tok = NextTok();
-            if( tok!=T_test && tok!=T_fanout && tok!=T_jumper && tok!=T_virtual_pin )
+
+            if( tok != T_test && tok != T_fanout && tok != T_jumper && tok != T_virtual_pin )
                 Expecting( "test|fanout|jumper|virtual_pin" );
+
             growth->attr = tok;
+
             if( tok == T_virtual_pin )
             {
                 NeedSYMBOL();
                 growth->virtual_pin_name = CurText();
             }
+
             NeedRIGHT();
             break;
 
         case T_contact:
             NeedSYMBOL();
             tok = T_SYMBOL;
-            while( IsSymbol(tok) )
+
+            while( IsSymbol( tok ) )
             {
                 growth->contact_layers.push_back( CurText() );
                 tok = NextTok();
             }
+
             if( tok != T_RIGHT )
                 Expecting( T_RIGHT );
+
             break;
 
         case T_supply:
@@ -2997,17 +3226,19 @@ void SPECCTRA_DB::doWIRING( WIRING* growth )
         )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_unit:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doUNIT( growth->unit );
             break;
@@ -3015,6 +3246,7 @@ void SPECCTRA_DB::doWIRING( WIRING* growth )
         case T_resolution:
             if( growth->unit )
                 Unexpected( tok );
+
             growth->unit = new UNIT_RES( growth, tok );
             doRESOLUTION( growth->unit );
             break;
@@ -3052,12 +3284,13 @@ void SPECCTRA_DB::doANCESTOR( ANCESTOR* growth )
     NeedSYMBOL();
     growth->filename = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_created_time:
@@ -3086,12 +3319,13 @@ void SPECCTRA_DB::doHISTORY( HISTORY* growth )
         (history [{<ancestor_file_descriptor> }] <self_descriptor> )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_ancestor:
@@ -3102,12 +3336,13 @@ void SPECCTRA_DB::doHISTORY( HISTORY* growth )
             break;
 
         case T_self:
-            while( (tok = NextTok()) != T_RIGHT )
+            while( ( tok = NextTok() ) != T_RIGHT )
             {
                 if( tok != T_LEFT )
                     Expecting( T_LEFT );
 
                 tok = NextTok();
+
                 switch( tok )
                 {
                 case T_created_time:
@@ -3125,6 +3360,7 @@ void SPECCTRA_DB::doHISTORY( HISTORY* growth )
                     Unexpected( CurText() );
                 }
             }
+
             break;
 
         default:
@@ -3155,12 +3391,13 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
     NeedSYMBOL();
     growth->session_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_base_design:
@@ -3172,6 +3409,7 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
         case T_history:
             if( growth->history )
                 Unexpected( tok );
+
             growth->history = new HISTORY( growth );
             doHISTORY( growth->history );
             break;
@@ -3179,6 +3417,7 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
         case T_structure:
             if( growth->structure )
                 Unexpected( tok );
+
             growth->structure = new STRUCTURE( growth );
             doSTRUCTURE( growth->structure );
             break;
@@ -3186,6 +3425,7 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
         case T_placement:
             if( growth->placement )
                 Unexpected( tok );
+
             growth->placement = new PLACEMENT( growth );
             doPLACEMENT( growth->placement );
             break;
@@ -3193,6 +3433,7 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
         case T_was_is:
             if( growth->was_is )
                 Unexpected( tok );
+
             growth->was_is = new WAS_IS( growth );
             doWAS_IS( growth->was_is );
             break;
@@ -3200,6 +3441,7 @@ void SPECCTRA_DB::doSESSION( SESSION* growth )
         case T_routes:
             if( growth->route )
                 Unexpected( tok );
+
             growth->route = new ROUTE( growth );
             doROUTE( growth->route );
             break;
@@ -3222,13 +3464,13 @@ void SPECCTRA_DB::doWAS_IS( WAS_IS* growth )
     */
 
     // none of the pins is ok too
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
-
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_pins:
@@ -3267,17 +3509,19 @@ void SPECCTRA_DB::doROUTE( ROUTE* growth )
         )
     */
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_resolution:
             if( growth->resolution )
                 Unexpected( tok );
+
             growth->resolution = new UNIT_RES( growth, tok );
             doRESOLUTION( growth->resolution );
             break;
@@ -3292,6 +3536,7 @@ void SPECCTRA_DB::doROUTE( ROUTE* growth )
                 delete growth->parser;
 #endif
             }
+
             growth->parser = new PARSER( growth );
             doPARSER( growth->parser );
             break;
@@ -3299,6 +3544,7 @@ void SPECCTRA_DB::doROUTE( ROUTE* growth )
         case T_structure_out:
             if( growth->structure_out )
                 Unexpected( tok );
+
             growth->structure_out = new STRUCTURE_OUT( growth );
             doSTRUCTURE_OUT( growth->structure_out );
             break;
@@ -3306,17 +3552,19 @@ void SPECCTRA_DB::doROUTE( ROUTE* growth )
         case T_library_out:
             if( growth->library )
                 Unexpected( tok );
+
             growth->library = new LIBRARY( growth, tok );
             doLIBRARY( growth->library );
             break;
 
         case T_network_out:
-            while( (tok = NextTok()) != T_RIGHT )
+            while( ( tok = NextTok() ) != T_RIGHT )
             {
                 if( tok != T_LEFT )
                     Expecting( T_LEFT );
 
                 tok = NextTok();
+
                 if( tok != T_net )      // it is class NET_OUT, but token T_net
                     Unexpected( CurText() );
 
@@ -3326,6 +3574,7 @@ void SPECCTRA_DB::doROUTE( ROUTE* growth )
                 growth->net_outs.push_back( net_out );
                 doNET_OUT( net_out );
             }
+
             break;
 
         default:
@@ -3352,18 +3601,21 @@ void SPECCTRA_DB::doNET_OUT( NET_OUT* growth )
     NeedSYMBOLorNUMBER();
     growth->net_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( tok != T_LEFT )
             Expecting( T_LEFT );
 
         tok = NextTok();
+
         switch( tok )
         {
         case T_net_number:
             tok = NextTok();
+
             if( tok!= T_NUMBER )
                 Expecting( T_NUMBER );
+
             growth->net_number = atoi( CurText() );
             NeedRIGHT();
             break;
@@ -3371,6 +3623,7 @@ void SPECCTRA_DB::doNET_OUT( NET_OUT* growth )
         case T_rule:
             if( growth->rules )
                 Unexpected( tok );
+
             growth->rules = new RULE( growth, tok );
             doRULE( growth->rules );
             break;
@@ -3415,7 +3668,7 @@ void SPECCTRA_DB::doSUPPLY_PIN( SUPPLY_PIN* growth )
     NeedSYMBOL();
     growth->net_id = CurText();
 
-    while( (tok = NextTok()) != T_RIGHT )
+    while( ( tok = NextTok() ) != T_RIGHT )
     {
         if( IsSymbol(tok) )
         {
@@ -3428,8 +3681,10 @@ void SPECCTRA_DB::doSUPPLY_PIN( SUPPLY_PIN* growth )
         else if( tok == T_LEFT )
         {
             tok = NextTok();
+
             if( tok != T_net )
                 Expecting( T_net );
+
             growth->net_id = CurText();
             NeedRIGHT();
         }
@@ -3556,12 +3811,8 @@ int ELEM_HOLDER::FindElem( T aType, int instanceNum )
 STRING_FORMATTER  ELEM::sf;
 
 
-//-----<UNIT_RES>---------------------------------------------------------
+UNIT_RES UNIT_RES::Default( nullptr, T_resolution );
 
-UNIT_RES UNIT_RES::Default( NULL, T_resolution );
-
-
-//-----<PADSTACK>---------------------------------------------------------
 
 int PADSTACK::Compare( PADSTACK* lhs, PADSTACK* rhs )
 {
@@ -3572,6 +3823,7 @@ int PADSTACK::Compare( PADSTACK* lhs, PADSTACK* rhs )
         rhs->hash = rhs->makeHash();
 
     int result = lhs->hash.compare( rhs->hash );
+
     if( result )
         return result;
 
@@ -3583,8 +3835,6 @@ int PADSTACK::Compare( PADSTACK* lhs, PADSTACK* rhs )
 }
 
 
-//-----<IMAGE>------------------------------------------------------------
-
 int IMAGE::Compare( IMAGE* lhs, IMAGE* rhs )
 {
     if( !lhs->hash.size() )
@@ -3599,8 +3849,6 @@ int IMAGE::Compare( IMAGE* lhs, IMAGE* rhs )
 }
 
 
-//-----<COMPONENT>--------------------------------------------------------
-
 /*
 int COMPONENT::Compare( COMPONENT* lhs, COMPONENT* rhs )
 {
@@ -3615,7 +3863,6 @@ int COMPONENT::Compare( COMPONENT* lhs, COMPONENT* rhs )
 }
 */
 
-//-----<PARSER>-----------------------------------------------------------
 PARSER::PARSER( ELEM* aParent ) :
     ELEM( T_parser, aParent )
 {
@@ -3643,7 +3890,7 @@ void PARSER::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
     out->Print( nestLevel, "(host_cad \"%s\")\n", host_cad.c_str() );
     out->Print( nestLevel, "(host_version \"%s\")\n", host_version.c_str() );
 
-    for( STRINGS::iterator i=constants.begin();  i!=constants.end();  )
+    for( STRINGS::iterator i = constants.begin(); i != constants.end(); )
     {
         const std::string& s1 = *i++;
         const std::string& s2 = *i++;
@@ -3651,16 +3898,15 @@ void PARSER::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
         const char* q1 = out->GetQuoteChar( s1.c_str() );
         const char* q2 = out->GetQuoteChar( s2.c_str() );
         out->Print( nestLevel, "(constant %s%s%s %s%s%s)\n",
-                               q1, s1.c_str(), q1,
-                               q2, s2.c_str(), q2 );
+                    q1, s1.c_str(), q1, q2, s2.c_str(), q2 );
     }
 
     if( routes_include_testpoint || routes_include_guides || routes_include_image_conductor )
     {
         out->Print( nestLevel, "(routes_include%s%s%s)\n",
-                               routes_include_testpoint ? " testpoint" : "",
-                               routes_include_guides ? " guides" : "",
-                               routes_include_image_conductor ? " image_conductor" : "" );
+                    routes_include_testpoint ? " testpoint" : "",
+                    routes_include_guides ? " guides" : "",
+                    routes_include_image_conductor ? " image_conductor" : "" );
     }
 
     if( wires_include_testpoint )
@@ -3684,27 +3930,20 @@ void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel )
     {
         useMultiLine = true;
 
-        out->Print( nestLevel, "(%s %s%s%s\n",
-                               Name(),
-                               quote, component_id.c_str(), quote );
-
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, component_id.c_str(), quote );
         out->Print( nestLevel+1, "%s", "" );
     }
     else
     {
         useMultiLine = false;
 
-        out->Print( nestLevel, "(%s %s%s%s",
-                               Name(),
-                               quote, component_id.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s", Name(), quote, component_id.c_str(), quote );
     }
 
     if( hasVertex )
     {
         out->Print( 0, " %.6f %.6f", vertex.x, vertex.y );
-
         out->Print( 0, " %s", GetTokenText( side ) );
-
         out->Print( 0, " %.6f", rotation );
     }
 
@@ -3732,6 +3971,7 @@ void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel )
     if( useMultiLine )
     {
         out->Print( 0, "\n" );
+
         if( place_rules )
         {
             place_rules->Format( out, nestLevel+1 );
@@ -3739,16 +3979,16 @@ void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel )
 
         if( properties.size() )
         {
-            out->Print( nestLevel+1, "(property \n" );
+            out->Print( nestLevel + 1, "(property \n" );
 
             for( PROPERTIES::const_iterator i = properties.begin(); i != properties.end(); ++i )
-                i->Format( out, nestLevel+2 );
+                i->Format( out, nestLevel + 2 );
 
-            out->Print( nestLevel+1, ")\n" );
+            out->Print( nestLevel + 1, ")\n" );
         }
 
         if( lock_type != T_NONE )
-            out->Print( nestLevel+1, "(lock_type %s)\n", GetTokenText(lock_type) );
+            out->Print( nestLevel + 1, "(lock_type %s)\n", GetTokenText( lock_type ) );
 
         if( rules )
             rules->Format( out, nestLevel+1 );
@@ -3759,14 +3999,14 @@ void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel )
         if( part_number.size() )
         {
             quote = out->GetQuoteChar( part_number.c_str() );
-            out->Print( nestLevel+1, "(PN %s%s%s)\n", quote, part_number.c_str(), quote );
+            out->Print( nestLevel + 1, "(PN %s%s%s)\n", quote, part_number.c_str(), quote );
         }
     }
     else
     {
         if( lock_type != T_NONE )
         {
-            out->Print( 0, "%s(lock_type %s)", space, GetTokenText(lock_type) );
+            out->Print( 0, "%s(lock_type %s)", space, GetTokenText( lock_type ) );
             space = "";
         }
 
@@ -3781,6 +4021,3 @@ void PLACE::Format( OUTPUTFORMATTER* out, int nestLevel )
 }
 
 } // namespace DSN
-
-
-//EOF
diff --git a/pcbnew/specctra_import_export/specctra.h b/pcbnew/specctra_import_export/specctra.h
index e4fe27de3a..c3a435094c 100644
--- a/pcbnew/specctra_import_export/specctra.h
+++ b/pcbnew/specctra_import_export/specctra.h
@@ -49,27 +49,27 @@ typedef DSN::T  DSN_T;
 
 
 /**
-    This source file implements export and import capabilities to the
-    specctra dsn file format.  The grammar for that file format is documented
-    fairly well.  There are classes for each major type of descriptor in the
-    spec.
-
-    Since there are so many classes in here, it may be helpful to generate
-    the Doxygen directory:
-
-    $ cd &ltkicadSourceRoot&gt
-    $ doxygen
-
-    Then you can view the html documentation in the &ltkicadSourceRoot&gt/doxygen
-    directory.  The main class in this file is SPECCTRA_DB and its main
-    functions are LoadPCB(), LoadSESSION(), and ExportPCB().
-
-    Wide use is made of boost::ptr_vector&lt&gt and std::vector&lt&gt template classes.
-    If the contained object is small, then std::vector tends to be used.
-    If the contained object is large, variable size, or would require writing
-    an assignment operator() or copy constructore, then boost::ptr_vector
-    cannot be beat.
-*/
+ * This source file implements export and import capabilities to the
+ * specctra dsn file format.  The grammar for that file format is documented
+ * fairly well.  There are classes for each major type of descriptor in the
+ * spec.
+ *
+ * Since there are so many classes in here, it may be helpful to generate
+ * the Doxygen directory:
+ *
+ * $ cd &ltkicadSourceRoot&gt
+ * $ doxygen
+ *
+ * Then you can view the html documentation in the &ltkicadSourceRoot&gt/doxygen
+ * directory.  The main class in this file is SPECCTRA_DB and its main
+ * functions are LoadPCB(), LoadSESSION(), and ExportPCB().
+ *
+ * Wide use is made of boost::ptr_vector&lt&gt and std::vector&lt&gt template classes.
+ * If the contained object is small, then std::vector tends to be used.
+ * If the contained object is large, variable size, or would require writing
+ * an assignment operator() or copy constructor, then boost::ptr_vector
+ * cannot be beat.
+ */
 namespace DSN {
 
 
@@ -77,18 +77,18 @@ class SPECCTRA_DB;
 
 
 /**
- * Function GetTokenText
- * is in the DSN namespace and returns the C string representing a
- * SPECCTRA_DB::keyword.  We needed a non-instanance function to get at
- * the SPECCTRA_DB::keyword[] and class SPECCTRA_DB is not defined yet.
+ * The DSN namespace and returns the C string representing a SPECCTRA_DB::keyword.
+ *
+ * We needed a non-instance function to get at the SPECCTRA_DB::keyword[] and class
+ * SPECCTRA_DB is not defined yet.
  */
 const char* GetTokenText( T aTok );
 
 
 /**
- * Struct POINT
- * is a holder for a point in the SPECCTRA DSN coordinate system.  It can also
- * be used to hold a distance (vector really) from some origin.
+ * A point in the SPECCTRA DSN coordinate system.
+ *
+ * It can also be used to hold a distance (vector really) from some origin.
  */
 struct POINT
 {
@@ -127,23 +127,23 @@ struct POINT
     }
 
     /**
-     * Function FixNegativeZero
-     * will change negative zero to positive zero in the IEEE floating point
-     * storage format.  Basically turns off the sign bit if the mantissa and
-     * exponent say the value is otherwise zero.
+     * Change negative zero to positive zero in the IEEE floating point storage format.
+     *
+     * Basically turns off the sign bit if the mantissa and exponent say the value is otherwise
+     * zero.
      */
     void FixNegativeZero()
     {
         if( x == -0.0 )
             x = 0.0;
+
         if( y == -0.0 )
             y = 0.0;
     }
 
     /**
-     * Function Format
-     * writes this object as ASCII out to an OUTPUTFORMATTER according to the
-     * SPECCTRA DSN format.
+     * Write this object as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN format.
+     *
      * @param out The formatter to write to.
      * @param nestLevel A multiple of the number of spaces to precede the output with.
      * @throw IO_ERROR if a system error writing the output, such as a full disk.
@@ -163,9 +163,8 @@ struct PROPERTY
     std::string value;
 
     /**
-     * Function Format
-     * writes this object as ASCII out to an OUTPUTFORMATTER according to the
-     * SPECCTRA DSN format.
+     * Write this object as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN format.
+     *
      * @param out The formatter to write to.
      * @param nestLevel A multiple of the number of spaces to precede the output with.
      * @throw IO_ERROR if a system error writing the output, such as a full disk.
@@ -180,30 +179,74 @@ struct PROPERTY
                    quoteValue, value.c_str(), quoteValue );
     }
 };
+
 typedef std::vector<PROPERTY>       PROPERTIES;
 
 
 class UNIT_RES;
 
 /**
- * ELEM
- * is a base class for any DSN element class.
- * See class ELEM_HOLDER also.
+ * A base class for any DSN element class.
+ *
+ * See class #ELEM_HOLDER also.
  */
 class ELEM
 {
-    friend class SPECCTRA_DB;
+public:
 
-protected:
-    DSN_T           type;
-    ELEM*           parent;
+    ELEM( DSN_T aType, ELEM* aParent = 0 );
+
+    virtual ~ELEM();
+
+    DSN_T   Type() const { return type; }
+
+    const char* Name() const;
 
 
     /**
-     * Function makeHash
-     * returns a string which uniquely represents this ELEM among other
-     * ELEMs of the same derived class as "this" one.
-     * It is not useable for all derived classes, only those which plan for
+     * Return the units for this section.
+     *
+     * Derived classes may override this to check for section specific overrides.
+     *
+     * @return an element from a local or parent scope.
+     */
+    virtual UNIT_RES* GetUnits() const;
+
+    /**
+     * Write this object as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN format.
+     *
+     * @param out The formatter to write to.
+     * @param nestLevel A multiple of the number of spaces to precede the output with.
+     * @throw IO_ERROR if a system error writing the output, such as a full disk.
+     */
+    virtual void Format( OUTPUTFORMATTER* out, int nestLevel );
+
+    /**
+     * Write the contents as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN format.
+     *
+     * This is the same as Format() except that the outer wrapper is not included.
+     *
+     * @param out The formatter to write to.
+     * @param nestLevel A multiple of the number of spaces to precede the output with.
+     * @throw IO_ERROR if a system error writing the output, such as a full disk.
+     */
+    virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel )
+    {
+        // overridden in ELEM_HOLDER
+    }
+
+    void SetParent( ELEM* aParent )
+    {
+        parent = aParent;
+    }
+
+protected:
+
+    /**
+     * Return a string which uniquely represents this ELEM among other ELEMs of the same
+     * derived class as "this" one.
+     *
+     * It is not usable for all derived classes, only those which plan for
      * it by implementing a FormatContents() function that captures all info
      * which will be used in the subsequent string compare.  THIS SHOULD
      * NORMALLY EXCLUDE THE TYPENAME, AND INSTANCE NAME OR ID AS WELL.
@@ -220,71 +263,21 @@ protected:
     // avoid creating this for every compare, make static.
     static STRING_FORMATTER  sf;
 
+    DSN_T           type;
+    ELEM*           parent;
 
-public:
-
-    ELEM( DSN_T aType, ELEM* aParent = 0 );
-
-    virtual ~ELEM();
-
-    DSN_T   Type() const { return type; }
-
-    const char* Name() const;
-
-
-    /**
-     * Function GetUnits
-     * returns the units for this section.  Derived classes may override this
-     * to check for section specific overrides.
-     * @return UNIT_RES* - from a local or parent scope
-     */
-    virtual UNIT_RES* GetUnits() const;
-
-    /**
-     * Function Format
-     * writes this object as ASCII out to an OUTPUTFORMATTER according to the
-     * SPECCTRA DSN format.
-     * @param out The formatter to write to.
-     * @param nestLevel A multiple of the number of spaces to precede the output with.
-     * @throw IO_ERROR if a system error writing the output, such as a full disk.
-     */
-    virtual void Format( OUTPUTFORMATTER* out, int nestLevel );
-
-
-    /**
-     * Function FormatContents
-     * writes the contents as ASCII out to an OUTPUTFORMATTER according to the
-     * SPECCTRA DSN format.  This is the same as Format() except that the outer
-     * wrapper is not included.
-     * @param out The formatter to write to.
-     * @param nestLevel A multiple of the number of spaces to precede the output with.
-     * @throw IO_ERROR if a system error writing the output, such as a full disk.
-     */
-    virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel )
-    {
-        // overridden in ELEM_HOLDER
-    }
-
-    void SetParent( ELEM* aParent )
-    {
-        parent = aParent;
-    }
+private:
+    friend class SPECCTRA_DB;
 };
 
 
 /**
- * ELEM_HOLDER
- * is a holder for any DSN class.  It can contain other
- * class instances, including classes derived from this class.
+ * A holder for any DSN class.
+ *
+ * It can contain other class instances, including classes derived from this class.
  */
 class ELEM_HOLDER : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    typedef boost::ptr_vector<ELEM> ELEM_ARRAY;
-
-    ELEM_ARRAY      kids;      ///< ELEM pointers
-
 public:
 
     ELEM_HOLDER( DSN_T aType, ELEM* aParent = 0 ) :
@@ -292,14 +285,14 @@ public:
     {
     }
 
-    virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override;
+    virtual void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override;
 
 
     //-----< list operations >--------------------------------------------
 
     /**
-     * Function FindElem
-     * finds a particular instance number of a given type of ELEM.
+     * Find a particular instance number of a given type of ELEM.
+     *
      * @param aType The type of ELEM to find
      * @param instanceNum The instance number of to find: 0 for first, 1 for second, etc.
      * @return int - The index into the kids array or -1 if not found.
@@ -308,9 +301,9 @@ public:
 
 
     /**
-     * Function Length
-     * returns the number of ELEMs in this ELEM.
-     * @return int - the count of children
+     * Return the number of ELEMs in this holder.
+     *
+     * @return the count of children elements.
      */
     int Length() const
     {
@@ -330,14 +323,11 @@ public:
 
     ELEM* Remove( int aIndex )
     {
-        ELEM_ARRAY::auto_type ret = kids.release( kids.begin()+aIndex );
+        ELEM_ARRAY::auto_type ret = kids.release( kids.begin() + aIndex );
         return ret.release();
     }
 
-    void Insert( int aIndex, ELEM* aElem )
-    {
-        kids.insert( kids.begin()+aIndex, aElem );
-    }
+    void Insert( int aIndex, ELEM* aElem ) { kids.insert( kids.begin() + aIndex, aElem ); }
 
     ELEM* At( int aIndex ) const
     {
@@ -351,20 +341,31 @@ public:
         return At( aIndex );
     }
 
-    void    Delete( int aIndex )
-    {
-        kids.erase( kids.begin()+aIndex );
-    }
+    void Delete( int aIndex ) { kids.erase( kids.begin() + aIndex ); }
+
+private:
+    friend class SPECCTRA_DB;
+
+    typedef boost::ptr_vector<ELEM> ELEM_ARRAY;
+
+    ELEM_ARRAY      kids;      ///< ELEM pointers
 };
 
 
 /**
- * PARSER
- * is simply a configuration record per the SPECCTRA DSN file spec.
+ * A configuration record per the SPECCTRA DSN file spec.
+ *
  * It is not actually a parser, but rather corresponds to &lt;parser_descriptor&gt;
  */
 class PARSER : public ELEM
 {
+public:
+
+    PARSER( ELEM* aParent );
+
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override;
+
+private:
     friend class SPECCTRA_DB;
 
     char        string_quote;
@@ -382,28 +383,15 @@ class PARSER : public ELEM
 
     std::string host_cad;
     std::string host_version;
-
-
-public:
-
-    PARSER( ELEM* aParent );
-
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override;
 };
 
 
 /**
- * UNIT_RES
- * is a holder for either a T_unit or T_resolution object which are usually
+ * A holder for either a T_unit or T_resolution object which are usually
  * mutually exclusive in the dsn grammar, except within the T_pcb level.
  */
 class UNIT_RES : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    DSN_T       units;
-    int         value;
-
 public:
 
     /**
@@ -422,25 +410,24 @@ public:
     DSN_T GetEngUnits() const  { return units; }
     int GetValue() const  { return value; }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( type == T_unit )
             out->Print( nestLevel, "(%s %s)\n", Name(), GetTokenText( units ) );
         else    // T_resolution
             out->Print( nestLevel, "(%s %s %d)\n", Name(), GetTokenText( units ), value );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    DSN_T       units;
+    int         value;
 };
 
 
 class RECTANGLE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     layer_id;
-
-    POINT           point0;         ///< one of two opposite corners
-    POINT           point1;
-
 public:
 
     RECTANGLE( ELEM* aParent ) :
@@ -465,7 +452,7 @@ public:
     POINT GetOrigin() { return point0; }
     POINT GetEnd() { return point1; }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* newline = nestLevel ? "\n" : "";
 
@@ -478,19 +465,22 @@ public:
                     point1.x, point1.y,
                     newline );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     layer_id;
+
+    POINT           point0;         ///< one of two opposite corners
+    POINT           point1;
 };
 
 
 /**
- * RULE
- * corresponds to the &lt;rule_descriptor&gt; in the specctra dsn spec.
+ * A &lt;rule_descriptor&gt; in the specctra dsn spec.
  */
 class RULE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    STRINGS     rules;      ///< rules are saved in std::string form.
-
 public:
 
     RULE( ELEM* aParent, DSN_T aType ) :
@@ -498,7 +488,7 @@ public:
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s", Name() );
 
@@ -524,16 +514,16 @@ public:
         if( nestLevel || !singleLine )
             out->Print( 0, "\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    STRINGS     rules;      ///< rules are saved in std::string form.
 };
 
 
 class LAYER_RULE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    STRINGS layer_ids;
-    RULE*   rule;
-
 public:
 
     LAYER_RULE( ELEM* aParent ) :
@@ -547,7 +537,7 @@ public:
         delete rule;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s", Name() );
 
@@ -564,6 +554,12 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    STRINGS layer_ids;
+    RULE*   rule;
 };
 
 
@@ -571,20 +567,11 @@ typedef boost::ptr_vector<LAYER_RULE>   LAYER_RULES;
 
 
 /**
- * PATH
- * supports both the &lt;path_descriptor&gt; and the &lt;polygon_descriptor&gt; per
+ * Support both the &lt;path_descriptor&gt; and the &lt;polygon_descriptor&gt; per
  * the specctra dsn spec.
  */
 class PATH : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     layer_id;
-    double          aperture_width;
-
-    POINTS          points;
-    DSN_T           aperture_type;
-
 public:
 
     PATH( ELEM* aParent, DSN_T aType = T_path ) :
@@ -611,7 +598,7 @@ public:
         aperture_width = aWidth;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* newline = nestLevel ? "\n" : "";
 
@@ -647,19 +634,22 @@ public:
 
         out->Print( 0, ")%s", newline );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     layer_id;
+    double          aperture_width;
+
+    POINTS          points;
+    DSN_T           aperture_type;
 };
+
 typedef boost::ptr_vector<PATH> PATHS;
 
 
 class BOUNDARY : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    // only one or the other of these two is used, not both
-    PATHS           paths;
-    RECTANGLE*      rectangle;
-
-
 public:
 
     BOUNDARY( ELEM* aParent, DSN_T aType = T_boundary ) :
@@ -708,7 +698,7 @@ public:
     }
 
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s\n", Name() );
 
@@ -722,18 +712,18 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    // only one or the other of these two is used, not both
+    PATHS           paths;
+    RECTANGLE*      rectangle;
 };
 
 
 class CIRCLE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string layer_id;
-
-    double      diameter;
-    POINT       vertex;     // POINT's constructor sets to (0,0)
-
 public:
     CIRCLE( ELEM* aParent ) :
         ELEM( T_circle, aParent )
@@ -741,14 +731,13 @@ public:
         diameter = 0.0;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* newline = nestLevel ? "\n" : "";
 
         const char* quote = out->GetQuoteChar( layer_id.c_str() );
-        out->Print( nestLevel, "(%s %s%s%s %.6g", Name(),
-                                quote, layer_id.c_str(), quote,
-                                diameter );
+        out->Print( nestLevel, "(%s %s%s%s %.6g", Name(), quote, layer_id.c_str(), quote,
+                    diameter );
 
         if( vertex.x!=0.0 || vertex.y!=0.0 )
             out->Print( 0, " %.6g %.6g)%s", vertex.x, vertex.y, newline );
@@ -770,17 +759,19 @@ public:
     {
         vertex = aVertex;
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string layer_id;
+
+    double      diameter;
+    POINT       vertex;     // POINT's constructor sets to (0,0)
 };
 
 
 class QARC : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string layer_id;
-    double      aperture_width;
-    POINT       vertex[3];
-
 public:
     QARC( ELEM* aParent ) :
         ELEM( T_qarc, aParent )
@@ -788,17 +779,16 @@ public:
         aperture_width = 0.0;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* newline = nestLevel ? "\n" : "";
 
         const char* quote = out->GetQuoteChar( layer_id.c_str() );
-        out->Print( nestLevel, "(%s %s%s%s %.6g", Name() ,
-                                 quote, layer_id.c_str(), quote,
-                                 aperture_width);
+        out->Print( nestLevel, "(%s %s%s%s %.6g", Name(), quote, layer_id.c_str(), quote,
+                                 aperture_width );
 
         for( int i=0;  i<3;  ++i )
-            out->Print( 0, "  %.6g %.6g",  vertex[i].x, vertex[i].y );
+            out->Print( 0, "  %.6g %.6g", vertex[i].x, vertex[i].y );
 
         out->Print( 0, ")%s", newline );
     }
@@ -811,6 +801,7 @@ public:
     void SetStart( const POINT& aStart )
     {
         vertex[0] = aStart;
+
         // no -0.0 on the printouts!
         vertex[0].FixNegativeZero();
     }
@@ -818,6 +809,7 @@ public:
     void SetEnd( const POINT& aEnd )
     {
         vertex[1] = aEnd;
+
         // no -0.0 on the printouts!
         vertex[1].FixNegativeZero();
     }
@@ -825,26 +817,22 @@ public:
     void SetCenter( const POINT& aCenter )
     {
         vertex[2] = aCenter;
+
         // no -0.0 on the printouts!
         vertex[2].FixNegativeZero();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string layer_id;
+    double      aperture_width;
+    POINT       vertex[3];
 };
 
 
 class WINDOW : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-protected:
-    /*  <shape_descriptor >::=
-        [<rectangle_descriptor> |
-        <circle_descriptor> |
-        <polygon_descriptor> |
-        <path_descriptor> |
-        <qarc_descriptor> ]
-    */
-    ELEM*       shape;
-
 public:
 
     WINDOW( ELEM* aParent, DSN_T aType = T_window ) :
@@ -875,7 +863,7 @@ public:
         }
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s ", Name() );
 
@@ -884,26 +872,8 @@ public:
 
         out->Print( 0, ")\n" );
     }
-};
-typedef boost::ptr_vector<WINDOW>   WINDOWS;
-
-
-/**
- * KEEPOUT
- * is used for &lt;keepout_descriptor&gt; and &lt;plane_descriptor&gt;.
- */
-class KEEPOUT : public ELEM
-{
-    friend class SPECCTRA_DB;
 
 protected:
-    std::string     name;
-    int             sequence_number;
-    RULE*           rules;
-    RULE*           place_rules;
-
-    WINDOWS         windows;
-
     /*  <shape_descriptor >::=
         [<rectangle_descriptor> |
         <circle_descriptor> |
@@ -911,13 +881,24 @@ protected:
         <path_descriptor> |
         <qarc_descriptor> ]
     */
-    ELEM*           shape;
+    ELEM*       shape;
 
+private:
+    friend class SPECCTRA_DB;
+};
+
+typedef boost::ptr_vector<WINDOW>   WINDOWS;
+
+
+/**
+ * Used for &lt;keepout_descriptor&gt; and &lt;plane_descriptor&gt;.
+ */
+class KEEPOUT : public ELEM
+{
 public:
 
     /**
-     * Constructor KEEPOUT
-     * requires a DSN_T because this class is used for T_place_keepout, T_via_keepout,
+     * Require a DSN_T because this class is used for T_place_keepout, T_via_keepout,
      * T_wire_keepout, T_bend_keepout, and T_elongate_keepout as well as T_keepout.
      */
     KEEPOUT( ELEM* aParent, DSN_T aType ) :
@@ -960,7 +941,7 @@ public:
         windows.push_back( aWindow );
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* newline = "\n";
 
@@ -974,7 +955,9 @@ public:
         // Could be not needed:
 #if 1
         else
+        {
             out->Print( 0, " \"\"" );   // the zone with no name or net_code == 0
+        }
 #endif
 
         if( sequence_number != -1 )
@@ -1011,23 +994,40 @@ public:
             out->Print( nestLevel, ")\n" );
         }
         else
+        {
             out->Print( 0, ")\n" );
+        }
     }
+
+protected:
+    std::string     name;
+    int             sequence_number;
+    RULE*           rules;
+    RULE*           place_rules;
+
+    WINDOWS         windows;
+
+    /*  <shape_descriptor >::=
+        [<rectangle_descriptor> |
+        <circle_descriptor> |
+        <polygon_descriptor> |
+        <path_descriptor> |
+        <qarc_descriptor> ]
+    */
+    ELEM*           shape;
+
+private:
+    friend class SPECCTRA_DB;
 };
+
 typedef boost::ptr_vector<KEEPOUT>  KEEPOUTS;
 
 
 /**
- * VIA
- * corresponds to the &lt;via_descriptor&gt; in the specctra dsn spec.
+ * A &lt;via_descriptor&gt; in the specctra dsn spec.
  */
 class VIA : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    STRINGS     padstacks;
-    STRINGS     spares;
-
 public:
 
     VIA( ELEM* aParent ) :
@@ -1040,7 +1040,7 @@ public:
         padstacks.push_back( aViaName );
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const int RIGHTMARGIN = 80;
         int perLine = out->Print( nestLevel, "(%s", Name() );
@@ -1080,22 +1080,24 @@ public:
 
         out->Print( 0, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    STRINGS     padstacks;
+    STRINGS     spares;
 };
 
 
 class CLASSES : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    STRINGS         class_ids;
-
 public:
     CLASSES( ELEM* aParent ) :
         ELEM( T_classes, aParent )
     {
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         for( STRINGS::iterator i = class_ids.begin(); i != class_ids.end(); ++i )
         {
@@ -1103,24 +1105,20 @@ public:
             out->Print( nestLevel, "%s%s%s\n", quote, i->c_str(), quote );
         }
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    STRINGS         class_ids;
 };
 
 
 class CLASS_CLASS : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-
-    CLASSES*        classes;
-
-    /*  rule | layer_rule are put into the kids container.
-    */
-
-
 public:
 
     /**
-     * Constructor CLASS_CLASS
-     * @param aParent - Parent element of the object.
+     * @param aParent is the arent element of the object.
      * @param aType May be either T_class_class or T_region_class_class
      */
     CLASS_CLASS( ELEM* aParent, DSN_T aType ) :
@@ -1134,7 +1132,7 @@ public:
         delete classes;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( classes )
             classes->Format( out, nestLevel );
@@ -1142,16 +1140,18 @@ public:
         // format the kids
         ELEM_HOLDER::FormatContents( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    CLASSES*        classes;
+
+    // rule | layer_rule are put into the kids container.
 };
 
 
 class CONTROL : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-
-    bool    via_at_smd;
-    bool    via_at_smd_grid_on;
-
 public:
     CONTROL( ELEM* aParent ) :
         ELEM_HOLDER( T_control, aParent )
@@ -1164,7 +1164,7 @@ public:
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s\n", Name() );
 
@@ -1180,25 +1180,18 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    bool    via_at_smd;
+    bool    via_at_smd_grid_on;
 };
 
 
 class LAYER : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string name;
-    DSN_T       layer_type; ///< one of: T_signal, T_power, T_mixed, T_jumper
-    int         direction;
-    int         cost;       ///< [forbidden | high | medium | low | free | \<positive_integer\> | -1]
-    int         cost_type;  ///< T_length | T_way
-    RULE*       rules;
-    STRINGS     use_net;
-
-    PROPERTIES  properties;
-
 public:
-
     LAYER( ELEM* aParent ) :
         ELEM( T_layer, aParent )
     {
@@ -1215,13 +1208,11 @@ public:
         delete rules;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( name.c_str() );
 
-        out->Print( nestLevel, "(%s %s%s%s\n",
-                               Name(),
-                               quote, name.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, name.c_str(), quote );
 
         out->Print( nestLevel+1, "(type %s)\n", GetTokenText( layer_type ) );
 
@@ -1245,7 +1236,8 @@ public:
         if( cost != -1 )
         {
             if( cost < 0 )
-                out->Print( nestLevel+1, "(cost %d", -cost );   // positive integer, stored as negative
+                // positive integer, stored as negative.
+                out->Print( nestLevel+1, "(cost %d", -cost );
             else
                 out->Print( nestLevel+1, "(cost %s", GetTokenText( (DSN_T)cost ) );
 
@@ -1270,6 +1262,21 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string name;
+    DSN_T       layer_type; ///< one of: T_signal, T_power, T_mixed, T_jumper
+    int         direction;
+
+    ///< [forbidden | high | medium | low | free | \<positive_integer\> | -1]
+    int         cost;
+    int         cost_type;  ///< T_length | T_way
+    RULE*       rules;
+    STRINGS     use_net;
+
+    PROPERTIES  properties;
 };
 
 typedef boost::ptr_vector<LAYER>    LAYERS;
@@ -1277,13 +1284,6 @@ typedef boost::ptr_vector<LAYER>    LAYERS;
 
 class SPECCTRA_LAYER_PAIR : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     layer_id0;
-    std::string     layer_id1;
-
-    double          layer_weight;
-
 public:
     SPECCTRA_LAYER_PAIR( ELEM* aParent ) :
         ELEM( T_layer_pair, aParent )
@@ -1291,18 +1291,24 @@ public:
         layer_weight = 0.0;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote0 = out->GetQuoteChar( layer_id0.c_str() );
         const char* quote1 = out->GetQuoteChar( layer_id1.c_str() );
 
-        out->Print( nestLevel, "(%s %s%s%s %s%s%s %.6g)\n",
-                               Name(),
-                               quote0, layer_id0.c_str(), quote0,
-                               quote1, layer_id1.c_str(), quote1,
-                               layer_weight );
+        out->Print( nestLevel, "(%s %s%s%s %s%s%s %.6g)\n", Name(), quote0, layer_id0.c_str(),
+                    quote0, quote1, layer_id1.c_str(), quote1, layer_weight );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     layer_id0;
+    std::string     layer_id1;
+
+    double          layer_weight;
 };
+
 typedef boost::ptr_vector<SPECCTRA_LAYER_PAIR>  SPECCTRA_LAYER_PAIRS;
 
 
@@ -1319,7 +1325,7 @@ public:
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s\n", Name() );
 
@@ -1332,34 +1338,30 @@ public:
 
 
 /**
- * COPPER_PLANE
- * corresponds to a &lt;plane_descriptor&gt; in the specctra dsn spec.
+ * A &lt;plane_descriptor&gt; in the specctra dsn spec.
  */
 class COPPER_PLANE : public KEEPOUT
 {
-    friend class SPECCTRA_DB;
-
 public:
     COPPER_PLANE( ELEM* aParent ) :
         KEEPOUT( aParent, T_plane )
     {}
+
+private:
+    friend class SPECCTRA_DB;
 };
+
 typedef boost::ptr_vector<COPPER_PLANE>    COPPER_PLANES;
 
 
 /**
- * TOKPROP
- * is a container for a single property whose value is another DSN_T token.
+ * A container for a single property whose value is another DSN_T token.
+ *
  * The name of the property is obtained from the DSN_T Type().
  */
 class TOKPROP : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    DSN_T       value;
-
 public:
-
     TOKPROP( ELEM* aParent, DSN_T aType ) :
         ELEM( aType, aParent )
     {
@@ -1367,34 +1369,32 @@ public:
         value = T_NONE;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
-        out->Print( nestLevel, "(%s %s)\n",
-                               Name(),
-                               GetTokenText( value ) );
+        out->Print( nestLevel, "(%s %s)\n", Name(), GetTokenText( value ) );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    DSN_T       value;
 };
 
 
 /**
- * STRINGPROP
- * is a container for a single property whose value is a string.
+ * A container for a single property whose value is a string.
+ *
  * The name of the property is obtained from the DSN_T.
  */
 class STRINGPROP : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     value;
-
 public:
-
     STRINGPROP( ELEM* aParent, DSN_T aType ) :
         ELEM( aType, aParent )
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( value.c_str() );
 
@@ -1402,26 +1402,16 @@ public:
                                Name(),
                                quote, value.c_str(), quote );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     value;
 };
 
 
 class REGION : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-
-    std::string     region_id;
-
-    //-----<mutually exclusive>--------------------------------------
-    RECTANGLE*      rectangle;
-    PATH*           polygon;
-    //-----</mutually exclusive>-------------------------------------
-
-    /* region_net | region_class | region_class_class are all mutually
-       exclusive and are put into the kids container.
-    */
-
-    RULE*           rules;
-
 public:
     REGION( ELEM* aParent ) :
         ELEM_HOLDER( T_region, aParent )
@@ -1438,7 +1428,7 @@ public:
         delete rules;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( region_id.size() )
         {
@@ -1457,21 +1447,28 @@ public:
         if( rules )
             rules->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     region_id;
+
+    //-----<mutually exclusive>--------------------------------------
+    RECTANGLE*      rectangle;
+    PATH*           polygon;
+    //-----</mutually exclusive>-------------------------------------
+
+    /* region_net | region_class | region_class_class are all mutually
+       exclusive and are put into the kids container.
+    */
+
+    RULE*           rules;
 };
 
 
 class GRID : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    DSN_T       grid_type;      ///< T_via | T_wire | T_via_keepout | T_place | T_snap
-    double      dimension;
-    DSN_T       direction;      ///< T_x | T_y | -1 for both
-    double      offset;
-    DSN_T       image_type;
-
 public:
-
     GRID( ELEM* aParent ) :
         ELEM( T_grid, aParent )
     {
@@ -1482,11 +1479,9 @@ public:
         image_type = T_NONE;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
-        out->Print( nestLevel, "(%s %s %.6g",
-                    Name(),
-                    GetTokenText( grid_type ), dimension );
+        out->Print( nestLevel, "(%s %s %.6g", Name(), GetTokenText( grid_type ), dimension );
 
         if( grid_type == T_place )
         {
@@ -1504,16 +1499,20 @@ public:
 
         out->Print( 0, ")\n");
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    DSN_T       grid_type;      ///< T_via | T_wire | T_via_keepout | T_place | T_snap
+    double      dimension;
+    DSN_T       direction;      ///< T_x | T_y | -1 for both
+    double      offset;
+    DSN_T       image_type;
 };
 
 
 class STRUCTURE_OUT : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    LAYERS      layers;
-    RULE*       rules;
-
 public:
     STRUCTURE_OUT( ELEM* aParent ) :
         ELEM( T_structure_out, aParent )
@@ -1526,7 +1525,7 @@ public:
         delete rules;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         for( LAYERS::iterator i = layers.begin(); i != layers.end(); ++i )
             i->Format( out, nestLevel );
@@ -1534,39 +1533,18 @@ public:
         if( rules )
             rules->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    LAYERS      layers;
+    RULE*       rules;
 };
 
 
 class STRUCTURE : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-
-    UNIT_RES*   unit;
-
-    LAYERS      layers;
-
-    LAYER_NOISE_WEIGHT*  layer_noise_weight;
-
-    BOUNDARY*   boundary;
-    BOUNDARY*   place_boundary;
-    VIA*        via;
-    CONTROL*    control;
-    RULE*       rules;
-
-    KEEPOUTS    keepouts;
-
-    COPPER_PLANES      planes;
-
-    typedef boost::ptr_vector<REGION>   REGIONS;
-    REGIONS     regions;
-
-    RULE*       place_rules;
-
-    typedef boost::ptr_vector<GRID>     GRIDS;
-    GRIDS       grids;
-
 public:
-
     STRUCTURE( ELEM* aParent ) :
         ELEM_HOLDER( T_structure, aParent )
     {
@@ -1610,7 +1588,7 @@ public:
             place_boundary->SetParent( this );
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( unit )
             unit->Format( out, nestLevel );
@@ -1664,46 +1642,42 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    UNIT_RES*   unit;
+
+    LAYERS      layers;
+
+    LAYER_NOISE_WEIGHT*  layer_noise_weight;
+
+    BOUNDARY*   boundary;
+    BOUNDARY*   place_boundary;
+    VIA*        via;
+    CONTROL*    control;
+    RULE*       rules;
+
+    KEEPOUTS    keepouts;
+
+    COPPER_PLANES      planes;
+
+    typedef boost::ptr_vector<REGION>   REGIONS;
+    REGIONS     regions;
+
+    RULE*       place_rules;
+
+    typedef boost::ptr_vector<GRID>     GRIDS;
+    GRIDS       grids;
 };
 
 
 /**
- * PLACE
- * implements the &lt;placement_reference&gt; in the specctra dsn spec.
+ * Implement a &lt;placement_reference&gt; in the specctra dsn spec.
  */
 class PLACE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     component_id;       ///< reference designator
-
-    DSN_T           side;
-
-    double          rotation;
-
-    bool            hasVertex;
-    POINT           vertex;
-
-    DSN_T           mirror;
-    DSN_T           status;
-
-    std::string     logical_part;
-
-    RULE*           place_rules;
-
-    PROPERTIES      properties;
-
-    DSN_T           lock_type;
-
-    //-----<mutually exclusive>--------------
-    RULE*           rules;
-    REGION*         region;
-    //-----</mutually exclusive>-------------
-
-    std::string     part_number;
-
 public:
-
     PLACE( ELEM* aParent ) :
         ELEM( T_place, aParent )
     {
@@ -1742,24 +1716,47 @@ public:
         rotation = aRotation;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override;
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override;
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     component_id;       ///< reference designator
+
+    DSN_T           side;
+
+    double          rotation;
+
+    bool            hasVertex;
+    POINT           vertex;
+
+    DSN_T           mirror;
+    DSN_T           status;
+
+    std::string     logical_part;
+
+    RULE*           place_rules;
+
+    PROPERTIES      properties;
+
+    DSN_T           lock_type;
+
+    //-----<mutually exclusive>--------------
+    RULE*           rules;
+    REGION*         region;
+    //-----</mutually exclusive>-------------
+
+    std::string     part_number;
 };
+
 typedef boost::ptr_vector<PLACE>    PLACES;
 
 
 /**
- * COMPONENT
- * implements the &lt;component_descriptor&gt; in the specctra dsn spec.
+ * Implement a &lt;component_descriptor&gt; in the specctra dsn spec.
  */
 class COMPONENT : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-//    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
-
-    std::string     image_id;
-    PLACES          places;
-
 public:
     COMPONENT( ELEM* aParent ) :
         ELEM( T_component, aParent )
@@ -1774,41 +1771,40 @@ public:
 
 
     /**
-     * Function Compare
-     * compares two objects of this type and returns <0, 0, or >0.
+     * Compare two objects of this type and returns <0, 0, or >0.
      */
 //    static int Compare( IMAGE* lhs, IMAGE* rhs );
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( image_id.c_str() );
-        out->Print( nestLevel, "(%s %s%s%s\n", Name(),
-                                quote, image_id.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, image_id.c_str(), quote );
 
         FormatContents( out, nestLevel+1 );
 
         out->Print( nestLevel, ")\n" );
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         for( PLACES::iterator i=places.begin();  i!=places.end();  ++i )
             i->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+//    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
+
+    std::string     image_id;
+    PLACES          places;
 };
+
 typedef boost::ptr_vector<COMPONENT> COMPONENTS;
 
 
 class PLACEMENT : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    UNIT_RES*   unit;
-
-    DSN_T       flip_style;
-
-    COMPONENTS  components;
-
 public:
     PLACEMENT( ELEM* aParent ) :
         ELEM( T_placement, aParent )
@@ -1823,15 +1819,16 @@ public:
     }
 
     /**
-     * Function LookupCOMPONENT
-     * looks up a COMPONENT by name.  If the name is not found, a new
-     * COMPONENT is added to the components container.  At any time the
-     * names in the component container should remain unique.
-     * @return COMPONENT* - an existing or new
+     * Look up a COMPONENT by name.
+     *
+     * If the name is not found, a new COMPONENT is added to the components container.  At any
+     * time the names in the component container should remain unique.
+     *
+     * @return existing or new COMPONENT.
      */
     COMPONENT* LookupCOMPONENT( const std::string& imageName )
     {
-        for( unsigned i=0; i<components.size();  ++i )
+        for( unsigned i = 0; i < components.size(); ++i )
         {
             if( 0 == components[i].GetImageId().compare( imageName ) )
                 return &components[i];
@@ -1843,7 +1840,7 @@ public:
         return added;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( unit )
             unit->Format( out, nestLevel );
@@ -1851,10 +1848,10 @@ public:
         if( flip_style != DSN_T( T_NONE ) )
         {
             out->Print( nestLevel, "(place_control (flip_style %s))\n",
-                       GetTokenText( flip_style ) );
+                        GetTokenText( flip_style ) );
         }
 
-        for( COMPONENTS::iterator i=components.begin();  i!=components.end();  ++i )
+        for( COMPONENTS::iterator i = components.begin(); i != components.end(); ++i )
             i->Format( out, nestLevel );
     }
 
@@ -1865,38 +1862,30 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    UNIT_RES*   unit;
+
+    DSN_T       flip_style;
+
+    COMPONENTS  components;
 };
 
 
 /**
- * SHAPE
- * corresponds to the "(shape ..)" element in the specctra dsn spec.
+ * A "(shape ..)" element in the specctra dsn spec.
+ *
  * It is not a &lt;shape_descriptor&gt;, which is one of things that this
  * elements contains, i.e. in its "shape" field.  This class also implements
  * the "(outline ...)" element as a dual personality.
  */
 class SHAPE : public WINDOW
 {
-    friend class SPECCTRA_DB;
-
-    DSN_T           connect;
-
-    /*  <shape_descriptor >::=
-        [<rectangle_descriptor> |
-        <circle_descriptor> |
-        <polygon_descriptor> |
-        <path_descriptor> |
-        <qarc_descriptor> ]
-    ELEM*           shape;      // inherited from WINDOW
-    */
-
-    WINDOWS         windows;
-
 public:
-
     /**
-     * Constructor SHAPE
-     * alternatively takes a DSN_T aType of T_outline
+     * Takes a DSN_T aType of T_outline
      */
     SHAPE( ELEM* aParent, DSN_T aType = T_shape ) :
         WINDOW( aParent, aType )
@@ -1909,7 +1898,7 @@ public:
         connect = aConnect;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s ", Name() );
 
@@ -1929,24 +1918,31 @@ public:
             out->Print( nestLevel, ")\n" );
         }
         else
+        {
             out->Print( 0, ")\n" );
+        }
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    DSN_T           connect;
+
+    /*  <shape_descriptor >::=
+        [<rectangle_descriptor> |
+        <circle_descriptor> |
+        <polygon_descriptor> |
+        <path_descriptor> |
+        <qarc_descriptor> ]
+    ELEM*           shape;      // inherited from WINDOW
+    */
+
+    WINDOWS         windows;
 };
 
 
 class PIN : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     padstack_id;
-    double          rotation;
-    bool            isRotated;
-    std::string     pin_id;
-    POINT           vertex;
-
-    int             kiNetCode;      ///< KiCad netcode
-
-
 public:
     PIN( ELEM* aParent ) :
         ELEM( T_pin, aParent )
@@ -1968,53 +1964,39 @@ public:
         vertex.FixNegativeZero();
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( padstack_id.c_str() );
         if( isRotated )
-            out->Print( nestLevel, "(pin %s%s%s (rotate %.6g)",
-                                     quote, padstack_id.c_str(), quote,
-                                     rotation
-                                     );
+            out->Print( nestLevel, "(pin %s%s%s (rotate %.6g)", quote, padstack_id.c_str(), quote,
+                        rotation );
         else
             out->Print( nestLevel, "(pin %s%s%s", quote, padstack_id.c_str(), quote );
 
         quote = out->GetQuoteChar( pin_id.c_str() );
-        out->Print( 0, " %s%s%s %.6g %.6g)\n", quote, pin_id.c_str(), quote,
-                   vertex.x, vertex.y );
+        out->Print( 0, " %s%s%s %.6g %.6g)\n", quote, pin_id.c_str(), quote, vertex.x, vertex.y );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     padstack_id;
+    double          rotation;
+    bool            isRotated;
+    std::string     pin_id;
+    POINT           vertex;
+
+    int             kiNetCode;      ///< KiCad netcode
 };
+
 typedef boost::ptr_vector<PIN>  PINS;
 
 
 class LIBRARY;
+
 class IMAGE : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-    friend class LIBRARY;
-
-    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
-
-    std::string     image_id;
-    DSN_T           side;
-    UNIT_RES*       unit;
-
-    /*  The grammar spec says only one outline is supported, but I am seeing
-        *.dsn examples with multiple outlines.  So the outlines will go into
-        the kids list.
-    */
-
-    PINS            pins;
-
-    RULE*           rules;
-    RULE*           place_rules;
-
-    KEEPOUTS        keepouts;
-
-    int             duplicated;     ///< no. times this image_id is duplicated
-
 public:
-
     IMAGE( ELEM* aParent ) :
         ELEM_HOLDER( T_image, aParent )
     {
@@ -2024,6 +2006,7 @@ public:
         place_rules = 0;
         duplicated = 0;
     }
+
     ~IMAGE()
     {
         delete unit;
@@ -2032,8 +2015,7 @@ public:
     }
 
     /**
-     * Function Compare
-     * compares two objects of this type and returns <0, 0, or >0.
+     * Compare two objects of this type and returns <0, 0, or >0.
      */
     static int Compare( IMAGE* lhs, IMAGE* rhs );
 
@@ -2053,15 +2035,13 @@ public:
         return image_id;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         std::string imageId = GetImageId();
 
         const char* quote = out->GetQuoteChar( imageId.c_str() );
 
-        out->Print( nestLevel, "(%s %s%s%s",
-                               Name(),
-                               quote, imageId.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s", Name(), quote, imageId.c_str(), quote );
 
         FormatContents( out, nestLevel+1 );
 
@@ -2069,7 +2049,7 @@ public:
     }
 
     // this is here for makeHash()
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( side != T_both )
             out->Print( 0, " (side %s)", GetTokenText( side ) );
@@ -2095,7 +2075,6 @@ public:
             i->Format( out, nestLevel );
     }
 
-
     UNIT_RES* GetUnits() const override
     {
         if( unit )
@@ -2103,42 +2082,48 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+    friend class LIBRARY;
+
+    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
+
+    std::string     image_id;
+    DSN_T           side;
+    UNIT_RES*       unit;
+
+    /*  The grammar spec says only one outline is supported, but I am seeing
+        *.dsn examples with multiple outlines.  So the outlines will go into
+        the kids list.
+    */
+
+    PINS            pins;
+
+    RULE*           rules;
+    RULE*           place_rules;
+
+    KEEPOUTS        keepouts;
+
+    int             duplicated;     ///< no. times this image_id is duplicated
 };
+
 typedef boost::ptr_vector<IMAGE>    IMAGES;
 
 
 /**
- * PADSTACK
- * holds either a via or a pad definition.
+ * Hold either a via or a pad definition.
  */
 class PADSTACK : public ELEM_HOLDER
 {
-    friend class SPECCTRA_DB;
-
-    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
-
-    std::string     padstack_id;
-    UNIT_RES*       unit;
-
-    /* The shapes are stored in the kids list */
-
-    DSN_T           rotate;
-    DSN_T           absolute;
-    DSN_T           attach;
-    std::string     via_id;
-
-    RULE*           rules;
-
 public:
-
     /**
-     * Constructor PADSTACK()
-     * cannot take ELEM* aParent because PADSTACKSET confuses this with a
+     * Cannot take ELEM* aParent because PADSTACKSET confuses this with a
      * copy constructor and causes havoc.  Instead set parent with
      * LIBRARY::AddPadstack()
      */
     PADSTACK() :
-        ELEM_HOLDER( T_padstack, NULL )
+        ELEM_HOLDER( T_padstack, nullptr )
     {
         unit = 0;
         rotate = T_on;
@@ -2146,6 +2131,7 @@ public:
         rules = 0;
         attach = T_off;
     }
+
     ~PADSTACK()
     {
         delete unit;
@@ -2158,33 +2144,28 @@ public:
     }
 
     /**
-     * Function Compare
-     * compares two objects of this type and returns <0, 0, or >0.
+     * Compare two objects of this type and returns <0, 0, or >0.
      */
     static int Compare( PADSTACK* lhs, PADSTACK* rhs );
 
-
     void SetPadstackId( const char* aPadstackId )
     {
         padstack_id = aPadstackId;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( padstack_id.c_str() );
 
-        out->Print( nestLevel, "(%s %s%s%s\n",
-                               Name(),
-                               quote, padstack_id.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, padstack_id.c_str(), quote );
 
         FormatContents( out, nestLevel+1 );
 
         out->Print( nestLevel, ")\n" );
     }
 
-
     // this factored out for use by Compare()
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( unit )
             unit->Format( out, nestLevel );
@@ -2204,8 +2185,7 @@ public:
         {
             const char* quote = out->GetQuoteChar( via_id.c_str() );
 
-            out->Print( 0, "(attach on (use_via %s%s%s))",
-                           quote, via_id.c_str(), quote );
+            out->Print( 0, "(attach on (use_via %s%s%s))", quote, via_id.c_str(), quote );
         }
 
         if( rotate == T_off )   // print the non-default
@@ -2228,13 +2208,30 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     hash;       ///< a hash string used by Compare(), not Format()ed/exported.
+
+    std::string     padstack_id;
+    UNIT_RES*       unit;
+
+    /* The shapes are stored in the kids list */
+
+    DSN_T           rotate;
+    DSN_T           absolute;
+    DSN_T           attach;
+    std::string     via_id;
+
+    RULE*           rules;
 };
+
 typedef boost::ptr_vector<PADSTACK> PADSTACKS;
 
 
 /**
- * Function operator<
- * is used by the PADSTACKSET boost::ptr_set below
+ * Used by the PADSTACKSET boost::ptr_set below.
  */
 inline bool operator<( const PADSTACK& lhs, const PADSTACK& rhs )
 {
@@ -2243,29 +2240,21 @@ inline bool operator<( const PADSTACK& lhs, const PADSTACK& rhs )
 
 
 /**
- * LIBRARY
- * corresponds to the &lt;library_descriptor&gt; in the specctra dsn specification.
+ * A &lt;library_descriptor&gt; in the specctra dsn specification.
+ *
  * Only unit_descriptor, image_descriptors, and padstack_descriptors are
  * included as children at this time.
  */
 class LIBRARY : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    UNIT_RES*       unit;
-    IMAGES          images;
-
-    PADSTACKS       padstacks;      ///< all except vias, which are in 'vias'
-    PADSTACKS       vias;
-
 public:
-
     LIBRARY( ELEM* aParent, DSN_T aType = T_library ) :
         ELEM( aType, aParent )
     {
         unit = 0;
 //        via_start_index = -1;       // 0 or greater means there is at least one via
     }
+
     ~LIBRARY()
     {
         delete unit;
@@ -2288,15 +2277,15 @@ public:
     }
 */
 
-
     /**
-     * Function FindIMAGE
-     * searches this LIBRARY for an image which matches the argument.
-     * @return int - if found the index into the images list, else -1.
+     * Search this LIBRARY for an image which matches the argument.
+     *
+     * @return index of image if found, else -1.
      */
     int FindIMAGE( IMAGE* aImage )
     {
         unsigned i;
+
         for( i=0;  i<images.size();  ++i )
         {
             if( 0 == IMAGE::Compare( aImage, &images[i] ) )
@@ -2306,6 +2295,7 @@ public:
         // There is no match to the IMAGE contents, but now generate a unique
         // name for it.
         int dups = 1;
+
         for( i=0;  i<images.size();  ++i )
         {
             if( 0 == aImage->image_id.compare( images[i].image_id ) )
@@ -2317,8 +2307,7 @@ public:
 
 
     /**
-     * Function AppendIMAGE
-     * adds the image to the image list.
+     * Add the image to the image list.
      */
     void AppendIMAGE( IMAGE* aImage )
     {
@@ -2327,28 +2316,28 @@ public:
     }
 
     /**
-     * Function LookupIMAGE
-     * will add the image only if one exactly like it does not already exist
-     * in the image container.
-     * @return IMAGE* - the IMAGE which is registered in the LIBRARY that
-     *           matches the argument, and it will be either the argument or
-     *           a previous image which is a duplicate.
+     * Add the image only if one exactly like it does not already exist in the image container.
+     *
+     * @return the IMAGE which is registered in the LIBRARY that matches the argument, and it
+     *         will be either the argument or a previous image which is a duplicate.
      */
     IMAGE* LookupIMAGE( IMAGE* aImage )
     {
         int ndx = FindIMAGE( aImage );
+
         if( ndx == -1 )
         {
             AppendIMAGE( aImage );
             return aImage;
         }
+
         return &images[ndx];
     }
 
     /**
-     * Function FindVia
-     * searches this LIBRARY for a via which matches the argument.
-     * @return int - if found the index into the padstack list, else -1.
+     * Search this LIBRARY for a via which matches the argument.
+     *
+     * @return the index found in the padstack list, else -1.
      */
     int FindVia( PADSTACK* aVia )
     {
@@ -2357,12 +2346,12 @@ public:
             if( 0 == PADSTACK::Compare( aVia, &vias[i] ) )
                 return int( i );
         }
+
         return -1;
     }
 
     /**
-     * Function AppendVia
-     * adds \a aVia to the internal via container.
+     * Add \a aVia to the internal via container.
      */
     void AppendVia( PADSTACK* aVia )
     {
@@ -2372,8 +2361,7 @@ public:
 
 
     /**
-     * Function AppendPADSTACK
-     * adds the padstack to the padstack container.
+     * Add the padstack to the padstack container.
      */
     void AppendPADSTACK( PADSTACK* aPadstack )
     {
@@ -2382,42 +2370,43 @@ public:
     }
 
     /**
-     * Function LookupVia
-     * will add the via only if one exactly like it does not already exist
-     * in the padstack container.
-     * @return PADSTACK* - the PADSTACK which is registered in the LIBRARY that
-     *           matches the argument, and it will be either the argument or
-     *           a previous padstack which is a duplicate.
+     * Add the via only if one exactly like it does not already exist in the padstack container.
+     *
+     * @return  the PADSTACK which is registered in the LIBRARY that matches the argument, and
+     *          it will be either the argument or a previous padstack which is a duplicate.
      */
     PADSTACK* LookupVia( PADSTACK* aVia )
     {
         int ndx = FindVia( aVia );
+
         if( ndx == -1 )
         {
             AppendVia( aVia );
             return aVia;
         }
+
         return &vias[ndx];
     }
 
     /**
-     * Function FindPADSTACK
-     * searches the padstack container by name.
-     * @return PADSTACK* - The PADSTACK with a matching name if it exists, else NULL.
+     * Search the padstack container by name.
+     *
+     * @return The PADSTACK with a matching name if it exists, else nullptr.
      */
     PADSTACK* FindPADSTACK( const std::string& aPadstackId )
     {
-        for( unsigned i=0;  i<padstacks.size();  ++i )
+        for( unsigned i = 0; i < padstacks.size(); ++i )
         {
             PADSTACK* ps = &padstacks[i];
 
             if( ps->GetPadstackId().compare( aPadstackId ) == 0 )
                 return ps;
         }
-        return NULL;
+
+        return nullptr;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( unit )
             unit->Format( out, nestLevel );
@@ -2439,18 +2428,23 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    UNIT_RES*       unit;
+    IMAGES          images;
+
+    PADSTACKS       padstacks;      ///< all except vias, which are in 'vias'
+    PADSTACKS       vias;
 };
 
 
 /**
- * PIN_REF
- * corresponds to the &lt;pin_reference&gt; definition in the specctra dsn spec.
+ * A &lt;pin_reference&gt; definition in the specctra dsn spec.
  */
 struct PIN_REF : public ELEM
 {
-    std::string     component_id;
-    std::string     pin_id;
-
     PIN_REF( ELEM* aParent ) :
         ELEM( T_pin, aParent )
     {
@@ -2458,9 +2452,9 @@ struct PIN_REF : public ELEM
 
 
     /**
-     * Function FormatIt
-     * is like Format() but is not virtual and returns the number of characters
-     * that were output.
+     * Like Format() but is not virtual.
+     *
+     * @return the number of characters that were output.
      */
     int FormatIt( OUTPUTFORMATTER* out, int nestLevel )
     {
@@ -2471,29 +2465,19 @@ struct PIN_REF : public ELEM
         const char* cquote = out->GetQuoteChar( component_id.c_str() );
         const char* pquote = out->GetQuoteChar( pin_id.c_str() );
 
-        return out->Print( nestLevel, "%s%s%s-%s%s%s%s",
-                                      cquote, component_id.c_str(), cquote,
-                                      pquote, pin_id.c_str(), pquote,
-                                      newline );
+        return out->Print( nestLevel, "%s%s%s-%s%s%s%s", cquote, component_id.c_str(), cquote,
+                                      pquote, pin_id.c_str(), pquote, newline );
     }
+
+    std::string     component_id;
+    std::string     pin_id;
 };
+
 typedef std::vector<PIN_REF>   PIN_REFS;
 
 
 class FROMTO : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     fromText;
-    std::string     toText;
-
-    DSN_T           fromto_type;
-    std::string     net_id;
-    RULE*           rules;
-//    std::string     circuit;
-    LAYER_RULES     layer_rules;
-
-
 public:
     FROMTO( ELEM* aParent ) :
         ELEM( T_fromto, aParent )
@@ -2506,7 +2490,7 @@ public:
         delete rules;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         // no quoting on these two, the lexer preserved the quotes on input
         out->Print( nestLevel, "(%s %s %s ",
@@ -2545,27 +2529,35 @@ public:
         if( nestLevel || !singleLine )
             out->Print( 0, "\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     fromText;
+    std::string     toText;
+
+    DSN_T           fromto_type;
+    std::string     net_id;
+    RULE*           rules;
+//    std::string     circuit;
+    LAYER_RULES     layer_rules;
 };
+
 typedef boost::ptr_vector<FROMTO>       FROMTOS;
 
 
 /**
- * COMP_ORDER
- * corresponds to the &lt;component_order_descriptor&gt;
+ * The &lt;component_order_descriptor&gt;
  */
 class COMP_ORDER : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    STRINGS         placement_ids;
-
 public:
     COMP_ORDER( ELEM* aParent ) :
         ELEM( T_comp_order, aParent )
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s", Name() );
 
@@ -2580,45 +2572,21 @@ public:
         if( nestLevel )
             out->Print( 0, "\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    STRINGS         placement_ids;
 };
+
 typedef boost::ptr_vector<COMP_ORDER>   COMP_ORDERS;
 
 /**
- * NET
- * corresponds to a &lt;net_descriptor&gt;
- * in the DSN spec.
+ * A &lt;net_descriptor&gt; in the DSN spec.
  */
 class NET : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     net_id;
-    bool            unassigned;
-    int             net_number;
-
-    DSN_T           pins_type;      ///< T_pins | T_order, type of field 'pins' below
-    PIN_REFS        pins;
-
-    PIN_REFS        expose;
-    PIN_REFS        noexpose;
-    PIN_REFS        source;
-    PIN_REFS        load;
-    PIN_REFS        terminator;
-
-    DSN_T           type;           ///< T_fix | T_normal
-
-    DSN_T           supply;         ///< T_power | T_ground
-
-    RULE*           rules;
-
-    LAYER_RULES     layer_rules;
-
-    FROMTOS         fromtos;
-
-    COMP_ORDER*     comp_order;
-
 public:
-
     NET( ELEM* aParent ) :
         ELEM( T_net, aParent )
     {
@@ -2646,17 +2614,16 @@ public:
             if( aComponent.compare( pins[i].component_id ) == 0 )
                 return int(i);
         }
+
         return -1;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( net_id.c_str() );
         const char* space = " ";
 
-        out->Print( nestLevel, "(%s %s%s%s",
-                               Name(),
-                               quote, net_id.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s", Name(), quote, net_id.c_str(), quote );
 
         if( unassigned )
         {
@@ -2677,7 +2644,7 @@ public:
             const int RIGHTMARGIN = 80;
             int perLine = out->Print( nestLevel+1, "(%s", GetTokenText( pins_type ) );
 
-            for( PIN_REFS::iterator i=pins.begin();  i!=pins.end();  ++i )
+            for( PIN_REFS::iterator i = pins.begin(); i != pins.end(); ++i )
             {
                 if( perLine > RIGHTMARGIN )
                 {
@@ -2691,6 +2658,7 @@ public:
 
                 perLine += i->FormatIt( out, 0 );
             }
+
             out->Print( 0, ")\n" );
         }
 
@@ -2711,41 +2679,138 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     net_id;
+    bool            unassigned;
+    int             net_number;
+
+    DSN_T           pins_type;      ///< T_pins | T_order, type of field 'pins' below
+    PIN_REFS        pins;
+
+    PIN_REFS        expose;
+    PIN_REFS        noexpose;
+    PIN_REFS        source;
+    PIN_REFS        load;
+    PIN_REFS        terminator;
+
+    DSN_T           type;           ///< T_fix | T_normal
+
+    DSN_T           supply;         ///< T_power | T_ground
+
+    RULE*           rules;
+
+    LAYER_RULES     layer_rules;
+
+    FROMTOS         fromtos;
+
+    COMP_ORDER*     comp_order;
 };
+
 typedef boost::ptr_vector<NET>  NETS;
 
 
 class TOPOLOGY : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    FROMTOS         fromtos;
-
-    COMP_ORDERS     comp_orders;
-
 public:
     TOPOLOGY( ELEM* aParent ) :
         ELEM( T_topology, aParent )
     {
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
-        for( FROMTOS::iterator i=fromtos.begin();  i!=fromtos.end();  ++i )
+        for( FROMTOS::iterator i = fromtos.begin(); i != fromtos.end(); ++i )
             i->Format( out, nestLevel );
 
-        for( COMP_ORDERS::iterator i=comp_orders.begin();  i!=comp_orders.end();  ++i )
+        for( COMP_ORDERS::iterator i = comp_orders.begin(); i != comp_orders.end(); ++i )
             i->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    FROMTOS         fromtos;
+
+    COMP_ORDERS     comp_orders;
 };
 
 
 /**
- * CLASS
- * corresponds to the &lt;class_descriptor&gt; in the specctra spec.
+ * The &lt;class_descriptor&gt; in the specctra spec.
  */
 class CLASS : public ELEM
 {
+public:
+    CLASS( ELEM* aParent ) :
+        ELEM( T_class, aParent )
+    {
+        rules = 0;
+        topology = 0;
+    }
+
+    ~CLASS()
+    {
+        delete rules;
+        delete topology;
+    }
+
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
+    {
+        const char* quote = out->GetQuoteChar( class_id.c_str() );
+
+        int perLine = out->Print( nestLevel, "(%s %s%s%s", Name(), quote, class_id.c_str(), quote );
+
+        const int RIGHTMARGIN = 72;
+
+        for( STRINGS::iterator i=net_ids.begin();  i!=net_ids.end();  ++i )
+        {
+            const char* space = " ";
+
+            if( perLine > RIGHTMARGIN )
+            {
+                out->Print( 0, "\n" );
+                perLine = out->Print( nestLevel+1, "%s", "" );
+                space = ""; // no space at first net_id of the line
+            }
+
+            quote = out->GetQuoteChar( i->c_str() );
+            perLine += out->Print( 0, "%s%s%s%s", space, quote, i->c_str(), quote );
+        }
+
+        bool newLine = false;
+
+        if( circuit.size() || rules || layer_rules.size() || topology )
+        {
+            out->Print( 0, "\n" );
+            newLine = true;
+        }
+
+        if( circuit.size() )
+        {
+            out->Print( nestLevel+1, "(circuit\n" );
+
+            for( STRINGS::iterator i = circuit.begin(); i != circuit.end(); ++i )
+                out->Print( nestLevel + 2, "%s\n", i->c_str() );
+
+            out->Print( nestLevel+1, ")\n" );
+        }
+
+        if( rules )
+            rules->Format( out, nestLevel+1 );
+
+        for( LAYER_RULES::iterator i = layer_rules.begin(); i != layer_rules.end(); ++i )
+            i->Format( out, nestLevel + 1 );
+
+        if( topology )
+            topology->Format( out, nestLevel+1 );
+
+        out->Print( newLine ? nestLevel : 0, ")\n" );
+    }
+
+private:
     friend class SPECCTRA_DB;
 
     std::string     class_id;
@@ -2760,99 +2825,33 @@ class CLASS : public ELEM
     LAYER_RULES     layer_rules;
 
     TOPOLOGY*       topology;
-
-public:
-
-    CLASS( ELEM* aParent ) :
-        ELEM( T_class, aParent )
-    {
-        rules = 0;
-        topology = 0;
-    }
-    ~CLASS()
-    {
-        delete rules;
-        delete topology;
-    }
-
-
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
-    {
-        const char* quote = out->GetQuoteChar( class_id.c_str() );
-
-        int perLine = out->Print( nestLevel, "(%s %s%s%s",
-                              Name(),
-                              quote, class_id.c_str(), quote );
-
-        const int RIGHTMARGIN = 72;
-
-        for( STRINGS::iterator i=net_ids.begin();  i!=net_ids.end();  ++i )
-        {
-            const char* space = " ";
-            if( perLine > RIGHTMARGIN )
-            {
-                out->Print( 0, "\n" );
-                perLine = out->Print( nestLevel+1, "%s", "" );
-                space = ""; // no space at first net_id of the line
-            }
-
-            quote = out->GetQuoteChar( i->c_str() );
-            perLine += out->Print( 0, "%s%s%s%s", space, quote, i->c_str(), quote );
-        }
-
-        bool newLine = false;
-        if( circuit.size() || rules || layer_rules.size() || topology )
-        {
-            out->Print( 0, "\n" );
-            newLine = true;
-        }
-
-        if( circuit.size() )
-        {
-            out->Print( nestLevel+1, "(circuit\n" );
-            for( STRINGS::iterator i=circuit.begin();  i!=circuit.end();  ++i )
-                out->Print( nestLevel+2, "%s\n", i->c_str() );
-            out->Print( nestLevel+1, ")\n" );
-        }
-
-        if( rules )
-            rules->Format( out, nestLevel+1 );
-
-        for( LAYER_RULES::iterator i=layer_rules.begin();  i!=layer_rules.end();  ++i )
-            i->Format( out, nestLevel+1 );
-
-        if( topology )
-            topology->Format( out, nestLevel+1 );
-
-        out->Print( newLine ? nestLevel : 0, ")\n" );
-    }
 };
+
 typedef boost::ptr_vector<CLASS> CLASSLIST;
 
 
 class NETWORK : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    NETS        nets;
-    CLASSLIST   classes;
-
-
 public:
-
     NETWORK( ELEM* aParent ) :
         ELEM( T_network, aParent )
     {
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
-        for( NETS::iterator i=nets.begin();  i!=nets.end();  ++i )
+        for( NETS::iterator i = nets.begin(); i != nets.end(); ++i )
             i->Format( out, nestLevel );
 
-        for( CLASSLIST::iterator i=classes.begin();  i!=classes.end();  ++i )
+        for( CLASSLIST::iterator i = classes.begin(); i != classes.end(); ++i )
             i->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    NETS        nets;
+    CLASSLIST   classes;
 };
 
 
@@ -2867,31 +2866,10 @@ public:
 
 
 /**
- * WIRE
- * corresponds to &lt;wire_shape_descriptor&gt; in the specctra dsn spec.
+ * A &lt;wire_shape_descriptor&gt; in the specctra dsn spec.
  */
 class WIRE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    /*  <shape_descriptor >::=
-        [<rectangle_descriptor> |
-        <circle_descriptor> |
-        <polygon_descriptor> |
-        <path_descriptor> |
-        <qarc_descriptor> ]
-    */
-    ELEM*           shape;
-
-    std::string     net_id;
-    int             turret;
-    DSN_T           wire_type;
-    DSN_T           attr;
-    std::string     shield;
-    WINDOWS         windows;
-    CONNECT*        connect;
-    bool            supply;
-
 public:
     WIRE( ELEM* aParent ) :
         ELEM( T_wire, aParent )
@@ -2926,7 +2904,7 @@ public:
         }
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         out->Print( nestLevel, "(%s ", Name() );
 
@@ -2936,8 +2914,7 @@ public:
         if( net_id.size() )
         {
             const char* quote = out->GetQuoteChar( net_id.c_str() );
-            out->Print( 0, "(net %s%s%s)",
-                       quote, net_id.c_str(), quote );
+            out->Print( 0, "(net %s%s%s)", quote, net_id.c_str(), quote );
         }
 
         if( turret >= 0 )
@@ -2952,16 +2929,15 @@ public:
         if( shield.size() )
         {
             const char* quote = out->GetQuoteChar( shield.c_str() );
-            out->Print( 0, "(shield %s%s%s)",
-                       quote, shield.c_str(), quote );
+            out->Print( 0, "(shield %s%s%s)", quote, shield.c_str(), quote );
         }
 
         if( windows.size() )
         {
             out->Print( 0, "\n" );
 
-            for( WINDOWS::iterator i=windows.begin();  i!=windows.end();  ++i )
-                i->Format( out, nestLevel+1 );
+            for( WINDOWS::iterator i = windows.begin(); i != windows.end(); ++i )
+                i->Format( out, nestLevel + 1 );
         }
 
         if( connect )
@@ -2972,29 +2948,37 @@ public:
 
         out->Print( 0, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    /*  <shape_descriptor >::=
+        [<rectangle_descriptor> |
+        <circle_descriptor> |
+        <polygon_descriptor> |
+        <path_descriptor> |
+        <qarc_descriptor> ]
+    */
+    ELEM*           shape;
+
+    std::string     net_id;
+    int             turret;
+    DSN_T           wire_type;
+    DSN_T           attr;
+    std::string     shield;
+    WINDOWS         windows;
+    CONNECT*        connect;
+    bool            supply;
 };
+
 typedef boost::ptr_vector<WIRE>     WIRES;
 
 
 /**
- * WIRE_VIA
- * corresponds to &lt;wire_via_descriptor&gt; in the specctra dsn spec.
+ * A &lt;wire_via_descriptor&gt; in the specctra dsn spec.
  */
 class WIRE_VIA : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     padstack_id;
-    POINTS          vertexes;
-    std::string     net_id;
-    int             via_number;
-    DSN_T           via_type;
-    DSN_T           attr;
-    std::string     virtual_pin_name;
-    STRINGS         contact_layers;
-    bool            supply;
-
-
 public:
     WIRE_VIA( ELEM* aParent ) :
         ELEM( T_via, aParent )
@@ -3010,16 +2994,15 @@ public:
         return padstack_id;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( padstack_id.c_str() );
 
         const int RIGHTMARGIN = 80;
-        int perLine = out->Print( nestLevel, "(%s %s%s%s",
-                       Name(),
-                       quote, padstack_id.c_str(), quote );
+        int perLine = out->Print( nestLevel, "(%s %s%s%s", Name(), quote, padstack_id.c_str(),
+                                  quote );
 
-        for( POINTS::iterator i=vertexes.begin();  i!=vertexes.end();  ++i )
+        for( POINTS::iterator i = vertexes.begin(); i != vertexes.end(); ++i )
         {
             if( perLine > RIGHTMARGIN )
             {
@@ -3027,7 +3010,9 @@ public:
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
             else
+            {
                 perLine += out->Print( 0, "  " );
+            }
 
             perLine += out->Print( 0, "%.6g %.6g", i->x, i->y );
         }
@@ -3042,6 +3027,7 @@ public:
                 out->Print( 0, "\n" );
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
+
             quote = out->GetQuoteChar( net_id.c_str() );
             perLine += out->Print( 0, "(net %s%s%s)", quote, net_id.c_str(), quote );
         }
@@ -3053,6 +3039,7 @@ public:
                 out->Print( 0, "\n" );
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
+
             perLine += out->Print( 0, "(via_number %d)", via_number );
         }
 
@@ -3063,6 +3050,7 @@ public:
                 out->Print( 0, "\n" );
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
+
             perLine += out->Print( 0, "(type %s)", GetTokenText( via_type ) );
         }
 
@@ -3073,14 +3061,17 @@ public:
                 out->Print( 0, "\n" );
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
+
             if( attr == T_virtual_pin )
             {
                 quote = out->GetQuoteChar( virtual_pin_name.c_str() );
-                perLine += out->Print( 0, "(attr virtual_pin %s%s%s)",
-                           quote, virtual_pin_name.c_str(), quote );
+                perLine += out->Print( 0, "(attr virtual_pin %s%s%s)", quote,
+                                       virtual_pin_name.c_str(), quote );
             }
             else
+            {
                 perLine += out->Print( 0, "(attr %s)", GetTokenText( attr ) );
+            }
         }
 
         if( supply )
@@ -3090,6 +3081,7 @@ public:
                 out->Print( 0, "\n" );
                 perLine = out->Print( nestLevel+1, "%s", "" );
             }
+
             perLine += out->Print( 0, "(supply)" );
         }
 
@@ -3098,53 +3090,63 @@ public:
             out->Print( 0, "\n" );
             out->Print( nestLevel+1, "(contact\n" );
 
-            for( STRINGS::iterator i=contact_layers.begin();  i!=contact_layers.end();  ++i )
+            for( STRINGS::iterator i = contact_layers.begin(); i != contact_layers.end(); ++i )
             {
                 quote = out->GetQuoteChar( i->c_str() );
                 out->Print( nestLevel+2, "%s%s%s\n", quote, i->c_str(), quote );
             }
+
             out->Print( nestLevel+1, "))\n" );
         }
         else
+        {
             out->Print( 0, ")\n" );
+        }
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     padstack_id;
+    POINTS          vertexes;
+    std::string     net_id;
+    int             via_number;
+    DSN_T           via_type;
+    DSN_T           attr;
+    std::string     virtual_pin_name;
+    STRINGS         contact_layers;
+    bool            supply;
 };
+
 typedef boost::ptr_vector<WIRE_VIA>      WIRE_VIAS;
 
 
 /**
- * WIRING
- * corresponds to &lt;wiring_descriptor&gt; in the specctra dsn spec.
+ * A &lt;wiring_descriptor&gt; in the specctra dsn spec.
  */
 class WIRING : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    UNIT_RES*   unit;
-    WIRES       wires;
-    WIRE_VIAS   wire_vias;
-
 public:
-
     WIRING( ELEM* aParent ) :
         ELEM( T_wiring, aParent )
     {
         unit = 0;
     }
+
     ~WIRING()
     {
         delete unit;
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( unit )
             unit->Format( out, nestLevel );
 
-        for( WIRES::iterator i=wires.begin();  i!=wires.end();  ++i )
+        for( WIRES::iterator i = wires.begin(); i != wires.end(); ++i )
             i->Format( out, nestLevel );
 
-        for( WIRE_VIAS::iterator i=wire_vias.begin();  i!=wire_vias.end();  ++i )
+        for( WIRE_VIAS::iterator i = wire_vias.begin(); i != wire_vias.end(); ++i )
             i->Format( out, nestLevel );
     }
 
@@ -3155,25 +3157,19 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    UNIT_RES*   unit;
+    WIRES       wires;
+    WIRE_VIAS   wire_vias;
 };
 
 
 class PCB : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     pcbname;
-    PARSER*         parser;
-    UNIT_RES*       resolution;
-    UNIT_RES*       unit;
-    STRUCTURE*      structure;
-    PLACEMENT*      placement;
-    LIBRARY*        library;
-    NETWORK*        network;
-    WIRING*         wiring;
-
 public:
-
     PCB( ELEM* aParent = 0 ) :
         ELEM( T_pcb, aParent )
     {
@@ -3199,12 +3195,11 @@ public:
         delete wiring;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( pcbname.c_str() );
 
-        out->Print( nestLevel, "(%s %s%s%s\n", Name(),
-                                quote, pcbname.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, pcbname.c_str(), quote );
 
         if( parser )
             parser->Format( out, nestLevel+1 );
@@ -3243,26 +3238,32 @@ public:
 
         return ELEM::GetUnits();
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     pcbname;
+    PARSER*         parser;
+    UNIT_RES*       resolution;
+    UNIT_RES*       unit;
+    STRUCTURE*      structure;
+    PLACEMENT*      placement;
+    LIBRARY*        library;
+    NETWORK*        network;
+    WIRING*         wiring;
 };
 
 
 class ANCESTOR : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     filename;
-    std::string     comment;
-    time_t          time_stamp;
-
-
 public:
     ANCESTOR( ELEM* aParent ) :
         ELEM( T_ancestor, aParent )
     {
-        time_stamp = time(NULL);
+        time_stamp = time(nullptr);
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         char    temp[80];
         struct  tm* tmp;
@@ -3272,41 +3273,38 @@ public:
 
         // format the time first to temp
         // filename may be empty, so quote it just in case.
-        out->Print( nestLevel, "(%s \"%s\" (created_time %s)\n",
-                     Name(),
-                     filename.c_str(),
-                     temp );
+        out->Print( nestLevel, "(%s \"%s\" (created_time %s)\n", Name(), filename.c_str(), temp );
 
         if( comment.size() )
         {
             const char* quote = out->GetQuoteChar( comment.c_str() );
-            out->Print( nestLevel+1, "(comment %s%s%s)\n",
-                       quote, comment.c_str(), quote );
+            out->Print( nestLevel+1, "(comment %s%s%s)\n", quote, comment.c_str(), quote );
         }
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     filename;
+    std::string     comment;
+    time_t          time_stamp;
 };
+
 typedef boost::ptr_vector<ANCESTOR>     ANCESTORS;
 
 
 class HISTORY : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    ANCESTORS       ancestors;
-    time_t          time_stamp;
-    STRINGS         comments;
-
 public:
-
     HISTORY( ELEM* aParent ) :
         ELEM( T_history, aParent )
     {
-        time_stamp = time(NULL);
+        time_stamp = time(nullptr);
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         for( ANCESTORS::iterator i=ancestors.begin();  i!=ancestors.end();  ++i )
             i->Format( out, nestLevel );
@@ -3315,7 +3313,7 @@ public:
         struct  tm* tmp;
 
         tmp = localtime( &time_stamp );
-        strftime( temp, sizeof(temp), "%b %d %H : %M : %S %Y", tmp );
+        strftime( temp, sizeof( temp ), "%b %d %H : %M : %S %Y", tmp );
 
         // format the time first to temp
         out->Print( nestLevel, "(self (created_time %s)\n", temp );
@@ -3323,33 +3321,33 @@ public:
         for( STRINGS::iterator i=comments.begin();  i!=comments.end();  ++i )
         {
             const char* quote = out->GetQuoteChar( i->c_str() );
-            out->Print( nestLevel+1, "(comment %s%s%s)\n",
-                       quote, i->c_str(), quote );
+            out->Print( nestLevel+1, "(comment %s%s%s)\n", quote, i->c_str(), quote );
         }
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    ANCESTORS       ancestors;
+    time_t          time_stamp;
+    STRINGS         comments;
 };
 
 
 /**
- * SUPPLY_PIN
- * corresponds to the &lt;supply_pin_descriptor&gt; in the specctra dsn spec.
-*/
+ * A &lt;supply_pin_descriptor&gt; in the specctra dsn spec.
+ */
 class SUPPLY_PIN : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    PIN_REFS        pin_refs;
-    std::string     net_id;
-
 public:
     SUPPLY_PIN( ELEM* aParent ) :
         ELEM( T_supply_pin, aParent )
     {
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         bool singleLine = pin_refs.size() <= 1;
         out->Print( nestLevel, "(%s", Name() );
@@ -3361,8 +3359,8 @@ public:
         }
         else
         {
-            for( PIN_REFS::iterator i=pin_refs.begin();  i!=pin_refs.end();  ++i )
-                i->FormatIt( out, nestLevel+1 );
+            for( PIN_REFS::iterator i = pin_refs.begin(); i != pin_refs.end(); ++i )
+                i->FormatIt( out, nestLevel + 1 );
         }
 
         if( net_id.size() )
@@ -3370,22 +3368,67 @@ public:
             const char* newline = singleLine ? "" : "\n";
 
             const char* quote = out->GetQuoteChar( net_id.c_str() );
-            out->Print( singleLine ? 0 : nestLevel+1,
-                       " (net %s%s%s)%s", quote, net_id.c_str(), quote, newline );
+            out->Print( singleLine ? 0 : nestLevel+1, " (net %s%s%s)%s",
+                        quote, net_id.c_str(), quote, newline );
         }
 
         out->Print( singleLine ? 0 : nestLevel, ")\n");
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    PIN_REFS        pin_refs;
+    std::string     net_id;
 };
+
 typedef boost::ptr_vector<SUPPLY_PIN>   SUPPLY_PINS;
 
 
 /**
- * NET_OUT
- * corresponds to the &lt;net_out_descriptor&gt; of the specctra dsn spec.
+ * A &lt;net_out_descriptor&gt; of the specctra dsn spec.
  */
 class NET_OUT : public ELEM
 {
+public:
+    NET_OUT( ELEM* aParent ) :
+        ELEM( T_net_out, aParent )
+    {
+        rules = 0;
+        net_number = -1;
+    }
+
+    ~NET_OUT()
+    {
+        delete rules;
+    }
+
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
+    {
+        const char* quote = out->GetQuoteChar( net_id.c_str() );
+
+        // cannot use Type() here, it is T_net_out and we need "(net "
+        out->Print( nestLevel, "(net %s%s%s\n", quote, net_id.c_str(), quote );
+
+        if( net_number>= 0 )
+            out->Print( nestLevel+1, "(net_number %d)\n", net_number );
+
+        if( rules )
+            rules->Format( out, nestLevel+1 );
+
+        for( WIRES::iterator i = wires.begin(); i != wires.end(); ++i )
+            i->Format( out, nestLevel + 1 );
+
+        for( WIRE_VIAS::iterator i = wire_vias.begin(); i != wire_vias.end(); ++i )
+            i->Format( out, nestLevel + 1 );
+
+        for( SUPPLY_PINS::iterator i = supply_pins.begin(); i != supply_pins.end(); ++i )
+            i->Format( out, nestLevel + 1 );
+
+        out->Print( nestLevel, ")\n" );
+    }
+
+private:
     friend class SPECCTRA_DB;
 
     std::string     net_id;
@@ -3394,62 +3437,14 @@ class NET_OUT : public ELEM
     WIRES           wires;
     WIRE_VIAS       wire_vias;
     SUPPLY_PINS     supply_pins;
-
-
-public:
-    NET_OUT( ELEM* aParent ) :
-        ELEM( T_net_out, aParent )
-    {
-        rules = 0;
-        net_number = -1;
-    }
-    ~NET_OUT()
-    {
-        delete rules;
-    }
-
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
-    {
-        const char* quote = out->GetQuoteChar( net_id.c_str() );
-
-        // cannot use Type() here, it is T_net_out and we need "(net "
-        out->Print( nestLevel, "(net %s%s%s\n",
-                   quote, net_id.c_str(), quote );
-
-        if( net_number>= 0 )
-            out->Print( nestLevel+1, "(net_number %d)\n", net_number );
-
-        if( rules )
-            rules->Format( out, nestLevel+1 );
-
-        for( WIRES::iterator i=wires.begin();  i!=wires.end();  ++i )
-            i->Format( out, nestLevel+1 );
-
-        for( WIRE_VIAS::iterator i=wire_vias.begin();  i!=wire_vias.end();  ++i )
-            i->Format( out, nestLevel+1 );
-
-        for( SUPPLY_PINS::iterator i=supply_pins.begin();  i!=supply_pins.end();  ++i )
-            i->Format( out, nestLevel+1 );
-
-        out->Print( nestLevel, ")\n" );
-    }
 };
+
 typedef boost::ptr_vector<NET_OUT>      NET_OUTS;
 
 
 class ROUTE : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    UNIT_RES*       resolution;
-    PARSER*         parser;
-    STRUCTURE_OUT*  structure_out;
-    LIBRARY*        library;
-    NET_OUTS        net_outs;
-//    TEST_POINTS*    test_points;
-
 public:
-
     ROUTE( ELEM* aParent ) :
         ELEM( T_route, aParent )
     {
@@ -3458,6 +3453,7 @@ public:
         structure_out = 0;
         library = 0;
     }
+
     ~ROUTE()
     {
         delete resolution;
@@ -3475,7 +3471,7 @@ public:
         return ELEM::GetUnits();
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         if( resolution )
             resolution->Format( out, nestLevel );
@@ -3492,21 +3488,32 @@ public:
         if( net_outs.size() )
         {
             out->Print( nestLevel, "(network_out\n" );
-            for( NET_OUTS::iterator i=net_outs.begin();  i!=net_outs.end();  ++i )
-                i->Format( out, nestLevel+1 );
+
+            for( NET_OUTS::iterator i = net_outs.begin(); i != net_outs.end(); ++i )
+                i->Format( out, nestLevel + 1 );
+
             out->Print( nestLevel, ")\n" );
         }
 
 //        if( test_poinst )
 //            test_points->Format( out, nestLevel );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    UNIT_RES*       resolution;
+    PARSER*         parser;
+    STRUCTURE_OUT*  structure_out;
+    LIBRARY*        library;
+    NET_OUTS        net_outs;
+//    TEST_POINTS*    test_points;
 };
 
 
 /**
- * Struct PIN_PAIR
- * is used within the WAS_IS class below to hold a pair of PIN_REFs and
- * corresponds to the (pins was is) construct within the specctra dsn spec.
+ * Used within the WAS_IS class below to hold a pair of PIN_REFs and corresponds to the (pins
+ * was is) construct within the specctra dsn spec.
  */
 struct PIN_PAIR
 {
@@ -3519,28 +3526,24 @@ struct PIN_PAIR
     PIN_REF     was;
     PIN_REF     is;
 };
+
 typedef std::vector<PIN_PAIR>   PIN_PAIRS;
 
 
 /**
- * WAS_IS
- * corresponds to the &lt;was_is_descriptor&gt; in the specctra dsn spec.
+ * A &lt;was_is_descriptor&gt; in the specctra dsn spec.
  */
 class WAS_IS : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    PIN_PAIRS       pin_pairs;
-
 public:
     WAS_IS( ELEM* aParent ) :
         ELEM( T_was_is, aParent )
     {
     }
 
-    void FormatContents( OUTPUTFORMATTER* out, int nestLevel )  override
+    void FormatContents( OUTPUTFORMATTER* out, int nestLevel ) override
     {
-        for( PIN_PAIRS::iterator i=pin_pairs.begin();  i!=pin_pairs.end();  ++i )
+        for( PIN_PAIRS::iterator i = pin_pairs.begin(); i != pin_pairs.end(); ++i )
         {
             out->Print( nestLevel, "(pins " );
             i->was.Format( out, 0 );
@@ -3549,34 +3552,20 @@ public:
             out->Print( 0, ")\n" );
         }
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    PIN_PAIRS       pin_pairs;
 };
 
 
 /**
- * SESSION
- * corresponds to the &lt;session_file_descriptor&gt; in the specctra dsn spec.
+ * A &lt;session_file_descriptor&gt; in the specctra dsn spec.
  */
 class SESSION : public ELEM
 {
-    friend class SPECCTRA_DB;
-
-    std::string     session_id;
-    std::string     base_design;
-
-    HISTORY*        history;
-    STRUCTURE*      structure;
-    PLACEMENT*      placement;
-    WAS_IS*         was_is;
-    ROUTE*          route;
-
-/*  not supported:
-    FLOOR_PLAN*         floor_plan;
-    NET_PIN_CHANGES*    net_pin_changes;
-    SWAP_HISTORY*       swap_history;
-*/
-
 public:
-
     SESSION( ELEM* aParent = 0 ) :
         ELEM( T_session, aParent )
     {
@@ -3586,6 +3575,7 @@ public:
         was_is = 0;
         route = 0;
     }
+
     ~SESSION()
     {
         delete history;
@@ -3595,11 +3585,10 @@ public:
         delete route;
     }
 
-    void Format( OUTPUTFORMATTER* out, int nestLevel )  override
+    void Format( OUTPUTFORMATTER* out, int nestLevel ) override
     {
         const char* quote = out->GetQuoteChar( session_id.c_str() );
-        out->Print( nestLevel, "(%s %s%s%s\n", Name(),
-                                quote, session_id.c_str(), quote );
+        out->Print( nestLevel, "(%s %s%s%s\n", Name(), quote, session_id.c_str(), quote );
 
         out->Print( nestLevel+1, "(base_design \"%s\")\n", base_design.c_str() );
 
@@ -3620,97 +3609,214 @@ public:
 
         out->Print( nestLevel, ")\n" );
     }
+
+private:
+    friend class SPECCTRA_DB;
+
+    std::string     session_id;
+    std::string     base_design;
+
+    HISTORY*        history;
+    STRUCTURE*      structure;
+    PLACEMENT*      placement;
+    WAS_IS*         was_is;
+    ROUTE*          route;
+
+/*  not supported:
+    FLOOR_PLAN*         floor_plan;
+    NET_PIN_CHANGES*    net_pin_changes;
+    SWAP_HISTORY*       swap_history;
+*/
 };
 
 typedef boost::ptr_set<PADSTACK>    PADSTACKSET;
 
 
 /**
- * SPECCTRA_DB
- * holds a DSN data tree, usually coming from a DSN file. Is essentially a SPECCTRA_PARSER class.
+ * A DSN data tree, usually coming from a DSN file. Is essentially a SPECCTRA_PARSER class.
  */
 class SPECCTRA_DB : public SPECCTRA_LEXER
 {
-    /// specctra DSN keywords
-    static const KEYWORD keywords[];
+public:
 
-    PCB*              m_pcb;
-    SHAPE_POLY_SET    m_brd_outlines;       // the board outlines for DSN export
-    SESSION*          m_session;
-    wxString          m_filename;
-    std::string       m_quote_char;
+    SPECCTRA_DB() :
+        SPECCTRA_LEXER( 0 )         // LINE_READER* == nullptr, no DSNLEXER::PushReader()
+    {
+        // The LINE_READER will be pushed from an automatic instantiation,
+        // we don't own it:
+        wxASSERT( !iOwnReaders );
 
-    bool              m_footprintsAreFlipped;
+        m_pcb   = 0;
+        m_session = 0;
+        m_quote_char += '"';
+        m_footprintsAreFlipped = false;
 
-    STRING_FORMATTER  m_sf;
+        SetSpecctraMode( true );
 
-    STRINGS           m_layerIds;        ///< indexed by PCB layer number
+        // Avoid not initialized members:
+        m_routeResolution = nullptr;
+        m_sessionBoard = nullptr;
+        m_top_via_layer = 0;
+        m_bot_via_layer = 0;
+    }
 
-    std::vector<int>          m_kicadLayer2pcb;  ///< maps BOARD layer number to PCB layer numbers
-    std::vector<PCB_LAYER_ID> m_pcbLayer2kicad;  ///< maps PCB layer number to BOARD layer numbers
+    virtual ~SPECCTRA_DB()
+    {
+        delete m_pcb;
+        delete m_session;
 
-    /// used during FromSESSION() only, memory for it is not owned here.
-    UNIT_RES*         m_routeResolution;
-
-    /// a copy to avoid passing as an argument, memory for it is not owned here.
-    BOARD*            m_sessionBoard;
-
-    static const KICAD_T scanPADs[];
-
-    PADSTACKSET       m_padstackset;
-
-    /// we don't want ownership here permanently, so we don't use boost::ptr_vector
-    std::vector<NET*> m_nets;
-
-    /// specctra cu layers, 0 based index:
-    int               m_top_via_layer;
-    int               m_bot_via_layer;
+        deleteNETs();
+    }
 
     /**
-     * Function buildLayerMaps
-     * creates a few data translation structures for layer name and number
-     * mapping between the DSN::PCB structure and the KiCad BOARD structure.
-     * @param aBoard The BOARD to create the maps for.
+     * Make a PCB with all the default ELEMs and parts on the heap.
+     */
+    static PCB* MakePCB();
+
+    /**
+     * Delete any existing PCB and replaces it with the given one.
+     */
+    void SetPCB( PCB* aPcb )
+    {
+        delete m_pcb;
+        m_pcb = aPcb;
+    }
+
+    PCB* GetPCB()  { return m_pcb; }
+
+    /**
+     * Delete any existing SESSION and replaces it with the given one.
+     */
+    void SetSESSION( SESSION* aSession )
+    {
+        delete m_session;
+        m_session = aSession;
+    }
+
+    SESSION* GetSESSION() { return m_session; }
+
+    /**
+     * A recursive descent parser for a SPECCTRA DSN "design" file.
+     *
+     * A design file is nearly a full description of a PCB (seems to be
+     * missing only the silkscreen stuff).
+     *
+     * @param aFilename The name of the dsn file to load.
+     * @throw IO_ERROR if there is a lexer or parser error.
+     */
+    void LoadPCB( const wxString& aFilename );
+
+    /**
+     * A recursive descent parser for a SPECCTRA DSN "session" file.
+     *
+     * A session file is a file that is fed back from the router to the layout
+     * tool (Pcbnew) and should be used to update a BOARD object with the new
+     * tracks, vias, and component locations.
+     *
+     * @param aFilename The name of the dsn file to load.
+     * @throw IO_ERROR if there is a lexer or parser error.
+     */
+    void LoadSESSION( const wxString& aFilename );
+
+    /**
+     * Write the internal PCB instance out as a SPECTRA DSN format file.
+     *
+     * @param aFilename The file to save to.
+     * @param aNameChange If true, causes the pcb's name to change to "aFilename"
+     *                    and also to to be changed in the output file.
+     * @throw IO_ERROR, if an i/o error occurs saving the file.
+     */
+    void ExportPCB( const wxString& aFilename,  bool aNameChange=false );
+
+    /**
+     * Add the entire BOARD to the PCB but does not write it out.
+     *
+     * @note The #BOARD given to this function must have all the FOOTPRINTs on the component
+     *       side of the BOARD.
+     *
+     * @see PCB_EDIT_FRAME::ExportToSpecctra() for an example before calling this function.
+     *
+     * @param aBoard The BOARD to convert to a PCB.
+     */
+    void FromBOARD( BOARD* aBoard );
+
+    /**
+     * Add the entire #SESSION info to a #BOARD but does not write it out.
+     *
+     * The #BOARD given to this function will have all its tracks and via's replaced, and all
+     * its components are subject to being moved.
+     *
+     * @param aBoard The #BOARD to merge the #SESSION information into.
+     */
+    void FromSESSION( BOARD* aBoard );
+
+    /**
+     * Write the internal #SESSION instance out as a #SPECTRA DSN format file.
+     *
+     * @param aFilename The file to save to.
+     */
+    void ExportSESSION( const wxString& aFilename );
+
+    /**
+     * Build the board outlines and store it in m_brd_outlines.
+     *
+     * Because it calls GetBoardPolygonOutlines() it *must be* called before flipping footprints
+     *
+     * @return false if the board outlines cannot be built (not closed outlines)
+     */
+    bool BuiltBoardOutlines( BOARD* aBoard  );
+
+    /**
+     * Flip the footprints which are on the back side of the board to the front.
+     */
+    void FlipFOOTPRINTs( BOARD* aBoard );
+
+    /**
+     * Flip the footprints which were on the back side of the board back to the back.
+     */
+    void RevertFOOTPRINTs( BOARD* aBoard );
+
+private:
+    /**
+     * Create a few data translation structures for layer name and number mapping between the
+     * DSN::PCB structure and the KiCad #BOARD structure.
+     *
+     * @param aBoard The #BOARD to create the maps for.
      */
     void buildLayerMaps( BOARD* aBoard );
 
     /**
-     * Function findLayerName
-     * returns the PCB layer index for a given layer name, within the specctra session
-     * file.
+     * Return the PCB layer index for a given layer name, within the specctra sessionfile.
      *
-     * @return int - the layer index within the specctra session file, or -1 if
-     *  aLayerName is not found.
+     * @return the layer index within the specctra session file, or -1 if \a aLayerName is not
+     *         found.
      */
     int findLayerName( const std::string& aLayerName ) const;
 
     /**
-     * Function readCOMPnPIN
-     * reads a &lt;pin_reference&gt; and splits it into the two parts which are
-     * on either side of the hyphen.  This function is specialized because
-     * pin_reference may or may not be using double quotes.  Both of these
-     * are legal:  U2-14 or "U2"-"14".  The lexer treats the first one as a
-     * single T_SYMBOL, so in that case we have to split it into two here.
-     * <p>
-     * The caller should have already read in the first token comprizing the
-     * pin_reference and it will be tested through CurTok().
+     * Read a &lt;pin_reference&gt; and splits it into the two parts which are on either side of
+     * the hyphen.
      *
+     * This function is specialized because pin_reference may or may not be using double quotes.
+     * Both of these are legal:  U2-14 or "U2"-"14".  The lexer treats the first one as a single
+     * T_SYMBOL, so in that case we have to split it into two here.
+     * <p>
+     * The caller should have already read in the first token comprising the pin_reference and
+     * it will be tested through CurTok().
+     * </p>
      * @param component_id Where to put the text preceding the '-' hyphen.
      * @param pid_id Where to put the text which trails the '-'.
      * @throw IO_ERROR, if the next token or two do no make up a pin_reference,
-     * or there is an error reading from the input stream.
+     *        or there is an error reading from the input stream.
      */
     void readCOMPnPIN( std::string* component_id, std::string* pid_id );
 
     /**
-     * Function readTIME
-     * reads a &lt;time_stamp&gt; which consists of 8 lexer tokens:
+     * Read a &lt;time_stamp&gt; which consists of 8 lexer tokens:
      * "month date hour : minute : second year".
-     * This function is specialized because time_stamps occur more than
-     * once in a session file.
-     * <p>
-     * The caller should not have already read in the first token comprizing the
-     * time stamp.
+     *
+     * This function is specialized because time_stamps occur more than once in a session file.
+     * The caller should not have already read in the first token comprising the time stamp.
      *
      * @param time_stamp Where to put the parsed time value.
      * @throw IO_ERROR, if the next token or 8 do no make up a time stamp,
@@ -3774,71 +3880,69 @@ class SPECCTRA_DB : public SPECCTRA_LEXER
     //-----<FromBOARD>-------------------------------------------------------
 
     /**
-     * Function fillBOUNDARY
-     * makes the board perimeter for the DSN file by filling the BOUNDARY element
+     * Make the board perimeter for the DSN file by filling the BOUNDARY element
      * in the specctra element tree.
+     *
      * @param aBoard The BOARD to get information from in order to make the BOUNDARY.
      * @param aBoundary The empty BOUNDARY to fill in.
      */
     void fillBOUNDARY( BOARD* aBoard, BOUNDARY* aBoundary );
 
     /**
-     * Function makeIMAGE
-     * allocates an IMAGE on the heap and creates all the PINs according to the PADs in the
+     * Allocates an I#MAGE on the heap and creates all the PINs according to the PADs in the
      * FOOTPRINT.
+     *
      * @param aBoard The owner of the FOOTPRINT.
      * @param aFootprint The FOOTPRINT from which to build the IMAGE.
-     * @return IMAGE* - not tested for duplication yet.
+     * @return not tested for duplication yet.
      */
     IMAGE* makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint );
 
     /**
-     * Function makePADSTACK
-     * creates a PADSTACK which matches the given pad.  Only pads which do not
-     * satisfy the function isKeepout() should be passed to this function.
+     * Create a #PADSTACK which matches the given pad.
+     *
+     * @note Only pads which do not satisfy the function isKeepout() should be passed to this
+     * function.
+     *
      * @param aBoard The owner of the PAD's footprint.
      * @param aPad The PAD which needs to be made into a PADSTACK.
-     * @return PADSTACK* - The created padstack, including its padstack_id.
+     * @return The created padstack, including its padstack_id.
      */
     PADSTACK* makePADSTACK( BOARD* aBoard, PAD* aPad );
 
     /**
-     * Function makeVia
-     * makes a round through hole PADSTACK using the given KiCad diameter in deci-mils.
+     * Make a round through hole #PADSTACK using the given KiCad diameter in deci-mils.
+     *
      * @param aCopperDiameter The diameter of the copper pad.
      * @param aDrillDiameter The drill diameter, used on re-import of the session file.
      * @param aTopLayer The DSN::PCB top most layer index.
      * @param aBotLayer The DSN::PCB bottom most layer index.
-     * @return PADSTACK* - The padstack, which is on the heap only, user must save
-     *  or delete it.
+     * @return The padstack, which is on the heap only, user must save or delete it.
      */
     PADSTACK* makeVia( int aCopperDiameter, int aDrillDiameter,
                        int aTopLayer, int aBotLayer );
 
     /**
-     * Function makeVia
-     * makes any kind of PADSTACK using the given KiCad VIA.
-     * @param aVia The VIA to build the padstack from.
-     * @return PADSTACK* - The padstack, which is on the heap only, user must save
-     *  or delete it.
+     * Make any kind of #PADSTACK using the given KiCad #VIA.
+     *
+     * @param aVia The #VIA to build the padstack from.
+     * @return The padstack, which is on the heap only, user must save or delete it.
      */
     PADSTACK* makeVia( const ::PCB_VIA* aVia );
 
     /**
-     * Function deleteNETs
-     * deletes all the NETs that may be in here.
+     * Delete all the NETs that may be in here.
      */
     void deleteNETs()
     {
-        for( unsigned n=0; n < m_nets.size(); ++n )
+        for( unsigned n = 0; n < m_nets.size(); ++n )
             delete m_nets[n];
 
         m_nets.clear();
     }
 
     /**
-     * Function exportNETCLASS
-     * exports \a aNetClass to the DSN file.
+     * Export \a aNetClass to the DSN file.
      */
     void exportNETCLASS( const std::shared_ptr<NETCLASS>& aNetClass, BOARD* aBoard );
 
@@ -3847,166 +3951,56 @@ class SPECCTRA_DB : public SPECCTRA_LEXER
     //-----<FromSESSION>-----------------------------------------------------
 
     /**
-     * Function makeTRACK
-     * creates a TRACK form the PATH and BOARD info.
+     * Create a #TRACK form the #PATH and #BOARD info.
      */
     PCB_TRACK* makeTRACK( PATH* aPath, int aPointIndex, int aNetcode );
 
     /**
-     * Function makeVIA
-     * instantiates a KiCad VIA on the heap and initializes it with internal
-     * values consistent with the given PADSTACK, POINT, and netcode.
+     * Instantiate a KiCad #VIA on the heap and initializes it with internal
+     * values consistent with the given #PADSTACK, #POINT, and netcode.
      */
-    PCB_VIA* makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNetCode, int aViaDrillDefault );
+    PCB_VIA* makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNetCode,
+                      int aViaDrillDefault );
 
     //-----</FromSESSION>----------------------------------------------------
 
-public:
+    /// specctra DSN keywords
+    static const KEYWORD keywords[];
 
-    SPECCTRA_DB() :
-        SPECCTRA_LEXER( 0 )         // LINE_READER* == NULL, no DSNLEXER::PushReader()
-    {
-        // The LINE_READER will be pushed from an automatic instantiation,
-        // we don't own it:
-        wxASSERT( !iOwnReaders );
+    PCB*              m_pcb;
+    SHAPE_POLY_SET    m_brd_outlines;       // the board outlines for DSN export
+    SESSION*          m_session;
+    wxString          m_filename;
+    std::string       m_quote_char;
 
-        m_pcb   = 0;
-        m_session = 0;
-        m_quote_char += '"';
-        m_footprintsAreFlipped = false;
+    bool              m_footprintsAreFlipped;
 
-        SetSpecctraMode( true );
+    STRING_FORMATTER  m_sf;
 
-        // Avoid not initialized members:
-        m_routeResolution = NULL;
-        m_sessionBoard = NULL;
-        m_top_via_layer = 0;
-        m_bot_via_layer = 0;
-    }
+    STRINGS           m_layerIds;        ///< indexed by PCB layer number
 
-    virtual ~SPECCTRA_DB()
-    {
-        delete m_pcb;
-        delete m_session;
+    std::vector<int>          m_kicadLayer2pcb;  ///< maps BOARD layer number to PCB layer numbers
+    std::vector<PCB_LAYER_ID> m_pcbLayer2kicad;  ///< maps PCB layer number to BOARD layer numbers
 
-        deleteNETs();
-    }
+    /// used during FromSESSION() only, memory for it is not owned here.
+    UNIT_RES*         m_routeResolution;
 
-    /**
-     * Function MakePCB
-     * makes a PCB with all the default ELEMs and parts on the heap.
-     */
-    static PCB* MakePCB();
+    /// a copy to avoid passing as an argument, memory for it is not owned here.
+    BOARD*            m_sessionBoard;
 
-    /**
-     * Function SetPCB
-     * deletes any existing PCB and replaces it with the given one.
-     */
-    void SetPCB( PCB* aPcb )
-    {
-        delete m_pcb;
-        m_pcb = aPcb;
-    }
-    PCB*  GetPCB()  { return m_pcb; }
+    static const KICAD_T scanPADs[];
 
-    /**
-     * Function SetSESSION
-     * deletes any existing SESSION and replaces it with the given one.
-     */
-    void SetSESSION( SESSION* aSession )
-    {
-        delete m_session;
-        m_session = aSession;
-    }
-    SESSION* GetSESSION() { return m_session; }
+    PADSTACKSET       m_padstackset;
 
-    /**
-     * Function LoadPCB
-     * is a recursive descent parser for a SPECCTRA DSN "design" file.
-     * A design file is nearly a full description of a PCB (seems to be
-     * missing only the silkscreen stuff).
-     *
-     * @param aFilename The name of the dsn file to load.
-     * @throw IO_ERROR if there is a lexer or parser error.
-     */
-    void LoadPCB( const wxString& aFilename );
+    /// we don't want ownership here permanently, so we don't use boost::ptr_vector
+    std::vector<NET*> m_nets;
 
-    /**
-     * Function LoadSESSION
-     * is a recursive descent parser for a SPECCTRA DSN "session" file.
-     * A session file is a file that is fed back from the router to the layout
-     * tool (Pcbnew) and should be used to update a BOARD object with the new
-     * tracks, vias, and component locations.
-     *
-     * @param aFilename The name of the dsn file to load.
-     * @throw IO_ERROR if there is a lexer or parser error.
-     */
-    void LoadSESSION( const wxString& aFilename );
-
-    /**
-     * Function ExportPCB
-     * writes the internal PCB instance out as a SPECTRA DSN format file.
-     *
-     * @param aFilename The file to save to.
-     * @param aNameChange If true, causes the pcb's name to change to "aFilename"
-     *          and also to to be changed in the output file.
-     * @throw IO_ERROR, if an i/o error occurs saving the file.
-     */
-    void ExportPCB( const wxString& aFilename,  bool aNameChange=false );
-
-    /**
-     * Function FromBOARD
-     * adds the entire BOARD to the PCB but does not write it out.  Note that the BOARD given
-     * to this function must have all the FOOTPRINTs on the component side of the BOARD.
-     *
-     * See PCB_EDIT_FRAME::ExportToSpecctra() for an example before calling this function.
-     *
-     * @param aBoard The BOARD to convert to a PCB.
-     */
-    void FromBOARD( BOARD* aBoard );
-
-    /**
-     * Function FromSESSION
-     * adds the entire SESSION info to a BOARD but does not write it out.  The BOARD given to
-     * this function will have all its tracks and via's replaced, and all its components are
-     * subject to being moved.
-     *
-     * @param aBoard The BOARD to merge the SESSION information into.
-     */
-    void FromSESSION( BOARD* aBoard );
-
-    /**
-     * Function ExportSESSION
-     * writes the internal SESSION instance out as a SPECTRA DSN format file.
-     *
-     * @param aFilename The file to save to.
-     */
-    void ExportSESSION( const wxString& aFilename );
-
-    /**
-     * Build the board outlines and store it in m_brd_outlines.
-     * Because it calls GetBoardPolygonOutlines() it *must be* called
-     * before flipping footprints
-     * @return false if the board outlines cannot be built (not closed outlines)
-     */
-    bool BuiltBoardOutlines( BOARD* aBoard  );
-
-    /**
-     * Function FlipFOOTPRINTs
-     * flips the footprints which are on the back side of the board to the front.
-     */
-    void FlipFOOTPRINTs( BOARD* aBoard );
-
-    /**
-     * Function RevertFOOTPRINTs
-     * flips the footprints which were on the back side of the board back to the back.
-     */
-    void RevertFOOTPRINTs( BOARD* aBoard );
+    /// specctra cu layers, 0 based index:
+    int               m_top_via_layer;
+    int               m_bot_via_layer;
 };
 
 
 }           // namespace DSN
 
 #endif      // SPECCTRA_H_
-
-//EOF
diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp
index 66be2bf49a..c33a117a39 100644
--- a/pcbnew/specctra_import_export/specctra_export.cpp
+++ b/pcbnew/specctra_import_export/specctra_export.cpp
@@ -96,7 +96,7 @@ bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename )
 
     LOCALE_IO       toggle;     // Switch the locale to standard C
 
-    // Build the board oulines *before* flipping footprints
+    // Build the board outlines *before* flipping footprints
     if( !db.BuiltBoardOutlines( GetBoard() ) )
     {
         wxLogWarning( _( "Board outline is malformed. Run DRC for a full analysis." ) );
@@ -307,300 +307,291 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, PAD* aPad )
     switch( aPad->GetShape() )
     {
     case PAD_SHAPE::CIRCLE:
+    {
+        double diameter = scale( aPad->GetSize().x );
+
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
         {
-            double diameter = scale( aPad->GetSize().x );
+            SHAPE* shape = new SHAPE( padstack );
 
-            for( int ndx=0; ndx<reportedLayers; ++ndx )
-            {
-                SHAPE* shape = new SHAPE( padstack );
+            padstack->Append( shape );
 
-                padstack->Append( shape );
+            CIRCLE* circle = new CIRCLE( shape );
 
-                CIRCLE* circle = new CIRCLE( shape );
+            shape->SetShape( circle );
 
-                shape->SetShape( circle );
-
-                circle->SetLayerId( layerName[ndx] );
-                circle->SetDiameter( diameter );
-                circle->SetVertex( dsnOffset );
-            }
-
-            snprintf( name, sizeof(name), "Round%sPad_%.6g_um",
-                      uniqifier.c_str(), IU2um( aPad->GetSize().x ) );
-
-            name[ sizeof(name) - 1 ] = 0;
-
-            padstack->SetPadstackId( name );
+            circle->SetLayerId( layerName[ndx] );
+            circle->SetDiameter( diameter );
+            circle->SetVertex( dsnOffset );
         }
+
+        snprintf( name, sizeof(name), "Round%sPad_%.6g_um",
+                  uniqifier.c_str(), IU2um( aPad->GetSize().x ) );
+
+        name[ sizeof(name) - 1 ] = 0;
+
+        padstack->SetPadstackId( name );
         break;
+    }
 
     case PAD_SHAPE::RECT:
+    {
+        double dx = scale( aPad->GetSize().x ) / 2.0;
+        double dy = scale( aPad->GetSize().y ) / 2.0;
+
+        POINT lowerLeft( -dx, -dy );
+        POINT upperRight( dx, dy );
+
+        lowerLeft += dsnOffset;
+        upperRight += dsnOffset;
+
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
         {
-            double  dx  = scale( aPad->GetSize().x ) / 2.0;
-            double  dy  = scale( aPad->GetSize().y ) / 2.0;
+            SHAPE* shape = new SHAPE( padstack );
 
-            POINT   lowerLeft( -dx, -dy );
-            POINT   upperRight( dx, dy );
+            padstack->Append( shape );
 
-            lowerLeft   += dsnOffset;
-            upperRight  += dsnOffset;
+            RECTANGLE* rect = new RECTANGLE( shape );
 
-            for( int ndx=0;  ndx<reportedLayers;  ++ndx )
-            {
-                SHAPE* shape = new SHAPE( padstack );
+            shape->SetShape( rect );
 
-                padstack->Append( shape );
-
-                RECTANGLE* rect = new RECTANGLE( shape );
-
-                shape->SetShape( rect );
-
-                rect->SetLayerId( layerName[ndx] );
-                rect->SetCorners( lowerLeft, upperRight );
-            }
-
-            snprintf( name, sizeof(name), "Rect%sPad_%.6gx%.6g_um",
-                      uniqifier.c_str(),
-                      IU2um( aPad->GetSize().x ),
-                      IU2um( aPad->GetSize().y ) );
-
-            name[ sizeof(name) - 1 ] = 0;
-
-            padstack->SetPadstackId( name );
+            rect->SetLayerId( layerName[ndx] );
+            rect->SetCorners( lowerLeft, upperRight );
         }
+
+        snprintf( name, sizeof( name ), "Rect%sPad_%.6gx%.6g_um", uniqifier.c_str(),
+                  IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ) );
+
+        name[sizeof( name ) - 1] = 0;
+
+        padstack->SetPadstackId( name );
         break;
+    }
 
     case PAD_SHAPE::OVAL:
+    {
+        double dx = scale( aPad->GetSize().x ) / 2.0;
+        double dy = scale( aPad->GetSize().y ) / 2.0;
+        double dr = dx - dy;
+        double radius;
+        POINT  pstart;
+        POINT  pstop;
+
+        if( dr >= 0 ) // oval is horizontal
         {
-            double  dx  = scale( aPad->GetSize().x ) / 2.0;
-            double  dy  = scale( aPad->GetSize().y ) / 2.0;
-            double  dr  = dx - dy;
-            double  radius;
-            POINT   pstart;
-            POINT   pstop;
+            radius = dy;
 
-            if( dr >= 0 )       // oval is horizontal
-            {
-                radius = dy;
-
-                pstart   = POINT( -dr, 0.0 );
-                pstop    = POINT(  dr, 0.0 );
-            }
-            else        // oval is vertical
-            {
-                radius  = dx;
-                dr      = -dr;
-
-                pstart   = POINT( 0.0, -dr );
-                pstop    = POINT( 0.0, dr );
-            }
-
-            pstart   += dsnOffset;
-            pstop    += dsnOffset;
-
-            for( int ndx=0; ndx<reportedLayers; ++ndx )
-            {
-                SHAPE*  shape;
-                PATH*   path;
-                // see http://www.freerouting.net/usren/viewtopic.php?f=3&t=317#p408
-                shape = new SHAPE( padstack );
-
-                padstack->Append( shape );
-                path = makePath( pstart, pstop, layerName[ndx] );
-                shape->SetShape( path );
-                path->aperture_width = 2.0 * radius;
-            }
-
-            snprintf( name, sizeof(name), "Oval%sPad_%.6gx%.6g_um",
-                      uniqifier.c_str(),
-                      IU2um( aPad->GetSize().x ),
-                      IU2um( aPad->GetSize().y ) );
-            name[ sizeof(name) - 1 ] = 0;
-
-            padstack->SetPadstackId( name );
+            pstart = POINT( -dr, 0.0 );
+            pstop = POINT( dr, 0.0 );
         }
+        else // oval is vertical
+        {
+            radius = dx;
+            dr = -dr;
+
+            pstart = POINT( 0.0, -dr );
+            pstop = POINT( 0.0, dr );
+        }
+
+        pstart += dsnOffset;
+        pstop += dsnOffset;
+
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
+        {
+            SHAPE* shape;
+            PATH*  path;
+
+            // see http://www.freerouting.net/usren/viewtopic.php?f=3&t=317#p408
+            shape = new SHAPE( padstack );
+
+            padstack->Append( shape );
+            path = makePath( pstart, pstop, layerName[ndx] );
+            shape->SetShape( path );
+            path->aperture_width = 2.0 * radius;
+        }
+
+        snprintf( name, sizeof( name ), "Oval%sPad_%.6gx%.6g_um", uniqifier.c_str(),
+                  IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ) );
+        name[sizeof( name ) - 1] = 0;
+
+        padstack->SetPadstackId( name );
         break;
+    }
 
     case PAD_SHAPE::TRAPEZOID:
+    {
+        double dx = scale( aPad->GetSize().x ) / 2.0;
+        double dy = scale( aPad->GetSize().y ) / 2.0;
+
+        double ddx = scale( aPad->GetDelta().x ) / 2.0;
+        double ddy = scale( aPad->GetDelta().y ) / 2.0;
+
+        // see class_pad_draw_functions.cpp which draws the trapezoid pad
+        POINT lowerLeft( -dx - ddy, -dy - ddx );
+        POINT upperLeft( -dx + ddy, +dy + ddx );
+        POINT upperRight( +dx - ddy, +dy - ddx );
+        POINT lowerRight( +dx + ddy, -dy + ddx );
+
+        lowerLeft += dsnOffset;
+        upperLeft += dsnOffset;
+        upperRight += dsnOffset;
+        lowerRight += dsnOffset;
+
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
         {
-            double  dx  = scale( aPad->GetSize().x ) / 2.0;
-            double  dy  = scale( aPad->GetSize().y ) / 2.0;
+            SHAPE* shape = new SHAPE( padstack );
 
-            double  ddx = scale( aPad->GetDelta().x ) / 2.0;
-            double  ddy = scale( aPad->GetDelta().y ) / 2.0;
+            padstack->Append( shape );
 
-            // see class_pad_draw_functions.cpp which draws the trapezoid pad
-            POINT   lowerLeft(  -dx - ddy, -dy - ddx );
-            POINT   upperLeft(  -dx + ddy, +dy + ddx );
-            POINT   upperRight( +dx - ddy, +dy - ddx );
-            POINT   lowerRight( +dx + ddy, -dy + ddx );
+            // a T_polygon exists as a PATH
+            PATH* polygon = new PATH( shape, T_polygon );
 
-            lowerLeft   += dsnOffset;
-            upperLeft   += dsnOffset;
-            upperRight  += dsnOffset;
-            lowerRight  += dsnOffset;
+            shape->SetShape( polygon );
 
-            for( int ndx=0; ndx<reportedLayers; ++ndx )
-            {
-                SHAPE* shape = new SHAPE( padstack );
+            polygon->SetLayerId( layerName[ndx] );
 
-                padstack->Append( shape );
-
-                // a T_polygon exists as a PATH
-                PATH* polygon = new PATH( shape, T_polygon );
-
-                shape->SetShape( polygon );
-
-                polygon->SetLayerId( layerName[ndx] );
-
-                polygon->AppendPoint( lowerLeft );
-                polygon->AppendPoint( upperLeft );
-                polygon->AppendPoint( upperRight );
-                polygon->AppendPoint( lowerRight );
-            }
-
-            // this string _must_ be unique for a given physical shape
-            snprintf( name, sizeof(name), "Trapz%sPad_%.6gx%.6g_%c%.6gx%c%.6g_um",
-                     uniqifier.c_str(), IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ),
-                     aPad->GetDelta().x < 0 ? 'n' : 'p',
-                     std::abs( IU2um( aPad->GetDelta().x )),
-                     aPad->GetDelta().y < 0 ? 'n' : 'p',
-                     std::abs( IU2um( aPad->GetDelta().y ) )
-                     );
-            name[ sizeof(name)-1 ] = 0;
-
-            padstack->SetPadstackId( name );
+            polygon->AppendPoint( lowerLeft );
+            polygon->AppendPoint( upperLeft );
+            polygon->AppendPoint( upperRight );
+            polygon->AppendPoint( lowerRight );
         }
+
+        // this string _must_ be unique for a given physical shape
+        snprintf( name, sizeof( name ), "Trapz%sPad_%.6gx%.6g_%c%.6gx%c%.6g_um", uniqifier.c_str(),
+                  IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ),
+                  aPad->GetDelta().x < 0 ? 'n' : 'p', std::abs( IU2um( aPad->GetDelta().x ) ),
+                  aPad->GetDelta().y < 0 ? 'n' : 'p', std::abs( IU2um( aPad->GetDelta().y ) ) );
+        name[sizeof( name ) - 1] = 0;
+
+        padstack->SetPadstackId( name );
         break;
+    }
 
     case PAD_SHAPE::CHAMFERED_RECT:
     case PAD_SHAPE::ROUNDRECT:
+    {
+        // Export the shape as as polygon, round rect does not exist as primitive
+        const int      circleToSegmentsCount = 36;
+        int            rradius = aPad->GetRoundRectCornerRadius();
+        SHAPE_POLY_SET cornerBuffer;
+
+        // Use a slightly bigger shape because the round corners are approximated by
+        // segments, giving to the polygon a slightly smaller shape than the actual shape
+
+        /* calculates the coeff to compensate radius reduction of holes clearance
+         * due to the segment approx.
+         * For a circle the min radius is radius * cos( 2PI / s_CircleToSegmentsCount / 2)
+         * correctionFactor is cos( PI/s_CircleToSegmentsCount  )
+         */
+        double correctionFactor = cos( M_PI / (double) circleToSegmentsCount );
+        int    extra_clearance = KiROUND( rradius * ( 1.0 - correctionFactor ) );
+        wxSize psize = aPad->GetSize();
+        psize.x += extra_clearance * 2;
+        psize.y += extra_clearance * 2;
+        rradius += extra_clearance;
+        bool doChamfer = aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT;
+
+        TransformRoundChamferedRectToPolygon(
+                cornerBuffer, wxPoint( 0, 0 ), psize, 0, rradius, aPad->GetChamferRectRatio(),
+                doChamfer ? aPad->GetChamferPositions() : 0, 0,
+                aBoard->GetDesignSettings().m_MaxError, ERROR_INSIDE );
+        SHAPE_LINE_CHAIN& polygonal_shape = cornerBuffer.Outline( 0 );
+
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
         {
-            // Export the shape as as polygon, round rect does not exist as primitive
-            const int circleToSegmentsCount = 36;
-            int rradius = aPad->GetRoundRectCornerRadius();
-            SHAPE_POLY_SET cornerBuffer;
-            // Use a slightly bigger shape because the round corners are approximated by
-            // segments, giving to the polygon a slightly smaller shape than the actual shape
+            SHAPE* shape = new SHAPE( padstack );
 
-            /* calculates the coeff to compensate radius reduction of holes clearance
-             * due to the segment approx.
-             * For a circle the min radius is radius * cos( 2PI / s_CircleToSegmentsCount / 2)
-             * correctionFactor is cos( PI/s_CircleToSegmentsCount  )
-             */
-            double correctionFactor = cos( M_PI / (double) circleToSegmentsCount );
-            int extra_clearance = KiROUND( rradius * (1.0 - correctionFactor ) );
-            wxSize psize = aPad->GetSize();
-            psize.x += extra_clearance*2;
-            psize.y += extra_clearance*2;
-            rradius += extra_clearance;
-            bool doChamfer = aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT;
+            padstack->Append( shape );
 
-            TransformRoundChamferedRectToPolygon( cornerBuffer, wxPoint(0,0), psize,
-                                         0, rradius,
-                                         aPad->GetChamferRectRatio(),
-                                         doChamfer ? aPad->GetChamferPositions() : 0,
-                                         0,
-                                         aBoard->GetDesignSettings().m_MaxError,
-                                         ERROR_INSIDE );
-            SHAPE_LINE_CHAIN& polygonal_shape = cornerBuffer.Outline( 0 );
+            // a T_polygon exists as a PATH
+            PATH* polygon = new PATH( shape, T_polygon );
 
-            for( int ndx=0; ndx < reportedLayers; ++ndx )
+            shape->SetShape( polygon );
+
+            polygon->SetLayerId( layerName[ndx] );
+
+            // append a closed polygon
+            POINT first_corner;
+
+            for( int idx = 0; idx < polygonal_shape.PointCount(); idx++ )
             {
-                SHAPE* shape = new SHAPE( padstack );
+                POINT corner( scale( polygonal_shape.CPoint( idx ).x ),
+                              scale( -polygonal_shape.CPoint( idx ).y ) );
+                corner += dsnOffset;
+                polygon->AppendPoint( corner );
 
-                padstack->Append( shape );
-
-                // a T_polygon exists as a PATH
-                PATH* polygon = new PATH( shape, T_polygon );
-
-                shape->SetShape( polygon );
-
-                polygon->SetLayerId( layerName[ndx] );
-                // append a closed polygon
-                POINT first_corner;
-
-                for( int idx = 0; idx < polygonal_shape.PointCount(); idx++ )
-                {
-                    POINT corner( scale( polygonal_shape.CPoint( idx ).x ),
-                            scale( -polygonal_shape.CPoint( idx ).y ) );
-                    corner += dsnOffset;
-                    polygon->AppendPoint( corner );
-
-                    if( idx == 0 )
-                        first_corner = corner;
-                }
-                polygon->AppendPoint( first_corner );   // Close polygon
+                if( idx == 0 )
+                    first_corner = corner;
             }
 
-            // this string _must_ be unique for a given physical shape
-            snprintf( name, sizeof(name), "RoundRect%sPad_%.6gx%.6g_%.6g_um_%f_%X",
-                      uniqifier.c_str(),
-                      IU2um( aPad->GetSize().x ),
-                      IU2um( aPad->GetSize().y ), IU2um( rradius ),
-                      doChamfer ? aPad->GetChamferRectRatio() : 0.0,
-                      doChamfer ? aPad->GetChamferPositions() : 0 );
-
-            name[ sizeof(name) - 1 ] = 0;
-
-            padstack->SetPadstackId( name );
+            polygon->AppendPoint( first_corner ); // Close polygon
         }
+
+        // this string _must_ be unique for a given physical shape
+        snprintf( name, sizeof( name ), "RoundRect%sPad_%.6gx%.6g_%.6g_um_%f_%X", uniqifier.c_str(),
+                  IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ), IU2um( rradius ),
+                  doChamfer ? aPad->GetChamferRectRatio() : 0.0,
+                  doChamfer ? aPad->GetChamferPositions() : 0 );
+
+        name[sizeof( name ) - 1] = 0;
+
+        padstack->SetPadstackId( name );
         break;
+    }
 
     case PAD_SHAPE::CUSTOM:
-        {
-            std::vector<wxPoint> polygonal_shape;
-            SHAPE_POLY_SET pad_shape;
-            aPad->MergePrimitivesAsPolygon( &pad_shape, UNDEFINED_LAYER );
+    {
+        std::vector<wxPoint> polygonal_shape;
+        SHAPE_POLY_SET       pad_shape;
+        aPad->MergePrimitivesAsPolygon( &pad_shape, UNDEFINED_LAYER );
 
 #ifdef EXPORT_CUSTOM_PADS_CONVEX_HULL
-            BuildConvexHull( polygonal_shape, pad_shape );
+        BuildConvexHull( polygonal_shape, pad_shape );
 #else
-            const SHAPE_LINE_CHAIN& p_outline = pad_shape.COutline( 0 );
+        const SHAPE_LINE_CHAIN& p_outline = pad_shape.COutline( 0 );
 
-            for( int ii = 0; ii < p_outline.PointCount(); ++ii )
-                polygonal_shape.push_back( wxPoint( p_outline.CPoint( ii ) ) );
+        for( int ii = 0; ii < p_outline.PointCount(); ++ii )
+            polygonal_shape.push_back( wxPoint( p_outline.CPoint( ii ) ) );
 #endif
 
-            // The polygon must be closed
-            if( polygonal_shape.front() != polygonal_shape.back() )
-                polygonal_shape.push_back( polygonal_shape.front() );
+        // The polygon must be closed
+        if( polygonal_shape.front() != polygonal_shape.back() )
+            polygonal_shape.push_back( polygonal_shape.front() );
 
-            for( int ndx=0; ndx < reportedLayers; ++ndx )
+        for( int ndx = 0; ndx < reportedLayers; ++ndx )
+        {
+            SHAPE* shape = new SHAPE( padstack );
+
+            padstack->Append( shape );
+
+            // a T_polygon exists as a PATH
+            PATH* polygon = new PATH( shape, T_polygon );
+
+            shape->SetShape( polygon );
+
+            polygon->SetLayerId( layerName[ndx] );
+
+            for( unsigned idx = 0; idx < polygonal_shape.size(); idx++ )
             {
-                SHAPE* shape = new SHAPE( padstack );
-
-                padstack->Append( shape );
-
-                // a T_polygon exists as a PATH
-                PATH* polygon = new PATH( shape, T_polygon );
-
-                shape->SetShape( polygon );
-
-                polygon->SetLayerId( layerName[ndx] );
-
-                for( unsigned idx = 0; idx < polygonal_shape.size(); idx++ )
-                {
-                    POINT corner( scale( polygonal_shape[idx].x ),
-                                  scale( -polygonal_shape[idx].y ) );
-                    corner += dsnOffset;
-                    polygon->AppendPoint( corner );
-                }
+                POINT corner( scale( polygonal_shape[idx].x ), scale( -polygonal_shape[idx].y ) );
+                corner += dsnOffset;
+                polygon->AppendPoint( corner );
             }
-
-            // this string _must_ be unique for a given physical shape, so try to make it unique
-            MD5_HASH hash  = pad_shape.GetHash();
-            EDA_RECT rect = aPad->GetBoundingBox();
-            snprintf( name, sizeof(name), "Cust%sPad_%.6gx%.6g_%.6gx_%.6g_%d_um_%s",
-                      uniqifier.c_str(), IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ),
-                      IU2um( rect.GetWidth() ), IU2um( rect.GetHeight() ),
-                      (int)polygonal_shape.size(), hash.Format( true ).c_str() );
-            name[ sizeof(name)-1 ] = 0;
-
-            padstack->SetPadstackId( name );
         }
+
+        // this string _must_ be unique for a given physical shape, so try to make it unique
+        MD5_HASH hash = pad_shape.GetHash();
+        EDA_RECT rect = aPad->GetBoundingBox();
+        snprintf( name, sizeof( name ), "Cust%sPad_%.6gx%.6g_%.6gx_%.6g_%d_um_%s",
+                  uniqifier.c_str(), IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ),
+                  IU2um( rect.GetWidth() ), IU2um( rect.GetHeight() ), (int) polygonal_shape.size(),
+                  hash.Format( true ).c_str() );
+        name[sizeof( name ) - 1] = 0;
+
+        padstack->SetPadstackId( name );
         break;
     }
+    }
 
     return padstack;
 }
@@ -625,7 +616,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint )
     image->image_id = aFootprint->GetFPID().Format().c_str();
 
     // from the pads, and make an IMAGE using collated padstacks.
-    for( int p=0; p < fpItems.GetCount(); ++p )
+    for( int p = 0; p < fpItems.GetCount(); ++p )
     {
         PAD* pad = (PAD*) fpItems[p];
 
@@ -652,9 +643,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint )
                 circle->SetLayerId( m_layerIds[layer].c_str() );
             }
         }
-        // else if() could there be a square keepout here?
-
-        else
+        else        // else if() could there be a square keepout here?
         {
             // Pads not on copper layers (i.e. only on tech layers) are ignored
             // because they create invalid pads in .dsn file for freeroute
@@ -739,35 +728,36 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint )
             break;
 
         case PCB_SHAPE_TYPE::CIRCLE:
+        {
+            // this is best done by 4 QARC's but freerouter does not yet support QARCs.
+            // for now, support by using line segments.
+            outline = new SHAPE( image, T_outline );
+            image->Append( outline );
+
+            path = new PATH( outline );
+
+            outline->SetShape( path );
+            path->SetAperture( scale( graphic->GetWidth() ) );
+            path->SetLayerId( "signal" );
+
+            double radius = graphic->GetRadius();
+            wxPoint circle_centre = graphic->GetStart0();
+
+            SHAPE_LINE_CHAIN polyline;
+            ConvertArcToPolyline( polyline, VECTOR2I( circle_centre ), radius, 0.0, 360.0,
+                                  ARC_HIGH_DEF, ERROR_INSIDE );
+
+            for( int ii = 0; ii < polyline.PointCount(); ++ii )
             {
-                // this is best done by 4 QARC's but freerouter does not yet support QARCs.
-                // for now, support by using line segments.
-                outline = new SHAPE( image, T_outline );
-                image->Append( outline );
-
-                path = new PATH( outline );
-
-                outline->SetShape( path );
-                path->SetAperture( scale( graphic->GetWidth() ) );
-                path->SetLayerId( "signal" );
-
-                double radius = graphic->GetRadius();
-                wxPoint circle_centre = graphic->GetStart0();
-
-                SHAPE_LINE_CHAIN polyline;
-                ConvertArcToPolyline( polyline, VECTOR2I( circle_centre ), radius, 0.0, 360.0,
-                                      ARC_HIGH_DEF, ERROR_INSIDE );
-
-                for( int ii = 0; ii < polyline.PointCount(); ++ii )
-                {
-                    wxPoint corner( polyline.CPoint( ii ).x, polyline.CPoint( ii ).y );
-                    path->AppendPoint( mapPt( corner ) );
-                }
+                wxPoint corner( polyline.CPoint( ii ).x, polyline.CPoint( ii ).y );
+                path->AppendPoint( mapPt( corner ) );
             }
+
             break;
+        }
 
         case PCB_SHAPE_TYPE::RECT:
-            {
+        {
             outline = new SHAPE( image, T_outline );
 
             image->Append( outline );
@@ -787,80 +777,79 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint )
 
             corner.x = graphic->GetStart0().x;
             path->AppendPoint( mapPt( corner ) );
-            }
             break;
+        }
 
         case PCB_SHAPE_TYPE::ARC:
+        {
+            // this is best done by QARC's but freerouter does not yet support QARCs.
+            // for now, support by using line segments.
+            // So we use a polygon (PATH) to create a approximate arc shape
+            outline = new SHAPE( image, T_outline );
+
+            image->Append( outline );
+            path = new PATH( outline );
+
+            outline->SetShape( path );
+            path->SetAperture( 0 );//scale( graphic->GetWidth() ) );
+            path->SetLayerId( "signal" );
+
+            wxPoint arc_centre = graphic->GetStart0();
+            double  radius = graphic->GetRadius() + graphic->GetWidth() / 2;
+            double  arcStartDeg = graphic->GetArcAngleStart() / 10.0;
+            double  arcAngleDeg = graphic->GetAngle() / 10.0;
+
+            // For some obscure reason, FreeRouter does not show the same polygonal
+            // shape for polygons CW and CCW. So used only the order of corners
+            // giving the best look.
+            if( arcAngleDeg < 0 )
             {
-                // this is best done by QARC's but freerouter does not yet support QARCs.
-                // for now, support by using line segments.
-                // So we use a polygon (PATH) to create a approximative arc shape
-                outline = new SHAPE( image, T_outline );
-
-                image->Append( outline );
-                path = new PATH( outline );
-
-                outline->SetShape( path );
-                path->SetAperture( 0 );//scale( graphic->GetWidth() ) );
-                path->SetLayerId( "signal" );
-
-                wxPoint arc_centre = graphic->GetStart0();
-                double radius = graphic->GetRadius() + graphic->GetWidth()/2;
-                double arcStartDeg = graphic->GetArcAngleStart() / 10.0;
-                double arcAngleDeg = graphic->GetAngle() / 10.0;
-
-                // For some obscure reason, FreeRouter does not show the same polygonal
-                // shape for polygons CW and CCW. So used only the order of corners
-                // giving the best look.
-                if( arcAngleDeg < 0 )
-                {
-                    arcStartDeg = graphic->GetArcAngleEnd() / 10.0;
-                    arcAngleDeg = - arcAngleDeg;
-                }
-
-                SHAPE_LINE_CHAIN polyline;
-                ConvertArcToPolyline( polyline, VECTOR2I( arc_centre ), radius,
-                                      arcStartDeg, arcAngleDeg, ARC_HIGH_DEF, ERROR_INSIDE );
-
-                SHAPE_POLY_SET polyBuffer;
-                polyBuffer.AddOutline( polyline );
-
-                radius -= graphic->GetWidth();
-
-                if( radius > 0 )
-                {
-                    polyline.Clear();
-                    ConvertArcToPolyline( polyline, VECTOR2I( arc_centre ), radius,
-                                          arcStartDeg, arcAngleDeg, ARC_HIGH_DEF, ERROR_INSIDE );
-
-                    // Add points in reverse order, to create a closed polygon
-                    for( int ii = polyline.PointCount()-1; ii >= 0; --ii )
-                        polyBuffer.Append( polyline.CPoint( ii ) );
-                }
-
-                // ensure the polygon is closed
-                polyBuffer.Append( polyBuffer.Outline(0).CPoint( 0 ) );
-
-                wxPoint move = graphic->GetCenter() - arc_centre;
-
-                TransformCircleToPolygon( polyBuffer, graphic->GetArcStart() - move,
-                                          graphic->GetWidth()/2,
-                                          ARC_HIGH_DEF, ERROR_INSIDE );
-
-                TransformCircleToPolygon( polyBuffer, graphic->GetArcEnd() - move,
-                                          graphic->GetWidth()/2,
-                                          ARC_HIGH_DEF, ERROR_INSIDE );
-
-                polyBuffer.Simplify( SHAPE_POLY_SET::PM_FAST );
-                SHAPE_LINE_CHAIN& poly = polyBuffer.Outline( 0 );
-
-                for( int ii = 0; ii < poly.PointCount(); ++ii )
-                {
-                    wxPoint corner( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
-                    path->AppendPoint( mapPt( corner ) );
-                }
+                arcStartDeg = graphic->GetArcAngleEnd() / 10.0;
+                arcAngleDeg = -arcAngleDeg;
             }
+
+            SHAPE_LINE_CHAIN polyline;
+            ConvertArcToPolyline( polyline, VECTOR2I( arc_centre ), radius, arcStartDeg,
+                                  arcAngleDeg, ARC_HIGH_DEF, ERROR_INSIDE );
+
+            SHAPE_POLY_SET polyBuffer;
+            polyBuffer.AddOutline( polyline );
+
+            radius -= graphic->GetWidth();
+
+            if( radius > 0 )
+            {
+                polyline.Clear();
+                ConvertArcToPolyline( polyline, VECTOR2I( arc_centre ), radius, arcStartDeg,
+                                      arcAngleDeg, ARC_HIGH_DEF, ERROR_INSIDE );
+
+                // Add points in reverse order, to create a closed polygon
+                for( int ii = polyline.PointCount() - 1; ii >= 0; --ii )
+                    polyBuffer.Append( polyline.CPoint( ii ) );
+            }
+
+            // ensure the polygon is closed
+            polyBuffer.Append( polyBuffer.Outline( 0 ).CPoint( 0 ) );
+
+            wxPoint move = graphic->GetCenter() - arc_centre;
+
+            TransformCircleToPolygon( polyBuffer, graphic->GetArcStart() - move,
+                                      graphic->GetWidth() / 2, ARC_HIGH_DEF, ERROR_INSIDE );
+
+            TransformCircleToPolygon( polyBuffer, graphic->GetArcEnd() - move,
+                                      graphic->GetWidth() / 2, ARC_HIGH_DEF, ERROR_INSIDE );
+
+            polyBuffer.Simplify( SHAPE_POLY_SET::PM_FAST );
+            SHAPE_LINE_CHAIN& poly = polyBuffer.Outline( 0 );
+
+            for( int ii = 0; ii < poly.PointCount(); ++ii )
+            {
+                wxPoint corner( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
+                path->AppendPoint( mapPt( corner ) );
+            }
+
             break;
+        }
 
         default:
             continue;
@@ -1063,8 +1052,8 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary )
         for( int ii = 0; ii < m_brd_outlines.HoleCount( cnt ); ii++ )
         {
             // emit a signal layers keepout for every interior polygon left...
-            KEEPOUT*    keepout = new KEEPOUT( NULL, T_keepout );
-            PATH*       poly_ko = new PATH( NULL, T_polygon );
+            KEEPOUT*    keepout = new KEEPOUT( nullptr, T_keepout );
+            PATH*       poly_ko = new PATH( nullptr, T_polygon );
 
             keepout->SetShape( poly_ko );
             poly_ko->SetLayerId( "signal" );
@@ -1250,7 +1239,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
         static const KICAD_T scanZONEs[] = { PCB_ZONE_T, EOT };
         items.Collect( aBoard, scanZONEs );
 
-        for( int i = 0; i<items.GetCount(); ++i )
+        for( int i = 0; i < items.GetCount(); ++i )
         {
             ZONE* item = (ZONE*) items[i];
 
@@ -1368,7 +1357,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
         static const KICAD_T  scanZONEs[] = { PCB_ZONE_T, EOT };
         items.Collect( aBoard, scanZONEs );
 
-        for( int i=0;  i<items.GetCount();  ++i )
+        for( int i = 0; i < items.GetCount(); ++i )
         {
             ZONE* item = (ZONE*) items[i];
 
@@ -1495,7 +1484,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
         deleteNETs();
 
         // expand the net vector to highestNetCode+1, setting empty to NULL
-        m_nets.resize( highestNetCode + 1, NULL );
+        m_nets.resize( highestNetCode + 1, nullptr );
 
         for( unsigned i = 1 /* skip "No Net" at [0] */; i < m_nets.size(); ++i )
             m_nets[i] = new NET( m_pcb->network );
@@ -1510,7 +1499,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
 
         m_padstackset.clear();
 
-        for( int m = 0; m<items.GetCount(); ++m )
+        for( int m = 0; m < items.GetCount(); ++m )
         {
             FOOTPRINT* footprint = (FOOTPRINT*) items[m];
 
@@ -1526,7 +1515,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
             // exported netlist will have some fabricated pin names in it.
             // If you don't like fabricated pin names, then make sure all pads
             // within your FOOTPRINTs are uniquely named!
-            for( unsigned p = 0; p<image->pins.size(); ++p )
+            for( unsigned p = 0; p < image->pins.size(); ++p )
             {
                 PIN*    pin = &image->pins[p];
 
@@ -1663,7 +1652,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
         int old_width = -1;
         LAYER_NUM old_layer = UNDEFINED_LAYER;
 
-        for( int i=0;  i<items.GetCount();  ++i )
+        for( int i = 0; i < items.GetCount(); ++i )
         {
             PCB_TRACK*  track = static_cast<PCB_TRACK*>( items[i] );
             int         netcode = track->GetNetCode();
diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp
index 55d17ee1dd..22c386f22c 100644
--- a/pcbnew/toolbars_footprint_editor.cpp
+++ b/pcbnew/toolbars_footprint_editor.cpp
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
- * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -32,6 +32,7 @@
 #include <pcb_layer_box_selector.h>
 #include <wx/choice.h>
 
+
 void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
 {
     // Note:
@@ -48,7 +49,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
     else
     {
         m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
-                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL);
+                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
+                                            wxAUI_TB_HORIZONTAL );
         m_mainToolBar->SetAuiManager( &m_auimgr );
     }
 
@@ -99,7 +101,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
     // Grid selection choice box.
     if( m_gridSelectBox == nullptr )
         m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT,
-                                    wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateGridSelectBox();
     m_mainToolBar->AddControl( m_gridSelectBox );
@@ -109,7 +111,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
     // Zoom selection choice box.
     if( m_zoomSelectBox == nullptr )
         m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT,
-                                    wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateZoomSelectBox();
     m_mainToolBar->AddControl( m_zoomSelectBox );
@@ -122,7 +124,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
         m_selLayerBox = new PCB_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_PCB_SELECT_LAYER );
         m_selLayerBox->SetBoardFrame( this );
 
-        // Some layers cannot be seclect (they are shown in the layer manager
+        // Some layers cannot be select (they are shown in the layer manager
         // only to set the color and visibility, but not for selection)
         // Disable them in layer box
         m_selLayerBox->SetNotAllowedLayerSet( LSET::ForbiddenFootprintLayers() );
@@ -186,7 +188,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar()
     }
     else
     {
-        m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
+        m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
+                                               wxDefaultSize,
                                                KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
         m_optionsToolBar->SetAuiManager( &m_auimgr );
     }
@@ -230,7 +233,7 @@ void FOOTPRINT_EDIT_FRAME::UpdateToolbarControlSizes()
 
 void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
 {
-    if( m_selLayerBox == NULL || m_mainToolBar == NULL )
+    if( m_selLayerBox == nullptr || m_mainToolBar == nullptr )
         return;
 
     m_selLayerBox->SetToolTip( _( "+/- to switch" ) );
diff --git a/pcbnew/toolbars_footprint_viewer.cpp b/pcbnew/toolbars_footprint_viewer.cpp
index 0c77968a65..52ebf06fd9 100644
--- a/pcbnew/toolbars_footprint_viewer.cpp
+++ b/pcbnew/toolbars_footprint_viewer.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -50,7 +50,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
     else
     {
         m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
-                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
+                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
+                                            wxAUI_TB_HORIZONTAL );
         m_mainToolBar->SetAuiManager( &m_auimgr );
     }
 
@@ -67,7 +68,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
     m_mainToolBar->Add( ACTIONS::zoomInCenter );
     m_mainToolBar->Add( ACTIONS::zoomOutCenter );
     m_mainToolBar->Add( ACTIONS::zoomFitScreen );
-    m_mainToolBar->Add( ACTIONS::zoomTool,                       ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
+    m_mainToolBar->Add( ACTIONS::zoomTool,
+                        ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
     m_mainToolBar->Add( PCB_ACTIONS::zoomFootprintAutomatically, ACTION_TOOLBAR::TOGGLE );
 
     m_mainToolBar->AddScaledSeparator( this );
@@ -81,7 +83,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
     // Grid selection choice box.
     if( m_gridSelectBox == nullptr )
         m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT,
-                                    wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateGridSelectBox();
     m_mainToolBar->AddControl( m_gridSelectBox );
@@ -91,7 +93,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
     // Zoom selection choice box.
     if( m_zoomSelectBox == nullptr )
         m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT,
-                                    wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateZoomSelectBox();
     m_mainToolBar->AddControl( m_zoomSelectBox );
@@ -110,7 +112,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar()
     }
     else
     {
-        m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
+        m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
+                                               wxDefaultSize,
                                                KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
         m_optionsToolBar->SetAuiManager( &m_auimgr );
     }
@@ -145,6 +148,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar()
 void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar()
 {
     PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
+
     // wxWidgets handles the Mac Application menu behind the scenes, but that means
     // we always have to start from scratch with a new wxMenuBar.
     wxMenuBar*  oldMenuBar = GetMenuBar();
@@ -157,7 +161,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar()
 
     fileMenu->AddClose( _( "Footprint Viewer" ) );
 
-
     //----- View menu -----------------------------------------------------------
     //
     ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
@@ -171,7 +174,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar()
     viewMenu->AppendSeparator();
     viewMenu->Add( ACTIONS::show3DViewer );
 
-
     //----- Menubar -------------------------------------------------------------
     //
     menuBar->Append( fileMenu, _( "&File" ) );
diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp
index f62d62f423..2aa30de6cf 100644
--- a/pcbnew/toolbars_pcb_editor.cpp
+++ b/pcbnew/toolbars_pcb_editor.cpp
@@ -4,7 +4,7 @@
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
- * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -211,11 +211,12 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
     else
     {
         m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
-                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
+                                            KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
+                                            wxAUI_TB_HORIZONTAL );
         m_mainToolBar->SetAuiManager( &m_auimgr );
 
-        // The layer indicator is special, so we register a callback directly that will regenerate the
-        // bitmap instead of using the conditions system
+        // The layer indicator is special, so we register a callback directly that will
+        // regenerate the bitmap instead of using the conditions system.
         auto layerIndicatorUpdate =
             [this] ( wxUpdateUIEvent& )
             {
@@ -508,7 +509,8 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
     }
     else
     {
-        m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
+        m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR, wxDefaultPosition,
+                                                 wxDefaultSize,
                                                  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
         m_auxiliaryToolBar->SetAuiManager( &m_auimgr );
     }
@@ -518,7 +520,7 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
     // Creates box to display and choose tracks widths:
     if( m_SelTrackWidthBox == nullptr )
         m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
-                                           wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                           wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
     m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
@@ -539,7 +541,7 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
 
     if( m_SelViaSizeBox == nullptr )
         m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_VIA_SIZE,
-                                        wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateViaSizeSelectBox( m_SelViaSizeBox );
     m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
@@ -549,7 +551,7 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
 
     if( m_gridSelectBox == nullptr )
         m_gridSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_GRID_SELECT,
-                                        wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateGridSelectBox();
 
@@ -560,7 +562,7 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
 
     if( m_zoomSelectBox == nullptr )
         m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_ZOOM_SELECT,
-                                        wxDefaultPosition, wxDefaultSize, 0, NULL );
+                                        wxDefaultPosition, wxDefaultSize, 0, nullptr );
 
     UpdateZoomSelectBox();
     m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
@@ -624,7 +626,7 @@ static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLab
 
 void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, bool aEdit )
 {
-    if( aTrackWidthSelectBox == NULL )
+    if( aTrackWidthSelectBox == nullptr )
         return;
 
     EDA_UNITS primaryUnit;
@@ -663,7 +665,7 @@ void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox,
 
 void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool aEdit )
 {
-    if( aViaSizeSelectBox == NULL )
+    if( aViaSizeSelectBox == nullptr )
         return;
 
     aViaSizeSelectBox->Clear();
@@ -731,7 +733,7 @@ void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool a
 
 void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
 {
-    if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
+    if( m_SelLayerBox == nullptr || m_mainToolBar == nullptr )
         return;
 
     m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp
index 1c0b3ce2ba..8a3d49def5 100644
--- a/pcbnew/tools/board_editor_control.cpp
+++ b/pcbnew/tools/board_editor_control.cpp
@@ -503,10 +503,7 @@ int BOARD_EDITOR_CONTROL::RepairBoard( const TOOL_EVENT& aEvent )
     wxString details;
     bool     quiet = aEvent.Parameter<bool>();
 
-    /*******************************
-     * Repair duplicate IDs and missing nets
-     */
-
+    // Repair duplicate IDs and missing nets.
     std::set<KIID> ids;
     int            duplicates = 0;
 
@@ -985,7 +982,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
                         }
                     }
 
-                    fp = NULL;
+                    fp = nullptr;
                 };
 
         if( evt->IsCancelInteractive() )
@@ -1021,7 +1018,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
                 // Pick the footprint to be placed
                 fp = m_frame->SelectFootprintFromLibTree();
 
-                if( fp == NULL )
+                if( fp == nullptr )
                     continue;
 
                 fp->SetLink( niluuid );
@@ -1055,7 +1052,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
             {
                 m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
                 commit.Push( _( "Place a footprint" ) );
-                fp = NULL;  // to indicate that there is no footprint that we currently modify
+                fp = nullptr;  // to indicate that there is no footprint that we currently modify
             }
         }
         else if( evt->IsClick( BUT_RIGHT ) )
@@ -1509,17 +1506,20 @@ void BOARD_EDITOR_CONTROL::setTransitions()
 
     Go( &BOARD_EDITOR_CONTROL::BoardSetup,             PCB_ACTIONS::boardSetup.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::ImportNetlist,          PCB_ACTIONS::importNetlist.MakeEvent() );
-    Go( &BOARD_EDITOR_CONTROL::ImportSpecctraSession,  PCB_ACTIONS::importSpecctraSession.MakeEvent() );
+    Go( &BOARD_EDITOR_CONTROL::ImportSpecctraSession,
+        PCB_ACTIONS::importSpecctraSession.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::ExportSpecctraDSN,      PCB_ACTIONS::exportSpecctraDSN.MakeEvent() );
 
     if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist && m_frame &&
         m_frame->GetExportNetlistAction() )
         Go( &BOARD_EDITOR_CONTROL::ExportNetlist, m_frame->GetExportNetlistAction()->MakeEvent() );
 
-    Go( &BOARD_EDITOR_CONTROL::GenerateDrillFiles,     PCB_ACTIONS::generateDrillFiles.MakeEvent() );
+    Go( &BOARD_EDITOR_CONTROL::GenerateDrillFiles,
+        PCB_ACTIONS::generateDrillFiles.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles,       PCB_ACTIONS::generateGerbers.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::GeneratePosFile,        PCB_ACTIONS::generatePosFile.MakeEvent() );
-    Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles,       PCB_ACTIONS::generateReportFile.MakeEvent() );
+    Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles,
+        PCB_ACTIONS::generateReportFile.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles,       PCB_ACTIONS::generateD356File.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles,       PCB_ACTIONS::generateBOM.MakeEvent() );
 
@@ -1545,8 +1545,10 @@ void BOARD_EDITOR_CONTROL::setTransitions()
     Go( &BOARD_EDITOR_CONTROL::LockSelected,           PCB_ACTIONS::lock.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::UnlockSelected,         PCB_ACTIONS::unlock.MakeEvent() );
 
-    Go( &BOARD_EDITOR_CONTROL::UpdatePCBFromSchematic, ACTIONS::updatePcbFromSchematic.MakeEvent() );
-    Go( &BOARD_EDITOR_CONTROL::UpdateSchematicFromPCB, ACTIONS::updateSchematicFromPcb.MakeEvent() );
+    Go( &BOARD_EDITOR_CONTROL::UpdatePCBFromSchematic,
+        ACTIONS::updatePcbFromSchematic.MakeEvent() );
+    Go( &BOARD_EDITOR_CONTROL::UpdateSchematicFromPCB,
+        ACTIONS::updateSchematicFromPcb.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::ShowEeschema,           PCB_ACTIONS::showEeschema.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::ToggleLayersManager,    PCB_ACTIONS::showLayersManager.MakeEvent() );
     Go( &BOARD_EDITOR_CONTROL::TogglePythonConsole,    PCB_ACTIONS::showPythonConsole.MakeEvent() );
diff --git a/pcbnew/tools/board_reannotate_tool.cpp b/pcbnew/tools/board_reannotate_tool.cpp
index dca58de349..8d8617d6dd 100644
--- a/pcbnew/tools/board_reannotate_tool.cpp
+++ b/pcbnew/tools/board_reannotate_tool.cpp
@@ -31,7 +31,7 @@
 
 BOARD_REANNOTATE_TOOL::BOARD_REANNOTATE_TOOL() :
      PCB_TOOL_BASE( "pcbnew.ReannotateTool" ),
-     m_selectionTool( NULL ),
+     m_selectionTool( nullptr ),
      m_frame( nullptr )
 {
 }
diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp
index a1737329a6..bc1a9977f3 100644
--- a/pcbnew/tools/convert_tool.cpp
+++ b/pcbnew/tools/convert_tool.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Jon Evans <jon@craftyjon.com>
  *
  * This program is free software; you can redistribute it and/or
@@ -48,12 +48,13 @@
 
 CONVERT_TOOL::CONVERT_TOOL() :
     TOOL_INTERACTIVE( "pcbnew.Convert" ),
-    m_selectionTool( NULL ),
-    m_menu( NULL ),
-    m_frame( NULL )
+    m_selectionTool( nullptr ),
+    m_menu( nullptr ),
+    m_frame( nullptr )
 {
 }
 
+
 CONVERT_TOOL::~CONVERT_TOOL()
 {
     delete m_menu;
@@ -601,7 +602,7 @@ int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent )
                 if( copperLayer == UNSELECTED_LAYER )
                     copperLayer = frame->SelectOneLayer( F_Cu, LSET::AllNonCuMask() );
 
-                if( copperLayer == UNDEFINED_LAYER )    // User cancelled
+                if( copperLayer == UNDEFINED_LAYER )    // User canceled
                     continue;
 
                 layer = copperLayer;
diff --git a/pcbnew/tools/drawing_stackup_table_tool.cpp b/pcbnew/tools/drawing_stackup_table_tool.cpp
index d6c07f05d5..34089e6c34 100644
--- a/pcbnew/tools/drawing_stackup_table_tool.cpp
+++ b/pcbnew/tools/drawing_stackup_table_tool.cpp
@@ -46,9 +46,11 @@
 
 using SCOPED_DRAW_MODE = SCOPED_SET_RESET<DRAWING_TOOL::MODE>;
 
+
 static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*>> aContent,
-                                        wxPoint origin, PCB_LAYER_ID aLayer, wxPoint* aTableSize,
-                                        bool aDrawFrame = true )
+                                               wxPoint origin, PCB_LAYER_ID aLayer,
+                                               wxPoint* aTableSize,
+                                               bool aDrawFrame = true )
 {
     int i;
     int j;
@@ -172,6 +174,7 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
         line->SetEndY( origin.y + height );
         table.push_back( line );
     }
+
     //Now add the text
     i           = 0;
     wxPoint pos = wxPoint( origin.x + xmargin, origin.y + ymargin );
@@ -354,6 +357,7 @@ std::vector<BOARD_ITEM*> DRAWING_TOOL::DrawSpecificationStackup(
     return table;
 }
 
+
 std::vector<BOARD_ITEM*> DRAWING_TOOL::DrawBoardCharacteristics(
         wxPoint aOrigin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint* tableSize )
 {
@@ -530,8 +534,8 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
 
     m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
     m_controls->ShowCursor( true );
-    // do not capture or auto-pan until we start placing the table
 
+    // do not capture or auto-pan until we start placing the table
     SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
 
     std::string tool = aEvent.GetCommandStr().get();
@@ -606,7 +610,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
         }
         else if( evt->IsClick( BUT_LEFT ) )
         {
-            if( aLayers != NULL )
+            if( aLayers != nullptr )
             {
                 PCB_LAYER_ID targetLayer = frame()->SelectOneLayer(
                                             PCB_LAYER_ID::PCB_LAYER_ID_COUNT,
@@ -652,9 +656,10 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
 
             break;
         }
-
         else
+        {
             evt->SetPassEvent();
+        }
     }
 
     view()->ClearPreview();
diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp
index 64025d098a..dd213083f2 100644
--- a/pcbnew/tools/drawing_tool.cpp
+++ b/pcbnew/tools/drawing_tool.cpp
@@ -455,7 +455,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
     else
         m_inDrawingTool = true;
 
-    BOARD_ITEM*                  text = NULL;
+    BOARD_ITEM*                  text = nullptr;
     const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
     BOARD_COMMIT                 commit( m_frame );
     SCOPED_DRAW_MODE             scopedDrawMode( m_mode, MODE::TEXT );
@@ -469,7 +469,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
                 m_controls->SetAutoPan( false );
                 m_controls->CaptureCursor( false );
                 delete text;
-                text = NULL;
+                text = nullptr;
             };
 
     auto setCursor =
@@ -582,7 +582,8 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
                 else
                 {
                     PCB_TEXT* pcbText = new PCB_TEXT( m_frame->GetModel() );
-                    // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an undo entry :| LEGACY_CLEANUP
+                    // TODO we have to set IS_NEW, otherwise InstallTextPCB.. creates an
+                    // undo entry :| LEGACY_CLEANUP
                     pcbText->SetFlags( IS_NEW );
 
                     pcbText->SetLayer( layer );
@@ -893,8 +894,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
 
                 m_controls->SetAutoPan( true );
                 m_controls->CaptureCursor( true );
-            }
                 break;
+            }
 
             case SET_END:
             {
@@ -1378,14 +1379,15 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
 
 int DRAWING_TOOL::ToggleLine45degMode( const TOOL_EVENT& toolEvent )
 {
-    m_frame->Settings().m_Use45DegreeGraphicSegments = !m_frame->Settings().m_Use45DegreeGraphicSegments;
+    m_frame->Settings().m_Use45DegreeGraphicSegments =
+            !m_frame->Settings().m_Use45DegreeGraphicSegments;
 
     return 0;
 }
 
 
 /**
- * Update an PCB_SHAPE from the current state of a TWO_POINT_GEOMETRY_MANAGER
+ * Update a #PCB_SHAPE from the current state of a #TWO_POINT_GEOMETRY_MANAGER.
  */
 static void updateSegmentFromGeometryMgr( const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER& aMgr,
                                           PCB_SHAPE* aGraphic )
@@ -1402,6 +1404,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
                                 OPT<VECTOR2D> aStartingPoint )
 {
     PCB_SHAPE_TYPE shape = ( *aGraphic )->GetShape();
+
     // Only three shapes are currently supported
     wxASSERT( shape == PCB_SHAPE_TYPE::SEGMENT || shape == PCB_SHAPE_TYPE::CIRCLE
               || shape == PCB_SHAPE_TYPE::RECT );
@@ -1717,8 +1720,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
 
 
 /**
- * Update an arc PCB_SHAPE from the current state
- * of an Arc Geometry Manager
+ * Update an arc PCB_SHAPE from the current state of an Arc Geometry Manager.
  */
 static void updateArcFromConstructionMgr( const KIGFX::PREVIEW::ARC_GEOM_MANAGER& aMgr,
                                           PCB_SHAPE& aArc )
diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp
index 2157474d4e..fe5003dacd 100644
--- a/pcbnew/tools/edit_tool.cpp
+++ b/pcbnew/tools/edit_tool.cpp
@@ -2,9 +2,9 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2017 CERN
+ * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
- * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -70,7 +70,7 @@ using namespace std::placeholders;
 
 EDIT_TOOL::EDIT_TOOL() :
         PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
-        m_selectionTool( NULL ),
+        m_selectionTool( nullptr ),
         m_dragging( false )
 {
 }
@@ -197,6 +197,7 @@ bool EDIT_TOOL::Init()
     menu.AddSeparator( 150 );
     menu.AddItem( ACTIONS::cut,                   SELECTION_CONDITIONS::NotEmpty, 150 );
     menu.AddItem( ACTIONS::copy,                  SELECTION_CONDITIONS::NotEmpty, 150 );
+
     // Selection tool handles the context menu for some other tools, such as the Picker.
     // Don't add things like Paste when another tool is active.
     menu.AddItem( ACTIONS::paste,                 noActiveToolCondition, 150 );
@@ -248,7 +249,8 @@ bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
         return false;
     }
 
-    // make sure we don't accidentally invoke inline routing mode while the router is already active!
+    // make sure we don't accidentally invoke inline routing mode while the router is already
+    // active!
     if( theRouter->IsToolActive() )
         return false;
 
@@ -458,7 +460,7 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
     // projected intersection points.
     //
     // The cursor will be constrained first within the isosceles triangle formed by the segments
-    // cSegTanStart, cSegTanEnd and cSegChord. After that it will be constratined to be outside
+    // cSegTanStart, cSegTanEnd and cSegChord. After that it will be constrained to be outside
     // maxTanCircle.
     //
     //
@@ -515,7 +517,6 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
     bool hasMouseMoved = false;
 
     // Start the tool loop
-    //====================
     while( TOOL_EVENT* evt = Wait() )
     {
         m_cursor = controls->GetMousePosition();
@@ -559,7 +560,7 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
         VECTOR2I newEnd = cSegTanEnd.LineProject( newCenter );
         VECTOR2I newMid = GetArcMid( newStart, newEnd, newCenter );
 
-        //Update objects
+        // Update objects
         theArc->SetStart( (wxPoint) newStart );
         theArc->SetEnd( (wxPoint) newEnd );
         theArc->SetMid( (wxPoint) newMid );
@@ -574,12 +575,12 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
         else
             trackOnEnd->SetEnd( (wxPoint) newEnd );
 
-        //Update view
+        // Update view
         getView()->Update( trackOnStart );
         getView()->Update( trackOnEnd );
         getView()->Update( theArc );
 
-        //Handle events
+        // Handle events
         if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
         {
             hasMouseMoved = true;
@@ -705,7 +706,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
     VECTOR2I              originalCursorPos = controls->GetCursorPosition();
 
     // Be sure that there is at least one item that we can modify. If nothing was selected before,
-    // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
+    // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
     PCB_SELECTION& selection = m_selectionTool->RequestSelection(
             []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
             {
@@ -777,7 +778,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
                     if( item->Type() == PCB_MARKER_T )
                         aCollector.Remove( item );
 
-                    // Treat all pads as locked (i.e. cannot be moved indepenendtly of footprint)
+                    // Treat all pads as locked (i.e. cannot be moved independently of footprint)
                     if( !sTool->IsFootprintEditor() && item->Type() == PCB_PAD_T )
                     {
                         if( !aCollector.HasItem( item->GetParent() ) )
@@ -1013,7 +1014,6 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
             m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false,
                                   new VECTOR2I( movement ) );
         }
-
         else if( evt->IsCancelInteractive() || evt->IsActivate() )
         {
             if( m_dragging && evt->IsCancelInteractive() )
@@ -1022,16 +1022,14 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
             restore_state = true; // Canceling the tool means that items have to be restored
             break;                // Finish
         }
-
         else if( evt->IsAction( &ACTIONS::undo ) )
         {
             restore_state = true; // Perform undo locally
             break;                // Finish
         }
-
-        // Dispatch TOOL_ACTIONs
         else if( evt->IsAction( &ACTIONS::doDelete ) || evt->IsAction( &ACTIONS::cut ) )
         {
+            // Dispatch TOOL_ACTIONs
             evt->SetPassEvent();
             break; // finish -- there is no further processing for removed items
         }
@@ -1077,7 +1075,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
     // Discard reference point when selection is "dropped" onto the board
     selection.ClearReferencePoint();
 
-    // TODO: there's an ecapsulation leak here: this commit often has more than just the move
+    // TODO: there's an encapsulation leak here: this commit often has more than just the move
     // in it; for instance it might have a paste, append board, etc. as well.
     if( restore_state )
         m_commit->Revert();
@@ -1210,7 +1208,6 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
         return 0;
     }
 
-
     struct FILLET_OP
     {
         PCB_TRACK* t1;
@@ -1495,8 +1492,8 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
 }
 
 
-/*!
- * Mirror a point about the vertical axis passing through another point
+/**
+ * Mirror a point about the vertical axis passing through another point.
  */
 static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
 {
@@ -1511,7 +1508,7 @@ static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint
 
 
 /**
- * Mirror a pad in the vertical axis passing through a point (mirror left to right)
+ * Mirror a pad in the vertical axis passing through a point (mirror left to right).
  */
 static void mirrorPadX( PAD& aPad, const wxPoint& aMirrorPoint )
 {
@@ -1776,76 +1773,78 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
         switch( item->Type() )
         {
         case PCB_FP_TEXT_T:
-            {
-                FP_TEXT*   text = static_cast<FP_TEXT*>( item );
-                FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
+        {
+            FP_TEXT*   text = static_cast<FP_TEXT*>( item );
+            FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
 
-                if( text->GetType() == FP_TEXT::TEXT_is_DIVERS )
-                {
-                    m_commit->Modify( parent );
-                    getView()->Remove( text );
-                    parent->Remove( text );
-                }
+            if( text->GetType() == FP_TEXT::TEXT_is_DIVERS )
+            {
+                m_commit->Modify( parent );
+                getView()->Remove( text );
+                parent->Remove( text );
             }
+
             break;
+        }
 
         case PCB_PAD_T:
-            {
-                PAD*       pad = static_cast<PAD*>( item );
-                FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
+        {
+            PAD*       pad = static_cast<PAD*>( item );
+            FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
 
-                m_commit->Modify( parent );
-                getView()->Remove( pad );
-                parent->Remove( pad );
-            }
+            m_commit->Modify( parent );
+            getView()->Remove( pad );
+            parent->Remove( pad );
             break;
+        }
 
         case PCB_FP_ZONE_T:
-            {
-                FP_ZONE*   zone = static_cast<FP_ZONE*>( item );
-                FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
+        {
+            FP_ZONE*   zone = static_cast<FP_ZONE*>( item );
+            FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
 
-                m_commit->Modify( parent );
-                getView()->Remove( zone );
-                parent->Remove( zone );
-            }
+            m_commit->Modify( parent );
+            getView()->Remove( zone );
+            parent->Remove( zone );
             break;
+        }
 
         case PCB_ZONE_T:
-            // We process the zones special so that cutouts can be deleted when the delete tool
-            // is called from inside a cutout when the zone is selected.
+        // We process the zones special so that cutouts can be deleted when the delete tool
+        // is called from inside a cutout when the zone is selected.
+        {
+            // Only interact with cutouts when deleting and a single item is selected
+            if( !isCut && selectionCopy.GetSize() == 1 )
             {
-                // Only interact with cutouts when deleting and a single item is selected
-                if( !isCut && selectionCopy.GetSize() == 1 )
+                VECTOR2I curPos = getViewControls()->GetCursorPosition();
+                ZONE*    zone   = static_cast<ZONE*>( item );
+
+                int outlineIdx, holeIdx;
+
+                if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
                 {
-                    VECTOR2I curPos = getViewControls()->GetCursorPosition();
-                    ZONE*    zone   = static_cast<ZONE*>( item );
+                    // Remove the cutout
+                    m_commit->Modify( zone );
+                    zone->RemoveCutout( outlineIdx, holeIdx );
+                    zone->UnFill();
 
-                    int outlineIdx, holeIdx;
+                    // TODO Refill zone when KiCad supports auto re-fill
 
-                    if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
-                    {
-                        // Remove the cutout
-                        m_commit->Modify( zone );
-                        zone->RemoveCutout( outlineIdx, holeIdx );
-                        zone->UnFill();
-                        // TODO Refill zone when KiCad supports auto re-fill
+                    // Update the display
+                    zone->HatchBorder();
+                    canvas()->Refresh();
 
-                        // Update the display
-                        zone->HatchBorder();
-                        canvas()->Refresh();
+                    // Restore the selection on the original zone
+                    m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, zone );
 
-                        // Restore the selection on the original zone
-                        m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, zone );
-
-                        break;
-                    }
+                    break;
                 }
-
-                // Remove the entire zone otherwise
-                m_commit->Remove( item );
             }
+
+            // Remove the entire zone otherwise
+            m_commit->Remove( item );
             break;
+        }
 
         case PCB_GROUP_T:
         {
@@ -1879,8 +1878,8 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
                                      {
                                          removeItem( aDescendant );
                                      });
-        }
             break;
+        }
 
         default:
             m_commit->Remove( item );
@@ -2048,7 +2047,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
     std::vector<BOARD_ITEM*> new_items;
     new_items.reserve( selection.Size() );
 
-
     // Each selected item is duplicated and pushed to new_items list
     // Old selection is cleared, and new items are then selected.
     for( EDA_ITEM* item : selection )
@@ -2140,7 +2138,8 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
         editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
                                                      (int) new_items.size() ) );
 
-        // TODO(ISM): This line can't be used to activate the tool until we allow multiple activations
+        // TODO(ISM): This line can't be used to activate the tool until we allow multiple
+        //            activations.
         // m_toolMgr->RunAction( PCB_ACTIONS::move, true );
         // Instead we have to create the event and call the tool's function
         // directly
@@ -2317,7 +2316,8 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
 {
     std::string  tool = "pcbnew.InteractiveEdit.selectReferencePoint";
     CLIPBOARD_IO io;
-    PCB_GRID_HELPER grid( m_toolMgr, getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
+    PCB_GRID_HELPER grid( m_toolMgr,
+                          getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
 
     frame()->PushTool( tool );
     Activate();
@@ -2335,7 +2335,9 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
                         aCollector.Remove( item );
                 }
             },
-            aEvent.IsAction( &ACTIONS::cut ) && !m_isFootprintEditor /* prompt user regarding locked items */ );
+
+            // Prompt user regarding locked items.
+            aEvent.IsAction( &ACTIONS::cut ) && !m_isFootprintEditor );
 
     if( !selection.Empty() )
     {
@@ -2350,7 +2352,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
         {
             if( !pickReferencePoint( _( "Select reference point for the copy..." ),
                                      _( "Selection copied" ),
-                                     _( "Copy cancelled" ),
+                                     _( "Copy canceled" ),
                                      refPoint ) )
                 return 0;
         }
diff --git a/pcbnew/tools/footprint_editor_control.cpp b/pcbnew/tools/footprint_editor_control.cpp
index 7c47932b74..c05cf6beaa 100644
--- a/pcbnew/tools/footprint_editor_control.cpp
+++ b/pcbnew/tools/footprint_editor_control.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2014-2019 CERN
- * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
  * This program is free software; you can redistribute it and/or
@@ -80,6 +80,7 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
                 LIB_ID sel = m_frame->GetTreeFPID();
                 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
             };
+
     // The libInferredCondition allows you to do things like New Symbol and Paste with a
     // symbol selected (in other words, when we know the library context even if the library
     // itself isn't selected.
@@ -199,7 +200,7 @@ int FOOTPRINT_EDITOR_CONTROL::CreateFootprint( const TOOL_EVENT& aEvent )
     auto* wizard = (FOOTPRINT_WIZARD_FRAME*) m_frame->Kiway().Player( FRAME_FOOTPRINT_WIZARD,
                                                                       true, m_frame );
 
-    if( wizard->ShowModal( NULL, m_frame ) )
+    if( wizard->ShowModal( nullptr, m_frame ) )
     {
         // Creates the new footprint from python script wizard
         FOOTPRINT* newFootprint = wizard->GetBuiltFootprint();
@@ -517,10 +518,7 @@ int FOOTPRINT_EDITOR_CONTROL::RepairFootprint( const TOOL_EVENT& aEvent )
     int        errors = 0;
     wxString   details;
 
-    /*******************************
-     * Repair duplicate IDs and missing nets
-     */
-
+    // Repair duplicate IDs and missing nets.
     std::set<KIID> ids;
     int            duplicates = 0;
 
@@ -615,8 +613,12 @@ void FOOTPRINT_EDITOR_CONTROL::setTransitions()
 
     Go( &FOOTPRINT_EDITOR_CONTROL::PinLibrary,           ACTIONS::pinLibrary.MakeEvent() );
     Go( &FOOTPRINT_EDITOR_CONTROL::UnpinLibrary,         ACTIONS::unpinLibrary.MakeEvent() );
-    Go( &FOOTPRINT_EDITOR_CONTROL::ToggleFootprintTree,  PCB_ACTIONS::showFootprintTree.MakeEvent() );
-    Go( &FOOTPRINT_EDITOR_CONTROL::ToggleFootprintTree,  PCB_ACTIONS::hideFootprintTree.MakeEvent() );
-    Go( &FOOTPRINT_EDITOR_CONTROL::Properties,           PCB_ACTIONS::footprintProperties.MakeEvent() );
-    Go( &FOOTPRINT_EDITOR_CONTROL::DefaultPadProperties, PCB_ACTIONS::defaultPadProperties.MakeEvent() );
+    Go( &FOOTPRINT_EDITOR_CONTROL::ToggleFootprintTree,
+        PCB_ACTIONS::showFootprintTree.MakeEvent() );
+    Go( &FOOTPRINT_EDITOR_CONTROL::ToggleFootprintTree,
+        PCB_ACTIONS::hideFootprintTree.MakeEvent() );
+    Go( &FOOTPRINT_EDITOR_CONTROL::Properties,
+        PCB_ACTIONS::footprintProperties.MakeEvent() );
+    Go( &FOOTPRINT_EDITOR_CONTROL::DefaultPadProperties,
+        PCB_ACTIONS::defaultPadProperties.MakeEvent() );
 }
diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp
index acb8892b00..4579e8b785 100644
--- a/pcbnew/tools/pcb_control.cpp
+++ b/pcbnew/tools/pcb_control.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2014-2016 CERN
- * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
  * This program is free software; you can redistribute it and/or
@@ -263,10 +263,9 @@ int PCB_CONTROL::HighContrastModeCycle( const TOOL_EVENT& aEvent )
 }
 
 
-// Layer control
 int PCB_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
 {
-    m_frame->SwitchLayer( NULL, aEvent.Parameter<PCB_LAYER_ID>() );
+    m_frame->SwitchLayer( nullptr, aEvent.Parameter<PCB_LAYER_ID>() );
 
     return 0;
 }
@@ -292,7 +291,7 @@ int PCB_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
     }
 
     wxCHECK( IsCopperLayer( layer ), 0 );
-    editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
+    editFrame->SwitchLayer( nullptr, ToLAYER_ID( layer ) );
 
     return 0;
 }
@@ -320,7 +319,7 @@ int PCB_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
 
 
     wxCHECK( IsCopperLayer( layer ), 0 );
-    editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
+    editFrame->SwitchLayer( nullptr, ToLAYER_ID( layer ) );
 
     return 0;
 }
@@ -332,9 +331,9 @@ int PCB_CONTROL::LayerToggle( const TOOL_EVENT& aEvent )
     PCB_SCREEN* screen = m_frame->GetScreen();
 
     if( currentLayer == screen->m_Route_Layer_TOP )
-        m_frame->SwitchLayer( NULL, screen->m_Route_Layer_BOTTOM );
+        m_frame->SwitchLayer( nullptr, screen->m_Route_Layer_BOTTOM );
     else
-        m_frame->SwitchLayer( NULL, screen->m_Route_Layer_TOP );
+        m_frame->SwitchLayer( nullptr, screen->m_Route_Layer_TOP );
 
     return 0;
 }
@@ -346,6 +345,7 @@ int PCB_CONTROL::LayerToggle( const TOOL_EVENT& aEvent )
 #define ALPHA_MAX 1.00
 #define ALPHA_STEP 0.05
 
+
 int PCB_CONTROL::LayerAlphaInc( const TOOL_EVENT& aEvent )
 {
     auto settings = m_frame->GetColorSettings();
@@ -398,13 +398,14 @@ int PCB_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent )
         static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
     }
     else
+    {
         wxBell();
+    }
 
     return 0;
 }
 
 
-// Grid control
 void PCB_CONTROL::DoSetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
                                    EDA_ITEM* originViewItem, const VECTOR2D& aPoint )
 {
@@ -516,9 +517,11 @@ int PCB_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
             collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
 
             if( m_isFootprintEditor )
-                collector.Collect( board, GENERAL_COLLECTOR::FootprintItems, (wxPoint) aPos, guide );
+                collector.Collect( board, GENERAL_COLLECTOR::FootprintItems,
+                                   (wxPoint) aPos, guide );
             else
-                collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, (wxPoint) aPos, guide );
+                collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems,
+                                   (wxPoint) aPos, guide );
 
             // Remove unselectable items
             for( int i = collector.GetCount() - 1; i >= 0; --i )
@@ -865,7 +868,7 @@ int PCB_CONTROL::placeBoardItems( BOARD* aBoard, bool aAnchorAtOrigin, bool aRea
     // PCB_SELECTION_TOOL::highlightInternal runs, which does a SetSelected() on all
     // descendants. In PCB_CONTROL::placeBoardItems, below, we skip that and
     // mark items non-recursively.  That works because the saving of the
-    // selection created aBoard that has the group and all descendents in it.
+    // selection created aBoard that has the group and all descendants in it.
     moveUnflaggedItems( aBoard->Groups(), items, isNew );
 
     return placeBoardItems( items, isNew, aAnchorAtOrigin, aReannotateDuplicates );
@@ -901,7 +904,7 @@ int PCB_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
         case PCB_DIM_CENTER_T:
         case PCB_DIM_ORTHOGONAL_T:
         case PCB_DIM_LEADER_T:
-            {
+        {
             // Dimensions need to have their units updated if they are automatic
             PCB_DIMENSION_BASE* dim = static_cast<PCB_DIMENSION_BASE*>( item );
 
@@ -909,7 +912,7 @@ int PCB_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
                 dim->SetUnits( frame()->GetUserUnits() );
 
             break;
-            }
+        }
 
         case PCB_FOOTPRINT_T:
             // Update the footprint path with the new KIID path if the footprint is new
diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp
index 71cf8db640..b16dd51527 100644
--- a/pcbnew/tools/pcb_grid_helper.cpp
+++ b/pcbnew/tools/pcb_grid_helper.cpp
@@ -157,7 +157,7 @@ VECTOR2I PCB_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos,
     ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, LSET::AllLayersMask() );
     ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, LSET::AllLayersMask() );
     ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, LSET::AllLayersMask() );
-    ANCHOR* best = NULL;
+    ANCHOR* best = nullptr;
     double minDist = std::numeric_limits<double>::max();
 
     if( nearestOrigin )
@@ -703,7 +703,7 @@ PCB_GRID_HELPER::ANCHOR* PCB_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, i
                                                          LSET aMatchLayers )
 {
     double  minDist = std::numeric_limits<double>::max();
-    ANCHOR* best = NULL;
+    ANCHOR* best = nullptr;
 
     for( ANCHOR& a : m_anchors )
     {
diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp
index bbbcddb59a..6c8f3371c2 100644
--- a/pcbnew/tools/pcb_point_editor.cpp
+++ b/pcbnew/tools/pcb_point_editor.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2021 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
  * This program is free software; you can redistribute it and/or
@@ -46,32 +47,38 @@ using namespace std::placeholders;
 #include <connectivity/connectivity_data.h>
 #include <widgets/progress_reporter.h>
 
+
 // Few constants to avoid using bare numbers for point indices
 enum SEG_POINTS
 {
     SEG_START, SEG_END
 };
 
+
 enum RECT_POINTS
 {
     RECT_TOP_LEFT, RECT_TOP_RIGHT, RECT_BOT_RIGHT, RECT_BOT_LEFT
 };
 
+
 enum RECT_LINES
 {
     RECT_TOP, RECT_RIGHT, RECT_BOT, RECT_LEFT
 };
 
+
 enum ARC_POINTS
 {
     ARC_CENTER, ARC_START, ARC_MID, ARC_END
 };
 
+
 enum CIRCLE_POINTS
 {
     CIRC_CENTER, CIRC_END
 };
 
+
 enum BEZIER_CURVE_POINTS
 {
     BEZIER_CURVE_START,
@@ -80,6 +87,7 @@ enum BEZIER_CURVE_POINTS
     BEZIER_CURVE_END
 };
 
+
 enum DIMENSION_POINTS
 {
     DIM_START,
@@ -89,6 +97,7 @@ enum DIMENSION_POINTS
     DIM_CROSSBAREND,
 };
 
+
 PCB_POINT_EDITOR::PCB_POINT_EDITOR() :
     PCB_TOOL_BASE( "pcbnew.PointEditor" ),
     m_selectionTool( nullptr ),
@@ -502,9 +511,9 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
                 }
 
                 m_editedPoint->SetPosition( pos );
-            }
                 break;
             }
+            }
 
             // The alternative constraint limits to 45 degrees
             bool enableAltConstraint = !!evt->Modifier( MD_SHIFT );
@@ -546,7 +555,6 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
 
             m_refill = true;
         }
-
         else if( evt->IsCancelInteractive() || evt->IsActivate() )
         {
             if( inDrag )      // Restore the last change
@@ -562,7 +570,6 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
             if( evt->IsActivate() && !evt->IsMoveTool() )
                 break;
         }
-
         else if( evt->Action() == TA_UNDO_REDO_POST )
         {
             break;
@@ -668,30 +675,30 @@ void PCB_POINT_EDITOR::editArcEndpointKeepTangent( PCB_SHAPE* aArc, VECTOR2I aCe
     double R               = v1.EuclideanNorm();
     bool   transformCircle = false;
 
-    /*                    p2
-        *                     X***
-        *                         **  <---- This is the arc
-        *            y ^            **
-        *              |      R       *
-        *              | <-----------> *
-        *       x------x------>--------x p1
-        *     C' <----> C      x
-        *         delta
-        *
-        * p1 does not move, and the tangent at p1 remains the same.
-        *  => The new center, C', will be on the C-p1 axis.
-        * p2 moves
-        *
-        * The radius of the new circle is delta + R
-        *
-        * || C' p2 || = || C' P1 ||
-        * is the same as :
-        * ( delta + p2.x ) ^ 2 + p2.y ^ 2 = ( R + delta ) ^ 2
-        *
-        * delta = ( R^2  - p2.x ^ 2 - p2.y ^2 ) / ( 2 * p2.x - 2 * R )
-        *
-        * We can use this equation for any point p2 with p2.x < R
-        */
+    /*                 p2
+     *                     X***
+     *                         **  <---- This is the arc
+     *            y ^            **
+     *              |      R       *
+     *              | <-----------> *
+     *       x------x------>--------x p1
+     *     C' <----> C      x
+     *         delta
+     *
+     * p1 does not move, and the tangent at p1 remains the same.
+     *  => The new center, C', will be on the C-p1 axis.
+     * p2 moves
+     *
+     * The radius of the new circle is delta + R
+     *
+     * || C' p2 || = || C' P1 ||
+     * is the same as :
+     * ( delta + p2.x ) ^ 2 + p2.y ^ 2 = ( R + delta ) ^ 2
+     *
+     * delta = ( R^2  - p2.x ^ 2 - p2.y ^2 ) / ( 2 * p2.x - 2 * R )
+     *
+     * We can use this equation for any point p2 with p2.x < R
+     */
 
     if( v2.x == R )
     {
@@ -706,6 +713,7 @@ void PCB_POINT_EDITOR::editArcEndpointKeepTangent( PCB_SHAPE* aArc, VECTOR2I aCe
             transformCircle = true;
             v2.x            = 2 * R - v2.x;
         }
+
         // We can keep the tangent constraint.
         double delta = ( R * R - v2.x * v2.x - v2.y * v2.y ) / ( 2 * v2.x - 2 * R );
 
@@ -714,11 +722,13 @@ void PCB_POINT_EDITOR::editArcEndpointKeepTangent( PCB_SHAPE* aArc, VECTOR2I aCe
         {
             arcValid = false;
         }
+
         // Never recorded a problem, but still checking.
         if( !std::isfinite( delta ) )
         {
             arcValid = false;
         }
+
         // v4 is the new center
         v4 = ( !transformCircle ) ? VECTOR2D( -delta, 0 ) : VECTOR2D( 2 * R + delta, 0 );
 
@@ -904,8 +914,10 @@ void PCB_POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCen
     else
     {
         double tan = target.y / static_cast<double>( target.x );
+
         // The divider is always greater than 1 ( cannot be 0 )
         double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
+
         // Move to the correct quadrant
         tmp   = target.x > 0 ? tmp : -tmp;
         p2->y = target.y / static_cast<double>( target.x ) * tmp;
@@ -941,7 +953,7 @@ void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
                                              const VECTOR2I aCursor ) const
 {
     // Now, update the edit point position
-    // Express the point in a cercle-centered coordinate system.
+    // Express the point in a circle-centered coordinate system.
     aStart = aStart - aCenter;
     aEnd   = aEnd - aCenter;
 
@@ -961,6 +973,7 @@ void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
 
         double tan = aStart.y / static_cast<double>( aStart.x );
         double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
+
         // Move to the correct quadrant
         tmp      = aStart.x > 0 ? tmp : -tmp;
         aStart.y = aStart.y / static_cast<double>( aStart.x ) * tmp;
@@ -981,6 +994,7 @@ void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
 
         double tan = aEnd.y / static_cast<double>( aEnd.x );
         double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
+
         // Move to the correct quadrant
         tmp    = aEnd.x > 0 ? tmp : -tmp;
         aEnd.y = aEnd.y / static_cast<double>( aEnd.x ) * tmp;
@@ -1076,7 +1090,8 @@ void PCB_POINT_EDITOR::updateItem() const
             for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
             {
                 if( !isModified( m_editPoints->Line( i ) ) )
-                    m_editPoints->Line( i ).SetConstraint( new EC_PERPLINE( m_editPoints->Line( i ) ) );
+                    m_editPoints->Line( i ).SetConstraint(
+                            new EC_PERPLINE( m_editPoints->Line( i ) ) );
             }
         }
             break;
@@ -1142,7 +1157,8 @@ void PCB_POINT_EDITOR::updateItem() const
             for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
             {
                 if( !isModified( m_editPoints->Line( i ) ) )
-                    m_editPoints->Line( i ).SetConstraint( new EC_PERPLINE( m_editPoints->Line( i ) ) );
+                    m_editPoints->Line( i ).SetConstraint(
+                            new EC_PERPLINE( m_editPoints->Line( i ) ) );
             }
 
             validatePolygon( outline );
@@ -1151,11 +1167,14 @@ void PCB_POINT_EDITOR::updateItem() const
 
         case PCB_SHAPE_TYPE::CURVE:
             if( isModified( m_editPoints->Point( BEZIER_CURVE_START ) ) )
-                shape->SetStart( (wxPoint) m_editPoints->Point( BEZIER_CURVE_START ).GetPosition() );
+                shape->SetStart( (wxPoint) m_editPoints->Point( BEZIER_CURVE_START ).
+                                 GetPosition() );
             else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ) ) )
-                shape->SetBezierC1((wxPoint) m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition());
+                shape->SetBezierC1( (wxPoint) m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).
+                                    GetPosition() );
             else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ) ) )
-                shape->SetBezierC2((wxPoint) m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition());
+                shape->SetBezierC2( (wxPoint) m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).
+                                    GetPosition() );
             else if( isModified( m_editPoints->Point( BEZIER_CURVE_END ) ) )
                 shape->SetEnd( (wxPoint) m_editPoints->Point( BEZIER_CURVE_END ).GetPosition() );
 
@@ -1282,8 +1301,9 @@ void PCB_POINT_EDITOR::updateItem() const
         default:        // suppress warnings
             break;
         }
-    }
+
         break;
+    }
 
     case PCB_FP_ZONE_T:
     case PCB_ZONE_T:
@@ -1346,20 +1366,24 @@ void PCB_POINT_EDITOR::updateItem() const
             dimension->SetStart( (wxPoint) m_editedPoint->GetPosition() );
             dimension->Update();
 
-            m_editPoints->Point( DIM_CROSSBARSTART ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
-                                                                                 m_editPoints->Point( DIM_START ) ) );
-            m_editPoints->Point( DIM_CROSSBAREND ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
-                                                                             m_editPoints->Point( DIM_END ) ) );
+            m_editPoints->Point( DIM_CROSSBARSTART ).
+                    SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
+                                                m_editPoints->Point( DIM_START ) ) );
+            m_editPoints->Point( DIM_CROSSBAREND ).
+                    SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
+                                                m_editPoints->Point( DIM_END ) ) );
         }
         else if( isModified( m_editPoints->Point( DIM_END ) ) )
         {
             dimension->SetEnd( (wxPoint) m_editedPoint->GetPosition() );
             dimension->Update();
 
-            m_editPoints->Point( DIM_CROSSBARSTART ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
-                                                                             m_editPoints->Point( DIM_START ) ) );
-            m_editPoints->Point( DIM_CROSSBAREND ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
-                                                                             m_editPoints->Point( DIM_END ) ) );
+            m_editPoints->Point( DIM_CROSSBARSTART ).
+                    SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
+                                                m_editPoints->Point( DIM_START ) ) );
+            m_editPoints->Point( DIM_CROSSBAREND ).
+                    SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
+                                                m_editPoints->Point( DIM_END ) ) );
         }
         else if( isModified( m_editPoints->Point(DIM_TEXT ) ) )
         {
@@ -1666,8 +1690,9 @@ void PCB_POINT_EDITOR::updatePoints()
                 m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( wxPoint( shapePos.x - halfSize.x,
                                                                            shapePos.y + halfSize.y ) );
             }
-        }
+
             break;
+        }
 
         default:        // suppress warnings
             break;
@@ -1949,14 +1974,15 @@ bool PCB_POINT_EDITOR::removeCornerCondition( const SELECTION& )
     // degenerating the polygon.
     // The first condition allows one to remove all corners from holes (when
     // there are only 2 vertices left, a hole is removed).
-    if( vertexIdx.m_contour == 0 && polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
+    if( vertexIdx.m_contour == 0 &&
+        polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
         return false;
 
     // Remove corner does not work with lines
     if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
         return false;
 
-    return m_editedPoint != NULL;
+    return m_editedPoint != nullptr;
 }
 
 
@@ -2047,7 +2073,6 @@ int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
 
         commit.Push( _( "Add a zone corner" ) );
     }
-
     else if( graphicItem && graphicItem->GetShape() == PCB_SHAPE_TYPE::SEGMENT )
     {
         commit.Modify( graphicItem );
diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp
index ffefa820de..53594846a0 100644
--- a/pcbnew/tools/pcb_selection_tool.cpp
+++ b/pcbnew/tools/pcb_selection_tool.cpp
@@ -102,7 +102,7 @@ public:
 
 PCB_SELECTION_TOOL::PCB_SELECTION_TOOL() :
         PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
-        m_frame( NULL ),
+        m_frame( nullptr ),
         m_additive( false ),
         m_subtractive( false ),
         m_exclusive_or( false ),
@@ -484,7 +484,7 @@ void PCB_SELECTION_TOOL::EnterGroup()
                  "EnterGroup called when selection is not a single group" );
     PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
 
-    if( m_enteredGroup != NULL )
+    if( m_enteredGroup != nullptr )
         ExitGroup();
 
     ClearSelection();
@@ -780,7 +780,7 @@ bool PCB_SELECTION_TOOL::selectCursor( bool aForceSelect, CLIENT_SELECTION_FILTE
     if( aForceSelect || m_selection.Empty() )
     {
         ClearSelection( true /*quiet mode*/ );
-        selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
+        selectPoint( getViewControls()->GetCursorPosition( false ), false, nullptr, aClientFilter );
     }
 
     return !m_selection.Empty();
@@ -1145,22 +1145,22 @@ void PCB_SELECTION_TOOL::selectConnectedTracks( BOARD_CONNECTED_ITEM& aStartItem
             PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
             trackMap[ track->GetStart() ].push_back( track );
             trackMap[ track->GetEnd() ].push_back( track );
-        }
             break;
+        }
 
         case PCB_VIA_T:
         {
             PCB_VIA* via = static_cast<PCB_VIA*>( item );
             viaMap[ via->GetStart() ] = via;
-        }
             break;
+        }
 
         case PCB_PAD_T:
         {
             PAD* pad = static_cast<PAD*>( item );
             padMap[ pad->GetPosition() ] = pad;
-        }
             break;
+        }
 
         default:
             break;
@@ -1248,8 +1248,10 @@ void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect )
     auto connectivity = board()->GetConnectivity();
 
     for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
+    {
         if( itemPassesFilter( item ) )
             aSelect ? select( item ) : unselect( item );
+    }
 }
 
 
@@ -1307,7 +1309,7 @@ void PCB_SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetPath )
             footprintList.push_back( footprint );
     }
 
-    //Generate a list of all pads, and of all nets they belong to.
+    // Generate a list of all pads, and of all nets they belong to.
     std::list<int>  netcodeList;
     std::list<PAD*> padList;
 
@@ -1322,6 +1324,7 @@ void PCB_SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetPath )
             }
         }
     }
+
     // remove all duplicates
     netcodeList.sort();
     netcodeList.unique();
@@ -1371,13 +1374,13 @@ void PCB_SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetPath )
 
     for( BOARD_ITEM* i : footprintList )
     {
-        if( i != NULL )
+        if( i != nullptr )
             select( i );
     }
 
     for( BOARD_CONNECTED_ITEM* i : localConnectionList )
     {
-        if( i != NULL )
+        if( i != nullptr )
             select( i );
     }
 }
@@ -1385,7 +1388,7 @@ void PCB_SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetPath )
 
 void PCB_SELECTION_TOOL::zoomFitSelection()
 {
-    //Should recalculate the view to zoom in on the selection
+    // Should recalculate the view to zoom in on the selection.
     auto selectionBox = m_selection.GetBoundingBox();
     auto view = getView();
 
@@ -1428,8 +1431,7 @@ int PCB_SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
     if( !selectCursor( true ) )
         return 0;
 
-    // this function currently only supports footprints since they are only
-    // on one sheet.
+    // this function currently only supports footprints since they are only on one sheet.
     auto item = m_selection.Front();
 
     if( !item )
@@ -1662,8 +1664,9 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem )
         {
             return false;
         }
-    }
+
         break;
+    }
 
     case PCB_FP_SHAPE_T:
     case PCB_SHAPE_T:
@@ -1834,7 +1837,9 @@ bool PCB_SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector )
                         unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
                 }
                 else if( current )
+                {
                     unhighlight( current, BRIGHTENED, &highlightGroup );
+                }
 
                 int id = *evt->GetCommandId();
 
@@ -1845,7 +1850,9 @@ bool PCB_SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector )
                     highlight( current, BRIGHTENED, &highlightGroup );
                 }
                 else
+                {
                     current = nullptr;
+                }
 
                 // User has pointed on the "Select All" option
                 if( id == limit + 1 )
@@ -1855,7 +1862,9 @@ bool PCB_SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector )
                     selectAll = true;
                 }
                 else
+                {
                     selectAll = false;
+                }
             }
             else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
             {
@@ -1865,7 +1874,9 @@ bool PCB_SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector )
                         unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
                 }
                 else if( current )
+                {
                     unhighlight( current, BRIGHTENED, &highlightGroup );
+                }
 
                 OPT<int> id = evt->GetCommandId();
 
@@ -1903,7 +1914,9 @@ bool PCB_SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector )
     getView()->Remove( &highlightGroup );
 
     if( selectAll )
+    {
         return true;
+    }
     else if( current )
     {
         aCollector->Empty();
@@ -2209,8 +2222,7 @@ void PCB_SELECTION_TOOL::unhighlight( BOARD_ITEM* aItem, int aMode, PCB_SELECTIO
     unhighlightInternal( aItem, aMode, aGroup != nullptr );
     view()->Update( aItem, KIGFX::REPAINT );
 
-    // Many selections are very temporal and updating the display each time just
-    // creates noise.
+    // Many selections are very temporal and updating the display each time just creates noise.
     if( aMode == BRIGHTENED )
         getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY );
 }
@@ -2285,15 +2297,15 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte
     {
         PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
         text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
-    }
         break;
+    }
 
     case PCB_FP_TEXT_T:
     {
         FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
         text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
-    }
         break;
+    }
 
     case PCB_ZONE_T:
     {
@@ -2306,8 +2318,9 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte
             distance = aMaxDistance / 2;
         else
             aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
-    }
+
         break;
+    }
 
     case PCB_FOOTPRINT_T:
     {
@@ -2319,8 +2332,9 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte
         // Consider footprints larger than the viewport only as a last resort
         if( bbox.GetHeight() > viewport.GetHeight() || bbox.GetWidth() > viewport.GetWidth() )
             distance = INT_MAX / 2;
-    }
+
         break;
+    }
 
     case PCB_MARKER_T:
     {
@@ -2330,8 +2344,8 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte
         marker->ShapeToPolygon( polygon );
         polygon.Move( marker->GetPos() );
         polygon.Collide( loc, aMaxDistance, &distance );
-    }
         break;
+    }
 
     case PCB_GROUP_T:
     {
@@ -2339,8 +2353,9 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte
 
         for( BOARD_ITEM* member : group->GetItems() )
             distance = std::min( distance, hitTestDistance( aWhere, member, aMaxDistance ) );
-    }
+
         break;
+    }
 
     default:
         aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
@@ -2643,7 +2658,8 @@ void PCB_SELECTION_TOOL::setTransitions()
     Go( &PCB_SELECTION_TOOL::selectNet,           PCB_ACTIONS::selectNet.MakeEvent() );
     Go( &PCB_SELECTION_TOOL::selectNet,           PCB_ACTIONS::deselectNet.MakeEvent() );
     Go( &PCB_SELECTION_TOOL::selectSameSheet,     PCB_ACTIONS::selectSameSheet.MakeEvent() );
-    Go( &PCB_SELECTION_TOOL::selectSheetContents, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
+    Go( &PCB_SELECTION_TOOL::selectSheetContents,
+        PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
     Go( &PCB_SELECTION_TOOL::updateSelection,     EVENTS::SelectedItemsModified );
     Go( &PCB_SELECTION_TOOL::updateSelection,     EVENTS::SelectedItemsMoved );
 
diff --git a/pcbnew/tools/pcb_selection_tool.h b/pcbnew/tools/pcb_selection_tool.h
index d327cc95c2..2c133578ff 100644
--- a/pcbnew/tools/pcb_selection_tool.h
+++ b/pcbnew/tools/pcb_selection_tool.h
@@ -220,8 +220,8 @@ private:
      * @return True if an item was selected, false otherwise.
      */
     bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
-                      bool* aSelectionCancelledFlag = NULL,
-                      CLIENT_SELECTION_FILTER aClientFilter = NULL );
+                      bool* aSelectionCancelledFlag = nullptr,
+                      CLIENT_SELECTION_FILTER aClientFilter = nullptr );
 
     /**
      * Select an item under the cursor unless there is something already selected or
@@ -232,7 +232,7 @@ private:
      * @return true if eventually there is an item selected, false otherwise.
      */
     bool selectCursor( bool aForceSelect = false,
-                       CLIENT_SELECTION_FILTER aClientFilter = NULL );
+                       CLIENT_SELECTION_FILTER aClientFilter = nullptr );
 
     /**
      * Handle drawing a selection box that allows one to select many items at the same time.
diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp
index 0664f1248e..9b798dbc01 100644
--- a/pcbnew/tools/placement_tool.cpp
+++ b/pcbnew/tools/placement_tool.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2014-2016 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
  * This program is free software; you can redistribute it and/or
@@ -39,8 +40,10 @@
 
 
 ALIGN_DISTRIBUTE_TOOL::ALIGN_DISTRIBUTE_TOOL() :
-    TOOL_INTERACTIVE( "pcbnew.Placement" ), m_selectionTool( NULL ), m_placementMenu( NULL ),
-    m_frame( NULL )
+    TOOL_INTERACTIVE( "pcbnew.Placement" ),
+    m_selectionTool( nullptr ),
+    m_placementMenu( nullptr ),
+    m_frame( nullptr )
 {
 }
 
@@ -751,6 +754,8 @@ void ALIGN_DISTRIBUTE_TOOL::setTransitions()
     Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterX,           PCB_ACTIONS::alignCenterX.MakeEvent() );
     Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterY,           PCB_ACTIONS::alignCenterY.MakeEvent() );
 
-    Go( &ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally, PCB_ACTIONS::distributeHorizontally.MakeEvent() );
-    Go( &ALIGN_DISTRIBUTE_TOOL::DistributeVertically,   PCB_ACTIONS::distributeVertically.MakeEvent() );
+    Go( &ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally,
+        PCB_ACTIONS::distributeHorizontally.MakeEvent() );
+    Go( &ALIGN_DISTRIBUTE_TOOL::DistributeVertically,
+        PCB_ACTIONS::distributeVertically.MakeEvent() );
 }
diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp
index 8a696c6792..41580f5911 100644
--- a/pcbnew/tools/position_relative_tool.cpp
+++ b/pcbnew/tools/position_relative_tool.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,9 +41,9 @@ using namespace std::placeholders;
 
 POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() :
     PCB_TOOL_BASE( "pcbnew.PositionRelative" ),
-    m_dialog( NULL ),
-    m_selectionTool( NULL ),
-    m_anchor_item( NULL )
+    m_dialog( nullptr ),
+    m_selectionTool( nullptr ),
+    m_anchor_item( nullptr )
 {
 }
 
@@ -235,5 +235,5 @@ void POSITION_RELATIVE_TOOL::setTransitions()
 {
     Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() );
     Go( &POSITION_RELATIVE_TOOL::SelectPositionRelativeItem,
-            PCB_ACTIONS::selectpositionRelativeItem.MakeEvent() );
+        PCB_ACTIONS::selectpositionRelativeItem.MakeEvent() );
 }
diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp
index d7c8ae040b..0f7f26792d 100644
--- a/pcbnew/undo_redo.cpp
+++ b/pcbnew/undo_redo.cpp
@@ -4,8 +4,8 @@
  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  * Copyright (C) 2016 CERN
+ * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Maciej Suminski <maciej.suminski@cern.ch>
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -98,19 +98,18 @@ using namespace std::placeholders;
 
 
 /**
- * Function TestForExistingItem
  * Test if aItem exists somewhere in undo/redo lists of items.  Used by PutDataInPreviousState
  * to be sure an item was not deleted since an undo or redo.
+ *
  * This could be possible:
  *   - if a call to SaveCopyInUndoList was forgotten in Pcbnew
  *   - in zones outlines, when a change in one zone merges this zone with an other
  * Before using this function to test existence of items, it must be called with aItem = NULL to
- * prepare the list
- * @param aPcb = board to test
- * @param aItem = item to find
- *              = NULL to build the list of existing items
+ * prepare the list.
+ *
+ * @param aPcb is the board to test.
+ * @param aItem is the item to find or NULL to build the list of existing items.
  */
-
 static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
 {
     for( PCB_TRACK* item : aPcb->Tracks() )
@@ -157,7 +156,7 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
 
 static void SwapItemData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
 {
-    if( aImage == NULL )
+    if( aImage == nullptr )
         return;
 
     wxASSERT( aItem->Type() == aImage->Type() );
@@ -274,11 +273,12 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis
              * in the picker, as link
              * If this link is not null, the copy is already done
              */
-            if( commandToUndo->GetPickedItemLink( ii ) == NULL )
+            if( commandToUndo->GetPickedItemLink( ii ) == nullptr )
             {
                 EDA_ITEM* cloned = item->Clone();
                 commandToUndo->SetPickedItemLink( cloned, ii );
             }
+
             break;
 
         case UNDO_REDO::NEWITEM:
@@ -289,12 +289,9 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis
             break;
 
         default:
-        {
             wxFAIL_MSG( wxString::Format( "SaveCopyInUndoList() error (unknown code %X)",
-                   command ) );
-        }
-        break;
-
+                                          command ) );
+            break;
         }
     }
 
@@ -468,8 +465,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
             view->Hide( item, false );
             connectivity->Add( item );
             item->GetBoard()->OnItemChanged( item );
+            break;
         }
-        break;
 
         case UNDO_REDO::NEWITEM:        /* new items are deleted */
             aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii );
@@ -517,8 +514,9 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
                 BOARD_EDITOR_CONTROL::DoSetDrillOrigin( view, this, item, origin );
             else
                 PCB_CONTROL::DoSetGridOrigin( view, this, item, origin );
+
+            break;
         }
-        break;
 
         case UNDO_REDO::PAGESETTINGS:
         {
@@ -527,12 +525,12 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
             DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
             item->Restore( this );
             *item = alt_item;
+            break;
         }
-        break;
 
         default:
             wxFAIL_MSG( wxString::Format( "PutDataInPreviousState() error (unknown code %X)",
-                    aList->GetPickedItemStatus( ii ) ) );
+                                          aList->GetPickedItemStatus( ii ) ) );
             break;
         }
     }
diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp
index 3a1918bf4b..27b270c8bf 100644
--- a/pcbnew/zone.cpp
+++ b/pcbnew/zone.cpp
@@ -668,8 +668,6 @@ void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>&
 }
 
 
-/* Geometric transforms: */
-
 void ZONE::Move( const wxPoint& offset )
 {
     /* move outlines */
@@ -775,7 +773,7 @@ void ZONE::Mirror( const wxPoint& aMirrorRef, bool aMirrorLeftRight )
 
 ZONE_CONNECTION ZONE::GetPadConnection( PAD* aPad, wxString* aSource ) const
 {
-    if( aPad == NULL || aPad->GetEffectiveZoneConnection() == ZONE_CONNECTION::INHERITED )
+    if( aPad == nullptr || aPad->GetEffectiveZoneConnection() == ZONE_CONNECTION::INHERITED )
     {
         if( aSource )
             *aSource = _( "zone" );
@@ -1014,27 +1012,25 @@ void ZONE::HatchBorder()
         // Iterate through all vertices
         for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
         {
-            double  x, y;
-            bool    ok;
+            double x, y;
+            bool   ok;
 
             SEG segment = *iterator;
 
-            ok = FindLineSegmentIntersection( a, slope,
-                                              segment.A.x, segment.A.y,
-                                              segment.B.x, segment.B.y,
-                                              x, y );
+            ok = FindLineSegmentIntersection( a, slope, segment.A.x, segment.A.y, segment.B.x,
+                                              segment.B.y, x, y );
 
-              if( ok )
-              {
-                  VECTOR2I point( KiROUND( x ), KiROUND( y ) );
-                  pointbuffer.push_back( point );
-              }
+            if( ok )
+            {
+                VECTOR2I point( KiROUND( x ), KiROUND( y ) );
+                pointbuffer.push_back( point );
+            }
 
-              if( pointbuffer.size() >= MAXPTS )    // overflow
-              {
-                  wxASSERT( 0 );
-                  break;
-              }
+            if( pointbuffer.size() >= MAXPTS ) // overflow
+            {
+                wxASSERT( 0 );
+                break;
+            }
         }
 
         // ensure we have found an even intersection points count
@@ -1318,9 +1314,6 @@ bool ZONE::KeepoutAll() const
 }
 
 
-//
-/********* FP_ZONE **************/
-//
 FP_ZONE::FP_ZONE( BOARD_ITEM_CONTAINER* aParent ) :
         ZONE( aParent, true )
 {