KiCad PCB EDA Suite
pns_layerset.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_LAYERSET_H
24#define __PNS_LAYERSET_H
25
26#include <algorithm>
27
32{
33public:
35 m_start( -1 ),
36 m_end( -1 )
37 {};
38
39 LAYER_RANGE( int aStart, int aEnd )
40 {
41 if( aStart > aEnd )
42 std::swap( aStart, aEnd );
43
44 m_start = aStart;
45 m_end = aEnd;
46 }
47
48 LAYER_RANGE( int aLayer )
49 {
50 m_start = m_end = aLayer;
51 }
52
53 LAYER_RANGE( const LAYER_RANGE& aB ) :
54 m_start( aB.m_start ),
55 m_end( aB.m_end )
56 {}
57
59
61 {
62 m_start = aB.m_start;
63 m_end = aB.m_end;
64 return *this;
65 }
66
67 bool Overlaps( const LAYER_RANGE& aOther ) const
68 {
69 return m_end >= aOther.m_start && m_start <= aOther.m_end;
70 }
71
72 bool Overlaps( const int aLayer ) const
73 {
74 return aLayer >= m_start && aLayer <= m_end;
75 }
76
77 bool IsMultilayer() const
78 {
79 return m_start != m_end;
80 }
81
82 int Start() const
83 {
84 return m_start;
85 }
86
87 int End() const
88 {
89 return m_end;
90 }
91
92 void Merge( const LAYER_RANGE& aOther )
93 {
94 if( m_start < 0 || m_end < 0 )
95 {
96 m_start = aOther.m_start;
97 m_end = aOther.m_end;
98 return;
99 }
100
101 if( aOther.m_start < m_start )
102 m_start = aOther.m_start;
103
104 if( aOther.m_end > m_end )
105 m_end = aOther.m_end;
106 }
107
110 {
111 return LAYER_RANGE( 0, 256 ); // fixme: use layer IDs header
112 }
113
114 bool operator==( const LAYER_RANGE& aOther ) const
115 {
116 return ( m_start == aOther.m_start ) && ( m_end == aOther.m_end );
117 }
118
119 bool operator!=( const LAYER_RANGE& aOther ) const
120 {
121 return ( m_start != aOther.m_start ) || ( m_end != aOther.m_end );
122 }
123
124private:
126 int m_end;
127};
128
129#endif // __PNS_LAYERSET_H
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
bool Overlaps(const int aLayer) const
Definition: pns_layerset.h:72
LAYER_RANGE & operator=(const LAYER_RANGE &aB)
Definition: pns_layerset.h:60
void Merge(const LAYER_RANGE &aOther)
Shortcut for comparisons/overlap tests.
Definition: pns_layerset.h:92
int Start() const
Definition: pns_layerset.h:82
bool operator!=(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:119
LAYER_RANGE(const LAYER_RANGE &aB)
Definition: pns_layerset.h:53
bool operator==(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:114
LAYER_RANGE(int aLayer)
Definition: pns_layerset.h:48
bool IsMultilayer() const
Definition: pns_layerset.h:77
int End() const
Definition: pns_layerset.h:87
static LAYER_RANGE All()
Definition: pns_layerset.h:109
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
LAYER_RANGE(int aStart, int aEnd)
Definition: pns_layerset.h:39