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 
50 
56 enum LAYER_ID: int
57 {
58  F_Cu, // 0
89  B_Cu, // 31
90 
93 
96 
99 
102 
109 
112 
115 
117 
120 };
121 
122 
123 #define MAX_CU_LAYERS (B_Cu - F_Cu + 1)
124 
126 typedef std::vector<LAYER_ID> BASE_SEQ;
127 
128 
146 class LSEQ : public BASE_SEQ
147 {
148  unsigned m_index;
149 
150 public:
151 
152  LSEQ() :
153  m_index( 0 )
154  {}
155 
156  template <class InputIterator>
157  LSEQ( InputIterator aStart, InputIterator aEnd ) :
158  BASE_SEQ( aStart, aEnd ), m_index( 0 )
159  {}
160 
161  void Rewind() { m_index = 0; }
162 
163  void operator ++ () { ++m_index; } // returns nothing, used in simple statements only.
164 
165  void operator ++ (int) { ++m_index; }
166 
167  operator bool () { return m_index < size(); }
168 
170  {
171  return at( m_index ); // throws std::out_of_range
172  }
173 };
174 
175 
176 typedef std::bitset<LAYER_ID_COUNT> BASE_SET;
177 
178 
186 class LSET : public BASE_SET
187 {
188 public:
189 
190  // The constructor flavors are carefully chosen to prevent LSET( int ) from compiling.
191  // That excludes "LSET s = 0;" and excludes "LSET s = -1;", etc.
192  // LSET s = 0; needs to be removed from the code, this accomplishes that.
193  // Remember LSET( LAYER_ID(0) ) sets bit 0, so "LSET s = 0;" is illegal
194  // to prevent that surprize. Therefore LSET's constructor suite is significantly
195  // different than the base class from which it is derived.
196 
197  // Other member functions (non-constructor functions) are identical to the base
198  // class's and therefore are re-used from the base class.
199 
204  LSET() :
205  BASE_SET() // all bits are set to zero in BASE_SET()
206  {
207  }
208 
209  LSET( const BASE_SET& aOther ) :
210  BASE_SET( aOther )
211  {
212  }
213 
229  LSET( LAYER_ID aLayer ) : // LAYER_ID deliberately exludes int and relatives
230  BASE_SET()
231  {
232  set( aLayer );
233  }
234 
239  LSET( const LAYER_ID* aArray, unsigned aCount );
240 
253  LSET( unsigned aIdCount, int aFirst, ... ); // args chosen to prevent LSET( int ) from compiling
254 
259  static const wxChar* Name( LAYER_ID aLayerId );
260 
266  static LSET InternalCuMask();
267 
272  static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
273 
278  static LSET ExternalCuMask();
279 
284  static LSET AllNonCuMask();
285 
286  static LSET AllLayersMask();
287 
292  static LSET FrontTechMask();
293 
299  static LSET FrontBoardTechMask();
300 
305  static LSET BackTechMask();
306 
312  static LSET BackBoardTechMask();
313 
318  static LSET AllTechMask();
319 
324  static LSET AllBoardTechMask();
325 
330  static LSET FrontMask();
331 
336  static LSET BackMask();
337 
338  static LSET UserMask();
339 
340 
347  LSEQ CuStack() const;
348 
355  LSEQ Technicals( LSET aSubToOmit = LSET() ) const;
356 
358  LSEQ Users() const;
359 
360  LSEQ UIOrder() const;
361 
370  LSEQ Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const;
371 
379  LSEQ Seq() const;
380 
386  LSEQ SeqStackupBottom2Top() const;
387 
392  std::string FmtHex() const;
393 
402  int ParseHex( const char* aStart, int aCount );
403 
408  std::string FmtBin() const;
409 
414  LAYER_ID ExtractLayer() const;
415 
416 private:
417 
419  LSET( unsigned long __val )
420  {
421  // not usable, it's private.
422  }
423 };
424 
425 
433 {
447 
448  // the rest of these do not currently support color changes:
454 
459 
463 
465 };
466 
467 // Some elements do not have yet a visibility control
468 // from a dialog, but have a visibility control flag.
469 // Here is a mask to set them visible, to be sure they are displayed
470 // after loading a board for instance
471 #define MIN_VISIBILITY_MASK int( (1 << TRACKS_VISIBLE) +\
472  (1 << PADS_VISIBLE) +\
473  (1 << PADS_HOLES_VISIBLE) +\
474  (1 << VIAS_HOLES_VISIBLE) +\
475  (1 << DRC_VISIBLE) +\
476  (1 << WORKSHEET) +\
477  (1 << GP_OVERLAY) )
478 
485 #if 0
486 // was:
487 enum NETNAMES_VISIBLE
488 {
489  LAYER_1_NETNAMES_VISIBLE, // bottom layer
490  LAYER_2_NETNAMES_VISIBLE,
491  LAYER_3_NETNAMES_VISIBLE,
492  LAYER_4_NETNAMES_VISIBLE,
493  LAYER_5_NETNAMES_VISIBLE,
494  LAYER_6_NETNAMES_VISIBLE,
495  LAYER_7_NETNAMES_VISIBLE,
496  LAYER_8_NETNAMES_VISIBLE,
497  LAYER_9_NETNAMES_VISIBLE,
498  LAYER_10_NETNAMES_VISIBLE,
499  LAYER_11_NETNAMES_VISIBLE,
500  LAYER_12_NETNAMES_VISIBLE,
501  LAYER_13_NETNAMES_VISIBLE,
502  LAYER_14_NETNAMES_VISIBLE,
503  LAYER_15_NETNAMES_VISIBLE,
504  LAYER_16_NETNAMES_VISIBLE, // top layer
505 
509 
510  END_NETNAMES_VISIBLE_LIST // sentinel
511 };
512 #else
514 {
518 
520 };
521 #endif
522 
523 
525 #define ITEM_GAL_LAYER(layer) (LAYER_ID_COUNT + layer)
526 
527 #define NETNAMES_GAL_LAYER(layer) (LAYER_ID_COUNT + END_PCB_VISIBLE_LIST + layer )
528 
530 #define TOTAL_LAYER_COUNT (LAYER_ID_COUNT + END_PCB_VISIBLE_LIST + END_NETNAMES_VISIBLE_LIST)
531 
540 inline bool IsValidLayer( LAYER_NUM aLayerId )
541 {
542  return unsigned( aLayerId ) < LAYER_ID_COUNT;
543 }
544 
551 inline bool IsPcbLayer( LAYER_NUM aLayer )
552 {
553  return aLayer >= F_Cu && aLayer < LAYER_ID_COUNT;
554 }
555 
562 inline bool IsCopperLayer( LAYER_NUM aLayerId )
563 {
564  return aLayerId >= F_Cu && aLayerId <= B_Cu;
565 }
566 
573 inline bool IsNonCopperLayer( LAYER_NUM aLayerId )
574 {
575  return aLayerId > B_Cu && aLayerId <= LAYER_ID_COUNT;
576 }
577 
584 inline bool IsUserLayer( LAYER_ID aLayerId )
585 {
586  return aLayerId >= Dwgs_User && aLayerId <= Eco2_User;
587 }
588 
589 /* IMPORTANT: If a layer is not a front layer not necessarily is true
590  the converse. The same hold for a back layer.
591  So a layer can be:
592  - Front
593  - Back
594  - Neither (internal or auxiliary)
595 
596  The check most frequent is for back layers, since it involves flips */
597 
598 
602 inline bool IsFrontLayer( LAYER_ID aLayerId )
603 {
604  switch( aLayerId )
605  {
606  case F_Cu:
607  case F_Adhes:
608  case F_Paste:
609  case F_SilkS:
610  case F_Mask:
611  case F_CrtYd:
612  case F_Fab:
613  return true;
614  default:
615  ;
616  }
617 
618  return false;
619 }
620 
621 
625 inline bool IsBackLayer( LAYER_ID aLayerId )
626 {
627  switch( aLayerId )
628  {
629  case B_Cu:
630  case B_Adhes:
631  case B_Paste:
632  case B_SilkS:
633  case B_Mask:
634  case B_CrtYd:
635  case B_Fab:
636  return true;
637  default:
638  ;
639  }
640 
641  return false;
642 }
643 
644 
655 LAYER_ID FlipLayer( LAYER_ID aLayerId, int aCopperLayersCount = 0 );
656 
665 LSET FlipLayerMask( LSET aMask, int aCopperLayersCount = 0 );
666 
667 
671 inline int GetNetnameLayer( int aLayer )
672 {
673  if( IsCopperLayer( aLayer ) )
674  return NETNAMES_GAL_LAYER( aLayer );
675  else if( aLayer == ITEM_GAL_LAYER( PADS_VISIBLE ) )
677  else if( aLayer == ITEM_GAL_LAYER( PAD_FR_VISIBLE ) )
679  else if( aLayer == ITEM_GAL_LAYER( PAD_BK_VISIBLE ) )
681 
682  // Fallback
683  return Cmts_User;
684 }
685 
692 inline bool IsNetnameLayer( LAYER_NUM aLayer )
693 {
694  return aLayer >= NETNAMES_GAL_LAYER( F_Cu ) &&
696 }
697 
698 
699 LAYER_ID ToLAYER_ID( int aLayer );
700 
701 #endif // LAYERS_ID_AND_VISIBILITY_H_
show modules on front
multilayer pads, usually with holes
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
static LSET FrontBoardTechMask()
Function FrontBoardTechMask returns a mask holding technical layers used in a board fabrication (no C...
Definition: lset.cpp:701
LSET(const BASE_SET &aOther)
text marked as invisible
LAYER_ID operator*() const
std::string FmtHex() const
Function FmtHex returns a hex string showing contents of this LSEQ.
Definition: lset.cpp:252
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
static LSET BackTechMask()
Function BackTechMask returns a mask holding all technical layers (no CU layer) on back side...
Definition: lset.cpp:682
bool IsBackLayer(LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
LAYER_ID FlipLayer(LAYER_ID aLayerId, int aCopperLayersCount=0)
Function FlippedLayerNumber.
Definition: lset.cpp:444
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:146
show a marker on pads with no nets
bool IsFrontLayer(LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
static const wxChar * Name(LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:73
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:661
LAYER_ID ExtractLayer() const
Find the first set LAYER_ID.
Definition: lset.cpp:577
static LSET FrontTechMask()
Function FrontTechMask returns a mask holding all technical layers (no CU layer) on front side...
Definition: lset.cpp:694
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side...
Definition: lset.cpp:708
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:737
LSEQ SeqStackupBottom2Top() const
Function SeqStackBottom2Top returns the sequence that is typical for a bottom-to-top stack-up...
Definition: lset.cpp:384
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
bool IsUserLayer(LAYER_ID aLayerId)
Function IsUserLayer tests whether a layer is a non copper and a non tech layer.
This file contains miscellaneous commonly used macros and functions.
LSEQ Seq() const
Function Seq returns a LSEQ from this LSET in ascending LAYER_ID order.
Definition: lset.cpp:370
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:490
std::bitset< LAYER_ID_COUNT > BASE_SET
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
Class LSET is a set of LAYER_IDs.
PCB_VISIBLE
Enum PCB_VISIBLE is a set of visible PCB elements.
show modules references (when texts are visibles)
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:598
static LSET ExternalCuMask()
Function ExternalCuMask returns a mask holding the Front and Bottom layers.
Definition: lset.cpp:668
static LSET AllLayersMask()
Definition: lset.cpp:675
LSEQ Technicals(LSET aSubToOmit=LSET()) const
Function Technicals returns a sequence of technical layers.
Definition: lset.cpp:188
Class LSEQ is a sequence (and therefore also a set) of LAYER_IDs.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
NETNAMES_VISIBLE
Enum NETNAMES_VISIBLE is a set of layers specific for displaying net names.
#define ITEM_GAL_LAYER(layer)
macro for obtaining layer number for specific item (eg. pad or text)
LSET()
Constructor LSET() creates an empty (cleared) set.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
static LSET BackBoardTechMask()
Function BackBoardTechMask returns a mask holding technical layers used in a board fabrication (no CU...
Definition: lset.cpp:688
LSET(LAYER_ID aLayer)
Constructor LSET( LAYER_ID ) takes a LAYER_ID and sets that bit.
std::string FmtBin() const
Function FmtBin returns a binary string showing contents of this LSEQ.
Definition: lset.cpp:228
static LSET BackMask()
Function BackMask returns a mask holding all technical layers and the external CU layer on back side...
Definition: lset.cpp:744
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:715
LSEQ(InputIterator aStart, InputIterator aEnd)
general purpose overlay
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:212
std::vector< LAYER_ID > BASE_SEQ
A sequence of layers, a sequence provides a certain order.
static LSET UserMask()
Definition: lset.cpp:722
LSET(unsigned long __val)
Take this off the market, it may not be used because of LSET( 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:284
#define NETNAMES_GAL_LAYER(layer)
show modules values (when texts are visibles)
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
LSEQ UIOrder() const
Definition: lset.cpp:751