KiCad PCB EDA Suite
collectors.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef COLLECTORS_H
26 #define COLLECTORS_H
27 
28 
29 /*
30  * This module contains a number of COLLECTOR implementations which are used
31  * to augment the functionality of class PCB_EDIT_FRAME.
32  */
33 
34 
35 #include <collector.h>
36 #include <layers_id_colors_and_visibility.h> // LAYER_COUNT, layer defs
37 #include <view/view.h>
38 #include <board_item.h>
39 
40 
41 
61 {
62 
63 public:
64  virtual ~COLLECTORS_GUIDE() {}
65 
69  virtual bool IsLayerLocked( PCB_LAYER_ID layer ) const = 0;
70 
74  virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
75 
79  virtual bool IgnoreLockedLayers() const = 0;
80 
84  virtual bool IgnoreNonVisibleLayers() const = 0;
85 
89  virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
90 
96  virtual bool IgnorePreferredLayer() const = 0;
97 
101  virtual bool IgnoreLockedItems() const = 0;
102 
108  virtual bool IncludeSecondary() const = 0;
109 
113  virtual bool IgnoreHiddenFPText() const = 0;
114 
118  virtual bool IgnoreFPTextOnBack() const = 0;
119 
123  virtual bool IgnoreFPTextOnFront() const = 0;
124 
128  virtual bool IgnoreFootprintsOnBack() const = 0;
129 
133  virtual bool IgnoreFootprintsOnFront() const = 0;
134 
138  virtual bool IgnorePadsOnBack() const = 0;
139 
143  virtual bool IgnorePadsOnFront() const = 0;
144 
148  virtual bool IgnoreThroughHolePads() const = 0;
149 
153  virtual bool IgnorePads() const
154  {
156  }
157 
161  virtual bool IgnoreFPValues() const = 0;
162 
166  virtual bool IgnoreFPReferences() const = 0;
167 
171  virtual bool IgnoreThroughVias() const = 0;
172 
176  virtual bool IgnoreBlindBuriedVias() const = 0;
177 
181  virtual bool IgnoreMicroVias() const = 0;
182 
186  virtual bool IgnoreTracks() const = 0;
187 
191  virtual bool IgnoreZoneFills() const = 0;
192 
193  virtual double OnePixelInIU() const = 0;
194 
200 };
201 
202 
203 
213 class PCB_COLLECTOR : public COLLECTOR
214 {
215 public:
222  BOARD_ITEM* operator[]( int ndx ) const override
223  {
224  if( (unsigned)ndx < (unsigned)GetCount() )
225  return (BOARD_ITEM*) m_list[ ndx ];
226 
227  return NULL;
228  }
229 };
230 
231 
242 {
243 protected:
250  std::vector<BOARD_ITEM*> m_List2nd;
251 
256 
262 
263 public:
264 
268  static const KICAD_T AllBoardItems[];
269 
273  static const KICAD_T Zones[];
274 
279  static const KICAD_T BoardLevelItems[];
280 
284  static const KICAD_T Footprints[];
285 
289  static const KICAD_T PadsOrTracks[];
290 
294  static const KICAD_T FootprintItems[];
295 
299  static const KICAD_T Tracks[];
300 
304  static const KICAD_T LockableItems[];
305 
309  static const KICAD_T Dimensions[];
310 
314  static const KICAD_T DraggableItems[];
315 
320  {
321  m_Guide = NULL;
322  m_PrimaryLength = 0;
324  }
325 
326  void Empty2nd()
327  {
328  m_List2nd.clear();
329  }
330 
331  void Append2nd( BOARD_ITEM* item )
332  {
333  m_List2nd.push_back( item );
334  }
335 
341  void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
342 
343  const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; }
344 
349 
360  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
361 
372  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
373  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
374 };
375 
376 
382 {
383 private:
384  // the storage architecture here is not important, since this is only
385  // a carrier object and its functions are what is used, and data only indirectly.
386 
389 
392 
395 
398 
414 
416 
417 public:
418 
427  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
428  KIGFX::VIEW* aView )
429  {
430  VECTOR2I one( 1, 1 );
431 
432  m_preferredLayer = aPreferredLayer;
433  m_ignorePreferredLayer = false;
434  m_visibleLayers = aVisibleLayerMask;
435  m_ignoreLockedLayers = true;
437  m_ignoreLockedItems = false;
438 
439 #if defined(USE_MATCH_LAYER)
440  m_IncludeSecondary = false;
441 #else
442  m_includeSecondary = true;
443 #endif
444 
445  m_ignoreHiddenFPText = true; // g_ModuleTextNOVColor;
446  m_ignoreFPTextOnBack = true;
447  m_ignoreFPTextOnFront = false;
448  m_ignoreFootprintsOnBack = true; // !Show_footprints_Cmp;
450 
451  m_ignorePadsOnFront = false;
452  m_ignorePadsOnBack = false;
453  m_ignoreThroughHolePads = false;
454 
455  m_ignoreFPValues = false;
456  m_ignoreFPReferences = false;
457 
458  m_ignoreThroughVias = false;
459  m_ignoreBlindBuriedVias = false;
460  m_ignoreMicroVias = false;
461  m_ignoreTracks = false;
462  m_ignoreZoneFills = true;
463 
464  m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
465  }
466 
470  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
471  {
472  return m_lockedLayers[aLayerId];
473  }
474 
475  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
476  {
477  m_lockedLayers.set( aLayerId, isLocked );
478  }
479 
483  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
484  {
485  return m_visibleLayers[aLayerId];
486  }
487  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
488  {
489  m_visibleLayers.set( aLayerId, isVisible );
490  }
491  void SetLayerVisibleBits( LSET aLayerBits ) { m_visibleLayers = aLayerBits; }
492 
496  bool IgnoreLockedLayers() const override { return m_ignoreLockedLayers; }
497  void SetIgnoreLockedLayers( bool ignore ) { m_ignoreLockedLayers = ignore; }
498 
502  bool IgnoreNonVisibleLayers() const override { return m_ignoreNonVisibleLayers; }
503  void SetIgnoreNonVisibleLayers( bool ignore ) { m_ignoreLockedLayers = ignore; }
504 
508  PCB_LAYER_ID GetPreferredLayer() const override { return m_preferredLayer; }
509  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_preferredLayer = aLayer; }
510 
516  bool IgnorePreferredLayer() const override { return m_ignorePreferredLayer; }
517  void SetIgnorePreferredLayer( bool ignore ) { m_ignorePreferredLayer = ignore; }
518 
522  bool IgnoreLockedItems() const override { return m_ignoreLockedItems; }
523  void SetIgnoreLockedItems( bool ignore ) { m_ignoreLockedItems = ignore; }
524 
530  bool IncludeSecondary() const override { return m_includeSecondary; }
531  void SetIncludeSecondary( bool include ) { m_includeSecondary = include; }
532 
536  bool IgnoreHiddenFPText() const override { return m_ignoreHiddenFPText; }
537  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_ignoreHiddenFPText = ignore; }
538 
542  bool IgnoreFPTextOnBack() const override { return m_ignoreFPTextOnBack; }
543  void SetIgnoreMTextsOnBack( bool ignore ) { m_ignoreFPTextOnBack = ignore; }
544 
548  bool IgnoreFPTextOnFront() const override { return m_ignoreFPTextOnFront; }
549  void SetIgnoreMTextsOnFront( bool ignore ) { m_ignoreFPTextOnFront = ignore; }
550 
554  bool IgnoreFootprintsOnBack() const override { return m_ignoreFootprintsOnBack; }
555  void SetIgnoreModulesOnBack( bool ignore ) { m_ignoreFootprintsOnBack = ignore; }
556 
560  bool IgnoreFootprintsOnFront() const override { return m_ignoreFootprintsOnFront; }
561  void SetIgnoreModulesOnFront( bool ignore ) { m_ignoreFootprintsOnFront = ignore; }
562 
566  bool IgnorePadsOnBack() const override { return m_ignorePadsOnBack; }
567  void SetIgnorePadsOnBack(bool ignore) { m_ignorePadsOnBack = ignore; }
568 
572  bool IgnorePadsOnFront() const override { return m_ignorePadsOnFront; }
573  void SetIgnorePadsOnFront(bool ignore) { m_ignorePadsOnFront = ignore; }
574 
578  bool IgnoreThroughHolePads() const override { return m_ignoreThroughHolePads; }
579  void SetIgnoreThroughHolePads(bool ignore) { m_ignoreThroughHolePads = ignore; }
580 
584  bool IgnoreFPValues() const override { return m_ignoreFPValues; }
585  void SetIgnoreModulesVals(bool ignore) { m_ignoreFPValues = ignore; }
586 
590  bool IgnoreFPReferences() const override { return m_ignoreFPReferences; }
591  void SetIgnoreModulesRefs(bool ignore) { m_ignoreFPReferences = ignore; }
592 
593  bool IgnoreThroughVias() const override { return m_ignoreThroughVias; }
594  void SetIgnoreThroughVias( bool ignore ) { m_ignoreThroughVias = ignore; }
595 
596  bool IgnoreBlindBuriedVias() const override { return m_ignoreBlindBuriedVias; }
597  void SetIgnoreBlindBuriedVias( bool ignore ) { m_ignoreBlindBuriedVias = ignore; }
598 
599  bool IgnoreMicroVias() const override { return m_ignoreMicroVias; }
600  void SetIgnoreMicroVias( bool ignore ) { m_ignoreMicroVias = ignore; }
601 
602  bool IgnoreTracks() const override { return m_ignoreTracks; }
603  void SetIgnoreTracks( bool ignore ) { m_ignoreTracks = ignore; }
604 
605  bool IgnoreZoneFills() const override { return m_ignoreZoneFills; }
606  void SetIgnoreZoneFills( bool ignore ) { m_ignoreZoneFills = ignore; }
607 
608  double OnePixelInIU() const override { return m_onePixelInIU; }
609  void SetOnePixelInIU( double aValue ) { m_onePixelInIU = aValue; }
610 };
611 
612 
619 {
620 public:
621 
630  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
631 
638  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
639 };
640 
641 
648 {
650 
651 public:
653  m_layer_id( aLayerId )
654  {
655  }
656 
657  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
658 
667  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
668 
675  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
676 };
677 
678 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:603
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:294
static const KICAD_T BoardLevelItems[]
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition: collectors.h:279
virtual bool IgnoreBlindBuriedVias() const =0
COLLECTOR class definition.
void SetOnePixelInIU(double aValue)
Definition: collectors.h:609
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:475
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:268
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:597
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:299
static const KICAD_T Footprints[]
A scan list for only FOOTPRINTs.
Definition: collectors.h:284
BOARD_ITEM * operator[](int ndx) const override
Overload the COLLECTOR::operator[](int) to return a BOARD_ITEM instead of an EDA_ITEM.
Definition: collectors.h:222
bool IgnoreFPReferences() const override
Definition: collectors.h:590
SEARCH_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the iterate function.
Definition: collectors.cpp:613
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:450
bool IgnoreMicroVias() const override
Definition: collectors.h:599
void SetScanTypes(const KICAD_T *scanTypes)
Record the list of KICAD_T types to consider for collection by the Inspect() function.
Definition: collector.h:220
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:567
virtual double OnePixelInIU() const =0
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:585
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:600
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:555
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:517
bool IgnoreFPTextOnBack() const override
Definition: collectors.h:542
virtual bool IgnoreFootprintsOnBack() const =0
virtual bool IgnoreZoneFills() const =0
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:331
bool IgnoreThroughVias() const override
Definition: collectors.h:593
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:591
virtual PCB_LAYER_ID GetPreferredLayer() const =0
virtual bool IgnoreFPTextOnFront() const =0
std::vector< EDA_ITEM * > m_list
Definition: collector.h:254
void Collect(BOARD_ITEM *aBoard, const KICAD_T aScanList[])
Tests a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:624
PCB_LAYER_ID m_layer_id
Definition: collectors.h:649
virtual bool IgnoreTracks() const =0
std::vector< BOARD_ITEM * > m_List2nd
A place to hold collected objects which don't match precisely the search criteria,...
Definition: collectors.h:250
virtual bool IgnoreFootprintsOnFront() const =0
double OnePixelInIU() const override
Definition: collectors.h:608
virtual bool IgnoreMicroVias() const =0
static const KICAD_T PadsOrTracks[]
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:289
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:647
bool IgnorePadsOnBack() const override
Definition: collectors.h:566
int m_PrimaryLength
The number of items that were originally in the primary list before the m_List2nd was concatenated on...
Definition: collectors.h:261
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:508
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:516
virtual bool IgnoreHiddenFPText() const =0
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:657
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
virtual bool IgnorePadsOnFront() const =0
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:341
virtual bool IgnoreThroughHolePads() const =0
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:491
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
SEARCH_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the Iterate function.
Definition: collectors.cpp:595
PCB_LAYER_ID
A quick note on layer IDs:
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:509
const COLLECTORS_GUIDE * GetGuide() const
Definition: collectors.h:343
bool IgnoreFootprintsOnFront() const override
Definition: collectors.h:560
LSET is a set of PCB_LAYER_IDs.
#define NULL
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:543
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:573
LSET m_lockedLayers
bit-mapped layer locked bits
Definition: collectors.h:390
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:549
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:487
bool IgnoreFPTextOnFront() const override
Definition: collectors.h:548
bool IgnoreZoneFills() const override
Definition: collectors.h:605
Collect BOARD_ITEM objects.
Definition: collectors.h:213
bool IgnoreTracks() const override
Definition: collectors.h:602
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:273
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:255
bool IgnoreThroughHolePads() const override
Definition: collectors.h:578
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:537
LSET m_visibleLayers
bit-mapped layer visible bits
Definition: collectors.h:393
void Collect(BOARD_ITEM *aBoard, const KICAD_T aScanList[])
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
Definition: collectors.cpp:605
virtual bool IgnoreThroughVias() const =0
bool IgnoreFootprintsOnBack() const override
Definition: collectors.h:554
bool IsLayerLocked(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:470
bool IgnoreLockedLayers() const override
Definition: collectors.h:496
static const KICAD_T LockableItems[]
A scan list for TRACKs, VIAs, FOOTPRINTs.
Definition: collectors.h:304
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:483
static const KICAD_T DraggableItems[]
A scan list for items that can be dragged.
Definition: collectors.h:314
virtual bool IgnoreFPTextOnBack() const =0
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer, KIGFX::VIEW *aView)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:427
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:596
bool IgnoreHiddenFPText() const override
Definition: collectors.h:536
bool IgnoreLockedItems() const override
Definition: collectors.h:522
bool IgnoreFPValues() const override
Definition: collectors.h:584
Board layer functions and definitions.
static const KICAD_T Dimensions[]
A scan list for dimensions.
Definition: collectors.h:309
virtual bool IgnorePads() const
Definition: collectors.h:153
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:652
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:561
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:523
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:594
GENERAL_COLLECTOR()
Constructor GENERALCOLLECTOR.
Definition: collectors.h:319
virtual bool IgnoreFPValues() const =0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:53
bool IgnoreNonVisibleLayers() const override
Definition: collectors.h:502
virtual bool IsLayerVisible(PCB_LAYER_ID layer) const =0
virtual bool IgnoreFPReferences() const =0
virtual bool IgnorePadsOnBack() const =0
PCB_LAYER_ID m_preferredLayer
Definition: collectors.h:387
An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, telling GENERAL_COLLEC...
Definition: collectors.h:60
bool IgnorePadsOnFront() const override
Definition: collectors.h:572
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:497
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
virtual bool IgnoreLockedLayers() const =0
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:618
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:381
SEARCH_RESULT
Definition: eda_item.h:40
virtual bool IncludeSecondary() const =0
Determine if the secondary criteria or 2nd choice items should be included.
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:503
SEARCH_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the Iterate function.
Definition: collectors.cpp:157
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:530
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:579
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:606
void SetIncludeSecondary(bool include)
Definition: collectors.h:531
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:64
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:567