pns_itemset.cpp 2.16 KB
Newer Older
1 2 3
/*
 * KiRouter - a push-and-(sometimes-)shove PCB router
 *
4
 * Copyright (C) 2013-2014 CERN
5
 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6
 *
7 8 9 10
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
11
 *
12 13 14 15
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 */

#include <boost/foreach.hpp>

#include "pns_itemset.h"

25
PNS_ITEMSET::PNS_ITEMSET( PNS_ITEM* aInitialItem )
26
{
Maciej Suminski's avatar
Maciej Suminski committed
27 28
    if( aInitialItem )
        m_items.push_back( aInitialItem );
29 30
}

31
PNS_ITEMSET& PNS_ITEMSET::FilterLayers( int aStart, int aEnd, bool aInvert )
32
{
33
    ITEMS newItems;
34 35 36 37 38 39 40
    PNS_LAYERSET l;

    if( aEnd < 0 )
        l = PNS_LAYERSET( aStart );
    else
        l = PNS_LAYERSET( aStart, aEnd );

41
    BOOST_FOREACH( PNS_ITEM* item, m_items )
42

43
    if( item->Layers().Overlaps( l ) ^ aInvert )
44 45 46
        newItems.push_back( item );

    m_items = newItems;
47

48
    return *this;
49 50
}

51

52
PNS_ITEMSET& PNS_ITEMSET::FilterKinds( int aKindMask, bool aInvert )
53
{
54
    ITEMS newItems;
55

56 57
    BOOST_FOREACH( PNS_ITEM* item, m_items )
    {
Maciej Suminski's avatar
Maciej Suminski committed
58
        if( item->OfKind( aKindMask ) ^ aInvert )
59 60
            newItems.push_back( item );
    }
61 62

    m_items = newItems;
63

64
    return *this;
65 66
}

67

68 69 70 71 72 73
PNS_ITEMSET& PNS_ITEMSET::FilterNet( int aNet, bool aInvert )
{
    ITEMS newItems;

    BOOST_FOREACH( PNS_ITEM* item, m_items )
    {
Maciej Suminski's avatar
Maciej Suminski committed
74
        if( ( item->Net() == aNet ) ^ aInvert )
75 76 77 78 79 80 81 82
            newItems.push_back( item );
    }

    m_items = newItems;

    return *this;
}

Maciej Suminski's avatar
Maciej Suminski committed
83
PNS_ITEMSET& PNS_ITEMSET::ExcludeItem( const PNS_ITEM* aItem )
84
{
85
    ITEMS newItems;
86

87 88
    BOOST_FOREACH( PNS_ITEM* item, m_items )
    {
89
        if( item != aItem )
90 91
            newItems.push_back( item );
    }
92 93

    m_items = newItems;
94

95
    return *this;
96
}