KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_itemset.cpp
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#include "pns_itemset.h"
23
24#include <core/typeinfo.h>
25
26#include "pns_line.h"
27#include "pns_segment.h"
28
29namespace PNS {
30
34
35
36void ITEM_SET::Add( const LINE& aLine )
37{
38 LINE* copy = aLine.Clone();
39 copy->SetOwner( this );
40 m_items.emplace_back( copy );
41}
42
43
44void ITEM_SET::Prepend( const LINE& aLine )
45{
46 LINE* copy = aLine.Clone();
47 copy->SetOwner( this );
48 m_items.emplace( m_items.begin(), copy );
49}
50
51
52ITEM_SET& ITEM_SET::FilterLayers( int aStart, int aEnd, bool aInvert )
53{
54 std::vector<ITEM*> newItems;
56
57 if( aEnd < 0 )
58 l = PNS_LAYER_RANGE( aStart );
59 else
60 l = PNS_LAYER_RANGE( aStart, aEnd );
61
62 for( ITEM* item : m_items )
63 {
64 if( item->Layers().Overlaps( l ) ^ aInvert )
65 newItems.push_back( item );
66 }
67
68 m_items = std::move( newItems );
69
70 return *this;
71}
72
73
74ITEM_SET& ITEM_SET::FilterKinds( int aKindMask, bool aInvert )
75{
76 std::vector<ITEM*> newItems;
77
78 for( ITEM *item : m_items )
79 {
80 if( item->OfKind( aKindMask ) ^ aInvert )
81 newItems.push_back( item );
82 }
83
84 m_items = std::move( newItems );
85
86 return *this;
87}
88
89
90ITEM_SET& ITEM_SET::FilterMarker( int aMarker, bool aInvert )
91{
92 std::vector<ITEM*> newItems;
93
94 for( ITEM* item : m_items )
95 {
96 if( item->Marker() & aMarker )
97 newItems.push_back( item );
98 }
99
100 m_items = std::move( newItems );
101
102 return *this;
103}
104
105
107{
108 std::vector<ITEM*> newItems;
109
110 for( ITEM *item : m_items )
111 {
112 if( ( item->Net() == aNet ) ^ aInvert )
113 newItems.push_back( item );
114 }
115
116 m_items = std::move( newItems );
117
118 return *this;
119}
120
121
123{
124 std::vector<ITEM*> newItems;
125
126 for( ITEM* item : m_items )
127 {
128 if( item != aItem )
129 newItems.push_back( item );
130 }
131
132 m_items = std::move( newItems );
133
134 return *this;
135}
136
138{
139 for( ITEM* item : m_items )
140 {
141 // fixme: biconnected concept
142 if( auto seg = dyn_cast<SEGMENT*>( item ) )
143 {
144 if( seg->Seg().A == aV || seg->Seg().B == aV )
145 return seg;
146 }
147 }
148
149 return nullptr;
150}
151
152}
ITEM_SET & FilterNet(NET_HANDLE aNet, bool aInvert=false)
std::vector< ITEM * > m_items
void Add(const LINE &aLine)
ITEM_SET & ExcludeItem(const ITEM *aItem)
ITEM_SET & FilterMarker(int aMarker, bool aInvert=false)
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
ITEM_SET & FilterLayers(int aStart, int aEnd=-1, bool aInvert=false)
ITEM_SET(ITEM *aInitialItem=nullptr, bool aBecomeOwner=false)
Definition pns_itemset.h:39
ITEM * FindVertex(const VECTOR2I &aV) const
void Prepend(const LINE &aLine)
Base class for PNS router board items.
Definition pns_item.h:98
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:162
Represent a contiguous set of PCB layers.
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition pns_item.h:55
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:61
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695