KiCad PCB EDA Suite
panel_fp_editor_color_settings.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <regex>
22 
23 #include <board.h>
24 #include <footprint_edit_frame.h>
30 
31 
33  wxWindow* aParent )
34  : PANEL_COLOR_SETTINGS( aParent ),
35  m_frame( aFrame ),
36  m_page( nullptr ),
37  m_titleBlock( nullptr )
38 {
39  // Currently this only applies to eeschema
40  m_optOverrideColors->Hide();
41 
42  m_colorNamespace = "board";
43 
45 
47  COLOR_SETTINGS* current = mgr->GetColorSettings( settings->m_ColorTheme );
48 
49  // Store the current settings before reloading below
50  current->Store();
51  mgr->SaveColorSettings( current, "board" );
52 
53  m_optOverrideColors->SetValue( current->GetOverrideSchItemColors() );
54 
55  m_currentSettings = new COLOR_SETTINGS( *current );
56 
57  mgr->ReloadColorSettings();
58  createThemeList( settings->m_ColorTheme );
59 
60  m_validLayers.push_back( F_Cu );
61  m_validLayers.push_back( In1_Cu ); // "Internal Layers"
62  m_validLayers.push_back( B_Cu );
63 
64  for( int id = GAL_LAYER_ID_START; id < GAL_LAYER_ID_END; id++ )
65  {
66  if( id == LAYER_VIAS
67  || id == LAYER_VIA_HOLES
68  || id == LAYER_VIA_HOLEWALLS
69  || id == LAYER_PAD_PLATEDHOLES
70  || id == LAYER_PAD_HOLEWALLS )
71  {
72  continue;
73  }
74 
75  m_validLayers.push_back( id );
76  }
77 
79 
80  m_colorsMainSizer->Insert( 0, 10, 0, 0, wxEXPAND, 5 );
81 
83 }
84 
85 
87 {
88  delete m_currentSettings;
89  delete m_page;
90  delete m_titleBlock;
91 }
92 
93 
95 {
99 
100  return true;
101 }
102 
103 
105 {
106  return true;
107 }
108 
109 
111 {
112  std::vector<GAL_LAYER_ID> galLayers;
113 
114  // Sort the gal layers by name
115  for( int i : m_validLayers )
116  {
117  if( i >= GAL_LAYER_ID_START && m_currentSettings->GetColor( i ) != COLOR4D::UNSPECIFIED )
118  galLayers.push_back( (GAL_LAYER_ID) i );
119  }
120 
121  std::sort( galLayers.begin(), galLayers.end(),
122  []( int a, int b )
123  {
124  return LayerName( a ) < LayerName( b );
125  } );
126 
127  BOARD* board = m_frame->GetBoard();
128 
129  createSwatch( F_Cu, board ? board->GetLayerName( F_Cu ) : LayerName( F_Cu ) );
130  createSwatch( In1_Cu, _( "Internal Layers" ) );
131  createSwatch( B_Cu, board ? board->GetLayerName( B_Cu ) : LayerName( B_Cu ) );
132 
133  for( GAL_LAYER_ID layer : galLayers )
134  createSwatch( layer, LayerName( layer ) );
135 }
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
SETTINGS_MANAGER * GetSettingsManager() const
to draw via holes (pad holes do not use this layer)
wxString GetFilename() const
Definition: json_settings.h:71
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
COLOR_SETTINGS * m_currentSettings
#define _(s)
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:27
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
COLOR4D GetColor(int aLayer) const
void ReloadColorSettings()
Re-scans the color themes directory, reloading any changes it finds.
Meta control for all vias opacity/visibility.
Board layer functions and definitions.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
Color settings are a bit different than most of the settings objects in that there can be more than o...
BOARD * GetBoard() const
void createSwatch(int aLayer, const wxString &aName)
PANEL_FP_EDITOR_COLOR_SETTINGS(FOOTPRINT_EDIT_FRAME *aFrame, wxWindow *aParent)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184