KiCad PCB EDA Suite
lset.cpp File Reference
#include <bitset>
#include <cassert>
#include <cstdarg>
#include <iostream>
#include <stddef.h>
#include <math/util.h>
#include <layers_id_colors_and_visibility.h>
#include <macros.h>
#include <wx/debug.h>
#include <wx/wx.h>

Go to the source code of this file.

Functions

PCB_LAYER_ID FlipLayer (PCB_LAYER_ID aLayerId, int aCopperLayersCount)
 Function FlippedLayerNumber. More...
 
LSET FlipLayerMask (LSET aMask, int aCopperLayersCount)
 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. More...
 
PCB_LAYER_ID ToLAYER_ID (int aLayer)
 

Function Documentation

◆ FlipLayer()

PCB_LAYER_ID FlipLayer ( PCB_LAYER_ID  aLayerId,
int  aCopperLayersCount = 0 
)

Function FlippedLayerNumber.

Returns
the layer number after flipping an item some (not all) layers: external copper, and paired layers( Mask, Paste, solder ... ) are swapped between front and back sides internal layers are flipped only if the copper layers count is known
Parameters
aLayerId= the PCB_LAYER_ID to flip
aCopperLayersCount= the number of copper layers. if 0 (in fact if < 4 ) internal layers will be not flipped because the layer count is not known

Definition at line 485 of file lset.cpp.

486 {
487  switch( aLayerId )
488  {
489  case B_Cu: return F_Cu;
490  case F_Cu: return B_Cu;
491 
492  case B_SilkS: return F_SilkS;
493  case F_SilkS: return B_SilkS;
494 
495  case B_Adhes: return F_Adhes;
496  case F_Adhes: return B_Adhes;
497 
498  case B_Mask: return F_Mask;
499  case F_Mask: return B_Mask;
500 
501  case B_Paste: return F_Paste;
502  case F_Paste: return B_Paste;
503 
504  case B_CrtYd: return F_CrtYd;
505  case F_CrtYd: return B_CrtYd;
506 
507  case B_Fab: return F_Fab;
508  case F_Fab: return B_Fab;
509 
510  default: // change internal layer if aCopperLayersCount is >= 4
511  if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
512  {
513  // internal copper layers count is aCopperLayersCount-2
514  PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
515  // Ensure fliplayer has a value which does not crash pcbnew:
516  if( fliplayer < F_Cu )
517  fliplayer = F_Cu;
518 
519  if( fliplayer > B_Cu )
520  fliplayer = B_Cu;
521 
522  return fliplayer;
523  }
524 
525  // No change for the other layers
526  return aLayerId;
527  }
528 }
PCB_LAYER_ID
A quick note on layer IDs:
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.

References B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, In1_Cu, and IsCopperLayer().

Referenced by PCAD2KICAD::PCB_MODULE::AddToBoard(), PCAD2KICAD::PCB_PAD::Flip(), PCAD2KICAD::PCB_LINE::Flip(), PCAD2KICAD::PCB_ARC::Flip(), PCAD2KICAD::PCB_POLYGON::Flip(), PCB_TARGET::Flip(), TEXTE_PCB::Flip(), EDGE_MODULE::Flip(), TRACK::Flip(), TEXTE_MODULE::Flip(), DIMENSION::Flip(), DRAWSEGMENT::Flip(), MODULE::Flip(), ARC::Flip(), VIA::Flip(), and ZONE_CONTAINER::Flip().

◆ FlipLayerMask()

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.

Parameters
aMask= the LSET to flip
aCopperLayersCount= the number of copper layers. if 0 (in fact if < 4 ) internal layers will be not flipped because the layer count is not known

Definition at line 531 of file lset.cpp.

