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-2017 KiCad Developers, see change_log.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 <class_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 
171 };
172 
173 
174 
184 class PCB_COLLECTOR : public COLLECTOR
185 {
186 public:
193  BOARD_ITEM* operator[]( int ndx ) const
194  {
195  if( (unsigned)ndx < (unsigned)GetCount() )
196  return (BOARD_ITEM*) m_List[ ndx ];
197 
198  return NULL;
199  }
200 };
201 
202 
213 {
214 protected:
221  std::vector<BOARD_ITEM*> m_List2nd;
222 
227 
233 
234 public:
235 
239  static const KICAD_T AllBoardItems[];
240 
244  static const KICAD_T AllButZones[];
245 
249  static const KICAD_T Zones[];
250 
255  static const KICAD_T BoardLevelItems[];
256 
260  static const KICAD_T Modules[];
261 
265  static const KICAD_T PadsOrModules[];
266 
270  static const KICAD_T PadsTracksOrZones[];
271 
276 
280  static const KICAD_T ModuleItems[];
281 
285  static const KICAD_T Tracks[];
286 
291  {
292  m_Guide = NULL;
293  m_PrimaryLength = 0;
294  SetScanTypes( AllBoardItems );
295  }
296 
297  void Empty2nd()
298  {
299  m_List2nd.clear();
300  }
301 
302  void Append2nd( BOARD_ITEM* item )
303  {
304  m_List2nd.push_back( item );
305  }
306 
312  void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
313 
318 
330  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
331 
342  void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
343  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide );
344 };
345 
346 
352 {
353 private:
354  // the storage architecture here is not important, since this is only
355  // a carrier object and its functions are what is used, and data only indirectly.
356 
359 
362 
365 
368 
378 
379 public:
380 
389  GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer )
390  {
391  m_PreferredLayer = aPreferredLayer;
392  m_IgnorePreferredLayer = false;
393  m_LayerVisible = aVisibleLayerMask;
394  m_IgnoreLockedLayers = true;
395  m_IgnoreNonVisibleLayers = true;
396  m_IgnoreLockedItems = false;
397 
398 #if defined(USE_MATCH_LAYER)
399  m_IncludeSecondary = false;
400 #else
401  m_IncludeSecondary = true;
402 #endif
403 
404  m_IgnoreMTextsMarkedNoShow = true; // g_ModuleTextNOVColor;
405  m_IgnoreMTextsOnBack = true;
406  m_IgnoreMTextsOnFront = false;
407  m_IgnoreModulesOnBack = true; // !Show_Modules_Cmp;
408  m_IgnoreModulesOnFront = false;
409 
410  m_IgnorePadsOnFront = false;
411  m_IgnorePadsOnBack = false;
412 
413  m_IgnoreModulesVals = false;
414  m_IgnoreModulesRefs = false;
415  }
416 
420  bool IsLayerLocked( PCB_LAYER_ID aLayerId ) const override
421  {
422  return m_LayerLocked[aLayerId];
423  }
424 
425  void SetLayerLocked( PCB_LAYER_ID aLayerId, bool isLocked )
426  {
427  m_LayerLocked.set( aLayerId, isLocked );
428  }
429 
433  bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
434  {
435  return m_LayerVisible[aLayerId];
436  }
437  void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
438  {
439  m_LayerVisible.set( aLayerId, isVisible );
440  }
441  void SetLayerVisibleBits( LSET aLayerBits ) { m_LayerVisible = aLayerBits; }
442 
446  bool IgnoreLockedLayers() const override { return m_IgnoreLockedLayers; }
447  void SetIgnoreLockedLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
448 
452  bool IgnoreNonVisibleLayers() const override { return m_IgnoreNonVisibleLayers; }
453  void SetIgnoreNonVisibleLayers( bool ignore ) { m_IgnoreLockedLayers = ignore; }
454 
458  PCB_LAYER_ID GetPreferredLayer() const override { return m_PreferredLayer; }
459  void SetPreferredLayer( PCB_LAYER_ID aLayer ) { m_PreferredLayer = aLayer; }
460 
466  bool IgnorePreferredLayer() const override { return m_IgnorePreferredLayer; }
467  void SetIgnorePreferredLayer( bool ignore ) { m_IgnorePreferredLayer = ignore; }
468 
472  bool IgnoreLockedItems() const override { return m_IgnoreLockedItems; }
473  void SetIgnoreLockedItems( bool ignore ) { m_IgnoreLockedItems = ignore; }
474 
480  bool IncludeSecondary() const override { return m_IncludeSecondary; }
481  void SetIncludeSecondary( bool include ) { m_IncludeSecondary = include; }
482 
486  bool IgnoreMTextsMarkedNoShow() const override { return m_IgnoreMTextsMarkedNoShow; }
487  void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_IgnoreMTextsMarkedNoShow = ignore; }
488 
492  bool IgnoreMTextsOnBack() const override { return m_IgnoreMTextsOnBack; }
493  void SetIgnoreMTextsOnBack( bool ignore ) { m_IgnoreMTextsOnBack = ignore; }
494 
498  bool IgnoreMTextsOnFront() const override { return m_IgnoreMTextsOnFront; }
499  void SetIgnoreMTextsOnFront( bool ignore ) { m_IgnoreMTextsOnFront = ignore; }
500 
504  bool IgnoreModulesOnBack() const override { return m_IgnoreModulesOnBack; }
505  void SetIgnoreModulesOnBack( bool ignore ) { m_IgnoreModulesOnBack = ignore; }
506 
510  bool IgnoreModulesOnFront() const override { return m_IgnoreModulesOnFront; }
511  void SetIgnoreModulesOnFront( bool ignore ) { m_IgnoreModulesOnFront = ignore; }
512 
516  bool IgnorePadsOnBack() const override { return m_IgnorePadsOnBack; }
517  void SetIgnorePadsOnBack(bool ignore) { m_IgnorePadsOnBack = ignore; }
518 
522  bool IgnorePadsOnFront() const override { return m_IgnorePadsOnFront; }
523  void SetIgnorePadsOnFront(bool ignore) { m_IgnorePadsOnFront = ignore; }
524 
528  bool IgnoreModulesVals() const override { return m_IgnoreModulesVals; }
529  void SetIgnoreModulesVals(bool ignore) { m_IgnoreModulesVals = ignore; }
530 
534  bool IgnoreModulesRefs() const override { return m_IgnoreModulesRefs; }
535  void SetIgnoreModulesRefs(bool ignore) { m_IgnoreModulesRefs = ignore; }
536 };
537 
538 
545 {
546 public:
547 
556  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
557 
564  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
565 };
566 
567 
574 {
576 
577 public:
579  m_layer_id( aLayerId )
580  {
581  }
582 
583  void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
584 
593  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
594 
601  void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] );
602 };
603 
604 #endif // COLLECTORS_H
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
int GetCount() const
Function GetCount returns the number of objects in the list.
static const KICAD_T BoardLevelItems[]
A scan list for all primary board items, omitting items which are subordinate to a MODULE...
Definition: collectors.h:255
bool IgnoreModulesOnFront() const override
Definition: collectors.h:510
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:389
void SetLayerLocked(PCB_LAYER_ID aLayerId, bool isLocked)
Definition: collectors.h:425
virtual bool IgnoreModulesOnFront() const =0
static const KICAD_T PadsTracksOrZones[]
A scan list for PADs, TRACKs, VIAs, or ZONEs.
Definition: collectors.h:270
static const KICAD_T AllBoardItems[]
A scan list for all editable board items, like PcbGeneralLocateAndDisplay()
Definition: collectors.h:239
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:285
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:483
Class 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:260
bool IgnoreModulesOnBack() const override
Definition: collectors.h:504
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
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:435
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:529
PCB_LAYER_ID m_PreferredLayer
Definition: collectors.h:357
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:505
void SetIgnorePreferredLayer(bool ignore)
Definition: collectors.h:467
virtual bool IgnoreNonVisibleLayers() const =0
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:302
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:535
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:494
bool IgnoreModulesVals() const override
Definition: collectors.h:528
PCB_LAYER_ID m_layer_id
Definition: collectors.h:575
static const KICAD_T AllButZones[]
A scan list for all editable board items, except zones.
Definition: collectors.h:244
std::vector< BOARD_ITEM * > m_List2nd
A place to hold collected objects which don't match precisely the search criteria, but would be acceptable if nothing else is found.
Definition: collectors.h:221
virtual bool IgnoreModulesVals() const =0
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:573
virtual bool IgnorePads() const
Definition: collectors.h:151
bool IgnorePadsOnBack() const override
Definition: collectors.h:516
int m_PrimaryLength
The number of items that were originally in the primary list before the m_List2nd was concatenated on...
Definition: collectors.h:232
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:458
bool IgnorePreferredLayer() const override
Provide wildcard behavior regarding the preferred layer.
Definition: collectors.h:466
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:583
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
static const KICAD_T ModulesAndTheirItems[]
A scan list for MODULEs and their items (for Modedit)
Definition: collectors.h:275
virtual bool IgnorePadsOnFront() const =0
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:312
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:441
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:465
PCB_LAYER_ID
A quick note on layer IDs:
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:459
Class LSET is a set of PCB_LAYER_IDs.
LSET m_LayerLocked
bit-mapped layer locked bits
Definition: collectors.h:360
virtual bool IgnoreMTextsOnBack() const =0
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:493
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:523
COLLECTOR class definition.
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:499
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:437
bool IgnoreMTextsOnBack() const override
Definition: collectors.h:492
Collect BOARD_ITEM objects.
Definition: collectors.h:184
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:249
bool IgnoreModulesRefs() const override
Definition: collectors.h:534
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:226
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:487
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:475
virtual bool IgnoreModulesRefs() const =0
bool IsLayerLocked(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:420
bool IgnoreMTextsOnFront() const override
Definition: collectors.h:498
bool IgnoreLockedLayers() const override
Definition: collectors.h:446
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:433
bool IgnoreLockedItems() const override
Definition: collectors.h:472
static const KICAD_T PadsOrModules[]
A scan list for PADs or MODULEs.
Definition: collectors.h:265
Board layer functions and definitions.
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:578
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:280
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:511
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:212
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:473
GENERAL_COLLECTOR()
Constructor GENERALCOLLECTOR.
Definition: collectors.h:290
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
bool IgnoreNonVisibleLayers() const override
Definition: collectors.h:452
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:193
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:522
virtual bool IgnoreLockedItems() const =0
void SetIgnoreLockedLayers(bool ignore)
Definition: collectors.h:447
virtual bool IgnoreLockedLayers() const =0
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:544
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:351
SEARCH_RESULT
Definition: base_struct.h:82
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
LSET m_LayerVisible
bit-mapped layer visible bits
Definition: collectors.h:363
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:486
void SetIgnoreNonVisibleLayers(bool ignore)
Definition: collectors.h:453
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:144
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:480
void SetIncludeSecondary(bool include)
Definition: collectors.h:481
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:67
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:517