2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_ITEMSET_H
|
|
|
|
#define __PNS_ITEMSET_H
|
|
|
|
|
|
|
|
#include <vector>
|
2014-11-14 18:15:58 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include "pns_item.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PNS_ITEMSET
|
|
|
|
*
|
2013-10-14 11:43:57 +00:00
|
|
|
* Holds a list of board items, that can be filtered against net, kinds,
|
2013-09-26 21:53:54 +00:00
|
|
|
* layers, etc.
|
2013-09-18 17:55:16 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
class PNS_ITEMSET
|
|
|
|
{
|
|
|
|
public:
|
2014-11-14 18:15:58 +00:00
|
|
|
typedef std::vector<PNS_ITEM*> ITEMS;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_ITEMSET( PNS_ITEM* aInitialItem = NULL );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_ITEMSET( const PNS_ITEMSET& aOther )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_items = aOther.m_items;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const PNS_ITEMSET& operator=( const PNS_ITEMSET& aOther )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_items = aOther.m_items;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
int Count( int aKindMask = -1 ) const
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
2014-11-14 19:19:00 +00:00
|
|
|
BOOST_FOREACH( PNS_ITEM* item, m_items )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
if( item->Kind() & aKindMask )
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITEMS& Items() { return m_items; }
|
|
|
|
const ITEMS& CItems() const { return m_items; }
|
|
|
|
|
|
|
|
PNS_ITEMSET& FilterLayers( int aStart, int aEnd = -1, bool aInvert = false );
|
|
|
|
PNS_ITEMSET& FilterKinds( int aKindMask, bool aInvert = false );
|
|
|
|
PNS_ITEMSET& FilterNet( int aNet, bool aInvert = false );
|
|
|
|
|
|
|
|
PNS_ITEMSET& ExcludeLayers( int aStart, int aEnd = -1 )
|
|
|
|
{
|
|
|
|
return FilterLayers( aStart, aEnd, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS_ITEMSET& ExcludeKinds( int aKindMask )
|
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
return FilterKinds( aKindMask, true );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
PNS_ITEMSET& ExcludeNet( int aNet )
|
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
return FilterNet( aNet, true );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
PNS_ITEMSET& ExcludeItem( const PNS_ITEM* aItem );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
int Size() const
|
|
|
|
{
|
|
|
|
return m_items.size();
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void Add( PNS_ITEM* aItem )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
m_items.push_back( aItem );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
PNS_ITEM* Get( int index ) const
|
|
|
|
{
|
|
|
|
return m_items[index];
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
PNS_ITEM* operator[] ( int index ) const
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
return m_items[index];
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
m_items.clear();
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
bool Contains( const PNS_ITEM* aItem ) const
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
return std::find( m_items.begin(), m_items.end(), aItem ) != m_items.end();
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
|
|
|
void Erase( const PNS_ITEM* aItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
ITEMS::iterator f = std::find( m_items.begin(), m_items.end(), aItem );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
|
|
|
if( f != m_items.end() )
|
2014-11-14 19:19:00 +00:00
|
|
|
m_items.erase( f );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
private:
|
2014-11-14 18:15:58 +00:00
|
|
|
ITEMS m_items;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|