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.

1041 lines
30 KiB

12 years ago
12 years ago
12 years ago
12 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
4 years ago
12 years ago
4 years ago
4 years ago
4 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-2022 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. /**
  33. * A quick note on layer IDs:
  34. *
  35. * The layers are stored in separate enums so that certain functions can
  36. * take in the enums as data types and don't have to know about layers from
  37. * other applications.
  38. *
  39. * Layers that are shared between applications should be in the GAL_LAYER_ID enum.
  40. *
  41. * The PCB_LAYER_ID struct must start at zero for compatibility with legacy board files.
  42. *
  43. * Some functions accept any layer ID, so they start at zero (i.e. F_Cu) and go up to
  44. * the LAYER_ID_COUNT, which needs to be kept up-to-date if new enums are added.
  45. */
  46. /**
  47. * This is the definition of all layers used in Pcbnew.
  48. *
  49. * The PCB layer types are fixed at value 0 through LAYER_ID_COUNT to ensure compatibility
  50. * with legacy board files.
  51. */
  52. enum PCB_LAYER_ID: int
  53. {
  54. UNDEFINED_LAYER = -1,
  55. UNSELECTED_LAYER = -2,
  56. PCBNEW_LAYER_ID_START = 0,
  57. F_Cu = PCBNEW_LAYER_ID_START,
  58. In1_Cu,
  59. In2_Cu,
  60. In3_Cu,
  61. In4_Cu,
  62. In5_Cu,
  63. In6_Cu,
  64. In7_Cu,
  65. In8_Cu,
  66. In9_Cu,
  67. In10_Cu,
  68. In11_Cu,
  69. In12_Cu,
  70. In13_Cu,
  71. In14_Cu,
  72. In15_Cu,
  73. In16_Cu,
  74. In17_Cu,
  75. In18_Cu,
  76. In19_Cu,
  77. In20_Cu,
  78. In21_Cu,
  79. In22_Cu,
  80. In23_Cu,
  81. In24_Cu,
  82. In25_Cu,
  83. In26_Cu,
  84. In27_Cu,
  85. In28_Cu,
  86. In29_Cu,
  87. In30_Cu,
  88. B_Cu, // 31
  89. B_Adhes,
  90. F_Adhes,
  91. B_Paste,
  92. F_Paste,
  93. B_SilkS,
  94. F_SilkS,
  95. B_Mask,
  96. F_Mask, // 39
  97. Dwgs_User,
  98. Cmts_User,
  99. Eco1_User,
  100. Eco2_User,
  101. Edge_Cuts,
  102. Margin, // 45
  103. B_CrtYd,
  104. F_CrtYd,
  105. B_Fab,
  106. F_Fab, // 49
  107. // User definable layers.
  108. User_1,
  109. User_2,
  110. User_3,
  111. User_4,
  112. User_5,
  113. User_6,
  114. User_7,
  115. User_8,
  116. User_9,
  117. Rescue, // 59
  118. // Four reserved layers (60 - 63) for future expansion within the 64 bit integer limit.
  119. PCB_LAYER_ID_COUNT
  120. };
  121. #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
  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 ) ( NETNAMES_LAYER_ID_START + layer )
  147. /**
  148. * GAL layers are "virtual" layers, i.e. not tied into design data.
  149. * Some layers here are shared between applications.
  150. *
  151. * NOTE: Be very careful where you add new layers here. Layers up to GAL_LAYER_ID_BITMASK_END
  152. * must never be re-ordered and new layers must always be added after this value, because the
  153. * layers before this value are mapped to bit locations in legacy board files.
  154. *
  155. * The values in this enum that are used to store visibility state are explicitly encoded with an
  156. * offset from GAL_LAYER_ID_START, which is explicitly encoded itself. The exact value of
  157. * GAL_LAYER_ID_START is not that sensitive, but the offsets should never be changed or else any
  158. * existing visibility settings will be disrupted.
  159. */
  160. enum GAL_LAYER_ID: int
  161. {
  162. GAL_LAYER_ID_START = NETNAMES_LAYER_ID_END,
  163. LAYER_VIAS = GAL_LAYER_ID_START + 0, ///< Meta control for all vias opacity/visibility
  164. LAYER_VIA_MICROVIA = GAL_LAYER_ID_START + 1, ///< to draw micro vias
  165. LAYER_VIA_BBLIND = GAL_LAYER_ID_START + 2, ///< to draw blind/buried vias
  166. LAYER_VIA_THROUGH = GAL_LAYER_ID_START + 3, ///< to draw usual through hole vias
  167. LAYER_NON_PLATEDHOLES = GAL_LAYER_ID_START + 4, ///< handle color for not plated holes (holes, not pads)
  168. LAYER_FP_TEXT = GAL_LAYER_ID_START + 5,
  169. // LAYER_MOD_TEXT_BK deprecated + 6,
  170. LAYER_HIDDEN_TEXT = GAL_LAYER_ID_START + 7, ///< text marked as invisible
  171. LAYER_ANCHOR = GAL_LAYER_ID_START + 8, ///< anchor of items having an anchor point (texts, footprints)
  172. LAYER_PADS_SMD_FR = GAL_LAYER_ID_START + 9, ///< smd pads, front layer
  173. LAYER_PADS_SMD_BK = GAL_LAYER_ID_START + 10, ///< smd pads, back layer
  174. LAYER_RATSNEST = GAL_LAYER_ID_START + 11,
  175. LAYER_GRID = GAL_LAYER_ID_START + 12,
  176. LAYER_GRID_AXES = GAL_LAYER_ID_START + 13,
  177. // LAYER_NO_CONNECTS deprecated + 14, ///< show a marker on pads with no nets
  178. LAYER_FOOTPRINTS_FR = GAL_LAYER_ID_START + 15, ///< show footprints on front
  179. LAYER_FOOTPRINTS_BK = GAL_LAYER_ID_START + 16, ///< show footprints on back
  180. LAYER_FP_VALUES = GAL_LAYER_ID_START + 17, ///< show footprints values (when texts are visible)
  181. LAYER_FP_REFERENCES = GAL_LAYER_ID_START + 18, ///< show footprints references (when texts are visible)
  182. LAYER_TRACKS = GAL_LAYER_ID_START + 19,
  183. LAYER_PADS_TH = GAL_LAYER_ID_START + 20, ///< multilayer pads, usually with holes
  184. LAYER_PAD_PLATEDHOLES = GAL_LAYER_ID_START + 21, ///< to draw pad holes (plated)
  185. LAYER_VIA_HOLES = GAL_LAYER_ID_START + 22, ///< to draw via holes (pad holes do not use this layer)
  186. LAYER_DRC_ERROR = GAL_LAYER_ID_START + 23, ///< layer for drc markers with SEVERITY_ERROR
  187. LAYER_DRAWINGSHEET = GAL_LAYER_ID_START + 24, ///< drawingsheet frame and titleblock
  188. LAYER_GP_OVERLAY = GAL_LAYER_ID_START + 25, ///< general purpose overlay
  189. LAYER_SELECT_OVERLAY = GAL_LAYER_ID_START + 26, ///< currently selected items overlay
  190. LAYER_PCB_BACKGROUND = GAL_LAYER_ID_START + 27, ///< PCB background color
  191. LAYER_CURSOR = GAL_LAYER_ID_START + 28, ///< PCB cursor
  192. LAYER_AUX_ITEMS = GAL_LAYER_ID_START + 29, ///< Auxiliary items (guides, rule, etc)
  193. LAYER_DRAW_BITMAPS = GAL_LAYER_ID_START + 30, ///< to handle and draw images bitmaps
  194. /// This is the end of the layers used for visibility bit masks in legacy board files
  195. GAL_LAYER_ID_BITMASK_END = GAL_LAYER_ID_START + 31,
  196. // Layers in this section have visibility controls but were not present in legacy board files.
  197. LAYER_PADS = GAL_LAYER_ID_START + 32, ///< Meta control for all pads opacity/visibility (color ignored)
  198. LAYER_ZONES = GAL_LAYER_ID_START + 33, ///< Control for copper zone opacity/visibility (color ignored)
  199. LAYER_PAD_HOLEWALLS = GAL_LAYER_ID_START + 34,
  200. LAYER_VIA_HOLEWALLS = GAL_LAYER_ID_START + 35,
  201. LAYER_DRC_WARNING = GAL_LAYER_ID_START + 36, ///< layer for drc markers with SEVERITY_WARNING
  202. LAYER_DRC_EXCLUSION = GAL_LAYER_ID_START + 37, ///< layer for drc markers which have been individually excluded
  203. LAYER_MARKER_SHADOWS = GAL_LAYER_ID_START + 38, ///< shadows for drc markers
  204. LAYER_LOCKED_ITEM_SHADOW = GAL_LAYER_ID_START + 39, ///< shadow layer for locked items
  205. LAYER_CONFLICTS_SHADOW = GAL_LAYER_ID_START + 40, ///< shadow layer for items flagged conficting
  206. // Add layers below this point that do not have visibility controls, so don't need explicit
  207. // enum values
  208. LAYER_DRAWINGSHEET_PAGE1, ///< for drawingsheetEditor previewing
  209. LAYER_DRAWINGSHEET_PAGEn, ///< for drawingsheetEditor previewing
  210. LAYER_PAGE_LIMITS, ///< color for drawing the page extents (visibility stored in
  211. ///< PCBNEW_SETTINGS::m_ShowPageLimits)
  212. /// Virtual layers for stacking zones and tracks on a given copper layer
  213. LAYER_ZONE_START,
  214. LAYER_ZONE_END = LAYER_ZONE_START + PCB_LAYER_ID_COUNT,
  215. /// Virtual layers for background images per board layer
  216. LAYER_BITMAP_START,
  217. LAYER_BITMAP_END = LAYER_BITMAP_START + PCB_LAYER_ID_COUNT,
  218. GAL_LAYER_ID_END
  219. };
  220. /// Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS
  221. #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
  222. /// Macros for getting the extra layers for a given board layer
  223. #define BITMAP_LAYER_FOR( boardLayer ) ( LAYER_BITMAP_START + boardLayer )
  224. #define ZONE_LAYER_FOR( boardLayer ) ( LAYER_ZONE_START + boardLayer )
  225. constexpr int GAL_LAYER_ID_COUNT = GAL_LAYER_ID_END - GAL_LAYER_ID_START;
  226. inline GAL_LAYER_ID operator++( GAL_LAYER_ID& a )
  227. {
  228. a = GAL_LAYER_ID( int( a ) + 1 );
  229. return a;
  230. }
  231. inline GAL_LAYER_ID ToGalLayer( int aInteger )
  232. {
  233. wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
  234. return static_cast<GAL_LAYER_ID>( aInteger );
  235. }
  236. /// Used for via types
  237. inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
  238. {
  239. GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
  240. wxASSERT( t <= GAL_LAYER_ID_END );
  241. return t;
  242. }
  243. /// @brief Wraps a std::bitset
  244. typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
  245. /// Helper for storing and iterating over GAL_LAYER_IDs
  246. class GAL_SET : public GAL_BASE_SET
  247. {
  248. private:
  249. static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
  250. public:
  251. GAL_SET() : std::bitset<GAL_LAYER_ID_COUNT>()
  252. {
  253. }
  254. GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
  255. {
  256. }
  257. GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
  258. GAL_SET& set()
  259. {
  260. GAL_BASE_SET::set();
  261. return *this;
  262. }
  263. GAL_SET& set( int aPos, bool aVal = true )
  264. {
  265. GAL_BASE_SET::set( aPos, aVal );
  266. return *this;
  267. }
  268. GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
  269. {
  270. GAL_BASE_SET::set( static_cast<std::size_t>( aPos ) - start, aVal );
  271. return *this;
  272. }
  273. bool Contains( GAL_LAYER_ID aPos )
  274. {
  275. return test( static_cast<std::size_t>( aPos ) - start );
  276. }
  277. std::vector<GAL_LAYER_ID> Seq() const;
  278. static GAL_SET DefaultVisible();
  279. };
  280. /// Eeschema drawing layers
  281. enum SCH_LAYER_ID: int
  282. {
  283. SCH_LAYER_ID_START = GAL_LAYER_ID_END,
  284. LAYER_WIRE = SCH_LAYER_ID_START,
  285. LAYER_BUS,
  286. LAYER_JUNCTION,
  287. LAYER_LOCLABEL,
  288. LAYER_GLOBLABEL,
  289. LAYER_HIERLABEL,
  290. LAYER_PINNUM,
  291. LAYER_PINNAM,
  292. LAYER_REFERENCEPART,
  293. LAYER_VALUEPART,
  294. LAYER_FIELDS,
  295. LAYER_INTERSHEET_REFS,
  296. LAYER_NETCLASS_REFS,
  297. LAYER_DEVICE,
  298. LAYER_NOTES,
  299. LAYER_PRIVATE_NOTES,
  300. LAYER_NOTES_BACKGROUND,
  301. LAYER_PIN,
  302. LAYER_SHEET,
  303. LAYER_SHEETNAME,
  304. LAYER_SHEETFILENAME,
  305. LAYER_SHEETFIELDS,
  306. LAYER_SHEETLABEL,
  307. LAYER_NOCONNECT,
  308. LAYER_DANGLING,
  309. LAYER_DNP_MARKER,
  310. LAYER_ERC_WARN,
  311. LAYER_ERC_ERR,
  312. LAYER_ERC_EXCLUSION,
  313. LAYER_DEVICE_BACKGROUND,
  314. LAYER_SHEET_BACKGROUND,
  315. LAYER_SCHEMATIC_GRID,
  316. LAYER_SCHEMATIC_GRID_AXES,
  317. LAYER_SCHEMATIC_BACKGROUND,
  318. LAYER_SCHEMATIC_CURSOR,
  319. LAYER_HOVERED,
  320. LAYER_BRIGHTENED,
  321. LAYER_HIDDEN,
  322. LAYER_SELECTION_SHADOWS,
  323. LAYER_SCHEMATIC_DRAWINGSHEET,
  324. LAYER_SCHEMATIC_PAGE_LIMITS,
  325. LAYER_BUS_JUNCTION,
  326. LAYER_SCHEMATIC_AUX_ITEMS,
  327. LAYER_SCHEMATIC_ANCHOR,
  328. LAYER_OP_VOLTAGES,
  329. LAYER_OP_CURRENTS,
  330. SCH_LAYER_ID_END
  331. };
  332. #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
  333. #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
  334. inline SCH_LAYER_ID operator++( SCH_LAYER_ID& a )
  335. {
  336. a = SCH_LAYER_ID( int( a ) + 1 );
  337. return a;
  338. }
  339. // number of draw layers in Gerbview
  340. #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
  341. /// GerbView draw layers
  342. enum GERBVIEW_LAYER_ID: int
  343. {
  344. GERBVIEW_LAYER_ID_START = SCH_LAYER_ID_END,
  345. /// GerbView draw layers and d-code layers
  346. GERBVIEW_LAYER_ID_RESERVED = GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ),
  347. LAYER_DCODES,
  348. LAYER_NEGATIVE_OBJECTS,
  349. LAYER_GERBVIEW_GRID,
  350. LAYER_GERBVIEW_AXES,
  351. LAYER_GERBVIEW_BACKGROUND,
  352. LAYER_GERBVIEW_DRAWINGSHEET,
  353. LAYER_GERBVIEW_PAGE_LIMITS,
  354. GERBVIEW_LAYER_ID_END
  355. };
  356. #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
  357. #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
  358. #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
  359. /// 3D Viewer virtual layers for color settings
  360. enum LAYER_3D_ID : int
  361. {
  362. LAYER_3D_START = GERBVIEW_LAYER_ID_END,
  363. LAYER_3D_BACKGROUND_BOTTOM,
  364. LAYER_3D_BACKGROUND_TOP,
  365. LAYER_3D_BOARD,
  366. LAYER_3D_COPPER,
  367. LAYER_3D_SILKSCREEN_BOTTOM,
  368. LAYER_3D_SILKSCREEN_TOP,
  369. LAYER_3D_SOLDERMASK_BOTTOM,
  370. LAYER_3D_SOLDERMASK_TOP,
  371. LAYER_3D_SOLDERPASTE,
  372. LAYER_3D_END = LAYER_3D_SOLDERPASTE
  373. };
  374. /// Must update this if you add any enums after GerbView!
  375. #define LAYER_ID_COUNT LAYER_3D_END
  376. /**
  377. * Returns the string equivalent of a given layer
  378. * @param aLayer is a valid layer ID
  379. */
  380. wxString LayerName( int aLayer );
  381. // Some elements do not have yet a visibility control
  382. // from a dialog, but have a visibility control flag.
  383. // Here is a mask to set them visible, to be sure they are displayed
  384. // after loading a board for instance
  385. #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PAD_PLATEDHOLES ) ) +\
  386. ( 1 << GAL_LAYER_INDEX( LAYER_VIA_HOLES ) ) +\
  387. ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
  388. ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
  389. ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
  390. /// A sequence of layers, a sequence provides a certain order.
  391. typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
  392. /**
  393. * LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs. A sequence provides
  394. * a certain order.
  395. * <p>
  396. * It can also be used as an iterator:
  397. * <code>
  398. *
  399. * for( LSEQ cu_stack = aSet.CuStack(); cu_stack; ++cu_stack )
  400. * {
  401. * layer_id = *cu_stack;
  402. * :
  403. * things to do with layer_id;
  404. * }
  405. *
  406. * </code>
  407. */
  408. class LSEQ : public BASE_SEQ
  409. {
  410. unsigned m_index;
  411. public:
  412. LSEQ() :
  413. m_index( 0 )
  414. {}
  415. template <class InputIterator>
  416. LSEQ( InputIterator aStart, InputIterator aEnd ) :
  417. BASE_SEQ( aStart, aEnd ), m_index( 0 )
  418. {}
  419. void Rewind() { m_index = 0; }
  420. void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
  421. void operator ++ (int) { ++m_index; }
  422. operator bool () { return m_index < size(); }
  423. PCB_LAYER_ID operator * () const
  424. {
  425. return at( m_index ); // throws std::out_of_range
  426. }
  427. };
  428. typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
  429. /**
  430. * LSET is a set of PCB_LAYER_IDs. It can be converted to numerous purpose LSEQs using
  431. * the various member functions, most of which are based on Seq(). The advantage
  432. * of converting to LSEQ using purposeful code, is it removes any dependency
  433. * on order/sequence inherent in this set.
  434. */
  435. class LSET : public BASE_SET
  436. {
  437. public:
  438. // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
  439. // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
  440. // LSET s = 0; needs to be removed from the code, this accomplishes that.
  441. // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
  442. // to prevent that surprise. Therefore LSET's constructor suite is significantly
  443. // different than the base class from which it is derived.
  444. // Other member functions (non-constructor functions) are identical to the base
  445. // class's and therefore are re-used from the base class.
  446. /**
  447. * Create an empty (cleared) set.
  448. */
  449. LSET() :
  450. BASE_SET() // all bits are set to zero in BASE_SET()
  451. {
  452. }
  453. LSET( const BASE_SET& aOther ) :
  454. BASE_SET( aOther )
  455. {
  456. }
  457. /**
  458. * Take a PCB_LAYER_ID and sets that bit. This makes the following code into
  459. * a bug:
  460. *
  461. * <code> LSET s = 0; </code>
  462. *
  463. * Instead use:
  464. *
  465. * <code>
  466. * LSET s;
  467. * </code>
  468. *
  469. * for an empty set.
  470. */
  471. LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately excludes int and relatives
  472. BASE_SET()
  473. {
  474. set( aLayer );
  475. }
  476. /**
  477. * Create an array or LSEQ.
  478. */
  479. LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
  480. /**
  481. * Take one or more PCB_LAYER_IDs in the argument list to construct the set. Typically
  482. * only used in static construction.
  483. *
  484. * @param aIdCount is the number of PCB_LAYER_IDs which follow.
  485. * @param aFirst is the first included in @a aIdCount and must always be present, and can
  486. * be followed by any number of additional PCB_LAYER_IDs so long as @a aIdCount accurately
  487. * reflects the count.
  488. *
  489. * Parameter is 'int' to avoid va_start undefined behavior.
  490. */
  491. LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
  492. /**
  493. * See if the layer set contains a PCB layer.
  494. *
  495. * @param aLayer is the layer to check
  496. * @return true if the layer is included
  497. */
  498. bool Contains( PCB_LAYER_ID aLayer )
  499. {
  500. try
  501. {
  502. return test( aLayer );
  503. }
  504. catch( std::out_of_range& )
  505. {
  506. return false;
  507. }
  508. }
  509. /**
  510. * Return the fixed name association with aLayerId.
  511. */
  512. static const wxChar* Name( PCB_LAYER_ID aLayerId );
  513. /**
  514. * Return a complete set of internal copper layers which is all Cu layers
  515. * except F_Cu and B_Cu.
  516. */
  517. static LSET InternalCuMask();
  518. /**
  519. * Return a complete set of all top assembly layers which is all F_SilkS and F_Mask
  520. */
  521. static LSET FrontAssembly();
  522. /**
  523. * Return a complete set of all bottom assembly layers which is all B_SilkS and B_Mask
  524. */
  525. static LSET BackAssembly();
  526. /**
  527. * Return a mask holding the requested number of Cu PCB_LAYER_IDs.
  528. */
  529. static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
  530. /**
  531. * Return a mask holding the Front and Bottom layers.
  532. */
  533. static LSET ExternalCuMask();
  534. /**
  535. * Return a mask holding all layer minus CU layers.
  536. */
  537. static LSET AllNonCuMask();
  538. static LSET AllLayersMask();
  539. /**
  540. * Return a mask holding all technical layers (no CU layer) on front side.
  541. */
  542. static LSET FrontTechMask();
  543. /**
  544. * Return a mask holding technical layers used in a board fabrication
  545. * (no CU layer) on front side.
  546. */
  547. static LSET FrontBoardTechMask();
  548. /**
  549. * Return a mask holding all technical layers (no CU layer) on back side.
  550. */
  551. static LSET BackTechMask();
  552. /**
  553. * Return a mask holding technical layers used in a board fabrication
  554. * (no CU layer) on Back side.
  555. */
  556. static LSET BackBoardTechMask();
  557. /**
  558. * Return a mask holding all technical layers (no CU layer) on both side.
  559. */
  560. static LSET AllTechMask();
  561. /**
  562. * Return a mask holding board technical layers (no CU layer) on both side.
  563. */
  564. static LSET AllBoardTechMask();
  565. /**
  566. * Return a mask holding all technical layers and the external CU layer on front side.
  567. */
  568. static LSET FrontMask();
  569. /**
  570. * Return a mask holding all technical layers and the external CU layer on back side.
  571. */
  572. static LSET BackMask();
  573. static LSET SideSpecificMask();
  574. static LSET UserMask();
  575. /**
  576. * Return a mask holding all layers which are physically realized. Equivalent to the copper
  577. * layers + the board tech mask.
  578. */
  579. static LSET PhysicalLayersMask();
  580. /**
  581. * Return a mask with all of the allowable user defined layers.
  582. */
  583. static LSET UserDefinedLayers();
  584. /**
  585. * Layers which are not allowed within footprint definitions. Currently internal
  586. * copper layers and Margin.
  587. */
  588. static LSET ForbiddenFootprintLayers();
  589. /**
  590. * Return a sequence of copper layers in starting from the front/top
  591. * and extending to the back/bottom. This specific sequence is depended upon
  592. * in numerous places.
  593. */
  594. LSEQ CuStack() const;
  595. /**
  596. * Return a sequence of technical layers. A sequence provides a certain order.
  597. *
  598. * @param aSubToOmit is the subset of the technical layers to omit, defaults to none.
  599. */
  600. LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
  601. /// *_User layers.
  602. LSEQ Users() const;
  603. /// Returns the technical and user layers in the order shown in layer widget
  604. LSEQ TechAndUserUIOrder() const;
  605. LSEQ UIOrder() const;
  606. /**
  607. * Return an LSEQ from the union of this LSET and a desired sequence. The LSEQ
  608. * element will be in the same sequence as aWishListSequence if they are present.
  609. * @param aWishListSequence establishes the order of the returned LSEQ, and the LSEQ will only
  610. * contain PCB_LAYER_IDs which are present in this set.
  611. * @param aCount is the length of aWishListSequence array.
  612. */
  613. LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
  614. LSEQ Seq( const LSEQ& aSequence ) const;
  615. /**
  616. * Return a LSEQ from this LSET in ascending PCB_LAYER_ID order. Each LSEQ
  617. * element will be in the same sequence as in PCB_LAYER_ID and only present
  618. * in the resultant LSEQ if present in this set. Therefore the sequence is
  619. * subject to change, use it only when enumeration and not order is important.
  620. */
  621. LSEQ Seq() const;
  622. /**
  623. * Return the sequence that is typical for a bottom-to-top stack-up.
  624. * For instance, to plot multiple layers in a single image, the top layers output last.
  625. */
  626. LSEQ SeqStackupBottom2Top() const;
  627. /**
  628. * Return a hex string showing contents of this LSEQ.
  629. */
  630. std::string FmtHex() const;
  631. /**
  632. * Convert the output of FmtHex() and replaces this set's values
  633. * with those given in the input string. Parsing stops at the first
  634. * non hex ASCII byte, except that marker bytes output from FmtHex are
  635. * not terminators.
  636. * @return int - number of bytes consumed
  637. */
  638. int ParseHex( const char* aStart, int aCount );
  639. /**
  640. * Return a binary string showing contents of this LSEQ.
  641. */
  642. std::string FmtBin() const;
  643. /**
  644. * Find the first set PCB_LAYER_ID. Returns UNDEFINED_LAYER if more
  645. * than one is set or UNSELECTED_LAYER if none is set.
  646. */
  647. PCB_LAYER_ID ExtractLayer() const;
  648. private:
  649. /// Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
  650. LSET( unsigned long __val )
  651. {
  652. // not usable, it's private.
  653. }
  654. };
  655. /**
  656. * Test whether a given integer is a valid layer index, i.e. can
  657. * be safely put in a PCB_LAYER_ID
  658. *
  659. * @param aLayerId = Layer index to test. It can be an int, so its useful during I/O
  660. * @return true if aLayerIndex is a valid layer index
  661. */
  662. inline bool IsValidLayer( int aLayerId )
  663. {
  664. return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
  665. }
  666. /**
  667. * Test whether a layer is a valid layer for Pcbnew
  668. *
  669. * @param aLayer = Layer to test
  670. * @return true if aLayer is a layer valid in Pcbnew
  671. */
  672. inline bool IsPcbLayer( int aLayer )
  673. {
  674. return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
  675. }
  676. /**
  677. * Tests whether a layer is a copper layer.
  678. *
  679. * @param aLayerId = Layer to test
  680. * @return true if aLayer is a valid copper layer
  681. */
  682. inline bool IsCopperLayer( int aLayerId )
  683. {
  684. return aLayerId >= F_Cu && aLayerId <= B_Cu;
  685. }
  686. /**
  687. * Test whether a layer is a non copper layer.
  688. *
  689. * @param aLayerId = Layer to test
  690. * @return true if aLayer is a non copper layer
  691. */
  692. inline bool IsNonCopperLayer( int aLayerId )
  693. {
  694. return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
  695. }
  696. /**
  697. * Tests whether a layer is a copper layer, optionally including synthetic copper layers such
  698. * as LAYER_VIA_THROUGH, LAYER_PADS_SMD_FR, etc.
  699. *
  700. * @param aLayerId
  701. * @param aIncludeSyntheticCopperLayers
  702. * @return
  703. */
  704. inline bool IsCopperLayer( int aLayerId, bool aIncludeSyntheticCopperLayers )
  705. {
  706. if( aIncludeSyntheticCopperLayers )
  707. return !IsNonCopperLayer( aLayerId );
  708. else
  709. return IsCopperLayer( aLayerId );
  710. }
  711. inline bool IsViaPadLayer( int aLayer )
  712. {
  713. return aLayer == LAYER_VIA_THROUGH
  714. || aLayer == LAYER_VIA_MICROVIA
  715. || aLayer == LAYER_VIA_BBLIND;
  716. }
  717. inline bool IsHoleLayer( int aLayer )
  718. {
  719. return aLayer == LAYER_VIA_HOLES
  720. || aLayer == LAYER_VIA_HOLEWALLS
  721. || aLayer == LAYER_PAD_PLATEDHOLES
  722. || aLayer == LAYER_PAD_HOLEWALLS
  723. || aLayer == LAYER_NON_PLATEDHOLES;
  724. }
  725. /**
  726. * Test whether a layer is a non copper and a non tech layer.
  727. *
  728. * @param aLayerId = Layer to test
  729. * @return true if aLayer is a user layer
  730. */
  731. inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
  732. {
  733. return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
  734. }
  735. /*
  736. * IMPORTANT: If a layer is not a front layer that doesn't necessarily mean it's a back layer.
  737. *
  738. * So a layer can be:
  739. * - Front
  740. * - Back
  741. * - Neither (internal or auxiliary)
  742. *
  743. * The check most frequent is for back layers, since it involves flips.
  744. */
  745. /**
  746. * Layer classification: check if it's a front layer
  747. */
  748. inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
  749. {
  750. switch( aLayerId )
  751. {
  752. case F_Cu:
  753. case F_Adhes:
  754. case F_Paste:
  755. case F_SilkS:
  756. case F_Mask:
  757. case F_CrtYd:
  758. case F_Fab:
  759. return true;
  760. default:
  761. ;
  762. }
  763. return false;
  764. }
  765. /**
  766. * Layer classification: check if it's a back layer
  767. */
  768. inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
  769. {
  770. switch( aLayerId )
  771. {
  772. case B_Cu:
  773. case B_Adhes:
  774. case B_Paste:
  775. case B_SilkS:
  776. case B_Mask:
  777. case B_CrtYd:
  778. case B_Fab:
  779. return true;
  780. default:
  781. return false;
  782. }
  783. }
  784. /**
  785. * @return the layer number after flipping an item
  786. * some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... )
  787. * are swapped between front and back sides
  788. * internal layers are flipped only if the copper layers count is known
  789. * @param aLayerId = the PCB_LAYER_ID to flip
  790. * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  791. * internal layers will be not flipped because the layer count is not known
  792. */
  793. PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
  794. /**
  795. * Calculate the mask layer when flipping a footprint.
  796. *
  797. * BACK and FRONT copper layers, mask, paste, solder layers are swapped
  798. * internal layers are flipped only if the copper layers count is known
  799. * @param aMask = the LSET to flip
  800. * @param aCopperLayersCount = the number of copper layers. if 0 (in fact if < 4 )
  801. * internal layers will be not flipped because the layer count is not known
  802. */
  803. LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
  804. /**
  805. * Returns a netname layer corresponding to the given layer.
  806. */
  807. inline int GetNetnameLayer( int aLayer )
  808. {
  809. if( IsCopperLayer( aLayer ) )
  810. return NETNAMES_LAYER_INDEX( aLayer );
  811. else if( aLayer == LAYER_PADS_TH )
  812. return LAYER_PAD_NETNAMES;
  813. else if( aLayer == LAYER_PADS_SMD_FR )
  814. return LAYER_PAD_FR_NETNAMES;
  815. else if( aLayer == LAYER_PADS_SMD_BK )
  816. return LAYER_PAD_BK_NETNAMES;
  817. else if( IsViaPadLayer( aLayer ) )
  818. return LAYER_VIA_NETNAMES;
  819. // Fallback
  820. return Cmts_User;
  821. }
  822. /**
  823. * Test whether a layer is a netname layer.
  824. *
  825. * @param aLayer = Layer to test
  826. * @return true if aLayer is a valid netname layer
  827. */
  828. inline bool IsNetnameLayer( int aLayer )
  829. {
  830. return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) && aLayer < NETNAMES_LAYER_ID_END;
  831. }
  832. inline bool IsZoneFillLayer( int aLayer )
  833. {
  834. return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
  835. }
  836. inline bool IsDCodeLayer( int aLayer )
  837. {
  838. return aLayer >= ( GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT )
  839. && aLayer < ( GERBVIEW_LAYER_ID_START + ( 2 * GERBER_DRAWLAYERS_COUNT ) );
  840. }
  841. /**
  842. * Checks if the given layer is "net copper", meaning it is eligible for net coloring.
  843. *
  844. * @param aLayer is the layer to test
  845. * @return true if the layer is one that participates in net coloring
  846. */
  847. inline bool IsNetCopperLayer( int aLayer )
  848. {
  849. static std::set<int> netCopperLayers =
  850. {
  851. LAYER_PADS_SMD_FR,
  852. LAYER_PADS_SMD_BK,
  853. LAYER_PADS_TH,
  854. LAYER_PAD_HOLEWALLS,
  855. LAYER_VIA_THROUGH,
  856. LAYER_VIA_BBLIND,
  857. LAYER_VIA_MICROVIA,
  858. LAYER_VIA_HOLEWALLS
  859. };
  860. return IsCopperLayer( aLayer ) || netCopperLayers.count( aLayer );
  861. }
  862. PCB_LAYER_ID ToLAYER_ID( int aLayer );
  863. #endif // LAYER_IDS_H