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 <layer_ids.h>
#include <macros.h>
#include <wx/debug.h>
#include <wx/string.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 544 of file lset.cpp.

545{
546 switch( aLayerId )
547 {
548 case B_Cu: return F_Cu;
549 case F_Cu: return B_Cu;
550
551 case B_SilkS: return F_SilkS;
552 case F_SilkS: return B_SilkS;
553
554 case B_Adhes: return F_Adhes;
555 case F_Adhes: return B_Adhes;
556
557 case B_Mask: return F_Mask;
558 case F_Mask: return B_Mask;
559
560 case B_Paste: return F_Paste;
561 case F_Paste: return B_Paste;
562
563 case B_CrtYd: return F_CrtYd;
564 case F_CrtYd: return B_CrtYd;
565
566 case B_Fab: return F_Fab;
567 case F_Fab: return B_Fab;
568
569 default: // change internal layer if aCopperLayersCount is >= 4
570 if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
571 {
572 // internal copper layers count is aCopperLayersCount-2
573 PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
574 // Ensure fliplayer has a value which does not crash Pcbnew:
575 if( fliplayer < F_Cu )
576 fliplayer = F_Cu;
577
578 if( fliplayer > B_Cu )
579 fliplayer = B_Cu;
580
581 return fliplayer;
582 }
583
584 // No change for the other layers
585 return aLayerId;
586 }
587}
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:827
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ F_CrtYd
Definition: layer_ids.h:117
@ B_Adhes
Definition: layer_ids.h:97
@ F_Paste
Definition: layer_ids.h:101
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ F_Fab
Definition: layer_ids.h:120
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ In1_Cu
Definition: layer_ids.h:65
@ B_SilkS
Definition: layer_ids.h:103
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:119

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_ARC::Flip(), PCAD2KICAD::PCB_LINE::Flip(), PCAD2KICAD::PCB_PAD::Flip(), PCAD2KICAD::PCB_POLYGON::Flip(), FOOTPRINT::Flip(), FP_SHAPE::Flip(), FP_TEXT::Flip(), PCB_DIMENSION_BASE::Flip(), PCB_SHAPE::Flip(), PCB_TARGET::Flip(), PCB_TEXT::Flip(), PCB_TEXTBOX::Flip(), PCB_TRACK::Flip(), PCB_ARC::Flip(), PCB_VIA::Flip(), and FABMASTER::loadFootprints().

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

591{
592 // layers on physical outside of a board:
593 const static LSET and_mask( 16, // !! update count
594 B_Cu, F_Cu,
597 B_Mask, F_Mask,
601 B_Fab, F_Fab
602 );
603
604 LSET newMask = aMask & ~and_mask;
605
606 if( aMask[B_Cu] )
607 newMask.set( F_Cu );
608
609 if( aMask[F_Cu] )
610 newMask.set( B_Cu );
611
612 if( aMask[B_SilkS] )
613 newMask.set( F_SilkS );
614
615 if( aMask[F_SilkS] )
616 newMask.set( B_SilkS );
617
618 if( aMask[B_Adhes] )
619 newMask.set( F_Adhes );
620
621 if( aMask[F_Adhes] )
622 newMask.set( B_Adhes );
623
624 if( aMask[B_Mask] )
625 newMask.set( F_Mask );
626
627 if( aMask[F_Mask] )
628 newMask.set( B_Mask );
629
630 if( aMask[B_Paste] )
631 newMask.set( F_Paste );
632
633 if( aMask[F_Paste] )
634 newMask.set( B_Paste );
635
636 if( aMask[B_Adhes] )
637 newMask.set( F_Adhes );
638
639 if( aMask[F_Adhes] )
640 newMask.set( B_Adhes );
641
642 if( aMask[B_CrtYd] )
643 newMask.set( F_CrtYd );
644
645 if( aMask[F_CrtYd] )
646 newMask.set( B_CrtYd );
647
648 if( aMask[B_Fab] )
649 newMask.set( F_Fab );
650
651 if( aMask[F_Fab] )
652 newMask.set( B_Fab );
653
654 if( aCopperLayersCount >= 4 ) // Internal layers exist
655 {
656 LSET internalMask = aMask & LSET::InternalCuMask();
657
658 if( internalMask != LSET::InternalCuMask() )
659 {
660 // the mask does not include all internal layers. Therefore
661 // the flipped mask for internal copper layers must be built
662 int innerLayerCnt = aCopperLayersCount -2;
663
664 // the flipped mask is the innerLayerCnt bits rewritten in reverse order
665 // ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
666 for( int ii = 0; ii < innerLayerCnt; ii++ )
667 {
668 if( internalMask[innerLayerCnt - ii] )
669 {
670 newMask.set( ii + In1_Cu );
671 }
672 else
673 {
674 newMask.reset( ii + In1_Cu );
675 }
676 }
677 }
678 }
679
680 return newMask;
681}
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:532
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:733

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

