From 3d6d8b9946b2ee7bfde5ef7a0b2f8dc44f72ed5d Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@gmail.com>
Date: Fri, 4 Oct 2024 15:20:03 +0100
Subject: [PATCH] Strip richio.h from headers that don't need them

Like the DSNLEXER header, this has visibility in over 700
files, whereas well under half actually use any of it
(quite a bit, but not all, of it actually via DSNLEXER)

Many places already forward-declare the OUTPUTFORMATTER type,
by doing that for the others, it still possible to use the
non-IO methods without having to see richio.h.
---
 common/xnode.cpp                               |  5 ++++-
 eeschema/cross-probing.cpp                     |  1 +
 eeschema/dialogs/panel_template_fieldnames.cpp |  4 +++-
 .../netlist_exporter_kicad.cpp                 |  5 +++--
 .../netlist_exporter_spice.cpp                 |  3 ++-
 .../netlist_exporter_spice_model.cpp           |  3 +++
 .../netlist_exporters/netlist_generator.cpp    |  1 +
 eeschema/sch_io/ltspice/ltspice_schematic.cpp  |  5 ++++-
 eeschema/sim/ngspice.cpp                       |  1 +
 eeschema/sim/sim_model.cpp                     |  6 +++++-
 eeschema/sim/sim_model_ngspice.cpp             |  3 ++-
 eeschema/sim/sim_model_serializer.cpp          |  4 +++-
 eeschema/sim/sim_model_spice.cpp               |  1 +
 eeschema/sim/sim_model_spice_fallback.cpp      |  4 +++-
 eeschema/sim/sim_model_subckt.cpp              |  5 +++--
 eeschema/sim/spice_circuit_model.cpp           |  6 ++++--
 eeschema/sim/spice_library_parser.cpp          | 11 +++++++----
 eeschema/sim/spice_model_parser.cpp            |  2 ++
 eeschema/tools/simulator_control.cpp           |  5 ++++-
 eeschema/tools/symbol_editor_edit_tool.cpp     |  4 +++-
 eeschema/tools/symbol_editor_edit_tool.h       |  7 +++----
 eeschema/widgets/tuner_slider.cpp              |  1 +
 include/embedded_files.h                       |  3 ++-
 include/template_fieldnames.h                  |  3 ++-
 include/xnode.h                                |  3 +--
 pcbnew/board_stackup_manager/board_stackup.cpp |  1 +
 .../panel_board_stackup.cpp                    |  1 +
 pcbnew/cross-probing.cpp                       |  1 +
 pcbnew/dialogs/dialog_board_reannotate.cpp     |  4 +++-
 pcbnew/exporters/export_gencad_writer.cpp      |  1 +
 pcbnew/exporters/export_hyperlynx.cpp          |  1 +
 pcbnew/exporters/gen_drill_report_files.cpp    |  1 +
 pcbnew/exporters/gendrill_file_writer_base.cpp |  1 +
 pcbnew/netlist_reader/netlist_reader.cpp       | 11 +++++++++++
 pcbnew/netlist_reader/netlist_reader.h         | 12 +++---------
 pcbnew/netlist_reader/pcb_netlist.cpp          |  4 +++-
 pcbnew/pcb_io/pcad/pcad_via.cpp                |  1 +
 pcbnew/tools/board_editor_control.cpp          |  6 ++++--
 qa/schematic_utils/eeschema_test_utils.cpp     | 18 ++++++++++++++++++
 qa/schematic_utils/eeschema_test_utils.h       | 12 ++----------
 qa/tests/eeschema/test_eagle_plugin.cpp        |  2 +-
 qa/tests/eeschema/test_sch_netclass.cpp        |  1 +
 qa/tests/eeschema/test_sch_sheet_list.cpp      |  1 +
 43 files changed, 123 insertions(+), 52 deletions(-)

diff --git a/common/xnode.cpp b/common/xnode.cpp
index 62b6477c45..4b75a2f09e 100644
--- a/common/xnode.cpp
+++ b/common/xnode.cpp
@@ -23,9 +23,12 @@
  */
 
 
-#include <xnode.h>
+#include "xnode.h"
+
+#include <richio.h>
 #include <string_utils.h>
 
