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 CHANGELOG.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 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[] = {
47 
52 
53  BLUE, MAGENTA,
54  LIGHTCYAN, RED,
55  MAGENTA, CYAN,
56  BROWN, MAGENTA,
57  LIGHTGRAY,
58  BLUE,
59  GREEN, YELLOW,
60  YELLOW,
62  YELLOW,
63  DARKGRAY
64 };
65 
66 
67 static const EDA_COLOR_T default_items_color[] = {
68  LIGHTGRAY, // unused
69  CYAN, // VIA_MICROVIA_VISIBLE
70  BROWN, // VIA_BBLIND_VISIBLE
71  LIGHTGRAY, // VIA_THROUGH_VISIBLE
72  YELLOW, // NON_PLATED_VISIBLE
73  LIGHTGRAY, // MOD_TEXT_FR_VISIBLE
74  BLUE, // MOD_TEXT_BK_VISIBLE
75  DARKGRAY, // MOD_TEXT_INVISIBLE
76  BLUE, // ANCHOR_VISIBLE
77  RED, // PAD_FR_VISIBLE
78  GREEN, // PAD_BK_VISIBLE
79  LIGHTGRAY, // RATSNEST_VISIBLE
80  DARKGRAY, // GRID_VISIBLE
85  LIGHTGRAY, LIGHTGRAY, LIGHTGRAY
86 };
87 
88 
90 {
91  for( unsigned src = 0, dst = 0; dst < DIM(m_LayersColors); ++dst )
92  {
94 
95  if( src >= DIM( default_layer_color ) )
96  src = 0; // wrap the source.
97  }
98 
99  for( unsigned src = 0, dst = 0; dst < DIM(m_ItemsColors); ++dst )
100  {
101  m_ItemsColors[dst] = COLOR4D( default_items_color[src++] );
102 
103  if( src >= DIM( default_items_color ) )
104  src = 0;
105  }
106 }
107 
108 
110 {
111  if( (unsigned) aLayer < DIM(m_LayersColors) )
112  {
113  return m_LayersColors[aLayer];
114  }
115  return COLOR4D::UNSPECIFIED;
116 }
117 
118 
120 {
121  if( (unsigned) aLayer < DIM(m_LayersColors) )
122  {
123  m_LayersColors[aLayer] = aColor;
124  }
125 }
126 
127 
129 {
130  if( (unsigned) aItemIdx < DIM( m_ItemsColors ) )
131  {
132  return m_ItemsColors[aItemIdx];
133  }
134 
135  return COLOR4D::UNSPECIFIED;
136 }
137 
138 
139 void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
140 {
141  if( (unsigned) aItemIdx < DIM(m_ItemsColors) )
142  {
143  m_ItemsColors[aItemIdx] = aColor;
144  }
145 }
146 
147 
149 {
150  for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
151  m_LayersColors[ii] = aColor;
152 
153  for( unsigned ii = 0; ii < DIM(m_ItemsColors); ii++ )
154  m_ItemsColors[ii] = aColor;
155 }
Definition: colors.h:57
#define DIM(x)
of elements in an array
Definition: macros.h:98
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 pcbstruct...
Definition: colors.h:61
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[]
This file contains miscellaneous commonly used macros and functions.
static const EDA_COLOR_T default_items_color[]
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
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...
Definition: colors.h:59
Definition: colors.h:60
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Definition: colors.h:58
COLOR4D m_ItemsColors[32]
All others items but layers.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
Definition: colors.h:68
Handle colors used to draw all items or layers.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62