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
86 static wxString Name( PCB_LAYER_ID aLayerId );
87
91 static int NameToLayer( wxString& aName );
92
99 static bool IsBetween( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aLayer );
100
105 static LSET InternalCuMask();
106
110 static LSET FrontAssembly();
111
115 static LSET BackAssembly();
116
120 static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
121
125 static LSET ExternalCuMask();
126
130 static LSET AllNonCuMask();
131
132 static LSET AllLayersMask();
133
137 static LSET FrontTechMask();
138
143 static LSET FrontBoardTechMask();
144
148 static LSET BackTechMask();
149
154 static LSET BackBoardTechMask();
155
159 static LSET AllTechMask();
160
164 static LSET AllBoardTechMask();
165
169 static LSET FrontMask();
170
174 static LSET BackMask();
175
176 static LSET SideSpecificMask();
177
178 static LSET UserMask();
179
185 static LSET PhysicalLayersMask();
186
190 static LSET UserDefinedLayers();
191
198 static LSET ForbiddenFootprintLayers();
199
204 LSEQ CuStack() const;
205
209 LSEQ TechAndUserUIOrder() const;
210
214 LSEQ UIOrder() const;
215
224 LSEQ Seq( const LSEQ& aSequence ) const;
225
233 LSEQ Seq() const;
234
241 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
242
248 LSEQ SeqStackupForPlotting() const;
249
253 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
254 {
255 for( size_t ii = 0; ii < size(); ++ii )
256 {
257 if( test( ii ) )
258 aFunction( PCB_LAYER_ID( ii ) );
259 }
260 }
261
267 PCB_LAYER_ID ExtractLayer() const;
268
269
280 LSET& Flip( int aCopperLayersCount = 0 );
281
285 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
286
287#ifndef SWIG
288 // Custom iterator to iterate over all set bits
290 {
291 public:
292 all_set_layers_iterator( const BASE_SET& set, size_t index ) :
293 BASE_SET::set_bits_iterator( set, index )
294 {
295 }
296
298 {
299 return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() );
300 }
301
303 {
305 return *this;
306 }
307 };
308
310 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
311
312 // Custom iterators for Copper and Non-Copper layers
314 {
315 public:
316 copper_layers_iterator( const BASE_SET& set, size_t index );
317 PCB_LAYER_ID operator*() const;
319
320 private:
321 void advance_to_next_set_copper_bit();
322 void next_copper_layer();
323 };
324
326 {
327 public:
328 non_copper_layers_iterator( const BASE_SET& set, size_t index );
329 PCB_LAYER_ID operator*() const;
331
332 private:
333 void advance_to_next_set_non_copper_bit();
334 };
335
336 copper_layers_iterator copper_layers_begin() const;
337 copper_layers_iterator copper_layers_end() const;
338 non_copper_layers_iterator non_copper_layers_begin() const;
339 non_copper_layers_iterator non_copper_layers_end() const;
340
341#endif
342
343};
344#endif // LSET_H
345
set_bits_iterator & operator++()
Definition: base_set.h:377
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:297
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition: lset.h:292
all_set_layers_iterator & operator++()
Definition: lset.h:302
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
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:253
all_set_layers_iterator begin() const
Definition: lset.h:309
all_set_layers_iterator end() const
Definition: lset.h:310
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:328
#define KICOMMON_API
Definition: kicommon.h:28
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
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:135
void Flip(T &aValue)
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)