◆ ToLAYER_ID()

PCB_LAYER_ID ToLAYER_ID ( int  aLayer)

Definition at line 932 of file lset.cpp.

933{
934 wxASSERT( aLayer < GAL_LAYER_ID_END );
935 return PCB_LAYER_ID( aLayer );
936}
@ GAL_LAYER_ID_END
Definition: layer_ids.h:260

References GAL_LAYER_ID_END.

Referenced by PNS_KICAD_IFACE::AddItem(), GRID_CELL_LAYER_SELECTOR::BeginEdit(), BOARD::BOARD(), DSN::SPECCTRA_DB::buildLayerMaps(), CN_ANCHOR::ConnectedItemsCount(), BOARD_ADAPTER::createLayers(), PCB_PROPERTIES_PANEL::createPGProperty(), PCB_MARKER::Deserialize(), KIGFX::PCB_PAINTER::draw(), GRID_CELL_LAYER_RENDERER::Draw(), DRAWING_TOOL::DrawVia(), PCB_LAYER_VALUE::EqualTo(), existsOnLayerFunc(), GENDRILL_WRITER_BASE::GenDrillReportFile(), GetGerberFileFunctionAttribute(), DIALOG_TRACK_VIA_PROPERTIES::getLayerDepth(), BOARD::GetLayerID(), PCB_LAYER_BOX_SELECTOR::getLayerName(), PCB_LAYER_SELECTOR::getLayerName(), DIALOG_IMPORTED_LAYERS::GetSelectedLayerID(), GRID_CELL_LAYER_SELECTOR::GetValue(), CONNECTIVITY_DATA::IsConnectedOnLayer(), CN_ANCHOR::IsDangling(), PNS_KICAD_IFACE_BASE::IsFlashedOnLayer(), PNS_PCBNEW_RULE_RESOLVER::IsNetTieExclusion(), BOARD::LayerDepth(), PCB_CONTROL::LayerNext(), PCB_CONTROL::LayerPrev(), PCAD2KICAD::PCB::MapLayer(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAddLayer(), APPEARANCE_CONTROLS::onLayerLeftClick(), DIALOG_COPPER_ZONE::OnLayerSelection(), DIALOG_NON_COPPER_ZONES_EDITOR::OnLayerSelection(), DIALOG_RULE_AREA_PROPERTIES::OnLayerSelection(), PLOT_CONTROLLER::OpenPlotfile(), DRC_RULES_PARSER::parseLayer(), PCB_MARKER::PCB_MARKER(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PLOT_CONTROLLER::PlotLayer(), ROUTER_TOOL::prepareInteractive(), PCB_EDIT_FRAME::Process_Special_Functions(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem(), PNS_PCBNEW_RULE_RESOLVER::QueryConstraint(), PCB_SELECTION_TOOL::Selectable(), FOOTPRINT_EDIT_FRAME::SelectLayer(), PCB_BASE_FRAME::SelectOneLayer(), DIALOG_GLOBAL_DELETION::SetCurrentLayer(), APPEARANCE_CONTROLS::SetLayerVisible(), PRIVATE_LAYERS_GRID_TABLE::SetValueAsLong(), FP_TEXT_GRID_TABLE::SetValueAsLong(), PNS_KICAD_IFACE_BASE::StackupHeight(), StartPlotBoard(), ROUTER_TOOL::switchLayerOnViaPlacement(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow(), and PNS_KICAD_IFACE::UpdateItem().