532 {
533  // layers on physical outside of a board:
534  const static LSET and_mask( 16, // !! update count
535  B_Cu, F_Cu,
536  B_SilkS, F_SilkS,
537  B_Adhes, F_Adhes,
538  B_Mask, F_Mask,
539  B_Paste, F_Paste,
540  B_Adhes, F_Adhes,
541  B_CrtYd, F_CrtYd,
542  B_Fab, F_Fab
543  );
544 
545  LSET newMask = aMask & ~and_mask;
546 
547  if( aMask[B_Cu] )
548  newMask.set( F_Cu );
549 
550  if( aMask[F_Cu] )
551  newMask.set( B_Cu );
552 
553  if( aMask[B_SilkS] )
554  newMask.set( F_SilkS );
555 
556  if( aMask[F_SilkS] )
557  newMask.set( B_SilkS );
558 
559  if( aMask[B_Adhes] )
560  newMask.set( F_Adhes );
561 
562  if( aMask[F_Adhes] )
563  newMask.set( B_Adhes );
564 
565  if( aMask[B_Mask] )
566  newMask.set( F_Mask );
567 
568  if( aMask[F_Mask] )
569  newMask.set( B_Mask );
570 
571  if( aMask[B_Paste] )
572  newMask.set( F_Paste );
573 
574  if( aMask[F_Paste] )
575  newMask.set( B_Paste );
576 
577  if( aMask[B_Adhes] )
578  newMask.set( F_Adhes );
579 
580  if( aMask[F_Adhes] )
581  newMask.set( B_Adhes );
582 
583  if( aMask[B_CrtYd] )
584  newMask.set( F_CrtYd );
585 
586  if( aMask[F_CrtYd] )
587  newMask.set( B_CrtYd );
588 
589  if( aMask[B_Fab] )
590  newMask.set( F_Fab );
591 
592  if( aMask[F_Fab] )
593  newMask.set( B_Fab );
594 
595  if( aCopperLayersCount >= 4 ) // Internal layers exist
596  {
597  LSET internalMask = aMask & LSET::InternalCuMask();
598 
599  if( internalMask != LSET::InternalCuMask() )
600  {
601  // the mask does not include all internal layers. Therefore
602  // the flipped mask for internal copper layers must be built
603  int innerLayerCnt = aCopperLayersCount -2;
604 
605  // the flipped mask is the innerLayerCnt bits rewritten in reverse order
606  // ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
607  for( int ii = 0; ii < innerLayerCnt; ii++ )
608  {
609  if( internalMask[innerLayerCnt - ii] )
610  {
611  newMask.set( ii + In1_Cu );
612  }
613  else
614  {
615  newMask.reset( ii + In1_Cu );
616  }
617  }
618  }
619  }
620 
621  return newMask;
622 }
LSET is a set of PCB_LAYER_IDs.
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:672

References B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, In1_Cu, and LSET::InternalCuMask().

Referenced by D_PAD::Flip(), ZONE_CONTAINER::Flip(), DIALOG_PAD_PROPERTIES::initValues(), ALTIUM_PCB::ParsePads6Data(), and DIALOG_PAD_PROPERTIES::TransferDataFromWindow().

◆ ToLAYER_ID()

PCB_LAYER_ID ToLAYER_ID ( int  aLayer)

Definition at line 849 of file lset.cpp.

850 {
851  wxASSERT( aLayer < GAL_LAYER_ID_END );
852  return PCB_LAYER_ID( aLayer );
853 }
Add new GAL layers here.
PCB_LAYER_ID
A quick note on layer IDs:

References GAL_LAYER_ID_END.

Referenced by DIALOG_GLOBAL_DELETION::AcceptPcbDelete(), PNS_KICAD_IFACE::AddItem(), GRID_CELL_LAYER_SELECTOR::BeginEdit(), BOARD::BOARD(), DSN::SPECCTRA_DB::buildLayerMaps(), BOARD_ADAPTER::createLayers(), GRID_CELL_LAYER_RENDERER::Draw(), DRAWING_TOOL::DrawVia(), GENDRILL_WRITER_BASE::GenDrillReportFile(), GetGerberFileFunctionAttribute(), BOARD::GetLayerID(), PCB_LAYER_SELECTOR::getLayerName(), PCB_LAYER_BOX_SELECTOR::getLayerName(), GRID_CELL_LAYER_SELECTOR::GetValue(), PCB_LAYER_BOX_SELECTOR::isLayerEnabled(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCAD2KICAD::PCB::MapLayer(), PCB_LAYER_WIDGET::OnLayerSelect(), DIALOG_KEEPOUT_AREA_PROPERTIES::OnLayerSelection(), DIALOG_NON_COPPER_ZONES_EDITOR::OnLayerSelection(), DIALOG_COPPER_ZONE::OnLayerSelection(), PCB_LAYER_WIDGET::onPopupSelection(), PLOT_CONTROLLER::OpenPlotfile(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PLOT_CONTROLLER::PlotLayer(), ROUTER_TOOL::prepareInteractive(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), PCB_EDIT_FRAME::Process_Special_Functions(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), PCB_BASE_FRAME::SelectLayer(), DIALOG_GLOBAL_DELETION::SetCurrentLayer(), TEXT_MOD_GRID_TABLE::SetValueAsLong(), ROUTER_TOOL::switchLayerOnViaPlacement(), PCB_LAYER_WIDGET::SyncLayerAlphaIndicators(), PCB_LAYER_WIDGET::SyncLayerVisibilities(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow().