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 LSEQ& aSeq );
49
50 LSET( const LAYER_RANGE& aRange );
51
52 LSET( unsigned long __val ) = delete;
53
60 bool Contains( PCB_LAYER_ID aLayer ) const
61 {
62 // At the moment, LSET cannot store negative layers, but PCB_LAYER_ID can contain them
63 if( aLayer < 0 )
64 return false;
65
66 try
67 {
68 return test( aLayer );
69 }
70 catch( std::out_of_range& )
71 {
72 return false;
73 }
74 }
75
79 static wxString Name( PCB_LAYER_ID aLayerId );
80
84 static int NameToLayer( wxString& aName );
85
90 static bool IsBetween( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aLayer );
91
96 static LSET InternalCuMask();
97
101 static LSET FrontAssembly();
102
106 static LSET BackAssembly();
107
111 static LSET AllCuMask( int aCuLayerCount = MAX_CU_LAYERS );
112
116 static LSET ExternalCuMask();
117
121 static LSET AllNonCuMask();
122
123 static LSET AllLayersMask();
124
128 static LSET FrontTechMask();
129
134 static LSET FrontBoardTechMask();
135
139 static LSET BackTechMask();
140
145 static LSET BackBoardTechMask();
146
150 static LSET AllTechMask();
151
155 static LSET AllBoardTechMask();
156
160 static LSET FrontMask();
161
165 static LSET BackMask();
166
167 static LSET SideSpecificMask();
168
169 static LSET UserMask();
170
175 static LSET PhysicalLayersMask();
176
180 static LSET UserDefinedLayers();
181
187 static LSET ForbiddenFootprintLayers();
188
193 LSEQ CuStack() const;
194
199 LSEQ TechAndUserUIOrder() const;
200
205 LSEQ UIOrder() const;
206
213 LSEQ Seq( const LSEQ& aSequence ) const;
214
221 LSEQ Seq() const;
222
230 LSEQ SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer = UNDEFINED_LAYER ) const;
231
236 LSEQ SeqStackupForPlotting() const;
237
241 void RunOnLayers( const std::function<void( PCB_LAYER_ID )>& aFunction ) const
242 {
243 for( size_t ii = 0; ii < size(); ++ii )
244 {
245 if( test( ii ) )
246 aFunction( PCB_LAYER_ID( ii ) );
247 }
248 }
249
253 std::string FmtHex() const;
254
262 int ParseHex( const char* aStart, int aCount );
263 int ParseHex( const std::string& str );
264
268 std::string FmtBin() const;
269
274 PCB_LAYER_ID ExtractLayer() const;
275
276
286 LSET& Flip( int aCopperLayersCount = 0 );
287
291 static int LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount );
292
293#ifndef SWIG
294 // Custom iterator to iterate over all set bits
296 {
297 public:
298 all_set_layers_iterator( const BASE_SET& set, size_t index ) :
299 BASE_SET::set_bits_iterator( set, index )
300 {
301 }
302
303 PCB_LAYER_ID operator*() const { return PCB_LAYER_ID( BASE_SET::set_bits_iterator::operator*() ); }
304
306 {
308 return *this;
309 }
310 };
311
313 all_set_layers_iterator end() const { return all_set_layers_iterator( *this, size() ); }
314
315 // Custom iterators for Copper and Non-Copper layers
317 {
318 public:
319 copper_layers_iterator( const BASE_SET& set, size_t index );
320 PCB_LAYER_ID operator*() const;
322
323 private:
324 void advance_to_next_set_copper_bit();
325 void next_copper_layer();
326 };
327
329 {
330 public:
331 non_copper_layers_iterator( const BASE_SET& set, size_t index );
332 PCB_LAYER_ID operator*() const;
334
335 private:
336 void advance_to_next_set_non_copper_bit();
337 };
338
339 copper_layers_iterator copper_layers_begin() const;
340 copper_layers_iterator copper_layers_end() const;
341 non_copper_layers_iterator non_copper_layers_begin() const;
342 non_copper_layers_iterator non_copper_layers_end() const;
343
344#endif
345
346};
347#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:303
all_set_layers_iterator(const BASE_SET &set, size_t index)
Definition: lset.h:298
all_set_layers_iterator & operator++()
Definition: lset.h:305
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:241
all_set_layers_iterator begin() const
Definition: lset.h:312
all_set_layers_iterator end() const
Definition: lset.h:313
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:60
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)