From 7583c0e69d5417472f3a2697a369c5e96ca93f0d Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Sat, 8 Feb 2025 23:26:30 +0000
Subject: [PATCH] Retire DIALOG_FOOTPRINT_CHOOSER.

---
 pcbnew/CMakeLists.txt                       |   1 -
 pcbnew/dialogs/dialog_footprint_chooser.cpp | 311 --------------------
 pcbnew/dialogs/dialog_footprint_chooser.h   |  84 ------
 pcbnew/footprint_chooser_frame.cpp          |   2 +
 pcbnew/load_select_footprint.cpp            |  18 +-
 pcbnew/widgets/panel_footprint_chooser.cpp  |   2 -
 6 files changed, 10 insertions(+), 408 deletions(-)
 delete mode 100644 pcbnew/dialogs/dialog_footprint_chooser.cpp
 delete mode 100644 pcbnew/dialogs/dialog_footprint_chooser.h

diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index f18d4a4616..effa09bdcd 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -55,7 +55,6 @@ set( PCBNEW_DIALOGS
     dialogs/dialog_footprint_associations_base.cpp
     dialogs/dialog_footprint_checker.cpp
     dialogs/dialog_footprint_checker_base.cpp
-    dialogs/dialog_footprint_chooser.cpp
     dialogs/dialog_footprint_properties.cpp
     dialogs/dialog_footprint_properties_base.cpp
     dialogs/dialog_footprint_properties_fp_editor.cpp
diff --git a/pcbnew/dialogs/dialog_footprint_chooser.cpp b/pcbnew/dialogs/dialog_footprint_chooser.cpp
deleted file mode 100644
index da7053f340..0000000000
--- a/pcbnew/dialogs/dialog_footprint_chooser.cpp
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * This program source code file is part of KiCad, a free EDA CAD application.
- *
- * Copyright (C) 2023 CERN
- * Copyright The 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 Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, you may find one here:
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- * or you may search the http://www.gnu.org website for the version 2 license,
- * or you may write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- */
-
-#include <dialog_footprint_chooser.h>
-#include <wx/sizer.h>
-#include <wx/button.h>
-#include <pcb_base_frame.h>
-#include <widgets/panel_footprint_chooser.h>
-#include <3d_canvas/eda_3d_canvas.h>
-#include <board.h>
-#include <project_pcb.h>
-#include <board_design_settings.h>
-#include <pgm_base.h>
-#include <settings/common_settings.h>
-#include <settings/settings_manager.h>
-#include <footprint_preview_panel.h>
-#include <widgets/bitmap_button.h>
-
-
-DIALOG_FOOTPRINT_CHOOSER::DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent,
-                                                    const LIB_ID& aPreselect,
-                                                    const wxArrayString& aFootprintHistoryList ) :
-        DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Footprint" ), wxDefaultPosition, wxDefaultSize,
-                     wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
-        m_boardAdapter(),
-        m_currentCamera( m_trackBallCamera ),
-        m_trackBallCamera( 2 * RANGE_SCALE_3D )
-{
-    m_parent = aParent;
-    m_showFpMode = true;
-
-    // This is also the main sizer:
-    wxBoxSizer* m_SizerTop = new wxBoxSizer( wxVERTICAL );
-
-    m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( aParent, this, aFootprintHistoryList,
-            // Filter
-            []( LIB_TREE_NODE& aNode ) -> bool
-            {
-                return true;
-            },
-            // Accept handler
-            [this]()
-            {
-                EndQuasiModal( wxID_OK );
-            },
-            // Escape handler
-            [this]()
-            {
-                EndQuasiModal( wxID_CANCEL );
-            } );
-
-    m_SizerTop->Add( m_chooserPanel, 1, wxEXPAND | wxRIGHT, 5 );
-    FOOTPRINT_PREVIEW_WIDGET* viewerFpPanel = m_chooserPanel->GetViewerPanel();
-
-    viewerFpPanel->Show( m_showFpMode );
-
-    build3DCanvas();
-
-    m_preview3DCanvas->Show( !m_showFpMode );
-
-    // bSizerBottom shows all buttons to the bottom of window
-    wxBoxSizer* bSizerBottom;
-    bSizerBottom = new wxBoxSizer( wxHORIZONTAL );
-
-    bSizerBottom->Add( 0, 0, 1, 0, 5 );     // Add spacer to right-align buttons
-
-    BITMAP_BUTTON* separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
-    separator->SetIsSeparator();
-    bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
-
-	m_grButton3DView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
-    m_grButton3DView->SetIsRadioButton();
-    m_grButton3DView->SetBitmap( KiBitmapBundle( BITMAPS::shape_3d ) );
-    m_grButton3DView->Check( !m_showFpMode );
-	bSizerBottom->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
-
-	m_grButtonFpView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
-    m_grButtonFpView->SetIsRadioButton();
-    m_grButtonFpView->SetBitmap( KiBitmapBundle( BITMAPS::module ) );
-    m_grButtonFpView->Check( m_showFpMode );
-	bSizerBottom->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
-
-    separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
-    separator->SetIsSeparator();
-    bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
-
-    if( aPreselect.IsValid() )
-        m_chooserPanel->SetPreselect( aPreselect );
-
-    SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
-                                             m_chooserPanel->GetItemCount() ) );
-
-    wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
-    wxButton*               okButton = new wxButton( this, wxID_OK );
-    wxButton*               cancelButton = new wxButton( this, wxID_CANCEL );
-    sdbSizer->AddButton( okButton );
-    sdbSizer->AddButton( cancelButton );
-    sdbSizer->Realize();
-
-    bSizerBottom->Add( 20, 0, 0, 0, 5 );     // Add spacer
-    bSizerBottom->Add( sdbSizer, 0, wxEXPAND | wxALL, 5 );
-
-    m_SizerTop->Add( bSizerBottom, 0, wxEXPAND, 5 );
-    SetSizer( m_SizerTop );
-
-    SetInitialFocus( m_chooserPanel->GetFocusTarget() );
-    SetupStandardButtons();
-
-    m_chooserPanel->FinishSetup();
-    // Ensure a reasonable min size that shows all widgets in this dialog
-    SetMinSize( wxSize( 400, 300 ) );
-    Layout();
-
-    // Connect Events
-    m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
-                               wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
-                               nullptr, this );
-    m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
-                               wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
-                               nullptr, this );
-
-    Connect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
-             nullptr, this );
-}
-
-
-DIALOG_FOOTPRINT_CHOOSER::~DIALOG_FOOTPRINT_CHOOSER()
-{
-    if( m_boardAdapter.m_Cfg )
-        m_boardAdapter.m_Cfg->m_Render = m_initialRender;
-
-    // Disconnect Events
-    m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
-                                  wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
-                                  nullptr, this );
-    m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
-                                  wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
-                                  nullptr, this );
-
-    Disconnect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
-                nullptr, this );
-}
-
-
-void DIALOG_FOOTPRINT_CHOOSER::build3DCanvas()
-{
-    // Create the dummy board used by the 3D canvas
-    m_dummyBoard = new BOARD();
-    m_dummyBoard->SetProject( &m_parent->Prj(), true );
-
-    // This board will only be used to hold a footprint for viewing
-    m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
-
-    m_boardAdapter.SetBoard( m_dummyBoard );
-    m_boardAdapter.m_IsBoardView = false;
-    m_boardAdapter.m_IsPreviewer = true;   // Force display 3D models, regardless the 3D viewer options
-
-    // Build the 3D canvas
-
-    m_preview3DCanvas = new EDA_3D_CANVAS( m_chooserPanel->m_RightPanel,
-                                           OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
-                                           m_boardAdapter, m_currentCamera,
-                                           PROJECT_PCB::Get3DCacheManager( &m_parent->Prj() ) );
-
-    COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
-
-    // TODO(JE) use all control options
-    m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
-
-    SETTINGS_MANAGER&       mgr = Pgm().GetSettingsManager();
-    EDA_3D_VIEWER_SETTINGS* cfg = mgr.GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" );
-
-    if( cfg )
-    {
-        // Save the 3D viewer render settings, to restore it after closing the preview
-        m_initialRender = cfg->m_Render;
-
-        m_boardAdapter.m_Cfg = cfg;
-
-        m_preview3DCanvas->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
-        m_preview3DCanvas->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
-        m_preview3DCanvas->SetProjectionMode( cfg->m_Camera.projection_mode );
-
-        // Ensure the board body is always shown, and do not use the settings of the 3D viewer
-        cfg->m_Render.show_copper_top = true;
-        cfg->m_Render.show_copper_bottom = true;
-        cfg->m_Render.show_soldermask_top = true;
-        cfg->m_Render.show_soldermask_bottom = true;
-        cfg->m_Render.show_solderpaste = true;
-        cfg->m_Render.show_zones = true;
-        cfg->m_Render.show_board_body = true;
-        cfg->m_Render.use_board_editor_copper_colors = false;
-    }
-
-    m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
-    m_chooserPanel->m_RightPanel->Layout();
-
-    BOARD_DESIGN_SETTINGS parent_bds = m_parent->GetDesignSettings();
-    BOARD_DESIGN_SETTINGS& dummy_bds = m_dummyBoard->GetDesignSettings();
-    dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
-    dummy_bds.SetEnabledLayers( LSET::FrontMask() | LSET::BackMask() );
-    BOARD_STACKUP& dummy_board_stackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
-    dummy_board_stackup.RemoveAll();
-    dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
-}
-
-
-
-LIB_ID DIALOG_FOOTPRINT_CHOOSER::GetSelectedLibId() const
-{
-    return m_chooserPanel->GetSelectedLibId();
-}
-
-
-void DIALOG_FOOTPRINT_CHOOSER::onFpChanged( wxCommandEvent& event )
-{
-    m_chooserPanel->GetViewerPanel()->Refresh();
-
-    if( m_showFpMode )      // the 3D viewer is not activated
-        return;
-
-    on3DviewReq( event );
-}
-
-
-void DIALOG_FOOTPRINT_CHOOSER::on3DviewReq( wxCommandEvent& event )
-{
-    m_showFpMode = false;
-
-    m_grButtonFpView->Check( m_showFpMode );
-    m_grButton3DView->Check( !m_showFpMode );
-
-    FOOTPRINT_PREVIEW_WIDGET* viewFpPanel = m_chooserPanel->GetViewerPanel();
-    viewFpPanel->Show( m_showFpMode );
-    m_preview3DCanvas->Show( !m_showFpMode );
-    m_dummyBoard->DeleteAllFootprints();
-
-    if( m_chooserPanel->m_CurrFootprint )
-        m_dummyBoard->Add( (FOOTPRINT*)m_chooserPanel->m_CurrFootprint->Clone() );
-
-    m_preview3DCanvas->ReloadRequest();
-    m_preview3DCanvas->Request_refresh();
-    m_chooserPanel->m_RightPanel->Layout();
-    m_chooserPanel->m_RightPanel->Refresh();
-}
-
-
-void DIALOG_FOOTPRINT_CHOOSER::onFpViewReq( wxCommandEvent& event )
-{
-    m_showFpMode = true;
-
-    m_grButtonFpView->Check( m_showFpMode );
-    m_grButton3DView->Check( !m_showFpMode );
-
-    FOOTPRINT_PREVIEW_WIDGET* viewFpPanel = m_chooserPanel->GetViewerPanel();
-    viewFpPanel->Show( m_showFpMode );
-    m_preview3DCanvas->Show( !m_showFpMode );
-    m_chooserPanel->m_RightPanel->Layout();
-    m_chooserPanel->m_RightPanel->Refresh();
-}
-
-
-void DIALOG_FOOTPRINT_CHOOSER::TearDownQuasiModal()
-{
-    wxLogDebug( wxS( "Entering DIALOG_FOOTPRINT_CHOOSER::TearDownQuasiModal()" ) );
-
-    if( m_chooserPanel )
-    {
-        FOOTPRINT_PREVIEW_WIDGET* viewerWidget = m_chooserPanel->GetViewerPanel();
-
-        if( viewerWidget )
-        {
-            FOOTPRINT_PREVIEW_PANEL_BASE* previewPanel = viewerWidget->GetPreviewPanel();
-
-            if( previewPanel )
-            {
-                wxLogDebug( wxS( "Stopping footprint preview panel drawing." ) );
-                previewPanel->GetCanvas()->StopDrawing();
-            }
-        }
-    }
-
-    if( m_preview3DCanvas )
-    {
-        // Work around assertion firing when we try to LockCtx on a hidden 3D canvas during dtor
-        wxCloseEvent dummy;
-        m_preview3DCanvas->Show();
-        m_preview3DCanvas->OnCloseWindow( dummy );
-    }
-}
diff --git a/pcbnew/dialogs/dialog_footprint_chooser.h b/pcbnew/dialogs/dialog_footprint_chooser.h
deleted file mode 100644
index 15f20aa588..0000000000
--- a/pcbnew/dialogs/dialog_footprint_chooser.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * This program source code file is part of KiCad, a free EDA CAD application.
- *
- * Copyright The 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 Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, you may find one here:
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- * or you may search the http://www.gnu.org website for the version 2 license,
- * or you may write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- */
-#ifndef DIALOG_FOOTPRINT_CHOOSER_H
-#define DIALOG_FOOTPRINT_CHOOSER_H
-
-#include <lib_id.h>
-#include "dialog_shim.h"
-#include <3d_canvas/board_adapter.h>
-#include <3d_rendering/track_ball.h>
-
-class PCB_BASE_FRAME;
-class PANEL_FOOTPRINT_CHOOSER;
-class EDA_3D_CANVAS;
-class BOARD;
-class CAMERA;
-class TRACK_BALL;
-class BITMAP_BUTTON;
-
-
-class DIALOG_FOOTPRINT_CHOOSER : public DIALOG_SHIM
-{
-public:
-    DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent, const LIB_ID& aPreselect,
-                              const wxArrayString& aFootprintHistoryList );
-
-    ~DIALOG_FOOTPRINT_CHOOSER();
-
-    /**
-     * To be called after this dialog returns from ShowModal().
-     *
-     * @return the #LIB_ID of the symbol that has been selected.
-     */
-    LIB_ID GetSelectedLibId() const;
-
-protected:
-	void on3DviewReq( wxCommandEvent& event );
-	void onFpViewReq( wxCommandEvent& event );
-
-    // A command event sent by a PANEL_FOOTPRINT_CHOOSER will fire this event:
-	void onFpChanged( wxCommandEvent& event );
-
-    void build3DCanvas();
-
-    virtual void TearDownQuasiModal() override;
-
-protected:
-    PANEL_FOOTPRINT_CHOOSER* m_chooserPanel;
-    bool                     m_showFpMode;   // True to show the footprint, false for the 3D model
-
-private:
-    PCB_BASE_FRAME*          m_parent;
-    BOARD_ADAPTER            m_boardAdapter;
-    EDA_3D_CANVAS*           m_preview3DCanvas;
-    CAMERA&                  m_currentCamera;
-    TRACK_BALL               m_trackBallCamera;
-    BOARD*                   m_dummyBoard;
-    BITMAP_BUTTON*           m_grButtonFpView;
-    BITMAP_BUTTON*           m_grButton3DView;
-
-    /// The 3d viewer Render initial settings (must be saved and restored)
-    EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS m_initialRender;
-};
-
-#endif /* DIALOG_FOOTPRINT_CHOOSER_H */
diff --git a/pcbnew/footprint_chooser_frame.cpp b/pcbnew/footprint_chooser_frame.cpp
index 4ebf93084e..959c9895d5 100644
--- a/pcbnew/footprint_chooser_frame.cpp
+++ b/pcbnew/footprint_chooser_frame.cpp
@@ -624,6 +624,8 @@ void FOOTPRINT_CHOOSER_FRAME::closeFootprintChooser( wxCommandEvent& aEvent )
 void FOOTPRINT_CHOOSER_FRAME::onFpChanged( wxCommandEvent& event )
 {
     updateViews();
+
+    GetToolManager()->RunAction( ACTIONS::measureTool );
 }
 
 
diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp
index 35da1b0230..a17bb154c3 100644
--- a/pcbnew/load_select_footprint.cpp
+++ b/pcbnew/load_select_footprint.cpp
@@ -30,10 +30,9 @@ using namespace std::placeholders;
 #include <footprint.h>
 #include <confirm.h>
 #include <connectivity/connectivity_data.h>
-#include <dialog_footprint_chooser.h>
 #include <eda_list_dialog.h>
 #include <footprint_edit_frame.h>
-#include <footprint_tree_pane.h>
+#include <footprint_chooser_frame.h>
 #include <footprint_viewer_frame.h>
 #include <fp_lib_table.h>
 #include <pcb_io/pcb_io_mgr.h>
@@ -186,23 +185,22 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint )
 
 FOOTPRINT* PCB_BASE_FRAME::SelectFootprintFromLibrary( LIB_ID aPreselect )
 {
-    wxString        footprintName;
+    wxString        footprintName = aPreselect.Format().wx_str();
     LIB_ID          fpid;
     FOOTPRINT*      footprint = nullptr;
 
     static wxString lastComponentName;
 
-    DIALOG_FOOTPRINT_CHOOSER dialog( this, aPreselect, s_FootprintHistoryList );
+    if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, this ) )
+    {
+        if( frame->ShowModal( &footprintName, this ) )
+            fpid.Parse( UTF8( footprintName ) );
 
-    if( dialog.ShowQuasiModal() == wxID_CANCEL )
-        return nullptr;
-
-    fpid = dialog.GetSelectedLibId();
+        frame->Destroy();
+    }
 
     if( !fpid.IsValid() )
         return nullptr;
-    else
-        footprintName = fpid.Format().wx_str();
 
     try
     {
diff --git a/pcbnew/widgets/panel_footprint_chooser.cpp b/pcbnew/widgets/panel_footprint_chooser.cpp
index 46c0cab3e8..5dd8fe720b 100644
--- a/pcbnew/widgets/panel_footprint_chooser.cpp
+++ b/pcbnew/widgets/panel_footprint_chooser.cpp
@@ -373,8 +373,6 @@ void PANEL_FOOTPRINT_CHOOSER::onFootprintSelected( wxCommandEvent& aEvent )
     event.SetEventObject( this );
 
     ProcessWindowEvent( event );
-
-    m_frame->GetToolManager()->RunAction( ACTIONS::measureTool );
 }