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-2020 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 <set>
35 #include <vector>
36 #include <bitset>
37 #include <wx/string.h>
38 
39 
45 typedef int LAYER_NUM;
46 
69 enum PCB_LAYER_ID: int
70 {
73 
106  B_Cu, // 31
107 
110 
113 
116 
118  F_Mask, // 39
119 
125  Margin, // 45
126 
129 
131  F_Fab, // 49
132 
133  // User definable layers.
143 
144  Rescue, // 59
145 
146  // Four reserved layers (60 - 63) for future expansion within the 64 bit integer limit.
147 
149 };
150 
151 #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
152 
155 {
156 
158 
160 
162 
164 
169 
171 };
172 
174 #define NETNAMES_LAYER_INDEX( layer ) ( NETNAMES_LAYER_ID_START + layer )
175 
178 enum GAL_LAYER_ID: int
179 {
181 
216 
220 
223 
226 
230 
232 
234 };
235 
237 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
238 
240 #define ZONE_LAYER_FOR( copperLayer ) ( LAYER_ZONE_START + copperLayer )
241 
243 
245 {
246  a = GAL_LAYER_ID( int( a ) + 1 );
247  return a;
248 }
249 
250 inline GAL_LAYER_ID ToGalLayer( int aInteger )
251 {
252  wxASSERT( aInteger >= GAL_LAYER_ID_START && aInteger <= GAL_LAYER_ID_END );
253  return static_cast<GAL_LAYER_ID>( aInteger );
254 }
255 
257 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
258 {
259  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
260  wxASSERT( t <= GAL_LAYER_ID_END );
261  return t;
262 }
263 
264 typedef std::bitset<GAL_LAYER_ID_COUNT> GAL_BASE_SET;
265 
267 class GAL_SET : public GAL_BASE_SET
268 {
269 private:
270  static constexpr int start = static_cast<int>( GAL_LAYER_ID_START );
271 
272 public:
274  {
275  }
276 
277  GAL_SET( const GAL_SET& aOther ) : std::bitset<GAL_LAYER_ID_COUNT>( aOther )
278  {
279  }
280 
281  GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount );
282 
284  {
285  GAL_BASE_SET::set();
286  return *this;
287  }
288 
289  GAL_SET& set( int aPos, bool aVal = true )
290  {
291  GAL_BASE_SET::set( aPos, aVal );
292  return *this;
293  }
294 
295  GAL_SET& set( GAL_LAYER_ID aPos, bool aVal = true )
296  {
297  GAL_BASE_SET::set( static_cast<std::size_t>( aPos ) - start, aVal );
298  return *this;
299  }
300 
301  bool Contains( GAL_LAYER_ID aPos )
302  {
303  return test( static_cast<std::size_t>( aPos ) - start );
304  }
305 
306  std::vector<GAL_LAYER_ID> Seq() const;
307 
308  static GAL_SET DefaultVisible();
309 };
310 
312 enum SCH_LAYER_ID: int
313 {
315 
351 
353 };
354 
355 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
356 
357 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
358 
360 {
361  a = SCH_LAYER_ID( int( a ) + 1 );
362  return a;
363 }
364 
365 // number of draw layers in Gerbview
366 #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
367 
370 {
372 
375 
382 
384 };
385 
386 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
387 
388 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
389 
390 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
391 
392 
394 enum LAYER_3D_ID : int
395 {
397 
406 
408 };
409 
411 #define LAYER_ID_COUNT LAYER_3D_END
412 
413 
418 wxString LayerName( int aLayer );
419 
420 
421 // Some elements do not have yet a visibility control
422 // from a dialog, but have a visibility control flag.
423 // Here is a mask to set them visible, to be sure they are displayed
424 // after loading a board for instance
425 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
426  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
427  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
428  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
429  ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
430 
431 
433 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
434 
435 
452 class LSEQ : public BASE_SEQ
453 {
454  unsigned m_index;
455 
456 public:
457 
458  LSEQ() :
459  m_index( 0 )
460  {}
461 
462  template <class InputIterator>
463  LSEQ( InputIterator aStart, InputIterator aEnd ) :
464  BASE_SEQ( aStart, aEnd ), m_index( 0 )
465  {}
466 
467  void Rewind() { m_index = 0; }
468 
469  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
470 
471  void operator ++ (int) { ++m_index; }
472 
473  operator bool () { return m_index < size(); }
474 
476  {
477  return at( m_index ); // throws std::out_of_range
478  }
479 };
480 
481 
482 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
483 
484 
491 class LSET : public BASE_SET
492 {
493 public:
494 
495  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
496  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
497  // LSET s = 0; needs to be removed from the code, this accomplishes that.
498  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
499  // to prevent that surprise. Therefore LSET's constructor suite is significantly
500  // different than the base class from which it is derived.
501 
502  // Other member functions (non-constructor functions) are identical to the base
503  // class's and therefore are re-used from the base class.
504 
508  LSET() :
509  BASE_SET() // all bits are set to zero in BASE_SET()
510  {
511  }
512 
513  LSET( const BASE_SET& aOther ) :
514  BASE_SET( aOther )
515  {
516  }
517 
532  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately excludes int and relatives
533  BASE_SET()
534  {
535  set( aLayer );
536  }
537 
541  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
542 
554  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
555 
562  bool Contains( PCB_LAYER_ID aLayer )
563  {
564  return test( aLayer );
565  }
566 
570  static const wxChar* Name( PCB_LAYER_ID aLayerId );
571 
576  static LSET InternalCuMask();
577 
581  static LSET FrontAssembly();
582 
586  static LSET BackAssembly();
587 
591  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
592 
596  static LSET ExternalCuMask();
597 
601  static LSET AllNonCuMask();
602 
603  static LSET AllLayersMask();
604 
608  static LSET FrontTechMask();
609 
614  static LSET FrontBoardTechMask();
615 
619  static LSET BackTechMask();
620 
625  static LSET BackBoardTechMask();
626 
630  static LSET AllTechMask();
631 
635  static LSET AllBoardTechMask();
636 
640  static LSET FrontMask();
641 
645  static LSET BackMask();
646 
647  static LSET UserMask();
648 
652  static LSET UserDefinedLayers();
653 
660 
666  LSEQ CuStack() const;
667 
673  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
674 
676  LSEQ Users() const;
677 
679  LSEQ TechAndUserUIOrder() const;
680 
681  LSEQ UIOrder() const;
682 
690  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
691 
698  LSEQ Seq() const;
699 
704  LSEQ SeqStackupBottom2Top() const;
705 
709  std::string FmtHex() const;
710 
718  int ParseHex( const char* aStart, int aCount );
719 
723  std::string FmtBin() const;
724 
729  PCB_LAYER_ID ExtractLayer() const;
730 
731 private:
732 
734  LSET( unsigned long __val )
735  {
736  // not usable, it's private.
737  }
738 };
739 
740 
748 inline bool IsValidLayer( LAYER_NUM aLayerId )
749 {
750  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
751 }
752 
759 inline bool IsPcbLayer( LAYER_NUM aLayer )
760 {
761  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
762 }
763 
770 inline bool IsCopperLayer( LAYER_NUM aLayerId )
771 {
772  return aLayerId >= F_Cu && aLayerId <= B_Cu;
773 }
774 
781 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
782 {
783  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
784 }
785 
792 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
793 {
794  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
795 }
796 
797 /*
798  @todo Where does this comment actually belong?
799 
800  IMPORTANT: If a layer is not a front layer not necessarily is true
801  the converse. The same hold for a back layer.
802  So a layer can be:
803  - Front
804  - Back
805  - Neither (internal or auxiliary)
806 
807  The check most frequent is for back layers, since it involves flips
808 */
809 
810 
814 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
815 {
816  switch( aLayerId )
817  {
818  case F_Cu:
819  case F_Adhes:
820  case F_Paste:
821  case F_SilkS:
822  case F_Mask:
823  case F_CrtYd:
824  case F_Fab:
825  return true;
826  default:
827  ;
828  }
829 
830  return false;
831 }
832 
833 
837 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
838 {
839  switch( aLayerId )
840  {
841  case B_Cu:
842  case B_Adhes:
843  case B_Paste:
844  case B_SilkS:
845  case B_Mask:
846  case B_CrtYd:
847  case B_Fab:
848  return true;
849  default:
850  ;
851  }
852 
853  return false;
854 }
855 
856 
866 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
867 
877 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
878 
879 
883 inline int GetNetnameLayer( int aLayer )
884 {
885  if( IsCopperLayer( aLayer ) )
886  return NETNAMES_LAYER_INDEX( aLayer );
887  else if( aLayer == LAYER_PADS_TH )
888  return LAYER_PADS_NETNAMES;
889  else if( aLayer == LAYER_PAD_FR )
890  return LAYER_PAD_FR_NETNAMES;
891  else if( aLayer == LAYER_PAD_BK )
892  return LAYER_PAD_BK_NETNAMES;
893  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
894  return LAYER_VIAS_NETNAMES;
895 
896  // Fallback
897  return Cmts_User;
898 }
899 
906 inline bool IsNetnameLayer( LAYER_NUM aLayer )
907 {
908  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
909  aLayer < NETNAMES_LAYER_ID_END;
910 }
911 
912 
913 inline bool IsZoneLayer( LAYER_NUM aLayer )
914 {
915  return aLayer >= LAYER_ZONE_START && aLayer <= LAYER_ZONE_END;
916 }
917 
918 
919 inline bool IsDCodeLayer( int aLayer )
920 {
921  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
923 }
924 
925 
932 inline bool IsNetCopperLayer( LAYER_NUM aLayer )
933 {
934  static std::set<LAYER_NUM> netCopperLayers =
935  {
936  LAYER_PAD_FR,
937  LAYER_PAD_BK,
942  };
943 
944  return IsCopperLayer( aLayer ) || netCopperLayers.count( aLayer );
945 }
946 
947 
948 PCB_LAYER_ID ToLAYER_ID( int aLayer );
949 
950 #endif // LAYERS_ID_AND_VISIBILITY_H_
GAL_LAYER_ID operator++(GAL_LAYER_ID &a)
static LSET UserDefinedLayers()
Return a mask with all of the allowable user defined layers.
Definition: lset.cpp:849
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
static LSET FrontBoardTechMask()
Return a mask holding technical layers used in a board fabrication (no CU layer) on front side.
Definition: lset.cpp:813
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
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:170
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)
Definition: lset.cpp:521
static LSET ForbiddenFootprintLayers()
Layers which are not allowed within footprint definitions.
Definition: lset.cpp:881
to handle and draw images bitmaps
GAL_LAYER_ID ToGalLayer(int aInteger)
static LSET BackTechMask()
Return a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:794
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()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:773
LAYER_3D_ID
3D Viewer virtual layers for color settings
show footprints on back
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
show footprints values (when texts are visibles)
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:58
static LSET FrontTechMask()
Return a mask holding all technical layers (no CU layer) on front side.
Definition: lset.cpp:806
bool IsUserLayer(PCB_LAYER_ID aLayerId)
Test 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 bit masks in Pcbnew There can be at most 32 layers ...
PCB_LAYER_ID operator *() const
LSEQ SeqStackupBottom2Top() const
Return the sequence that is typical for a bottom-to-top stack-up.
Definition: lset.cpp:461
LSEQ Users() const
*_User layers.
Definition: lset.cpp:236
Add new GAL layers here.
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:867
GERBVIEW_LAYER_ID
GerbView draw layers.
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Test whether a layer is a non copper layer.
LSET(PCB_LAYER_ID aLayer)
Take a PCB_LAYER_ID and sets that bit.
show footprints on front
LSEQ TechAndUserUIOrder() const
Returns the technical and user layers in the order shown in layer widget.
Definition: lset.cpp:261
GAL_SET & set(int aPos, bool aVal=true)
std::bitset< PCB_LAYER_ID_COUNT > BASE_SET
bool IsValidLayer(LAYER_NUM aLayerId)
Test whether a given integer is a valid layer index, i.e.
LSEQ Seq() const
Return a LSEQ from this LSET in ascending PCB_LAYER_ID order.
Definition: lset.cpp:445
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint.
Definition: lset.cpp:567
static LSET BackAssembly()
Return a complete set of all bottom assembly layers which is all B_SilkS and B_Mask.
Definition: lset.cpp:696
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)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
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:27
Helper for storing and iterating over GAL_LAYER_IDs.
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:710
static LSET ExternalCuMask()
Return a mask holding the Front and Bottom layers.
Definition: lset.cpp:780
static GAL_SET DefaultVisible()
Definition: lset.cpp:926
constexpr int GAL_LAYER_ID_COUNT
static LSET FrontAssembly()
Return a complete set of all top assembly layers which is all F_SilkS and F_Mask.
Definition: lset.cpp:682
static LSET AllLayersMask()
Definition: lset.cpp:787
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
Return a sequence of technical layers.
Definition: lset.cpp:212
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
This 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:898
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()
Create an empty (cleared) set.
std::string FmtBin() const
Return a binary string showing contents of this LSEQ.
Definition: lset.cpp:297
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:661
static LSET BackBoardTechMask()
Return a mask holding technical layers used in a board fabrication (no CU layer) on Back side.
Definition: lset.cpp:800
static constexpr int start
std::string FmtHex() const
Return a hex string showing contents of this LSEQ.
Definition: lset.cpp:321
currently selected items overlay
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:874
std::vector< PCB_LAYER_ID > BASE_SEQ
A sequence of layers, a sequence provides a certain order.
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
static LSET AllBoardTechMask()
Return a mask holding board technical layers (no CU layer) on both side.
Definition: lset.cpp:827
std::vector< GAL_LAYER_ID > Seq() const
Definition: lset.cpp:912
GAL_SET(const GAL_SET &aOther)
LSEQ(InputIterator aStart, InputIterator aEnd)
bool IsPcbLayer(LAYER_NUM aLayer)
Test whether a layer is a valid layer for Pcbnew.
static LSET UserMask()
Definition: lset.cpp:834
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:888
int ParseHex(const char *aStart, int aCount)
Convert the output of FmtHex() and replaces this set's values with those given in the input string.
Definition: lset.cpp:359
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
show footprints 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)
Test whether a layer is a netname layer.
NETNAMES_LAYER_ID
Dedicated layers for net names used in Pcbnew.
bool Contains(GAL_LAYER_ID aPos)