+
 typedef wxXmlAttribute   XATTR;
 
 
diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp
index 3b71d5ffe7..c68d28c588 100644
--- a/eeschema/cross-probing.cpp
+++ b/eeschema/cross-probing.cpp
@@ -34,6 +34,7 @@
 #include <netlist_exporters/netlist_exporter_kicad.h>
 #include <project/project_file.h>
 #include <project/net_settings.h>
+#include <richio.h>
 #include <tools/ee_actions.h>
 #include <tools/sch_editor_control.h>
 #include <advanced_config.h>
diff --git a/eeschema/dialogs/panel_template_fieldnames.cpp b/eeschema/dialogs/panel_template_fieldnames.cpp
index bdcb490efc..0717aab873 100644
--- a/eeschema/dialogs/panel_template_fieldnames.cpp
+++ b/eeschema/dialogs/panel_template_fieldnames.cpp
@@ -22,6 +22,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "panel_template_fieldnames.h"
+
 #include <wx/msgdlg.h>
 
 #include <pgm_base.h>
@@ -31,8 +33,8 @@
 #include <template_fieldnames.h>
 #include <grid_tricks.h>
 #include <bitmaps.h>
+#include <richio.h>
 #include <string_utils.h>
-#include <panel_template_fieldnames.h>
 
 PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES( wxWindow* aWindow,
                                                       TEMPLATES* aProjectTemplateMgr ) :
diff --git a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp
index 99dc041e00..85cf7d363b 100644
--- a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp
+++ b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp
@@ -23,13 +23,14 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "netlist_exporter_kicad.h"
 
 #include <algorithm>
 #include <confirm.h>
 
-#include <xnode.h>
 #include <connection_graph.h>
-#include "netlist_exporter_kicad.h"
+#include <richio.h>
+#include <xnode.h>
 
 
 bool NETLIST_EXPORTER_KICAD::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp
index dffa1b1cab..b6dd752abc 100644
--- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp
+++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp
@@ -32,6 +32,7 @@
 #include <confirm.h>
 #include <pgm_base.h>
 #include <env_paths.h>
+#include <richio.h>
 #include <sim/sim_library_ibis.h>
 #include <sim/sim_xspice_parser.h>
 #include <sch_screen.h>
@@ -488,7 +489,7 @@ void NETLIST_EXPORTER_SPICE::getNodePattern( SPICE_ITEM&               aItem,
                                              std::vector<std::string>& aModifiers )
 {
     std::string input = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_NODES_FORMAT_FIELD, true );
-    
+
     if( input == "" )
         return;
 
diff --git a/eeschema/netlist_exporters/netlist_exporter_spice_model.cpp b/eeschema/netlist_exporters/netlist_exporter_spice_model.cpp
index 49bad7dbd5..8d9f71f264 100644
--- a/eeschema/netlist_exporters/netlist_exporter_spice_model.cpp
+++ b/eeschema/netlist_exporters/netlist_exporter_spice_model.cpp
@@ -23,8 +23,11 @@
  */
 
 #include "netlist_exporter_spice_model.h"
+
 #include <sch_screen.h>
 #include <string_utils.h>
