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 (C) 2024 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
36{
37public:
38
42 LSET() : BASE_SET( PCB_LAYER_ID_COUNT ) {} // all bits are set to zero in BASE_SET()
43
44 LSET( const BASE_SET& aOther ) : BASE_SET( aOther ) {}
45
46 LSET( std::initializer_list<PCB_LAYER_ID> aList );
47
48 LSET( const std::vector<PCB_LAYER_ID>& aList );
49
50 LSET( const LSEQ& aSeq );
51
52 LSET( const LAYER_RANGE& aRange );
53
54 LSET( unsigned long __val ) = delete;
55
62 bool Contains( PCB_LAYER_ID aLayer ) const
63 {
64 // At the moment, LSET cannot store negative layers, but PCB_LAYER_ID can contain them
65 if( aLayer < 0 )
66 return false;
67
68 try
69 {
70 return test( aLayer );
71 }
72 catch( std::out_of_range& )
73 {
74 return false;
75 }
76 }
77
81 static wxString Name( PCB_LAYER_ID aLayerId );
82
86 static int NameToLayer( wxString& aName );
87
92 static bool IsBetween( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aLayer );
93
98 static LSET InternalCuMask();
99
103 static LSET FrontAssembly();
104
108 static LSET BackAssembly();
109
113 static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
114
118 static LSET ExternalCuMask();
119
123 static LSET AllNonCuMask();
124
125 static LSET AllLayersMask();
126
130 static LSET FrontTechMask();
131
136 static LSET FrontBoardTechMask();
137
141 static LSET BackTechMask();
142
147 static LSET BackBoardTechMask();
148
152 static LSET AllTechMask();
153
157 static LSET AllBoardTechMask();
158
162 static LSET FrontMask();
163
167 static LSET BackMask();
168
169 static LSET SideSpecificMask();
170
171 static LSET UserMask();
172
177 static LSET PhysicalLayersMask();
178
182 static LSET UserDefinedLayers();
183
189 static LSET ForbiddenFootprintLayers();
190
195 LSEQ CuStack() const;
196
201 LSEQ TechAndUserUIOrder() const;
202
207 LSEQ UIOrder() const;
208
215 LSEQ Seq( const LSEQ& aSequence ) const;
216
223 LSEQ Seq() const;
224
232 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
233
238 LSEQ SeqStackupForPlotting() const;
239
243 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
244 {
245 for( size_t ii = 0; ii < size(); ++ii )
246 {
247 if( test( ii ) )
248 aFunction( PCB_LAYER_ID( ii ) );
249 }
250 }
251
255 std::string FmtHex() const;
256
264 int ParseHex( const char* aStart, int aCount );
265 int ParseHex( const std::string& str );
266
270 std::string FmtBin() const;
271
276 PCB_LAYER_ID ExtractLayer() const;
277
278
288 LSET& Flip( int aCopperLayersCount = 0 );
289
293 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
294
295#ifndef SWIG
296 // Custom iterator to iterate over all set bits
298 {
299 public:
300 all_set_layers_iterator( const BASE_SET& set, size_t index ) :
301 BASE_SET::set_bits_iterator( set, index )
302 {
303 }
304
305 PCB_LAYER_ID operator*() const { return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() ); }
306
308 {
310 return *this;
311 }
312 };
313
315 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
316
317 // Custom iterators for Copper and Non-Copper layers
319 {
320 public:
321 copper_layers_iterator( const BASE_SET& set, size_t index );
322 PCB_LAYER_ID operator*() const;
324
325 private:
326 void advance_to_next_set_copper_bit();
327 void next_copper_layer();
328 };
329
331 {
332 public:
333 non_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_non_copper_bit();
339 };
340
341 copper_layers_iterator copper_layers_begin() const;
342 copper_layers_iterator copper_layers_end() const;
343 non_copper_layers_iterator non_copper_layers_begin() const;
344 non_copper_layers_iterator non_copper_layers_end() const;
345
346#endif
347
348};
349#endif // LSET_H
set_bits_iterator & operator++()
Definition: base_set.h:235
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:305
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition: lset.h:300
all_set_layers_iterator & operator++()
Definition: lset.h:307
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
LSET(unsigned long __val)=delete
LSET(const BASE_SET &aOther)
Definition: lset.h:44
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
Definition: lset.h:243
all_set_layers_iterator begin() const
Definition: lset.h:314
all_set_layers_iterator end() const
Definition: lset.h:315
LSET()
Create an empty (cleared) set.
Definition: lset.h:42
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:62
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)