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 (LAYER_VIAS = GAL_LAYER_ID_START)
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, LIGHTGRAY, // LAYER_PADS, LAYER_PADS_PLATEDHOLES
92  LIGHTGRAY, // LAYER_VIAS_HOLES
93  LIGHTGRAY, // LAYER_DRC
94  DARKRED, // LAYER_WORKSHEET
95  LIGHTGRAY, // LAYER_GP_OVERLAY
96  LIGHTGRAY, // LAYER_SELECT_OVERLAY
97  BLACK, // LAYER_PCB_BACKGROUND
98  WHITE, // LAYER_CURSOR
99  WHITE, // LAYER_AUX_ITEMS
100  LIGHTGRAY, // LAYER_DRAW_BITMAPS
101  LIGHTGRAY // unused (GAL_LAYER_ID_BITMASK_END)
102 };
103 
104 
106 {
107  m_frameType = aFrameType;
108 
109  for( unsigned src = 0, dst = 0; dst < arrayDim( m_LayersColors ); ++dst )
110  {
111  m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
112 
113  if( src >= arrayDim( default_layer_color ) )
114  src = 0; // wrap the source.
115  }
116 
117  for( unsigned src = 0, dst = LAYER_VIAS; src < arrayDim( default_items_color ); ++dst, ++src )
118  {
120  }
121 
123 }
124 
125 
127 {
128  if( (unsigned) aLayer < arrayDim( default_layer_color ) )
129  return COLOR4D( default_layer_color[aLayer] );
130 
131  return COLOR4D::UNSPECIFIED;
132 }
133 
134 
136 {
137  if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
138  return m_LayersColors[aLayer];
139 
140  return COLOR4D::UNSPECIFIED;
141 }
142 
143 
145 {
146  if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
147  m_LayersColors[aLayer] = aColor;
148 }
149 
150 
152 {
153  unsigned int idx = (unsigned) aItemIdx - LAYER_VIAS;
154  if( idx < arrayDim( default_items_color ) )
155  return COLOR4D( default_items_color[idx] );
156 
157  return COLOR4D::UNSPECIFIED;
158 }
159 
160 
162 {
163  if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
164  return m_LayersColors[aItemIdx];
165 
166  return COLOR4D::UNSPECIFIED;
167 }
168 
169 
170 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
171 {
172  if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
173  m_LayersColors[aItemIdx] = aColor;
174 }
175 
176 
178 {
179  for( unsigned ii = 0; ii < arrayDim(m_LayersColors); ii++ )
180  m_LayersColors[ii] = aColor;
181 }
182 
183 #define LOC_COLOR(layer) &m_LayersColors[layer]
184 #define ITEM_COLOR(item_visible) &m_LayersColors[item_visible]
185 
187 {
188  wxASSERT( arrayDim( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
189 
190  wxString currprefix = GetConfigPrefix();
191 
192  switch( m_frameType )
193  {
194  case FRAME_GERBER:
195  case FRAME_PCB_EDITOR: /* no prefix */ break;
196 
197  case FRAME_CVPCB_DISPLAY:
202  case FRAME_FOOTPRINT_EDITOR: SetConfigPrefix( "ModEdit" ); break;
203 
204  case FRAME_PCB_DISPLAY3D: SetConfigPrefix( "fp3d_" ); break;
205 
206  default: break;
207  }
208 
209  wxString fmt( "Color4DPCBLayer_%s" );
210 
211  for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
212  {
213  wxString cfgkey = wxString::Format( fmt, LSET::Name( PCB_LAYER_ID( i ) ) );
214  Add( cfgkey, LOC_COLOR(i), m_LayersColors[i] );
215  }
216 
217  Add( "Color4DTxtFrontEx", ITEM_COLOR( LAYER_MOD_TEXT_FR ), LIGHTGRAY );
218  Add( "Color4DTxtBackEx", ITEM_COLOR( LAYER_MOD_TEXT_BK ), BLUE );
219  Add( "Color4DTxtInvisEx", ITEM_COLOR( LAYER_MOD_TEXT_INVISIBLE ), DARKGRAY );
220  Add( "Color4DPadBackEx", ITEM_COLOR( LAYER_PAD_BK ), GREEN );
221  Add( "Color4DAnchorEx", ITEM_COLOR( LAYER_ANCHOR ), BLUE );
222  Add( "Color4DPadFrontEx", ITEM_COLOR( LAYER_PAD_FR ), RED );
223  Add( "Color4DPadThruHoleEx", ITEM_COLOR( LAYER_PADS_TH ), YELLOW );
224  Add( "Color4DNonPlatedEx", ITEM_COLOR( LAYER_NON_PLATEDHOLES ), YELLOW );
225  Add( "Color4DPCBBackground", ITEM_COLOR( LAYER_PCB_BACKGROUND ), BLACK );
226  Add( "Color4DPCBCursor", ITEM_COLOR( LAYER_CURSOR ), WHITE );
227  Add( "Color4DAuxItems", ITEM_COLOR( LAYER_AUX_ITEMS ), WHITE );
228  Add( "Color4DWorksheet", ITEM_COLOR( LAYER_WORKSHEET ), DARKRED );
229  Add( "Color4DGrid", ITEM_COLOR( LAYER_GRID ), DARKGRAY );
230 
231 
232  // Add prms only relevant in board editor
234  {
235  Add( "Color4DViaThruEx", ITEM_COLOR( LAYER_VIA_THROUGH ), LIGHTGRAY );
236  Add( "Color4DViaBBlindEx", ITEM_COLOR( LAYER_VIA_BBLIND ), BROWN );
237  Add( "Color4DViaMicroEx", ITEM_COLOR( LAYER_VIA_MICROVIA ), CYAN );
238  Add( "Color4DRatsEx", ITEM_COLOR( LAYER_RATSNEST ), WHITE );
239  Add( "Color4DNoNetPadMarker", ITEM_COLOR( LAYER_NO_CONNECTS ), BLUE );
240  }
241 
242  SetConfigPrefix( currprefix );
243 }
244 
245 void COLORS_DESIGN_SETTINGS::Load( wxConfigBase *aConfig )
246 {
247  SETTINGS::Load(aConfig);
248 }
249 
250 void COLORS_DESIGN_SETTINGS::Save( wxConfigBase *aConfig )
251 {
252  SETTINGS::Save(aConfig);
253 }
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 GAL_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 which is one of the item indices given in enum PCB_L...
static COLOR4D GetDefaultLayerColor(LAYER_NUM aLayer)
Function GetDefaultLayerColor.
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:649
Definition: colors.h:49
static COLOR4D GetDefaultItemColor(int aItemIdx)
Function GetDefaultItemColor.
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