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.

919 lines
25 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12 years ago
4 years ago
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef LAYER_IDS_H
  26. #define LAYER_IDS_H
  27. #include <set>
  28. #include <vector>
  29. #include <bitset>
  30. #include <stdexcept>
  31. #include <wx/string.h>
  32. #include <kicommon.h>
  33. /**
  34. * A quick note on layer IDs:
  35. *
  36. * The layers are stored in separate enums so that certain functions can
  37. * take in the enums as data types and don't have to know about layers from
  38. * other applications.
  39. *
  40. * Layers that are shared between applications should be in the GAL_LAYER_ID enum.
  41. *
  42. * The PCB_LAYER_ID struct must start at zero for compatibility with legacy board files.
  43. *
  44. * Some functions accept any layer ID, so they start at zero (i.e. F_Cu) and go up to
  45. * the LAYER_ID_COUNT, which needs to be kept up-to-date if new enums are added.
  46. */
  47. /**
  48. * This is the definition of all layers used in Pcbnew.
  49. *
  50. * The PCB layer types are fixed at value 0 through #LAYER_ID_COUNT to ensure compatibility
  51. * with legacy board files.
  52. */
  53. enum PCB_LAYER_ID: int
  54. {
  55. UNDEFINED_LAYER = -1,
  56. UNSELECTED_LAYER = -2,
  57. F_Cu = 0,
  58. B_Cu = 2,
  59. In1_Cu = 4,
  60. In2_Cu = 6,
  61. In3_Cu = 8,
  62. In4_Cu = 10,
  63. In5_Cu = 12,
  64. In6_Cu = 14,
  65. In7_Cu = 16,
  66. In8_Cu = 18,
  67. In9_Cu = 20,
  68. In10_Cu = 22,
  69. In11_Cu = 24,
  70. In12_Cu = 26,
  71. In13_Cu = 28,
  72. In14_Cu = 30,
  73. In15_Cu = 32,
  74. In16_Cu = 34,
  75. In17_Cu = 36,
  76. In18_Cu = 38,
  77. In19_Cu = 40,
  78. In20_Cu = 42,
  79. In21_Cu = 44,
  80. In22_Cu = 46,
  81. In23_Cu = 48,
  82. In24_Cu = 50,
  83. In25_Cu = 52,
  84. In26_Cu = 54,
  85. In27_Cu = 56,
  86. In28_Cu = 58,
  87. In29_Cu = 60,
  88. In30_Cu = 62,
  89. F_Mask = 1,
  90. B_Mask = 3,
  91. F_SilkS = 5,
  92. B_SilkS = 7,
  93. F_Adhes = 9,
  94. B_Adhes = 11,
  95. F_Paste = 13,
  96. B_Paste = 15,
  97. Dwgs_User = 17,
  98. Cmts_User = 19,
  99. Eco1_User = 21,
  100. Eco2_User = 23,
  101. Edge_Cuts = 25,
  102. Margin = 27,
  103. B_CrtYd = 29,
  104. F_CrtYd = 31,
  105. B_Fab = 33,
  106. F_Fab = 35,
  107. Rescue = 37,
  108. // User definable layers.
  109. User_1 = 39,
  110. User_2 = 41,
  111. User_3 = 43,
  112. User_4 = 45,
  113. User_5 = 47,
  114. User_6 = 49,
  115. User_7 = 51,
  116. User_8 = 53,
  117. User_9 = 55,
  118. User_10 = 57,
  119. User_11 = 59,
  120. User_12 = 61,
  121. User_13 = 63,
  122. User_14 = 65,
  123. User_15 = 67,
  124. User_16 = 69,
  125. User_17 = 71,
  126. User_18 = 73,
  127. User_19 = 75,
  128. User_20 = 77,
  129. User_21 = 79,
  130. User_22 = 81,
  131. User_23 = 83,
  132. User_24 = 85,
  133. User_25 = 87,
  134. User_26 = 89,
  135. User_27 = 91,
  136. User_28 = 93,
  137. User_29 = 95,
  138. User_30 = 97,
  139. User_31 = 99,
  140. User_32 = 101,
  141. User_33 = 103,
  142. User_34 = 105,
  143. User_35 = 107,
  144. User_36 = 109,
  145. User_37 = 111,
  146. User_38 = 113,
  147. User_39 = 115,
  148. User_40 = 117,
  149. User_41 = 119,
  150. User_42 = 121,
  151. User_43 = 123,
  152. User_44 = 125,
  153. User_45 = 127,
  154. PCB_LAYER_ID_COUNT = 128
  155. };
  156. constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START = F_Cu;
  157. #define MAX_CU_LAYERS 32
  158. #define MAX_USER_DEFINED_LAYERS 45
  159. /**
  160. * Enum used during connectivity building to ensure we do not query connectivity while building
  161. * the database.
  162. */
  163. enum class FLASHING
  164. {
  165. DEFAULT, ///< Flashing follows connectivity.
  166. ALWAYS_FLASHED, ///< Always flashed for connectivity.
  167. NEVER_FLASHED, ///< Never flashed for connectivity.
  168. };
  169. /// Dedicated layers for net names used in Pcbnew.
  170. enum NETNAMES_LAYER_ID: int
  171. {
  172. NETNAMES_LAYER_ID_START = PCB_LAYER_ID_COUNT,
  173. /// Reserved space for board layer netnames.
  174. NETNAMES_LAYER_ID_RESERVED = NETNAMES_LAYER_ID_START + PCB_LAYER_ID_COUNT,
  175. /// Additional netnames layers (not associated with a PCB layer).
  176. LAYER_PAD_FR_NETNAMES,
  177. LAYER_PAD_BK_NETNAMES,
  178. LAYER_PAD_NETNAMES,
  179. LAYER_VIA_NETNAMES,
  180. NETNAMES_LAYER_ID_END
  181. };
  182. /// Macro for obtaining netname layer for a given PCB layer
  183. #define NETNAMES_LAYER_INDEX( layer ) ( static_cast<int>( NETNAMES_LAYER_ID_START ) + layer )
  184. #define GAL_UI_LAYER_COUNT 10
  185. /**
  186. * GAL layers are "virtual" layers, i.e. not tied into design data.
  187. *
  188. * Some layers here are shared between applications.
  189. *
  190. * @note Be very careful where you add new layers here. Layers up to #GAL_LAYER_ID_BITMASK_END
  191. * must never be re-ordered and new layers must always be added after this value, because the
  192. * layers before this value are mapped to bit locations in legacy board files.
  193. *
  194. * The values in this enum that are used to store visibility state are explicitly encoded with an
  195. * offset from #GAL_LAYER_ID_START, which is explicitly encoded itself. The exact value of
  196. * #GAL_LAYER_ID_START is not that sensitive, but the offsets should never be changed or else any
  197. * existing visibility settings will be disrupted.
  198. */
  199. enum GAL_LAYER_ID: int
  200. {
  201. GAL_LAYER_ID_START = NETNAMES_LAYER_ID_END,
  202. /// Meta control for all vias opacity/visibility.
  203. LAYER_VIAS = GAL_LAYER_ID_START + 0,
  204. LAYER_VIA_MICROVIA = GAL_LAYER_ID_START + 1, /// Draw micro vias.
  205. LAYER_VIA_BBLIND = GAL_LAYER_ID_START + 2, /// Draw blind/buried vias.
  206. LAYER_VIA_THROUGH = GAL_LAYER_ID_START + 3, /// Draw usual through hole vias.
  207. /// Handle color for not plated holes (holes, not pads).
  208. LAYER_NON_PLATEDHOLES = GAL_LAYER_ID_START + 4,
  209. LAYER_FP_TEXT = GAL_LAYER_ID_START + 5,
  210. // LAYER_MOD_TEXT_BK deprecated + 6,
  211. // DEPRECATED, UNUSED SINCE 9.0. text marked as invisible.
  212. // LAYER_HIDDEN_TEXT = GAL_LAYER_ID_START + 7,
  213. /// Anchor of items having an anchor point (texts, footprints).
  214. LAYER_ANCHOR = GAL_LAYER_ID_START + 8,
  215. // LAYER_PADS_SMD_FR = GAL_LAYER_ID_START + 9, // Deprecated since 9.0
  216. // LAYER_PADS_SMD_BK = GAL_LAYER_ID_START + 10, // Deprecated since 9.0
  217. LAYER_RATSNEST = GAL_LAYER_ID_START + 11,
  218. LAYER_GRID = GAL_LAYER_ID_START + 12,
  219. LAYER_GRID_AXES = GAL_LAYER_ID_START + 13,
  220. // LAYER_NO_CONNECTS deprecated + 14, // show a marker on pads with no nets
  221. LAYER_FOOTPRINTS_FR = GAL_LAYER_ID_START + 15, ///< Show footprints on front.
  222. LAYER_FOOTPRINTS_BK = GAL_LAYER_ID_START + 16, ///< Show footprints on back.
  223. /// Show footprints values (when texts are visible).
  224. LAYER_FP_VALUES = GAL_LAYER_ID_START + 17,
  225. /// Show footprints references (when texts are visible).
  226. LAYER_FP_REFERENCES = GAL_LAYER_ID_START + 18,
  227. LAYER_TRACKS = GAL_LAYER_ID_START + 19,
  228. // LAYER_PADS_TH = GAL_LAYER_ID_START + 20, ///< Deprecated since 9.0
  229. LAYER_PAD_PLATEDHOLES = GAL_LAYER_ID_START + 21, ///< to draw pad holes (plated)
  230. /// Draw via holes (pad holes do not use this layer).
  231. LAYER_VIA_HOLES = GAL_LAYER_ID_START + 22,
  232. /// Layer for DRC markers with #SEVERITY_ERROR.
  233. LAYER_DRC_ERROR = GAL_LAYER_ID_START + 23,
  234. LAYER_DRAWINGSHEET = GAL_LAYER_ID_START + 24, ///< Sheet frame and title block.
  235. LAYER_GP_OVERLAY = GAL_LAYER_ID_START + 25, ///< General purpose overlay.
  236. LAYER_SELECT_OVERLAY = GAL_LAYER_ID_START + 26, ///< Selected items overlay.
  237. LAYER_PCB_BACKGROUND = GAL_LAYER_ID_START + 27, ///< PCB background color.
  238. LAYER_CURSOR = GAL_LAYER_ID_START + 28, ///< PCB cursor.
  239. LAYER_AUX_ITEMS = GAL_LAYER_ID_START + 29, ///< Auxiliary items (guides, rule, etc).
  240. LAYER_DRAW_BITMAPS = GAL_LAYER_ID_START + 30, ///< Draw images.
  241. /// This is the end of the layers used for visibility bit masks in legacy board files
  242. GAL_LAYER_ID_BITMASK_END = GAL_LAYER_ID_START + 31,
  243. // Layers in this section have visibility controls but were not present in legacy board files.
  244. /// Meta control for all pads opacity/visibility (color ignored).
  245. LAYER_PADS = GAL_LAYER_ID_START + 32,
  246. /// Control for copper zone opacity/visibility (color ignored).
  247. LAYER_ZONES = GAL_LAYER_ID_START + 33,
  248. LAYER_PAD_HOLEWALLS = GAL_LAYER_ID_START + 34,
  249. LAYER_VIA_HOLEWALLS = GAL_LAYER_ID_START + 35,
  250. /// Layer for DRC markers with #SEVERITY_WARNING.
  251. LAYER_DRC_WARNING = GAL_LAYER_ID_START + 36,
  252. /// Layer for DRC markers which have been individually excluded.
  253. LAYER_DRC_EXCLUSION = GAL_LAYER_ID_START + 37,
  254. LAYER_MARKER_SHADOWS = GAL_LAYER_ID_START + 38, ///< Shadows for DRC markers.
  255. LAYER_LOCKED_ITEM_SHADOW = GAL_LAYER_ID_START + 39, ///< Shadow layer for locked items.
  256. /// Shadow layer for items flagged conflicting.
  257. LAYER_CONFLICTS_SHADOW = GAL_LAYER_ID_START + 40,
  258. /// Copper graphic shape opacity/visibility (color ignored).
  259. LAYER_FILLED_SHAPES = GAL_LAYER_ID_START + 41,
  260. LAYER_DRC_SHAPE1 = GAL_LAYER_ID_START + 42, ///< Custom shape for DRC marker.
  261. LAYER_DRC_SHAPE2 = GAL_LAYER_ID_START + 43, ///< Custom shape for DRC marker.
  262. LAYER_BOARD_OUTLINE_AREA = GAL_LAYER_ID_START + 44, ///< PCB board outline
  263. // Add layers below this point that do not have visibility controls, so don't need explicit
  264. // enum values
  265. LAYER_DRAWINGSHEET_PAGE1, ///< Sheet Editor previewing first page.
  266. LAYER_DRAWINGSHEET_PAGEn, ///< Sheet Editor previewing pages after first page.
  267. LAYER_PAGE_LIMITS, ///< Color for drawing the page extents (visibility stored in
  268. ///< PCBNEW_SETTINGS::m_ShowPageLimits)
  269. /// Virtual layers for stacking zones and tracks on a given copper layer.
  270. LAYER_ZONE_START,
  271. LAYER_ZONE_END = LAYER_ZONE_START + PCB_LAYER_ID_COUNT,
  272. /// Virtual layers for pad copper on a given copper layer.
  273. LAYER_PAD_COPPER_START,
  274. LAYER_PAD_COPPER_END = LAYER_PAD_COPPER_START + PCB_LAYER_ID_COUNT,
  275. /// Virtual layers for via copper on a given copper layer.
  276. LAYER_VIA_COPPER_START,
  277. LAYER_VIA_COPPER_END = LAYER_VIA_COPPER_START + PCB_LAYER_ID_COUNT,
  278. /// Virtual layers for pad/via/track clearance outlines for a given copper layer.
  279. LAYER_CLEARANCE_START,
  280. LAYER_CLEARANCE_END = LAYER_CLEARANCE_START + PCB_LAYER_ID_COUNT,
  281. /// Virtual layers for background images per board layer.
  282. LAYER_BITMAP_START,
  283. LAYER_BITMAP_END = LAYER_BITMAP_START + PCB_LAYER_ID_COUNT,
  284. // Layers for drawing on-canvas UI
  285. LAYER_UI_START,
  286. LAYER_UI_END = LAYER_UI_START + GAL_UI_LAYER_COUNT,
  287. GAL_LAYER_ID_END
  288. };
  289. /// Use this macro to convert a #GAL layer to a 0-indexed offset from #LAYER_VIAS.
  290. #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
  291. /// Macros for getting the extra layers for a given board layer.
  292. #define BITMAP_LAYER_FOR( boardLayer ) ( LAYER_BITMAP_START + boardLayer )
  293. #define ZONE_LAYER_FOR( boardLayer ) ( LAYER_ZONE_START + boardLayer )
  294. #define PAD_COPPER_LAYER_FOR( boardLayer ) ( LAYER_PAD_COPPER_START + boardLayer )
  295. #define VIA_COPPER_LAYER_FOR( boardLayer ) ( LAYER_VIA_COPPER_START + boardLayer )
  296. #define CLEARANCE_LAYER_FOR( boardLayer ) ( LAYER_CLEARANCE_START + boardLayer )
  297. constexpr int GAL_LAYER_ID_COUNT = GAL_LAYER_ID_END - GAL_LAYER_ID_START;
  298. inline GAL_LAYER_ID operator++( GAL_LAYER_ID& a )
  299. {
  300. a = GAL_LAYER_ID( int( a ) + 1 );
  301. return a;
  302. }
  303. inline GAL_LAYER_ID ToGalLayer( int aInteger )
  304. {
  305. wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
  306. return static_cast<GAL_LAYER_ID>( aInteger );
  307. }
  308. /// Used for via types.
  309. inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
  310. {
  311. GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
  312. wxASSERT( t <= GAL_LAYER_ID_END );
  313. return t;
  314. }
  315. /// Wraps a std::bitset.
  316. typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
  317. /// Helper for storing and iterating over GAL_LAYER_IDs.
  318. class KICOMMON_API GAL_SET : public GAL_BASE_SET
  319. {
  320. private:
  321. static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
  322. public:
  323. GAL_SET() : std::bitset<GAL_LAYER_ID_COUNT>()
  324. {
  325. }
  326. GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
  327. {
  328. }
  329. GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
  330. GAL_SET& set()
  331. {
  332. GAL_BASE_SET::set();
  333. return *this;
  334. }
  335. GAL_SET& set( int aPos, bool aVal = true )
  336. {
  337. GAL_BASE_SET::set( aPos, aVal );
  338. return *this;
  339. }
  340. GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
  341. {
  342. GAL_BASE_SET::set( static_cast<std::size_t>( aPos ) - start, aVal );
  343. return *this;
  344. }
  345. bool Contains( GAL_LAYER_ID aPos )
  346. {
  347. return test( static_cast<std::size_t>( aPos ) - start );
  348. }
  349. std::vector<GAL_LAYER_ID> Seq() const;
  350. static GAL_SET DefaultVisible();
  351. };
  352. /// Eeschema drawing layers.
  353. enum SCH_LAYER_ID : int
  354. {
  355. SCH_LAYER_ID_START = GAL_LAYER_ID_END,
  356. LAYER_WIRE = SCH_LAYER_ID_START,
  357. LAYER_BUS,
  358. LAYER_JUNCTION,
  359. LAYER_LOCLABEL,
  360. LAYER_GLOBLABEL,
  361. LAYER_HIERLABEL,
  362. LAYER_PINNUM,
  363. LAYER_PINNAM,
  364. LAYER_REFERENCEPART,
  365. LAYER_VALUEPART,
  366. LAYER_FIELDS,
  367. LAYER_INTERSHEET_REFS,
  368. LAYER_NETCLASS_REFS,
  369. LAYER_RULE_AREAS,
  370. LAYER_DEVICE,
  371. LAYER_NOTES,
  372. LAYER_PRIVATE_NOTES,
  373. LAYER_NOTES_BACKGROUND,
  374. LAYER_PIN,
  375. LAYER_SHEET,
  376. LAYER_SHEETNAME,
  377. LAYER_SHEETFILENAME,
  378. LAYER_SHEETFIELDS,
  379. LAYER_SHEETLABEL,
  380. LAYER_NOCONNECT,
  381. LAYER_DANGLING,
  382. LAYER_DNP_MARKER,
  383. LAYER_ERC_WARN,
  384. LAYER_ERC_ERR,
  385. LAYER_ERC_EXCLUSION,
  386. LAYER_EXCLUDED_FROM_SIM,
  387. LAYER_SHAPES_BACKGROUND,
  388. LAYER_DEVICE_BACKGROUND,
  389. LAYER_SHEET_BACKGROUND,
  390. LAYER_SCHEMATIC_GRID,
  391. LAYER_SCHEMATIC_GRID_AXES,
  392. LAYER_SCHEMATIC_BACKGROUND,
  393. LAYER_SCHEMATIC_CURSOR,
  394. LAYER_HOVERED,
  395. LAYER_BRIGHTENED,
  396. LAYER_HIDDEN,
  397. LAYER_NET_COLOR_HIGHLIGHT,
  398. LAYER_SELECTION_SHADOWS,
  399. LAYER_SCHEMATIC_DRAWINGSHEET,
  400. LAYER_SCHEMATIC_PAGE_LIMITS,
  401. LAYER_BUS_JUNCTION,
  402. LAYER_SCHEMATIC_AUX_ITEMS,
  403. LAYER_SCHEMATIC_ANCHOR,
  404. LAYER_OP_VOLTAGES,
  405. LAYER_OP_CURRENTS,
  406. SCH_LAYER_ID_END
  407. };
  408. #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
  409. #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
  410. inline SCH_LAYER_ID operator++( SCH_LAYER_ID& a )
  411. {
  412. a = SCH_LAYER_ID( int( a ) + 1 );
  413. return a;
  414. }
  415. /// Number of draw layers in Gerbview.
  416. #define GERBER_DRAWLAYERS_COUNT static_cast<int>( PCB_LAYER_ID_COUNT )
  417. /// Gerbview draw layers.
  418. enum GERBVIEW_LAYER_ID: int
  419. {
  420. GERBVIEW_LAYER_ID_START = SCH_LAYER_ID_END,
  421. /// Gerbview draw layers and d-code layers
  422. GERBVIEW_LAYER_ID_RESERVED = GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ),
  423. LAYER_DCODES,
  424. LAYER_NEGATIVE_OBJECTS,
  425. LAYER_GERBVIEW_GRID,
  426. LAYER_GERBVIEW_AXES,
  427. LAYER_GERBVIEW_BACKGROUND,
  428. LAYER_GERBVIEW_DRAWINGSHEET,
  429. LAYER_GERBVIEW_PAGE_LIMITS,
  430. GERBVIEW_LAYER_ID_END
  431. };
  432. #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
  433. #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
  434. #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
  435. /// 3D Viewer virtual layers for color settings
  436. enum LAYER_3D_ID : int
  437. {
  438. LAYER_3D_START = GERBVIEW_LAYER_ID_END,
  439. LAYER_3D_BACKGROUND_BOTTOM,
  440. LAYER_3D_BACKGROUND_TOP,
  441. LAYER_3D_BOARD,
  442. LAYER_3D_COPPER_TOP,
  443. LAYER_3D_COPPER_BOTTOM,
  444. LAYER_3D_SILKSCREEN_BOTTOM,
  445. LAYER_3D_SILKSCREEN_TOP,
  446. LAYER_3D_SOLDERMASK_BOTTOM,
  447. LAYER_3D_SOLDERMASK_TOP,
  448. LAYER_3D_SOLDERPASTE,
  449. LAYER_3D_ADHESIVE,
  450. LAYER_3D_USER_COMMENTS,
  451. LAYER_3D_USER_DRAWINGS,
  452. LAYER_3D_USER_ECO1,
  453. LAYER_3D_USER_ECO2,
  454. LAYER_3D_USER_1,
  455. LAYER_3D_USER_2,
  456. LAYER_3D_USER_3,
  457. LAYER_3D_USER_4,
  458. LAYER_3D_USER_5,
  459. LAYER_3D_USER_6,
  460. LAYER_3D_USER_7,
  461. LAYER_3D_USER_8,
  462. LAYER_3D_USER_9,
  463. LAYER_3D_USER_10,
  464. LAYER_3D_USER_11,
  465. LAYER_3D_USER_12,
  466. LAYER_3D_USER_13,
  467. LAYER_3D_USER_14,
  468. LAYER_3D_USER_15,
  469. LAYER_3D_USER_16,
  470. LAYER_3D_USER_17,
  471. LAYER_3D_USER_18,
  472. LAYER_3D_USER_19,
  473. LAYER_3D_USER_20,
  474. LAYER_3D_USER_21,
  475. LAYER_3D_USER_22,
  476. LAYER_3D_USER_23,
  477. LAYER_3D_USER_24,
  478. LAYER_3D_USER_25,
  479. LAYER_3D_USER_26,
  480. LAYER_3D_USER_27,
  481. LAYER_3D_USER_28,
  482. LAYER_3D_USER_29,
  483. LAYER_3D_USER_30,
  484. LAYER_3D_USER_31,
  485. LAYER_3D_USER_32,
  486. LAYER_3D_USER_33,
  487. LAYER_3D_USER_34,
  488. LAYER_3D_USER_35,
  489. LAYER_3D_USER_36,
  490. LAYER_3D_USER_37,
  491. LAYER_3D_USER_38,
  492. LAYER_3D_USER_39,
  493. LAYER_3D_USER_40,
  494. LAYER_3D_USER_41,
  495. LAYER_3D_USER_42,
  496. LAYER_3D_USER_43,
  497. LAYER_3D_USER_44,
  498. LAYER_3D_USER_45,
  499. LAYER_3D_TH_MODELS,
  500. LAYER_3D_SMD_MODELS,
  501. LAYER_3D_VIRTUAL_MODELS,
  502. LAYER_3D_MODELS_NOT_IN_POS,
  503. LAYER_3D_MODELS_MARKED_DNP,
  504. LAYER_3D_NAVIGATOR,
  505. LAYER_3D_BOUNDING_BOXES,
  506. LAYER_3D_OFF_BOARD_SILK,
  507. LAYER_3D_PLATED_BARRELS,
  508. LAYER_3D_END
  509. };
  510. /// Must update this if you add any enums after Gerbview!
  511. #define LAYER_ID_COUNT LAYER_3D_END
  512. /**
  513. * Return the string equivalent of a given layer.
  514. *
  515. * @param aLayer is a valid layer ID.
  516. */
  517. KICOMMON_API wxString LayerName( int aLayer );
  518. // Some elements do not have yet a visibility control
  519. // from a dialog, but have a visibility control flag.
  520. // Here is a mask to set them visible, to be sure they are displayed
  521. // after loading a board for instance
  522. #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PAD_PLATEDHOLES ) ) +\
  523. ( 1 << GAL_LAYER_INDEX( LAYER_VIA_HOLES ) ) +\
  524. ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
  525. ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
  526. ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
  527. /**
  528. * Test whether a given integer is a valid layer index, i.e. can
  529. * be safely put in a #PCB_LAYER_ID.
  530. *
  531. * @param aLayerId = Layer index to test. It can be an int, so its useful during I/O
  532. * @return true if aLayerIndex is a valid layer index
  533. */
  534. inline bool IsValidLayer( int aLayerId )
  535. {
  536. return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
  537. }
  538. /**
  539. * Test whether a layer is a valid layer for Pcbnew
  540. *
  541. * @param aLayer = Layer to test
  542. * @return true if aLayer is a layer valid in Pcbnew
  543. */
  544. inline bool IsPcbLayer( int aLayer )
  545. {
  546. return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
  547. }
  548. /**
  549. * Test whether a layer is a copper layer.
  550. *
  551. * @param aLayerId = Layer to test
  552. * @return true if aLayer is a valid copper layer
  553. */
  554. inline bool IsCopperLayer( int aLayerId )
  555. {
  556. return !( aLayerId & 1 ) && aLayerId < PCB_LAYER_ID_COUNT && aLayerId >= 0;
  557. }
  558. /**
  559. * Test whether a layer is an external (#F_Cu or #B_Cu) copper layer.
  560. *
  561. * @param aLayerId = Layer to test
  562. * @return true if aLayer is a valid external copper layer
  563. */
  564. inline bool IsExternalCopperLayer( int aLayerId )
  565. {
  566. return aLayerId == F_Cu || aLayerId == B_Cu;
  567. }
  568. /**
  569. * Test whether a layer is an inner (#In1_Cu to #In30_Cu) copper layer.
  570. *
  571. * @param aLayerId = Layer to test
  572. * @return true if aLayer is a valid inner copper layer
  573. */
  574. inline bool IsInnerCopperLayer( int aLayerId )
  575. {
  576. return IsCopperLayer( aLayerId ) && !IsExternalCopperLayer( aLayerId );
  577. }
  578. /**
  579. * Test whether a layer is a non copper layer.
  580. *
  581. * @param aLayerId = Layer to test
  582. * @return true if aLayer is a non copper layer
  583. */
  584. inline bool IsNonCopperLayer( int aLayerId )
  585. {
  586. return ( aLayerId & 1 ) && aLayerId <= PCB_LAYER_ID_COUNT;
  587. }
  588. /**
  589. * Test whether a layer is a copper layer, optionally including synthetic copper layers such
  590. * as #LAYER_VIA_THROUGH, #LAYER_PADS_SMD_FR, etc.
  591. *
  592. * @param aLayerId
  593. * @param aIncludeSyntheticCopperLayers
  594. * @return
  595. */
  596. inline bool IsCopperLayer( int aLayerId, bool aIncludeSyntheticCopperLayers )
  597. {
  598. if( aIncludeSyntheticCopperLayers )
  599. return !IsNonCopperLayer( aLayerId );
  600. else
  601. return IsCopperLayer( aLayerId );
  602. }
  603. inline bool IsViaPadLayer( int aLayer )
  604. {
  605. return aLayer == LAYER_VIA_THROUGH
  606. || aLayer == LAYER_VIA_MICROVIA
  607. || aLayer == LAYER_VIA_BBLIND;
  608. }
  609. inline bool IsHoleLayer( int aLayer )
  610. {
  611. return aLayer == LAYER_VIA_HOLES
  612. || aLayer == LAYER_VIA_HOLEWALLS
  613. || aLayer == LAYER_PAD_PLATEDHOLES
  614. || aLayer == LAYER_PAD_HOLEWALLS
  615. || aLayer == LAYER_NON_PLATEDHOLES;
  616. }
  617. inline bool IsSolderMaskLayer( int aLayer )
  618. {
  619. return aLayer == F_Mask || aLayer == B_Mask;
  620. }
  621. /**
  622. * Test whether a layer is a non copper and a non tech layer.
  623. *
  624. * @param aLayerId = Layer to test
  625. * @return true if aLayer is a user layer
  626. */
  627. inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
  628. {
  629. return aLayerId == Dwgs_User || aLayerId == Cmts_User || aLayerId == Eco1_User
  630. || aLayerId == Eco2_User || ( aLayerId >= User_1 && !IsCopperLayer( aLayerId ) );
  631. }
  632. /*
  633. * IMPORTANT: If a layer is not a front layer that doesn't necessarily mean it's a back layer.
  634. *
  635. * So a layer can be:
  636. * - Front
  637. * - Back
  638. * - Neither (internal or auxiliary)
  639. *
  640. * The check most frequent is for back layers, since it involves flips.
  641. */
  642. /**
  643. * Layer classification: check if it's a front layer.
  644. */
  645. inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
  646. {
  647. switch( aLayerId )
  648. {
  649. case F_Cu:
  650. case F_Adhes:
  651. case F_Paste:
  652. case F_SilkS:
  653. case F_Mask:
  654. case F_CrtYd:
  655. case F_Fab:
  656. return true;
  657. default:
  658. ;
  659. }
  660. return false;
  661. }
  662. /**
  663. * Layer classification: check if it's a back layer.
  664. */
  665. inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
  666. {
  667. switch( aLayerId )
  668. {
  669. case B_Cu:
  670. case B_Adhes:
  671. case B_Paste:
  672. case B_SilkS:
  673. case B_Mask:
  674. case B_CrtYd:
  675. case B_Fab:
  676. return true;
  677. default:
  678. return false;
  679. }
  680. }
  681. /**
  682. * Return true if copper aLayerA is placed lower than aLayerB, false otherwise.
  683. */
  684. inline bool IsCopperLayerLowerThan( PCB_LAYER_ID aLayerA, PCB_LAYER_ID aLayerB )
  685. {
  686. if( aLayerA == aLayerB )
  687. return false;
  688. if( aLayerA == B_Cu )
  689. return true;
  690. if( aLayerB == B_Cu )
  691. return false;
  692. return aLayerA > aLayerB;
  693. }
  694. /**
  695. * @param aLayerId = the PCB_LAYER_ID to flip
  696. * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  697. * internal layers will be not flipped because the layer count is not known
  698. * @return the layer number after flipping an item
  699. * some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... )
  700. * are swapped between front and back sides
  701. * internal layers are flipped only if the copper layers count is known
  702. */
  703. KICOMMON_API PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
  704. /**
  705. * Return a netname layer corresponding to the given layer.
  706. */
  707. inline int GetNetnameLayer( int aLayer )
  708. {
  709. if( IsCopperLayer( aLayer ) || IsViaPadLayer( aLayer ) )
  710. return NETNAMES_LAYER_INDEX( aLayer );
  711. // Fallback
  712. return Cmts_User;
  713. }
  714. /**
  715. * Test whether a layer is a netname layer.
  716. *
  717. * @param aLayer = Layer to test
  718. * @return true if aLayer is a valid netname layer
  719. */
  720. inline bool IsNetnameLayer( int aLayer )
  721. {
  722. return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) && aLayer < NETNAMES_LAYER_ID_END;
  723. }
  724. inline bool IsZoneFillLayer( int aLayer )
  725. {
  726. return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
  727. }
  728. inline bool IsPadCopperLayer( int aLayer )
  729. {
  730. return aLayer >= LAYER_PAD_COPPER_START && aLayer <= LAYER_PAD_COPPER_END;
  731. }
  732. inline bool IsViaCopperLayer( int aLayer )
  733. {
  734. return aLayer >= LAYER_VIA_COPPER_START && aLayer <= LAYER_VIA_COPPER_END;
  735. }
  736. inline bool IsClearanceLayer( int aLayer )
  737. {
  738. return aLayer >= LAYER_CLEARANCE_START && aLayer <= LAYER_CLEARANCE_END;
  739. }
  740. inline bool IsDCodeLayer( int aLayer )
  741. {
  742. return aLayer >= ( GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT )
  743. && aLayer < ( GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ) );
  744. }
  745. /// Converts KiCad copper layer enum to an ordinal between the front and back layers.
  746. inline size_t CopperLayerToOrdinal( PCB_LAYER_ID aLayer )
  747. {
  748. wxCHECK( IsCopperLayer( aLayer ), 0 );
  749. switch( aLayer )
  750. {
  751. case F_Cu: return 0;
  752. case B_Cu: return MAX_CU_LAYERS - 1;
  753. default: return ( aLayer - B_Cu ) / 2;
  754. }
  755. }
  756. /**
  757. * Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
  758. */
  759. KICOMMON_API PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId );
  760. KICOMMON_API PCB_LAYER_ID Map3DLayerToPCBLayer( int aLayer );
  761. KICOMMON_API int MapPCBLayerTo3DLayer( PCB_LAYER_ID aLayer );
  762. KICOMMON_API PCB_LAYER_ID ToLAYER_ID( int aLayer );
  763. #endif // LAYER_IDS_H