From d6fca11419e0dff44e7c2fef2c7189b8f1c1efd6 Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Mon, 24 Oct 2022 22:21:50 +0100
Subject: [PATCH] Finish up work on PlaceFile settings persistence.

We were missing several flags, and using the Plot output directory
instead of saving our own.

Fixes https://gitlab.com/kicad/code/kicad/issues/12715

Fixes https://gitlab.com/kicad/code/kicad/issues/12714
---
 pcbnew/exporters/gen_footprints_placefile.cpp | 28 ++++++++-----------
 pcbnew/pcbnew_settings.cpp                    | 11 +++++++-
 pcbnew/pcbnew_settings.h                      | 17 +++++------
 3 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/pcbnew/exporters/gen_footprints_placefile.cpp b/pcbnew/exporters/gen_footprints_placefile.cpp
index 78602a7317..48f5c37184 100644
--- a/pcbnew/exporters/gen_footprints_placefile.cpp
+++ b/pcbnew/exporters/gen_footprints_placefile.cpp
@@ -54,8 +54,7 @@ class DIALOG_GEN_FOOTPRINT_POSITION : public DIALOG_GEN_FOOTPRINT_POSITION_BASE
 public:
     DIALOG_GEN_FOOTPRINT_POSITION( PCB_EDIT_FRAME * aParent ):
         DIALOG_GEN_FOOTPRINT_POSITION_BASE( aParent ),
-        m_parent( aParent ),
-        m_plotOpts( aParent->GetPlotSettings() )
+        m_parent( aParent )
     {
         m_messagesPanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
         m_reporter = &m_messagesPanel->Reporter();
@@ -160,7 +159,6 @@ private:
 
 private:
     PCB_EDIT_FRAME* m_parent;
-    PCB_PLOT_PARAMS m_plotOpts;
     REPORTER*       m_reporter;
 };
 
@@ -175,7 +173,7 @@ void DIALOG_GEN_FOOTPRINT_POSITION::initDialog()
     m_units = cfg->m_PlaceFile.units == 0 ? EDA_UNITS::INCHES : EDA_UNITS::MILLIMETRES;
 
     // Output directory
-    m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
+    m_outputDirectoryName->SetValue( cfg->m_PlaceFile.output_directory );
 
     // Update Options
     m_radioBoxUnits->SetSelection( cfg->m_PlaceFile.units );
@@ -224,9 +222,16 @@ void DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked( wxCommandEve
 
 void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
 {
-    PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings();
     m_units  = m_radioBoxUnits->GetSelection() == 0 ? EDA_UNITS::INCHES : EDA_UNITS::MILLIMETRES;
 
+    PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings();
+
+    wxString dirStr = m_outputDirectoryName->GetValue();
+    // Keep unix directory format convention in cfg files
+    dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
+
+    cfg->m_PlaceFile.output_directory   = dirStr;
+
     cfg->m_PlaceFile.units              = m_units == EDA_UNITS::INCHES ? 0 : 1;
     cfg->m_PlaceFile.file_options       = m_radioBoxFilesCount->GetSelection();
     cfg->m_PlaceFile.file_format        = m_rbFormat->GetSelection();
@@ -236,15 +241,6 @@ void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
     cfg->m_PlaceFile.use_aux_origin     = m_useDrillPlaceOrigin->GetValue();
     cfg->m_PlaceFile.negate_xcoord      = m_negateXcb->GetValue();
 
-    // Set output directory and replace backslashes with forward ones
-    // (Keep unix convention in cfg files)
-    wxString dirStr;
-    dirStr = m_outputDirectoryName->GetValue();
-    dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
-
-    m_plotOpts.SetOutputDirectory( dirStr );
-    m_parent->SetPlotSettings( m_plotOpts );
-
     if( m_rbFormat->GetSelection() == 2 )
         CreateGerberFiles();
     else
@@ -269,7 +265,7 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles()
                 return m_parent->GetBoard()->ResolveTextVar( token, 0 );
             };
 
-    wxString path = m_plotOpts.GetOutputDirectory();
+    wxString path = m_parent->GetPcbNewSettings()->m_PlaceFile.output_directory;
     path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
     path = ExpandEnvVarSubstitutions( path, nullptr );
 
@@ -377,7 +373,7 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
                 return m_parent->GetBoard()->ResolveTextVar( token, 0 );
             };
 
-    wxString path = m_plotOpts.GetOutputDirectory();
+    wxString path = m_parent->GetPcbNewSettings()->m_PlaceFile.output_directory;
     path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
     path = ExpandEnvVarSubstitutions( path, nullptr );
 
diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp
index 0b2f9f4da1..d887f51cf2 100644
--- a/pcbnew/pcbnew_settings.cpp
+++ b/pcbnew/pcbnew_settings.cpp
@@ -407,7 +407,10 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
     m_params.emplace_back( new PARAM<bool>( "netlist.associate_by_ref_sch",
             &m_NetlistDialog.associate_by_ref_sch, false ) );
 
-    m_params.emplace_back(new PARAM<int>( "place_file.units",
+    m_params.emplace_back( new PARAM<wxString>( "place_file.output_directory",
+            &m_PlaceFile.output_directory, wxEmptyString ) );
+
+    m_params.emplace_back( new PARAM<int>( "place_file.units",
             &m_PlaceFile.units, 1 ) );
 
     m_params.emplace_back( new PARAM<int>( "place_file.file_options",
@@ -416,6 +419,12 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
     m_params.emplace_back( new PARAM<int>( "place_file.file_format",
             &m_PlaceFile.file_format, 0 ) );
 
+    m_params.emplace_back( new PARAM<bool>( "place_file.excludeTH",
+            &m_PlaceFile.exclude_TH, false ) );
+
+    m_params.emplace_back( new PARAM<bool>( "place_file.onlySMD",
+            &m_PlaceFile.only_SMD, false ) );
+
     m_params.emplace_back( new PARAM<bool>( "place_file.include_board_edge",
             &m_PlaceFile.include_board_edge, false ) );
 
diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h
index c19001e93c..b041396862 100644
--- a/pcbnew/pcbnew_settings.h
+++ b/pcbnew/pcbnew_settings.h
@@ -232,14 +232,15 @@ public:
 
     struct DIALOG_PLACE_FILE
     {
-        int  units;
-        int  file_options;
-        int  file_format;
-        bool include_board_edge;
-        bool exclude_TH;
-        bool only_SMD;
-        bool use_aux_origin;
-        bool negate_xcoord;
+        wxString output_directory;
+        int      units;
+        int      file_options;
+        int      file_format;
+        bool     include_board_edge;
+        bool     exclude_TH;
+        bool     only_SMD;
+        bool     use_aux_origin;
+        bool     negate_xcoord;
     };
 
     struct DIALOG_PLOT