KiCad PCB EDA Suite
Loading...
Searching...
No Matches
layer_id.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <layer_ids.h>
21#include <magic_enum.hpp>
22#include <wx/translation.h>
23
31wxString LayerName( int aLayer )
32{
33 switch( aLayer )
34 {
35 // PCB_LAYER_ID
36 case UNDEFINED_LAYER: return _( "undefined" );
37
38 // Copper
39 case PCB_LAYER_ID::F_Cu: return wxT( "F.Cu" );
40 case PCB_LAYER_ID::B_Cu: return wxT( "B.Cu" );
41
42 // Technicals
43 case PCB_LAYER_ID::B_Adhes: return wxT( "B.Adhesive" );
44 case PCB_LAYER_ID::F_Adhes: return wxT( "F.Adhesive" );
45 case PCB_LAYER_ID::B_Paste: return wxT( "B.Paste" );
46 case PCB_LAYER_ID::F_Paste: return wxT( "F.Paste" );
47 case PCB_LAYER_ID::B_SilkS: return wxT( "B.Silkscreen" );
48 case PCB_LAYER_ID::F_SilkS: return wxT( "F.Silkscreen" );
49 case PCB_LAYER_ID::B_Mask: return wxT( "B.Mask" );
50 case PCB_LAYER_ID::F_Mask: return wxT( "F.Mask" );
51
52 // Users
53 case PCB_LAYER_ID::Dwgs_User: return wxT( "User.Drawings" );
54 case PCB_LAYER_ID::Cmts_User: return wxT( "User.Comments" );
55 case PCB_LAYER_ID::Eco1_User: return wxT( "User.Eco1" );
56 case PCB_LAYER_ID::Eco2_User: return wxT( "User.Eco2" );
57 case PCB_LAYER_ID::Edge_Cuts: return wxT( "Edge.Cuts" );
58 case PCB_LAYER_ID::Margin: return wxT( "Margin" );
59
60 // Footprint
61 case PCB_LAYER_ID::F_CrtYd: return wxT( "F.Courtyard" );
62 case PCB_LAYER_ID::B_CrtYd: return wxT( "B.Courtyard" );
63 case PCB_LAYER_ID::F_Fab: return wxT( "F.Fab" );
64 case PCB_LAYER_ID::B_Fab: return wxT( "B.Fab" );
65
66 // Rescue
67 case PCB_LAYER_ID::Rescue: return _( "Rescue" );
68
69 // SCH_LAYER_ID
70
71 case LAYER_WIRE: return _( "Wires" );
72 case LAYER_BUS: return _( "Buses" );
73 case LAYER_BUS_JUNCTION: return _( "Bus junctions" );
74 case LAYER_JUNCTION: return _( "Junctions" );
75 case LAYER_LOCLABEL: return _( "Labels" );
76 case LAYER_GLOBLABEL: return _( "Global labels" );
77 case LAYER_HIERLABEL: return _( "Hierarchical labels" );
78 case LAYER_PINNUM: return _( "Pin numbers" );
79 case LAYER_PINNAM: return _( "Pin names" );
80 case LAYER_REFERENCEPART: return _( "Symbol references" );
81 case LAYER_VALUEPART: return _( "Symbol values" );
82 case LAYER_FIELDS: return _( "Symbol fields" );
83 case LAYER_INTERSHEET_REFS: return _( "Sheet references" );
84 case LAYER_NETCLASS_REFS: return _( "Net class references" );
85 case LAYER_RULE_AREAS: return _( "Rule areas" );
86 case LAYER_DEVICE: return _( "Symbol body outlines" );
87 case LAYER_DEVICE_BACKGROUND: return _( "Symbol body fills" );
88 case LAYER_SHAPES_BACKGROUND: return _( "Shape fills" );
89 case LAYER_NOTES: return _( "Schematic text && graphics" );
90 case LAYER_PRIVATE_NOTES: return _( "Symbol private text && graphics" );
91 case LAYER_NOTES_BACKGROUND: return _( "Schematic text && graphics backgrounds" );
92 case LAYER_PIN: return _( "Pins" );
93 case LAYER_SHEET: return _( "Sheet borders" );
94 case LAYER_SHEET_BACKGROUND: return _( "Sheet backgrounds" );
95 case LAYER_SHEETNAME: return _( "Sheet names" );
96 case LAYER_SHEETFIELDS: return _( "Sheet fields" );
97 case LAYER_SHEETFILENAME: return _( "Sheet file names" );
98 case LAYER_SHEETLABEL: return _( "Sheet pins" );
99 case LAYER_NOCONNECT: return _( "No-connect symbols" );
100 case LAYER_DNP_MARKER: return _( "DNP markers" );
101 case LAYER_EXCLUDED_FROM_SIM: return _( "Excluded-from-simulation markers" );
102 case LAYER_ERC_WARN: return _( "ERC warnings" );
103 case LAYER_ERC_ERR: return _( "ERC errors" );
104 case LAYER_ERC_EXCLUSION: return _( "ERC exclusions" );
105 case LAYER_SCHEMATIC_ANCHOR: return _( "Anchors" );
106 case LAYER_SCHEMATIC_AUX_ITEMS: return _( "Helper items" );
107 case LAYER_SCHEMATIC_GRID: return _( "Grid" );
108 case LAYER_SCHEMATIC_GRID_AXES: return _( "Axes" );
109 case LAYER_SCHEMATIC_BACKGROUND: return _( "Background" );
110 case LAYER_SCHEMATIC_CURSOR: return _( "Cursor" );
111 case LAYER_HOVERED: return _( "Hovered items" );
112 case LAYER_BRIGHTENED: return _( "Highlighted items" );
113 case LAYER_HIDDEN: return _( "Hidden items" );
114 case LAYER_SELECTION_SHADOWS: return _( "Selection highlight" );
115 case LAYER_NET_COLOR_HIGHLIGHT: return _( "Net color highlight" );
116 case LAYER_SCHEMATIC_DRAWINGSHEET: return _( "Drawing sheet" );
117 case LAYER_SCHEMATIC_PAGE_LIMITS: return _( "Page limits" );
118 case LAYER_OP_VOLTAGES: return _( "Operating point voltages" );
119 case LAYER_OP_CURRENTS: return _( "Operating point currents" );
120
121 // GAL_LAYER_ID
122
123 case LAYER_FOOTPRINTS_FR: return _( "Footprints front" );
124 case LAYER_FOOTPRINTS_BK: return _( "Footprints back" );
125 case LAYER_FP_VALUES: return _( "Values" );
126 case LAYER_FP_REFERENCES: return _( "Reference designators" );
127 case LAYER_FP_TEXT: return _( "Footprint text" );
128 case LAYER_TRACKS: return _( "Tracks" );
129 case LAYER_VIA_THROUGH: return _( "Through vias" );
130 case LAYER_VIA_BBLIND: return _( "Blind/Buried vias" );
131 case LAYER_VIA_MICROVIA: return _( "Micro-vias" );
132 case LAYER_VIA_HOLES: return _( "Via holes" );
133 case LAYER_VIA_HOLEWALLS: return _( "Via hole walls" );
134 case LAYER_PAD_PLATEDHOLES: return _( "Plated holes" );
135 case LAYER_PAD_HOLEWALLS: return _( "Plated hole walls" );
136 case LAYER_NON_PLATEDHOLES: return _( "Non-plated holes" );
137 case LAYER_RATSNEST: return _( "Ratsnest" );
138 case LAYER_DRC_WARNING: return _( "DRC warnings" );
139 case LAYER_DRC_ERROR: return _( "DRC errors" );
140 case LAYER_DRC_SHAPE1: return _( "DRC shape 1" );
141 case LAYER_DRC_SHAPE2: return _( "DRC shape 2" );
142 case LAYER_DRC_EXCLUSION: return _( "DRC exclusions" );
143 case LAYER_MARKER_SHADOWS: return _( "DRC marker shadows" );
144 case LAYER_ANCHOR: return _( "Anchors" );
145 case LAYER_DRAWINGSHEET: return _( "Drawing sheet" );
146 case LAYER_PAGE_LIMITS: return _( "Page limits" );
147 case LAYER_CURSOR: return _( "Cursor" );
148 case LAYER_AUX_ITEMS: return _( "Helper items" );
149 case LAYER_GRID: return _( "Grid" );
150 case LAYER_GRID_AXES: return _( "Grid axes" );
151 case LAYER_PCB_BACKGROUND: return _( "Background" );
152 case LAYER_SELECT_OVERLAY: return _( "Selection highlight" );
153 case LAYER_LOCKED_ITEM_SHADOW: return _( "Locked item shadow" );
154 case LAYER_CONFLICTS_SHADOW: return _( "Courtyard collision shadow" );
155 case NETNAMES_LAYER_ID_START: return _( "Track net names" );
156 case LAYER_PAD_NETNAMES: return _( "Pad net names" );
157 case LAYER_VIA_NETNAMES: return _( "Via net names" );
158
159 default:
160 // Catch the general board layers that have numerically increasing names
161 if( aLayer > 0 && aLayer < PCB_LAYER_ID_COUNT && aLayer & 1 )
162 return wxString::Format( wxT( "User.%d" ), ( aLayer - PCB_LAYER_ID::User_1 ) / 2 + 1 );
163
164 return wxString::Format( wxT( "In%d.Cu" ), ( aLayer - PCB_LAYER_ID::In1_Cu ) / 2 + 1 );
165 }
166}
167
168
169PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
170{
171 switch( aLayerId )
172 {
173 case B_Cu: return F_Cu;
174 case F_Cu: return B_Cu;
175
176 case B_SilkS: return F_SilkS;
177 case F_SilkS: return B_SilkS;
178
179 case B_Adhes: return F_Adhes;
180 case F_Adhes: return B_Adhes;
181
182 case B_Mask: return F_Mask;
183 case F_Mask: return B_Mask;
184
185 case B_Paste: return F_Paste;
186 case F_Paste: return B_Paste;
187
188 case B_CrtYd: return F_CrtYd;
189 case F_CrtYd: return B_CrtYd;
190
191 case B_Fab: return F_Fab;
192 case F_Fab: return B_Fab;
193
194 default: // change internal layer if aCopperLayersCount is >= 4
195 if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
196 {
197 // internal copper layers count is aCopperLayersCount-2
198 PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
199 // Ensure fliplayer has a value which does not crash Pcbnew:
200 if( fliplayer < F_Cu )
201 fliplayer = F_Cu;
202
203 if( fliplayer > B_Cu )
204 fliplayer = B_Cu;
205
206 return fliplayer;
207 }
208
209 // No change for the other layers
210 return aLayerId;
211 }
212}
213
214
216{
217 switch( aLegacyId )
218 {
219 case 0: return F_Cu;
220 case 31: return B_Cu;
221
222 default:
223 if( aLegacyId < 0 )
224 return magic_enum::enum_cast<PCB_LAYER_ID>( aLegacyId ).value_or( UNDEFINED_LAYER );
225
226 if( aLegacyId < 31 )
227 return static_cast<PCB_LAYER_ID>( In1_Cu + ( aLegacyId - 1 ) * 2 );
228
229 switch( aLegacyId )
230 {
231 case 32: return B_Adhes;
232 case 33: return F_Adhes;
233 case 34: return B_Paste;
234 case 35: return F_Paste;
235 case 36: return B_SilkS;
236 case 37: return F_SilkS;
237 case 38: return B_Mask;
238 case 39: return F_Mask;
239 case 40: return Dwgs_User;
240 case 41: return Cmts_User;
241 case 42: return Eco1_User;
242 case 43: return Eco2_User;
243 case 44: return Edge_Cuts;
244 case 45: return Margin;
245 case 46: return B_CrtYd;
246 case 47: return F_CrtYd;
247 case 48: return B_Fab;
248 case 49: return F_Fab;
249 case 50: return User_1;
250 case 51: return User_2;
251 case 52: return User_3;
252 case 53: return User_4;
253 case 54: return User_5;
254 case 55: return User_6;
255 case 56: return User_7;
256 case 57: return User_8;
257 case 58: return User_9;
258 case 59: return Rescue;
259 default: return UNDEFINED_LAYER;
260 }
261 }
262}
#define _(s)
PCB_LAYER_ID BoardLayerFromLegacyId(int aLegacyId)
Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
Definition: layer_id.cpp:215
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: layer_id.cpp:169
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:31
@ LAYER_PAD_NETNAMES
Definition: layer_ids.h:201
@ NETNAMES_LAYER_ID_START
Definition: layer_ids.h:193
@ LAYER_VIA_NETNAMES
Definition: layer_ids.h:202
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:617
@ LAYER_GRID
Definition: layer_ids.h:252
@ LAYER_PAGE_LIMITS
Color for drawing the page extents (visibility stored in PCBNEW_SETTINGS::m_ShowPageLimits)
Definition: layer_ids.h:322
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition: layer_ids.h:305
@ LAYER_VIA_HOLEWALLS
Definition: layer_ids.h:296
@ LAYER_GRID_AXES
Definition: layer_ids.h:253
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
Definition: layer_ids.h:308
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition: layer_ids.h:257
@ LAYER_DRC_SHAPE1
Custom shape for DRC marker.
Definition: layer_ids.h:313
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition: layer_ids.h:237
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition: layer_ids.h:276
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition: layer_ids.h:264
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition: layer_ids.h:302
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:279
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition: layer_ids.h:299
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition: layer_ids.h:269
@ LAYER_TRACKS
Definition: layer_ids.h:265
@ LAYER_CURSOR
PCB cursor.
Definition: layer_ids.h:280
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
Definition: layer_ids.h:281
@ LAYER_RATSNEST
Definition: layer_ids.h:251
@ LAYER_DRC_SHAPE2
Custom shape for DRC marker.
Definition: layer_ids.h:314
@ LAYER_FP_TEXT
Definition: layer_ids.h:238
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition: layer_ids.h:258
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition: layer_ids.h:246
@ LAYER_MARKER_SHADOWS
Shadows for DRC markers.
Definition: layer_ids.h:303
@ LAYER_VIA_HOLES
Draw via holes (pad holes do not use this layer).
Definition: layer_ids.h:272
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition: layer_ids.h:261
@ LAYER_VIA_MICROVIA
Definition: layer_ids.h:232
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition: layer_ids.h:278
@ LAYER_VIA_THROUGH
Draw blind/buried vias.
Definition: layer_ids.h:234
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition: layer_ids.h:275
@ LAYER_VIA_BBLIND
Draw micro vias.
Definition: layer_ids.h:233
@ LAYER_PAD_HOLEWALLS
Definition: layer_ids.h:295
@ LAYER_SHAPES_BACKGROUND
Definition: layer_ids.h:471
@ LAYER_SHEETNAME
Definition: layer_ids.h:460
@ LAYER_ERC_WARN
Definition: layer_ids.h:467
@ LAYER_SCHEMATIC_ANCHOR
Definition: layer_ids.h:487
@ LAYER_SHEETLABEL
Definition: layer_ids.h:463
@ LAYER_PINNUM
Definition: layer_ids.h:446
@ LAYER_RULE_AREAS
Definition: layer_ids.h:453
@ LAYER_DEVICE
Definition: layer_ids.h:454
@ LAYER_SHEET_BACKGROUND
Definition: layer_ids.h:473
@ LAYER_EXCLUDED_FROM_SIM
Definition: layer_ids.h:470
@ LAYER_BRIGHTENED
Definition: layer_ids.h:479
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:469
@ LAYER_HIDDEN
Definition: layer_ids.h:480
@ LAYER_HIERLABEL
Definition: layer_ids.h:445
@ LAYER_PINNAM
Definition: layer_ids.h:447
@ LAYER_PRIVATE_NOTES
Definition: layer_ids.h:456
@ LAYER_HOVERED
Definition: layer_ids.h:478
@ LAYER_GLOBLABEL
Definition: layer_ids.h:444
@ LAYER_WIRE
Definition: layer_ids.h:440
@ LAYER_NOTES
Definition: layer_ids.h:455
@ LAYER_NET_COLOR_HIGHLIGHT
Definition: layer_ids.h:481
@ LAYER_ERC_ERR
Definition: layer_ids.h:468
@ LAYER_PIN
Definition: layer_ids.h:458
@ LAYER_VALUEPART
Definition: layer_ids.h:449
@ LAYER_BUS
Definition: layer_ids.h:441
@ LAYER_SCHEMATIC_CURSOR
Definition: layer_ids.h:477
@ LAYER_FIELDS
Definition: layer_ids.h:450
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:472
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:483
@ LAYER_LOCLABEL
Definition: layer_ids.h:443
@ LAYER_JUNCTION
Definition: layer_ids.h:442
@ LAYER_SHEETFIELDS
Definition: layer_ids.h:462
@ LAYER_SCHEMATIC_GRID_AXES
Definition: layer_ids.h:475
@ LAYER_REFERENCEPART
Definition: layer_ids.h:448
@ LAYER_NETCLASS_REFS
Definition: layer_ids.h:452
@ LAYER_NOTES_BACKGROUND
Definition: layer_ids.h:457
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:489
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:484
@ LAYER_SHEET
Definition: layer_ids.h:459
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:482
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:476
@ LAYER_SCHEMATIC_AUX_ITEMS
Definition: layer_ids.h:486
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:451
@ LAYER_OP_VOLTAGES
Definition: layer_ids.h:488
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:461
@ LAYER_BUS_JUNCTION
Definition: layer_ids.h:485
@ LAYER_DNP_MARKER
Definition: layer_ids.h:466
@ LAYER_NOCONNECT
Definition: layer_ids.h:464
@ LAYER_SCHEMATIC_GRID
Definition: layer_ids.h:474
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ User_8
Definition: layer_ids.h:131
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Adhes
Definition: layer_ids.h:103
@ Edge_Cuts
Definition: layer_ids.h:112
@ Dwgs_User
Definition: layer_ids.h:107
@ F_Paste
Definition: layer_ids.h:104
@ Cmts_User
Definition: layer_ids.h:108
@ User_6
Definition: layer_ids.h:129
@ User_7
Definition: layer_ids.h:130
@ F_Adhes
Definition: layer_ids.h:102
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ User_5
Definition: layer_ids.h:128
@ Eco1_User
Definition: layer_ids.h:109
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ User_9
Definition: layer_ids.h:132
@ F_Fab
Definition: layer_ids.h:119
@ Margin
Definition: layer_ids.h:113
@ F_SilkS
Definition: layer_ids.h:100
@ B_CrtYd
Definition: layer_ids.h:115
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ Eco2_User
Definition: layer_ids.h:110
@ In1_Cu
Definition: layer_ids.h:66
@ Rescue
Definition: layer_ids.h:121
@ User_3
Definition: layer_ids.h:126
@ User_1
Definition: layer_ids.h:124
@ B_SilkS
Definition: layer_ids.h:101
@ User_4
Definition: layer_ids.h:127
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:171
@ User_2
Definition: layer_ids.h:125
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:118