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-2018 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 
29 #ifndef COLLECTORS_H
30 #define COLLECTORS_H
31 
32 
33 /* This module contains a number of COLLECTOR implementations which are used
34  * to augment the functionality of class PCB_EDIT_FRAME.
35  */
36 
37 
38 #include <collector.h>
39 #include <layers_id_colors_and_visibility.h> // LAYER_COUNT, layer defs
40 
41 
42 class BOARD_ITEM;
43 
44 
64 {
65 
66 public:
67  virtual ~COLLECTORS_GUIDE() {}
68 
72  virtual bool IsLayerLocked( PCB_LAYER_ID layer ) const = 0;
73 
77  virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
78 
82  virtual bool IgnoreLockedLayers() const = 0;
83 
87  virtual bool IgnoreNonVisibleLayers() const = 0;
88 
92  virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
93 
99  virtual bool IgnorePreferredLayer() const = 0;
100 
104  virtual bool IgnoreLockedItems() const = 0;
105 
111  virtual bool IncludeSecondary() const = 0;
112 
116  virtual bool IgnoreMTextsMarkedNoShow() const = 0;
117 
121  virtual bool IgnoreMTextsOnBack() const = 0;
122 
126  virtual bool IgnoreMTextsOnFront() const = 0;
127 
131  virtual bool IgnoreModulesOnBack() const = 0;
132 
136  virtual bool IgnoreModulesOnFront() const = 0;
137 
141  virtual bool IgnorePadsOnBack() const = 0;
142 
146  virtual bool IgnorePadsOnFront() const = 0;
147 
151  virtual bool IgnoreThroughHolePads() const = 0;
152 
156  virtual bool IgnorePads() const
157  {
159  }
160 
164  virtual bool IgnoreModulesVals() const = 0;
165 
169  virtual bool IgnoreModulesRefs() const = 0;
170 
174  virtual bool IgnoreThroughVias() const = 0;
175 
179  virtual bool IgnoreBlindBuriedVias() const = 0;
180 
184  virtual bool IgnoreMicroVias() const = 0;
185 
189  virtual bool IgnoreTracks() const = 0;
190 
194  virtual bool IgnoreZoneFills() const = 0;
195 
201 };
202 
203 
204 
214 class PCB_COLLECTOR : public COLLECTOR
215 {
216 public:
223  BOARD_ITEM* operator[]( int ndx ) const
224  {
225  if( (unsigned)ndx < (unsigned)GetCount() )
226  return (BOARD_ITEM*) m_List[ ndx ];
227 
228  return NULL;
229  }
230 };
231 
232 
243 {
244 protected:
251  std::vector<BOARD_ITEM*> m_List2nd;
252 
257 
263 
264 public:
265 
269  static const KICAD_T AllBoardItems[];
270 
274  static const KICAD_T AllButZones[];
275 
279  static const KICAD_T Zones[];
280 
285  static const KICAD_T BoardLevelItems[];
286 
290  static const KICAD_T Modules[];
291 
295  static const KICAD_T PadsOrModules[];
296 
300  static const KICAD_T PadsOrTracks[];
301 
305  static const KICAD_T ModulesAndTheirItems[];
306 
310  static const KICAD_T ModuleItems[];
311 
315  static const KICAD_T Tracks[];
316 
320  static const KICAD_T LockableItems[];
321 
326  {
327  m_Guide = NULL;
328  m_PrimaryLength = 0;
329  SetScanTypes( AllBoardItems );
330  }
331 
332  void Empty2nd()
333  {
334  m_List2nd.clear();
335  }
336 
337  void Append2nd( BOARD_ITEM* item )
338  {
339  m_List2nd.push_back( item );
340  }
341 
347  void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
348 
352  int GetPrimaryCount() { return m_PrimaryLength; }
353 
365  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
366 
377  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
378  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
379 };
380 
381 
387 {
388 private:
389  // the storage architecture here is not important, since this is only
390  // a carrier object and its functions are what is used, and data only indirectly.
391 
394 
397 
400 
403 
419 
420 public:
421 
430  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer )
431  {
432  m_PreferredLayer = aPreferredLayer;
433  m_IgnorePreferredLayer = false;
434  m_LayerVisible = aVisibleLayerMask;
435  m_IgnoreLockedLayers = true;
436  m_IgnoreNonVisibleLayers = 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_IgnoreMTextsMarkedNoShow = true; // g_ModuleTextNOVColor;
446  m_IgnoreMTextsOnBack = true;
447  m_IgnoreMTextsOnFront = false;
448  m_IgnoreModulesOnBack = true; // !Show_Modules_Cmp;
449  m_IgnoreModulesOnFront = false;
450 
451  m_IgnorePadsOnFront = false;
452  m_IgnorePadsOnBack = false;
453  m_IgnoreThroughHolePads = false;
454 
455  m_IgnoreModulesVals = false;
456  m_IgnoreModulesRefs = false;
457 
458  m_IgnoreThroughVias = false;
459  m_IgnoreBlindBuriedVias = false;
460  m_IgnoreMicroVias = false;
461  m_IgnoreTracks = false;
462  m_IgnoreZoneFills = true;
463  }
464 
468  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
469  {
470  return m_LayerLocked[aLayerId];
471  }
472 
473  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
474  {
475  m_LayerLocked.set( aLayerId, isLocked );
476  }
477 
481  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
482  {
483  return m_LayerVisible[aLayerId];
484  }
485  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
486  {
487  m_LayerVisible.set( aLayerId, isVisible );
488  }
489  void SetLayerVisibleBits( LSET aLayerBits ) { m_LayerVisible = aLayerBits; }
490 
494  bool IgnoreLockedLayers() const override { return m_IgnoreLockedLayers; }
495  void SetIgnoreLockedLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
496 
500  bool IgnoreNonVisibleLayers() const override { return m_IgnoreNonVisibleLayers; }
501  void SetIgnoreNonVisibleLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
502 
506  PCB_LAYER_ID GetPreferredLayer() const override { return m_PreferredLayer; }
507  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_PreferredLayer = aLayer; }
508 
514  bool IgnorePreferredLayer() const override { return m_IgnorePreferredLayer; }
515  void SetIgnorePreferredLayer( bool ignore ) { m_IgnorePreferredLayer = ignore; }
516 
520  bool IgnoreLockedItems() const override { return m_IgnoreLockedItems; }
521  void SetIgnoreLockedItems( bool ignore ) { m_IgnoreLockedItems = ignore; }
522 
528  bool IncludeSecondary() const override { return m_IncludeSecondary; }
529  void SetIncludeSecondary( bool include ) { m_IncludeSecondary = include; }
530 
534  bool IgnoreMTextsMarkedNoShow() const override { return m_IgnoreMTextsMarkedNoShow; }
535  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_IgnoreMTextsMarkedNoShow = ignore; }
536 
540  bool IgnoreMTextsOnBack() const override { return m_IgnoreMTextsOnBack; }
541  void SetIgnoreMTextsOnBack( bool ignore ) { m_IgnoreMTextsOnBack = ignore; }
542 
546  bool IgnoreMTextsOnFront() const override { return m_IgnoreMTextsOnFront; }
547  void SetIgnoreMTextsOnFront( bool ignore ) { m_IgnoreMTextsOnFront = ignore; }
548 
552  bool IgnoreModulesOnBack() const override { return m_IgnoreModulesOnBack; }
553  void SetIgnoreModulesOnBack( bool ignore ) { m_IgnoreModulesOnBack = ignore; }
554 
558  bool IgnoreModulesOnFront() const override { return m_IgnoreModulesOnFront; }
559  void SetIgnoreModulesOnFront( bool ignore ) { m_IgnoreModulesOnFront = ignore; }
560 
564  bool IgnorePadsOnBack() const override { return m_IgnorePadsOnBack; }
565  void SetIgnorePadsOnBack(bool ignore) { m_IgnorePadsOnBack = ignore; }
566 
570  bool IgnorePadsOnFront() const override { return m_IgnorePadsOnFront; }
571  void SetIgnorePadsOnFront(bool ignore) { m_IgnorePadsOnFront = ignore; }
572 
576  bool IgnoreThroughHolePads() const override { return m_IgnoreThroughHolePads; }
577  void SetIgnoreThroughHolePads(bool ignore) { m_IgnoreThroughHolePads = ignore; }
578 
582  bool IgnoreModulesVals() const override { return m_IgnoreModulesVals; }
583  void SetIgnoreModulesVals(bool ignore) { m_IgnoreModulesVals = ignore; }
584 
588  bool IgnoreModulesRefs() const override { return m_IgnoreModulesRefs; }
589  void SetIgnoreModulesRefs(bool ignore) { m_IgnoreModulesRefs = ignore; }
590 
591  bool IgnoreThroughVias() const override { return m_IgnoreThroughVias; }
592  void SetIgnoreThroughVias( bool ignore ) { m_IgnoreThroughVias = ignore; }
593 
594  bool IgnoreBlindBuriedVias() const override { return m_IgnoreBlindBuriedVias; }
595  void SetIgnoreBlindBuriedVias( bool ignore ) { m_IgnoreBlindBuriedVias = ignore; }
596 
597  bool IgnoreMicroVias() const override { return m_IgnoreMicroVias; }
598  void SetIgnoreMicroVias( bool ignore ) { m_IgnoreMicroVias = ignore; }
599 
600  bool IgnoreTracks() const override { return m_IgnoreTracks; }
601  void SetIgnoreTracks( bool ignore ) { m_IgnoreTracks = ignore; }
602 
603  bool IgnoreZoneFills() const override { return m_IgnoreZoneFills; }
604  void SetIgnoreZoneFills( bool ignore ) { m_IgnoreZoneFills = ignore; }
605 };
606 
607 
614 {
615 public:
616 
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 {
645 
646 public:
648  m_layer_id( aLayerId )
649  {
650  }
651 
652  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
653 
662  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
663 
670  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
671 };
672 
673 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:601
bool IgnoreModulesOnFront() const override
Definition: collectors.h:558
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:430
virtual bool IgnoreBlindBuriedVias() const =0
COLLECTOR class definition.
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:473
virtual bool IgnoreModulesOnFront() const =0
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:595
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
bool IgnoreModulesOnBack() const override
Definition: collectors.h:552
bool IgnoreMicroVias() const override
Definition: collectors.h:597
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:583
PCB_LAYER_ID m_PreferredLayer
Definition: collectors.h:392
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:598
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:553
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:515
virtual bool IgnoreZoneFills() const =0
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:337
bool IgnoreThroughVias() const override
Definition: collectors.h:591
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:589
virtual PCB_LAYER_ID GetPreferredLayer() const =0
bool IgnoreModulesVals() const override
Definition: collectors.h:582
PCB_LAYER_ID m_layer_id
Definition: collectors.h:644
virtual bool IgnoreTracks() const =0
std::vector< BOARD_ITEM * > m_List2nd
A place to hold collected objects which don&#39;t match precisely the search criteria, but would be acceptable if nothing else is found.
Definition: collectors.h:251
virtual bool IgnoreMicroVias() const =0
virtual bool IgnoreModulesVals() const =0
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:642
virtual bool IgnorePads() const
Definition: collectors.h:156
bool IgnorePadsOnBack() const override
Definition: collectors.h:564
int m_PrimaryLength
The number of items that were originally in the primary list before the m_List2nd was concatenated on...
Definition: collectors.h:262
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:506
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:514
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:652
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
virtual bool IgnorePadsOnFront() const =0
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:347
virtual bool IgnoreThroughHolePads() const =0
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:489
PCB_LAYER_ID
A quick note on layer IDs:
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:507
Class LSET is a set of PCB_LAYER_IDs.
LSET m_LayerLocked
bit-mapped layer locked bits
Definition: collectors.h:395
virtual bool IgnoreMTextsOnBack() const =0
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:541
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:571
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:547
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:485
bool IgnoreMTextsOnBack() const override
Definition: collectors.h:540
bool IgnoreZoneFills() const override
Definition: collectors.h:603
Collect BOARD_ITEM objects.
Definition: collectors.h:214
bool IgnoreTracks() const override
Definition: collectors.h:600
bool IgnoreModulesRefs() const override
Definition: collectors.h:588
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:256
bool IgnoreThroughHolePads() const override
Definition: collectors.h:576
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:535
virtual bool IgnoreMTextsMarkedNoShow() const =0
virtual bool IgnoreThroughVias() const =0
virtual bool IgnoreModulesRefs() const =0
bool IsLayerLocked(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:468
bool IgnoreMTextsOnFront() const override
Definition: collectors.h:546
bool IgnoreLockedLayers() const override
Definition: collectors.h:494
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:481
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:594
bool IgnoreLockedItems() const override
Definition: collectors.h:520
Board layer functions and definitions.
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:647
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:559
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:242
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:521
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:592
GENERAL_COLLECTOR()
Constructor GENERALCOLLECTOR.
Definition: collectors.h:325
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
Definition: collector.h:55
bool IgnoreNonVisibleLayers() const override
Definition: collectors.h:500
virtual bool IsLayerVisible(PCB_LAYER_ID layer) const =0
BOARD_ITEM * operator[](int ndx) const
Overload the COLLECTOR::operator[](int) to return a BOARD_ITEM instead of an EDA_ITEM.
Definition: collectors.h:223
virtual bool IgnorePadsOnBack() const =0
An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, telling GENERAL_COLLEC...
Definition: collectors.h:63
bool IgnorePadsOnFront() const override
Definition: collectors.h:570
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:495
virtual bool IgnoreLockedLayers() const =0
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:613
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:386
SEARCH_RESULT
Definition: base_struct.h:66
LSET m_LayerVisible
bit-mapped layer visible bits
Definition: collectors.h:398
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:534
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:501
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:528
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:577
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:604
void SetIncludeSecondary(bool include)
Definition: collectors.h:529
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:67
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:565