From 2d17d2b91fa0f94245e97bd125395a218eb1d81f Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Fri, 12 Jul 2019 00:28:46 +0100
Subject: [PATCH] Cleanup and commenting.

---
 3d-viewer/3d_viewer/eda_3d_viewer.cpp         | 13 ++---------
 cvpcb/tools/cvpcb_selection_tool.h            |  3 ---
 gerbview/tools/gerbview_selection_tool.cpp    |  3 +--
 gerbview/tools/gerbview_selection_tool.h      | 19 ++++-----------
 pagelayout_editor/tools/pl_selection_tool.cpp |  1 -
 pagelayout_editor/tools/pl_selection_tool.h   |  2 --
 pcbnew/tools/pad_tool.cpp                     | 23 +++++++------------
 pcbnew/zone_filler.cpp                        | 13 ++++++++---
 8 files changed, 26 insertions(+), 51 deletions(-)

diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp
index a86c150ef9..b22a0e3843 100644
--- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp
+++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp
@@ -22,11 +22,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-/**
- * @file  eda_3d_viewer.cpp
- * @brief Implements a 3d viewer windows GUI
- */
-
 #include "eda_3d_viewer.h"
 
 #include "../3d_viewer_id.h"
@@ -42,7 +37,6 @@
 #include <tool/common_control.h>
 #include <hotkeys_basic.h>
 #include <wx/colordlg.h>
-#include <wx/colourdata.h>
 #include <wx/toolbar.h>
 
 
@@ -86,11 +80,8 @@ static const wxChar keyBoardBodyColor_Red[]     = wxT( "BoardBodyColor_Red" );
 static const wxChar keyBoardBodyColor_Green[]   = wxT( "BoardBodyColor_Green" );
 static const wxChar keyBoardBodyColor_Blue[]    = wxT( "BoardBodyColor_Blue" );
 
-static const wxChar keyMousewheelPanning[]      = wxT( "MousewheelPAN3D" );
-
 static const wxChar keyShowRealisticMode[]      = wxT( "ShowRealisticMode" );
 static const wxChar keyRenderEngine[]           = wxT( "RenderEngine" );
-//static const wxChar keyRenderTextures[]         = wxT( "Render_Textures" );
 static const wxChar keyRenderMaterial[]         = wxT( "Render_Material" );
 
 static const wxChar keyRenderOGL_ShowCopperTck[]= wxT( "Render_OGL_ShowCopperThickness" );
@@ -220,7 +211,7 @@ EDA_3D_VIEWER::~EDA_3D_VIEWER()
 
     // m_canvas delete will be called by wxWidget manager
     //delete m_canvas;
-    //m_canvas = 0;
+    //m_canvas = nullptr;
 }
 
 
@@ -260,7 +251,7 @@ void EDA_3D_VIEWER::OnCloseWindow( wxCloseEvent &event )
 
     // m_canvas delete will be called by wxWidget manager
     //delete m_canvas;
-    //m_canvas = 0;
+    //m_canvas = nullptr;
 
     Destroy();
     event.Skip( true );