+#include <project.h>
+#include <richio.h>
 
 
 void NETLIST_EXPORTER_SPICE_MODEL::WriteHead( OUTPUTFORMATTER& aFormatter,
diff --git a/eeschema/netlist_exporters/netlist_generator.cpp b/eeschema/netlist_exporters/netlist_generator.cpp
index 0b769f32e6..3595ba7525 100644
--- a/eeschema/netlist_exporters/netlist_generator.cpp
+++ b/eeschema/netlist_exporters/netlist_generator.cpp
@@ -33,6 +33,7 @@
 #include <confirm.h>
 #include <kiway.h>
 #include <erc/erc.h>
+#include <richio.h>
 
 #include <netlist.h>
 #include <netlist_exporter_base.h>
diff --git a/eeschema/sch_io/ltspice/ltspice_schematic.cpp b/eeschema/sch_io/ltspice/ltspice_schematic.cpp
index 1375e0fac6..239d2d2f33 100644
--- a/eeschema/sch_io/ltspice/ltspice_schematic.cpp
+++ b/eeschema/sch_io/ltspice/ltspice_schematic.cpp
@@ -23,7 +23,8 @@
  * @brief Loads the asc file and asy files.
  */
 
-#include <sch_io/ltspice/ltspice_schematic.h>
+#include "sch_io/ltspice/ltspice_schematic.h"
+
 #include <sch_io/ltspice/sch_io_ltspice_parser.h>
 #include <sch_screen.h>
 #include <wx/log.h>
@@ -31,6 +32,8 @@
 #include <wildcards_and_files_ext.h>
 #include <sch_sheet.h>
 #include <schematic.h>
+#include <project.h>
+#include <richio.h>
 
 
 void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp
index 3399c9b1d8..f1d9fd6364 100644
--- a/eeschema/sim/ngspice.cpp
+++ b/eeschema/sim/ngspice.cpp
@@ -30,6 +30,7 @@
 #include <locale_io.h>
 #include <fmt/core.h>
 #include <paths.h>
+#include <richio.h>
 
 #include "spice_circuit_model.h"
 #include "ngspice.h"
diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp
index 24e9b08473..3a76be1c8b 100644
--- a/eeschema/sim/sim_model.cpp
+++ b/eeschema/sim/sim_model.cpp
@@ -22,11 +22,15 @@
  * or you may write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
+
+#include <ki_exception.h>
 #include <lib_symbol.h>
 #include <sch_symbol.h>
 #include <string_utils.h>
 #include <wx/regex.h>
 
+#include <iterator>
+
 #include <sim/sim_model.h>
 #include <sim/sim_model_behavioral.h>
 #include <sim/sim_model_ideal.h>
@@ -47,7 +51,7 @@
 #include <fmt/core.h>
 #include <pegtl/contrib/parse_tree.hpp>
 
-#include <iterator>
+
 #include "sim_model_spice_fallback.h"
 
 using TYPE = SIM_MODEL::TYPE;
diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp
index 8a7b1eb4a1..667671a07a 100644
--- a/eeschema/sim/sim_model_ngspice.cpp
+++ b/eeschema/sim/sim_model_ngspice.cpp
@@ -22,10 +22,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <sim/sim_model_ngspice.h>
+#include "sim/sim_model_ngspice.h"
 
 #include <boost/algorithm/string.hpp>
 #include <fmt/core.h>
+#include <ki_exception.h>
 
 
 std::vector<std::string> SPICE_GENERATOR_NGSPICE::CurrentNames( const SPICE_ITEM& aItem ) const
diff --git a/eeschema/sim/sim_model_serializer.cpp b/eeschema/sim/sim_model_serializer.cpp
index 1eb921248b..fbcde41dea 100644
--- a/eeschema/sim/sim_model_serializer.cpp
+++ b/eeschema/sim/sim_model_serializer.cpp
@@ -22,7 +22,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <sim/sim_model_serializer.h>
+#include "sim/sim_model_serializer.h"
+
+#include <ki_exception.h>
 #include <fmt/core.h>
 #include <pegtl.hpp>
 #include <pegtl/contrib/parse_tree.hpp>
diff --git a/eeschema/sim/sim_model_spice.cpp b/eeschema/sim/sim_model_spice.cpp
index db270f353c..45cf9315a9 100644
--- a/eeschema/sim/sim_model_spice.cpp
+++ b/eeschema/sim/sim_model_spice.cpp
@@ -29,6 +29,7 @@
 #include <sim/sim_library_spice.h>
 
 #include <boost/algorithm/string/trim.hpp>
+#include <ki_exception.h>
 
 
 std::string SPICE_GENERATOR_SPICE::Preview( const SPICE_ITEM& aItem ) const
diff --git a/eeschema/sim/sim_model_spice_fallback.cpp b/eeschema/sim/sim_model_spice_fallback.cpp
index 0eb05cb40a..ec047adc16 100644
--- a/eeschema/sim/sim_model_spice_fallback.cpp
+++ b/eeschema/sim/sim_model_spice_fallback.cpp
@@ -21,7 +21,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <sim/sim_model_spice_fallback.h>
+#include "sim/sim_model_spice_fallback.h"
+
+#include <ki_exception.h>
 #include <fmt/format.h>
 
 
diff --git a/eeschema/sim/sim_model_subckt.cpp b/eeschema/sim/sim_model_subckt.cpp
index 144af38522..e0687edb6a 100644
--- a/eeschema/sim/sim_model_subckt.cpp
+++ b/eeschema/sim/sim_model_subckt.cpp
@@ -22,12 +22,13 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <sim/sim_model_subckt.h>
-#include <sim/spice_grammar.h>
+#include "sim/sim_model_subckt.h"
 
+#include <ki_exception.h>
 #include <fmt/core.h>
 #include <pegtl.hpp>
 #include <pegtl/contrib/parse_tree.hpp>
+#include <sim/spice_grammar.h>
 
 
 namespace SIM_MODEL_SUBCKT_SPICE_PARSER
diff --git a/eeschema/sim/spice_circuit_model.cpp b/eeschema/sim/spice_circuit_model.cpp
index 46e21d74e3..7687f32d00 100644
--- a/eeschema/sim/spice_circuit_model.cpp
+++ b/eeschema/sim/spice_circuit_model.cpp
@@ -24,11 +24,13 @@
  */
 
 #include "spice_circuit_model.h"
-#include <string_utils.h>
+
 #include <wx/regex.h>
 #include <wx/tokenzr.h>
-#include <locale_io.h>
 
+#include <locale_io.h>
+#include <richio.h>
+#include <string_utils.h>
 
 SIM_TRACE_TYPE SPICE_CIRCUIT_MODEL::VectorToSignal( const std::string& aVector,
                                                     wxString& aSignal ) const
diff --git a/eeschema/sim/spice_library_parser.cpp b/eeschema/sim/spice_library_parser.cpp
index e271d92713..a2b9cabd69 100644
--- a/eeschema/sim/spice_library_parser.cpp
+++ b/eeschema/sim/spice_library_parser.cpp
@@ -22,16 +22,19 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <sim/spice_library_parser.h>
+#include "sim/spice_library_parser.h"
+
+#include <utility>
+
+#include <core/thread_pool.h>
+#include <ki_exception.h>
 #include <sim/sim_library_spice.h>
 #include <sim/spice_grammar.h>
 #include <sim/sim_model_spice.h>
-#include <ki_exception.h>
+#include <richio.h>
 
 #include <pegtl.hpp>
 #include <pegtl/contrib/parse_tree.hpp>
-#include <utility>
-#include <core/thread_pool.h>
 
 
 namespace SIM_LIBRARY_SPICE_PARSER
diff --git a/eeschema/sim/spice_model_parser.cpp b/eeschema/sim/spice_model_parser.cpp
index 7960d8af34..10baaca94c 100644
--- a/eeschema/sim/spice_model_parser.cpp
+++ b/eeschema/sim/spice_model_parser.cpp
@@ -23,6 +23,8 @@
  */
 
 #include <wx/log.h>
+
+#include <ki_exception.h>
 #include <sim/spice_model_parser.h>
 #include <sim/spice_grammar.h>
 #include <sim/sim_model_spice.h>
diff --git a/eeschema/tools/simulator_control.cpp b/eeschema/tools/simulator_control.cpp
index 70776a22e4..51624b26e6 100644
--- a/eeschema/tools/simulator_control.cpp
+++ b/eeschema/tools/simulator_control.cpp
@@ -20,6 +20,9 @@
  * or you may write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
+
+#include "tools/simulator_control.h"
+
 #define wxUSE_BASE64 1
 #include <wx/base64.h>
 
@@ -38,13 +41,13 @@
 #include <sim/sim_plot_tab.h>
 #include <tool/tool_manager.h>
 #include <tools/ee_actions.h>
-#include <tools/simulator_control.h>
 #include <scintilla_tricks.h>
 #include <sim/spice_circuit_model.h>
 #include <dialogs/dialog_user_defined_signals.h>
 #include <wx/clipbrd.h>
 #include <wx/dataobj.h>
 #include <wx/mstream.h>
+#include <richio.h>
 #include <string_utils.h>
 
 
diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp
index c2d4a19bf4..3ad2f694c1 100644
--- a/eeschema/tools/symbol_editor_edit_tool.cpp
+++ b/eeschema/tools/symbol_editor_edit_tool.cpp
@@ -22,6 +22,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "symbol_editor_edit_tool.h"
+
 #include <tool/picker_tool.h>
 #include <tools/ee_selection_tool.h>
 #include <tools/symbol_editor_pin_tool.h>
@@ -38,9 +40,9 @@
 #include <dialogs/dialog_lib_edit_pin_table.h>
 #include <dialogs/dialog_update_symbol_fields.h>
 #include <view/view_controls.h>
+#include <richio.h>
 #include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>
 #include <sch_textbox.h>
-#include "symbol_editor_edit_tool.h"
 #include <wx/textdlg.h>     // for wxTextEntryDialog
 #include <math/util.h>      // for KiROUND
 
diff --git a/eeschema/tools/symbol_editor_edit_tool.h b/eeschema/tools/symbol_editor_edit_tool.h
index d741d5152a..8915995061 100644
--- a/eeschema/tools/symbol_editor_edit_tool.h
+++ b/eeschema/tools/symbol_editor_edit_tool.h
@@ -22,12 +22,13 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#ifndef SYMBOL_EDITOR_EDIT_TOOL_H
-#define SYMBOL_EDITOR_EDIT_TOOL_H
+#pragma once
 
 #include <tools/ee_tool_base.h>
 
 
+class SCH_PIN;
+class SCH_SHAPE;
 class SYMBOL_EDIT_FRAME;
 
 
@@ -77,5 +78,3 @@ private:
 
     EDA_ITEM* m_pickerItem;
 };
