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(); } }