KiCad PCB EDA Suite
panel_modedit_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 <class_board.h>
24 #include <footprint_edit_frame.h>
29 #include <pgm_base.h>
31 
32 
34  wxWindow* aParent )
35  : PANEL_COLOR_SETTINGS( aParent ),
36  m_frame( aFrame ),
37  m_page( nullptr ),
38  m_titleBlock( nullptr )
39 {
40  // Currently this only applies to eeschema
41  m_optOverrideColors->Hide();
42 
43  m_colorNamespace = "board";
44 
45  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
46 
48  COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
49 
50  // Store the current settings before reloading below
51  current->Store();
52  mgr.SaveColorSettings( current, "board" );
53 
54  m_optOverrideColors->SetValue( current->GetOverrideSchItemColors() );
55 
56  m_currentSettings = new COLOR_SETTINGS( *current );
57 
58  mgr.ReloadColorSettings();
59  createThemeList( settings->m_ColorTheme );
60 
61  m_validLayers.push_back( F_Cu );
62  m_validLayers.push_back( In1_Cu ); // "Internal Layers"
63  m_validLayers.push_back( B_Cu );
64 
65  for( int id = GAL_LAYER_ID_START; id < GAL_LAYER_ID_END; id++ )
66  {
67  if( id == LAYER_VIAS
68  || id == LAYER_GRID_AXES
69  || id == LAYER_PADS_PLATEDHOLES
70  || id == LAYER_VIAS_HOLES )
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 {
96  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
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...
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxString GetFilename() const
Definition: json_settings.h:64
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
Add new GAL layers here.
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
PANEL_MODEDIT_COLOR_SETTINGS(FOOTPRINT_EDIT_FRAME *aFrame, wxWindow *aParent)
void createThemeList(const wxString &aCurrent)
COLOR_SETTINGS * m_currentSettings
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 string equivalent of a given layer.
Definition: layer_id.cpp:24
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.
see class PGM_BASE
Meta control for all vias opacity/visibility.
Board layer functions and definitions.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
#define _(s)
Definition: 3d_actions.cpp:33
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)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:174