From 3be6d5c5de743bebee0dc382d7926cab74c39eff Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 31 May 2024 12:32:01 +0100 Subject: [PATCH] Setup 3D canvas for Footprint Chooser previews. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17910 --- pcbnew/dialogs/dialog_footprint_chooser.cpp | 42 ++++++++++++++++++--- pcbnew/dialogs/dialog_footprint_chooser.h | 21 ++++++----- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/pcbnew/dialogs/dialog_footprint_chooser.cpp b/pcbnew/dialogs/dialog_footprint_chooser.cpp index f44a572b62..4af5bff529 100644 --- a/pcbnew/dialogs/dialog_footprint_chooser.cpp +++ b/pcbnew/dialogs/dialog_footprint_chooser.cpp @@ -143,6 +143,9 @@ DIALOG_FOOTPRINT_CHOOSER::DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent, 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 ), NULL, this ); @@ -166,15 +169,44 @@ void DIALOG_FOOTPRINT_CHOOSER::build3DCanvas() m_boardAdapter.SetBoard( m_dummyBoard ); m_boardAdapter.m_IsBoardView = false; m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options - EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - m_boardAdapter.m_Cfg = cfg; // 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() ) ); + OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ), + m_boardAdapter, m_currentCamera, + PROJECT_PCB::Get3DCacheManager( &m_parent->Prj() ) ); + + COMMON_SETTINGS* settings = Pgm().GetCommonSettings(); + + const DPI_SCALING_COMMON dpi{ settings, this }; + m_preview3DCanvas->SetScaleFactor( dpi.GetScaleFactor() ); + + // TODO(JE) use all control options + m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0; + + EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + + 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; + } m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 ); m_chooserPanel->m_RightPanel->Layout(); diff --git a/pcbnew/dialogs/dialog_footprint_chooser.h b/pcbnew/dialogs/dialog_footprint_chooser.h index 6e80f9aede..0971c82e19 100644 --- a/pcbnew/dialogs/dialog_footprint_chooser.h +++ b/pcbnew/dialogs/dialog_footprint_chooser.h @@ -63,17 +63,20 @@ protected: protected: PANEL_FOOTPRINT_CHOOSER* m_chooserPanel; - bool m_showFpMode; // True to show the footprint, false for the 3D model + 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; + 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 */