You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.7 KiB

11 years ago
11 years ago
11 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2013-2014 CERN
  5. * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
  6. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  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. #include "pns_itemset.h"
  22. #include "pns_line.h"
  23. namespace PNS {
  24. ITEM_SET::~ITEM_SET()
  25. {
  26. }
  27. void ITEM_SET::Add( const LINE& aLine )
  28. {
  29. LINE* copy = aLine.Clone();
  30. m_items.push_back( ENTRY( copy, true ) );
  31. }
  32. void ITEM_SET::Prepend( const LINE& aLine )
  33. {
  34. LINE* copy = aLine.Clone();
  35. m_items.insert( m_items.begin(), ENTRY( copy, true ) );
  36. }
  37. ITEM_SET& ITEM_SET::FilterLayers( int aStart, int aEnd, bool aInvert )
  38. {
  39. ENTRIES newItems;
  40. LAYER_RANGE l;
  41. if( aEnd < 0 )
  42. l = LAYER_RANGE( aStart );
  43. else
  44. l = LAYER_RANGE( aStart, aEnd );
  45. for( const ENTRY& ent : m_items )
  46. {
  47. if( ent.item->Layers().Overlaps( l ) ^ aInvert )
  48. {
  49. newItems.push_back( ent );
  50. }
  51. }
  52. m_items = newItems;
  53. return *this;
  54. }
  55. ITEM_SET& ITEM_SET::FilterKinds( int aKindMask, bool aInvert )
  56. {
  57. ENTRIES newItems;
  58. for( const ENTRY& ent : m_items )
  59. {
  60. if( ent.item->OfKind( aKindMask ) ^ aInvert )
  61. {
  62. newItems.push_back( ent );
  63. }
  64. }
  65. m_items = newItems;
  66. return *this;
  67. }
  68. ITEM_SET& ITEM_SET::FilterMarker( int aMarker, bool aInvert )
  69. {
  70. ENTRIES newItems;
  71. for( const ENTRY& ent : m_items )
  72. {
  73. if( ent.item->Marker() & aMarker )
  74. {
  75. newItems.push_back( ent );
  76. }
  77. }
  78. m_items = newItems;
  79. return *this;
  80. }
  81. ITEM_SET& ITEM_SET::FilterNet( int aNet, bool aInvert )
  82. {
  83. ENTRIES newItems;
  84. for( const ENTRY& ent : m_items )
  85. {
  86. if( ( ent.item->Net() == aNet ) ^ aInvert )
  87. {
  88. newItems.push_back( ent );
  89. }
  90. }
  91. m_items = newItems;
  92. return *this;
  93. }
  94. ITEM_SET& ITEM_SET::ExcludeItem( const ITEM* aItem )
  95. {
  96. ENTRIES newItems;
  97. for( const ENTRY& ent : m_items )
  98. {
  99. if( ent.item != aItem )
  100. newItems.push_back( ent );
  101. }
  102. m_items = newItems;
  103. return *this;
  104. }
  105. }