KiCad PCB EDA Suite
class_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 
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
92  LIGHTGRAY, LIGHTGRAY, LIGHTGRAY
93 };
94 
95 
97 {
98  m_frameType = aFrameType;
99 
100  for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
101  {
102  m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
103 
104  if( src >= DIM( default_layer_color ) )
105  src = 0; // wrap the source.
106  }
107 
108  for( unsigned src = 0, dst = LAYER_VIAS; src < DIM( default_items_color ); ++dst, ++src )
109  {
111  }
112 
118 
120 }
121 
122 
124 {
125  if( (unsigned) aLayer < DIM( m_LayersColors ) )
126  {
127  return m_LayersColors[aLayer];
128  }
129  return COLOR4D::UNSPECIFIED;
130 }
131 
132 
134 {
135  if( (unsigned) aLayer < DIM( m_LayersColors ) )
136  {
137  m_LayersColors[aLayer] = aColor;
138  }
139 }
140 
141 
143 {
144  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
145  {
146  return m_LayersColors[aItemIdx];
147  }
148 
149  return COLOR4D::UNSPECIFIED;
150 }
151 
152 
153 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
154 {
155  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
156  {
157  m_LayersColors[aItemIdx] = aColor;
158  }
159 }
160 
161 
163 {
164  for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
165  m_LayersColors[ii] = aColor;
166 }
167 
168 #define LOC_COLOR(layer) &m_LayersColors[layer]
169 #define ITEM_COLOR(item_visible) &m_LayersColors[item_visible]
170 
172 {
173  wxASSERT( DIM( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
174 
175  wxString currprefix = GetConfigPrefix();
176 
177  switch( m_frameType )
178  {
179  case FRAME_PCB: break; // no prefix
180 
182  SetConfigPrefix( "ModEdit" );
183  break;
184 
189  SetConfigPrefix( "fpview_" );
190  break;
191 
192  case FRAME_PCB_DISPLAY3D:
193  SetConfigPrefix( "fp3d_" );
194  break;
195 
196  default:
197  break;
198  }
199 
200 
201  wxString fmt( "Color4DPCBLayer_%s" );
202 
203  for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
204  {
205  wxString cfgkey = wxString::Format( fmt, LSET::Name( PCB_LAYER_ID( i ) ) );
206  Add( cfgkey, LOC_COLOR(i), m_LayersColors[i] );
207  }
208 
209  Add( "Color4DTxtFrontEx", ITEM_COLOR( LAYER_MOD_TEXT_FR ), LIGHTGRAY );
210  Add( "Color4DTxtBackEx", ITEM_COLOR( LAYER_MOD_TEXT_BK ), BLUE );
211  Add( "Color4DTxtInvisEx", ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ), DARKGRAY );
212  Add( "Color4DPadBackEx", ITEM_COLOR( LAYER_PAD_BK ), GREEN );
213  Add( "Color4DAnchorEx", ITEM_COLOR( LAYER_ANCHOR ), BLUE );
214  Add( "Color4DPadFrontEx", ITEM_COLOR( LAYER_PAD_FR ), RED );
215  Add( "Color4DNonPlatedEx", ITEM_COLOR( LAYER_NON_PLATED ), YELLOW );
216  Add( "Color4DPCBBackground", ITEM_COLOR( LAYER_PCB_BACKGROUND ), BLACK );
217  Add( "Color4DPCBCursor", ITEM_COLOR( LAYER_CURSOR ), WHITE );
218  Add( "Color4DAuxItems", ITEM_COLOR( LAYER_AUX_ITEMS ), WHITE );
219  Add( "Color4DWorksheet", ITEM_COLOR( LAYER_WORKSHEET ), DARKRED );
220  Add( "Color4DGrid", ITEM_COLOR( LAYER_GRID ), DARKGRAY );
221 
222 
223  // Add prms only relevant in board editor
224  if( m_frameType == FRAME_PCB )
225  {
226  Add( "Color4DViaThruEx", ITEM_COLOR( LAYER_VIA_THROUGH ), LIGHTGRAY );
227  Add( "Color4DViaBBlindEx", ITEM_COLOR( LAYER_VIA_BBLIND ), BROWN );
228  Add( "Color4DViaMicroEx", ITEM_COLOR( LAYER_VIA_MICROVIA ), CYAN );
229  Add( "Color4DRatsEx", ITEM_COLOR( LAYER_RATSNEST ), WHITE );
230  Add( "Color4DNoNetPadMarker", ITEM_COLOR( LAYER_NO_CONNECTS ), BLUE );
231  }
232 
233  SetConfigPrefix( currprefix );
234 }
235 
236 void COLORS_DESIGN_SETTINGS::Load( wxConfigBase *aConfig )
237 {
238  SETTINGS::Load(aConfig);
239 }
240 
241 void COLORS_DESIGN_SETTINGS::Save( wxConfigBase *aConfig )
242 {
243  SETTINGS::Save(aConfig);
244 }
Definition: colors.h:57
#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...
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.
static const EDA_COLOR_T default_layer_color[]
smd pads, back layer
#define ITEM_COLOR(item_visible)
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
static const EDA_COLOR_T default_items_color[]
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
#define LOC_COLOR(layer)
PCB_LAYER_ID
A quick note on layer IDs:
Auxillary 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
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
handle color for not plated holes
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
Definition: colors.h:49
Definition: colors.h:45
Definition: colors.h:68
Handle colors used to draw all items or layers.
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
Definition: colors.h:62