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 IgnorePads() const
152  {
153  return IgnorePadsOnFront() && IgnorePadsOnBack();
154  }
155 
159  virtual bool IgnoreModulesVals() const = 0;
160 
164  virtual bool IgnoreModulesRefs() const = 0;
165 
169  virtual bool IgnoreThroughVias() const = 0;
170 
174  virtual bool IgnoreBlindBuriedVias() const = 0;
175 
179  virtual bool IgnoreMicroVias() const = 0;
180 
184  virtual bool IgnoreTracks() const = 0;
185 
191 };
192 
193 
194 
204 class PCB_COLLECTOR : public COLLECTOR
205 {
206 public:
213  BOARD_ITEM* operator[]( int ndx ) const
214  {
215  if( (unsigned)ndx < (unsigned)GetCount() )
216  return (BOARD_ITEM*) m_List[ ndx ];
217 
218  return NULL;
219  }
220 };
221 
222 
233 {
234 protected:
241  std::vector<BOARD_ITEM*> m_List2nd;
242 
247 
253 
254 public:
255 
259  static const KICAD_T AllBoardItems[];
260 
264  static const KICAD_T AllButZones[];
265 
269  static const KICAD_T Zones[];
270 
275  static const KICAD_T BoardLevelItems[];
276 
280  static const KICAD_T Modules[];
281 
285  static const KICAD_T PadsOrModules[];
286 
290  static const KICAD_T PadsTracksOrZones[];
291 
295  static const KICAD_T ModulesAndTheirItems[];
296 
300  static const KICAD_T ModuleItems[];
301 
305  static const KICAD_T Tracks[];
306 
310  static const KICAD_T LockableItems[];
311 
316  {
317  m_Guide = NULL;
318  m_PrimaryLength = 0;
319  SetScanTypes( AllBoardItems );
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 
342  int GetPrimaryCount() { return m_PrimaryLength; }
343 
355  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
356 
367  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
368  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
369 };
370 
371 
377 {
378 private:
379  // the storage architecture here is not important, since this is only
380  // a carrier object and its functions are what is used, and data only indirectly.
381 
384 
387 
390 
393 
407 
408 public:
409 
418  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer )
419  {
420  m_PreferredLayer = aPreferredLayer;
421  m_IgnorePreferredLayer = false;
422  m_LayerVisible = aVisibleLayerMask;
423  m_IgnoreLockedLayers = true;
424  m_IgnoreNonVisibleLayers = true;
425  m_IgnoreLockedItems = false;
426 
427 #if defined(USE_MATCH_LAYER)
428  m_IncludeSecondary = false;
429 #else
430  m_IncludeSecondary = true;
431 #endif
432 
433  m_IgnoreMTextsMarkedNoShow = true; // g_ModuleTextNOVColor;
434  m_IgnoreMTextsOnBack = true;
435  m_IgnoreMTextsOnFront = false;
436  m_IgnoreModulesOnBack = true; // !Show_Modules_Cmp;
437  m_IgnoreModulesOnFront = false;
438 
439  m_IgnorePadsOnFront = false;
440  m_IgnorePadsOnBack = false;
441 
442  m_IgnoreModulesVals = false;
443  m_IgnoreModulesRefs = false;
444 
445  m_IgnoreThroughVias = false;
446  m_IgnoreBlindBuriedVias = false;
447  m_IgnoreMicroVias = false;
448  m_IgnoreTracks = false;
449  }
450 
454  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
455  {
456  return m_LayerLocked[aLayerId];
457  }
458 
459  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
460  {
461  m_LayerLocked.set( aLayerId, isLocked );
462  }
463 
467  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
468  {
469  return m_LayerVisible[aLayerId];
470  }
471  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
472  {
473  m_LayerVisible.set( aLayerId, isVisible );
474  }
475  void SetLayerVisibleBits( LSET aLayerBits ) { m_LayerVisible = aLayerBits; }
476 
480  bool IgnoreLockedLayers() const override { return m_IgnoreLockedLayers; }
481  void SetIgnoreLockedLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
482 
486  bool IgnoreNonVisibleLayers() const override { return m_IgnoreNonVisibleLayers; }
487  void SetIgnoreNonVisibleLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
488 
492  PCB_LAYER_ID GetPreferredLayer() const override { return m_PreferredLayer; }
493  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_PreferredLayer = aLayer; }
494 
500  bool IgnorePreferredLayer() const override { return m_IgnorePreferredLayer; }
501  void SetIgnorePreferredLayer( bool ignore ) { m_IgnorePreferredLayer = ignore; }
502 
506  bool IgnoreLockedItems() const override { return m_IgnoreLockedItems; }
507  void SetIgnoreLockedItems( bool ignore ) { m_IgnoreLockedItems = ignore; }
508 
514  bool IncludeSecondary() const override { return m_IncludeSecondary; }
515  void SetIncludeSecondary( bool include ) { m_IncludeSecondary = include; }
516 
520  bool IgnoreMTextsMarkedNoShow() const override { return m_IgnoreMTextsMarkedNoShow; }
521  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_IgnoreMTextsMarkedNoShow = ignore; }
522 
526  bool IgnoreMTextsOnBack() const override { return m_IgnoreMTextsOnBack; }
527  void SetIgnoreMTextsOnBack( bool ignore ) { m_IgnoreMTextsOnBack = ignore; }
528 
532  bool IgnoreMTextsOnFront() const override { return m_IgnoreMTextsOnFront; }
533  void SetIgnoreMTextsOnFront( bool ignore ) { m_IgnoreMTextsOnFront = ignore; }
534 
538  bool IgnoreModulesOnBack() const override { return m_IgnoreModulesOnBack; }
539  void SetIgnoreModulesOnBack( bool ignore ) { m_IgnoreModulesOnBack = ignore; }
540 
544  bool IgnoreModulesOnFront() const override { return m_IgnoreModulesOnFront; }
545  void SetIgnoreModulesOnFront( bool ignore ) { m_IgnoreModulesOnFront = ignore; }
546 
550  bool IgnorePadsOnBack() const override { return m_IgnorePadsOnBack; }
551  void SetIgnorePadsOnBack(bool ignore) { m_IgnorePadsOnBack = ignore; }
552 
556  bool IgnorePadsOnFront() const override { return m_IgnorePadsOnFront; }
557  void SetIgnorePadsOnFront(bool ignore) { m_IgnorePadsOnFront = ignore; }
558 
562  bool IgnoreModulesVals() const override { return m_IgnoreModulesVals; }
563  void SetIgnoreModulesVals(bool ignore) { m_IgnoreModulesVals = ignore; }
564 
568  bool IgnoreModulesRefs() const override { return m_IgnoreModulesRefs; }
569  void SetIgnoreModulesRefs(bool ignore) { m_IgnoreModulesRefs = ignore; }
570 
571  bool IgnoreThroughVias() const override { return m_IgnoreThroughVias; }
572  void SetIgnoreThroughVias( bool ignore ) { m_IgnoreThroughVias = ignore; }
573 
574  bool IgnoreBlindBuriedVias() const override { return m_IgnoreBlindBuriedVias; }
575  void SetIgnoreBlindBuriedVias( bool ignore ) { m_IgnoreBlindBuriedVias = ignore; }
576 
577  bool IgnoreMicroVias() const override { return m_IgnoreMicroVias; }
578  void SetIgnoreMicroVias( bool ignore ) { m_IgnoreMicroVias = ignore; }
579 
580  bool IgnoreTracks() const override { return m_IgnoreTracks; }
581  void SetIgnoreTracks( bool ignore ) { m_IgnoreTracks = ignore; }
582 };
583 
584 
591 {
592 public:
593 
602  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
603 
610  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
611 };
612 
613 
620 {
622 
623 public:
625  m_layer_id( aLayerId )
626  {
627  }
628 
629  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
630 
639  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
640 
647  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
648 };
649 
650 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:581
bool IgnoreModulesOnFront() const override
Definition: collectors.h:544
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:418
virtual bool IgnoreBlindBuriedVias() const =0
COLLECTOR class definition.
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:459
virtual bool IgnoreModulesOnFront() const =0
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:575
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:538
bool IgnoreMicroVias() const override
Definition: collectors.h:577
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:563
PCB_LAYER_ID m_PreferredLayer
Definition: collectors.h:382
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:578
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:539
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:501
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:327
bool IgnoreThroughVias() const override
Definition: collectors.h:571
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:569
virtual PCB_LAYER_ID GetPreferredLayer() const =0
bool IgnoreModulesVals() const override
Definition: collectors.h:562
PCB_LAYER_ID m_layer_id
Definition: collectors.h:621
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:241
virtual bool IgnoreMicroVias() const =0
virtual bool IgnoreModulesVals() const =0
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:619
virtual bool IgnorePads() const
Definition: collectors.h:151
bool IgnorePadsOnBack() const override
Definition: collectors.h:550
int m_PrimaryLength
The number of items that were originally in the primary list before the m_List2nd was concatenated on...
Definition: collectors.h:252
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:492
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:500
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:629
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:337
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:475
PCB_LAYER_ID
A quick note on layer IDs:
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:493
Class LSET is a set of PCB_LAYER_IDs.
LSET m_LayerLocked
bit-mapped layer locked bits
Definition: collectors.h:385
virtual bool IgnoreMTextsOnBack() const =0
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:527
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:557
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:533
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:471
bool IgnoreMTextsOnBack() const override
Definition: collectors.h:526
Collect BOARD_ITEM objects.
Definition: collectors.h:204
bool IgnoreTracks() const override
Definition: collectors.h:580
bool IgnoreModulesRefs() const override
Definition: collectors.h:568
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:246
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:521
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:454
bool IgnoreMTextsOnFront() const override
Definition: collectors.h:532
bool IgnoreLockedLayers() const override
Definition: collectors.h:480
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:467
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:574
bool IgnoreLockedItems() const override
Definition: collectors.h:506
Board layer functions and definitions.
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:624
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:545
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:232
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:507
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:572
GENERAL_COLLECTOR()
Constructor GENERALCOLLECTOR.
Definition: collectors.h:315
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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:486
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:213
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:556
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:481
virtual bool IgnoreLockedLayers() const =0
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:590
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:376
SEARCH_RESULT
Definition: base_struct.h:66
LSET m_LayerVisible
bit-mapped layer visible bits
Definition: collectors.h:388
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:520
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:487
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:514
void SetIncludeSecondary(bool include)
Definition: collectors.h:515
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:67
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:551