-
-#endif // SYMBOL_EDITOR_EDIT_TOOL_H
diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp
index 8f81585136..343b7050c1 100644
--- a/eeschema/widgets/tuner_slider.cpp
+++ b/eeschema/widgets/tuner_slider.cpp
@@ -25,6 +25,7 @@
  */
 
 
+#include <ki_exception.h>
 #include <sim/simulator_frame_ui.h>
 #include <sim/simulator_frame.h>
 #include <sch_symbol.h>
diff --git a/include/embedded_files.h b/include/embedded_files.h
index 2906a49660..90d4fabc43 100644
--- a/include/embedded_files.h
+++ b/include/embedded_files.h
@@ -26,9 +26,10 @@
 
 #include <mmh3_hash.h>
 #include <picosha2.h>
-#include <richio.h>
 #include <wildcards_and_files_ext.h>
 
+class OUTPUTFORMATTER;
+
 class EMBEDDED_FILES
 {
 public:
diff --git a/include/template_fieldnames.h b/include/template_fieldnames.h
index d25e3fd4a1..b14570537d 100644
--- a/include/template_fieldnames.h
+++ b/include/template_fieldnames.h
@@ -24,8 +24,9 @@
 
 #pragma once
 
-#include <richio.h>
+#include <wx/string.h>
 
+class OUTPUTFORMATTER;
 class TEMPLATE_FIELDNAMES_LEXER;
 
 
diff --git a/include/xnode.h b/include/xnode.h
index 22d073f204..5793ce0869 100644
--- a/include/xnode.h
+++ b/include/xnode.h
@@ -25,8 +25,6 @@
 #ifndef XNODE_H_
 #define XNODE_H_
 
-#include <richio.h>
-
 // quiet the deprecated warnings with 3 lines:
 #include <wx/defs.h>
 #undef wxDEPRECATED
@@ -34,6 +32,7 @@
 
 #include <wx/xml/xml.h>
 
+class OUTPUTFORMATTER;
 
 /**
  * Hold an XML or S-expression element.
diff --git a/pcbnew/board_stackup_manager/board_stackup.cpp b/pcbnew/board_stackup_manager/board_stackup.cpp
index e3aa4071bf..4f8c1ce0ec 100644
--- a/pcbnew/board_stackup_manager/board_stackup.cpp
+++ b/pcbnew/board_stackup_manager/board_stackup.cpp
@@ -27,6 +27,7 @@
 #include <board.h>
 #include <i18n_utility.h>       // For _HKI definition
 #include "stackup_predefined_prms.h"
+#include <richio.h>
 #include <google/protobuf/any.pb.h>
 #include <api/board/board.pb.h>
 #include <api/api_enums.h>
diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp
index ddabbbc5e2..fbc0e84217 100644
--- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp
+++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp
@@ -48,6 +48,7 @@
 
 #include <locale_io.h>
 #include <eda_list_dialog.h>
+#include <richio.h>
 #include <string_utils.h>               // for UIDouble2Str()
 
 
diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp
index 6595100fde..f604f56019 100644
--- a/pcbnew/cross-probing.cpp
+++ b/pcbnew/cross-probing.cpp
@@ -49,6 +49,7 @@
 #include <pcb_edit_frame.h>
 #include <pcbnew_settings.h>
 #include <render_settings.h>
+#include <richio.h>
 #include <tool/tool_manager.h>
 #include <tools/pcb_actions.h>
 #include <tools/pcb_selection_tool.h>
diff --git a/pcbnew/dialogs/dialog_board_reannotate.cpp b/pcbnew/dialogs/dialog_board_reannotate.cpp
index 62eb64cf46..432e0b4dd9 100644
--- a/pcbnew/dialogs/dialog_board_reannotate.cpp
+++ b/pcbnew/dialogs/dialog_board_reannotate.cpp
@@ -23,18 +23,20 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "dialog_board_reannotate.h"
+
 #include <algorithm>
 #include <base_units.h>
 #include <bitmaps.h>
 #include <board_commit.h>
 #include <confirm.h>
 #include <ctype.h>
-#include <dialog_board_reannotate.h>
 #include <gal/graphics_abstraction_layer.h>
 #include <string_utils.h>  // StrNumCmp
 #include <kiface_base.h>
 #include <pcbnew_settings.h>
 #include <refdes_utils.h>
+#include <richio.h>
 #include <tool/grid_menu.h>
 #include <widgets/wx_html_report_panel.h>
 #include <wx/valtext.h>
diff --git a/pcbnew/exporters/export_gencad_writer.cpp b/pcbnew/exporters/export_gencad_writer.cpp
index ca4c6a5b40..93e5ba52b5 100644
--- a/pcbnew/exporters/export_gencad_writer.cpp
+++ b/pcbnew/exporters/export_gencad_writer.cpp
@@ -25,6 +25,7 @@
 #include <footprint.h>
 #include <pad.h>
 #include <pcb_track.h>
+#include <richio.h>
 #include <locale_io.h>
 #include <macros.h>
 #include <hash_eda.h>
diff --git a/pcbnew/exporters/export_hyperlynx.cpp b/pcbnew/exporters/export_hyperlynx.cpp
index f75524dbba..2ba6de3358 100644
--- a/pcbnew/exporters/export_hyperlynx.cpp
+++ b/pcbnew/exporters/export_hyperlynx.cpp
@@ -37,6 +37,7 @@
 #include <ki_exception.h>
 #include <locale_io.h>
 #include <reporter.h>
+#include <richio.h>
 #include <exporters/board_exporter_base.h>
 #include <wx/log.h>
 
diff --git a/pcbnew/exporters/gen_drill_report_files.cpp b/pcbnew/exporters/gen_drill_report_files.cpp
index f1fb0ade6f..ceae694064 100644
--- a/pcbnew/exporters/gen_drill_report_files.cpp
+++ b/pcbnew/exporters/gen_drill_report_files.cpp
@@ -28,6 +28,7 @@
 #include <eda_item.h>
 #include <font/font.h>
 #include <confirm.h>
+#include <richio.h>
 #include <string_utils.h>
 #include <locale_io.h>
 #include <macros.h>
diff --git a/pcbnew/exporters/gendrill_file_writer_base.cpp b/pcbnew/exporters/gendrill_file_writer_base.cpp
index 3a190ce962..d8fca875d6 100644
--- a/pcbnew/exporters/gendrill_file_writer_base.cpp
+++ b/pcbnew/exporters/gendrill_file_writer_base.cpp
@@ -29,6 +29,7 @@
 #include <pcb_track.h>
 #include <collectors.h>
 #include <reporter.h>
+#include <richio.h>
 
 #include <gendrill_file_writer_base.h>
 
diff --git a/pcbnew/netlist_reader/netlist_reader.cpp b/pcbnew/netlist_reader/netlist_reader.cpp
index 97e5565280..2dcf96a4eb 100644
--- a/pcbnew/netlist_reader/netlist_reader.cpp
+++ b/pcbnew/netlist_reader/netlist_reader.cpp
@@ -30,6 +30,7 @@
 
 #include <string_utils.h>
 #include <reporter.h>
+#include <richio.h>
 
 #include "pcb_netlist.h"
 #include "netlist_reader.h"
@@ -112,6 +113,16 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST*        aNetlist,
 }
 
 
+CMP_READER::~CMP_READER()
+{
+    if( m_lineReader )
+    {
+        delete m_lineReader;
+        m_lineReader = nullptr;
+    }
+}
+
+
 bool CMP_READER::Load( NETLIST* aNetlist )
 {
     wxCHECK_MSG( aNetlist != nullptr, true, wxT( "No netlist passed to CMP_READER::Load()" ) );
diff --git a/pcbnew/netlist_reader/netlist_reader.h b/pcbnew/netlist_reader/netlist_reader.h
index 9c5e842927..24aafc1ea5 100644
--- a/pcbnew/netlist_reader/netlist_reader.h
+++ b/pcbnew/netlist_reader/netlist_reader.h
@@ -31,8 +31,9 @@
 #include <lib_id.h>
 
 
-class NETLIST;
 class COMPONENT;
+class NETLIST;
+class LINE_READER;
 
 
 /**
@@ -51,14 +52,7 @@ public:
         m_lineReader = aLineReader;
     }
 
-    ~CMP_READER()
-    {
-        if( m_lineReader )
-        {
-            delete m_lineReader;
-            m_lineReader = nullptr;
-        }
-    }
+    ~CMP_READER();
 
     /**
      * Read the *.cmp file format contains the component footprint assignments created by CvPcb
diff --git a/pcbnew/netlist_reader/pcb_netlist.cpp b/pcbnew/netlist_reader/pcb_netlist.cpp
index f3d84e3659..e261166a8d 100644
--- a/pcbnew/netlist_reader/pcb_netlist.cpp
+++ b/pcbnew/netlist_reader/pcb_netlist.cpp
@@ -24,9 +24,11 @@
  */
 
 
-#include <string_utils.h>
 #include "pcb_netlist.h"
+
 #include <footprint.h>
+#include <richio.h>
+#include <string_utils.h>
 
 
 int COMPONENT_NET::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
diff --git a/pcbnew/pcb_io/pcad/pcad_via.cpp b/pcbnew/pcb_io/pcad/pcad_via.cpp
index 165788dde0..1637cca67c 100644
--- a/pcbnew/pcb_io/pcad/pcad_via.cpp
+++ b/pcbnew/pcb_io/pcad/pcad_via.cpp
@@ -26,6 +26,7 @@
 #include <pcad/pcad_via.h>
 #include <pcad/pcad_via_shape.h>
 
+#include <richio.h>
 #include <xnode.h>
 
 #include <wx/string.h>
diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp
index 3d0e9b4b78..99fcbc53e5 100644
--- a/pcbnew/tools/board_editor_control.cpp
+++ b/pcbnew/tools/board_editor_control.cpp
@@ -23,12 +23,13 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "board_editor_control.h"
+
 #include <functional>
 #include <memory>
 
 #include <pgm_base.h>
 #include <advanced_config.h>
-#include "board_editor_control.h"
 #include <bitmaps.h>
 #include <pcb_painter.h>
 #include <board.h>
@@ -64,6 +65,7 @@
 #include <tools/edit_tool.h>
 #include <tools/tool_event_utils.h>
 #include <tools/zone_filler_tool.h>
+#include <richio.h>
 #include <router/router_tool.h>
 #include <view/view_controls.h>
 #include <view/view_group.h>
@@ -430,7 +432,7 @@ int BOARD_EDITOR_CONTROL::ExportSpecctraDSN( const TOOL_EVENT& aEvent )
 int BOARD_EDITOR_CONTROL::ExportNetlist( const TOOL_EVENT& aEvent )
 {
     wxCHECK( m_frame, 0 );
-     
+
     wxFileName fn = m_frame->Prj().GetProjectFullName();
 
     // Use a different file extension for the board netlist so the schematic netlist file
diff --git a/qa/schematic_utils/eeschema_test_utils.cpp b/qa/schematic_utils/eeschema_test_utils.cpp
index cc9f7a1dce..80b8c67d76 100644
--- a/qa/schematic_utils/eeschema_test_utils.cpp
+++ b/qa/schematic_utils/eeschema_test_utils.cpp
@@ -22,12 +22,15 @@
  */
 
 #include "eeschema_test_utils.h"
+
 #include <qa_utils/wx_utils/unit_test_utils.h>
+#include <sch_io/sch_io.h>
 #include <wildcards_and_files_ext.h>
 
 #include <cstdlib>
 #include <memory>
 
+#include <eeschema/sch_io/sch_io.h>
 #include <eeschema/sch_io/sch_io_mgr.h>
 #include <eeschema/sch_screen.h>
 #include <eeschema/schematic.h>
@@ -35,6 +38,21 @@
 #include <eeschema/sch_rule_area.h>
 
 
+KI_TEST::SCHEMATIC_TEST_FIXTURE::SCHEMATIC_TEST_FIXTURE() :
+        m_schematic( nullptr ),
+        m_pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ),
+        m_manager( true )
+{
+}
+
+
+KI_TEST::SCHEMATIC_TEST_FIXTURE::~SCHEMATIC_TEST_FIXTURE()
+{
+    m_schematic.Reset();
+    m_pi.reset();
+}
+
+
 void KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic( const wxString& aBaseName )
 {
     wxFileName fn = GetSchematicPath( aBaseName );
diff --git a/qa/schematic_utils/eeschema_test_utils.h b/qa/schematic_utils/eeschema_test_utils.h
index 934feeecd9..bb3dcfd906 100644
--- a/qa/schematic_utils/eeschema_test_utils.h
+++ b/qa/schematic_utils/eeschema_test_utils.h
@@ -49,17 +49,9 @@ namespace KI_TEST
 class SCHEMATIC_TEST_FIXTURE
 {
 public:
-    SCHEMATIC_TEST_FIXTURE()
-        : m_schematic( nullptr ),
-          m_pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ),
-          m_manager( true )
-    { }
+    SCHEMATIC_TEST_FIXTURE();
 
-    virtual ~SCHEMATIC_TEST_FIXTURE()
-    {
-        m_schematic.Reset();
-        m_pi.reset();
-    }
+    ~SCHEMATIC_TEST_FIXTURE();
 
 protected:
     virtual void LoadSchematic( const wxString& aRelativePath );
diff --git a/qa/tests/eeschema/test_eagle_plugin.cpp b/qa/tests/eeschema/test_eagle_plugin.cpp
index 600b5aa8e5..aed1d03a29 100644
--- a/qa/tests/eeschema/test_eagle_plugin.cpp
+++ b/qa/tests/eeschema/test_eagle_plugin.cpp
@@ -26,7 +26,7 @@
 
 #include <core/ignore.h>
 #include <kiway.h>
-#include <sch_io/sch_io_mgr.h>
+#include <sch_io/sch_io.h>
 
 #include "eeschema_test_utils.h"
 
diff --git a/qa/tests/eeschema/test_sch_netclass.cpp b/qa/tests/eeschema/test_sch_netclass.cpp
index fba57c058f..bc3bcb376a 100644
--- a/qa/tests/eeschema/test_sch_netclass.cpp
+++ b/qa/tests/eeschema/test_sch_netclass.cpp
@@ -22,6 +22,7 @@
 
 #include <sch_sheet_path.h>
 #include <sch_label.h>
+#include <sch_io/sch_io.h>
 #include <project/net_settings.h>
 #include <project/project_file.h>
 
diff --git a/qa/tests/eeschema/test_sch_sheet_list.cpp b/qa/tests/eeschema/test_sch_sheet_list.cpp
index c2fed752cf..f81c781723 100644
--- a/qa/tests/eeschema/test_sch_sheet_list.cpp
+++ b/qa/tests/eeschema/test_sch_sheet_list.cpp
@@ -20,6 +20,7 @@
 #include <qa_utils/wx_utils/unit_test_utils.h>
 #include "eeschema_test_utils.h"
 
+#include <sch_io/sch_io.h>
 #include <sch_sheet_path.h>
 #include <wildcards_and_files_ext.h>