KiCad PCB EDA Suite
lset.cpp File Reference
#include <stdarg.h>
#include <assert.h>
#include <layers_id_colors_and_visibility.h>
#include <class_board.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

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 472 of file lset.cpp.

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(), TEXTE_PCB::Flip(), PCB_TARGET::Flip(), EDGE_MODULE::Flip(), TEXTE_MODULE::Flip(), TRACK::Flip(), DIMENSION::Flip(), MODULE::Flip(), DRAWSEGMENT::Flip(), ZONE_CONTAINER::Flip(), VIA::Flip(), and IsBackLayer().

473 {
474  switch( aLayerId )
475  {
476  case B_Cu: return F_Cu;
477  case F_Cu: return B_Cu;
478 
479  case B_SilkS: return F_SilkS;
480  case F_SilkS: return B_SilkS;
481 
482  case B_Adhes: return F_Adhes;
483  case F_Adhes: return B_Adhes;
484 
485  case B_Mask: return F_Mask;
486  case F_Mask: return B_Mask;
487 
488  case B_Paste: return F_Paste;
489  case F_Paste: return B_Paste;
490 
491  case B_CrtYd: return F_CrtYd;
492  case F_CrtYd: return B_CrtYd;
493 
494  case B_Fab: return F_Fab;
495  case F_Fab: return B_Fab;
496 
497  default: // change internal layer if aCopperLayersCount is >= 4
498  if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
499  {
500  // internal copper layers count is aCopperLayersCount-2
501  PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
502  // Ensure fliplayer has a value which does not crash pcbnew:
503  if( fliplayer < F_Cu )
504  fliplayer = F_Cu;
505 
506  if( fliplayer > B_Cu )
507  fliplayer = B_Cu;
508 
509  return fliplayer;
510  }
511 
512  // No change for the other layers
513  return aLayerId;
514  }
515 }
PCB_LAYER_ID
A quick note on layer IDs:
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
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 518 of file lset.cpp.

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(), IsBackLayer(), and DIALOG_PAD_PROPERTIES::TransferDataFromWindow().

519 {
520  // layers on physical outside of a board:
521  const static LSET and_mask( 16, // !! update count
522  B_Cu, F_Cu,
523  B_SilkS, F_SilkS,
524  B_Adhes, F_Adhes,
525  B_Mask, F_Mask,
526  B_Paste, F_Paste,
527  B_Adhes, F_Adhes,
528  B_CrtYd, F_CrtYd,
529  B_Fab, F_Fab
530  );
531 
532  LSET newMask = aMask & ~and_mask;
533 
534  if( aMask[B_Cu] )
535  newMask.set( F_Cu );
536 
537  if( aMask[F_Cu] )
538  newMask.set( B_Cu );
539 
540  if( aMask[B_SilkS] )
541  newMask.set( F_SilkS );
542 
543  if( aMask[F_SilkS] )
544  newMask.set( B_SilkS );
545 
546  if( aMask[B_Adhes] )
547  newMask.set( F_Adhes );
548 
549  if( aMask[F_Adhes] )
550  newMask.set( B_Adhes );
551 
552  if( aMask[B_Mask] )
553  newMask.set( F_Mask );
554 
555  if( aMask[F_Mask] )
556  newMask.set( B_Mask );
557 
558  if( aMask[B_Paste] )
559  newMask.set( F_Paste );
560 
561  if( aMask[F_Paste] )
562  newMask.set( B_Paste );
563 
564  if( aMask[B_Adhes] )
565  newMask.set( F_Adhes );
566 
567  if( aMask[F_Adhes] )
568  newMask.set( B_Adhes );
569 
570  if( aMask[B_CrtYd] )
571  newMask.set( F_CrtYd );
572 
573  if( aMask[F_CrtYd] )
574  newMask.set( B_CrtYd );
575 
576  if( aMask[B_Fab] )
577  newMask.set( F_Fab );
578 
579  if( aMask[F_Fab] )
580  newMask.set( B_Fab );
581 
582  if( aCopperLayersCount >= 4 ) // Internal layers exist
583  {
584  LSET internalMask = aMask & LSET::InternalCuMask();
585 
586  if( internalMask != LSET::InternalCuMask() )
587  {
588  // the mask does not include all internal layers. Therefore
589  // the flipped mask for internal copper layers must be built
590  int innerLayerCnt = aCopperLayersCount -2;
591 
592  // the flipped mask is the innerLayerCnt bits rewritten in reverse order
593  // ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
594  for( int ii = 0; ii < innerLayerCnt; ii++ )
595  {
596  if( internalMask[innerLayerCnt - ii] )
597  {
598  newMask.set( ii + In1_Cu );
599  }
600  else
601  {
602  newMask.reset( ii + In1_Cu );
603  }
604  }
605  }
606  }
607 
608  return newMask;
609 }
Class 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:633
PCB_LAYER_ID ToLAYER_ID ( int  aLayer)

Definition at line 810 of file lset.cpp.

References GAL_LAYER_ID_END.

Referenced by DIALOG_GLOBAL_DELETION::AcceptPcbDelete(), DXF2BRD_CONVERTER::addArc(), DXF2BRD_CONVERTER::addCircle(), PNS_KICAD_IFACE::AddItem(), DXF2BRD_CONVERTER::addLine(), DXF2BRD_CONVERTER::addMText(), DXF2BRD_CONVERTER::addText(), GRID_CELL_LAYER_SELECTOR::BeginEdit(), BOARD::BOARD(), DSN::SPECCTRA_DB::buildLayerMaps(), CINFO3D_VISU::createLayers(), PCB_BASE_FRAME::CreateNewModule(), 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(), DXF2BRD_CONVERTER::insertArc(), DXF2BRD_CONVERTER::insertLine(), DXF2BRD_CONVERTER::insertSpline(), IsDCodeLayer(), PCB_LAYER_BOX_SELECTOR::IsLayerEnabled(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCAD2KICAD::PCB::MapLayer(), PCB_EDIT_FRAME::OnHotKey(), 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(), PCB_EDIT_FRAME::Other_Layer_Route(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PLOT_CONTROLLER::PlotLayer(), ROUTER_TOOL::prepareInteractive(), 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().

811 {
812  wxASSERT( aLayer < GAL_LAYER_ID_END );
813  return PCB_LAYER_ID( aLayer );
814 }
Add new GAL layers here.
PCB_LAYER_ID
A quick note on layer IDs: