From 4a201df5564208708873921b4ed99ac860ce9ef2 Mon Sep 17 00:00:00 2001 From: John Beard Date: Mon, 8 Apr 2019 10:49:18 +0100 Subject: [PATCH] 3D viewer: use hi-DPI settings for canvases The 3D viewer also uses OpenGL, so it also needs to adjust based on DPI scale factors. This patch moves the 3D viewer common config code solely within the 3D viewer, and adds handling of the DPI scale. This also avoids duplicated logic in PCB_BASE_FRAME::CommonSettingsChanged. For now, as EDA_3D_VIEWER is not included in the Kiway settings dispatch, still manually invoke the settings update from PCB_BASE_FRAME. The PANEL_3D_PREV gets a similar function to read the config, but it doesn't have a listener for the update, so it's set just once at dialog init, just like the existing pan settings. Fixes: lp:1823681 * https://bugs.launchpad.net/kicad/+bug/1823681 (cherry picked from commit 124dd5e59ac843c4220dc3a4c36d0598d7634d2f) --- .../3d_cache/dialogs/panel_prev_model.cpp | 37 ++++++++++--- 3d-viewer/3d_cache/dialogs/panel_prev_model.h | 5 ++ 3d-viewer/3d_viewer/eda_3d_viewer.cpp | 55 +++++++++++++++---- 3d-viewer/3d_viewer/eda_3d_viewer.h | 14 +++++ pcbnew/pcb_base_frame.cpp | 5 +- 5 files changed, 95 insertions(+), 21 deletions(-) diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp index af0ee8678c..5d5f2fbdee 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp @@ -28,16 +28,20 @@ * @file panel_prev_model.cpp */ +#include "panel_prev_model.h" + #include <3d_canvas/eda_3d_canvas.h> #include -#include -#include -#include "project.h" -#include "panel_prev_model.h" #include + +#include +#include #include +#include #include +#include + PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule, std::vector *aParentModelList ) : @@ -58,15 +62,13 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* // Set 3d viewer configuration for preview m_settings3Dviewer = new CINFO3D_VISU(); - bool option; - Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false ); - m_settings3Dviewer->SetFlag( FL_MOUSEWHEEL_PANNING, option ); - // Create the 3D canvas m_previewPane = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( true ), m_dummyBoard, *m_settings3Dviewer, aFrame->Prj().Get3DCacheManager() ); + loadCommonSettings(); + m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 ); } @@ -111,6 +113,25 @@ void PANEL_PREV_3D::initPanel() } +void PANEL_PREV_3D::loadCommonSettings() +{ + wxCHECK_RET( m_previewPane, "Cannot load settings to null canvas" ); + + wxConfigBase& cmnCfg = *Pgm().CommonSettings(); + + { + const DPI_SCALING dpi{ &cmnCfg, this }; + m_previewPane->SetScaleFactor( dpi.GetScaleFactor() ); + } + + { + bool option; + cmnCfg.Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false ); + m_settings3Dviewer->SetFlag( FL_MOUSEWHEEL_PANNING, option ); + } +} + + /** * @brief rotationFromString * Ensure -MAX_ROTATION <= rotation <= MAX_ROTATION diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.h b/3d-viewer/3d_cache/dialogs/panel_prev_model.h index 6f0142d7ab..b2c932a2ee 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.h +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.h @@ -93,6 +93,11 @@ private: private: void initPanel(); + /** + * Load 3D relevant settings from the user configuration + */ + void loadCommonSettings(); + /** * @brief updateOrientation - it will receive the events from editing the fields * @param event diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index c14c2a2697..38724b5df9 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -28,18 +28,22 @@ */ #include "eda_3d_viewer.h" + #include "../3d_viewer_id.h" -#include +#include "../common_ogl/cogl_att_list.h" + +#include +#include #include +#include +#include +#include #include + +#include #include #include -#include -#include "../common_ogl/cogl_att_list.h" -#include #include -#include -#include /** @@ -168,10 +172,6 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, icon.CopyFromBitmap( KiBitmap( icon_3d_xpm ) ); SetIcon( icon ); - bool option; - Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false ); - m_settings.SetFlag( FL_MOUSEWHEEL_PANNING, option ); - LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); @@ -190,6 +190,9 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, if( m_canvas ) m_canvas->SetStatusBar( status_bar ); + // Some settings need the canvas + loadCommonSettings(); + CreateMenuBar(); ReCreateMainToolbar(); @@ -869,6 +872,19 @@ void EDA_3D_VIEWER::SaveSettings( wxConfigBase *aCfg ) } +void EDA_3D_VIEWER::CommonSettingsChanged() +{ + wxLogTrace( m_logTrace, "EDA_3D_VIEWER::CommonSettingsChanged" ); + + // Regen menu bars, etc + EDA_BASE_FRAME::CommonSettingsChanged(); + + loadCommonSettings(); + + NewDisplay( true ); +} + + void EDA_3D_VIEWER::OnLeftClick( wxDC *DC, const wxPoint &MousePos ) { wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnLeftClick" ); @@ -1225,3 +1241,22 @@ void EDA_3D_VIEWER::OnUpdateUIAxis( wxUpdateUIEvent& aEvent ) { aEvent.Check( m_settings.GetFlag( FL_AXIS ) ); } + + +void EDA_3D_VIEWER::loadCommonSettings() +{ + wxCHECK_RET( m_canvas, "Cannot load settings to null canvas" ); + + wxConfigBase& cmnCfg = *Pgm().CommonSettings(); + + { + const DPI_SCALING dpi{ &cmnCfg, this }; + m_canvas->SetScaleFactor( dpi.GetScaleFactor() ); + } + + { + bool option; + cmnCfg.Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false ); + m_settings.SetFlag( FL_MOUSEWHEEL_PANNING, option ); + } +} \ No newline at end of file diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.h b/3d-viewer/3d_viewer/eda_3d_viewer.h index 36e0c29db8..b6ecf729bd 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.h +++ b/3d-viewer/3d_viewer/eda_3d_viewer.h @@ -154,6 +154,15 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER */ bool Set3DSilkScreenColorFromUser(); + /** + * Notification that common settings are updated. + * + * This would be private (and only called by the Kiway), but we + * need to do this manually from the PCB frame because the 3D viewer isn't + * updated via the #KIWAY. + */ + void CommonSettingsChanged() override; + private: /// Called when user press the File->Exit void Exit3DFrame( wxCommandEvent &event ); @@ -217,6 +226,11 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER private: + /** + * Load configuration from common settings. + */ + void loadCommonSettings(); + /** * Filename to propose for save a screenshot */ diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 61fdf831ed..dcf825c2a6 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -992,9 +992,8 @@ void PCB_BASE_FRAME::CommonSettingsChanged() if( viewer ) { - bool option; - Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option ); - viewer->GetSettings().SetFlag( FL_MOUSEWHEEL_PANNING, option ); + // The 3D viewer isn't in the Kiway, so send its update manually + viewer->CommonSettingsChanged(); } }