diff --git a/cvpcb/tools/cvpcb_selection_tool.h b/cvpcb/tools/cvpcb_selection_tool.h
index 481d9c5509..55fb9731c8 100644
--- a/cvpcb/tools/cvpcb_selection_tool.h
+++ b/cvpcb/tools/cvpcb_selection_tool.h
@@ -30,8 +30,6 @@
 
 /**
  * Class CVPCB_SELECTION_TOOL
- *
- * Selection tool for GerbView, based on the one in PcbNew
  */
 class CVPCB_SELECTION_TOOL : public TOOL_INTERACTIVE
 {
@@ -65,7 +63,6 @@ public:
     void setTransitions() override;
 
 private:
-    /// Pointer to the parent frame.
     DISPLAY_FOOTPRINTS_FRAME* m_frame;
 
     /// Current state of selection (not really used: no selection in display footprints frame).
diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp
index 6d40c0abc2..4f9fbf1264 100644
--- a/gerbview/tools/gerbview_selection_tool.cpp
+++ b/gerbview/tools/gerbview_selection_tool.cpp
@@ -110,8 +110,7 @@ GERBVIEW_SELECTION_TOOL::GERBVIEW_SELECTION_TOOL() :
         m_frame( NULL ),
         m_additive( false ),
         m_subtractive( false ),
-        m_exclusive_or( false ),
-        m_multiple( false )
+        m_exclusive_or( false )
 {
     m_preliminary = true;
 }
diff --git a/gerbview/tools/gerbview_selection_tool.h b/gerbview/tools/gerbview_selection_tool.h
index 312f22d9ab..96444b6045 100644
--- a/gerbview/tools/gerbview_selection_tool.h
+++ b/gerbview/tools/gerbview_selection_tool.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
- * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2017-2019 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
@@ -73,19 +73,12 @@ public:
      */
     GERBVIEW_SELECTION& GetSelection();
 
-    ///> Clear current selection event handler.
     int ClearSelection( const TOOL_EVENT& aEvent );
 
-    ///> Item selection event handler.
     int SelectItem( const TOOL_EVENT& aEvent );
-
-    ///> Multiple item selection event handler
     int SelectItems( const TOOL_EVENT& aEvent );
 
-    ///> Item unselection event handler.
     int UnselectItem( const TOOL_EVENT& aEvent );
-
-    ///> Multiple item unselection event handler
     int UnselectItems( const TOOL_EVENT& aEvent );
 
     ///> Launches a tool to measure between points
@@ -97,9 +90,8 @@ public:
 private:
     /**
      * Function selectPoint()
-     * Selects an item pointed by the parameter aWhere. If there is more than
-     * one item at that place, there is a menu displayed that allows one to
-     * choose the item.
+     * Selects an item pointed by the parameter aWhere. If there is more than one item at that
+     * place, there is a menu displayed that allows one to choose the item.
      *
      * @param aWhere is the place where the item should be selected.
      * @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then
@@ -110,8 +102,8 @@ private:
 
     /**
      * Function selectCursor()
-     * Selects an item under the cursor unless there is something already selected or aSelectAlways
-     * is true.
+     * Selects an item under the cursor unless there is something already selected or
+     * aSelectAlways is true.
      * @param aSelectAlways forces to select an item even if there is an item already selected.
      * @return true if eventually there is an item selected, false otherwise.
      */
@@ -176,7 +168,6 @@ private:
     bool m_additive;                // Items should be added to selection (instead of replacing)
     bool m_subtractive;             // Items should be removed from selection
     bool m_exclusive_or;            // Items' selection state should be toggled
-    bool m_multiple;                // Multiple selection mode is active
     bool m_preliminary;             // Determines if the selection is preliminary or final.
 };
 
diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp
index 750e851034..2ac6d81798 100644
--- a/pagelayout_editor/tools/pl_selection_tool.cpp
+++ b/pagelayout_editor/tools/pl_selection_tool.cpp
@@ -500,7 +500,6 @@ void PL_SELECTION_TOOL::UnbrightenItem( EDA_ITEM* aItem )
 int PL_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
 {
     ClearSelection();
-
     return 0;
 }
 
diff --git a/pagelayout_editor/tools/pl_selection_tool.h b/pagelayout_editor/tools/pl_selection_tool.h
index 01ef93582b..587594f1bd 100644
--- a/pagelayout_editor/tools/pl_selection_tool.h
+++ b/pagelayout_editor/tools/pl_selection_tool.h
@@ -105,9 +105,7 @@ public:
     void BrightenItem( EDA_ITEM* aItem );
     void UnbrightenItem( EDA_ITEM* aItem );
 
-    ///> Clear current selection event handler.
     int ClearSelection( const TOOL_EVENT& aEvent );
