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
|
2022-08-29 20:21:46 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
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
|
|
|
|
|
2015-08-19 15:27:23 +00:00
|
|
|
#include <vector>
|
2020-10-24 12:21:40 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_item.h"
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* Hold a list of board items, that can be filtered against net, kinds, layers, etc.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
class LINE;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
class ITEM_SET : public ITEM_OWNER
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-19 23:56:05 +00:00
|
|
|
ITEM_SET( ITEM* aInitialItem = nullptr, bool aBecomeOwner = false )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aInitialItem )
|
2022-08-29 20:21:46 +00:00
|
|
|
m_items.emplace_back( aInitialItem );
|
|
|
|
|
|
|
|
if( aBecomeOwner )
|
|
|
|
aInitialItem->SetOwner( this );
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET( const ITEM_SET& aOther )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-08-19 15:27:23 +00:00
|
|
|
m_items = aOther.m_items;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
~ITEM_SET();
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2018-09-21 03:15:47 +00:00
|
|
|
ITEM_SET& operator=( const ITEM_SET& aOther )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
m_items.clear();
|
|
|
|
m_items.reserve( aOther.m_items.size() );
|
|
|
|
|
|
|
|
for( ITEM* item : aOther.m_items )
|
|
|
|
m_items.push_back( item );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
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;
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2018-05-07 20:51:40 +00:00
|
|
|
if( aKindMask == -1 || aKindMask == ITEM::ANY_T )
|
2021-04-08 03:16:56 +00:00
|
|
|
return static_cast<int>( m_items.size() );
|
2018-05-07 20:51:40 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : m_items )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
if( item->Kind() & aKindMask )
|
|
|
|
n++;
|
|
|
|
}
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
bool Empty() const
|
|
|
|
{
|
|
|
|
return m_items.empty();
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
std::vector<ITEM*>& Items() { return m_items; }
|
|
|
|
const std::vector<ITEM*>& CItems() const { return m_items; }
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& FilterLayers( int aStart, int aEnd = -1, bool aInvert = false );
|
|
|
|
ITEM_SET& FilterKinds( int aKindMask, bool aInvert = false );
|
2023-08-22 12:06:33 +00:00
|
|
|
ITEM_SET& FilterNet( NET_HANDLE aNet, bool aInvert = false );
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& FilterMarker( int aMarker, bool aInvert = false );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& ExcludeLayers( int aStart, int aEnd = -1 )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
return FilterLayers( aStart, aEnd, true );
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& ExcludeKinds( int aKindMask )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
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
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
ITEM_SET& ExcludeNet( NET_HANDLE aNet )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& ExcludeItem( const ITEM* aItem );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
int Size() const
|
|
|
|
{
|
2021-04-08 03:16:56 +00:00
|
|
|
return static_cast<int>( m_items.size() );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void Add( const LINE& aLine );
|
|
|
|
void Prepend( const LINE& aLine );
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2021-04-08 03:16:56 +00:00
|
|
|
ITEM* operator[]( size_t aIndex ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
return m_items[aIndex];
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
std::vector<ITEM*>::iterator begin() { return m_items.begin(); }
|
|
|
|
std::vector<ITEM*>::iterator end() { return m_items.end(); }
|
|
|
|
std::vector<ITEM*>::const_iterator cbegin() const { return m_items.cbegin(); }
|
|
|
|
std::vector<ITEM*>::const_iterator cend() const { return m_items.cend(); }
|
2021-04-04 17:58:51 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void Add( ITEM* aItem, bool aBecomeOwner = false )
|
2014-11-14 19:19:00 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
m_items.emplace_back( aItem );
|
|
|
|
|
|
|
|
if( aBecomeOwner )
|
|
|
|
aItem->SetOwner( this );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void Prepend( ITEM* aItem, bool aBecomeOwner = false )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
m_items.emplace( m_items.begin(), aItem );
|
|
|
|
|
|
|
|
if( aBecomeOwner )
|
|
|
|
aItem->SetOwner( this );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool Contains( ITEM* aItem ) const
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
return alg::contains( m_items, aItem );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void Erase( ITEM* aItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
std::vector<ITEM*>::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
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
template<class T>
|
2016-08-29 17:31:13 +00:00
|
|
|
T* FindByKind( ITEM::PnsKind kind, int index = 0 )
|
2015-08-12 19:12:12 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : m_items )
|
2015-08-12 19:12:12 +00:00
|
|
|
{
|
|
|
|
if( item->OfKind( kind ) )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2015-08-12 19:12:12 +00:00
|
|
|
if( index == n )
|
|
|
|
return static_cast<T*>( item );
|
|
|
|
else
|
|
|
|
n++;
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2015-08-12 19:12:12 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
private:
|
2022-08-29 20:21:46 +00:00
|
|
|
std::vector<ITEM*> m_items;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#endif
|