KiCad PCB EDA Suite
colors_design_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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <macros.h>
31 
32 #include <colors_design_settings.h>
33 
34 /* Class for handle list of color settings for designs
35  * in Eeschema, Pcbnew and GerbView
36  */
37 
38 /* Initial colors values: optimized for Pcbnew up to 64 layers.
39  * The table is not actually used by Eeschema.
40  * these values are superseded by config reading
41  */
42 static const EDA_COLOR_T default_layer_color[] = {
43  // Copper layers
48 
53 
54  // tech layers
55  BLUE, MAGENTA, // B_Adhes, F_Adhes
56  LIGHTCYAN, RED, // B_Paste, F_Paste
57  MAGENTA, CYAN, // B_SilkS, F_SilkS
58  BROWN, MAGENTA, // B_Mask, F_Mask
59 
60  // user layers
61  LIGHTGRAY, BLUE, GREEN, YELLOW, // Dwgs_User, Cmts_User, Eco1_User, Eco2_User
62 
63  // Special layers
64  YELLOW, // Edge_Cuts
65  LIGHTMAGENTA, // Margin
66  DARKGRAY, LIGHTGRAY, // B_CrtYd, F_CrtYd,
67  BLUE, DARKGRAY // B_Fab, F_Fab
68 };
69 
70 
71 // for color order, see enum GAL_LAYER_ID
72 static const EDA_COLOR_T default_items_color[] = {
73  LIGHTGRAY, // unused
74  CYAN, // LAYER_VIA_MICROVIA
75  BROWN, // LAYER_VIA_BBLIND
76  LIGHTGRAY, // LAYER_VIA_THROUGH
77  YELLOW, // LAYER_NON_PLATED
78  LIGHTGRAY, // LAYER_MOD_TEXT_FR
79  BLUE, // LAYER_MOD_TEXT_BK
80  DARKGRAY, // LAYER_MOD_TEXT_INVISIBLE
81  BLUE, // LAYER_ANCHOR
82  RED, // LAYER_PAD_FR
83  GREEN, // LAYER_PAD_BK
84  LIGHTGRAY, // LAYER_RATSNEST
85  DARKGRAY, // LAYER_GRID
86  LIGHTRED, // LAYER_GRID_AXES
87  BLUE, // LAYER_NO_CONNECTS
88  LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_FR, LAYER_MOD_BK
89  LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_VALUES, LAYER_MOD_REFERENCES
90  LIGHTGRAY, // LAYER_TRACKS
91  YELLOW, // LAYER_PADS
95 };
96 
97 
99 {
100  m_frameType = aFrameType;
101 
102  for( unsigned src = 0, dst = 0; dst < arrayDim( m_LayersColors ); ++dst )
103  {
104  m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
105 
106  if( src >= arrayDim( default_layer_color ) )
107  src = 0; // wrap the source.
108  }
109 
110  for( unsigned src = 0, dst = LAYER_VIAS; src < arrayDim( default_items_color ); ++dst, ++src )
111  {
113  }
114 
120 
122 }
123 
124 
126 {
127  if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
128  return m_LayersColors[aLayer];
129 
130  return COLOR4D::UNSPECIFIED;
131 }
132 
133 
135 {
136  if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
137  m_LayersColors[aLayer] = aColor;
138 }
139 
140 
142 {
143  if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
144  return m_LayersColors[aItemIdx];
145 
146  return COLOR4D::UNSPECIFIED;
147 }
148 
149 
150 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
151 {
152  if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
153  m_LayersColors[aItemIdx] = aColor;
154 }
155 
156 
158 {
159  for( unsigned ii = 0; ii < arrayDim(m_LayersColors); ii++ )
160  m_LayersColors[ii] = aColor;
161 }
162 
163 #define LOC_COLOR(layer) &m_LayersColors[layer]
164 #define ITEM_COLOR(item_visible) &m_LayersColors[item_visible]
165 
167 {
168  wxASSERT( arrayDim( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
169 
170  wxString currprefix = GetConfigPrefix();
171 
172  switch( m_frameType )
173  {
174  case FRAME_GERBER:
175  case FRAME_PCB: /* no prefix */ break;
176 
177  case FRAME_CVPCB_DISPLAY:
182  case FRAME_PCB_MODULE_EDITOR: SetConfigPrefix( "ModEdit" ); break;
183 
184  case FRAME_PCB_DISPLAY3D: SetConfigPrefix( "fp3d_" ); break;
185 
186  default: break;
187  }
188 
189  wxString fmt( "Color4DPCBLayer_%s" );
190 
191  for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
192  {
193  wxString cfgkey = wxString::Format( fmt, LSET::Name( PCB_LAYER_ID( i ) ) );
194  Add( cfgkey, LOC_COLOR(i), m_LayersColors[i] );
195  }
196 
197  Add( "Color4DTxtFrontEx", ITEM_COLOR( LAYER_MOD_TEXT_FR ), LIGHTGRAY );
198  Add( "Color4DTxtBackEx", ITEM_COLOR( LAYER_MOD_TEXT_BK ), BLUE );
199  Add( "Color4DTxtInvisEx", ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ), DARKGRAY );
200  Add( "Color4DPadBackEx", ITEM_COLOR( LAYER_PAD_BK ), GREEN );
201  Add( "Color4DAnchorEx", ITEM_COLOR( LAYER_ANCHOR ), BLUE );
202  Add( "Color4DPadFrontEx", ITEM_COLOR( LAYER_PAD_FR ), RED );
203  Add( "Color4DPadThruHoleEx", ITEM_COLOR( LAYER_PADS_TH ), YELLOW );
204  Add( "Color4DNonPlatedEx", ITEM_COLOR( LAYER_NON_PLATEDHOLES ), YELLOW );
205  Add( "Color4DPCBBackground", ITEM_COLOR( LAYER_PCB_BACKGROUND ), BLACK );
206  Add( "Color4DPCBCursor", ITEM_COLOR( LAYER_CURSOR ), WHITE );
207  Add( "Color4DAuxItems", ITEM_COLOR( LAYER_AUX_ITEMS ), WHITE );
208  Add( "Color4DWorksheet", ITEM_COLOR( LAYER_WORKSHEET ), DARKRED );
209  Add( "Color4DGrid", ITEM_COLOR( LAYER_GRID ), DARKGRAY );
210 
211 
212  // Add prms only relevant in board editor
213  if( m_frameType == FRAME_PCB )
214  {
215  Add( "Color4DViaThruEx", ITEM_COLOR( LAYER_VIA_THROUGH ), LIGHTGRAY );
216  Add( "Color4DViaBBlindEx", ITEM_COLOR( LAYER_VIA_BBLIND ), BROWN );
217  Add( "Color4DViaMicroEx", ITEM_COLOR( LAYER_VIA_MICROVIA ), CYAN );
218  Add( "Color4DRatsEx", ITEM_COLOR( LAYER_RATSNEST ), WHITE );
219  Add( "Color4DNoNetPadMarker", ITEM_COLOR( LAYER_NO_CONNECTS ), BLUE );
220  }
221 
222  SetConfigPrefix( currprefix );
223 }
224 
225 void COLORS_DESIGN_SETTINGS::Load( wxConfigBase *aConfig )
226 {
227  SETTINGS::Load(aConfig);
228 }
229 
230 void COLORS_DESIGN_SETTINGS::Save( wxConfigBase *aConfig )
231 {
232  SETTINGS::Save(aConfig);
233 }
Definition: colors.h:57
#define LOC_COLOR(layer)
to draw blind/buried vias
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
show a marker on pads with no nets
void SetItemColor(int aItemIdx, COLOR4D aColor)
Function SetItemColor sets the color for an item which is one of the item indices given in enum PCB_L...
multilayer pads, usually with holes
Handle colors used to draw all items or layers.
handle color for not plated holes (holes, not pads)
anchor of items having an anchor point (texts, footprints)
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
const wxString & GetConfigPrefix()
Definition: settings.h:57
Definition: colors.h:61
virtual void Save(wxConfigBase *aConfig)
Definition: settings.cpp:39
virtual void Load(wxConfigBase *aConfig)
Definition: settings.cpp:26
void SetLayerColor(LAYER_NUM aLayer, COLOR4D aColor)
Function SetLayerColor sets the color for aLayer.
Definition: colors.h:54
This file contains miscellaneous commonly used macros and functions.
virtual void Save(wxConfigBase *aConfig) override
void Add(const wxString &name, int *aPtr, int aDefaultValue)
Definition: settings.h:93
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
PCB_LAYER_ID
A quick note on layer IDs:
Auxiliary items (guides, rule, etc)
COLOR4D m_LayersColors[LAYER_ID_COUNT]
Layer colors (tracks and graphic items)
void SetAllColorsAs(COLOR4D aColor)
Function SetAllColorsAs sets alls colors to aColor Usefull to create a monochrome color selection for...
COLORS_DESIGN_SETTINGS(FRAME_T aFrameType)
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:73
static const EDA_COLOR_T default_items_color[]
to draw usual through hole vias
Definition: colors.h:59
Definition: colors.h:60
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
smd pads, front layer
Definition: colors.h:58
virtual void Load(wxConfigBase *aConfig) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define ITEM_COLOR(item_visible)
size_t i
Definition: json11.cpp:597
Definition: colors.h:49
Definition: colors.h:45
Definition: colors.h:68
void SetConfigPrefix(const wxString &aPrefix)
Set a prefix that will be prepent to the keywords when adding a setting in list.
Definition: settings.h:50
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
static const EDA_COLOR_T default_layer_color[]
Definition: colors.h:62