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 const LSET& InternalCuMask();
106
110 static const LSET& FrontAssembly();
111
115 static const LSET& BackAssembly();
116
120 static LSET AllCuMask( int aCuLayerCount );
121
125 static LSET AllCuMask();
126
130 static const LSET& ExternalCuMask();
131
135 static LSET AllNonCuMask();
136
137 static const LSET& AllLayersMask();
138
142 static const LSET& FrontTechMask();
143
148 static const LSET& FrontBoardTechMask();
149
153 static const LSET& BackTechMask();
154
159 static const LSET& BackBoardTechMask();
160
164 static const LSET& AllTechMask();
165
169 static const LSET& AllBoardTechMask();
170
174 static const LSET& FrontMask();
175
179 static const LSET& BackMask();
180
181 static const LSET& SideSpecificMask();
182
183 static const LSET& UserMask();
184
190 static const LSET& PhysicalLayersMask();
191
197 static LSET UserDefinedLayersMask( int aUserDefinedLayerCount = MAX_USER_DEFINED_LAYERS );
198
205 static const LSET& ForbiddenFootprintLayers();
206
211 LSEQ CuStack() const;
212
216 LSEQ TechAndUserUIOrder() const;
217
221 LSEQ UIOrder() const;
222
231 LSEQ Seq( const LSEQ& aSequence ) const;
232
240 LSEQ Seq() const;
241
248 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
249
255 LSEQ SeqStackupForPlotting() const;
256
260 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
261 {
262 for( size_t ii = 0; ii < size(); ++ii )
263 {
264 if( test( ii ) )
265 aFunction( PCB_LAYER_ID( ii ) );
266 }
267 }
268
274 PCB_LAYER_ID ExtractLayer() const;
275
276
287 LSET& FlipStandardLayers( int aCopperLayersCount = 0 );
288
292 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
293
297 LSET& ClearCopperLayers();
298
302 LSET& ClearNonCopperLayers();
303
307 LSET& ClearUserDefinedLayers();
308
309#ifndef SWIG
310 // Custom iterator to iterate over all set bits
312 {
313 public:
314 all_set_layers_iterator( const BASE_SET& set, size_t index ) :
315 BASE_SET::set_bits_iterator( set, index )
316 {
317 }
318
320 {
321 return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() );
322 }
323
325 {
327 return *this;
328 }
329 };
330
332 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
333
334 // Custom iterators for Copper and Non-Copper layers
336 {
337 public:
338 copper_layers_iterator( const BASE_SET& set, size_t index );
339 PCB_LAYER_ID operator*() const;
341
342 private:
343 void advance_to_next_set_copper_bit();
344 void next_copper_layer();
345 };
346
348 {
349 public:
350 non_copper_layers_iterator( const BASE_SET& set, size_t index );
351 PCB_LAYER_ID operator*() const;
353
354 private:
355 void advance_to_next_set_non_copper_bit();
356 };
357
358 copper_layers_iterator copper_layers_begin() const;
359 copper_layers_iterator copper_layers_end() const;
360 non_copper_layers_iterator non_copper_layers_begin() const;
361 non_copper_layers_iterator non_copper_layers_end() const;
362
363#endif
364
365};
366#endif // LSET_H
367
set_bits_iterator & operator++()
Definition: base_set.h:431
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:319
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition: lset.h:314
all_set_layers_iterator & operator++()
Definition: lset.h:324
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:260
all_set_layers_iterator begin() const
Definition: lset.h:331
all_set_layers_iterator end() const
Definition: lset.h:332
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)