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  for( int id = F_Cu; id < PCB_LAYER_ID_COUNT; id++ )
62  m_validLayers.push_back( id );
63 
64  for( int id = GAL_LAYER_ID_START; id < GAL_LAYER_ID_END; id++ )
65  {
66  if( id == LAYER_VIAS || id == LAYER_GRID_AXES || id == LAYER_PADS_PLATEDHOLES
67  || id == LAYER_VIAS_HOLES )
68  {
69  continue;
70  }
71 
72  m_validLayers.push_back( id );
73  }
74 
76 
77  m_colorsMainSizer->Insert( 0, 10, 0, 0, wxEXPAND, 5 );
78 
80 }
81 
82 
84 {
85  delete m_page;
86  delete m_titleBlock;
87 }
88 
89 
91 {
93 
94  if( !saveCurrentTheme( true ) )
95  return false;
96 
98 
99  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
102 
104 
105  return true;
106 }
107 
108 
110 {
111  return true;
112 }
113 
114 
116 {
117  std::vector<int> layers;
118 
120  {
121  if( m_currentSettings->GetColor( i ) != COLOR4D::UNSPECIFIED )
122  layers.push_back( i );
123  }
124 
125  std::sort( layers.begin(), layers.end(),
126  []( int a, int b )
127  {
128  return LayerName( a ) < LayerName( b );
129  } );
130 
131  // Don't sort board layers by name
132  for( int i = PCBNEW_LAYER_ID_START; i < PCB_LAYER_ID_COUNT; ++i )
133  layers.insert( layers.begin() + i, i );
134 
135  BOARD* board = m_frame->GetBoard();
136 
137  for( int layer : layers )
138  {
139  wxString name = LayerName( layer );
140 
141  if( board && layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
142  name = board->GetLayerName( static_cast<PCB_LAYER_ID>( layer ) );
143 
144  createSwatch( layer, name );
145  }
146 }
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
virtual bool saveCurrentTheme(bool aValidate)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
Add new GAL layers here.
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
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
void SetOverrideSchItemColors(bool aFlag)
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
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
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.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
COLOR4D GetColor(int aLayer) const
void ReloadColorSettings()
Re-scans the color themes directory, reloading any changes it finds.
see class PGM_BASE
Board layer functions and definitions.
const char * name
Definition: DXF_plotter.cpp:60
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
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...
std::string GetFilename() const
Definition: json_settings.h:56
BOARD * GetBoard() const
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
void createSwatch(int aLayer, const wxString &aName)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:156