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_TH ) ) +\
307  ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
308  ( 1 << GAL_LAYER_INDEX( LAYER_NON_PLATEDHOLES ) ) +\
309  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
310  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
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 
550  LSEQ TechAndUserUIOrder() const;
551 
552  LSEQ UIOrder() const;
553 
562  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
563 
571  LSEQ Seq() const;
572 
578  LSEQ SeqStackupBottom2Top() const;
579 
584  std::string FmtHex() const;
585 
594  int ParseHex( const char* aStart, int aCount );
595 
600  std::string FmtBin() const;
601 
606  PCB_LAYER_ID ExtractLayer() const;
607 
608 private:
609 
611  LSET( unsigned long __val )
612  {
613  // not usable, it's private.
614  }
615 };
616 
617 
626 inline bool IsValidLayer( LAYER_NUM aLayerId )
627 {
628  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
629 }
630 
637 inline bool IsPcbLayer( LAYER_NUM aLayer )
638 {
639  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
640 }
641 
648 inline bool IsCopperLayer( LAYER_NUM aLayerId )
649 {
650  return aLayerId >= F_Cu && aLayerId <= B_Cu;
651 }
652 
659 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
660 {
661  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
662 }
663 
670 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
671 {
672  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
673 }
674 
675 /* IMPORTANT: If a layer is not a front layer not necessarily is true
676  the converse. The same hold for a back layer.
677  So a layer can be:
678  - Front
679  - Back
680  - Neither (internal or auxiliary)
681 
682  The check most frequent is for back layers, since it involves flips */
683 
684 
688 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
689 {
690  switch( aLayerId )
691  {
692  case F_Cu:
693  case F_Adhes:
694  case F_Paste:
695  case F_SilkS:
696  case F_Mask:
697  case F_CrtYd:
698  case F_Fab:
699  return true;
700  default:
701  ;
702  }
703 
704  return false;
705 }
706 
707 
711 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
712 {
713  switch( aLayerId )
714  {
715  case B_Cu:
716  case B_Adhes:
717  case B_Paste:
718  case B_SilkS:
719  case B_Mask:
720  case B_CrtYd:
721  case B_Fab:
722  return true;
723  default:
724  ;
725  }
726 
727  return false;
728 }
729 
730 
741 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
742 
751 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
752 
753 
757 inline int GetNetnameLayer( int aLayer )
758 {
759  if( IsCopperLayer( aLayer ) )
760  return NETNAMES_LAYER_INDEX( aLayer );
761  else if( aLayer == LAYER_PADS_TH )
762  return LAYER_PADS_NETNAMES;
763  else if( aLayer == LAYER_PAD_FR )
764  return LAYER_PAD_FR_NETNAMES;
765  else if( aLayer == LAYER_PAD_BK )
766  return LAYER_PAD_BK_NETNAMES;
767  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
768  return LAYER_VIAS_NETNAMES;
769 
770  // Fallback
771  return Cmts_User;
772 }
773 
780 inline bool IsNetnameLayer( LAYER_NUM aLayer )
781 {
782  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
783  aLayer < NETNAMES_LAYER_ID_END;
784 }
785 
786 
787 inline bool IsDCodeLayer( int aLayer )
788 {
789  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
791 }
792 
793 
794 PCB_LAYER_ID ToLAYER_ID( int aLayer );
795 
796 #endif // LAYERS_ID_AND_VISIBILITY_H_
GAL_LAYER_ID operator++(GAL_LAYER_ID &a)
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)
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:472
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&#39;s a back layer.
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)
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.
smd pads, back layer
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
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:518
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
to draw usual through hole vias
general purpose overlay
SCH_LAYER_ID
Eeschema drawing layers.
GerbView draw layers and d-code layers.
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&#39;s a front layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
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.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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.
LSEQ(InputIterator aStart, InputIterator aEnd)
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
LSET(unsigned long __val)
Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
#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.