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 
205 
209 
212 
214 
216 };
217 
219 #define GAL_LAYER_INDEX( x ) ( x - GAL_LAYER_ID_START )
220 
222 {
223  a = GAL_LAYER_ID( int( a ) + 1 );
224  return a;
225 }
226 
228 inline GAL_LAYER_ID operator+( const GAL_LAYER_ID& a, int b )
229 {
230  GAL_LAYER_ID t = GAL_LAYER_ID( int( a ) + b );
231  wxASSERT( t <= GAL_LAYER_ID_END );
232  return t;
233 }
234 
236 enum SCH_LAYER_ID: int
237 {
239 
272 
274 };
275 
276 #define SCH_LAYER_ID_COUNT ( SCH_LAYER_ID_END - SCH_LAYER_ID_START )
277 
278 #define SCH_LAYER_INDEX( x ) ( x - SCH_LAYER_ID_START )
279 
281 {
282  a = SCH_LAYER_ID( int( a ) + 1 );
283  return a;
284 }
285 
286 // number of draw layers in Gerbview
287 #define GERBER_DRAWLAYERS_COUNT PCB_LAYER_ID_COUNT
288 
291 {
293 
296 
303 
305 };
306 
307 #define GERBER_DRAW_LAYER( x ) ( GERBVIEW_LAYER_ID_START + x )
308 
309 #define GERBER_DCODE_LAYER( x ) ( GERBER_DRAWLAYERS_COUNT + x )
310 
311 #define GERBER_DRAW_LAYER_INDEX( x ) ( x - GERBVIEW_LAYER_ID_START )
312 
313 // TODO(JE) Remove after we have color themes
314 // Temporary virtual layers to store color themes for footprint editor
315 enum FPEDIT_LAYER_ID : int
316 {
318 
319  // Reserve a copy of the board and netname layers...
321 
322  // And a copy of the GAL layers
324 
326 };
327 
329 enum LAYER_3D_ID : int
330 {
332 
341 
343 };
344 
346 #define LAYER_ID_COUNT FPEDIT_LAYER_ID_END
347 
348 
350 wxString LayerName( SCH_LAYER_ID aLayer );
351 
352 
353 // Some elements do not have yet a visibility control
354 // from a dialog, but have a visibility control flag.
355 // Here is a mask to set them visible, to be sure they are displayed
356 // after loading a board for instance
357 #define MIN_VISIBILITY_MASK int( ( 1 << GAL_LAYER_INDEX( LAYER_PADS_PLATEDHOLES ) ) +\
358  ( 1 << GAL_LAYER_INDEX( LAYER_VIAS_HOLES ) ) +\
359  ( 1 << GAL_LAYER_INDEX( LAYER_SELECT_OVERLAY ) ) +\
360  ( 1 << GAL_LAYER_INDEX( LAYER_GP_OVERLAY ) ) +\
361  ( 1 << GAL_LAYER_INDEX( LAYER_RATSNEST ) ) )
362 
363 
365 typedef std::vector<PCB_LAYER_ID> BASE_SEQ;
366 
367 
385 class LSEQ : public BASE_SEQ
386 {
387  unsigned m_index;
388 
389 public:
390 
391  LSEQ() :
392  m_index( 0 )
393  {}
394 
395  template <class InputIterator>
396  LSEQ( InputIterator aStart, InputIterator aEnd ) :
397  BASE_SEQ( aStart, aEnd ), m_index( 0 )
398  {}
399 
400  void Rewind() { m_index = 0; }
401 
402  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
403 
404  void operator ++ (int) { ++m_index; }
405 
406  operator bool () { return m_index < size(); }
407 
409  {
410  return at( m_index ); // throws std::out_of_range
411  }
412 };
413 
414 
415 typedef std::bitset<PCB_LAYER_ID_COUNT> BASE_SET;
416 
417 
425 class LSET : public BASE_SET
426 {
427 public:
428 
429  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
430  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
431  // LSET s = 0; needs to be removed from the code, this accomplishes that.
432  // Remember LSET( PCB_LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
433  // to prevent that surprize. Therefore LSET's constructor suite is significantly
434  // different than the base class from which it is derived.
435 
436  // Other member functions (non-constructor functions) are identical to the base
437  // class's and therefore are re-used from the base class.
438 
443  LSET() :
444  BASE_SET() // all bits are set to zero in BASE_SET()
445  {
446  }
447 
448  LSET( const BASE_SET& aOther ) :
449  BASE_SET( aOther )
450  {
451  }
452 
468  LSET( PCB_LAYER_ID aLayer ) : // PCB_LAYER_ID deliberately exludes int and relatives
469  BASE_SET()
470  {
471  set( aLayer );
472  }
473 
478  LSET( const PCB_LAYER_ID* aArray, unsigned aCount );
479 
492  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
493 
498  static const wxChar* Name( PCB_LAYER_ID aLayerId );
499 
505  static LSET InternalCuMask();
506 
511  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
512 
517  static LSET ExternalCuMask();
518 
523  static LSET AllNonCuMask();
524 
525  static LSET AllLayersMask();
526 
531  static LSET FrontTechMask();
532 
538  static LSET FrontBoardTechMask();
539 
544  static LSET BackTechMask();
545 
551  static LSET BackBoardTechMask();
552 
557  static LSET AllTechMask();
558 
563  static LSET AllBoardTechMask();
564 
569  static LSET FrontMask();
570 
575  static LSET BackMask();
576 
577  static LSET UserMask();
578 
586 
591  static LSET ForbiddenTextLayers();
592 
599  LSEQ CuStack() const;
600 
607  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
608 
610  LSEQ Users() const;
611 
613  LSEQ TechAndUserUIOrder() const;
614 
615  LSEQ UIOrder() const;
616 
625  LSEQ Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const;
626 
634  LSEQ Seq() const;
635 
641  LSEQ SeqStackupBottom2Top() const;
642 
647  std::string FmtHex() const;
648 
657  int ParseHex( const char* aStart, int aCount );
658 
663  std::string FmtBin() const;
664 
669  PCB_LAYER_ID ExtractLayer() const;
670 
671 private:
672 
674  LSET( unsigned long __val )
675  {
676  // not usable, it's private.
677  }
678 };
679 
680 
689 inline bool IsValidLayer( LAYER_NUM aLayerId )
690 {
691  return unsigned( aLayerId ) < PCB_LAYER_ID_COUNT;
692 }
693 
700 inline bool IsPcbLayer( LAYER_NUM aLayer )
701 {
702  return aLayer >= F_Cu && aLayer < PCB_LAYER_ID_COUNT;
703 }
704 
711 inline bool IsCopperLayer( LAYER_NUM aLayerId )
712 {
713  return aLayerId >= F_Cu && aLayerId <= B_Cu;
714 }
715 
722 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
723 {
724  return aLayerId > B_Cu && aLayerId <= PCB_LAYER_ID_COUNT;
725 }
726 
733 inline bool IsUserLayer( PCB_LAYER_ID aLayerId )
734 {
735  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
736 }
737 
738 /* IMPORTANT: If a layer is not a front layer not necessarily is true
739  the converse. The same hold for a back layer.
740  So a layer can be:
741  - Front
742  - Back
743  - Neither (internal or auxiliary)
744 
745  The check most frequent is for back layers, since it involves flips */
746 
747 
751 inline bool IsFrontLayer( PCB_LAYER_ID aLayerId )
752 {
753  switch( aLayerId )
754  {
755  case F_Cu:
756  case F_Adhes:
757  case F_Paste:
758  case F_SilkS:
759  case F_Mask:
760  case F_CrtYd:
761  case F_Fab:
762  return true;
763  default:
764  ;
765  }
766 
767  return false;
768 }
769 
770 
774 inline bool IsBackLayer( PCB_LAYER_ID aLayerId )
775 {
776  switch( aLayerId )
777  {
778  case B_Cu:
779  case B_Adhes:
780  case B_Paste:
781  case B_SilkS:
782  case B_Mask:
783  case B_CrtYd:
784  case B_Fab:
785  return true;
786  default:
787  ;
788  }
789 
790  return false;
791 }
792 
793 
804 PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount = 0 );
805 
814 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
815 
816 
820 inline int GetNetnameLayer( int aLayer )
821 {
822  if( IsCopperLayer( aLayer ) )
823  return NETNAMES_LAYER_INDEX( aLayer );
824  else if( aLayer == LAYER_PADS_TH )
825  return LAYER_PADS_NETNAMES;
826  else if( aLayer == LAYER_PAD_FR )
827  return LAYER_PAD_FR_NETNAMES;
828  else if( aLayer == LAYER_PAD_BK )
829  return LAYER_PAD_BK_NETNAMES;
830  else if( aLayer >= LAYER_VIA_MICROVIA && aLayer <= LAYER_VIA_THROUGH )
831  return LAYER_VIAS_NETNAMES;
832 
833  // Fallback
834  return Cmts_User;
835 }
836 
843 inline bool IsNetnameLayer( LAYER_NUM aLayer )
844 {
845  return aLayer >= NETNAMES_LAYER_INDEX( F_Cu ) &&
846  aLayer < NETNAMES_LAYER_ID_END;
847 }
848 
849 
850 inline bool IsDCodeLayer( int aLayer )
851 {
852  return aLayer >= (GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT) &&
854 }
855 
856 
857 PCB_LAYER_ID ToLAYER_ID( int aLayer );
858 
859 #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:686
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:749
LSET(const BASE_SET &aOther)
to draw blind/buried vias
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:155
show a marker on pads with no nets
bool IsDCodeLayer(int aLayer)
for pageLayout editor previewing
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:485
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:799
to handle and draw images bitmaps
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:730
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's a back layer.
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:709
LAYER_3D_ID
3D Viewer virtual layers for color settings
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:742
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...
PCB_LAYER_ID operator *() const
LSEQ SeqStackupBottom2Top() const
Function SeqStackBottom2Top returns the sequence that is typical for a bottom-to-top stack-up.
Definition: lset.cpp:425
LSEQ Users() const
*_User layers.
Definition: lset.cpp:221
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:756
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:785
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
LSEQ TechAndUserUIOrder() const
Returns the technical and user layers in the order shown in layer widget.
Definition: lset.cpp:237
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.
LSEQ Seq() const
Function Seq returns a LSEQ from this LSET in ascending PCB_LAYER_ID order.
Definition: lset.cpp:411
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount=0)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask,...
Definition: lset.cpp:531
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
Auxiliary items (guides, rule, etc)
#define GERBER_DRAWLAYERS_COUNT
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:78
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:646
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:716
static LSET AllLayersMask()
Definition: lset.cpp:723
SCH_LAYER_ID
Eeschema drawing layers.
GerbView draw layers and d-code layers.
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:197
Reserved space for board layer netnames.
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.
layer for drc markers with SEVERITY_WARNING
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:823
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.
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:264
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:625
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:736
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:288
currently selected items overlay
static LSET BackMask()
Function BackMask returns a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:792
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:763
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:806
LSEQ(InputIterator aStart, InputIterator aEnd)
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
wxString LayerName(SCH_LAYER_ID aLayer)
Returns the string equivalent of a given layer.
Definition: layer_id.cpp:24
static LSET UserMask()
Definition: lset.cpp:770
LSET(unsigned long __val)
Take this off the market, it may not be used because of LSET( PCB_LAYER_ID ).
for pageLayout editor previewing
LSEQ UIOrder() const
Definition: lset.cpp:813
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:325
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
show modules references (when texts are visibles)
layer for drc markers with SEVERITY_ERROR
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.