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

LAYER_ID FlipLayer (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...
 
LAYER_ID ToLAYER_ID (int aLayer)
 

Function Documentation

LAYER_ID FlipLayer ( 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
aLayer= the 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 444 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_ARC::Flip(), PCAD2KICAD::PCB_PAD::Flip(), PCAD2KICAD::PCB_LINE::Flip(), PCAD2KICAD::PCB_MODULE::Flip(), TEXTE_PCB::Flip(), PCB_TARGET::Flip(), EDGE_MODULE::Flip(), TEXTE_MODULE::Flip(), TRACK::Flip(), MODULE::Flip(), DIMENSION::Flip(), DRAWSEGMENT::Flip(), VIA::Flip(), and ZONE_CONTAINER::Flip().

445 {
446  switch( aLayerId )
447  {
448  case B_Cu: return F_Cu;
449  case F_Cu: return B_Cu;
450 
451  case B_SilkS: return F_SilkS;
452  case F_SilkS: return B_SilkS;
453 
454  case B_Adhes: return F_Adhes;
455  case F_Adhes: return B_Adhes;
456 
457  case B_Mask: return F_Mask;
458  case F_Mask: return B_Mask;
459 
460  case B_Paste: return F_Paste;
461  case F_Paste: return B_Paste;
462 
463  case B_CrtYd: return F_CrtYd;
464  case F_CrtYd: return B_CrtYd;
465 
466  case B_Fab: return F_Fab;
467  case F_Fab: return B_Fab;
468 
469  default: // change internal layer if aCopperLayersCount is >= 4
470  if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
471  {
472  // internal copper layers count is aCopperLayersCount-2
473  LAYER_ID fliplayer = LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
474  // Ensure fliplayer has a value which does not crash pcbnew:
475  if( fliplayer < F_Cu )
476  fliplayer = F_Cu;
477 
478  if( fliplayer > B_Cu )
479  fliplayer = B_Cu;
480 
481  return fliplayer;
482  }
483 
484  // No change for the other layers
485  return aLayerId;
486  }
487 }
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
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 490 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(), DIALOG_PAD_PROPERTIES::initValues(), and DIALOG_PAD_PROPERTIES::TransferDataFromWindow().

491 {
492  // layers on physical outside of a board:
493  const static LSET and_mask( 16, // !! update count
494  B_Cu, F_Cu,
495  B_SilkS, F_SilkS,
496  B_Adhes, F_Adhes,
497  B_Mask, F_Mask,
498  B_Paste, F_Paste,
499  B_Adhes, F_Adhes,
500  B_CrtYd, F_CrtYd,
501  B_Fab, F_Fab
502  );
503 
504  LSET newMask = aMask & ~and_mask;
505 
506  if( aMask[B_Cu] )
507  newMask.set( F_Cu );
508 
509  if( aMask[F_Cu] )
510  newMask.set( B_Cu );
511 
512  if( aMask[B_SilkS] )
513  newMask.set( F_SilkS );
514 
515  if( aMask[F_SilkS] )
516  newMask.set( B_SilkS );
517 
518  if( aMask[B_Adhes] )
519  newMask.set( F_Adhes );
520 
521  if( aMask[F_Adhes] )
522  newMask.set( B_Adhes );
523 
524  if( aMask[B_Mask] )
525  newMask.set( F_Mask );
526 
527  if( aMask[F_Mask] )
528  newMask.set( B_Mask );
529 
530  if( aMask[B_Paste] )
531  newMask.set( F_Paste );
532 
533  if( aMask[F_Paste] )
534  newMask.set( B_Paste );
535 
536  if( aMask[B_Adhes] )
537  newMask.set( F_Adhes );
538 
539  if( aMask[F_Adhes] )
540  newMask.set( B_Adhes );
541 
542  if( aMask[B_CrtYd] )
543  newMask.set( F_CrtYd );
544 
545  if( aMask[F_CrtYd] )
546  newMask.set( B_CrtYd );
547 
548  if( aMask[B_Fab] )
549  newMask.set( F_Fab );
550 
551  if( aMask[F_Fab] )
552  newMask.set( B_Fab );
553 
554  if( aCopperLayersCount >= 4 ) // Internal layers exist
555  {
556  LSET internalMask = aMask & ~LSET::InternalCuMask();
557 
558  if( internalMask != LSET::InternalCuMask() )
559  { // the mask does not include all internal layers. Therefore
560  // the flipped mask for internal copper layers must be built
561  int innerLayerCnt = aCopperLayersCount -2;
562 
563  for( int ii = 0; ii < innerLayerCnt; ii++ )
564  {
565  if( internalMask[innerLayerCnt - ii + In1_Cu] )
566  newMask.set( ii + In1_Cu );
567  else
568  newMask.reset( ii + In1_Cu );
569  }
570  }
571  }
572 
573  return newMask;
574 }
Class LSET is a set of LAYER_IDs.
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:598
LAYER_ID ToLAYER_ID ( int  aLayer)

Definition at line 766 of file lset.cpp.

References LAYER_ID_COUNT.

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_KEEPOUT_AREA_PROPERTIES::AcceptOptionsForKeepOut(), DIALOG_GLOBAL_DELETION::AcceptPcbDelete(), DXF2BRD_CONVERTER::addArc(), DXF2BRD_CONVERTER::addCircle(), PNS_KICAD_IFACE::AddItem(), DXF2BRD_CONVERTER::addLine(), DXF2BRD_CONVERTER::addMText(), DXF2BRD_CONVERTER::addPolyline(), DXF2BRD_CONVERTER::addText(), BOARD::BOARD(), DSN::SPECCTRA_DB::buildLayerMaps(), CINFO3D_VISU::createLayers(), PCB_BASE_FRAME::CreateNewModule(), EVT_COMMAND_RANGE(), EXCELLON_WRITER::GenDrillReportFile(), BRDITEMS_PLOTTER::getColor(), GetGerberFileFunctionAttribute(), PCB_LAYER_SELECTOR::GetLayerColor(), PCB_LAYER_BOX_SELECTOR::GetLayerColor(), BOARD::GetLayerID(), PCB_LAYER_SELECTOR::GetLayerName(), PCB_LAYER_BOX_SELECTOR::GetLayerName(), DXF2BRD_CONVERTER::insertArc(), DXF2BRD_CONVERTER::insertLine(), PCB_LAYER_BOX_SELECTOR::IsLayerEnabled(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCAD2KICAD::PCB::MapLayer(), PCB_EDIT_FRAME::OnHotKey(), PCB_LAYER_WIDGET::OnLayerColorChange(), PCB_LAYER_WIDGET::OnLayerSelect(), DIALOG_DIMENSION_EDITOR::OnOKClick(), 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(), SWAP_LAYERS_DIALOG::Sel_Layer(), PCB_BASE_FRAME::SelectLayer(), DIALOG_GLOBAL_DELETION::SetCurrentLayer(), ROUTER_TOOL::switchLayerOnViaPlacement(), PCB_LAYER_WIDGET::SyncLayerVisibilities(), DialogEditModuleText::TransferDataFromWindow(), DIALOG_PCB_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), and DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataFromWindow().

767 {
768  wxASSERT( unsigned( aLayer ) < LAYER_ID_COUNT );
769  return LAYER_ID( aLayer );
770 }
LAYER_ID
Enum LAYER_ID is the set of PCB layers.