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 <pad.h>
23
24
25wxString LAYER_UTILS::AccumulateNames( const LSEQ& aLayers, const BOARD* aBoard )
26{
27 wxString result;
28
29 for( const PCB_LAYER_ID layer : aLayers )
30 {
31 if( !result.IsEmpty() )
32 result += ", ";
33
34 result += aBoard ? aBoard->GetLayerName( layer ) : LayerName( layer );
35 }
36
37 return result;
38}
39
40
42{
43 LSET usedLayers{};
44
45 aFootprint.RunOnChildren(
46 [&]( BOARD_ITEM* aSubItem )
47 {
48 wxCHECK2( aSubItem, /*void*/ );
49 usedLayers |= aSubItem->GetLayerSet();
50 },
52
53 return usedLayers;
54}
55
56
58 const LSET& aCustomUserLayers )
59{
60 LSET usedLayers{};
61
62 aFootprint.RunOnChildren(
63 [&]( BOARD_ITEM* aSubItem )
64 {
65 wxCHECK2( aSubItem, /*void*/ );
66
67 LSET itemLayers = aSubItem->GetLayerSet();
68
69 // *.Cu wildcard pins no copper layer, an explicit padstack layer still does
70 if( aSubItem->Type() == PCB_PAD_T )
71 {
72 const PAD* pad = static_cast<const PAD*>( aSubItem );
73 LSET copper = itemLayers & LSET::AllCuMask();
74
75 if( copper.count() > 1 )
76 {
77 for( PCB_LAYER_ID layer : copper )
78 {
79 if( !pad->HasExplicitDefinitionForLayer( layer ) )
80 itemLayers.reset( layer );
81 }
82 }
83 }
84
85 usedLayers |= itemLayers;
86 },
88
89 usedLayers &= ~aCustomUserLayers;
90 usedLayers &= ~LSET::AllTechMask();
91 usedLayers &= ~LSET::UserMask();
92
93 // Rescue is a pseudo-layer used as a fallback for items referencing unknown layer
94 // names at load time. It is not exposed in any layer-selection UI, so the user has no
95 // way to "keep" it. Items on Rescue are an orphan state that predates any Footprint
96 // Properties edit and are surfaced through library-parity DRC instead.
97 usedLayers.reset( Rescue );
98
99 return usedLayers;
100}
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:346
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:943
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
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
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 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