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 
204 
208 
211 
213 
215 };
216 
218 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
219 
221 {
222  a = GAL_LAYER_ID( int( a ) + 1 );
223  return a;
224 }
225 
227 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
228 {
229  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
230  wxASSERT( t <= GAL_LAYER_ID_END );
231  return t;
232 }
233 
235 enum SCH_LAYER_ID: int
236 {
238 
269 
271 };
272 
273 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
274 
275 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
276 
278 {
279  a = SCH_LAYER_ID( int( a ) + 1 );
280  return a;
281 }
282 
283 // number of draw layers in Gerbview
284 #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
285 
288 {
290 
293 
299 
301 };
302 
303 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
304 
305 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
306 
307 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
308 
310 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
311 
312 
313 // Some elements do not have yet a visibility control
314 // from a dialog, but have a visibility control flag.
315 // Here is a mask to set them visible, to be sure they are displayed
316 // after loading a board for instance
317 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
318  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
319  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
320  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
321  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
322  ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
323 
324 
326 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
327 
328 
346 class LSEQ : public BASE_SEQ
347 {
348  unsigned m_index;
349 
350 public:
351 
352  LSEQ() :
353  m_index( 0 )
354  {}
355 
356  template <class InputIterator>
357  LSEQ( InputIterator aStart, InputIterator aEnd ) :
358  BASE_SEQ( aStart, aEnd ), m_index( 0 )
359  {}
360 
361  void Rewind() { m_index = 0; }
362 
363  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
364 
365  void operator ++ (int) { ++m_index; }
366 
367  operator bool () { return m_index < size(); }
368 
370  {
371  return at( m_index ); // throws std::out_of_range
372  }
373 };
374 
375 
376 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
377 
378 
386 class LSET : public BASE_SET
387 {
388 public:
389 
390  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
391  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
392  // LSET s = 0; needs to be removed from the code, this accomplishes that.
393  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
394  // to prevent that surprize. Therefore LSET's constructor suite is significantly
395  // different than the base class from which it is derived.
396 
397  // Other member functions (non-constructor functions) are identical to the base
398  // class's and therefore are re-used from the base class.
399 
404  LSET() :
405  BASE_SET() // all bits are set to zero in BASE_SET()
406  {
407  }
408 
409  LSET( const BASE_SET& aOther ) :
410  BASE_SET( aOther )
411  {
412  }
413 
429  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
430  BASE_SET()
431  {
432  set( aLayer );
433  }
434 
439  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
440 
453  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
454 
459  static const wxChar* Name( PCB_LAYER_ID aLayerId );
460 
466  static LSET InternalCuMask();
467 
472  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
473 
478  static LSET ExternalCuMask();
479 
484  static LSET AllNonCuMask();
485 
486  static LSET AllLayersMask();
487 
492  static LSET FrontTechMask();
493 
499  static LSET FrontBoardTechMask();
500 
505  static LSET BackTechMask();
506 
512  static LSET BackBoardTechMask();
513 
518  static LSET AllTechMask();
519 
524  static LSET AllBoardTechMask();
525 
530  static LSET FrontMask();
531 
536  static LSET BackMask();
537 
538  static LSET UserMask();
539 
547 
552  static LSET ForbiddenTextLayers();
553 
560  LSEQ CuStack() const;
561 
568  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
569 
571  LSEQ Users() const;
572 
574  LSEQ TechAndUserUIOrder() const;
575 
576  LSEQ UIOrder() const;
577 
586  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
587 
595  LSEQ Seq() const;
596 
602  LSEQ SeqStackupBottom2Top() const;
603 
608  std::string FmtHex() const;
609 
618  int ParseHex( const char* aStart, int aCount );
619 
624  std::string FmtBin() const;
625 
630  PCB_LAYER_ID ExtractLayer() const;
631 
632 private:
633 
635  LSET( unsigned long __val )
636  {
637  // not usable, it's private.
638  }
639 };
640 
641 
650 inline bool IsValidLayer( LAYER_NUM aLayerId )
651 {
652  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
653 }
654 
661 inline bool IsPcbLayer( LAYER_NUM aLayer )
662 {
663  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
664 }
665 
672 inline bool IsCopperLayer( LAYER_NUM aLayerId )
673 {
674  return aLayerId >= F_Cu && aLayerId <= B_Cu;
675 }
676 
683 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
684 {
685  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
686 }
687 
694 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
695 {
696  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
697 }
698 
699 /* IMPORTANT: If a layer is not a front layer not necessarily is true
700  the converse. The same hold for a back layer.
701  So a layer can be:
702  - Front
703  - Back
704  - Neither (internal or auxiliary)
705 
706  The check most frequent is for back layers, since it involves flips */
707 
708 
712 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
713 {
714  switch( aLayerId )
715  {
716  case F_Cu:
717  case F_Adhes:
718  case F_Paste:
719  case F_SilkS:
720  case F_Mask:
721  case F_CrtYd:
722  case F_Fab:
723  return true;
724  default:
725  ;
726  }
727 
728  return false;
729 }
730 
731 
735 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
736 {
737  switch( aLayerId )
738  {
739  case B_Cu:
740  case B_Adhes:
741  case B_Paste:
742  case B_SilkS:
743  case B_Mask:
744  case B_CrtYd:
745  case B_Fab:
746  return true;
747  default:
748  ;
749  }
750 
751  return false;
752 }
753 
754 
765 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
766 
775 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
776 
777 
781 inline int GetNetnameLayer( int aLayer )
782 {
783  if( IsCopperLayer( aLayer ) )
784  return NETNAMES_LAYER_INDEX( aLayer );
785  else if( aLayer == LAYER_PADS_TH )
786  return LAYER_PADS_NETNAMES;
787  else if( aLayer == LAYER_PAD_FR )
788  return LAYER_PAD_FR_NETNAMES;
789  else if( aLayer == LAYER_PAD_BK )
790  return LAYER_PAD_BK_NETNAMES;
791  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
792  return LAYER_VIAS_NETNAMES;
793 
794  // Fallback
795  return Cmts_User;
796 }
797 
804 inline bool IsNetnameLayer( LAYER_NUM aLayer )
805 {
806  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
807  aLayer < NETNAMES_LAYER_ID_END;
808 }
809 
810 
811 inline bool IsDCodeLayer( int aLayer )
812 {
813  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
815 }
816 
817 
818 PCB_LAYER_ID ToLAYER_ID( int aLayer );
819 
820 #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:676
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:739
LSET(const BASE_SET &aOther)
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:150
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:475
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:789
to handle and draw images bitmaps
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:720
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.
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:699
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:732
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...
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:415
LSEQ Users() const
*_User layers.
Definition: lset.cpp:216
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:746
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:775
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:232
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:401
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask,...
Definition: lset.cpp:521
PCB_LAYER_ID
A quick note on layer IDs:
Class 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:73
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:636
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:706
static LSET AllLayersMask()
Definition: lset.cpp:713
SCH_LAYER_ID
Eeschema drawing layers.
GerbView draw layers and d-code layers.
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:192
Reserved space for board layer netnames.
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:813
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.
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:259
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:615
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:726
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:283
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:782
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:753
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:796
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:760
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:803
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:315
#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.