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_PADS_PLATEDHOLES ) ) +\
306  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
307  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
308  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
309 
310 
312 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
313 
314 
332 class LSEQ : public BASE_SEQ
333 {
334  unsigned m_index;
335 
336 public:
337 
338  LSEQ() :
339  m_index( 0 )
340  {}
341 
342  template <class InputIterator>
343  LSEQ( InputIterator aStart, InputIterator aEnd ) :
344  BASE_SEQ( aStart, aEnd ), m_index( 0 )
345  {}
346 
347  void Rewind() { m_index = 0; }
348 
349  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
350 
351  void operator ++ (int) { ++m_index; }
352 
353  operator bool () { return m_index < size(); }
354 
356  {
357  return at( m_index ); // throws std::out_of_range
358  }
359 };
360 
361 
362 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
363 
364 
372 class LSET : public BASE_SET
373 {
374 public:
375 
376  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
377  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
378  // LSET s = 0; needs to be removed from the code, this accomplishes that.
379  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
380  // to prevent that surprize. Therefore LSET's constructor suite is significantly
381  // different than the base class from which it is derived.
382 
383  // Other member functions (non-constructor functions) are identical to the base
384  // class's and therefore are re-used from the base class.
385 
390  LSET() :
391  BASE_SET() // all bits are set to zero in BASE_SET()
392  {
393  }
394 
395  LSET( const BASE_SET& aOther ) :
396  BASE_SET( aOther )
397  {
398  }
399 
415  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
416  BASE_SET()
417  {
418  set( aLayer );
419  }
420 
425  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
426 
439  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
440 
445  static const wxChar* Name( PCB_LAYER_ID aLayerId );
446 
452  static LSET InternalCuMask();
453 
458  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
459 
464  static LSET ExternalCuMask();
465 
470  static LSET AllNonCuMask();
471 
472  static LSET AllLayersMask();
473 
478  static LSET FrontTechMask();
479 
485  static LSET FrontBoardTechMask();
486 
491  static LSET BackTechMask();
492 
498  static LSET BackBoardTechMask();
499 
504  static LSET AllTechMask();
505 
510  static LSET AllBoardTechMask();
511 
516  static LSET FrontMask();
517 
522  static LSET BackMask();
523 
524  static LSET UserMask();
525 
526 
533  LSEQ CuStack() const;
534 
541  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
542 
544  LSEQ Users() const;
545 
547  LSEQ TechAndUserUIOrder() const;
548 
549  LSEQ UIOrder() const;
550 
559  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
560 
568  LSEQ Seq() const;
569 
575  LSEQ SeqStackupBottom2Top() const;
576 
581  std::string FmtHex() const;
582 
591  int ParseHex( const char* aStart, int aCount );
592 
597  std::string FmtBin() const;
598 
603  PCB_LAYER_ID ExtractLayer() const;
604 
605 private:
606 
608  LSET( unsigned long __val )
609  {
610  // not usable, it's private.
611  }
612 };
613 
614 
623 inline bool IsValidLayer( LAYER_NUM aLayerId )
624 {
625  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
626 }
627 
634 inline bool IsPcbLayer( LAYER_NUM aLayer )
635 {
636  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
637 }
638 
645 inline bool IsCopperLayer( LAYER_NUM aLayerId )
646 {
647  return aLayerId >= F_Cu && aLayerId <= B_Cu;
648 }
649 
656 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
657 {
658  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
659 }
660 
667 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
668 {
669  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
670 }
671 
672 /* IMPORTANT: If a layer is not a front layer not necessarily is true
673  the converse. The same hold for a back layer.
674  So a layer can be:
675  - Front
676  - Back
677  - Neither (internal or auxiliary)
678 
679  The check most frequent is for back layers, since it involves flips */
680 
681 
685 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
686 {
687  switch( aLayerId )
688  {
689  case F_Cu:
690  case F_Adhes:
691  case F_Paste:
692  case F_SilkS:
693  case F_Mask:
694  case F_CrtYd:
695  case F_Fab:
696  return true;
697  default:
698  ;
699  }
700 
701  return false;
702 }
703 
704 
708 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
709 {
710  switch( aLayerId )
711  {
712  case B_Cu:
713  case B_Adhes:
714  case B_Paste:
715  case B_SilkS:
716  case B_Mask:
717  case B_CrtYd:
718  case B_Fab:
719  return true;
720  default:
721  ;
722  }
723 
724  return false;
725 }
726 
727 
738 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
739 
748 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
749 
750 
754 inline int GetNetnameLayer( int aLayer )
755 {
756  if( IsCopperLayer( aLayer ) )
757  return NETNAMES_LAYER_INDEX( aLayer );
758  else if( aLayer == LAYER_PADS_TH )
759  return LAYER_PADS_NETNAMES;
760  else if( aLayer == LAYER_PAD_FR )
761  return LAYER_PAD_FR_NETNAMES;
762  else if( aLayer == LAYER_PAD_BK )
763  return LAYER_PAD_BK_NETNAMES;
764  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
765  return LAYER_VIAS_NETNAMES;
766 
767  // Fallback
768  return Cmts_User;
769 }
770 
777 inline bool IsNetnameLayer( LAYER_NUM aLayer )
778 {
779  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
780  aLayer < NETNAMES_LAYER_ID_END;
781 }
782 
783 
784 inline bool IsDCodeLayer( int aLayer )
785 {
786  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
788 }
789 
790 
791 PCB_LAYER_ID ToLAYER_ID( int aLayer );
792 
793 #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.