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 static const EDA_COLOR_T default_items_color[] = {
72  LIGHTGRAY, // unused
73  CYAN, // LAYER_VIA_MICROVIA
74  BROWN, // LAYER_VIA_BBLIND
75  LIGHTGRAY, // LAYER_VIA_THROUGH
76  YELLOW, // LAYER_NON_PLATED
77  LIGHTGRAY, // LAYER_MOD_TEXT_FR
78  BLUE, // LAYER_MOD_TEXT_BK
79  DARKGRAY, // LAYER_MOD_TEXT_INVISIBLE
80  BLUE, // LAYER_ANCHOR
81  RED, // LAYER_PAD_FR
82  GREEN, // LAYER_PAD_BK
83  LIGHTGRAY, // LAYER_RATSNEST
84  DARKGRAY, // LAYER_GRID
89  LIGHTGRAY, LIGHTGRAY, LIGHTGRAY
90 };
91 
92 
94 {
95  m_frameType = aFrameType;
96 
97  for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
98  {
100 
101  if( src >= DIM( default_layer_color ) )
102  src = 0; // wrap the source.
103  }
104 
105  for( unsigned src = 0, dst = LAYER_VIAS; dst < DIM( default_items_color ); ++dst )
106  {
107  m_LayersColors[dst] = COLOR4D( default_items_color[src++] );
108  }
109 
115 
117 }
118 
119 
121 {
122  if( (unsigned) aLayer < DIM( m_LayersColors ) )
123  {
124  return m_LayersColors[aLayer];
125  }
126  return COLOR4D::UNSPECIFIED;
127 }
128 
129 
131 {
132  if( (unsigned) aLayer < DIM( m_LayersColors ) )
133  {
134  m_LayersColors[aLayer] = aColor;
135  }
136 }
137 
138 
140 {
141  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
142  {
143  return m_LayersColors[aItemIdx];
144  }
145 
146  return COLOR4D::UNSPECIFIED;
147 }
148 
149 
150 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
151 {
152  if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
153  {
154  m_LayersColors[aItemIdx] = aColor;
155  }
156 }
157 
158 
160 {
161  for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
162  m_LayersColors[ii] = aColor;
163 }
164 
165 #define LOC_COLOR(layer) &m_LayersColors[layer]
166 #define ITEM_COLOR(item_visible) &m_LayersColors[item_visible]
167 
169 {
170  wxASSERT( DIM( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
171 
172  wxString currprefix = GetConfigPrefix();
173 
174  switch( m_frameType )
175  {
176  case FRAME_PCB: break; // no prefix
177 
179  SetConfigPrefix( "ModEdit" );
180  break;
181 
186  SetConfigPrefix( "fpview_" );
187  break;
188 
189  case FRAME_PCB_DISPLAY3D:
190  SetConfigPrefix( "fp3d_" );
191  break;
192 
193  default:
194  break;
195  }
196 
197 
198  wxString fmt( "Color4DPCBLayer_%s" );
199 
200  for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
201  {
202  wxString cfgkey = wxString::Format( fmt, LSET::Name( PCB_LAYER_ID( i ) ) );
203  Add( cfgkey, LOC_COLOR(i), m_LayersColors[i] );
204  }
205 
206  Add( "Color4DTxtFrontEx", ITEM_COLOR( LAYER_MOD_TEXT_FR ), LIGHTGRAY );
207  Add( "Color4DTxtBackEx", ITEM_COLOR( LAYER_MOD_TEXT_BK ), BLUE );
208  Add( "Color4DTxtInvisEx", ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ), DARKGRAY );
209  Add( "Color4DPadBackEx", ITEM_COLOR( LAYER_PAD_BK ), GREEN );
210  Add( "Color4DAnchorEx", ITEM_COLOR( LAYER_ANCHOR ), BLUE );
211  Add( "Color4DPadFrontEx", ITEM_COLOR( LAYER_PAD_FR ), RED );
212  Add( "Color4DNonPlatedEx", ITEM_COLOR( LAYER_NON_PLATED ), YELLOW );
213  Add( "Color4DPCBBackground", ITEM_COLOR( LAYER_PCB_BACKGROUND ), BLACK );
214  Add( "Color4DPCBCursor", ITEM_COLOR( LAYER_CURSOR ), WHITE );
215  Add( "Color4DAuxItems", ITEM_COLOR( LAYER_AUX_ITEMS ), WHITE );
216  Add( "Color4DWorksheet", ITEM_COLOR( LAYER_WORKSHEET ), DARKRED );
217  Add( "Color4DGrid", ITEM_COLOR( LAYER_GRID ), DARKGRAY );
218 
219 
220  // Add prms only relevant in board editor
221  if( m_frameType == FRAME_PCB )
222  {
223  Add( "Color4DViaThruEx", ITEM_COLOR( LAYER_VIA_THROUGH ), LIGHTGRAY );
224  Add( "Color4DViaBBlindEx", ITEM_COLOR( LAYER_VIA_BBLIND ), BROWN );
225  Add( "Color4DViaMicroEx", ITEM_COLOR( LAYER_VIA_MICROVIA ), CYAN );
226  Add( "Color4DRatsEx", ITEM_COLOR( LAYER_RATSNEST ), WHITE );
227  }
228 
229  SetConfigPrefix( currprefix );
230 }
231 
232 void COLORS_DESIGN_SETTINGS::Load( wxConfigBase *aConfig )
233 {
234  SETTINGS::Load(aConfig);
235 }
236 
237 void COLORS_DESIGN_SETTINGS::Save( wxConfigBase *aConfig )
238 {
239  SETTINGS::Save(aConfig);
240 }
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
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 which is one of the layer indices given in pcbstruct...
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