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
94  LIGHTGRAY, LIGHTGRAY, LIGHTGRAY
95 };
96 
97 
99 {
100  m_frameType = aFrameType;
101  m_legacyMode = false;
102 
103  for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
104  {
105  m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
106 
107  if( src >= DIM( default_layer_color ) )
108  src = 0; // wrap the source.
109  }
110 
111  for( unsigned src = 0, dst = LAYER_VIAS; src < DIM( default_items_color ); ++dst, ++src )
112  {
114  }
115 
121 
123 }
124 
125 
127 {
128  if( (unsigned) aLayer < DIM( m_LayersColors ) )
129  {
130  return m_legacyMode ? m_LayersColors[aLayer].AsLegacyColor()
131  : m_LayersColors[aLayer];
132  }
133  return COLOR4D::UNSPECIFIED;
134 }
135 
136 
138 {
139  if( (unsigned) aLayer < DIM( m_LayersColors ) )
140  {
141  m_LayersColors[aLayer] = aColor;
142  }
143 }
144 
145 
147 {
148  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
149  {
150  return m_legacyMode ? m_LayersColors[aItemIdx].AsLegacyColor()
151  : m_LayersColors[aItemIdx];
152  }
153 
154  return COLOR4D::UNSPECIFIED;
155 }
156 
157 
158 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
159 {
160  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
161  {
162  m_LayersColors[aItemIdx] = aColor;
163  }
164 }
165 
166 
168 {
169  for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
170  m_LayersColors[ii] = aColor;
171 }
172 
173 #define LOC_COLOR(layer) &m_LayersColors[layer]
174 #define ITEM_COLOR(item_visible) &m_LayersColors[item_visible]
175 
177 {
178  wxASSERT( DIM( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
179 
180  wxString currprefix = GetConfigPrefix();
181 
182  switch( m_frameType )
183  {
184  case FRAME_GERBER:
185  case FRAME_PCB: /* no prefix */ break;
186 
187  case FRAME_CVPCB_DISPLAY:
192  case FRAME_PCB_MODULE_EDITOR: SetConfigPrefix( "ModEdit" ); break;
193 
194  case FRAME_PCB_DISPLAY3D: SetConfigPrefix( "fp3d_" ); break;
195 
196  default: break;
197  }
198 
199  wxString fmt( "Color4DPCBLayer_%s" );
200 
201  for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
202  {
203  wxString cfgkey = wxString::Format( fmt, LSET::Name( PCB_LAYER_ID( i ) ) );
204  Add( cfgkey, LOC_COLOR(i), m_LayersColors[i] );
205  }
206 
207  Add( "Color4DTxtFrontEx", ITEM_COLOR( LAYER_MOD_TEXT_FR ), LIGHTGRAY );
208  Add( "Color4DTxtBackEx", ITEM_COLOR( LAYER_MOD_TEXT_BK ), BLUE );
209  Add( "Color4DTxtInvisEx", ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ), DARKGRAY );
210  Add( "Color4DPadBackEx", ITEM_COLOR( LAYER_PAD_BK ), GREEN );
211  Add( "Color4DAnchorEx", ITEM_COLOR( LAYER_ANCHOR ), BLUE );
212  Add( "Color4DPadFrontEx", ITEM_COLOR( LAYER_PAD_FR ), RED );
213  Add( "Color4DPadThruHoleEx", ITEM_COLOR( LAYER_PADS_TH ), YELLOW );
214  Add( "Color4DNonPlatedEx", ITEM_COLOR( LAYER_NON_PLATEDHOLES ), YELLOW );
215  Add( "Color4DPCBBackground", ITEM_COLOR( LAYER_PCB_BACKGROUND ), BLACK );
216  Add( "Color4DPCBCursor", ITEM_COLOR( LAYER_CURSOR ), WHITE );
217  Add( "Color4DAuxItems", ITEM_COLOR( LAYER_AUX_ITEMS ), WHITE );
218  Add( "Color4DWorksheet", ITEM_COLOR( LAYER_WORKSHEET ), DARKRED );
219  Add( "Color4DGrid", ITEM_COLOR( LAYER_GRID ), DARKGRAY );
220 
221 
222  // Add prms only relevant in board editor
223  if( m_frameType == FRAME_PCB )
224  {
225  Add( "Color4DViaThruEx", ITEM_COLOR( LAYER_VIA_THROUGH ), LIGHTGRAY );
226  Add( "Color4DViaBBlindEx", ITEM_COLOR( LAYER_VIA_BBLIND ), BROWN );
227  Add( "Color4DViaMicroEx", ITEM_COLOR( LAYER_VIA_MICROVIA ), CYAN );
228  Add( "Color4DRatsEx", ITEM_COLOR( LAYER_RATSNEST ), WHITE );
229  Add( "Color4DNoNetPadMarker", ITEM_COLOR( LAYER_NO_CONNECTS ), BLUE );
230  }
231 
232  SetConfigPrefix( currprefix );
233 }
234 
235 void COLORS_DESIGN_SETTINGS::Load( wxConfigBase *aConfig )
236 {
237  SETTINGS::Load(aConfig);
238 }
239 
240 void COLORS_DESIGN_SETTINGS::Save( wxConfigBase *aConfig )
241 {
242  SETTINGS::Save(aConfig);
243 }
Definition: colors.h:57
#define LOC_COLOR(layer)
#define DIM(x)
of elements in an array
Definition: macros.h:98
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.
smd pads, back layer
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.
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.
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
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
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