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 
292 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
293 
294 
295 // Some elements do not have yet a visibility control
296 // from a dialog, but have a visibility control flag.
297 // Here is a mask to set them visible, to be sure they are displayed
298 // after loading a board for instance
299 #define MIN_VISIBILITY_MASK int( (1 << GAL_LAYER_INDEX( LAYER_TRACKS ) ) +\
300  ( 1 << GAL_LAYER_INDEX( LAYER_PADS ) ) +\
301  ( 1 << GAL_LAYER_INDEX( LAYER_PADS_HOLES ) ) +\
302  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
303  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
304  ( 1 << GAL_LAYER_INDEX( LAYER_WORKSHEET ) ) +\
305  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
306 
307 
309 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
310 
311 
329 class LSEQ : public BASE_SEQ
330 {
331  unsigned m_index;
332 
333 public:
334 
335  LSEQ() :
336  m_index( 0 )
337  {}
338 
339  template <class InputIterator>
340  LSEQ( InputIterator aStart, InputIterator aEnd ) :
341  BASE_SEQ( aStart, aEnd ), m_index( 0 )
342  {}
343 
344  void Rewind() { m_index = 0; }
345 
346  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
347 
348  void operator ++ (int) { ++m_index; }
349 
350  operator bool () { return m_index < size(); }
351 
353  {
354  return at( m_index ); // throws std::out_of_range
355  }
356 };
357 
358 
359 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
360 
361 
369 class LSET : public BASE_SET
370 {
371 public:
372 
373  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
374  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
375  // LSET s = 0; needs to be removed from the code, this accomplishes that.
376  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
377  // to prevent that surprize. Therefore LSET's constructor suite is significantly
378  // different than the base class from which it is derived.
379 
380  // Other member functions (non-constructor functions) are identical to the base
381  // class's and therefore are re-used from the base class.
382 
387  LSET() :
388  BASE_SET() // all bits are set to zero in BASE_SET()
389  {
390  }
391 
392  LSET( const BASE_SET& aOther ) :
393  BASE_SET( aOther )
394  {
395  }
396 
412  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
413  BASE_SET()
414  {
415  set( aLayer );
416  }
417 
422  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
423 
436  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
437 
442  static const wxChar* Name( PCB_LAYER_ID aLayerId );
443 
449  static LSET InternalCuMask();
450 
455  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
456 
461  static LSET ExternalCuMask();
462 
467  static LSET AllNonCuMask();
468 
469  static LSET AllLayersMask();
470 
475  static LSET FrontTechMask();
476 
482  static LSET FrontBoardTechMask();
483 
488  static LSET BackTechMask();
489 
495  static LSET BackBoardTechMask();
496 
501  static LSET AllTechMask();
502 
507  static LSET AllBoardTechMask();
508 
513  static LSET FrontMask();
514 
519  static LSET BackMask();
520 
521  static LSET UserMask();
522 
523 
530  LSEQ CuStack() const;
531 
538  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
539 
541  LSEQ Users() const;
542 
543  LSEQ UIOrder() const;
544 
553  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
554 
562  LSEQ Seq() const;
563 
569  LSEQ SeqStackupBottom2Top() const;
570 
575  std::string FmtHex() const;
576 
585  int ParseHex( const char* aStart, int aCount );
586 
591  std::string FmtBin() const;
592 
597  PCB_LAYER_ID ExtractLayer() const;
598 
599 private:
600 
602  LSET( unsigned long __val )
603  {
604  // not usable, it's private.
605  }
606 };
607 
616 inline bool IsValidLayer( LAYER_NUM aLayerId )
617 {
618  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
619 }
620 
627 inline bool IsPcbLayer( LAYER_NUM aLayer )
628 {
629  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
630 }
631 
638 inline bool IsCopperLayer( LAYER_NUM aLayerId )
639 {
640  return aLayerId >= F_Cu && aLayerId <= B_Cu;
641 }
642 
649 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
650 {
651  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
652 }
653 
660 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
661 {
662  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
663 }
664 
665 /* IMPORTANT: If a layer is not a front layer not necessarily is true
666  the converse. The same hold for a back layer.
667  So a layer can be:
668  - Front
669  - Back
670  - Neither (internal or auxiliary)
671 
672  The check most frequent is for back layers, since it involves flips */
673 
674 
678 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
679 {
680  switch( aLayerId )
681  {
682  case F_Cu:
683  case F_Adhes:
684  case F_Paste:
685  case F_SilkS:
686  case F_Mask:
687  case F_CrtYd:
688  case F_Fab:
689  return true;
690  default:
691  ;
692  }
693 
694  return false;
695 }
696 
697 
701 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
702 {
703  switch( aLayerId )
704  {
705  case B_Cu:
706  case B_Adhes:
707  case B_Paste:
708  case B_SilkS:
709  case B_Mask:
710  case B_CrtYd:
711  case B_Fab:
712  return true;
713  default:
714  ;
715  }
716 
717  return false;
718 }
719 
720 
731 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
732 
741 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
742 
743 
747 inline int GetNetnameLayer( int aLayer )
748 {
749  if( IsCopperLayer( aLayer ) )
750  return NETNAMES_LAYER_INDEX( aLayer );
751  else if( aLayer == LAYER_PADS )
752  return LAYER_PADS_NETNAMES;
753  else if( aLayer == LAYER_PAD_FR )
754  return LAYER_PAD_FR_NETNAMES;
755  else if( aLayer == LAYER_PAD_BK )
756  return LAYER_PAD_BK_NETNAMES;
757  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
758  return LAYER_VIAS_NETNAMES;
759 
760  // Fallback
761  return Cmts_User;
762 }
763 
770 inline bool IsNetnameLayer( LAYER_NUM aLayer )
771 {
772  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
773  aLayer < NETNAMES_LAYER_ID_END;
774 }
775 
776 
777 PCB_LAYER_ID ToLAYER_ID( int aLayer );
778 
779 #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.
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: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