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-2021 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 public:
63  virtual ~COLLECTORS_GUIDE() {}
64 
68  virtual bool IsLayerLocked( PCB_LAYER_ID layer ) const = 0;
69 
73  virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
74 
78  virtual bool IgnoreLockedLayers() const = 0;
79 
83  virtual bool IgnoreNonVisibleLayers() const = 0;
84 
88  virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
89 
95  virtual bool IgnorePreferredLayer() const = 0;
96 
100  virtual bool IgnoreLockedItems() const = 0;
101 
107  virtual bool IncludeSecondary() const = 0;
108 
112  virtual bool IgnoreHiddenFPText() const = 0;
113 
117  virtual bool IgnoreFPTextOnBack() const = 0;
118 
122  virtual bool IgnoreFPTextOnFront() const = 0;
123 
127  virtual bool IgnoreFootprintsOnBack() const = 0;
128 
132  virtual bool IgnoreFootprintsOnFront() const = 0;
133 
137  virtual bool IgnorePadsOnBack() const = 0;
138 
142  virtual bool IgnorePadsOnFront() const = 0;
143 
147  virtual bool IgnoreThroughHolePads() const = 0;
148 
152  virtual bool IgnorePads() const
153  {
155  }
156 
160  virtual bool IgnoreFPValues() const = 0;
161 
165  virtual bool IgnoreFPReferences() const = 0;
166 
170  virtual bool IgnoreThroughVias() const = 0;
171 
175  virtual bool IgnoreBlindBuriedVias() const = 0;
176 
180  virtual bool IgnoreMicroVias() const = 0;
181 
185  virtual bool IgnoreTracks() const = 0;
186 
190  virtual bool IgnoreZoneFills() const = 0;
191 
192  virtual double OnePixelInIU() const = 0;
193 
199 };
200 
201 
202 
212 class PCB_COLLECTOR : public COLLECTOR
213 {
214 public:
221  BOARD_ITEM* operator[]( int ndx ) const override
222  {
223  if( (unsigned)ndx < (unsigned)GetCount() )
224  return (BOARD_ITEM*) m_list[ ndx ];
225 
226  return nullptr;
227  }
228 };
229 
230 
241 {
242 protected:
249  std::vector<BOARD_ITEM*> m_List2nd;
250 
255 
261 
262 public:
263 
267  static const KICAD_T AllBoardItems[];
268 
272  static const KICAD_T Zones[];
273 
278  static const KICAD_T BoardLevelItems[];
279 
283  static const KICAD_T Footprints[];
284 
288  static const KICAD_T PadsOrTracks[];
289 
293  static const KICAD_T FootprintItems[];
294 
298  static const KICAD_T Tracks[];
299 
303  static const KICAD_T LockableItems[];
304 
308  static const KICAD_T Dimensions[];
309 
313  static const KICAD_T DraggableItems[];
314 
316  {
317  m_Guide = nullptr;
318  m_PrimaryLength = 0;
320  }
321 
322  void Empty2nd()
323  {
324  m_List2nd.clear();
325  }
326 
327  void Append2nd( BOARD_ITEM* item )
328  {
329  m_List2nd.push_back( item );
330  }
331 
337  void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
338 
339  const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; }
340 
345 
356  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
357 
368  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
369  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
370 };
371 
372 
378 {
379 public:
380 
389  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
390  KIGFX::VIEW* aView )
391  {
392  VECTOR2I one( 1, 1 );
393 
394  m_preferredLayer = aPreferredLayer;
395  m_ignorePreferredLayer = false;
396  m_visibleLayers = aVisibleLayerMask;
397  m_ignoreLockedLayers = true;
399  m_ignoreLockedItems = false;
400 
401 #if defined(USE_MATCH_LAYER)
402  m_includeSecondary = false;
403 #else
404  m_includeSecondary = true;
405 #endif
406 
407  m_ignoreHiddenFPText = true; // g_ModuleTextNOVColor;
408  m_ignoreFPTextOnBack = true;
409  m_ignoreFPTextOnFront = false;
410  m_ignoreFootprintsOnBack = true; // !Show_footprints_Cmp;
412 
413  m_ignorePadsOnFront = false;
414  m_ignorePadsOnBack = false;
415  m_ignoreThroughHolePads = false;
416 
417  m_ignoreFPValues = false;
418  m_ignoreFPReferences = false;
419 
420  m_ignoreThroughVias = false;
421  m_ignoreBlindBuriedVias = false;
422  m_ignoreMicroVias = false;
423  m_ignoreTracks = false;
424  m_ignoreZoneFills = true;
425 
426  m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
427  }
428 
432  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
433  {
434  return m_lockedLayers[aLayerId];
435  }
436 
437  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
438  {
439  m_lockedLayers.set( aLayerId, isLocked );
440  }
441 
445  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
446  {
447  return m_visibleLayers[aLayerId];
448  }
449  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
450  {
451  m_visibleLayers.set( aLayerId, isVisible );
452  }
453  void SetLayerVisibleBits( LSET aLayerBits ) { m_visibleLayers = aLayerBits; }
454 
458  bool IgnoreLockedLayers() const override { return m_ignoreLockedLayers; }
459  void SetIgnoreLockedLayers( bool ignore ) { m_ignoreLockedLayers = ignore; }
460 
464  bool IgnoreNonVisibleLayers() const override { return m_ignoreNonVisibleLayers; }
465  void SetIgnoreNonVisibleLayers( bool ignore ) { m_ignoreLockedLayers = ignore; }
466 
470  PCB_LAYER_ID GetPreferredLayer() const override { return m_preferredLayer; }
471  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_preferredLayer = aLayer; }
472 
478  bool IgnorePreferredLayer() const override { return m_ignorePreferredLayer; }
479  void SetIgnorePreferredLayer( bool ignore ) { m_ignorePreferredLayer = ignore; }
480 
484  bool IgnoreLockedItems() const override { return m_ignoreLockedItems; }
485  void SetIgnoreLockedItems( bool ignore ) { m_ignoreLockedItems = ignore; }
486 
492  bool IncludeSecondary() const override { return m_includeSecondary; }
493  void SetIncludeSecondary( bool include ) { m_includeSecondary = include; }
494 
498  bool IgnoreHiddenFPText() const override { return m_ignoreHiddenFPText; }
499  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_ignoreHiddenFPText = ignore; }
500 
504  bool IgnoreFPTextOnBack() const override { return m_ignoreFPTextOnBack; }
505  void SetIgnoreMTextsOnBack( bool ignore ) { m_ignoreFPTextOnBack = ignore; }
506 
510  bool IgnoreFPTextOnFront() const override { return m_ignoreFPTextOnFront; }
511  void SetIgnoreMTextsOnFront( bool ignore ) { m_ignoreFPTextOnFront = ignore; }
512 
516  bool IgnoreFootprintsOnBack() const override { return m_ignoreFootprintsOnBack; }
517  void SetIgnoreModulesOnBack( bool ignore ) { m_ignoreFootprintsOnBack = ignore; }
518 
522  bool IgnoreFootprintsOnFront() const override { return m_ignoreFootprintsOnFront; }
523  void SetIgnoreModulesOnFront( bool ignore ) { m_ignoreFootprintsOnFront = ignore; }
524 
528  bool IgnorePadsOnBack() const override { return m_ignorePadsOnBack; }
529  void SetIgnorePadsOnBack(bool ignore) { m_ignorePadsOnBack = ignore; }
530 
534  bool IgnorePadsOnFront() const override { return m_ignorePadsOnFront; }
535  void SetIgnorePadsOnFront(bool ignore) { m_ignorePadsOnFront = ignore; }
536 
540  bool IgnoreThroughHolePads() const override { return m_ignoreThroughHolePads; }
541  void SetIgnoreThroughHolePads(bool ignore) { m_ignoreThroughHolePads = ignore; }
542 
546  bool IgnoreFPValues() const override { return m_ignoreFPValues; }
547  void SetIgnoreModulesVals(bool ignore) { m_ignoreFPValues = ignore; }
548 
552  bool IgnoreFPReferences() const override { return m_ignoreFPReferences; }
553  void SetIgnoreModulesRefs(bool ignore) { m_ignoreFPReferences = ignore; }
554 
555  bool IgnoreThroughVias() const override { return m_ignoreThroughVias; }
556  void SetIgnoreThroughVias( bool ignore ) { m_ignoreThroughVias = ignore; }
557 
558  bool IgnoreBlindBuriedVias() const override { return m_ignoreBlindBuriedVias; }
559  void SetIgnoreBlindBuriedVias( bool ignore ) { m_ignoreBlindBuriedVias = ignore; }
560 
561  bool IgnoreMicroVias() const override { return m_ignoreMicroVias; }
562  void SetIgnoreMicroVias( bool ignore ) { m_ignoreMicroVias = ignore; }
563 
564  bool IgnoreTracks() const override { return m_ignoreTracks; }
565  void SetIgnoreTracks( bool ignore ) { m_ignoreTracks = ignore; }
566 
567  bool IgnoreZoneFills() const override { return m_ignoreZoneFills; }
568  void SetIgnoreZoneFills( bool ignore ) { m_ignoreZoneFills = ignore; }
569 
570  double OnePixelInIU() const override { return m_onePixelInIU; }
571  void SetOnePixelInIU( double aValue ) { m_onePixelInIU = aValue; }
572 
573 private:
574  // the storage architecture here is not important, since this is only
575  // a carrier object and its functions are what is used, and data only indirectly.
576 
579 
582 
585 
588 
604 
606 };
607 
608 
615 {
616 public:
617 
625  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
626 
633  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
634 };
635 
636 
643 {
644 public:
646  m_layer_id( aLayerId )
647  {
648  }
649 
650  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
651 
660  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
661 
668  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
669 
670 private:
672 };
673 
674 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:565
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:293
static const KICAD_T BoardLevelItems[]
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition: collectors.h:278
virtual bool IgnoreBlindBuriedVias() const =0
COLLECTOR class definition.
void SetOnePixelInIU(double aValue)
Definition: collectors.h:571
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:437
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:559
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:298
static const KICAD_T Footprints[]
A scan list for only FOOTPRINTs.
Definition: collectors.h:283
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:221
bool IgnoreFPReferences() const override
Definition: collectors.h:552
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:80
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:451
bool IgnoreMicroVias() const override
Definition: collectors.h:561
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:547
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:562
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:517
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:479
bool IgnoreFPTextOnBack() const override
Definition: collectors.h:504
virtual bool IgnoreFootprintsOnBack() const =0
virtual bool IgnoreZoneFills() const =0
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:327
bool IgnoreThroughVias() const override
Definition: collectors.h:555
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:553
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[])
Test 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:671
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:249
virtual bool IgnoreFootprintsOnFront() const =0
double OnePixelInIU() const override
Definition: collectors.h:570
virtual bool IgnoreMicroVias() const =0
static const KICAD_T PadsOrTracks[]
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:288
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:642
bool IgnorePadsOnBack() const override
Definition: collectors.h:528
int m_PrimaryLength
The number of items that were originally in the primary list before the m_List2nd was concatenated on...
Definition: collectors.h:260
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:470
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:478
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:650
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:337
virtual bool IgnoreThroughHolePads() const =0
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:453
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:471
const COLLECTORS_GUIDE * GetGuide() const
Definition: collectors.h:339
bool IgnoreFootprintsOnFront() const override
Definition: collectors.h:522
LSET is a set of PCB_LAYER_IDs.
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:505
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:535
LSET m_lockedLayers
bit-mapped layer locked bits
Definition: collectors.h:580
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:511
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:449
bool IgnoreFPTextOnFront() const override
Definition: collectors.h:510
bool IgnoreZoneFills() const override
Definition: collectors.h:567
Collect BOARD_ITEM objects.
Definition: collectors.h:212
bool IgnoreTracks() const override
Definition: collectors.h:564
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:272
const COLLECTORS_GUIDE * m_Guide
Determine which items are to be collected by Inspect().
Definition: collectors.h:254
bool IgnoreThroughHolePads() const override
Definition: collectors.h:540
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:499
LSET m_visibleLayers
bit-mapped layer visible bits
Definition: collectors.h:583
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:516
bool IsLayerLocked(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:432
bool IgnoreLockedLayers() const override
Definition: collectors.h:458
static const KICAD_T LockableItems[]
A scan list for TRACKs, VIAs, FOOTPRINTs.
Definition: collectors.h:303
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:445
static const KICAD_T DraggableItems[]
A scan list for items that can be dragged.
Definition: collectors.h:313
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:389
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:558
bool IgnoreHiddenFPText() const override
Definition: collectors.h:498
bool IgnoreLockedItems() const override
Definition: collectors.h:484
bool IgnoreFPValues() const override
Definition: collectors.h:546
Board layer functions and definitions.
static const KICAD_T Dimensions[]
A scan list for dimensions.
Definition: collectors.h:308
virtual bool IgnorePads() const
Definition: collectors.h:152
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:645
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:523
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:485
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:556
virtual bool IgnoreFPValues() const =0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
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:464
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:577
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:534
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:459
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:614
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377
SEARCH_RESULT
Definition: eda_item.h:41
virtual bool IncludeSecondary() const =0
Determine if the secondary criteria or 2nd choice items should be included.
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:465
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:492
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:541
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:568
void SetIncludeSecondary(bool include)
Definition: collectors.h:493
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:63
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:529