Save 3D prefs after editing, and load some of them into FP Props.

Fixes https://gitlab.com/kicad/code/kicad/issues/8712
This commit is contained in:
Jeff Young 2021-07-04 13:19:40 +01:00
parent 0116e9c94e
commit c11ee69499
9 changed files with 101 additions and 53 deletions

View File

@ -37,8 +37,9 @@
#include <gal/dpi_scaling.h> #include <gal/dpi_scaling.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <settings/common_settings.h> #include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <widgets/infobar.h> #include <widgets/infobar.h>
#include <eda_3d_viewer_settings.h>
PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame,
FOOTPRINT* aFootprint, FOOTPRINT* aFootprint,
@ -95,7 +96,7 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM
m_dummyBoard, m_boardAdapter, m_currentCamera, m_dummyBoard, m_boardAdapter, m_currentCamera,
aFrame->Prj().Get3DCacheManager() ); aFrame->Prj().Get3DCacheManager() );
loadCommonSettings(); loadSettings();
m_boardAdapter.SetFlag( FL_USE_SELECTION, false ); m_boardAdapter.SetFlag( FL_USE_SELECTION, false );
m_boardAdapter.SetFlag( FL_HIGHLIGHT_ROLLOVER_ITEM, false ); m_boardAdapter.SetFlag( FL_HIGHLIGHT_ROLLOVER_ITEM, false );
@ -161,7 +162,7 @@ void PANEL_PREVIEW_3D_MODEL::OnMenuEvent( wxMenuEvent& aEvent )
} }
void PANEL_PREVIEW_3D_MODEL::loadCommonSettings() void PANEL_PREVIEW_3D_MODEL::loadSettings()
{ {
wxCHECK_RET( m_previewPane, "Cannot load settings to null canvas" ); wxCHECK_RET( m_previewPane, "Cannot load settings to null canvas" );
@ -172,6 +173,43 @@ void PANEL_PREVIEW_3D_MODEL::loadCommonSettings()
// TODO(JE) use all control options // TODO(JE) use all control options
m_boardAdapter.SetFlag( FL_MOUSEWHEEL_PANNING, settings->m_Input.scroll_modifier_zoom != 0 ); m_boardAdapter.SetFlag( FL_MOUSEWHEEL_PANNING, settings->m_Input.scroll_modifier_zoom != 0 );
COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
if( colors )
{
auto set =
[] ( const COLOR4D& aColor, SFVEC4F& aTarget )
{
aTarget.r = aColor.r;
aTarget.g = aColor.g;
aTarget.b = aColor.b;
aTarget.a = aColor.a;
};
set( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ), m_boardAdapter.m_BgColorBot );
set( colors->GetColor( LAYER_3D_BACKGROUND_TOP ), m_boardAdapter.m_BgColorTop );
set( colors->GetColor( LAYER_3D_BOARD ), m_boardAdapter.m_BoardBodyColor );
set( colors->GetColor( LAYER_3D_COPPER ), m_boardAdapter.m_CopperColor );
set( colors->GetColor( LAYER_3D_SILKSCREEN_BOTTOM ), m_boardAdapter.m_SilkScreenColorBot );
set( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ), m_boardAdapter.m_SilkScreenColorTop );
set( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorBot );
set( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorTop );
set( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_boardAdapter.m_SolderPasteColor );
}
EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
if( cfg )
{
m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL_LEGACY );
m_boardAdapter.SetFlag( FL_USE_REALISTIC_MODE, cfg->m_Render.realistic );
m_boardAdapter.SetMaterialMode( static_cast<MATERIAL_MODE>( cfg->m_Render.material_mode ) );
m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
}
} }

View File

@ -106,7 +106,7 @@ private:
/** /**
* Load 3D relevant settings from the user configuration * Load 3D relevant settings from the user configuration
*/ */
void loadCommonSettings(); void loadSettings();
/** /**
* It will receive the events from editing the fields. * It will receive the events from editing the fields.

View File

@ -25,13 +25,18 @@
#include <widgets/color_swatch.h> #include <widgets/color_swatch.h>
#include <3d_canvas/board_adapter.h> #include <3d_canvas/board_adapter.h>
#include <3d_viewer/eda_3d_viewer.h> #include <3d_viewer/eda_3d_viewer.h>
#include <eda_3d_viewer_settings.h>
#include <settings/settings_manager.h>
#include <board_stackup_manager/stackup_predefined_prms.h> #include <board_stackup_manager/stackup_predefined_prms.h>
#include <board_stackup_manager/board_stackup.h> #include <board_stackup_manager/board_stackup.h>
#include <board_design_settings.h> #include <board_design_settings.h>
#include <pgm_base.h>
PANEL_3D_COLORS::PANEL_3D_COLORS( EDA_3D_VIEWER_FRAME* aFrame, wxWindow* aParent ) : PANEL_3D_COLORS::PANEL_3D_COLORS( EDA_3D_VIEWER_FRAME* aFrame, wxWindow* aParent ) :
PANEL_3D_COLORS_BASE( aParent ), PANEL_3D_COLORS_BASE( aParent ),
m_settings( aFrame->GetAdapter() ) m_frame( aFrame ),
m_boardAdapter( aFrame->GetAdapter() )
{ {
#define ADD_COLOR( list, r, g, b, a, name ) \ #define ADD_COLOR( list, r, g, b, a, name ) \
list.push_back( CUSTOM_COLOR_ITEM( r/255.0, g/255.0, b/255.0, a, name ) ) list.push_back( CUSTOM_COLOR_ITEM( r/255.0, g/255.0, b/255.0, a, name ) )
@ -109,15 +114,15 @@ bool PANEL_3D_COLORS::TransferDataToWindow()
return COLOR4D( src.r, src.g, src.b, src.a ); return COLOR4D( src.r, src.g, src.b, src.a );
}; };
m_backgroundTop->SetSwatchColor( to_COLOR4D( m_settings.m_BgColorTop ), false ); m_backgroundTop->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_BgColorTop ), false );
m_backgroundBottom->SetSwatchColor( to_COLOR4D( m_settings.m_BgColorBot ), false ); m_backgroundBottom->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_BgColorBot ), false );
m_silkscreenTop->SetSwatchColor( to_COLOR4D( m_settings.m_SilkScreenColorTop ), false ); m_silkscreenTop->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_SilkScreenColorTop ), false );
m_silkscreenBottom->SetSwatchColor( to_COLOR4D( m_settings.m_SilkScreenColorBot ), false ); m_silkscreenBottom->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_SilkScreenColorBot ), false );
m_solderMaskTop->SetSwatchColor( to_COLOR4D( m_settings.m_SolderMaskColorTop ), false ); m_solderMaskTop->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_SolderMaskColorTop ), false );
m_solderMaskBottom->SetSwatchColor( to_COLOR4D( m_settings.m_SolderMaskColorBot ), false ); m_solderMaskBottom->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_SolderMaskColorBot ), false );
m_solderPaste->SetSwatchColor( to_COLOR4D( m_settings.m_SolderPasteColor ), false ); m_solderPaste->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_SolderPasteColor ), false );
m_surfaceFinish->SetSwatchColor( to_COLOR4D( m_settings.m_CopperColor ), false ); m_surfaceFinish->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_CopperColor ), false );
m_boardBody->SetSwatchColor( to_COLOR4D( m_settings.m_BoardBodyColor ), false ); m_boardBody->SetSwatchColor( to_COLOR4D( m_boardAdapter.m_BoardBodyColor ), false );
return true; return true;
} }
@ -130,15 +135,20 @@ bool PANEL_3D_COLORS::TransferDataFromWindow()
return SFVEC4F( src.r, src.g, src.b, src.a ); return SFVEC4F( src.r, src.g, src.b, src.a );
}; };
m_settings.m_BgColorTop = to_SFVEC4F( m_backgroundTop->GetSwatchColor() ); m_boardAdapter.m_BgColorTop = to_SFVEC4F( m_backgroundTop->GetSwatchColor() );
m_settings.m_BgColorBot = to_SFVEC4F( m_backgroundBottom->GetSwatchColor() ); m_boardAdapter.m_BgColorBot = to_SFVEC4F( m_backgroundBottom->GetSwatchColor() );
m_settings.m_SilkScreenColorTop = to_SFVEC4F( m_silkscreenTop->GetSwatchColor() ); m_boardAdapter.m_SilkScreenColorTop = to_SFVEC4F( m_silkscreenTop->GetSwatchColor() );
m_settings.m_SilkScreenColorBot = to_SFVEC4F( m_silkscreenBottom->GetSwatchColor() ); m_boardAdapter.m_SilkScreenColorBot = to_SFVEC4F( m_silkscreenBottom->GetSwatchColor() );
m_settings.m_SolderMaskColorTop = to_SFVEC4F( m_solderMaskTop->GetSwatchColor() ); m_boardAdapter.m_SolderMaskColorTop = to_SFVEC4F( m_solderMaskTop->GetSwatchColor() );
m_settings.m_SolderMaskColorBot = to_SFVEC4F( m_solderMaskBottom->GetSwatchColor() ); m_boardAdapter.m_SolderMaskColorBot = to_SFVEC4F( m_solderMaskBottom->GetSwatchColor() );
m_settings.m_SolderPasteColor = to_SFVEC4F( m_solderPaste->GetSwatchColor() ); m_boardAdapter.m_SolderPasteColor = to_SFVEC4F( m_solderPaste->GetSwatchColor() );
m_settings.m_CopperColor = to_SFVEC4F( m_surfaceFinish->GetSwatchColor() ); m_boardAdapter.m_CopperColor = to_SFVEC4F( m_surfaceFinish->GetSwatchColor() );
m_settings.m_BoardBodyColor = to_SFVEC4F( m_boardBody->GetSwatchColor() ); m_boardAdapter.m_BoardBodyColor = to_SFVEC4F( m_boardBody->GetSwatchColor() );
auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
if( cfg )
m_frame->SaveSettings( cfg );
return true; return true;
} }
@ -146,7 +156,7 @@ bool PANEL_3D_COLORS::TransferDataFromWindow()
void PANEL_3D_COLORS::OnLoadColorsFromBoardStackup( wxCommandEvent& event ) void PANEL_3D_COLORS::OnLoadColorsFromBoardStackup( wxCommandEvent& event )
{ {
const BOARD* brd = m_settings.GetBoard(); const BOARD* brd = m_boardAdapter.GetBoard();
const FAB_LAYER_COLOR* stdColors = GetColorStandardList(); const FAB_LAYER_COLOR* stdColors = GetColorStandardList();
wxColour color; wxColour color;
@ -179,26 +189,26 @@ void PANEL_3D_COLORS::OnLoadColorsFromBoardStackup( wxCommandEvent& event )
switch( stckpItem->GetBrdLayerId() ) switch( stckpItem->GetBrdLayerId() )
{ {
case F_SilkS: case F_SilkS:
m_settings.m_SilkScreenColorTop.r = color.Red() / 255.0; m_boardAdapter.m_SilkScreenColorTop.r = color.Red() / 255.0;
m_settings.m_SilkScreenColorTop.g = color.Green() / 255.0; m_boardAdapter.m_SilkScreenColorTop.g = color.Green() / 255.0;
m_settings.m_SilkScreenColorTop.b = color.Blue() / 255.0; m_boardAdapter.m_SilkScreenColorTop.b = color.Blue() / 255.0;
break; break;
case B_SilkS: case B_SilkS:
m_settings.m_SilkScreenColorBot.r = color.Red() / 255.0; m_boardAdapter.m_SilkScreenColorBot.r = color.Red() / 255.0;
m_settings.m_SilkScreenColorBot.g = color.Green() / 255.0; m_boardAdapter.m_SilkScreenColorBot.g = color.Green() / 255.0;
m_settings.m_SilkScreenColorBot.b = color.Blue() / 255.0; m_boardAdapter.m_SilkScreenColorBot.b = color.Blue() / 255.0;
break; break;
case F_Mask: case F_Mask:
m_settings.m_SolderMaskColorTop.r = color.Red() / 255.0; m_boardAdapter.m_SolderMaskColorTop.r = color.Red() / 255.0;
m_settings.m_SolderMaskColorTop.g = color.Green() / 255.0; m_boardAdapter.m_SolderMaskColorTop.g = color.Green() / 255.0;
m_settings.m_SolderMaskColorTop.b = color.Blue() / 255.0; m_boardAdapter.m_SolderMaskColorTop.b = color.Blue() / 255.0;
// Keep the previous alpha value // Keep the previous alpha value
//m_boardAdapter.m_SolderMaskColorTop.a = color.Alpha() / 255.0; //m_boardAdapter.m_SolderMaskColorTop.a = color.Alpha() / 255.0;
break; break;
case B_Mask: case B_Mask:
m_settings.m_SolderMaskColorBot.r = color.Red() / 255.0; m_boardAdapter.m_SolderMaskColorBot.r = color.Red() / 255.0;
m_settings.m_SolderMaskColorBot.g = color.Green() / 255.0; m_boardAdapter.m_SolderMaskColorBot.g = color.Green() / 255.0;
m_settings.m_SolderMaskColorBot.b = color.Blue() / 255.0; m_boardAdapter.m_SolderMaskColorBot.b = color.Blue() / 255.0;
// Keep the previous alpha value // Keep the previous alpha value
//m_boardAdapter.m_SolderMaskColorBot.a = color.Alpha() / 255.0; //m_boardAdapter.m_SolderMaskColorBot.a = color.Alpha() / 255.0;
break; break;

View File

@ -41,13 +41,14 @@ public:
void OnLoadColorsFromBoardStackup( wxCommandEvent& event ) override; void OnLoadColorsFromBoardStackup( wxCommandEvent& event ) override;
private: private:
BOARD_ADAPTER& m_settings; EDA_3D_VIEWER_FRAME* m_frame;
BOARD_ADAPTER& m_boardAdapter;
CUSTOM_COLORS_LIST m_silkscreenColors; CUSTOM_COLORS_LIST m_silkscreenColors;
CUSTOM_COLORS_LIST m_maskColors; CUSTOM_COLORS_LIST m_maskColors;
CUSTOM_COLORS_LIST m_pasteColors; CUSTOM_COLORS_LIST m_pasteColors;
CUSTOM_COLORS_LIST m_finishColors; CUSTOM_COLORS_LIST m_finishColors;
CUSTOM_COLORS_LIST m_boardColors; CUSTOM_COLORS_LIST m_boardColors;
}; };

View File

@ -106,6 +106,9 @@ public:
EDA_3D_CANVAS* GetCanvas() { return m_canvas; } EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
/** /**
* Notification that common settings are updated. * Notification that common settings are updated.
* *
@ -137,10 +140,6 @@ private:
void CreateMenuBar(); void CreateMenuBar();
void ReCreateMainToolbar(); void ReCreateMainToolbar();
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
/** /**
* Create a Screenshot of the current 3D view. * Create a Screenshot of the current 3D view.
* Output file format is png or jpeg, or image is copied to the clipboard * Output file format is png or jpeg, or image is copied to the clipboard

View File

@ -262,7 +262,7 @@ bool PGM_BASE::InitPgm( bool aHeadless )
// Load common settings from disk after setting up env vars // Load common settings from disk after setting up env vars
GetSettingsManager().Load( GetCommonSettings() ); GetSettingsManager().Load( GetCommonSettings() );
// Init user language *before* calling loadCommonSettings, because // Init user language *before* calling loadSettings, because
// env vars could be incorrectly initialized on Linux // env vars could be incorrectly initialized on Linux
// (if the value contains some non ASCII7 chars, the env var is not initialized) // (if the value contains some non ASCII7 chars, the env var is not initialized)
SetLanguage( tmp, true ); SetLanguage( tmp, true );
@ -343,7 +343,7 @@ void PGM_BASE::loadCommonSettings()
for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars ) for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
{ {
wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s", wxLogTrace( traceEnvVars, "PGM_BASE::loadSettings: Found entry %s = %s",
it.first, it.second.GetValue() ); it.first, it.second.GetValue() );
// Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason

View File

@ -428,7 +428,7 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
{ {
m_state = IDLE; m_state = IDLE;
#if defined USE_MOUSE_CAPTURE #if defined USE_MOUSE_CAPTURE
if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() ) if( !m_boardAdapter.m_cursorCaptured && m_parentPanel->HasCapture() )
m_parentPanel->ReleaseMouse(); m_parentPanel->ReleaseMouse();
#endif #endif
} }
@ -629,7 +629,7 @@ void WX_VIEW_CONTROLS::CancelDrag()
{ {
m_state = IDLE; m_state = IDLE;
#if defined USE_MOUSE_CAPTURE #if defined USE_MOUSE_CAPTURE
if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() ) if( !m_boardAdapter.m_cursorCaptured && m_parentPanel->HasCapture() )
m_parentPanel->ReleaseMouse(); m_parentPanel->ReleaseMouse();
#endif #endif
} }

View File

@ -280,7 +280,7 @@
<property name="id">ID_MENU_SET_SIMUL</property> <property name="id">ID_MENU_SET_SIMUL</property>
<property name="kind">wxITEM_NORMAL</property> <property name="kind">wxITEM_NORMAL</property>
<property name="label">Settings...</property> <property name="label">Settings...</property>
<property name="name">m_settings</property> <property name="name">m_boardAdapter</property>
<property name="permission">protected</property> <property name="permission">protected</property>
<property name="shortcut"></property> <property name="shortcut"></property>
<property name="unchecked_bitmap"></property> <property name="unchecked_bitmap"></property>

View File

@ -261,7 +261,7 @@ SYMBOL_EDIT_FRAME::~SYMBOL_EDIT_FRAME()
void SYMBOL_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) void SYMBOL_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{ {
wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_settings" ); wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_boardAdapter" );
SCH_BASE_FRAME::LoadSettings( GetSettings() ); SCH_BASE_FRAME::LoadSettings( GetSettings() );
@ -276,7 +276,7 @@ void SYMBOL_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
void SYMBOL_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) void SYMBOL_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{ {
wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_settings" ); wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_boardAdapter" );
GetGalDisplayOptions().m_axesEnabled = true; GetGalDisplayOptions().m_axesEnabled = true;