KiCad PCB EDA Suite
Loading...
Searching...
No Matches
layer_utils.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "layer_utils.h"
21
22#include <algorithm>
23
24#include <pad.h>
25
26
27wxString LAYER_UTILS::AccumulateNames( const LSEQ& aLayers, const BOARD* aBoard )
28{
29 wxString result;
30
31 for( const PCB_LAYER_ID layer : aLayers )
32 {
33 if( !result.IsEmpty() )
34 result += ", ";
35
36 result += aBoard ? aBoard->GetLayerName( layer ) : LayerName( layer );
37 }
38
39 return result;
40}
41
42
44{
45 LSET usedLayers{};
46
47 aFootprint.RunOnChildren(
48 [&]( BOARD_ITEM* aSubItem )
49 {
50 wxCHECK2( aSubItem, /*void*/ );
51 usedLayers |= aSubItem->GetLayerSet();
52 },
54
55 return usedLayers;
56}
57
58
60{
61 LSET usedLayers{};
62
63 aFootprint.RunOnChildren(
64 [&]( BOARD_ITEM* aSubItem )
65 {
66 wxCHECK2( aSubItem, /*void*/ );
67
68 LSET itemLayers = aSubItem->GetLayerSet();
69
70 // *.Cu wildcard pins no copper layer, an explicit padstack layer still does
71 if( aSubItem->Type() == PCB_PAD_T )
72 {
73 const PAD* pad = static_cast<const PAD*>( aSubItem );
74 LSET copper = itemLayers & LSET::AllCuMask();
75
76 // A blind span such as F.Cu..In2.Cu is a real layer choice, not the wildcard
77 if( copper.count() > 1 && copper == LSET::AllCuMask( copper.count() ) )
78 {
79 for( PCB_LAYER_ID layer : copper )
80 {
81 if( !pad->HasExplicitDefinitionForLayer( layer ) )
82 itemLayers.reset( layer );
83 }
84 }
85 }
86
87 usedLayers |= itemLayers;
88 },
90
91 return usedLayers;
92}
93
94
96{
97 const LSET innerCopper = aLayers & LSET::InternalCuMask();
98 int copperCount = 2;
99
100 for( PCB_LAYER_ID layer : innerCopper )
101 copperCount = std::max( copperCount, static_cast<int>( CopperLayerToOrdinal( layer ) ) + 2 );
102
103 // Stackups only come in even copper counts
104 return copperCount + copperCount % 2;
105}
106
107
109 const LSET& aCustomUserLayers )
110{
111 LSET usedLayers = GetUsedFootprintLayers( aFootprint );
112
113 usedLayers &= ~aCustomUserLayers;
114 usedLayers &= ~LSET::AllTechMask();
115 usedLayers &= ~LSET::UserMask();
116
117 // Rescue is a pseudo-layer used as a fallback for items referencing unknown layer
118 // names at load time. It is not exposed in any layer-selection UI, so the user has no
119 // way to "keep" it. Items on Rescue are an orphan state that predates any Footprint
120 // Properties edit and are surfaced through library-parity DRC instead.
121 usedLayers.reset( Rescue );
122
123 return usedLayers;
124}
BASE_SET & reset(size_t pos)
Definition base_set.h:153
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:354
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:940
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:573
Definition pad.h:61
@ RECURSE
Definition eda_item.h:51
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition layer_id.cpp:31
size_t CopperLayerToOrdinal(PCB_LAYER_ID aLayer)
Converts KiCad copper layer enum to an ordinal between the front and back layers.
Definition layer_ids.h:945
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Rescue
Definition layer_ids.h:117
wxString AccumulateNames(const LSEQ &aLayers, const BOARD *aBoard)
Accumulate layer names from a layer set into a comma separated string.
LSET GetUsedFootprintLayers(const FOOTPRINT &aFootprint)
Return the layers the footprint's items actually occupy.
int MinimalCopperLayerCount(const LSET &aLayers)
Return the smallest even copper layer count whose stackup contains every copper layer in aLayers.
LSET GetAllFootprintLayers(const FOOTPRINT &aFootprint)
Return the union of layers referenced by every item inside the footprint (including graphic items,...
LSET GetOrphanedFootprintLayers(const FOOTPRINT &aFootprint, const LSET &aCustomUserLayers)
Compute the set of footprint-used layers that would be orphaned if the footprint's allowed layer set ...
wxString result
Test unit parsing edge cases and error handling.
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79