Setup 3D canvas for Footprint Chooser previews.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17910
This commit is contained in:
Jeff Young 2024-05-31 12:32:01 +01:00
parent 6f0a1ade01
commit 3be6d5c5de
2 changed files with 49 additions and 14 deletions

View File

@ -143,6 +143,9 @@ DIALOG_FOOTPRINT_CHOOSER::DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent,
DIALOG_FOOTPRINT_CHOOSER::~DIALOG_FOOTPRINT_CHOOSER() DIALOG_FOOTPRINT_CHOOSER::~DIALOG_FOOTPRINT_CHOOSER()
{ {
if( m_boardAdapter.m_Cfg )
m_boardAdapter.m_Cfg->m_Render = m_initialRender;
// Disconnect Events // Disconnect Events
m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ), NULL, this ); wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ), NULL, this );
@ -166,15 +169,44 @@ void DIALOG_FOOTPRINT_CHOOSER::build3DCanvas()
m_boardAdapter.SetBoard( m_dummyBoard ); m_boardAdapter.SetBoard( m_dummyBoard );
m_boardAdapter.m_IsBoardView = false; m_boardAdapter.m_IsBoardView = false;
m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
m_boardAdapter.m_Cfg = cfg;
// Build the 3D canvas // Build the 3D canvas
m_preview3DCanvas = new EDA_3D_CANVAS( m_chooserPanel->m_RightPanel, m_preview3DCanvas = new EDA_3D_CANVAS( m_chooserPanel->m_RightPanel,
OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ), OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
m_boardAdapter, m_currentCamera, m_boardAdapter, m_currentCamera,
PROJECT_PCB::Get3DCacheManager( &m_parent->Prj() ) ); 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<EDA_3D_VIEWER_SETTINGS>();
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_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
m_chooserPanel->m_RightPanel->Layout(); m_chooserPanel->m_RightPanel->Layout();

View File

@ -63,17 +63,20 @@ protected:
protected: protected:
PANEL_FOOTPRINT_CHOOSER* m_chooserPanel; 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: private:
PCB_BASE_FRAME* m_parent; PCB_BASE_FRAME* m_parent;
BOARD_ADAPTER m_boardAdapter; BOARD_ADAPTER m_boardAdapter;
EDA_3D_CANVAS* m_preview3DCanvas; EDA_3D_CANVAS* m_preview3DCanvas;
CAMERA& m_currentCamera; CAMERA& m_currentCamera;
TRACK_BALL m_trackBallCamera; TRACK_BALL m_trackBallCamera;
BOARD* m_dummyBoard; BOARD* m_dummyBoard;
BITMAP_BUTTON* m_grButtonFpView; BITMAP_BUTTON* m_grButtonFpView;
BITMAP_BUTTON* m_grButton3DView; 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 */ #endif /* DIALOG_FOOTPRINT_CHOOSER_H */