KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lset.h
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, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LSET_H
21#define LSET_H
22
23#include <layer_ids.h>
24#include <base_set.h>
25
26class LSEQ;
27class LAYER_RANGE;
28
37{
38public:
39
43 LSET() : BASE_SET( PCB_LAYER_ID_COUNT ) {} // all bits are set to zero in BASE_SET()
44
45 LSET( const BASE_SET& aOther ) : BASE_SET( aOther ) {}
46
47 LSET( std::initializer_list<PCB_LAYER_ID> aList );
48
49 LSET( const std::vector<PCB_LAYER_ID>& aList );
50
51 LSET( const LSEQ& aSeq );
52
53 LSET( const LAYER_RANGE& aRange );
54
55 LSET( unsigned long __val ) = delete;
56
63 bool Contains( PCB_LAYER_ID aLayer ) const
64 {
65 // At the moment, LSET cannot store negative layers, but PCB_LAYER_ID can contain them
66 if( aLayer < 0 )
67 return false;
68
69 try
70 {
71 return test( aLayer );
72 }
73 catch( std::out_of_range& )
74 {
75 return false;
76 }
77 }
78
85 bool ContainsAll( const LSET& aLayers ) const
86 {
87 return aLayers.is_subset_of( *this );
88 }
89
97 static wxString Name( PCB_LAYER_ID aLayerId );
98
102 static int NameToLayer( wxString& aName );
103
110 static bool IsBetween( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aLayer );
111
116 static const LSET& InternalCuMask();
117
121 static const LSET& FrontAssembly();
122
126 static const LSET& BackAssembly();
127
131 static LSET AllCuMask( int aCuLayerCount );
132
136 static LSET AllCuMask();
137
141 static const LSET& ExternalCuMask();
142
146 static LSET AllNonCuMask();
147
148 static const LSET& AllLayersMask();
149
153 static const LSET& FrontTechMask();
154
159 static const LSET& FrontBoardTechMask();
160
164 static const LSET& BackTechMask();
165
170 static const LSET& BackBoardTechMask();
171
175 static const LSET& AllTechMask();
176
180 static const LSET& AllBoardTechMask();
181
185 static const LSET& FrontMask();
186
190 static const LSET& BackMask();
191
192 static const LSET& SideSpecificMask();
193
194 static const LSET& UserMask();
195
201 static const LSET& PhysicalLayersMask();
202
208 static LSET UserDefinedLayersMask( int aUserDefinedLayerCount = MAX_USER_DEFINED_LAYERS );
209
214 LSEQ CuStack() const;
215
219 LSEQ TechAndUserUIOrder() const;
220
224 LSEQ UIOrder() const;
225
234 LSEQ Seq( const LSEQ& aSequence ) const;
235
243 LSEQ Seq() const;
244
251 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
252
258 LSEQ SeqStackupForPlotting() const;
259
263 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
264 {
265 for( size_t ii = 0; ii < size(); ++ii )
266 {
267 if( test( ii ) )
268 aFunction( PCB_LAYER_ID( ii ) );
269 }
270 }
271
277 PCB_LAYER_ID ExtractLayer() const;
278
279
290 LSET& FlipStandardLayers( int aCopperLayersCount = 0 );
291
295 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
296
300 LSET& ClearCopperLayers();
301
305 LSET& ClearNonCopperLayers();
306
310 LSET& ClearUserDefinedLayers();
311
312#ifndef SWIG
313 // Custom iterator to iterate over all set bits
315 {
316 public:
321
323 {
324 return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() );
325 }
326
332 };
333
335 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
336
337 // Custom iterators for Copper and Non-Copper layers
339 {
340 public:
341 copper_layers_iterator( const BASE_SET& set, size_t index );
342 PCB_LAYER_ID operator*() const;
344
345 private:
347 void next_copper_layer();
348 };
349
360
365
366#endif
367
368};
369#endif // LSET_H
int index
set_bits_iterator & operator++()
Definition base_set.h:431
set_bits_iterator(const BASE_SET &baseSet, size_t index)
Definition base_set.h:423
BASE_SET(size_t size=64)
Definition base_set.h:111
BASE_SET & set(size_t pos)
Definition base_set.h:116
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
PCB_LAYER_ID operator*() const
Definition lset.h:322
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition lset.h:317
all_set_layers_iterator & operator++()
Definition lset.h:327
void advance_to_next_set_copper_bit()
Definition lset.cpp:881
copper_layers_iterator(const BASE_SET &set, size_t index)
Definition lset.cpp:838
non_copper_layers_iterator(const BASE_SET &set, size_t index)
Definition lset.cpp:888
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
copper_layers_iterator copper_layers_end() const
Definition lset.cpp:924
LSET(unsigned long __val)=delete
LSET(const BASE_SET &aOther)
Definition lset.h:45
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
Definition lset.h:263
all_set_layers_iterator begin() const
Definition lset.h:334
bool ContainsAll(const LSET &aLayers) const
See if this layer set contains all layers in another set.
Definition lset.h:85
all_set_layers_iterator end() const
Definition lset.h:335
copper_layers_iterator copper_layers_begin() const
Definition lset.cpp:918
non_copper_layers_iterator non_copper_layers_begin() const
Definition lset.cpp:930
non_copper_layers_iterator non_copper_layers_end() const
Definition lset.cpp:936
LSET()
Create an empty (cleared) set.
Definition lset.h:43
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
EDA_ANGLE operator*(const EDA_ANGLE &aAngleA, double aOperator)
Definition eda_angle.h:336
#define KICOMMON_API
Definition kicommon.h:28
#define MAX_USER_DEFINED_LAYERS
Definition layer_ids.h:177
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)