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 
78  F_Cu = 0, // 0
109  B_Cu, // 31
110 
113 
116 
119 
122 
129 
132 
135 
137 };
138 
139 #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
140 
143 {
144 
146 
148 
150 
152 
157 
159 };
160 
162 #define NETNAMES_LAYER_INDEX( layer ) ( NETNAMES_LAYER_ID_START + layer )
163 
166 enum GAL_LAYER_ID: int
167 {
169 
199 
203 
205 
207 };
208 
210 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
211 
213 {
214  a = GAL_LAYER_ID( int( a ) + 1 );
215  return a;
216 }
217 
219 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
220 {
221  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
222  wxASSERT( t <= GAL_LAYER_ID_END );
223  return t;
224 }
225 
227 enum SCH_LAYER_ID: int
228 {
230 
257 
259 };
260 
261 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
262 
263 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
264 
266 {
267  a = SCH_LAYER_ID( int( a ) + 1 );
268  return a;
269 }
270 
271 // number of draw layers in Gerbview
272 #define GERBER_DRAWLAYERS_COUNT 32
273 
276 {
278 
281 
287 
289 };
290 
291 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
292 
293 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
294 
295 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
296 
298 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
299 
300 
301 // Some elements do not have yet a visibility control
302 // from a dialog, but have a visibility control flag.
303 // Here is a mask to set them visible, to be sure they are displayed
304 // after loading a board for instance
305 #define MIN_VISIBILITY_MASK int( (1 << GAL_LAYER_INDEX( LAYER_TRACKS ) ) +\
306  ( 1 << GAL_LAYER_INDEX( LAYER_PADS ) ) +\
307  ( 1 << GAL_LAYER_INDEX( LAYER_PADS_HOLES ) ) +\
308  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
309  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
310  ( 1 << GAL_LAYER_INDEX( LAYER_WORKSHEET ) ) +\
311  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
312 
313 
315 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
316 
317 
335 class LSEQ : public BASE_SEQ
336 {
337  unsigned m_index;
338 
339 public:
340 
341  LSEQ() :
342  m_index( 0 )
343  {}
344 
345  template <class InputIterator>
346  LSEQ( InputIterator aStart, InputIterator aEnd ) :
347  BASE_SEQ( aStart, aEnd ), m_index( 0 )
348  {}
349 
350  void Rewind() { m_index = 0; }
351 
352  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
353 
354  void operator ++ (int) { ++m_index; }
355 
356  operator bool () { return m_index < size(); }
357 
359  {
360  return at( m_index ); // throws std::out_of_range
361  }
362 };
363 
364 
365 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
366 
367 
375 class LSET : public BASE_SET
376 {
377 public:
378 
379  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
380  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
381  // LSET s = 0; needs to be removed from the code, this accomplishes that.
382  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
383  // to prevent that surprize. Therefore LSET's constructor suite is significantly
384  // different than the base class from which it is derived.
385 
386  // Other member functions (non-constructor functions) are identical to the base
387  // class's and therefore are re-used from the base class.
388 
393  LSET() :
394  BASE_SET() // all bits are set to zero in BASE_SET()
395  {
396  }
397 
398  LSET( const BASE_SET& aOther ) :
399  BASE_SET( aOther )
400  {
401  }
402 
418  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
419  BASE_SET()
420  {
421  set( aLayer );
422  }
423 
428  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
429 
442  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
443 
448  static const wxChar* Name( PCB_LAYER_ID aLayerId );
449 
455  static LSET InternalCuMask();
456 
461  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
462 
467  static LSET ExternalCuMask();
468 
473  static LSET AllNonCuMask();
474 
475  static LSET AllLayersMask();
476 
481  static LSET FrontTechMask();
482 
488  static LSET FrontBoardTechMask();
489 
494  static LSET BackTechMask();
495 
501  static LSET BackBoardTechMask();
502 
507  static LSET AllTechMask();
508 
513  static LSET AllBoardTechMask();
514 
519  static LSET FrontMask();
520 
525  static LSET BackMask();
526 
527  static LSET UserMask();
528 
529 
536  LSEQ CuStack() const;
537 
544  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
545 
547  LSEQ Users() const;
548 
549  LSEQ UIOrder() const;
550 
559  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
560 
568  LSEQ Seq() const;
569 
575  LSEQ SeqStackupBottom2Top() const;
576 
581  std::string FmtHex() const;
582 
591  int ParseHex( const char* aStart, int aCount );
592 
597  std::string FmtBin() const;
598 
603  PCB_LAYER_ID ExtractLayer() const;
604 
605 private:
606 
608  LSET( unsigned long __val )
609  {
610  // not usable, it's private.
611  }
612 };
613 
614 
623 inline bool IsValidLayer( LAYER_NUM aLayerId )
624 {
625  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
626 }
627 
634 inline bool IsPcbLayer( LAYER_NUM aLayer )
635 {
636  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
637 }
638 
645 inline bool IsCopperLayer( LAYER_NUM aLayerId )
646 {
647  return aLayerId >= F_Cu && aLayerId <= B_Cu;
648 }
649 
656 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
657 {
658  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
659 }
660 
667 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
668 {
669  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
670 }
671 
672 /* IMPORTANT: If a layer is not a front layer not necessarily is true
673  the converse. The same hold for a back layer.
674  So a layer can be:
675  - Front
676  - Back
677  - Neither (internal or auxiliary)
678 
679  The check most frequent is for back layers, since it involves flips */
680 
681 
685 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
686 {
687  switch( aLayerId )
688  {
689  case F_Cu:
690  case F_Adhes:
691  case F_Paste:
692  case F_SilkS:
693  case F_Mask:
694  case F_CrtYd:
695  case F_Fab:
696  return true;
697  default:
698  ;
699  }
700 
701  return false;
702 }
703 
704 
708 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
709 {
710  switch( aLayerId )
711  {
712  case B_Cu:
713  case B_Adhes:
714  case B_Paste:
715  case B_SilkS:
716  case B_Mask:
717  case B_CrtYd:
718  case B_Fab:
719  return true;
720  default:
721  ;
722  }
723 
724  return false;
725 }
726 
727 
738 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
739 
748 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
749 
750 
754 inline int GetNetnameLayer( int aLayer )
755 {
756  if( IsCopperLayer( aLayer ) )
757  return NETNAMES_LAYER_INDEX( aLayer );
758  else if( aLayer == LAYER_PADS )
759  return LAYER_PADS_NETNAMES;
760  else if( aLayer == LAYER_PAD_FR )
761  return LAYER_PAD_FR_NETNAMES;
762  else if( aLayer == LAYER_PAD_BK )
763  return LAYER_PAD_BK_NETNAMES;
764  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
765  return LAYER_VIAS_NETNAMES;
766 
767  // Fallback
768  return Cmts_User;
769 }
770 
777 inline bool IsNetnameLayer( LAYER_NUM aLayer )
778 {
779  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
780  aLayer < NETNAMES_LAYER_ID_END;
781 }
782 
783 
784 inline bool IsDCodeLayer( int aLayer )
785 {
786  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
788 }
789 
790 
791 PCB_LAYER_ID ToLAYER_ID( int aLayer );
792 
793 #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:646
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:709
LSET(const BASE_SET &aOther)
PCB_LAYER_ID operator*() const
to draw blind/buried vias
show a marker on pads with no nets
bool IsDCodeLayer(int aLayer)
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:253
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:445
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side...
Definition: lset.cpp:690
anchor of items having an anchor point (texts, footprints)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:147
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:669
show modules on back
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:702
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...
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:716
smd pads, back layer
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:745
LSEQ SeqStackupBottom2Top() const
Function SeqStackBottom2Top returns the sequence that is typical for a bottom-to-top stack-up...
Definition: lset.cpp:385
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.
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:585
show modules on front
LSEQ Seq() const
Function Seq returns a LSEQ from this LSET in ascending PCB_LAYER_ID order.
Definition: lset.cpp:371
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.
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask, paste, solder layers are swapped internal layers are flipped only if the copper layers count is known.
Definition: lset.cpp:491
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
Auxillary 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:73
multilayer pads, usually with holes
to draw usual through hole vias
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:606
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:676
general purpose overlay
static LSET AllLayersMask()
Definition: lset.cpp:683
SCH_LAYER_ID
Eeschema drawing layers.
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:189
GerbView draw layers and d-code layers.
Reserved space for board layer netnames.
to draw pad holes (plated or not plated)
Class 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.
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:774
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.
handle color for not plated holes
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:696
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:229
static LSET BackMask()
Function BackMask returns a mask holding all technical layers and the external CU layer on back side...
Definition: lset.cpp:752
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:723
LSEQ(InputIterator aStart, InputIterator aEnd)
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
LSEQ Users() const
*_User layers.
Definition: lset.cpp:213
static LSET UserMask()
Definition: lset.cpp:730
LSET(unsigned long __val)
Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
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:285
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
show modules references (when texts are visibles)
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.
LSEQ UIOrder() const
Definition: lset.cpp:759