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
192 static LSET UserDefinedLayersMask( int aUserDefinedLayerCount = MAX_USER_DEFINED_LAYERS );
193
200 static LSET ForbiddenFootprintLayers();
201
206 LSEQ CuStack() const;
207
211 LSEQ TechAndUserUIOrder() const;
212
216 LSEQ UIOrder() const;
217
226 LSEQ Seq( const LSEQ& aSequence ) const;
227
235 LSEQ Seq() const;
236
243 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
244
250 LSEQ SeqStackupForPlotting() const;
251
255 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
256 {
257 for( size_t ii = 0; ii < size(); ++ii )
258 {
259 if( test( ii ) )
260 aFunction( PCB_LAYER_ID( ii ) );
261 }
262 }
263
269 PCB_LAYER_ID ExtractLayer() const;
270
271
282 LSET& Flip( int aCopperLayersCount = 0 );
283
287 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
288
292 LSET& ClearCopperLayers();
293
297 LSET& ClearNonCopperLayers();
298
302 LSET& ClearUserDefinedLayers();
303
304#ifndef SWIG
305 // Custom iterator to iterate over all set bits
307 {
308 public:
309 all_set_layers_iterator( const BASE_SET& set, size_t index ) :
310 BASE_SET::set_bits_iterator( set, index )
311 {
312 }
313
315 {
316 return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() );
317 }
318
320 {
322 return *this;
323 }
324 };
325
327 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
328
329 // Custom iterators for Copper and Non-Copper layers
331 {
332 public:
333 copper_layers_iterator( const BASE_SET& set, size_t index );
334 PCB_LAYER_ID operator*() const;
336
337 private:
338 void advance_to_next_set_copper_bit();
339 void next_copper_layer();
340 };
341
343 {
344 public:
345 non_copper_layers_iterator( const BASE_SET& set, size_t index );
346 PCB_LAYER_ID operator*() const;
348
349 private:
350 void advance_to_next_set_non_copper_bit();
351 };
352
353 copper_layers_iterator copper_layers_begin() const;
354 copper_layers_iterator copper_layers_end() const;
355 non_copper_layers_iterator non_copper_layers_begin() const;
356 non_copper_layers_iterator non_copper_layers_end() const;
357
358#endif
359
360};
361#endif // LSET_H
362
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:314
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition: lset.h:309
all_set_layers_iterator & operator++()
Definition: lset.h:319
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:255
all_set_layers_iterator begin() const
Definition: lset.h:326
all_set_layers_iterator end() const
Definition: lset.h:327
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_USER_DEFINED_LAYERS
Definition: layer_ids.h:177
#define MAX_CU_LAYERS
Definition: layer_ids.h:176
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
void Flip(T &aValue)
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)