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 
196 
200 
202 
204 };
205 
207 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
208 
210 {
211  a = GAL_LAYER_ID( int( a ) + 1 );
212  return a;
213 }
214 
216 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
217 {
218  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
219  wxASSERT( t <= GAL_LAYER_ID_END );
220  return t;
221 }
222 
224 enum SCH_LAYER_ID: int
225 {
227 
254 
256 };
257 
258 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
259 
260 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
261 
263 {
264  a = SCH_LAYER_ID( int( a ) + 1 );
265  return a;
266 }
267 
268 // number of draw layers in Gerbview
269 #define GERBER_DRAWLAYERS_COUNT 32
270 
273 {
275 
278 
284 
286 };
287 
289 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
290 
291 
292 // Some elements do not have yet a visibility control
293 // from a dialog, but have a visibility control flag.
294 // Here is a mask to set them visible, to be sure they are displayed
295 // after loading a board for instance
296 #define MIN_VISIBILITY_MASK int( (1 << GAL_LAYER_INDEX( LAYER_TRACKS ) ) +\
297  ( 1 << GAL_LAYER_INDEX( LAYER_PADS ) ) +\
298  ( 1 << GAL_LAYER_INDEX( LAYER_PADS_HOLES ) ) +\
299  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
300  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
301  ( 1 << GAL_LAYER_INDEX( LAYER_WORKSHEET ) ) +\
302  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
303 
304 
306 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
307 
308 
326 class LSEQ : public BASE_SEQ
327 {
328  unsigned m_index;
329 
330 public:
331 
332  LSEQ() :
333  m_index( 0 )
334  {}
335 
336  template <class InputIterator>
337  LSEQ( InputIterator aStart, InputIterator aEnd ) :
338  BASE_SEQ( aStart, aEnd ), m_index( 0 )
339  {}
340 
341  void Rewind() { m_index = 0; }
342 
343  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
344 
345  void operator ++ (int) { ++m_index; }
346 
347  operator bool () { return m_index < size(); }
348 
350  {
351  return at( m_index ); // throws std::out_of_range
352  }
353 };
354 
355 
356 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
357 
358 
366 class LSET : public BASE_SET
367 {
368 public:
369 
370  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
371  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
372  // LSET s = 0; needs to be removed from the code, this accomplishes that.
373  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
374  // to prevent that surprize. Therefore LSET's constructor suite is significantly
375  // different than the base class from which it is derived.
376 
377  // Other member functions (non-constructor functions) are identical to the base
378  // class's and therefore are re-used from the base class.
379 
384  LSET() :
385  BASE_SET() // all bits are set to zero in BASE_SET()
386  {
387  }
388 
389  LSET( const BASE_SET& aOther ) :
390  BASE_SET( aOther )
391  {
392  }
393 
409  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
410  BASE_SET()
411  {
412  set( aLayer );
413  }
414 
419  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
420 
433  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
434 
439  static const wxChar* Name( PCB_LAYER_ID aLayerId );
440 
446  static LSET InternalCuMask();
447 
452  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
453 
458  static LSET ExternalCuMask();
459 
464  static LSET AllNonCuMask();
465 
466  static LSET AllLayersMask();
467 
472  static LSET FrontTechMask();
473 
479  static LSET FrontBoardTechMask();
480 
485  static LSET BackTechMask();
486 
492  static LSET BackBoardTechMask();
493 
498  static LSET AllTechMask();
499 
504  static LSET AllBoardTechMask();
505 
510  static LSET FrontMask();
511 
516  static LSET BackMask();
517 
518  static LSET UserMask();
519 
520 
527  LSEQ CuStack() const;
528 
535  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
536 
538  LSEQ Users() const;
539 
540  LSEQ UIOrder() const;
541 
550  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
551 
559  LSEQ Seq() const;
560 
566  LSEQ SeqStackupBottom2Top() const;
567 
572  std::string FmtHex() const;
573 
582  int ParseHex( const char* aStart, int aCount );
583 
588  std::string FmtBin() const;
589 
594  PCB_LAYER_ID ExtractLayer() const;
595 
596 private:
597 
599  LSET( unsigned long __val )
600  {
601  // not usable, it's private.
602  }
603 };
604 
613 inline bool IsValidLayer( LAYER_NUM aLayerId )
614 {
615  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
616 }
617 
624 inline bool IsPcbLayer( LAYER_NUM aLayer )
625 {
626  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
627 }
628 
635 inline bool IsCopperLayer( LAYER_NUM aLayerId )
636 {
637  return aLayerId >= F_Cu && aLayerId <= B_Cu;
638 }
639 
646 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
647 {
648  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
649 }
650 
657 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
658 {
659  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
660 }
661 
662 /* IMPORTANT: If a layer is not a front layer not necessarily is true
663  the converse. The same hold for a back layer.
664  So a layer can be:
665  - Front
666  - Back
667  - Neither (internal or auxiliary)
668 
669  The check most frequent is for back layers, since it involves flips */
670 
671 
675 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
676 {
677  switch( aLayerId )
678  {
679  case F_Cu:
680  case F_Adhes:
681  case F_Paste:
682  case F_SilkS:
683  case F_Mask:
684  case F_CrtYd:
685  case F_Fab:
686  return true;
687  default:
688  ;
689  }
690 
691  return false;
692 }
693 
694 
698 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
699 {
700  switch( aLayerId )
701  {
702  case B_Cu:
703  case B_Adhes:
704  case B_Paste:
705  case B_SilkS:
706  case B_Mask:
707  case B_CrtYd:
708  case B_Fab:
709  return true;
710  default:
711  ;
712  }
713 
714  return false;
715 }
716 
717 
728 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
729 
738 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
739 
740 
744 inline int GetNetnameLayer( int aLayer )
745 {
746  if( IsCopperLayer( aLayer ) )
747  return NETNAMES_LAYER_INDEX( aLayer );
748  else if( aLayer == LAYER_PADS )
749  return LAYER_PADS_NETNAMES;
750  else if( aLayer == LAYER_PAD_FR )
751  return LAYER_PAD_FR_NETNAMES;
752  else if( aLayer == LAYER_PAD_BK )
753  return LAYER_PAD_BK_NETNAMES;
754  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
755  return LAYER_VIAS_NETNAMES;
756 
757  // Fallback
758  return Cmts_User;
759 }
760 
767 inline bool IsNetnameLayer( LAYER_NUM aLayer )
768 {
769  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
770  aLayer < NETNAMES_LAYER_ID_END;
771 }
772 
773 
774 PCB_LAYER_ID ToLAYER_ID( int aLayer );
775 
776 #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:639
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:702
LSET(const BASE_SET &aOther)
PCB_LAYER_ID operator*() const
to draw blind/buried vias
show a marker on pads with no nets
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:683
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:662
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:695
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:709
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:738
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:578
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.
#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:599
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:669
general purpose overlay
static LSET AllLayersMask()
Definition: lset.cpp:676
SCH_LAYER_ID
Eeschema drawing layers.
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:189
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:767
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:689
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:745
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:716
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:723
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:752