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.

754 lines
22 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 (C) 2007-2023 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. PCB_LAYER_ID_COUNT = 64
  119. };
  120. constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START = F_Cu;
  121. #define MAX_CU_LAYERS 32
  122. /**
  123. * Enum used during connectivity building to ensure we do not query connectivity while building
  124. * the database
  125. */
  126. enum class FLASHING
  127. {
  128. DEFAULT, // Flashing follows connectivity
  129. ALWAYS_FLASHED, // Always flashed for connectivity
  130. NEVER_FLASHED, // Never flashed for connectivity
  131. };
  132. /// Dedicated layers for net names used in Pcbnew
  133. enum NETNAMES_LAYER_ID: int
  134. {
  135. NETNAMES_LAYER_ID_START = PCB_LAYER_ID_COUNT,
  136. /// Reserved space for board layer netnames
  137. NETNAMES_LAYER_ID_RESERVED = NETNAMES_LAYER_ID_START + PCB_LAYER_ID_COUNT,
  138. /// Additional netnames layers (not associated with a PCB layer)
  139. LAYER_PAD_FR_NETNAMES,
  140. LAYER_PAD_BK_NETNAMES,
  141. LAYER_PAD_NETNAMES,
  142. LAYER_VIA_NETNAMES,
  143. NETNAMES_LAYER_ID_END
  144. };
  145. /// Macro for obtaining netname layer for a given PCB layer
  146. #define NETNAMES_LAYER_INDEX( layer ) ( static_cast<int>( NETNAMES_LAYER_ID_START ) + layer )
  147. #define GAL_UI_LAYER_COUNT 10
  148. /**
  149. * GAL layers are "virtual" layers, i.e. not tied into design data.
  150. * Some layers here are shared between applications.
  151. *
  152. * NOTE: Be very careful where you add new layers here. Layers up to GAL_LAYER_ID_BITMASK_END
  153. * must never be re-ordered and new layers must always be added after this value, because the
  154. * layers before this value are mapped to bit locations in legacy board files.
  155. *
  156. * The values in this enum that are used to store visibility state are explicitly encoded with an
  157. * offset from GAL_LAYER_ID_START, which is explicitly encoded itself. The exact value of
  158. * GAL_LAYER_ID_START is not that sensitive, but the offsets should never be changed or else any
  159. * existing visibility settings will be disrupted.
  160. */
  161. enum GAL_LAYER_ID: int
  162. {
  163. GAL_LAYER_ID_START = NETNAMES_LAYER_ID_END,
  164. LAYER_VIAS = GAL_LAYER_ID_START + 0, ///< Meta control for all vias opacity/visibility
  165. LAYER_VIA_MICROVIA = GAL_LAYER_ID_START + 1, ///< to draw micro vias
  166. LAYER_VIA_BBLIND = GAL_LAYER_ID_START + 2, ///< to draw blind/buried vias
  167. LAYER_VIA_THROUGH = GAL_LAYER_ID_START + 3, ///< to draw usual through hole vias
  168. LAYER_NON_PLATEDHOLES = GAL_LAYER_ID_START + 4, ///< handle color for not plated holes (holes, not pads)
  169. LAYER_FP_TEXT = GAL_LAYER_ID_START + 5,
  170. // LAYER_MOD_TEXT_BK deprecated + 6,
  171. // LAYER_HIDDEN_TEXT = GAL_LAYER_ID_START + 7, ///< DEPRECATED, UNUSED SINCE 9.0. text marked as invisible
  172. LAYER_ANCHOR = GAL_LAYER_ID_START + 8, ///< anchor of items having an anchor point (texts, footprints)
  173. LAYER_PADS_SMD_FR = GAL_LAYER_ID_START + 9, ///< smd pads, front layer
  174. LAYER_PADS_SMD_BK = GAL_LAYER_ID_START + 10, ///< smd pads, back layer
  175. LAYER_RATSNEST = GAL_LAYER_ID_START + 11,
  176. LAYER_GRID = GAL_LAYER_ID_START + 12,
  177. LAYER_GRID_AXES = GAL_LAYER_ID_START + 13,
  178. // LAYER_NO_CONNECTS deprecated + 14, ///< show a marker on pads with no nets
  179. LAYER_FOOTPRINTS_FR = GAL_LAYER_ID_START + 15, ///< show footprints on front
  180. LAYER_FOOTPRINTS_BK = GAL_LAYER_ID_START + 16, ///< show footprints on back
  181. LAYER_FP_VALUES = GAL_LAYER_ID_START + 17, ///< show footprints values (when texts are visible)
  182. LAYER_FP_REFERENCES = GAL_LAYER_ID_START + 18, ///< show footprints references (when texts are visible)
  183. LAYER_TRACKS = GAL_LAYER_ID_START + 19,
  184. LAYER_PADS_TH = GAL_LAYER_ID_START + 20, ///< multilayer pads, usually with holes
  185. LAYER_PAD_PLATEDHOLES = GAL_LAYER_ID_START + 21, ///< to draw pad holes (plated)
  186. LAYER_VIA_HOLES = GAL_LAYER_ID_START + 22, ///< to draw via holes (pad holes do not use this layer)
  187. LAYER_DRC_ERROR = GAL_LAYER_ID_START + 23, ///< layer for drc markers with SEVERITY_ERROR
  188. LAYER_DRAWINGSHEET = GAL_LAYER_ID_START + 24, ///< drawingsheet frame and titleblock
  189. LAYER_GP_OVERLAY = GAL_LAYER_ID_START + 25, ///< general purpose overlay
  190. LAYER_SELECT_OVERLAY = GAL_LAYER_ID_START + 26, ///< currently selected items overlay
  191. LAYER_PCB_BACKGROUND = GAL_LAYER_ID_START + 27, ///< PCB background color
  192. LAYER_CURSOR = GAL_LAYER_ID_START + 28, ///< PCB cursor
  193. LAYER_AUX_ITEMS = GAL_LAYER_ID_START + 29, ///< Auxiliary items (guides, rule, etc)
  194. LAYER_DRAW_BITMAPS = GAL_LAYER_ID_START + 30, ///< to handle and draw images bitmaps
  195. /// This is the end of the layers used for visibility bit masks in legacy board files
  196. GAL_LAYER_ID_BITMASK_END = GAL_LAYER_ID_START + 31,
  197. // Layers in this section have visibility controls but were not present in legacy board files.
  198. LAYER_PADS = GAL_LAYER_ID_START + 32, ///< Meta control for all pads opacity/visibility (color ignored)
  199. LAYER_ZONES = GAL_LAYER_ID_START + 33, ///< Control for copper zone opacity/visibility (color ignored)
  200. LAYER_PAD_HOLEWALLS = GAL_LAYER_ID_START + 34,
  201. LAYER_VIA_HOLEWALLS = GAL_LAYER_ID_START + 35,
  202. LAYER_DRC_WARNING = GAL_LAYER_ID_START + 36, ///< layer for drc markers with SEVERITY_WARNING
  203. LAYER_DRC_EXCLUSION = GAL_LAYER_ID_START + 37, ///< layer for drc markers which have been individually excluded
  204. LAYER_MARKER_SHADOWS = GAL_LAYER_ID_START + 38, ///< shadows for drc markers
  205. LAYER_LOCKED_ITEM_SHADOW = GAL_LAYER_ID_START + 39, ///< shadow layer for locked items
  206. LAYER_CONFLICTS_SHADOW = GAL_LAYER_ID_START + 40, ///< shadow layer for items flagged conficting
  207. LAYER_SHAPES = GAL_LAYER_ID_START + 41, ///< Copper graphic shape opacity/visibility (color ignored)
  208. LAYER_DRC_SHAPE1 = GAL_LAYER_ID_START + 42, ///< Custom shape for DRC marker
  209. LAYER_DRC_SHAPE2 = GAL_LAYER_ID_START + 43, ///< Custom shape for DRC marker
  210. // Add layers below this point that do not have visibility controls, so don't need explicit
  211. // enum values
  212. LAYER_DRAWINGSHEET_PAGE1, ///< for drawingsheetEditor previewing
  213. LAYER_DRAWINGSHEET_PAGEn, ///< for drawingsheetEditor previewing
  214. LAYER_PAGE_LIMITS, ///< color for drawing the page extents (visibility stored in
  215. ///< PCBNEW_SETTINGS::m_ShowPageLimits)
  216. /// Virtual layers for stacking zones and tracks on a given copper layer
  217. LAYER_ZONE_START,
  218. LAYER_ZONE_END = LAYER_ZONE_START + PCB_LAYER_ID_COUNT,
  219. /// Virtual layers for background images per board layer
  220. LAYER_BITMAP_START,
  221. LAYER_BITMAP_END = LAYER_BITMAP_START + PCB_LAYER_ID_COUNT,
  222. // Layers for drawing on-canvas UI
  223. LAYER_UI_START,
  224. LAYER_UI_END = LAYER_UI_START + GAL_UI_LAYER_COUNT,
  225. GAL_LAYER_ID_END
  226. };
  227. /// Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS
  228. #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
  229. /// Macros for getting the extra layers for a given board layer
  230. #define BITMAP_LAYER_FOR( boardLayer ) ( LAYER_BITMAP_START + boardLayer )
  231. #define ZONE_LAYER_FOR( boardLayer ) ( LAYER_ZONE_START + boardLayer )
  232. constexpr int GAL_LAYER_ID_COUNT = GAL_LAYER_ID_END - GAL_LAYER_ID_START;
  233. inline GAL_LAYER_ID operator++( GAL_LAYER_ID& a )
  234. {
  235. a = GAL_LAYER_ID( int( a ) + 1 );
  236. return a;
  237. }
  238. inline GAL_LAYER_ID ToGalLayer( int aInteger )
  239. {
  240. wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
  241. return static_cast<GAL_LAYER_ID>( aInteger );
  242. }
  243. /// Used for via types
  244. inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
  245. {
  246. GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
  247. wxASSERT( t <= GAL_LAYER_ID_END );
  248. return t;
  249. }
  250. /// @brief Wraps a std::bitset
  251. typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
  252. /// Helper for storing and iterating over GAL_LAYER_IDs
  253. class KICOMMON_API GAL_SET : public GAL_BASE_SET
  254. {
  255. private:
  256. static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
  257. public:
  258. GAL_SET() : std::bitset<GAL_LAYER_ID_COUNT>()
  259. {
  260. }
  261. GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
  262. {
  263. }
  264. GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
  265. GAL_SET& set()
  266. {
  267. GAL_BASE_SET::set();
  268. return *this;
  269. }
  270. GAL_SET& set( int aPos, bool aVal = true )
  271. {
  272. GAL_BASE_SET::set( aPos, aVal );
  273. return *this;
  274. }
  275. GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
  276. {
  277. GAL_BASE_SET::set( static_cast<std::size_t>( aPos ) - start, aVal );
  278. return *this;
  279. }
  280. bool Contains( GAL_LAYER_ID aPos )
  281. {
  282. return test( static_cast<std::size_t>( aPos ) - start );
  283. }
  284. std::vector<GAL_LAYER_ID> Seq() const;
  285. static GAL_SET DefaultVisible();
  286. };
  287. /// Eeschema drawing layers
  288. enum SCH_LAYER_ID : int
  289. {
  290. SCH_LAYER_ID_START = GAL_LAYER_ID_END,
  291. LAYER_WIRE = SCH_LAYER_ID_START,
  292. LAYER_BUS,
  293. LAYER_JUNCTION,
  294. LAYER_LOCLABEL,
  295. LAYER_GLOBLABEL,
  296. LAYER_HIERLABEL,
  297. LAYER_PINNUM,
  298. LAYER_PINNAM,
  299. LAYER_REFERENCEPART,
  300. LAYER_VALUEPART,
  301. LAYER_FIELDS,
  302. LAYER_INTERSHEET_REFS,
  303. LAYER_NETCLASS_REFS,
  304. LAYER_RULE_AREAS,
  305. LAYER_DEVICE,
  306. LAYER_NOTES,
  307. LAYER_PRIVATE_NOTES,
  308. LAYER_NOTES_BACKGROUND,
  309. LAYER_PIN,
  310. LAYER_SHEET,
  311. LAYER_SHEETNAME,
  312. LAYER_SHEETFILENAME,
  313. LAYER_SHEETFIELDS,
  314. LAYER_SHEETLABEL,
  315. LAYER_NOCONNECT,
  316. LAYER_DANGLING,
  317. LAYER_DNP_MARKER,
  318. LAYER_ERC_WARN,
  319. LAYER_ERC_ERR,
  320. LAYER_ERC_EXCLUSION,
  321. LAYER_EXCLUDED_FROM_SIM,
  322. LAYER_DEVICE_BACKGROUND,
  323. LAYER_SHEET_BACKGROUND,
  324. LAYER_SCHEMATIC_GRID,
  325. LAYER_SCHEMATIC_GRID_AXES,
  326. LAYER_SCHEMATIC_BACKGROUND,
  327. LAYER_SCHEMATIC_CURSOR,
  328. LAYER_HOVERED,
  329. LAYER_BRIGHTENED,
  330. LAYER_HIDDEN,
  331. LAYER_NET_COLOR_HIGHLIGHT,
  332. LAYER_SELECTION_SHADOWS,
  333. LAYER_SCHEMATIC_DRAWINGSHEET,
  334. LAYER_SCHEMATIC_PAGE_LIMITS,
  335. LAYER_BUS_JUNCTION,
  336. LAYER_SCHEMATIC_AUX_ITEMS,
  337. LAYER_SCHEMATIC_ANCHOR,
  338. LAYER_OP_VOLTAGES,
  339. LAYER_OP_CURRENTS,
  340. SCH_LAYER_ID_END
  341. };
  342. #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
  343. #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
  344. inline SCH_LAYER_ID operator++( SCH_LAYER_ID& a )
  345. {
  346. a = SCH_LAYER_ID( int( a ) + 1 );
  347. return a;
  348. }
  349. // number of draw layers in Gerbview
  350. #define GERBER_DRAWLAYERS_COUNT static_cast<int>( PCB_LAYER_ID_COUNT )
  351. /// GerbView draw layers
  352. enum GERBVIEW_LAYER_ID: int
  353. {
  354. GERBVIEW_LAYER_ID_START = SCH_LAYER_ID_END,
  355. /// GerbView draw layers and d-code layers
  356. GERBVIEW_LAYER_ID_RESERVED = GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ),
  357. LAYER_DCODES,
  358. LAYER_NEGATIVE_OBJECTS,
  359. LAYER_GERBVIEW_GRID,
  360. LAYER_GERBVIEW_AXES,
  361. LAYER_GERBVIEW_BACKGROUND,
  362. LAYER_GERBVIEW_DRAWINGSHEET,
  363. LAYER_GERBVIEW_PAGE_LIMITS,
  364. GERBVIEW_LAYER_ID_END
  365. };
  366. #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
  367. #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
  368. #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
  369. /// 3D Viewer virtual layers for color settings
  370. enum LAYER_3D_ID : int
  371. {
  372. LAYER_3D_START = GERBVIEW_LAYER_ID_END,
  373. LAYER_3D_BACKGROUND_BOTTOM,
  374. LAYER_3D_BACKGROUND_TOP,
  375. LAYER_3D_BOARD,
  376. LAYER_3D_COPPER_TOP,
  377. LAYER_3D_COPPER_BOTTOM,
  378. LAYER_3D_SILKSCREEN_BOTTOM,
  379. LAYER_3D_SILKSCREEN_TOP,
  380. LAYER_3D_SOLDERMASK_BOTTOM,
  381. LAYER_3D_SOLDERMASK_TOP,
  382. LAYER_3D_SOLDERPASTE,
  383. LAYER_3D_ADHESIVE,
  384. LAYER_3D_USER_COMMENTS,
  385. LAYER_3D_USER_DRAWINGS,
  386. LAYER_3D_USER_ECO1,
  387. LAYER_3D_USER_ECO2,
  388. LAYER_3D_TH_MODELS,
  389. LAYER_3D_SMD_MODELS,
  390. LAYER_3D_VIRTUAL_MODELS,
  391. LAYER_3D_MODELS_NOT_IN_POS,
  392. LAYER_3D_MODELS_MARKED_DNP,
  393. LAYER_3D_AXES,
  394. LAYER_3D_BOUNDING_BOXES,
  395. LAYER_3D_OFF_BOARD_SILK,
  396. LAYER_3D_END
  397. };
  398. /// Must update this if you add any enums after GerbView!
  399. #define LAYER_ID_COUNT LAYER_3D_END
  400. /**
  401. * Returns the string equivalent of a given layer
  402. * @param aLayer is a valid layer ID
  403. */
  404. KICOMMON_API wxString LayerName( int aLayer );
  405. // Some elements do not have yet a visibility control
  406. // from a dialog, but have a visibility control flag.
  407. // Here is a mask to set them visible, to be sure they are displayed
  408. // after loading a board for instance
  409. #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PAD_PLATEDHOLES ) ) +\
  410. ( 1 << GAL_LAYER_INDEX( LAYER_VIA_HOLES ) ) +\
  411. ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
  412. ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
  413. ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
  414. /**
  415. * Test whether a given integer is a valid layer index, i.e. can
  416. * be safely put in a PCB_LAYER_ID
  417. *
  418. * @param aLayerId = Layer index to test. It can be an int, so its useful during I/O
  419. * @return true if aLayerIndex is a valid layer index
  420. */
  421. inline bool IsValidLayer( int aLayerId )
  422. {
  423. return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
  424. }
  425. /**
  426. * Test whether a layer is a valid layer for Pcbnew
  427. *
  428. * @param aLayer = Layer to test
  429. * @return true if aLayer is a layer valid in Pcbnew
  430. */
  431. inline bool IsPcbLayer( int aLayer )
  432. {
  433. return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
  434. }
  435. /**
  436. * Tests whether a layer is a copper layer.
  437. *
  438. * @param aLayerId = Layer to test
  439. * @return true if aLayer is a valid copper layer
  440. */
  441. inline bool IsCopperLayer( int aLayerId )
  442. {
  443. return !( aLayerId & 1 ) && aLayerId <= PCB_LAYER_ID_COUNT;
  444. }
  445. /**
  446. * Tests whether a layer is an external (F_Cu or B_Cu) copper layer.
  447. *
  448. * @param aLayerId = Layer to test
  449. * @return true if aLayer is a valid external copper layer
  450. */
  451. inline bool IsExternalCopperLayer( int aLayerId )
  452. {
  453. return aLayerId == F_Cu || aLayerId == B_Cu;
  454. }
  455. /**
  456. * Test whether a layer is a non copper layer.
  457. *
  458. * @param aLayerId = Layer to test
  459. * @return true if aLayer is a non copper layer
  460. */
  461. inline bool IsNonCopperLayer( int aLayerId )
  462. {
  463. return ( aLayerId & 1 ) && aLayerId <= PCB_LAYER_ID_COUNT;
  464. }
  465. /**
  466. * Tests whether a layer is a copper layer, optionally including synthetic copper layers such
  467. * as LAYER_VIA_THROUGH, LAYER_PADS_SMD_FR, etc.
  468. *
  469. * @param aLayerId
  470. * @param aIncludeSyntheticCopperLayers
  471. * @return
  472. */
  473. inline bool IsCopperLayer( int aLayerId, bool aIncludeSyntheticCopperLayers )
  474. {
  475. if( aIncludeSyntheticCopperLayers )
  476. return !IsNonCopperLayer( aLayerId );
  477. else
  478. return IsCopperLayer( aLayerId );
  479. }
  480. inline bool IsViaPadLayer( int aLayer )
  481. {
  482. return aLayer == LAYER_VIA_THROUGH
  483. || aLayer == LAYER_VIA_MICROVIA
  484. || aLayer == LAYER_VIA_BBLIND;
  485. }
  486. inline bool IsHoleLayer( int aLayer )
  487. {
  488. return aLayer == LAYER_VIA_HOLES
  489. || aLayer == LAYER_VIA_HOLEWALLS
  490. || aLayer == LAYER_PAD_PLATEDHOLES
  491. || aLayer == LAYER_PAD_HOLEWALLS
  492. || aLayer == LAYER_NON_PLATEDHOLES;
  493. }
  494. inline bool IsSolderMaskLayer( int aLayer )
  495. {
  496. return aLayer == F_Mask || aLayer == B_Mask;
  497. }
  498. /**
  499. * Test whether a layer is a non copper and a non tech layer.
  500. *
  501. * @param aLayerId = Layer to test
  502. * @return true if aLayer is a user layer
  503. */
  504. inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
  505. {
  506. return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
  507. }
  508. /*
  509. * IMPORTANT: If a layer is not a front layer that doesn't necessarily mean it's a back layer.
  510. *
  511. * So a layer can be:
  512. * - Front
  513. * - Back
  514. * - Neither (internal or auxiliary)
  515. *
  516. * The check most frequent is for back layers, since it involves flips.
  517. */
  518. /**
  519. * Layer classification: check if it's a front layer
  520. */
  521. inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
  522. {
  523. switch( aLayerId )
  524. {
  525. case F_Cu:
  526. case F_Adhes:
  527. case F_Paste:
  528. case F_SilkS:
  529. case F_Mask:
  530. case F_CrtYd:
  531. case F_Fab:
  532. return true;
  533. default:
  534. ;
  535. }
  536. return false;
  537. }
  538. /**
  539. * Layer classification: check if it's a back layer
  540. */
  541. inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
  542. {
  543. switch( aLayerId )
  544. {
  545. case B_Cu:
  546. case B_Adhes:
  547. case B_Paste:
  548. case B_SilkS:
  549. case B_Mask:
  550. case B_CrtYd:
  551. case B_Fab:
  552. return true;
  553. default:
  554. return false;
  555. }
  556. }
  557. /**
  558. * Returns true if copper aLayerA is placed lower than aLayerB, false otherwise.
  559. */
  560. inline bool IsCopperLayerLowerThan( PCB_LAYER_ID aLayerA, PCB_LAYER_ID aLayerB )
  561. {
  562. if( aLayerA == aLayerB )
  563. return false;
  564. if( aLayerA == B_Cu )
  565. return true;
  566. if( aLayerB == B_Cu )
  567. return false;
  568. return aLayerA > aLayerB;
  569. }
  570. /**
  571. * @return the layer number after flipping an item
  572. * some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... )
  573. * are swapped between front and back sides
  574. * internal layers are flipped only if the copper layers count is known
  575. * @param aLayerId = the PCB_LAYER_ID to flip
  576. * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  577. * internal layers will be not flipped because the layer count is not known
  578. */
  579. KICOMMON_API PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
  580. /**
  581. * Returns a netname layer corresponding to the given layer.
  582. */
  583. inline int GetNetnameLayer( int aLayer )
  584. {
  585. if( IsCopperLayer( aLayer ) )
  586. return NETNAMES_LAYER_INDEX( aLayer );
  587. else if( aLayer == LAYER_PADS_TH )
  588. return LAYER_PAD_NETNAMES;
  589. else if( aLayer == LAYER_PADS_SMD_FR )
  590. return LAYER_PAD_FR_NETNAMES;
  591. else if( aLayer == LAYER_PADS_SMD_BK )
  592. return LAYER_PAD_BK_NETNAMES;
  593. else if( IsViaPadLayer( aLayer ) )
  594. return LAYER_VIA_NETNAMES;
  595. // Fallback
  596. return Cmts_User;
  597. }
  598. /**
  599. * Test whether a layer is a netname layer.
  600. *
  601. * @param aLayer = Layer to test
  602. * @return true if aLayer is a valid netname layer
  603. */
  604. inline bool IsNetnameLayer( int aLayer )
  605. {
  606. return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) && aLayer < NETNAMES_LAYER_ID_END;
  607. }
  608. inline bool IsZoneFillLayer( int aLayer )
  609. {
  610. return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
  611. }
  612. inline bool IsDCodeLayer( int aLayer )
  613. {
  614. return aLayer >= ( GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT )
  615. && aLayer < ( GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ) );
  616. }
  617. ///! Converts KiCad copper layer enum to an ordinal between the front and back layers
  618. inline size_t CopperLayerToOrdinal( PCB_LAYER_ID aLayer )
  619. {
  620. wxCHECK( IsCopperLayer( aLayer ), 0 );
  621. switch( aLayer )
  622. {
  623. case F_Cu: return 0;
  624. case B_Cu: return MAX_CU_LAYERS - 1;
  625. default: return ( aLayer - B_Cu ) / 2;
  626. }
  627. }
  628. KICOMMON_API PCB_LAYER_ID ToLAYER_ID( int aLayer );
  629. #endif // LAYER_IDS_H