-
     void ClearSelection();
 
     /**
diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp
index 41b7480b8a..23b28d8645 100644
--- a/pcbnew/tools/pad_tool.cpp
+++ b/pcbnew/tools/pad_tool.cpp
@@ -356,9 +356,8 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
     bool isFirstPoint = true;   // used to be sure oldCursorPos will be initialized at least once.
 
     STATUS_TEXT_POPUP statusPopup( frame() );
-    statusPopup.SetText( wxString::Format(
-            _( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ),
-            padPrefix.c_str(), seqPadNum ) );
+    wxString msg = _( "Click on pad %s%d\nPress <esc> to cancel or double-click to commit" );
+    statusPopup.SetText( wxString::Format( msg, padPrefix, seqPadNum ) );
     statusPopup.Popup();
     statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
 
@@ -437,7 +436,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
                     else
                         newval = seqPadNum++;
 
-                    wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), newval );
+                    wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix, newval );
                     oldNames[newName] = { newval, pad->GetName() };
                     pad->SetName( newName );
                     pad->SetSelected();
@@ -449,14 +448,10 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
                     else
                         newval = seqPadNum;
 
-                    statusPopup.SetText( wxString::Format( _( "Click on pad %s%d\n"
-                                                              "Press Escape to cancel or "
-                                                              "double-click to commit" ),
-                                                           padPrefix.c_str(),
-                                                           newval ) );
+                    statusPopup.SetText( wxString::Format( msg, padPrefix, newval ) );
                 }
 
-                    // ..or restore the old name if it was enumerated and clicked again
+                // ... or restore the old name if it was enumerated and clicked again
                 else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
                 {
                     auto it = oldNames.find( pad->GetName() );
@@ -468,11 +463,9 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
                         pad->SetName( it->second.second );
                         oldNames.erase( it );
 
-                        statusPopup.SetText( wxString::Format( _( "Click on pad %s%d\n"
-                                                                  "Press Escape to cancel or "
-                                                                  "double-click to commit" ),
-                                                               padPrefix.c_str(),
-                                                               storedPadNumbers.front() ) );
+                        int newval = storedPadNumbers.front();
+
+                        statusPopup.SetText( wxString::Format( msg, padPrefix, newval ) );
                     }
 
                     pad->ClearSelected();
diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp
index 6b540ed453..e419a03bf3 100644
--- a/pcbnew/zone_filler.cpp
+++ b/pcbnew/zone_filler.cpp
@@ -695,27 +695,34 @@ void ZONE_FILLER::computeRawFilledArea( const ZONE_CONTAINER* aZone,
     if( s_DumpZonesWhenFilling )
         dumper->Write( &solidAreas, "clearance holes" );
 
+    buildThermalSpokes( aZone, thermalSpokes );
+
+    // Create a temporary zone that we can hit-test spoke-ends against.  It's only temporary
+    // because the "real" subtract-clearance-holes has to be done after the spokes are added.
+    static const bool USE_BBOX_CACHES = true;
     SHAPE_POLY_SET testAreas = solidAreas;
     testAreas.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
 
     // Remove areas that don't meet minimum-width criteria
     testAreas.Inflate( -outline_half_thickness, numSegs, true );
     testAreas.Inflate( outline_half_thickness, numSegs, true );
-    testAreas.BuildBBoxCaches();
 
-    static const bool USE_BBOX_CACHES = true;
-    buildThermalSpokes( aZone, thermalSpokes );
+    // Spoke-end-testing is hugely expensive so we generate cached bounding-boxes to speed
+    // things up a bit.
+    testAreas.BuildBBoxCaches();
 
     for( const SHAPE_LINE_CHAIN& spoke : thermalSpokes )
     {
         const VECTOR2I& testPt = spoke.CPoint( 3 );
 
+        // Hit-test against zone body
         if( testAreas.Contains( testPt, -1, false, true, USE_BBOX_CACHES ) )
         {
             solidAreas.AddOutline( spoke );
             continue;
         }
 
+        // Hit-test against other spokes
         for( const SHAPE_LINE_CHAIN& other : thermalSpokes )
         {
             if( &other != &spoke && other.PointInside( testPt, 1, USE_BBOX_CACHES  ) )