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 /* This module contains a number of COLLECTOR implementations which are used
30  * to augment the functionality of class PCB_EDIT_FRAME.
31  */
32 
33 
34 #include <collector.h>
35 #include <layers_id_colors_and_visibility.h> // LAYER_COUNT, layer defs
36 #include <view/view.h>
37 #include <class_board_item.h>
38 
39 
40 
60 {
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 IgnoreMTextsMarkedNoShow() const = 0;
113 
117  virtual bool IgnoreMTextsOnBack() const = 0;
118 
122  virtual bool IgnoreMTextsOnFront() const = 0;
123 
127  virtual bool IgnoreModulesOnBack() const = 0;
128 
132  virtual bool IgnoreModulesOnFront() 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 IgnoreModulesVals() const = 0;
161 
165  virtual bool IgnoreModulesRefs() 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 NULL;
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 AllButZones[];
273 
277  static const KICAD_T Zones[];
278 
283  static const KICAD_T BoardLevelItems[];
284 
288  static const KICAD_T Modules[];
289 
293  static const KICAD_T PadsOrModules[];
294 
298  static const KICAD_T PadsOrTracks[];
299 
304 
308  static const KICAD_T ModuleItems[];
309 
313  static const KICAD_T Tracks[];
314 
318  static const KICAD_T LockableItems[];
319 
324  {
325  m_Guide = NULL;
326  m_PrimaryLength = 0;
328  }
329 
330  void Empty2nd()
331  {
332  m_List2nd.clear();
333  }
334 
335  void Append2nd( BOARD_ITEM* item )
336  {
337  m_List2nd.push_back( item );
338  }
339 
345  void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
346 
347  const COLLECTORS_GUIDE* GetGuide() { return m_Guide; }
348 
353 
364  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
365 
376  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
377  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
378 };
379 
380 
386 {
387 private:
388  // the storage architecture here is not important, since this is only
389  // a carrier object and its functions are what is used, and data only indirectly.
390 
393 
396 
399 
402 
418 
420 
421 public:
422 
431  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
432  KIGFX::VIEW* aView )
433  {
434  VECTOR2I one( 1, 1 );
435 
436  m_PreferredLayer = aPreferredLayer;
437  m_IgnorePreferredLayer = false;
438  m_LayerVisible = aVisibleLayerMask;
439  m_IgnoreLockedLayers = true;
441  m_IgnoreLockedItems = false;
442 
443 #if defined(USE_MATCH_LAYER)
444  m_IncludeSecondary = false;
445 #else
446  m_IncludeSecondary = true;
447 #endif
448 
449  m_IgnoreMTextsMarkedNoShow = true; // g_ModuleTextNOVColor;
450  m_IgnoreMTextsOnBack = true;
451  m_IgnoreMTextsOnFront = false;
452  m_IgnoreModulesOnBack = true; // !Show_Modules_Cmp;
453  m_IgnoreModulesOnFront = false;
454 
455  m_IgnorePadsOnFront = false;
456  m_IgnorePadsOnBack = false;
457  m_IgnoreThroughHolePads = false;
458 
459  m_IgnoreModulesVals = false;
460  m_IgnoreModulesRefs = false;
461 
462  m_IgnoreThroughVias = false;
463  m_IgnoreBlindBuriedVias = false;
464  m_IgnoreMicroVias = false;
465  m_IgnoreTracks = false;
466  m_IgnoreZoneFills = true;
467 
468  m_OnePixelInIU = aView->ToWorld( one, false ).x;
469  }
470 
474  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
475  {
476  return m_LayerLocked[aLayerId];
477  }
478 
479  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
480  {
481  m_LayerLocked.set( aLayerId, isLocked );
482  }
483 
487  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
488  {
489  return m_LayerVisible[aLayerId];
490  }
491  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
492  {
493  m_LayerVisible.set( aLayerId, isVisible );
494  }
495  void SetLayerVisibleBits( LSET aLayerBits ) { m_LayerVisible = aLayerBits; }
496 
500  bool IgnoreLockedLayers() const override { return m_IgnoreLockedLayers; }
501  void SetIgnoreLockedLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
502 
506  bool IgnoreNonVisibleLayers() const override { return m_IgnoreNonVisibleLayers; }
507  void SetIgnoreNonVisibleLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
508 
512  PCB_LAYER_ID GetPreferredLayer() const override { return m_PreferredLayer; }
513  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_PreferredLayer = aLayer; }
514 
520  bool IgnorePreferredLayer() const override { return m_IgnorePreferredLayer; }
521  void SetIgnorePreferredLayer( bool ignore ) { m_IgnorePreferredLayer = ignore; }
522 
526  bool IgnoreLockedItems() const override { return m_IgnoreLockedItems; }
527  void SetIgnoreLockedItems( bool ignore ) { m_IgnoreLockedItems = ignore; }
528 
534  bool IncludeSecondary() const override { return m_IncludeSecondary; }
535  void SetIncludeSecondary( bool include ) { m_IncludeSecondary = include; }
536 
540  bool IgnoreMTextsMarkedNoShow() const override { return m_IgnoreMTextsMarkedNoShow; }
541  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_IgnoreMTextsMarkedNoShow = ignore; }
542 
546  bool IgnoreMTextsOnBack() const override { return m_IgnoreMTextsOnBack; }
547  void SetIgnoreMTextsOnBack( bool ignore ) { m_IgnoreMTextsOnBack = ignore; }
548 
552  bool IgnoreMTextsOnFront() const override { return m_IgnoreMTextsOnFront; }
553  void SetIgnoreMTextsOnFront( bool ignore ) { m_IgnoreMTextsOnFront = ignore; }
554 
558  bool IgnoreModulesOnBack() const override { return m_IgnoreModulesOnBack; }
559  void SetIgnoreModulesOnBack( bool ignore ) { m_IgnoreModulesOnBack = ignore; }
560 
564  bool IgnoreModulesOnFront() const override { return m_IgnoreModulesOnFront; }
565  void SetIgnoreModulesOnFront( bool ignore ) { m_IgnoreModulesOnFront = ignore; }
566 
570  bool IgnorePadsOnBack() const override { return m_IgnorePadsOnBack; }
571  void SetIgnorePadsOnBack(bool ignore) { m_IgnorePadsOnBack = ignore; }
572 
576  bool IgnorePadsOnFront() const override { return m_IgnorePadsOnFront; }
577  void SetIgnorePadsOnFront(bool ignore) { m_IgnorePadsOnFront = ignore; }
578 
582  bool IgnoreThroughHolePads() const override { return m_IgnoreThroughHolePads; }
583  void SetIgnoreThroughHolePads(bool ignore) { m_IgnoreThroughHolePads = ignore; }
584 
588  bool IgnoreModulesVals() const override { return m_IgnoreModulesVals; }
589  void SetIgnoreModulesVals(bool ignore) { m_IgnoreModulesVals = ignore; }
590 
594  bool IgnoreModulesRefs() const override { return m_IgnoreModulesRefs; }
595  void SetIgnoreModulesRefs(bool ignore) { m_IgnoreModulesRefs = ignore; }
596 
597  bool IgnoreThroughVias() const override { return m_IgnoreThroughVias; }
598  void SetIgnoreThroughVias( bool ignore ) { m_IgnoreThroughVias = ignore; }
599 
600  bool IgnoreBlindBuriedVias() const override { return m_IgnoreBlindBuriedVias; }
601  void SetIgnoreBlindBuriedVias( bool ignore ) { m_IgnoreBlindBuriedVias = ignore; }
602 
603  bool IgnoreMicroVias() const override { return m_IgnoreMicroVias; }
604  void SetIgnoreMicroVias( bool ignore ) { m_IgnoreMicroVias = ignore; }
605 
606  bool IgnoreTracks() const override { return m_IgnoreTracks; }
607  void SetIgnoreTracks( bool ignore ) { m_IgnoreTracks = ignore; }
608 
609  bool IgnoreZoneFills() const override { return m_IgnoreZoneFills; }
610  void SetIgnoreZoneFills( bool ignore ) { m_IgnoreZoneFills = ignore; }
611 
612  double OnePixelInIU() const override { return m_OnePixelInIU; }
613 };
614 
615 
622 {
623 public:
624 
633  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
634 
641  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
642 };
643 
644 
651 {
653 
654 public:
656  m_layer_id( aLayerId )
657  {
658  }
659 
660  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
661 
670  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
671 
678  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
679 };
680 
681 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:607
static const KICAD_T BoardLevelItems[]
A scan list for all primary board items, omitting items which are subordinate to a MODULE,...
Definition: collectors.h:283
bool IgnoreModulesOnFront() const override
Definition: collectors.h:564
virtual bool IgnoreBlindBuriedVias() const =0
COLLECTOR class definition.
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:479
virtual bool IgnoreModulesOnFront() const =0
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:601
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:313
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
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:585
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
static const KICAD_T Modules[]
A scan list for only MODULEs.
Definition: collectors.h:288
bool IgnoreModulesOnBack() const override
Definition: collectors.h:558
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:475
bool IgnoreMicroVias() const override
Definition: collectors.h:603
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
Definition: collector.h:201
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:539
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
virtual double OnePixelInIU() const =0
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:589
PCB_LAYER_ID m_PreferredLayer
Definition: collectors.h:391
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:604
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:559
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:521
virtual bool IgnoreZoneFills() const =0
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:335
bool IgnoreThroughVias() const override
Definition: collectors.h:597
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:595
virtual PCB_LAYER_ID GetPreferredLayer() const =0
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:601
bool IgnoreModulesVals() const override
Definition: collectors.h:588
PCB_LAYER_ID m_layer_id
Definition: collectors.h:652
static const KICAD_T AllButZones[]
A scan list for all editable board items, except zones.
Definition: collectors.h:272
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
double OnePixelInIU() const override
Definition: collectors.h:612
virtual bool IgnoreMicroVias() const =0
virtual bool IgnoreModulesVals() const =0
static const KICAD_T PadsOrTracks[]
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:298
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:650
const COLLECTORS_GUIDE * GetGuide()
Definition: collectors.h:347
bool IgnorePadsOnBack() const override
Definition: collectors.h:570
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:512
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:520
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:660
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static const KICAD_T ModulesAndTheirItems[]
A scan list for MODULEs and their items (for Modedit)
Definition: collectors.h:303
virtual bool IgnorePadsOnFront() const =0
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:345
virtual bool IgnoreThroughHolePads() const =0
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:495
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
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:567
PCB_LAYER_ID
A quick note on layer IDs:
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:513
LSET is a set of PCB_LAYER_IDs.
LSET m_LayerLocked
bit-mapped layer locked bits
Definition: collectors.h:394
#define NULL
virtual bool IgnoreMTextsOnBack() const =0
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:547
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:577
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:553
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:491
bool IgnoreMTextsOnBack() const override
Definition: collectors.h:546
bool IgnoreZoneFills() const override
Definition: collectors.h:609
Collect BOARD_ITEM objects.
Definition: collectors.h:212
bool IgnoreTracks() const override
Definition: collectors.h:606
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:277
bool IgnoreModulesRefs() const override
Definition: collectors.h:594
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:254
bool IgnoreThroughHolePads() const override
Definition: collectors.h:582
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:541
virtual bool IgnoreMTextsMarkedNoShow() const =0
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:577
virtual bool IgnoreThroughVias() const =0
virtual bool IgnoreModulesRefs() const =0
bool IsLayerLocked(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:474
bool IgnoreMTextsOnFront() const override
Definition: collectors.h:552
bool IgnoreLockedLayers() const override
Definition: collectors.h:500
static const KICAD_T LockableItems[]
A scan list for TRACKS, VIAS, MODULES.
Definition: collectors.h:318
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:487
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer, KIGFX::VIEW *aView)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:431
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:600
bool IgnoreLockedItems() const override
Definition: collectors.h:526
static const KICAD_T PadsOrModules[]
A scan list for PADs or MODULEs.
Definition: collectors.h:293
Board layer functions and definitions.
virtual bool IgnorePads() const
Definition: collectors.h:152
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:655
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:565
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:527
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:598
GENERAL_COLLECTOR()
Constructor GENERALCOLLECTOR.
Definition: collectors.h:323
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
COLLECTOR is an abstract class that will find and hold all the objects according to an inspection don...
Definition: collector.h:55
bool IgnoreNonVisibleLayers() const override
Definition: collectors.h:506
virtual bool IsLayerVisible(PCB_LAYER_ID layer) const =0
virtual bool IgnorePadsOnBack() const =0
An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, telling GENERAL_COLLEC...
Definition: collectors.h:59
bool IgnorePadsOnFront() const override
Definition: collectors.h:576
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:501
VIEW.
Definition: view.h:61
virtual bool IgnoreLockedLayers() const =0
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:621
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:385
SEARCH_RESULT
Definition: base_struct.h:51
std::vector< EDA_ITEM * > m_List
Definition: collector.h:58
LSET m_LayerVisible
bit-mapped layer visible bits
Definition: collectors.h:397
virtual bool IgnoreModulesOnBack() const =0
virtual bool IgnoreMTextsOnFront() const =0
virtual bool IncludeSecondary() const =0
Determine if the secondary criteria or 2nd choice items should be included.
bool IgnoreMTextsMarkedNoShow() const override
Definition: collectors.h:540
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:507
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:162
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:534
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:583
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:610
void SetIncludeSecondary(bool include)
Definition: collectors.h:535
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:63
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:571