Browse Source

Gerbview: fix some issues related to color settings.

Now colors can be set both from the Layer manager and the
color settings panel, without loss of settings.
7.0
jean-pierre charras 3 years ago
parent
commit
a0d859c324
  1. 16
      gerbview/dialogs/panel_gerbview_color_settings.cpp
  2. 12
      gerbview/gerbview_draw_panel_gal.cpp
  3. 5
      gerbview/gerbview_frame.cpp
  4. 2
      gerbview/gerbview_frame.h
  5. 47
      gerbview/widgets/gerbview_layer_widget.cpp
  6. 7
      gerbview/widgets/gerbview_layer_widget.h
  7. 21
      gerbview/widgets/layer_widget.cpp
  8. 7
      gerbview/widgets/layer_widget.h

16
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;
}

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

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

2
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;

47
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 );

7
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.
*/

21
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 );

7
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.

Loading…
Cancel
Save