KiCad PCB EDA Suite
panel_pcbnew_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>
27 #include <pcbnew_settings.h>
28 #include <pcb_edit_frame.h>
29 #include <pcb_layer_widget.h>
30 #include <pgm_base.h>
32 
33 
35  wxWindow* aParent )
36  : PANEL_COLOR_SETTINGS( aParent ),
37  m_frame( aFrame ),
38  m_page( nullptr ),
39  m_titleBlock( nullptr ),
40  m_ws( nullptr )
41 {
42  // Currently this only applies to eeschema
43  m_optOverrideColors->Hide();
44 
45  m_colorNamespace = "board";
46 
47  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
48 
49  PCBNEW_SETTINGS* app_settings = mgr.GetAppSettings<PCBNEW_SETTINGS>();
50  COLOR_SETTINGS* current = mgr.GetColorSettings( app_settings->m_ColorTheme );
51 
52  // Store the current settings before reloading below
53  current->Store();
54  mgr.SaveColorSettings( current, "board" );
55 
56  m_optOverrideColors->SetValue( current->GetOverrideSchItemColors() );
57 
58  m_currentSettings = new COLOR_SETTINGS( *current );
59 
60  mgr.ReloadColorSettings();
61  createThemeList( app_settings->m_ColorTheme );
62 
63  for( int id = GAL_LAYER_ID_START; id < GAL_LAYER_ID_BITMASK_END; id++ )
64  {
65  if( id == LAYER_VIAS || id == LAYER_GRID_AXES || id == LAYER_PADS_PLATEDHOLES
66  || id == LAYER_VIAS_HOLES || id == LAYER_DRAW_BITMAPS
67  || id == LAYER_GP_OVERLAY )
68  {
69  continue;
70  }
71 
72  m_validLayers.push_back( id );
73  }
74 
75  // NOTE: Main board layers are added by createSwatches()
76 
78 
79  m_colorsMainSizer->Insert( 0, 10, 0, 0, wxEXPAND, 5 );
80 
82 }
83 
84 
86 {
87  delete m_page;
88  delete m_titleBlock;
89 }
90 
91 
93 {
95 
96  if( !saveCurrentTheme( true ) )
97  return false;
98 
100 
101  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
102  PCBNEW_SETTINGS* app_settings = settingsMgr.GetAppSettings<PCBNEW_SETTINGS>();
103  app_settings->m_ColorTheme = m_currentSettings->GetFilename();
104 
106 
107  return true;
108 }
109 
110 
112 {
113  return true;
114 }
115 
116 
118 {
119  std::vector<int> layers( m_validLayers );
120 
121  std::sort( layers.begin(), layers.end(),
122  []( int a, int b )
123  {
124  return LayerName( a ) < LayerName( b );
125  } );
126 
127  // Don't sort board layers by name
128  for( int i = PCBNEW_LAYER_ID_START; i < PCB_LAYER_ID_COUNT; ++i )
129  layers.insert( layers.begin() + i, i );
130 
131  BOARD* board = m_frame->GetBoard();
132 
133  for( int layer : layers )
134  {
135  wxString name = LayerName( layer );
136 
137  if( board && layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
138  name = board->GetLayerName( static_cast<PCB_LAYER_ID>( layer ) );
139 
140  createSwatch( layer, name );
141  }
142 
143  // Give a minimal width to m_colorsListWindow, in order to always having
144  // a full row shown
145  int min_width = m_colorsGridSizer->GetMinSize().x;
146  const int margin = 20; // A margin around the sizer
147  m_colorsListWindow->SetMinSize( wxSize( min_width + margin, -1 ) );
148 }
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.
to handle and draw images bitmaps
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
to draw via holes (pad holes do not use this layer)
This is the end of the layers used for visibility bitmasks in Pcbnew There can be at most 32 layers a...
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
PANEL_PCBNEW_COLOR_SETTINGS(PCB_EDIT_FRAME *aFrame, wxWindow *aParent)
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
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
PCB_LAYER_WIDGET * GetLayerManager()
void SyncLayerColors()
Updates the color for each layer and item from the active color theme.
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.
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
PCB_EDIT_FRAME is the main frame for Pcbnew.
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