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 };
139 
140 #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
141 
144 {
145 
147 
149 
151 
153 
158 
160 };
161 
163 #define NETNAMES_LAYER_INDEX( layer ) ( NETNAMES_LAYER_ID_START + layer )
164 
167 enum GAL_LAYER_ID: int
168 {
170 
202 
206 
208 
210 };
211 
213 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
214 
216 {
217  a = GAL_LAYER_ID( int( a ) + 1 );
218  return a;
219 }
220 
222 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
223 {
224  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
225  wxASSERT( t <= GAL_LAYER_ID_END );
226  return t;
227 }
228 
230 enum SCH_LAYER_ID: int
231 {
233 
263 
265 };
266 
267 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
268 
269 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
270 
272 {
273  a = SCH_LAYER_ID( int( a ) + 1 );
274  return a;
275 }
276 
277 // number of draw layers in Gerbview
278 #define GERBER_DRAWLAYERS_COUNT 32
279 
282 {
284 
287 
293 
295 };
296 
297 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
298 
299 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
300 
301 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
302 
304 #define LAYER_ID_COUNT GERBVIEW_LAYER_ID_END
305 
306 
307 // Some elements do not have yet a visibility control
308 // from a dialog, but have a visibility control flag.
309 // Here is a mask to set them visible, to be sure they are displayed
310 // after loading a board for instance
311 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
312  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
313  ( 1 << GAL_LAYER_INDEX( LAYER_DRC ) ) +\
314  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
315  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) )
316 
317 
319 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
320 
321 
339 class LSEQ : public BASE_SEQ
340 {
341  unsigned m_index;
342 
343 public:
344 
345  LSEQ() :
346  m_index( 0 )
347  {}
348 
349  template <class InputIterator>
350  LSEQ( InputIterator aStart, InputIterator aEnd ) :
351  BASE_SEQ( aStart, aEnd ), m_index( 0 )
352  {}
353 
354  void Rewind() { m_index = 0; }
355 
356  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
357 
358  void operator ++ (int) { ++m_index; }
359 
360  operator bool () { return m_index < size(); }
361 
363  {
364  return at( m_index ); // throws std::out_of_range
365  }
366 };
367 
368 
369 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
370 
371 
379 class LSET : public BASE_SET
380 {
381 public:
382 
383  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
384  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
385  // LSET s = 0; needs to be removed from the code, this accomplishes that.
386  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
387  // to prevent that surprize. Therefore LSET's constructor suite is significantly
388  // different than the base class from which it is derived.
389 
390  // Other member functions (non-constructor functions) are identical to the base
391  // class's and therefore are re-used from the base class.
392 
397  LSET() :
398  BASE_SET() // all bits are set to zero in BASE_SET()
399  {
400  }
401 
402  LSET( const BASE_SET& aOther ) :
403  BASE_SET( aOther )
404  {
405  }
406 
422  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
423  BASE_SET()
424  {
425  set( aLayer );
426  }
427 
432  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
433 
446  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
447 
452  static const wxChar* Name( PCB_LAYER_ID aLayerId );
453 
459  static LSET InternalCuMask();
460 
465  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
466 
471  static LSET ExternalCuMask();
472 
477  static LSET AllNonCuMask();
478 
479  static LSET AllLayersMask();
480 
485  static LSET FrontTechMask();
486 
492  static LSET FrontBoardTechMask();
493 
498  static LSET BackTechMask();
499 
505  static LSET BackBoardTechMask();
506 
511  static LSET AllTechMask();
512 
517  static LSET AllBoardTechMask();
518 
523  static LSET FrontMask();
524 
529  static LSET BackMask();
530 
531  static LSET UserMask();
532 
539  static LSET ForbiddenFootprintLayers();
540 
545  static LSET ForbiddenTextLayers();
546 
553  LSEQ CuStack() const;
554 
561  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
562 
564  LSEQ Users() const;
565 
567  LSEQ TechAndUserUIOrder() const;
568 
569  LSEQ UIOrder() const;
570 
579  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
580 
588  LSEQ Seq() const;
589 
595  LSEQ SeqStackupBottom2Top() const;
596 
601  std::string FmtHex() const;
602 
611  int ParseHex( const char* aStart, int aCount );
612 
617  std::string FmtBin() const;
618 
623  PCB_LAYER_ID ExtractLayer() const;
624 
625 private:
626 
628  LSET( unsigned long __val )
629  {
630  // not usable, it's private.
631  }
632 };
633 
634 
643 inline bool IsValidLayer( LAYER_NUM aLayerId )
644 {
645  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
646 }
647 
654 inline bool IsPcbLayer( LAYER_NUM aLayer )
655 {
656  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
657 }
658 
665 inline bool IsCopperLayer( LAYER_NUM aLayerId )
666 {
667  return aLayerId >= F_Cu && aLayerId <= B_Cu;
668 }
669 
676 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
677 {
678  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
679 }
680 
687 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
688 {
689  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
690 }
691 
692 /* IMPORTANT: If a layer is not a front layer not necessarily is true
693  the converse. The same hold for a back layer.
694  So a layer can be:
695  - Front
696  - Back
697  - Neither (internal or auxiliary)
698 
699  The check most frequent is for back layers, since it involves flips */
700 
701 
705 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
706 {
707  switch( aLayerId )
708  {
709  case F_Cu:
710  case F_Adhes:
711  case F_Paste:
712  case F_SilkS:
713  case F_Mask:
714  case F_CrtYd:
715  case F_Fab:
716  return true;
717  default:
718  ;
719  }
720 
721  return false;
722 }
723 
724 
728 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
729 {
730  switch( aLayerId )
731  {
732  case B_Cu:
733  case B_Adhes:
734  case B_Paste:
735  case B_SilkS:
736  case B_Mask:
737  case B_CrtYd:
738  case B_Fab:
739  return true;
740  default:
741  ;
742  }
743 
744  return false;
745 }
746 
747 
758 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
759 
768 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
769 
770 
774 inline int GetNetnameLayer( int aLayer )
775 {
776  if( IsCopperLayer( aLayer ) )
777  return NETNAMES_LAYER_INDEX( aLayer );
778  else if( aLayer == LAYER_PADS_TH )
779  return LAYER_PADS_NETNAMES;
780  else if( aLayer == LAYER_PAD_FR )
781  return LAYER_PAD_FR_NETNAMES;
782  else if( aLayer == LAYER_PAD_BK )
783  return LAYER_PAD_BK_NETNAMES;
784  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
785  return LAYER_VIAS_NETNAMES;
786 
787  // Fallback
788  return Cmts_User;
789 }
790 
797 inline bool IsNetnameLayer( LAYER_NUM aLayer )
798 {
799  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
800  aLayer < NETNAMES_LAYER_ID_END;
801 }
802 
803 
804 inline bool IsDCodeLayer( int aLayer )
805 {
806  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
808 }
809 
810 
811 PCB_LAYER_ID ToLAYER_ID( int aLayer );
812 
813 #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
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:518
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:810
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:170
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.