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.

262 lines
12 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_BBLIND: return _( "Blind/Buried vias" );
  120. case LAYER_VIA_MICROVIA: return _( "Micro-vias" );
  121. case LAYER_VIA_HOLES: return _( "Via holes" );
  122. case LAYER_VIA_HOLEWALLS: return _( "Via hole walls" );
  123. case LAYER_PAD_PLATEDHOLES: return _( "Plated holes" );
  124. case LAYER_PAD_HOLEWALLS: return _( "Plated hole walls" );
  125. case LAYER_NON_PLATEDHOLES: return _( "Non-plated holes" );
  126. case LAYER_RATSNEST: return _( "Ratsnest" );
  127. case LAYER_DRC_WARNING: return _( "DRC warnings" );
  128. case LAYER_DRC_ERROR: return _( "DRC errors" );
  129. case LAYER_DRC_SHAPE1: return _( "DRC shape 1" );
  130. case LAYER_DRC_SHAPE2: return _( "DRC shape 2" );
  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_DRAWINGSHEET: return _( "Drawing sheet" );
  135. case LAYER_PAGE_LIMITS: return _( "Page limits" );
  136. case LAYER_CURSOR: return _( "Cursor" );
  137. case LAYER_AUX_ITEMS: return _( "Helper items" );
  138. case LAYER_GRID: return _( "Grid" );
  139. case LAYER_GRID_AXES: return _( "Grid axes" );
  140. case LAYER_PCB_BACKGROUND: return _( "Background" );
  141. case LAYER_SELECT_OVERLAY: return _( "Selection highlight" );
  142. case LAYER_LOCKED_ITEM_SHADOW: return _( "Locked item shadow" );
  143. case LAYER_CONFLICTS_SHADOW: return _( "Courtyard collision shadow" );
  144. case NETNAMES_LAYER_ID_START: return _( "Track net names" );
  145. case LAYER_PAD_NETNAMES: return _( "Pad net names" );
  146. case LAYER_VIA_NETNAMES: return _( "Via net names" );
  147. default:
  148. // Catch the general board layers that have numerically increasing names
  149. if( aLayer > 0 && aLayer < PCB_LAYER_ID_COUNT && aLayer & 1 )
  150. return wxString::Format( wxT( "User.%d" ), ( aLayer - PCB_LAYER_ID::User_1 ) / 2 + 1 );
  151. return wxString::Format( wxT( "In%d.Cu" ), ( aLayer - PCB_LAYER_ID::In1_Cu ) / 2 + 1 );
  152. }
  153. }
  154. PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
  155. {
  156. switch( aLayerId )
  157. {
  158. case B_Cu: return F_Cu;
  159. case F_Cu: return B_Cu;
  160. case B_SilkS: return F_SilkS;
  161. case F_SilkS: return B_SilkS;
  162. case B_Adhes: return F_Adhes;
  163. case F_Adhes: return B_Adhes;
  164. case B_Mask: return F_Mask;
  165. case F_Mask: return B_Mask;
  166. case B_Paste: return F_Paste;
  167. case F_Paste: return B_Paste;
  168. case B_CrtYd: return F_CrtYd;
  169. case F_CrtYd: return B_CrtYd;
  170. case B_Fab: return F_Fab;
  171. case F_Fab: return B_Fab;
  172. default: // change internal layer if aCopperLayersCount is >= 4
  173. if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
  174. {
  175. // internal copper layers count is aCopperLayersCount-2
  176. PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
  177. // Ensure fliplayer has a value which does not crash Pcbnew:
  178. if( fliplayer < F_Cu )
  179. fliplayer = F_Cu;
  180. if( fliplayer > B_Cu )
  181. fliplayer = B_Cu;
  182. return fliplayer;
  183. }
  184. // No change for the other layers
  185. return aLayerId;
  186. }
  187. }
  188. PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId )
  189. {
  190. switch( aLegacyId )
  191. {
  192. case 0: return F_Cu;
  193. case 31: return B_Cu;
  194. default:
  195. if( aLegacyId < 0 )
  196. return magic_enum::enum_cast<PCB_LAYER_ID>( aLegacyId ).value_or( UNDEFINED_LAYER );
  197. if( aLegacyId < 31 )
  198. return static_cast<PCB_LAYER_ID>( In1_Cu + ( aLegacyId - 1 ) * 2 );
  199. switch( aLegacyId )
  200. {
  201. case 32: return B_Adhes;
  202. case 33: return F_Adhes;
  203. case 34: return B_Paste;
  204. case 35: return F_Paste;
  205. case 36: return B_SilkS;
  206. case 37: return F_SilkS;
  207. case 38: return B_Mask;
  208. case 39: return F_Mask;
  209. case 40: return Dwgs_User;
  210. case 41: return Cmts_User;
  211. case 42: return Eco1_User;
  212. case 43: return Eco2_User;
  213. case 44: return Edge_Cuts;
  214. case 45: return Margin;
  215. case 46: return B_CrtYd;
  216. case 47: return F_CrtYd;
  217. case 48: return B_Fab;
  218. case 49: return F_Fab;
  219. case 50: return User_1;
  220. case 51: return User_2;
  221. case 52: return User_3;
  222. case 53: return User_4;
  223. case 54: return User_5;
  224. case 55: return User_6;
  225. case 56: return User_7;
  226. case 57: return User_8;
  227. case 58: return User_9;
  228. case 59: return Rescue;
  229. default: return UNDEFINED_LAYER;
  230. }
  231. }
  232. }