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 
206 
210 
213 
216 
220 
222 
224 };
225 
227 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
228 
230 #define ZONE_LAYER_FOR( copperLayer ) ( LAYER_ZONE_START + copperLayer )
231 
233 
235 {
236  a = GAL_LAYER_ID( int( a ) + 1 );
237  return a;
238 }
239 
240 inline GAL_LAYER_ID ToGalLayer( int aInteger )
241 {
242  wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
243  return static_cast<GAL_LAYER_ID>( aInteger );
244 }
245 
247 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
248 {
249  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
250  wxASSERT( t <= GAL_LAYER_ID_END );
251  return t;
252 }
253 
254 typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
255 
257 class GAL_SET : public GAL_BASE_SET
258 {
259 private:
260  static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
261 
262 public:
264  {
265  }
266 
267  GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
268  {
269  }
270 
271  GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
272 
274  {
275  GAL_BASE_SET::set();
276  return *this;
277  }
278 
279  GAL_SET& set( int aPos, bool aVal = true )
280  {
281  GAL_BASE_SET::set( aPos, aVal );
282  return *this;
283  }
284 
285  GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
286  {
287  GAL_BASE_SET::set( static_cast<int>( aPos ) - start, aVal );
288  return *this;
289  }
290 
291  bool Contains( GAL_LAYER_ID aPos )
292  {
293  return test( static_cast<int>( aPos ) - start );
294  }
295 
296  std::vector<GAL_LAYER_ID> Seq() const;
297 
298  static GAL_SET DefaultVisible();
299 };
300 
302 enum SCH_LAYER_ID: int
303 {
305 
341 
343 };
344 
345 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
346 
347 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
348 
350 {
351  a = SCH_LAYER_ID( int( a ) + 1 );
352  return a;
353 }
354 
355 // number of draw layers in Gerbview
356 #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
357 
360 {
362 
365 
372 
374 };
375 
376 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
377 
378 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
379 
380 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
381 
382 
384 enum LAYER_3D_ID : int
385 {
387 
396 
398 };
399 
401 #define LAYER_ID_COUNT LAYER_3D_END
402 
403 
408 wxString LayerName( int aLayer );
409 
410 
411 // Some elements do not have yet a visibility control
412 // from a dialog, but have a visibility control flag.
413 // Here is a mask to set them visible, to be sure they are displayed
414 // after loading a board for instance
415 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
416  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
417  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
418  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
419  ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
420 
421 
423 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
424 
425 
443 class LSEQ : public BASE_SEQ
444 {
445  unsigned m_index;
446 
447 public:
448 
449  LSEQ() :
450  m_index( 0 )
451  {}
452 
453  template <class InputIterator>
454  LSEQ( InputIterator aStart, InputIterator aEnd ) :
455  BASE_SEQ( aStart, aEnd ), m_index( 0 )
456  {}
457 
458  void Rewind() { m_index = 0; }
459 
460  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
461 
462  void operator ++ (int) { ++m_index; }
463 
464  operator bool () { return m_index < size(); }
465 
467  {
468  return at( m_index ); // throws std::out_of_range
469  }
470 };
471 
472 
473 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
474 
475 
483 class LSET : public BASE_SET
484 {
485 public:
486 
487  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
488  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
489  // LSET s = 0; needs to be removed from the code, this accomplishes that.
490  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
491  // to prevent that surprize. Therefore LSET's constructor suite is significantly
492  // different than the base class from which it is derived.
493 
494  // Other member functions (non-constructor functions) are identical to the base
495  // class's and therefore are re-used from the base class.
496 
501  LSET() :
502  BASE_SET() // all bits are set to zero in BASE_SET()
503  {
504  }
505 
506  LSET( const BASE_SET& aOther ) :
507  BASE_SET( aOther )
508  {
509  }
510 
526  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
527  BASE_SET()
528  {
529  set( aLayer );
530  }
531 
536  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
537 
550  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
551 
558  bool Contains( PCB_LAYER_ID aLayer )
559  {
560  return test( aLayer );
561  }
562 
567  static const wxChar* Name( PCB_LAYER_ID aLayerId );
568 
574  static LSET InternalCuMask();
575 
581  static LSET FrontAssembly();
582 
588  static LSET BackAssembly();
589 
594  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
595 
600  static LSET ExternalCuMask();
601 
606  static LSET AllNonCuMask();
607 
608  static LSET AllLayersMask();
609 
614  static LSET FrontTechMask();
615 
621  static LSET FrontBoardTechMask();
622 
627  static LSET BackTechMask();
628 
634  static LSET BackBoardTechMask();
635 
640  static LSET AllTechMask();
641 
646  static LSET AllBoardTechMask();
647 
652  static LSET FrontMask();
653 
658  static LSET BackMask();
659 
660  static LSET UserMask();
661 
669 
674  static LSET ForbiddenTextLayers();
675 
682  LSEQ CuStack() const;
683 
690  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
691 
693  LSEQ Users() const;
694 
696  LSEQ TechAndUserUIOrder() const;
697 
698  LSEQ UIOrder() const;
699 
708  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
709 
717  LSEQ Seq() const;
718 
724  LSEQ SeqStackupBottom2Top() const;
725 
730  std::string FmtHex() const;
731 
740  int ParseHex( const char* aStart, int aCount );
741 
746  std::string FmtBin() const;
747 
752  PCB_LAYER_ID ExtractLayer() const;
753 
754 private:
755 
757  LSET( unsigned long __val )
758  {
759  // not usable, it's private.
760  }
761 };
762 
763 
772 inline bool IsValidLayer( LAYER_NUM aLayerId )
773 {
774  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
775 }
776 
783 inline bool IsPcbLayer( LAYER_NUM aLayer )
784 {
785  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
786 }
787 
794 inline bool IsCopperLayer( LAYER_NUM aLayerId )
795 {
796  return aLayerId >= F_Cu && aLayerId <= B_Cu;
797 }
798 
805 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
806 {
807  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
808 }
809 
816 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
817 {
818  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
819 }
820 
821 /* IMPORTANT: If a layer is not a front layer not necessarily is true
822  the converse. The same hold for a back layer.
823  So a layer can be:
824  - Front
825  - Back
826  - Neither (internal or auxiliary)
827 
828  The check most frequent is for back layers, since it involves flips */
829 
830 
834 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
835 {
836  switch( aLayerId )
837  {
838  case F_Cu:
839  case F_Adhes:
840  case F_Paste:
841  case F_SilkS:
842  case F_Mask:
843  case F_CrtYd:
844  case F_Fab:
845  return true;
846  default:
847  ;
848  }
849 
850  return false;
851 }
852 
853 
857 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
858 {
859  switch( aLayerId )
860  {
861  case B_Cu:
862  case B_Adhes:
863  case B_Paste:
864  case B_SilkS:
865  case B_Mask:
866  case B_CrtYd:
867  case B_Fab:
868  return true;
869  default:
870  ;
871  }
872 
873  return false;
874 }
875 
876 
887 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
888 
897 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
898 
899 
903 inline int GetNetnameLayer( int aLayer )
904 {
905  if( IsCopperLayer( aLayer ) )
906  return NETNAMES_LAYER_INDEX( aLayer );
907  else if( aLayer == LAYER_PADS_TH )
908  return LAYER_PADS_NETNAMES;
909  else if( aLayer == LAYER_PAD_FR )
910  return LAYER_PAD_FR_NETNAMES;
911  else if( aLayer == LAYER_PAD_BK )
912  return LAYER_PAD_BK_NETNAMES;
913  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
914  return LAYER_VIAS_NETNAMES;
915 
916  // Fallback
917  return Cmts_User;
918 }
919 
926 inline bool IsNetnameLayer( LAYER_NUM aLayer )
927 {
928  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
929  aLayer < NETNAMES_LAYER_ID_END;
930 }
931 
932 
933 inline bool IsZoneLayer( LAYER_NUM aLayer )
934 {
935  return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
936 }
937 
938 
939 inline bool IsDCodeLayer( int aLayer )
940 {
941  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
943 }
944 
945 
951 inline bool IsNetCopperLayer( LAYER_NUM aLayer )
952 {
953  static std::set<LAYER_NUM> netCopperLayers =
954  {
955  LAYER_PAD_FR,
956  LAYER_PAD_BK,
961  };
962 
963  return IsCopperLayer( aLayer ) || netCopperLayers.count( aLayer );
964 }
965 
966 
967 PCB_LAYER_ID ToLAYER_ID( int aLayer );
968 
969 #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:719
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:782
LSET(const BASE_SET &aOther)
Virtual layers for stacking zones and tracks on a given copper layer.
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:158
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:490
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:832
to handle and draw images bitmaps
GAL_LAYER_ID ToGalLayer(int aInteger)
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:763
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.
Control for copper zone opacity/visibility (color ignored)
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:742
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)
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:56
static LSET FrontTechMask()
Function FrontTechMask returns a mask holding all technical layers (no CU layer) on front side.
Definition: lset.cpp:775
bool IsUserLayer(PCB_LAYER_ID aLayerId)
Function IsUserLayer tests whether a layer is a non copper and a non tech layer.
bool IsNetCopperLayer(LAYER_NUM aLayer)
Checks if the given layer is "net copper", meaning it is eligible for net coloring.
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:430
LSEQ Users() const
*_User layers.
Definition: lset.cpp:224
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:789
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:818
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:240
GAL_SET & set(int aPos, bool aVal=true)
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:414
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask,...
Definition: lset.cpp:536
static LSET BackAssembly()
Function BackAssembly() returns a complete set of all bottom assembly layers, which is all B_SilkS an...
Definition: lset.cpp:665
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:81
bool IsZoneLayer(LAYER_NUM aLayer)
Meta control for all pads opacity/visibility (color ignored)
to draw usual through hole vias
wxString LayerName(int aLayer)
Returns the string equivalent of a given layer.
Definition: layer_id.cpp:24
Helper for storing and iterating over GAL_LAYER_IDs.
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:679
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:749
static GAL_SET DefaultVisible()
Definition: lset.cpp:884
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:651
static LSET AllLayersMask()
Definition: lset.cpp:756
SCH_LAYER_ID
Eeschema drawing layers.
GerbView draw layers and d-code layers.
GAL_SET & set(GAL_LAYER_ID aPos, bool aVal=true)
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:200
Reserved space for board layer netnames.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
std::bitset< GAL_LAYER_ID_COUNT > GAL_BASE_SET
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
layer for drc markers which have been individually excluded
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:856
GAL_LAYER_ID operator+(const GAL_LAYER_ID &a, int b)
Used for via types.
smd pads, front layer
Meta control for all vias opacity/visibility.
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:267
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:630
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:769
static constexpr int start
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:291
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:825
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:796
std::vector< GAL_LAYER_ID > Seq() const
Definition: lset.cpp:870
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:839
GAL_SET(const GAL_SET &aOther)
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:803
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:846
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:328
#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.
bool Contains(GAL_LAYER_ID aPos)