KiCad PCB EDA Suite
lset.cpp File Reference
#include <bitset>
#include <cassert>
#include <cstdarg>
#include <iostream>
#include <stddef.h>
#include <core/arraydim.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)
 
LSET FlipLayerMask (LSET aMask, int aCopperLayersCount)
 Calculate the mask layer when flipping a footprint. More...
 
PCB_LAYER_ID ToLAYER_ID (int aLayer)
 

Function Documentation

◆ FlipLayer()

PCB_LAYER_ID FlipLayer ( PCB_LAYER_ID  aLayerId,
int  aCopperLayersCount = 0 
)
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 521 of file lset.cpp.

522 {
523  switch( aLayerId )
524  {
525  case B_Cu: return F_Cu;
526  case F_Cu: return B_Cu;
527 
528  case B_SilkS: return F_SilkS;
529  case F_SilkS: return B_SilkS;
530 
531  case B_Adhes: return F_Adhes;
532  case F_Adhes: return B_Adhes;
533 
534  case B_Mask: return F_Mask;
535  case F_Mask: return B_Mask;
536 
537  case B_Paste: return F_Paste;
538  case F_Paste: return B_Paste;
539 
540  case B_CrtYd: return F_CrtYd;
541  case F_CrtYd: return B_CrtYd;
542 
543  case B_Fab: return F_Fab;
544  case F_Fab: return B_Fab;
545 
546  default: // change internal layer if aCopperLayersCount is >= 4
547  if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
548  {
549  // internal copper layers count is aCopperLayersCount-2
550  PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
551  // Ensure fliplayer has a value which does not crash Pcbnew:
552  if( fliplayer < F_Cu )
553  fliplayer = F_Cu;
554 
555  if( fliplayer > B_Cu )
556  fliplayer = B_Cu;
557 
558  return fliplayer;
559  }
560 
561  // No change for the other layers
562  return aLayerId;
563  }
564 }
PCB_LAYER_ID
A quick note on layer IDs:
bool IsCopperLayer(LAYER_NUM aLayerId)
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_FOOTPRINT::AddToBoard(), PCAD2KICAD::PCB_PAD::Flip(), PCAD2KICAD::PCB_ARC::Flip(), PCAD2KICAD::PCB_LINE::Flip(), PCAD2KICAD::PCB_POLYGON::Flip(), PCB_TARGET::Flip(), PCB_TEXT::Flip(), FP_SHAPE::Flip(), TRACK::Flip(), FP_TEXT::Flip(), DIMENSION_BASE::Flip(), FOOTPRINT::Flip(), ARC::Flip(), PCB_SHAPE::Flip(), VIA::Flip(), and ZONE::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 567 of file lset.cpp.

568 {
569  // layers on physical outside of a board:
570  const static LSET and_mask( 16, // !! update count
571  B_Cu, F_Cu,
572  B_SilkS, F_SilkS,
573  B_Adhes, F_Adhes,
574  B_Mask, F_Mask,
575  B_Paste, F_Paste,
576  B_Adhes, F_Adhes,
577  B_CrtYd, F_CrtYd,
578  B_Fab, F_Fab
579  );
580 
581  LSET newMask = aMask & ~and_mask;
582 
583  if( aMask[B_Cu] )
584  newMask.set( F_Cu );
585 
586  if( aMask[F_Cu] )
587  newMask.set( B_Cu );
588 
589  if( aMask[B_SilkS] )
590  newMask.set( F_SilkS );
591 
592  if( aMask[F_SilkS] )
593  newMask.set( B_SilkS );
594 
595  if( aMask[B_Adhes] )
596  newMask.set( F_Adhes );
597 
598  if( aMask[F_Adhes] )
599  newMask.set( B_Adhes );
600 
601  if( aMask[B_Mask] )
602  newMask.set( F_Mask );
603 
604  if( aMask[F_Mask] )
605  newMask.set( B_Mask );
606 
607  if( aMask[B_Paste] )
608  newMask.set( F_Paste );
609 
610  if( aMask[F_Paste] )
611  newMask.set( B_Paste );
612 
613  if( aMask[B_Adhes] )
614  newMask.set( F_Adhes );
615 
616  if( aMask[F_Adhes] )
617  newMask.set( B_Adhes );
618 
619  if( aMask[B_CrtYd] )
620  newMask.set( F_CrtYd );
621 
622  if( aMask[F_CrtYd] )
623  newMask.set( B_CrtYd );
624 
625  if( aMask[B_Fab] )
626  newMask.set( F_Fab );
627 
628  if( aMask[F_Fab] )
629  newMask.set( B_Fab );
630 
631  if( aCopperLayersCount >= 4 ) // Internal layers exist
632  {
633  LSET internalMask = aMask & LSET::InternalCuMask();
634 
635  if( internalMask != LSET::InternalCuMask() )
636  {
637  // the mask does not include all internal layers. Therefore
638  // the flipped mask for internal copper layers must be built
639  int innerLayerCnt = aCopperLayersCount -2;
640 
641  // the flipped mask is the innerLayerCnt bits rewritten in reverse order
642  // ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
643  for( int ii = 0; ii < innerLayerCnt; ii++ )
644  {
645  if( internalMask[innerLayerCnt - ii] )
646  {
647  newMask.set( ii + In1_Cu );
648  }
649  else
650  {
651  newMask.reset( ii + In1_Cu );
652  }
653  }
654  }
655  }
656 
657  return newMask;
658 }
LSET is a set of PCB_LAYER_IDs.
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:710

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 PAD::Flip(), ZONE::Flip(), and ALTIUM_PCB::ParsePads6Data().

◆ ToLAYER_ID()

PCB_LAYER_ID ToLAYER_ID ( int  aLayer)

Definition at line 898 of file lset.cpp.

899 {
900  wxASSERT( aLayer < GAL_LAYER_ID_END );
901  return PCB_LAYER_ID( aLayer );
902 }
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(), KIGFX::PCB_PAINTER::draw(), DRAWING_TOOL::DrawVia(), PCB_LAYER_VALUE::EqualTo(), existsOnLayer(), GENDRILL_WRITER_BASE::GenDrillReportFile(), GetGerberFileFunctionAttribute(), BOARD::GetLayerID(), PCB_LAYER_SELECTOR::getLayerName(), PCB_LAYER_BOX_SELECTOR::getLayerName(), DIALOG_IMPORTED_LAYERS::GetSelectedLayerID(), GRID_CELL_LAYER_SELECTOR::GetValue(), PCB_LAYER_BOX_SELECTOR::isLayerEnabled(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCAD2KICAD::PCB::MapLayer(), APPEARANCE_CONTROLS::onLayerClick(), DIALOG_RULE_AREA_PROPERTIES::OnLayerSelection(), DIALOG_NON_COPPER_ZONES_EDITOR::OnLayerSelection(), DIALOG_COPPER_ZONE::OnLayerSelection(), PLOT_CONTROLLER::OpenPlotfile(), DRC_RULES_PARSER::parseLayer(), 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(), SELECTION_TOOL::Selectable(), FOOTPRINT_EDIT_FRAME::SelectLayer(), PCB_BASE_FRAME::SelectLayer(), DIALOG_GLOBAL_DELETION::SetCurrentLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), TEXT_MOD_GRID_TABLE::SetValueAsLong(), ROUTER_TOOL::switchLayerOnViaPlacement(), PNS_KICAD_IFACE_BASE::syncZone(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), and DIALOG_TEXT_PROPERTIES::TransferDataFromWindow().