diff --git a/gerbview/dialogs/panel_gerbview_color_settings.cpp b/gerbview/dialogs/panel_gerbview_color_settings.cpp index 12e9a3b22d..3efc302b5c 100644 --- a/gerbview/dialogs/panel_gerbview_color_settings.cpp +++ b/gerbview/dialogs/panel_gerbview_color_settings.cpp @@ -22,7 +22,10 @@ #include <panel_gerbview_color_settings.h> #include <settings/settings_manager.h> #include <gerbview_settings.h> +#include <gerbview_frame.h> +#include <widgets/gerbview_layer_widget.h> +#include <wx/log.h> PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS( wxWindow* aParent ) : PANEL_COLOR_SETTINGS( aParent ) { @@ -32,15 +35,26 @@ PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS( wxWindow* aParent GERBVIEW_SETTINGS* app_settings = mgr.GetAppSettings<GERBVIEW_SETTINGS>(); COLOR_SETTINGS* current = mgr.GetColorSettings( app_settings->m_ColorTheme ); + // Colors can also be modified from the LayersManager, so collect last settings if exist + // (They can be no yet saved on disk) + GERBVIEW_FRAME* gbr_mainframe = dynamic_cast<GERBVIEW_FRAME*>( + wxWindow::FindWindowByName( GERBVIEW_FRAME_NAME ) ); + if( gbr_mainframe ) + { + gbr_mainframe->m_LayersManager->CollectCurrentColorSettings( current ); + } + // Saved theme doesn't exist? Reset to default if( current->GetFilename() != app_settings->m_ColorTheme ) app_settings->m_ColorTheme = current->GetFilename(); createThemeList( app_settings->m_ColorTheme ); + // Currently this only applies to eeschema m_optOverrideColors->Hide(); + m_currentSettings = new COLOR_SETTINGS( *current ); for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; i++ ) @@ -92,7 +106,7 @@ void PANEL_GERBVIEW_COLOR_SETTINGS::createSwatches() case LAYER_GERBVIEW_BACKGROUND: layerName = _( "Background" ); break; default: - layerName = wxString::Format( _( "Layer %d" ), layer + 1 - GERBVIEW_LAYER_ID_START ); + layerName = wxString::Format( _( "Graphic Layer %d" ), layer + 1 - GERBVIEW_LAYER_ID_START ); break; } diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 0e2d9ac1a6..13d0d88c98 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -58,8 +58,16 @@ EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalTy setDefaultLayerDeps(); + COLOR_SETTINGS* color_settings; + + if( auto frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() ) ) + color_settings = frame->GetColorSettings(); + else + color_settings = Pgm().GetSettingsManager().GetColorSettings(); + + wxASSERT( color_settings ); auto renderSettings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_painter->GetSettings() ); - renderSettings->LoadColors( Pgm().GetSettingsManager().GetColorSettings() ); + renderSettings->LoadColors( color_settings ); } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index ce9997e562..f318da5f68 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -374,9 +374,10 @@ void GERBVIEW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) COLOR_SETTINGS* GERBVIEW_FRAME::GetColorSettings( bool aForceRefresh ) const { - GERBVIEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<GERBVIEW_SETTINGS>(); + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + GERBVIEW_SETTINGS* cfg = mgr.GetAppSettings<GERBVIEW_SETTINGS>(); wxString currentTheme = cfg->m_ColorTheme; - return Pgm().GetSettingsManager().GetColorSettings( currentTheme ); + return mgr.GetColorSettings( currentTheme ); } diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 20100e3fdf..1d24d0de9a 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -526,9 +526,9 @@ public: wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about // gerber data (format..) -protected: GERBER_LAYER_WIDGET* m_LayersManager; +protected: FILE_HISTORY m_zipFileHistory; FILE_HISTORY m_drillFileHistory; FILE_HISTORY m_jobFileHistory; diff --git a/gerbview/widgets/gerbview_layer_widget.cpp b/gerbview/widgets/gerbview_layer_widget.cpp index c75fe5ae38..6e8b1d4938 100644 --- a/gerbview/widgets/gerbview_layer_widget.cpp +++ b/gerbview/widgets/gerbview_layer_widget.cpp @@ -80,6 +80,41 @@ void GERBER_LAYER_WIDGET::SetLayersManagerTabsText() m_notebook->SetPageText( 1, _( "Items" ) ); } + +void GERBER_LAYER_WIDGET::CollectCurrentColorSettings( COLOR_SETTINGS* aColorSettings ) +{ + std::vector<int>render_layers{ LAYER_DCODES, LAYER_NEGATIVE_OBJECTS, LAYER_GERBVIEW_GRID, + LAYER_GERBVIEW_DRAWINGSHEET, LAYER_GERBVIEW_PAGE_LIMITS, + LAYER_GERBVIEW_BACKGROUND }; + + for( int layer: render_layers ) + { + int row = findRenderRow( layer ); + + if( row < 0 ) + continue; + + COLOR4D color = GetRenderColor( row ); + + if( color != COLOR4D::UNSPECIFIED ) + aColorSettings->SetColor( layer, color ); + } + + for( int layer = GERBVIEW_LAYER_ID_START; layer < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; layer++ ) + { + int row = findLayerRow( layer - GERBVIEW_LAYER_ID_START ); + + if( row < 0 ) // Not existing in layer list + continue; + + COLOR4D color = GetLayerColor( row ); + + if( color != COLOR4D::UNSPECIFIED ) + aColorSettings->SetColor( layer, color ); + } +} + + void GERBER_LAYER_WIDGET::ReFillRender() { ClearRenderRows(); @@ -296,8 +331,10 @@ void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, const COLOR4D& aColor m_frame->m_SelLayerBox->ResyncBitmapOnly(); KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); - auto settings = m_frame->GetColorSettings(); - view->GetPainter()->GetSettings()->LoadColors( settings ); + COLOR_SETTINGS* color_settings = m_frame->GetColorSettings(); + color_settings->SetColor( aLayer, aColor ); + + view->GetPainter()->GetSettings()->LoadColors( color_settings ); view->UpdateLayerColor( GERBER_DRAW_LAYER( aLayer ) ); m_frame->GetCanvas()->Refresh(); @@ -348,9 +385,11 @@ void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, const COLOR4D& aColor ) m_frame->SetVisibleElementColor( aId, aColor ); auto view = m_frame->GetCanvas()->GetView(); - COLOR_SETTINGS* settings = m_frame->GetColorSettings(); - view->GetPainter()->GetSettings()->LoadColors( settings ); + COLOR_SETTINGS* color_settings = m_frame->GetColorSettings(); + color_settings->SetColor( aId, aColor ); + + view->GetPainter()->GetSettings()->LoadColors( color_settings ); view->UpdateLayerColor( aId ); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); view->UpdateAllItems( KIGFX::COLOR ); diff --git a/gerbview/widgets/gerbview_layer_widget.h b/gerbview/widgets/gerbview_layer_widget.h index 8b1dece426..9d4c858752 100644 --- a/gerbview/widgets/gerbview_layer_widget.h +++ b/gerbview/widgets/gerbview_layer_widget.h @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2010 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> - * Copyright (C) 2010-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2010-2022 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,6 +42,11 @@ public: */ GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFocusOwner ); + /** + * Collect the current color settings and put it in aColorSettings + */ + void CollectCurrentColorSettings( COLOR_SETTINGS* aColorSettings ); + /** * Rebuild Render for instance after the config is read. */ diff --git a/gerbview/widgets/layer_widget.cpp b/gerbview/widgets/layer_widget.cpp index eef4a981e6..b868407eef 100644 --- a/gerbview/widgets/layer_widget.cpp +++ b/gerbview/widgets/layer_widget.cpp @@ -3,7 +3,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> - * Copyright (C) 2010-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2010-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -764,7 +764,7 @@ COLOR4D LAYER_WIDGET::GetLayerColor( int aLayer ) const if( row >= 0 ) { - int col = 1; // bitmap button is column 1 + const int col = 1; // bitmap button is column 1 auto swatch = static_cast<COLOR_SWATCH*>( getLayerComp( row, col ) ); wxASSERT( swatch ); @@ -775,6 +775,23 @@ COLOR4D LAYER_WIDGET::GetLayerColor( int aLayer ) const } +COLOR4D LAYER_WIDGET::GetRenderColor( int aRow ) const +{ + int row = aRow; + + if( row >= 0 ) + { + const int col = 0; // bitmap button (swatch) is column 0 + auto swatch = static_cast<COLOR_SWATCH*>( getRenderComp( row, col ) ); + wxASSERT( swatch ); + + return swatch->GetSwatchColor(); + } + + return COLOR4D::UNSPECIFIED; // it's caller fault, gave me a bad layer +} + + void LAYER_WIDGET::SetRenderState( int aId, bool isSet ) { int row = findRenderRow( aId ); diff --git a/gerbview/widgets/layer_widget.h b/gerbview/widgets/layer_widget.h index 2ac55b5816..58c923cfc1 100644 --- a/gerbview/widgets/layer_widget.h +++ b/gerbview/widgets/layer_widget.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> - * Copyright (C) 2010-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2010-2022 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -245,6 +245,11 @@ public: */ COLOR4D GetLayerColor( int aLayer ) const; + /** + * Return the color of the Render ROW in position \a aRow. + */ + COLOR4D GetRenderColor( int aRow ) const; + /** * Set the state of the checkbox associated with \a aId within the Render tab group of the * widget.