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 
210 
212 };
213 
215 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
216 
218 {
219  a = GAL_LAYER_ID( int( a ) + 1 );
220  return a;
221 }
222 
224 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
225 {
226  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
227  wxASSERT( t <= GAL_LAYER_ID_END );
228  return t;
229 }
230 
232 enum SCH_LAYER_ID: int
233 {
235 
265 
267 };
268 
269 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
270 
271 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
272 
274 {
275  a = SCH_LAYER_ID( int( a ) + 1 );
276  return a;
277 }
278 
279 // number of draw layers in Gerbview
280 #define GERBER_DRAWLAYERS_COUNT 32
281 
284 {
286 
289 
295 
297 };
298 
299 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
300 
301 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
302 
303 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
304 
306 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
307 
308 
309 // Some elements do not have yet a visibility control
310 // from a dialog, but have a visibility control flag.
311 // Here is a mask to set them visible, to be sure they are displayed
312 // after loading a board for instance
313 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
314  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
315  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
316  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
317  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
318 
319 
321 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
322 
323 
341 class LSEQ : public BASE_SEQ
342 {
343  unsigned m_index;
344 
345 public:
346 
347  LSEQ() :
348  m_index( 0 )
349  {}
350 
351  template <class InputIterator>
352  LSEQ( InputIterator aStart, InputIterator aEnd ) :
353  BASE_SEQ( aStart, aEnd ), m_index( 0 )
354  {}
355 
356  void Rewind() { m_index = 0; }
357 
358  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
359 
360  void operator ++ (int) { ++m_index; }
361 
362  operator bool () { return m_index < size(); }
363 
365  {
366  return at( m_index ); // throws std::out_of_range
367  }
368 };
369 
370 
371 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
372 
373 
381 class LSET : public BASE_SET
382 {
383 public:
384 
385  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
386  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
387  // LSET s = 0; needs to be removed from the code, this accomplishes that.
388  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
389  // to prevent that surprize. Therefore LSET's constructor suite is significantly
390  // different than the base class from which it is derived.
391 
392  // Other member functions (non-constructor functions) are identical to the base
393  // class's and therefore are re-used from the base class.
394 
399  LSET() :
400  BASE_SET() // all bits are set to zero in BASE_SET()
401  {
402  }
403 
404  LSET( const BASE_SET& aOther ) :
405  BASE_SET( aOther )
406  {
407  }
408 
424  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
425  BASE_SET()
426  {
427  set( aLayer );
428  }
429 
434  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
435 
448  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
449 
454  static const wxChar* Name( PCB_LAYER_ID aLayerId );
455 
461  static LSET InternalCuMask();
462 
467  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
468 
473  static LSET ExternalCuMask();
474 
479  static LSET AllNonCuMask();
480 
481  static LSET AllLayersMask();
482 
487  static LSET FrontTechMask();
488 
494  static LSET FrontBoardTechMask();
495 
500  static LSET BackTechMask();
501 
507  static LSET BackBoardTechMask();
508 
513  static LSET AllTechMask();
514 
519  static LSET AllBoardTechMask();
520 
525  static LSET FrontMask();
526 
531  static LSET BackMask();
532 
533  static LSET UserMask();
534 
541  static LSET ForbiddenFootprintLayers();
542 
547  static LSET ForbiddenTextLayers();
548 
555  LSEQ CuStack() const;
556 
563  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
564 
566  LSEQ Users() const;
567 
569  LSEQ TechAndUserUIOrder() const;
570 
571  LSEQ UIOrder() const;
572 
581  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
582 
590  LSEQ Seq() const;
591 
597  LSEQ SeqStackupBottom2Top() const;
598 
603  std::string FmtHex() const;
604 
613  int ParseHex( const char* aStart, int aCount );
614 
619  std::string FmtBin() const;
620 
625  PCB_LAYER_ID ExtractLayer() const;
626 
627 private:
628 
630  LSET( unsigned long __val )
631  {
632  // not usable, it's private.
633  }
634 };
635 
636 
645 inline bool IsValidLayer( LAYER_NUM aLayerId )
646 {
647  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
648 }
649 
656 inline bool IsPcbLayer( LAYER_NUM aLayer )
657 {
658  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
659 }
660 
667 inline bool IsCopperLayer( LAYER_NUM aLayerId )
668 {
669  return aLayerId >= F_Cu && aLayerId <= B_Cu;
670 }
671 
678 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
679 {
680  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
681 }
682 
689 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
690 {
691  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
692 }
693 
694 /* IMPORTANT: If a layer is not a front layer not necessarily is true
695  the converse. The same hold for a back layer.
696  So a layer can be:
697  - Front
698  - Back
699  - Neither (internal or auxiliary)
700 
701  The check most frequent is for back layers, since it involves flips */
702 
703 
707 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
708 {
709  switch( aLayerId )
710  {
711  case F_Cu:
712  case F_Adhes:
713  case F_Paste:
714  case F_SilkS:
715  case F_Mask:
716  case F_CrtYd:
717  case F_Fab:
718  return true;
719  default:
720  ;
721  }
722 
723  return false;
724 }
725 
726 
730 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
731 {
732  switch( aLayerId )
733  {
734  case B_Cu:
735  case B_Adhes:
736  case B_Paste:
737  case B_SilkS:
738  case B_Mask:
739  case B_CrtYd:
740  case B_Fab:
741  return true;
742  default:
743  ;
744  }
745 
746  return false;
747 }
748 
749 
760 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
761 
770 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
771 
772 
776 inline int GetNetnameLayer( int aLayer )
777 {
778  if( IsCopperLayer( aLayer ) )
779  return NETNAMES_LAYER_INDEX( aLayer );
780  else if( aLayer == LAYER_PADS_TH )
781  return LAYER_PADS_NETNAMES;
782  else if( aLayer == LAYER_PAD_FR )
783  return LAYER_PAD_FR_NETNAMES;
784  else if( aLayer == LAYER_PAD_BK )
785  return LAYER_PAD_BK_NETNAMES;
786  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
787  return LAYER_VIAS_NETNAMES;
788 
789  // Fallback
790  return Cmts_User;
791 }
792 
799 inline bool IsNetnameLayer( LAYER_NUM aLayer )
800 {
801  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
802  aLayer < NETNAMES_LAYER_ID_END;
803 }
804 
805 
806 inline bool IsDCodeLayer( int aLayer )
807 {
808  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
810 }
811 
812 
813 PCB_LAYER_ID ToLAYER_ID( int aLayer );
814 
815 #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:475
to handle and draw images bitmaps
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: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
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: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.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
currently selected items overlay
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.