KiCad PCB EDA Suite
layers_id_colors_and_visibility.h
Go to the documentation of this file.
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-2017 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 
31 #ifndef LAYERS_ID_AND_VISIBILITY_H_
32 #define LAYERS_ID_AND_VISIBILITY_H_
33 
34 #include <vector>
35 #include <bitset>
36 #include <wx/string.h>
37 #include <macros.h>
38 
39 class BOARD;
40 
41 
48 typedef int LAYER_NUM;
49 
73 enum PCB_LAYER_ID: int
74 {
77 
110  B_Cu, // 31
111 
114 
117 
120 
123 
130 
133 
136 
138 
140 };
141 
142 #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
143 
146 {
147 
149 
151 
153 
155 
160 
162 };
163 
165 #define NETNAMES_LAYER_INDEX( layer ) ( NETNAMES_LAYER_ID_START + layer )
166 
169 enum GAL_LAYER_ID: int
170 {
172 
205 
209 
212 
214 
216 };
217 
219 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
220 
222 
224 {
225  a = GAL_LAYER_ID( int( a ) + 1 );
226  return a;
227 }
228 
230 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
231 {
232  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
233  wxASSERT( t <= GAL_LAYER_ID_END );
234  return t;
235 }
236 
238 enum SCH_LAYER_ID: int
239 {
241 
276 
278 };
279 
280 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
281 
282 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
283 
285 {
286  a = SCH_LAYER_ID( int( a ) + 1 );
287  return a;
288 }
289 
290 // number of draw layers in Gerbview
291 #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
292 
295 {
297 
300 
307 
309 };
310 
311 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
312 
313 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
314 
315 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
316 
317 
319 enum LAYER_3D_ID : int
320 {
322 
331 
333 };
334 
336 #define LAYER_ID_COUNT LAYER_3D_END
337 
338 
343 wxString LayerName( int aLayer );
344 
345 
346 // Some elements do not have yet a visibility control
347 // from a dialog, but have a visibility control flag.
348 // Here is a mask to set them visible, to be sure they are displayed
349 // after loading a board for instance
350 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
351  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
352  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
353  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
354  ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
355 
356 
358 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
359 
360 
378 class LSEQ : public BASE_SEQ
379 {
380  unsigned m_index;
381 
382 public:
383 
384  LSEQ() :
385  m_index( 0 )
386  {}
387 
388  template <class InputIterator>
389  LSEQ( InputIterator aStart, InputIterator aEnd ) :
390  BASE_SEQ( aStart, aEnd ), m_index( 0 )
391  {}
392 
393  void Rewind() { m_index = 0; }
394 
395  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
396 
397  void operator ++ (int) { ++m_index; }
398 
399  operator bool () { return m_index < size(); }
400 
402  {
403  return at( m_index ); // throws std::out_of_range
404  }
405 };
406 
407 typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_SET;
408 
409 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
410 
411 
419 class LSET : public BASE_SET
420 {
421 public:
422 
423  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
424  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
425  // LSET s = 0; needs to be removed from the code, this accomplishes that.
426  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
427  // to prevent that surprize. Therefore LSET's constructor suite is significantly
428  // different than the base class from which it is derived.
429 
430  // Other member functions (non-constructor functions) are identical to the base
431  // class's and therefore are re-used from the base class.
432 
437  LSET() :
438  BASE_SET() // all bits are set to zero in BASE_SET()
439  {
440  }
441 
442  LSET( const BASE_SET& aOther ) :
443  BASE_SET( aOther )
444  {
445  }
446 
462  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
463  BASE_SET()
464  {
465  set( aLayer );
466  }
467 
472  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
473 
486  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
487 
494  bool Contains( PCB_LAYER_ID aLayer )
495  {
496  return test( aLayer );
497  }
498 
503  static const wxChar* Name( PCB_LAYER_ID aLayerId );
504 
510  static LSET InternalCuMask();
511 
517  static LSET FrontAssembly();
518 
524  static LSET BackAssembly();
525 
530  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
531 
536  static LSET ExternalCuMask();
537 
542  static LSET AllNonCuMask();
543 
544  static LSET AllLayersMask();
545 
550  static LSET FrontTechMask();
551 
557  static LSET FrontBoardTechMask();
558 
563  static LSET BackTechMask();
564 
570  static LSET BackBoardTechMask();
571 
576  static LSET AllTechMask();
577 
582  static LSET AllBoardTechMask();
583 
588  static LSET FrontMask();
589 
594  static LSET BackMask();
595 
596  static LSET UserMask();
597 
605 
610  static LSET ForbiddenTextLayers();
611 
618  LSEQ CuStack() const;
619 
626  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
627 
629  LSEQ Users() const;
630 
632  LSEQ TechAndUserUIOrder() const;
633 
634  LSEQ UIOrder() const;
635 
644  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
645 
653  LSEQ Seq() const;
654 
660  LSEQ SeqStackupBottom2Top() const;
661 
666  std::string FmtHex() const;
667 
676  int ParseHex( const char* aStart, int aCount );
677 
682  std::string FmtBin() const;
683 
688  PCB_LAYER_ID ExtractLayer() const;
689 
690 private:
691 
693  LSET( unsigned long __val )
694  {
695  // not usable, it's private.
696  }
697 };
698 
699 
708 inline bool IsValidLayer( LAYER_NUM aLayerId )
709 {
710  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
711 }
712 
719 inline bool IsPcbLayer( LAYER_NUM aLayer )
720 {
721  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
722 }
723 
730 inline bool IsCopperLayer( LAYER_NUM aLayerId )
731 {
732  return aLayerId >= F_Cu && aLayerId <= B_Cu;
733 }
734 
741 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
742 {
743  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
744 }
745 
752 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
753 {
754  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
755 }
756 
757 /* IMPORTANT: If a layer is not a front layer not necessarily is true
758  the converse. The same hold for a back layer.
759  So a layer can be:
760  - Front
761  - Back
762  - Neither (internal or auxiliary)
763 
764  The check most frequent is for back layers, since it involves flips */
765 
766 
770 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
771 {
772  switch( aLayerId )
773  {
774  case F_Cu:
775  case F_Adhes:
776  case F_Paste:
777  case F_SilkS:
778  case F_Mask:
779  case F_CrtYd:
780  case F_Fab:
781  return true;
782  default:
783  ;
784  }
785 
786  return false;
787 }
788 
789 
793 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
794 {
795  switch( aLayerId )
796  {
797  case B_Cu:
798  case B_Adhes:
799  case B_Paste:
800  case B_SilkS:
801  case B_Mask:
802  case B_CrtYd:
803  case B_Fab:
804  return true;
805  default:
806  ;
807  }
808 
809  return false;
810 }
811 
812 
823 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
824 
833 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
834 
835 
839 inline int GetNetnameLayer( int aLayer )
840 {
841  if( IsCopperLayer( aLayer ) )
842  return NETNAMES_LAYER_INDEX( aLayer );
843  else if( aLayer == LAYER_PADS_TH )
844  return LAYER_PADS_NETNAMES;
845  else if( aLayer == LAYER_PAD_FR )
846  return LAYER_PAD_FR_NETNAMES;
847  else if( aLayer == LAYER_PAD_BK )
848  return LAYER_PAD_BK_NETNAMES;
849  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
850  return LAYER_VIAS_NETNAMES;
851 
852  // Fallback
853  return Cmts_User;
854 }
855 
862 inline bool IsNetnameLayer( LAYER_NUM aLayer )
863 {
864  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
865  aLayer < NETNAMES_LAYER_ID_END;
866 }
867 
868 
869 inline bool IsDCodeLayer( int aLayer )
870 {
871  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
873 }
874 
875 
876 PCB_LAYER_ID ToLAYER_ID( int aLayer );
877 
878 #endif // LAYERS_ID_AND_VISIBILITY_H_
GAL_LAYER_ID operator++(GAL_LAYER_ID &a)
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:775
LSET(const BASE_SET &aOther)
to draw blind/buried vias
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:155
show a marker on pads with no nets
bool IsDCodeLayer(int aLayer)
for pageLayout editor previewing
multilayer pads, usually with holes
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount=0)
Function FlippedLayerNumber.
Definition: lset.cpp:485
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:825
to handle and draw images bitmaps
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:756
handle color for not plated holes (holes, not pads)
anchor of items having an anchor point (texts, footprints)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:735
LAYER_3D_ID
3D Viewer virtual layers for color settings
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
show modules values (when texts are visibles)
static LSET FrontTechMask()
Function FrontTechMask returns a mask holding all technical layers (no CU layer) on front side.
Definition: lset.cpp:768
bool IsUserLayer(PCB_LAYER_ID aLayerId)
Function IsUserLayer tests whether a layer is a non copper and a non tech layer.
This is the end of the layers used for visibility bitmasks in Pcbnew There can be at most 32 layers a...
PCB_LAYER_ID operator *() const
LSEQ SeqStackupBottom2Top() const
Function SeqStackBottom2Top returns the sequence that is typical for a bottom-to-top stack-up.
Definition: lset.cpp:425
LSEQ Users() const
*_User layers.
Definition: lset.cpp:221
Add new GAL layers here.
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:782
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:811
GERBVIEW_LAYER_ID
GerbView draw layers.
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
LSET(PCB_LAYER_ID aLayer)
Constructor LSET( PCB_LAYER_ID ) takes a PCB_LAYER_ID and sets that bit.
This file contains miscellaneous commonly used macros and functions.
show modules on front
LSEQ TechAndUserUIOrder() const
Returns the technical and user layers in the order shown in layer widget.
Definition: lset.cpp:237
std::bitset< PCB_LAYER_ID_COUNT > BASE_SET
bool IsValidLayer(LAYER_NUM aLayerId)
Function IsValidLayer tests whether a given integer is a valid layer index, i.e.
LSEQ Seq() const
Function Seq returns a LSEQ from this LSET in ascending PCB_LAYER_ID order.
Definition: lset.cpp:411
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask,...
Definition: lset.cpp:531
static LSET BackAssembly()
Function BackAssembly() returns a complete set of all bottom assembly layers, which is all B_SilkS an...
Definition: lset.cpp:659
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
Auxiliary items (guides, rule, etc)
#define GERBER_DRAWLAYERS_COUNT
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:78
to draw usual through hole vias
wxString LayerName(int aLayer)
Returns the string equivalent of a given layer.
Definition: layer_id.cpp:24
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:672
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:742
constexpr int GAL_LAYER_ID_COUNT
static LSET FrontAssembly()
Function FrontAssembly() returns a complete set of all top assembly layers, which is all F_SilkS and ...
Definition: lset.cpp:646
static LSET AllLayersMask()
Definition: lset.cpp:749
SCH_LAYER_ID
Eeschema drawing layers.
GerbView draw layers and d-code layers.
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:197
Reserved space for board layer netnames.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
layer for drc markers with SEVERITY_WARNING
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849
GAL_LAYER_ID operator+(const GAL_LAYER_ID &a, int b)
Used for via types.
smd pads, front layer
LSET()
Constructor LSET() creates an empty (cleared) set.
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:264
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:625
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:762
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:288
currently selected items overlay
static LSET BackMask()
Function BackMask returns a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:818
std::vector< PCB_LAYER_ID > BASE_SEQ
A sequence of layers, a sequence provides a certain order.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
static LSET AllBoardTechMask()
Function AllTechMask returns a mask holding board technical layers (no CU layer) on both side.
Definition: lset.cpp:789
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:832
LSEQ(InputIterator aStart, InputIterator aEnd)
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
static LSET UserMask()
Definition: lset.cpp:796
std::bitset< GAL_LAYER_ID_COUNT > GAL_SET
LSET(unsigned long __val)
Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
for pageLayout editor previewing
LSEQ UIOrder() const
Definition: lset.cpp:839
int ParseHex(const char *aStart, int aCount)
Function ParseHex understands the output of FmtHex() and replaces this set's values with those given ...
Definition: lset.cpp:325
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
show modules references (when texts are visibles)
layer for drc markers with SEVERITY_ERROR
Additional netnames layers (not associated with a PCB layer)
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
NETNAMES_LAYER_ID
Dedicated layers for net names used in Pcbnew.