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.

868 lines
24 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_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. // Add layers below this point that do not have visibility controls, so don't need explicit
  263. // enum values
  264. LAYER_DRAWINGSHEET_PAGE1, ///< Sheet Editor previewing first page.
  265. LAYER_DRAWINGSHEET_PAGEn, ///< Sheet Editor previewing pages after first page.
  266. LAYER_PAGE_LIMITS, ///< Color for drawing the page extents (visibility stored in
  267. ///< PCBNEW_SETTINGS::m_ShowPageLimits)
  268. /// Virtual layers for stacking zones and tracks on a given copper layer.
  269. LAYER_ZONE_START,
  270. LAYER_ZONE_END = LAYER_ZONE_START + PCB_LAYER_ID_COUNT,
  271. /// Virtual layers for pad copper on a given copper layer.
  272. LAYER_PAD_COPPER_START,
  273. LAYER_PAD_COPPER_END = LAYER_PAD_COPPER_START + PCB_LAYER_ID_COUNT,
  274. /// Virtual layers for via copper on a given copper layer.
  275. LAYER_VIA_COPPER_START,
  276. LAYER_VIA_COPPER_END = LAYER_VIA_COPPER_START + PCB_LAYER_ID_COUNT,
  277. /// Virtual layers for pad/via/track clearance outlines for a given copper layer.
  278. LAYER_CLEARANCE_START,
  279. LAYER_CLEARANCE_END = LAYER_CLEARANCE_START + PCB_LAYER_ID_COUNT,
  280. /// Virtual layers for background images per board layer.
  281. LAYER_BITMAP_START,
  282. LAYER_BITMAP_END = LAYER_BITMAP_START + PCB_LAYER_ID_COUNT,
  283. // Layers for drawing on-canvas UI
  284. LAYER_UI_START,
  285. LAYER_UI_END = LAYER_UI_START + GAL_UI_LAYER_COUNT,
  286. GAL_LAYER_ID_END
  287. };
  288. /// Use this macro to convert a #GAL layer to a 0-indexed offset from #LAYER_VIAS.
  289. #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
  290. /// Macros for getting the extra layers for a given board layer.
  291. #define BITMAP_LAYER_FOR( boardLayer ) ( LAYER_BITMAP_START + boardLayer )
  292. #define ZONE_LAYER_FOR( boardLayer ) ( LAYER_ZONE_START + boardLayer )
  293. #define PAD_COPPER_LAYER_FOR( boardLayer ) ( LAYER_PAD_COPPER_START + boardLayer )
  294. #define VIA_COPPER_LAYER_FOR( boardLayer ) ( LAYER_VIA_COPPER_START + boardLayer )
  295. #define CLEARANCE_LAYER_FOR( boardLayer ) ( LAYER_CLEARANCE_START + boardLayer )
  296. constexpr int GAL_LAYER_ID_COUNT = GAL_LAYER_ID_END - GAL_LAYER_ID_START;
  297. inline GAL_LAYER_ID operator++( GAL_LAYER_ID& a )
  298. {
  299. a = GAL_LAYER_ID( int( a ) + 1 );
  300. return a;
  301. }
  302. inline GAL_LAYER_ID ToGalLayer( int aInteger )
  303. {
  304. wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
  305. return static_cast<GAL_LAYER_ID>( aInteger );
  306. }
  307. /// Used for via types.
  308. inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
  309. {
  310. GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
  311. wxASSERT( t <= GAL_LAYER_ID_END );
  312. return t;
  313. }
  314. /// Wraps a std::bitset.
  315. typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
  316. /// Helper for storing and iterating over GAL_LAYER_IDs.
  317. class KICOMMON_API GAL_SET : public GAL_BASE_SET
  318. {
  319. private:
  320. static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
  321. public:
  322. GAL_SET() : std::bitset<GAL_LAYER_ID_COUNT>()
  323. {
  324. }
  325. GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
  326. {
  327. }
  328. GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
  329. GAL_SET& set()
  330. {
  331. GAL_BASE_SET::set();
  332. return *this;
  333. }
  334. GAL_SET& set( int aPos, bool aVal = true )
  335. {
  336. GAL_BASE_SET::set( aPos, aVal );
  337. return *this;
  338. }
  339. GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
  340. {
  341. GAL_BASE_SET::set( static_cast<std::size_t>( aPos ) - start, aVal );
  342. return *this;
  343. }
  344. bool Contains( GAL_LAYER_ID aPos )
  345. {
  346. return test( static_cast<std::size_t>( aPos ) - start );
  347. }
  348. std::vector<GAL_LAYER_ID> Seq() const;
  349. static GAL_SET DefaultVisible();
  350. };
  351. /// Eeschema drawing layers.
  352. enum SCH_LAYER_ID : int
  353. {
  354. SCH_LAYER_ID_START = GAL_LAYER_ID_END,
  355. LAYER_WIRE = SCH_LAYER_ID_START,
  356. LAYER_BUS,
  357. LAYER_JUNCTION,
  358. LAYER_LOCLABEL,
  359. LAYER_GLOBLABEL,
  360. LAYER_HIERLABEL,
  361. LAYER_PINNUM,
  362. LAYER_PINNAM,
  363. LAYER_REFERENCEPART,
  364. LAYER_VALUEPART,
  365. LAYER_FIELDS,
  366. LAYER_INTERSHEET_REFS,
  367. LAYER_NETCLASS_REFS,
  368. LAYER_RULE_AREAS,
  369. LAYER_DEVICE,
  370. LAYER_NOTES,
  371. LAYER_PRIVATE_NOTES,
  372. LAYER_NOTES_BACKGROUND,
  373. LAYER_PIN,
  374. LAYER_SHEET,
  375. LAYER_SHEETNAME,
  376. LAYER_SHEETFILENAME,
  377. LAYER_SHEETFIELDS,
  378. LAYER_SHEETLABEL,
  379. LAYER_NOCONNECT,
  380. LAYER_DANGLING,
  381. LAYER_DNP_MARKER,
  382. LAYER_ERC_WARN,
  383. LAYER_ERC_ERR,
  384. LAYER_ERC_EXCLUSION,
  385. LAYER_EXCLUDED_FROM_SIM,
  386. LAYER_SHAPES_BACKGROUND,
  387. LAYER_DEVICE_BACKGROUND,
  388. LAYER_SHEET_BACKGROUND,
  389. LAYER_SCHEMATIC_GRID,
  390. LAYER_SCHEMATIC_GRID_AXES,
  391. LAYER_SCHEMATIC_BACKGROUND,
  392. LAYER_SCHEMATIC_CURSOR,
  393. LAYER_HOVERED,
  394. LAYER_BRIGHTENED,
  395. LAYER_HIDDEN,
  396. LAYER_NET_COLOR_HIGHLIGHT,
  397. LAYER_SELECTION_SHADOWS,
  398. LAYER_SCHEMATIC_DRAWINGSHEET,
  399. LAYER_SCHEMATIC_PAGE_LIMITS,
  400. LAYER_BUS_JUNCTION,
  401. LAYER_SCHEMATIC_AUX_ITEMS,
  402. LAYER_SCHEMATIC_ANCHOR,
  403. LAYER_OP_VOLTAGES,
  404. LAYER_OP_CURRENTS,
  405. SCH_LAYER_ID_END
  406. };
  407. #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
  408. #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
  409. inline SCH_LAYER_ID operator++( SCH_LAYER_ID& a )
  410. {
  411. a = SCH_LAYER_ID( int( a ) + 1 );
  412. return a;
  413. }
  414. /// Number of draw layers in Gerbview.
  415. #define GERBER_DRAWLAYERS_COUNT static_cast<int>( PCB_LAYER_ID_COUNT )
  416. /// Gerbview draw layers.
  417. enum GERBVIEW_LAYER_ID: int
  418. {
  419. GERBVIEW_LAYER_ID_START = SCH_LAYER_ID_END,
  420. /// Gerbview draw layers and d-code layers
  421. GERBVIEW_LAYER_ID_RESERVED = GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ),
  422. LAYER_DCODES,
  423. LAYER_NEGATIVE_OBJECTS,
  424. LAYER_GERBVIEW_GRID,
  425. LAYER_GERBVIEW_AXES,
  426. LAYER_GERBVIEW_BACKGROUND,
  427. LAYER_GERBVIEW_DRAWINGSHEET,
  428. LAYER_GERBVIEW_PAGE_LIMITS,
  429. GERBVIEW_LAYER_ID_END
  430. };
  431. #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
  432. #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
  433. #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
  434. /// 3D Viewer virtual layers for color settings
  435. enum LAYER_3D_ID : int
  436. {
  437. LAYER_3D_START = GERBVIEW_LAYER_ID_END,
  438. LAYER_3D_BACKGROUND_BOTTOM,
  439. LAYER_3D_BACKGROUND_TOP,
  440. LAYER_3D_BOARD,
  441. LAYER_3D_COPPER_TOP,
  442. LAYER_3D_COPPER_BOTTOM,
  443. LAYER_3D_SILKSCREEN_BOTTOM,
  444. LAYER_3D_SILKSCREEN_TOP,
  445. LAYER_3D_SOLDERMASK_BOTTOM,
  446. LAYER_3D_SOLDERMASK_TOP,
  447. LAYER_3D_SOLDERPASTE,
  448. LAYER_3D_ADHESIVE,
  449. LAYER_3D_USER_COMMENTS,
  450. LAYER_3D_USER_DRAWINGS,
  451. LAYER_3D_USER_ECO1,
  452. LAYER_3D_USER_ECO2,
  453. LAYER_3D_TH_MODELS,
  454. LAYER_3D_SMD_MODELS,
  455. LAYER_3D_VIRTUAL_MODELS,
  456. LAYER_3D_MODELS_NOT_IN_POS,
  457. LAYER_3D_MODELS_MARKED_DNP,
  458. LAYER_3D_AXES,
  459. LAYER_3D_BOUNDING_BOXES,
  460. LAYER_3D_OFF_BOARD_SILK,
  461. LAYER_3D_END
  462. };
  463. /// Must update this if you add any enums after Gerbview!
  464. #define LAYER_ID_COUNT LAYER_3D_END
  465. /**
  466. * Return the string equivalent of a given layer.
  467. *
  468. * @param aLayer is a valid layer ID.
  469. */
  470. KICOMMON_API wxString LayerName( int aLayer );
  471. // Some elements do not have yet a visibility control
  472. // from a dialog, but have a visibility control flag.
  473. // Here is a mask to set them visible, to be sure they are displayed
  474. // after loading a board for instance
  475. #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PAD_PLATEDHOLES ) ) +\
  476. ( 1 << GAL_LAYER_INDEX( LAYER_VIA_HOLES ) ) +\
  477. ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
  478. ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
  479. ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
  480. /**
  481. * Test whether a given integer is a valid layer index, i.e. can
  482. * be safely put in a #PCB_LAYER_ID.
  483. *
  484. * @param aLayerId = Layer index to test. It can be an int, so its useful during I/O
  485. * @return true if aLayerIndex is a valid layer index
  486. */
  487. inline bool IsValidLayer( int aLayerId )
  488. {
  489. return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
  490. }
  491. /**
  492. * Test whether a layer is a valid layer for Pcbnew
  493. *
  494. * @param aLayer = Layer to test
  495. * @return true if aLayer is a layer valid in Pcbnew
  496. */
  497. inline bool IsPcbLayer( int aLayer )
  498. {
  499. return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
  500. }
  501. /**
  502. * Test whether a layer is a copper layer.
  503. *
  504. * @param aLayerId = Layer to test
  505. * @return true if aLayer is a valid copper layer
  506. */
  507. inline bool IsCopperLayer( int aLayerId )
  508. {
  509. return !( aLayerId & 1 ) && aLayerId < PCB_LAYER_ID_COUNT && aLayerId >= 0;
  510. }
  511. /**
  512. * Test whether a layer is an external (#F_Cu or #B_Cu) copper layer.
  513. *
  514. * @param aLayerId = Layer to test
  515. * @return true if aLayer is a valid external copper layer
  516. */
  517. inline bool IsExternalCopperLayer( int aLayerId )
  518. {
  519. return aLayerId == F_Cu || aLayerId == B_Cu;
  520. }
  521. /**
  522. * Test whether a layer is an inner (#In1_Cu to #In30_Cu) copper layer.
  523. *
  524. * @param aLayerId = Layer to test
  525. * @return true if aLayer is a valid inner copper layer
  526. */
  527. inline bool IsInnerCopperLayer( int aLayerId )
  528. {
  529. return IsCopperLayer( aLayerId ) && !IsExternalCopperLayer( aLayerId );
  530. }
  531. /**
  532. * Test whether a layer is a non copper layer.
  533. *
  534. * @param aLayerId = Layer to test
  535. * @return true if aLayer is a non copper layer
  536. */
  537. inline bool IsNonCopperLayer( int aLayerId )
  538. {
  539. return ( aLayerId & 1 ) && aLayerId <= PCB_LAYER_ID_COUNT;
  540. }
  541. /**
  542. * Test whether a layer is a copper layer, optionally including synthetic copper layers such
  543. * as #LAYER_VIA_THROUGH, #LAYER_PADS_SMD_FR, etc.
  544. *
  545. * @param aLayerId
  546. * @param aIncludeSyntheticCopperLayers
  547. * @return
  548. */
  549. inline bool IsCopperLayer( int aLayerId, bool aIncludeSyntheticCopperLayers )
  550. {
  551. if( aIncludeSyntheticCopperLayers )
  552. return !IsNonCopperLayer( aLayerId );
  553. else
  554. return IsCopperLayer( aLayerId );
  555. }
  556. inline bool IsViaPadLayer( int aLayer )
  557. {
  558. return aLayer == LAYER_VIA_THROUGH
  559. || aLayer == LAYER_VIA_MICROVIA
  560. || aLayer == LAYER_VIA_BBLIND;
  561. }
  562. inline bool IsHoleLayer( int aLayer )
  563. {
  564. return aLayer == LAYER_VIA_HOLES
  565. || aLayer == LAYER_VIA_HOLEWALLS
  566. || aLayer == LAYER_PAD_PLATEDHOLES
  567. || aLayer == LAYER_PAD_HOLEWALLS
  568. || aLayer == LAYER_NON_PLATEDHOLES;
  569. }
  570. inline bool IsSolderMaskLayer( int aLayer )
  571. {
  572. return aLayer == F_Mask || aLayer == B_Mask;
  573. }
  574. /**
  575. * Test whether a layer is a non copper and a non tech layer.
  576. *
  577. * @param aLayerId = Layer to test
  578. * @return true if aLayer is a user layer
  579. */
  580. inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
  581. {
  582. return aLayerId == Dwgs_User || aLayerId == Cmts_User || aLayerId == Eco1_User
  583. || aLayerId == Eco2_User || ( aLayerId >= User_1 && !IsCopperLayer( aLayerId ) );
  584. }
  585. /*
  586. * IMPORTANT: If a layer is not a front layer that doesn't necessarily mean it's a back layer.
  587. *
  588. * So a layer can be:
  589. * - Front
  590. * - Back
  591. * - Neither (internal or auxiliary)
  592. *
  593. * The check most frequent is for back layers, since it involves flips.
  594. */
  595. /**
  596. * Layer classification: check if it's a front layer.
  597. */
  598. inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
  599. {
  600. switch( aLayerId )
  601. {
  602. case F_Cu:
  603. case F_Adhes:
  604. case F_Paste:
  605. case F_SilkS:
  606. case F_Mask:
  607. case F_CrtYd:
  608. case F_Fab:
  609. return true;
  610. default:
  611. ;
  612. }
  613. return false;
  614. }
  615. /**
  616. * Layer classification: check if it's a back layer.
  617. */
  618. inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
  619. {
  620. switch( aLayerId )
  621. {
  622. case B_Cu:
  623. case B_Adhes:
  624. case B_Paste:
  625. case B_SilkS:
  626. case B_Mask:
  627. case B_CrtYd:
  628. case B_Fab:
  629. return true;
  630. default:
  631. return false;
  632. }
  633. }
  634. /**
  635. * Return true if copper aLayerA is placed lower than aLayerB, false otherwise.
  636. */
  637. inline bool IsCopperLayerLowerThan( PCB_LAYER_ID aLayerA, PCB_LAYER_ID aLayerB )
  638. {
  639. if( aLayerA == aLayerB )
  640. return false;
  641. if( aLayerA == B_Cu )
  642. return true;
  643. if( aLayerB == B_Cu )
  644. return false;
  645. return aLayerA > aLayerB;
  646. }
  647. /**
  648. * @param aLayerId = the PCB_LAYER_ID to flip
  649. * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  650. * internal layers will be not flipped because the layer count is not known
  651. * @return the layer number after flipping an item
  652. * some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... )
  653. * are swapped between front and back sides
  654. * internal layers are flipped only if the copper layers count is known
  655. */
  656. KICOMMON_API PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
  657. /**
  658. * Return a netname layer corresponding to the given layer.
  659. */
  660. inline int GetNetnameLayer( int aLayer )
  661. {
  662. if( IsCopperLayer( aLayer ) || IsViaPadLayer( aLayer ) )
  663. return NETNAMES_LAYER_INDEX( aLayer );
  664. // Fallback
  665. return Cmts_User;
  666. }
  667. /**
  668. * Test whether a layer is a netname layer.
  669. *
  670. * @param aLayer = Layer to test
  671. * @return true if aLayer is a valid netname layer
  672. */
  673. inline bool IsNetnameLayer( int aLayer )
  674. {
  675. return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) && aLayer < NETNAMES_LAYER_ID_END;
  676. }
  677. inline bool IsZoneFillLayer( int aLayer )
  678. {
  679. return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
  680. }
  681. inline bool IsPadCopperLayer( int aLayer )
  682. {
  683. return aLayer >= LAYER_PAD_COPPER_START && aLayer <= LAYER_PAD_COPPER_END;
  684. }
  685. inline bool IsViaCopperLayer( int aLayer )
  686. {
  687. return aLayer >= LAYER_VIA_COPPER_START && aLayer <= LAYER_VIA_COPPER_END;
  688. }
  689. inline bool IsClearanceLayer( int aLayer )
  690. {
  691. return aLayer >= LAYER_CLEARANCE_START && aLayer <= LAYER_CLEARANCE_END;
  692. }
  693. inline bool IsDCodeLayer( int aLayer )
  694. {
  695. return aLayer >= ( GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT )
  696. && aLayer < ( GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ) );
  697. }
  698. /// Converts KiCad copper layer enum to an ordinal between the front and back layers.
  699. inline size_t CopperLayerToOrdinal( PCB_LAYER_ID aLayer )
  700. {
  701. wxCHECK( IsCopperLayer( aLayer ), 0 );
  702. switch( aLayer )
  703. {
  704. case F_Cu: return 0;
  705. case B_Cu: return MAX_CU_LAYERS - 1;
  706. default: return ( aLayer - B_Cu ) / 2;
  707. }
  708. }
  709. /**
  710. * Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
  711. */
  712. KICOMMON_API PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId );
  713. KICOMMON_API PCB_LAYER_ID ToLAYER_ID( int aLayer );
  714. #endif // LAYER_IDS_H