You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
18 KiB

  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. #include <layer_ids.h>
  20. #include <magic_enum.hpp>
  21. #include <wx/translation.h>
  22. /**
  23. * Returns the default display name for a given layer. These are not the same as the canonical
  24. * name in LSET::Name(), which is used in board files and cannot be translated or changed.
  25. * WARNING: do not translate board physical layers names (F.Cu to User.9): because canonical names
  26. * are used in files (boards and fab files), using translated names in UI create mistakes for users.
  27. * Board physical layers names must be seen as proper nouns.
  28. */
  29. wxString LayerName( int aLayer )
  30. {
  31. switch( aLayer )
  32. {
  33. // PCB_LAYER_ID
  34. case UNDEFINED_LAYER: return _( "undefined" );
  35. // Copper
  36. case PCB_LAYER_ID::F_Cu: return wxT( "F.Cu" );
  37. case PCB_LAYER_ID::B_Cu: return wxT( "B.Cu" );
  38. // Technicals
  39. case PCB_LAYER_ID::B_Adhes: return wxT( "B.Adhesive" );
  40. case PCB_LAYER_ID::F_Adhes: return wxT( "F.Adhesive" );
  41. case PCB_LAYER_ID::B_Paste: return wxT( "B.Paste" );
  42. case PCB_LAYER_ID::F_Paste: return wxT( "F.Paste" );
  43. case PCB_LAYER_ID::B_SilkS: return wxT( "B.Silkscreen" );
  44. case PCB_LAYER_ID::F_SilkS: return wxT( "F.Silkscreen" );
  45. case PCB_LAYER_ID::B_Mask: return wxT( "B.Mask" );
  46. case PCB_LAYER_ID::F_Mask: return wxT( "F.Mask" );
  47. // Users
  48. case PCB_LAYER_ID::Dwgs_User: return wxT( "User.Drawings" );
  49. case PCB_LAYER_ID::Cmts_User: return wxT( "User.Comments" );
  50. case PCB_LAYER_ID::Eco1_User: return wxT( "User.Eco1" );
  51. case PCB_LAYER_ID::Eco2_User: return wxT( "User.Eco2" );
  52. case PCB_LAYER_ID::Edge_Cuts: return wxT( "Edge.Cuts" );
  53. case PCB_LAYER_ID::Margin: return wxT( "Margin" );
  54. // Footprint
  55. case PCB_LAYER_ID::F_CrtYd: return wxT( "F.Courtyard" );
  56. case PCB_LAYER_ID::B_CrtYd: return wxT( "B.Courtyard" );
  57. case PCB_LAYER_ID::F_Fab: return wxT( "F.Fab" );
  58. case PCB_LAYER_ID::B_Fab: return wxT( "B.Fab" );
  59. // Rescue
  60. case PCB_LAYER_ID::Rescue: return _( "Rescue" );
  61. // SCH_LAYER_ID
  62. case LAYER_WIRE: return _( "Wires" );
  63. case LAYER_BUS: return _( "Buses" );
  64. case LAYER_BUS_JUNCTION: return _( "Bus junctions" );
  65. case LAYER_JUNCTION: return _( "Junctions" );
  66. case LAYER_LOCLABEL: return _( "Labels" );
  67. case LAYER_GLOBLABEL: return _( "Global labels" );
  68. case LAYER_HIERLABEL: return _( "Hierarchical labels" );
  69. case LAYER_PINNUM: return _( "Pin numbers" );
  70. case LAYER_PINNAM: return _( "Pin names" );
  71. case LAYER_REFERENCEPART: return _( "Symbol references" );
  72. case LAYER_VALUEPART: return _( "Symbol values" );
  73. case LAYER_FIELDS: return _( "Symbol fields" );
  74. case LAYER_INTERSHEET_REFS: return _( "Sheet references" );
  75. case LAYER_NETCLASS_REFS: return _( "Net class references" );
  76. case LAYER_RULE_AREAS: return _( "Rule areas" );
  77. case LAYER_DEVICE: return _( "Symbol body outlines" );
  78. case LAYER_DEVICE_BACKGROUND: return _( "Symbol body fills" );
  79. case LAYER_SHAPES_BACKGROUND: return _( "Shape fills" );
  80. case LAYER_NOTES: return _( "Schematic text && graphics" );
  81. case LAYER_PRIVATE_NOTES: return _( "Symbol private text && graphics" );
  82. case LAYER_NOTES_BACKGROUND: return _( "Schematic text && graphics backgrounds" );
  83. case LAYER_PIN: return _( "Pins" );
  84. case LAYER_SHEET: return _( "Sheet borders" );
  85. case LAYER_SHEET_BACKGROUND: return _( "Sheet backgrounds" );
  86. case LAYER_SHEETNAME: return _( "Sheet names" );
  87. case LAYER_SHEETFIELDS: return _( "Sheet fields" );
  88. case LAYER_SHEETFILENAME: return _( "Sheet file names" );
  89. case LAYER_SHEETLABEL: return _( "Sheet pins" );
  90. case LAYER_NOCONNECT: return _( "No-connect symbols" );
  91. case LAYER_DNP_MARKER: return _( "DNP markers" );
  92. case LAYER_EXCLUDED_FROM_SIM: return _( "Excluded-from-simulation markers" );
  93. case LAYER_ERC_WARN: return _( "ERC warnings" );
  94. case LAYER_ERC_ERR: return _( "ERC errors" );
  95. case LAYER_ERC_EXCLUSION: return _( "ERC exclusions" );
  96. case LAYER_SCHEMATIC_ANCHOR: return _( "Anchors" );
  97. case LAYER_SCHEMATIC_AUX_ITEMS: return _( "Helper items" );
  98. case LAYER_SCHEMATIC_GRID: return _( "Grid" );
  99. case LAYER_SCHEMATIC_GRID_AXES: return _( "Axes" );
  100. case LAYER_SCHEMATIC_BACKGROUND: return _( "Background" );
  101. case LAYER_SCHEMATIC_CURSOR: return _( "Cursor" );
  102. case LAYER_HOVERED: return _( "Hovered items" );
  103. case LAYER_BRIGHTENED: return _( "Highlighted items" );
  104. case LAYER_HIDDEN: return _( "Hidden items" );
  105. case LAYER_SELECTION_SHADOWS: return _( "Selection highlight" );
  106. case LAYER_NET_COLOR_HIGHLIGHT: return _( "Net color highlight" );
  107. case LAYER_SCHEMATIC_DRAWINGSHEET: return _( "Drawing sheet" );
  108. case LAYER_SCHEMATIC_PAGE_LIMITS: return _( "Page limits" );
  109. case LAYER_OP_VOLTAGES: return _( "Operating point voltages" );
  110. case LAYER_OP_CURRENTS: return _( "Operating point currents" );
  111. // GAL_LAYER_ID
  112. case LAYER_FOOTPRINTS_FR: return _( "Footprints front" );
  113. case LAYER_FOOTPRINTS_BK: return _( "Footprints back" );
  114. case LAYER_FP_VALUES: return _( "Values" );
  115. case LAYER_FP_REFERENCES: return _( "Reference designators" );
  116. case LAYER_FP_TEXT: return _( "Footprint text" );
  117. case LAYER_TRACKS: return _( "Tracks" );
  118. case LAYER_VIA_THROUGH: return _( "Through vias" );
  119. case LAYER_VIA_BLIND: return _( "Blind vias" );
  120. case LAYER_VIA_BURIED: return _( "Buried vias" );
  121. case LAYER_VIA_MICROVIA: return _( "Micro-vias" );
  122. case LAYER_VIA_HOLES: return _( "Via holes" );
  123. case LAYER_VIA_HOLEWALLS: return _( "Via hole walls" );
  124. case LAYER_PAD_PLATEDHOLES: return _( "Plated holes" );
  125. case LAYER_PAD_HOLEWALLS: return _( "Plated hole walls" );
  126. case LAYER_NON_PLATEDHOLES: return _( "Non-plated holes" );
  127. case LAYER_RATSNEST: return _( "Ratsnest" );
  128. case LAYER_DRC_WARNING: return _( "DRC warnings" );
  129. case LAYER_DRC_ERROR: return _( "DRC errors" );
  130. case LAYER_DRC_SHAPES: return _( "DRC shapes" );
  131. case LAYER_DRC_EXCLUSION: return _( "DRC exclusions" );
  132. case LAYER_MARKER_SHADOWS: return _( "DRC marker shadows" );
  133. case LAYER_ANCHOR: return _( "Anchors" );
  134. case LAYER_POINTS: return _( "Points" );
  135. case LAYER_DRAWINGSHEET: return _( "Drawing sheet" );
  136. case LAYER_PAGE_LIMITS: return _( "Page limits" );
  137. case LAYER_CURSOR: return _( "Cursor" );
  138. case LAYER_AUX_ITEMS: return _( "Helper items" );
  139. case LAYER_GRID: return _( "Grid" );
  140. case LAYER_GRID_AXES: return _( "Grid axes" );
  141. case LAYER_PCB_BACKGROUND: return _( "Background" );
  142. case LAYER_SELECT_OVERLAY: return _( "Selection highlight" );
  143. case LAYER_LOCKED_ITEM_SHADOW: return _( "Locked item shadow" );
  144. case LAYER_CONFLICTS_SHADOW: return _( "Courtyard collision shadow" );
  145. case LAYER_BOARD_OUTLINE_AREA: return _( "Board outline area" );
  146. case NETNAMES_LAYER_ID_START: return _( "Track net names" );
  147. case LAYER_PAD_NETNAMES: return _( "Pad net names" );
  148. case LAYER_VIA_NETNAMES: return _( "Via net names" );
  149. default:
  150. // Catch the general board layers that have numerically increasing names
  151. if( aLayer > 0 && aLayer < PCB_LAYER_ID_COUNT && aLayer & 1 )
  152. return wxString::Format( wxT( "User.%d" ), ( aLayer - PCB_LAYER_ID::User_1 ) / 2 + 1 );
  153. return wxString::Format( wxT( "In%d.Cu" ), ( aLayer - PCB_LAYER_ID::In1_Cu ) / 2 + 1 );
  154. }
  155. }
  156. PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
  157. {
  158. switch( aLayerId )
  159. {
  160. case B_Cu: return F_Cu;
  161. case F_Cu: return B_Cu;
  162. case B_SilkS: return F_SilkS;
  163. case F_SilkS: return B_SilkS;
  164. case B_Adhes: return F_Adhes;
  165. case F_Adhes: return B_Adhes;
  166. case B_Mask: return F_Mask;
  167. case F_Mask: return B_Mask;
  168. case B_Paste: return F_Paste;
  169. case F_Paste: return B_Paste;
  170. case B_CrtYd: return F_CrtYd;
  171. case F_CrtYd: return B_CrtYd;
  172. case B_Fab: return F_Fab;
  173. case F_Fab: return B_Fab;
  174. default: // change internal layer if aCopperLayersCount is >= 4
  175. if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
  176. {
  177. // internal copper layers count is aCopperLayersCount-2
  178. PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
  179. // Ensure fliplayer has a value which does not crash Pcbnew:
  180. if( fliplayer < F_Cu )
  181. fliplayer = F_Cu;
  182. if( fliplayer > B_Cu )
  183. fliplayer = B_Cu;
  184. return fliplayer;
  185. }
  186. // No change for the other layers
  187. return aLayerId;
  188. }
  189. }
  190. PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId )
  191. {
  192. switch( aLegacyId )
  193. {
  194. case 0: return F_Cu;
  195. case 31: return B_Cu;
  196. default:
  197. if( aLegacyId < 0 )
  198. return magic_enum::enum_cast<PCB_LAYER_ID>( aLegacyId ).value_or( UNDEFINED_LAYER );
  199. if( aLegacyId < 31 )
  200. return static_cast<PCB_LAYER_ID>( In1_Cu + ( aLegacyId - 1 ) * 2 );
  201. switch( aLegacyId )
  202. {
  203. case 32: return B_Adhes;
  204. case 33: return F_Adhes;
  205. case 34: return B_Paste;
  206. case 35: return F_Paste;
  207. case 36: return B_SilkS;
  208. case 37: return F_SilkS;
  209. case 38: return B_Mask;
  210. case 39: return F_Mask;
  211. case 40: return Dwgs_User;
  212. case 41: return Cmts_User;
  213. case 42: return Eco1_User;
  214. case 43: return Eco2_User;
  215. case 44: return Edge_Cuts;
  216. case 45: return Margin;
  217. case 46: return B_CrtYd;
  218. case 47: return F_CrtYd;
  219. case 48: return B_Fab;
  220. case 49: return F_Fab;
  221. case 50: return User_1;
  222. case 51: return User_2;
  223. case 52: return User_3;
  224. case 53: return User_4;
  225. case 54: return User_5;
  226. case 55: return User_6;
  227. case 56: return User_7;
  228. case 57: return User_8;
  229. case 58: return User_9;
  230. case 59: return Rescue;
  231. default: return UNDEFINED_LAYER;
  232. }
  233. }
  234. }
  235. PCB_LAYER_ID Map3DLayerToPCBLayer( int aLayer )
  236. {
  237. // NOTE: User_1..User45 are NOT consecutive numbers!
  238. switch( aLayer )
  239. {
  240. case LAYER_3D_COPPER_TOP: return F_Cu;
  241. case LAYER_3D_COPPER_BOTTOM: return B_Cu;
  242. case LAYER_3D_SILKSCREEN_BOTTOM: return B_SilkS;
  243. case LAYER_3D_SILKSCREEN_TOP: return F_SilkS;
  244. case LAYER_3D_SOLDERMASK_BOTTOM: return B_Mask;
  245. case LAYER_3D_SOLDERMASK_TOP: return F_Mask;
  246. case LAYER_3D_USER_COMMENTS: return Cmts_User;
  247. case LAYER_3D_USER_DRAWINGS: return Dwgs_User;
  248. case LAYER_3D_USER_ECO1: return Eco1_User;
  249. case LAYER_3D_USER_ECO2: return Eco2_User;
  250. case LAYER_3D_USER_1: return User_1;
  251. case LAYER_3D_USER_2: return User_2;
  252. case LAYER_3D_USER_3: return User_3;
  253. case LAYER_3D_USER_4: return User_4;
  254. case LAYER_3D_USER_5: return User_5;
  255. case LAYER_3D_USER_6: return User_6;
  256. case LAYER_3D_USER_7: return User_7;
  257. case LAYER_3D_USER_8: return User_8;
  258. case LAYER_3D_USER_9: return User_9;
  259. case LAYER_3D_USER_10: return User_10;
  260. case LAYER_3D_USER_11: return User_11;
  261. case LAYER_3D_USER_12: return User_12;
  262. case LAYER_3D_USER_13: return User_13;
  263. case LAYER_3D_USER_14: return User_14;
  264. case LAYER_3D_USER_15: return User_15;
  265. case LAYER_3D_USER_16: return User_16;
  266. case LAYER_3D_USER_17: return User_17;
  267. case LAYER_3D_USER_18: return User_18;
  268. case LAYER_3D_USER_19: return User_19;
  269. case LAYER_3D_USER_20: return User_20;
  270. case LAYER_3D_USER_21: return User_21;
  271. case LAYER_3D_USER_22: return User_22;
  272. case LAYER_3D_USER_23: return User_23;
  273. case LAYER_3D_USER_24: return User_24;
  274. case LAYER_3D_USER_25: return User_25;
  275. case LAYER_3D_USER_26: return User_26;
  276. case LAYER_3D_USER_27: return User_27;
  277. case LAYER_3D_USER_28: return User_28;
  278. case LAYER_3D_USER_29: return User_29;
  279. case LAYER_3D_USER_30: return User_30;
  280. case LAYER_3D_USER_31: return User_31;
  281. case LAYER_3D_USER_32: return User_32;
  282. case LAYER_3D_USER_33: return User_33;
  283. case LAYER_3D_USER_34: return User_34;
  284. case LAYER_3D_USER_35: return User_35;
  285. case LAYER_3D_USER_36: return User_36;
  286. case LAYER_3D_USER_37: return User_37;
  287. case LAYER_3D_USER_38: return User_38;
  288. case LAYER_3D_USER_39: return User_39;
  289. case LAYER_3D_USER_40: return User_40;
  290. case LAYER_3D_USER_41: return User_41;
  291. case LAYER_3D_USER_42: return User_42;
  292. case LAYER_3D_USER_43: return User_43;
  293. case LAYER_3D_USER_44: return User_44;
  294. case LAYER_3D_USER_45: return User_45;
  295. default: return UNDEFINED_LAYER;
  296. }
  297. }
  298. int MapPCBLayerTo3DLayer( PCB_LAYER_ID aLayer )
  299. {
  300. // NOTE: User_1..User45 are NOT consecutive numbers!
  301. switch( aLayer )
  302. {
  303. case F_Cu: return LAYER_3D_COPPER_TOP;
  304. case B_Cu: return LAYER_3D_COPPER_BOTTOM;
  305. case B_SilkS: return LAYER_3D_SILKSCREEN_BOTTOM;
  306. case F_SilkS: return LAYER_3D_SILKSCREEN_TOP;
  307. case B_Mask: return LAYER_3D_SOLDERMASK_BOTTOM;
  308. case F_Mask: return LAYER_3D_SOLDERMASK_TOP;
  309. case Cmts_User: return LAYER_3D_USER_COMMENTS;
  310. case Dwgs_User: return LAYER_3D_USER_DRAWINGS;
  311. case Eco1_User: return LAYER_3D_USER_ECO1;
  312. case Eco2_User: return LAYER_3D_USER_ECO2;
  313. case User_1: return LAYER_3D_USER_1;
  314. case User_2: return LAYER_3D_USER_2;
  315. case User_3: return LAYER_3D_USER_3;
  316. case User_4: return LAYER_3D_USER_4;
  317. case User_5: return LAYER_3D_USER_5;
  318. case User_6: return LAYER_3D_USER_6;
  319. case User_7: return LAYER_3D_USER_7;
  320. case User_8: return LAYER_3D_USER_8;
  321. case User_9: return LAYER_3D_USER_9;
  322. case User_10: return LAYER_3D_USER_10;
  323. case User_11: return LAYER_3D_USER_11;
  324. case User_12: return LAYER_3D_USER_12;
  325. case User_13: return LAYER_3D_USER_13;
  326. case User_14: return LAYER_3D_USER_14;
  327. case User_15: return LAYER_3D_USER_15;
  328. case User_16: return LAYER_3D_USER_16;
  329. case User_17: return LAYER_3D_USER_17;
  330. case User_18: return LAYER_3D_USER_18;
  331. case User_19: return LAYER_3D_USER_19;
  332. case User_20: return LAYER_3D_USER_20;
  333. case User_21: return LAYER_3D_USER_21;
  334. case User_22: return LAYER_3D_USER_22;
  335. case User_23: return LAYER_3D_USER_23;
  336. case User_24: return LAYER_3D_USER_24;
  337. case User_25: return LAYER_3D_USER_25;
  338. case User_26: return LAYER_3D_USER_26;
  339. case User_27: return LAYER_3D_USER_27;
  340. case User_28: return LAYER_3D_USER_28;
  341. case User_29: return LAYER_3D_USER_29;
  342. case User_30: return LAYER_3D_USER_30;
  343. case User_31: return LAYER_3D_USER_31;
  344. case User_32: return LAYER_3D_USER_32;
  345. case User_33: return LAYER_3D_USER_33;
  346. case User_34: return LAYER_3D_USER_34;
  347. case User_35: return LAYER_3D_USER_35;
  348. case User_36: return LAYER_3D_USER_36;
  349. case User_37: return LAYER_3D_USER_37;
  350. case User_38: return LAYER_3D_USER_38;
  351. case User_39: return LAYER_3D_USER_39;
  352. case User_40: return LAYER_3D_USER_40;
  353. case User_41: return LAYER_3D_USER_41;
  354. case User_42: return LAYER_3D_USER_42;
  355. case User_43: return LAYER_3D_USER_43;
  356. case User_44: return LAYER_3D_USER_44;
  357. case User_45: return LAYER_3D_USER_45;
  358. default: return UNDEFINED_LAYER;
  359. }
  360. }