KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_itemset.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 The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __PNS_ITEMSET_H
23#define __PNS_ITEMSET_H
24
25#include <vector>
26#include <core/kicad_algo.h>
27#include "pns_item.h"
28
29namespace PNS {
30
34class LINE;
35
36class ITEM_SET : public ITEM_OWNER
37{
38public:
39 ITEM_SET( ITEM* aInitialItem = nullptr, bool aBecomeOwner = false )
40 {
41 if( aInitialItem )
42 m_items.emplace_back( aInitialItem );
43
44 if( aBecomeOwner && aInitialItem )
45 aInitialItem->SetOwner( this );
46 }
47
48 ITEM_SET( const ITEM_SET& aOther )
49 {
50 m_items = aOther.m_items;
51 }
52
53 ITEM_SET( ITEM_SET&& aOther ) noexcept { m_items = std::move( aOther.m_items ); }
54
55 ITEM_SET& operator=( ITEM_SET&& aOther ) noexcept
56 {
57 m_items = std::move( aOther.m_items );
58 return *this;
59 }
60
61 ~ITEM_SET();
62
63 ITEM_SET& operator=( const ITEM_SET& aOther )
64 {
65 m_items.clear();
66 m_items.reserve( aOther.m_items.size() );
67
68 for( ITEM* item : aOther.m_items )
69 m_items.push_back( item );
70
71 return *this;
72 }
73
74 int Count( int aKindMask = -1 ) const
75 {
76 int n = 0;
77
78 if( aKindMask == -1 || aKindMask == ITEM::ANY_T )
79 return static_cast<int>( m_items.size() );
80
81 for( ITEM* item : m_items )
82 {
83 if( item->Kind() & aKindMask )
84 n++;
85 }
86
87 return n;
88 }
89
90 bool Empty() const
91 {
92 return m_items.empty();
93 }
94
95 std::vector<ITEM*>& Items() { return m_items; }
96 const std::vector<ITEM*>& CItems() const { return m_items; }
97
98 ITEM_SET& FilterLayers( int aStart, int aEnd = -1, bool aInvert = false );
99 ITEM_SET& FilterKinds( int aKindMask, bool aInvert = false );
100 ITEM_SET& FilterNet( NET_HANDLE aNet, bool aInvert = false );
101 ITEM_SET& FilterMarker( int aMarker, bool aInvert = false );
102
103 ITEM_SET& ExcludeLayers( int aStart, int aEnd = -1 )
104 {
105 return FilterLayers( aStart, aEnd, true );
106 }
107
108 ITEM_SET& ExcludeKinds( int aKindMask )
109 {
110 return FilterKinds( aKindMask, true );
111 }
112
114 {
115 return FilterNet( aNet, true );
116 }
117
118 ITEM_SET& ExcludeItem( const ITEM* aItem );
119
120 int Size() const
121 {
122 return static_cast<int>( m_items.size() );
123 }
124
125 void Add( const LINE& aLine );
126 void Prepend( const LINE& aLine );
127
128 ITEM* operator[]( const size_t aIndex ) const { return m_items[aIndex]; }
129
130 std::vector<ITEM*>::iterator begin() { return m_items.begin(); }
131 std::vector<ITEM*>::iterator end() { return m_items.end(); }
132 std::vector<ITEM*>::const_iterator cbegin() const { return m_items.cbegin(); }
133 std::vector<ITEM*>::const_iterator cend() const { return m_items.cend(); }
134
135 std::vector<ITEM*>::reverse_iterator rbegin() { return m_items.rbegin(); }
136 std::vector<ITEM*>::reverse_iterator rend() { return m_items.rend(); }
137 std::vector<ITEM*>::const_reverse_iterator crbegin() const { return m_items.crbegin(); }
138 std::vector<ITEM*>::const_reverse_iterator crend() const { return m_items.crend(); }
139
140 void Add( ITEM* aItem, bool aBecomeOwner = false )
141 {
142 m_items.emplace_back( aItem );
143
144 if( aBecomeOwner )
145 aItem->SetOwner( this );
146 }
147
148 void Prepend( ITEM* aItem, bool aBecomeOwner = false )
149 {
150 m_items.emplace( m_items.begin(), aItem );
151
152 if( aBecomeOwner )
153 aItem->SetOwner( this );
154 }
155
156 void Clear()
157 {
158 m_items.clear();
159 }
160
161 bool Contains( ITEM* aItem ) const
162 {
163 return alg::contains( m_items, aItem );
164 }
165
166 void Erase( ITEM* aItem )
167 {
168 std::vector<ITEM*>::iterator f = std::find( m_items.begin(), m_items.end(), aItem );
169
170 if( f != m_items.end() )
171 m_items.erase( f );
172 }
173
174 template<class T>
175 T* FindByKind( ITEM::PnsKind kind, int index = 0 )
176 {
177 int n = 0;
178
179 for( const ITEM* item : m_items )
180 {
181 if( item->OfKind( kind ) )
182 {
183 if( index == n )
184 return static_cast<T*>( item );
185 else
186 n++;
187 }
188 }
189
190 return nullptr;
191 }
192
193 ITEM* FindVertex( const VECTOR2I& aV ) const;
194
195private:
196 std::vector<ITEM*> m_items;
197};
198
199}
200
201#endif
int index
ITEM_SET & operator=(ITEM_SET &&aOther) noexcept
Definition pns_itemset.h:55
bool Empty() const
Definition pns_itemset.h:90
int Size() const
void Prepend(ITEM *aItem, bool aBecomeOwner=false)
std::vector< ITEM * >::reverse_iterator rbegin()
ITEM_SET & operator=(const ITEM_SET &aOther)
Definition pns_itemset.h:63
ITEM * operator[](const size_t aIndex) const
int Count(int aKindMask=-1) const
Definition pns_itemset.h:74
ITEM_SET & FilterNet(NET_HANDLE aNet, bool aInvert=false)
std::vector< ITEM * > m_items
void Add(const LINE &aLine)
std::vector< ITEM * >::const_reverse_iterator crend() const
ITEM_SET & ExcludeItem(const ITEM *aItem)
std::vector< ITEM * >::const_iterator cbegin() const
ITEM_SET & FilterMarker(int aMarker, bool aInvert=false)
bool Contains(ITEM *aItem) const
ITEM_SET(const ITEM_SET &aOther)
Definition pns_itemset.h:48
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
ITEM_SET & ExcludeNet(NET_HANDLE aNet)
ITEM_SET & FilterLayers(int aStart, int aEnd=-1, bool aInvert=false)
std::vector< ITEM * >::const_reverse_iterator crbegin() const
ITEM_SET(ITEM_SET &&aOther) noexcept
Definition pns_itemset.h:53
std::vector< ITEM * > & Items()
Definition pns_itemset.h:95
ITEM_SET & ExcludeLayers(int aStart, int aEnd=-1)
ITEM_SET(ITEM *aInitialItem=nullptr, bool aBecomeOwner=false)
Definition pns_itemset.h:39
std::vector< ITEM * >::const_iterator cend() const
std::vector< ITEM * >::reverse_iterator rend()
ITEM_SET & ExcludeKinds(int aKindMask)
std::vector< ITEM * >::iterator end()
ITEM * FindVertex(const VECTOR2I &aV) const
void Prepend(const LINE &aLine)
void Erase(ITEM *aItem)
std::vector< ITEM * >::iterator begin()
T * FindByKind(ITEM::PnsKind kind, int index=0)
void Add(ITEM *aItem, bool aBecomeOwner=false)
const std::vector< ITEM * > & CItems() const
Definition pns_itemset.h:96
Base class for PNS router board items.
Definition pns_item.h:98
PnsKind
< Supported item types
Definition pns_item.h:102
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition pns_item.h:77
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition pns_item.h:55
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687