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 
156 
158 };
159 
161 #define NETNAMES_LAYER_INDEX( layer ) ( NETNAMES_LAYER_ID_START + layer )
162 
165 enum GAL_LAYER_ID: int
166 {
168 
195 
199 
201 
203 };
204 
206 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
207 
209 {
210  a = GAL_LAYER_ID( int( a ) + 1 );
211  return a;
212 }
213 
215 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
216 {
217  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
218  wxASSERT( t <= GAL_LAYER_ID_END );
219  return t;
220 }
221 
223 enum SCH_LAYER_ID: int
224 {
226 
253 
255 };
256 
257 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
258 
259 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
260 
262 {
263  a = SCH_LAYER_ID( int( a ) + 1 );
264  return a;
265 }
266 
267 // number of draw layers in Gerbview
268 #define GERBER_DRAWLAYERS_COUNT 32
269 
272 {
274 
277 
283 
285 };
286 
288 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
289 
290 
291 // Some elements do not have yet a visibility control
292 // from a dialog, but have a visibility control flag.
293 // Here is a mask to set them visible, to be sure they are displayed
294 // after loading a board for instance
295 #define MIN_VISIBILITY_MASK int( (1 << GAL_LAYER_INDEX( LAYER_TRACKS ) ) +\
296  ( 1 << GAL_LAYER_INDEX( LAYER_PADS ) ) +\
297  ( 1 << GAL_LAYER_INDEX( LAYER_PADS_HOLES ) ) +\
298  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
299  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
300  ( 1 << GAL_LAYER_INDEX( LAYER_WORKSHEET ) ) +\
301  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
302 
303 
305 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
306 
307 
325 class LSEQ : public BASE_SEQ
326 {
327  unsigned m_index;
328 
329 public:
330 
331  LSEQ() :
332  m_index( 0 )
333  {}
334 
335  template <class InputIterator>
336  LSEQ( InputIterator aStart, InputIterator aEnd ) :
337  BASE_SEQ( aStart, aEnd ), m_index( 0 )
338  {}
339 
340  void Rewind() { m_index = 0; }
341 
342  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
343 
344  void operator ++ (int) { ++m_index; }
345 
346  operator bool () { return m_index < size(); }
347 
349  {
350  return at( m_index ); // throws std::out_of_range
351  }
352 };
353 
354 
355 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
356 
357 
365 class LSET : public BASE_SET
366 {
367 public:
368 
369  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
370  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
371  // LSET s = 0; needs to be removed from the code, this accomplishes that.
372  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
373  // to prevent that surprize. Therefore LSET's constructor suite is significantly
374  // different than the base class from which it is derived.
375 
376  // Other member functions (non-constructor functions) are identical to the base
377  // class's and therefore are re-used from the base class.
378 
383  LSET() :
384  BASE_SET() // all bits are set to zero in BASE_SET()
385  {
386  }
387 
388  LSET( const BASE_SET& aOther ) :
389  BASE_SET( aOther )
390  {
391  }
392 
408  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
409  BASE_SET()
410  {
411  set( aLayer );
412  }
413 
418  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
419 
432  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
433 
438  static const wxChar* Name( PCB_LAYER_ID aLayerId );
439 
445  static LSET InternalCuMask();
446 
451  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
452 
457  static LSET ExternalCuMask();
458 
463  static LSET AllNonCuMask();
464 
465  static LSET AllLayersMask();
466 
471  static LSET FrontTechMask();
472 
478  static LSET FrontBoardTechMask();
479 
484  static LSET BackTechMask();
485 
491  static LSET BackBoardTechMask();
492 
497  static LSET AllTechMask();
498 
503  static LSET AllBoardTechMask();
504 
509  static LSET FrontMask();
510 
515  static LSET BackMask();
516 
517  static LSET UserMask();
518 
519 
526  LSEQ CuStack() const;
527 
534  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
535 
537  LSEQ Users() const;
538 
539  LSEQ UIOrder() const;
540 
549  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
550 
558  LSEQ Seq() const;
559 
565  LSEQ SeqStackupBottom2Top() const;
566 
571  std::string FmtHex() const;
572 
581  int ParseHex( const char* aStart, int aCount );
582 
587  std::string FmtBin() const;
588 
593  PCB_LAYER_ID ExtractLayer() const;
594 
595 private:
596 
598  LSET( unsigned long __val )
599  {
600  // not usable, it's private.
601  }
602 };
603 
612 inline bool IsValidLayer( LAYER_NUM aLayerId )
613 {
614  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
615 }
616 
623 inline bool IsPcbLayer( LAYER_NUM aLayer )
624 {
625  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
626 }
627 
634 inline bool IsCopperLayer( LAYER_NUM aLayerId )
635 {
636  return aLayerId >= F_Cu && aLayerId <= B_Cu;
637 }
638 
645 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
646 {
647  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
648 }
649 
656 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
657 {
658  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
659 }
660 
661 /* IMPORTANT: If a layer is not a front layer not necessarily is true
662  the converse. The same hold for a back layer.
663  So a layer can be:
664  - Front
665  - Back
666  - Neither (internal or auxiliary)
667 
668  The check most frequent is for back layers, since it involves flips */
669 
670 
674 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
675 {
676  switch( aLayerId )
677  {
678  case F_Cu:
679  case F_Adhes:
680  case F_Paste:
681  case F_SilkS:
682  case F_Mask:
683  case F_CrtYd:
684  case F_Fab:
685  return true;
686  default:
687  ;
688  }
689 
690  return false;
691 }
692 
693 
697 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
698 {
699  switch( aLayerId )
700  {
701  case B_Cu:
702  case B_Adhes:
703  case B_Paste:
704  case B_SilkS:
705  case B_Mask:
706  case B_CrtYd:
707  case B_Fab:
708  return true;
709  default:
710  ;
711  }
712 
713  return false;
714 }
715 
716 
727 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
728 
737 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
738 
739 
743 inline int GetNetnameLayer( int aLayer )
744 {
745  if( IsCopperLayer( aLayer ) )
746  return NETNAMES_LAYER_INDEX( aLayer );
747  else if( aLayer == LAYER_PADS )
748  return LAYER_PADS_NETNAMES;
749  else if( aLayer == LAYER_PAD_FR )
750  return LAYER_PAD_FR_NETNAMES;
751  else if( aLayer == LAYER_PAD_BK )
752  return LAYER_PAD_BK_NETNAMES;
753 
754  // Fallback
755  return Cmts_User;
756 }
757 
764 inline bool IsNetnameLayer( LAYER_NUM aLayer )
765 {
766  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
767  aLayer < NETNAMES_LAYER_ID_END;
768 }
769 
770 
771 PCB_LAYER_ID ToLAYER_ID( int aLayer );
772 
773 #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:166
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