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 <[email protected]>
5 * Copyright (C) 2004-2022 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#include <collector.h>
34#include <layer_ids.h> // LAYER_COUNT, layer defs
35#include <view/view.h>
36#include <board_item.h>
37
53{
54public:
55 virtual ~COLLECTORS_GUIDE() {}
56
60 virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
61
65 virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
66
70 virtual bool IgnoreLockedItems() const = 0;
71
77 virtual bool IncludeSecondary() const = 0;
78
82 virtual bool IgnoreHiddenFPText() const = 0;
83
87 virtual bool IgnoreFPTextOnBack() const = 0;
88
92 virtual bool IgnoreFPTextOnFront() const = 0;
93
97 virtual bool IgnoreFootprintsOnBack() const = 0;
98
102 virtual bool IgnoreFootprintsOnFront() const = 0;
103
107 virtual bool IgnorePadsOnBack() const = 0;
108
112 virtual bool IgnorePadsOnFront() const = 0;
113
117 virtual bool IgnoreThroughHolePads() const = 0;
118
122 virtual bool IgnorePads() const
123 {
125 }
126
130 virtual bool IgnoreFPValues() const = 0;
131
135 virtual bool IgnoreFPReferences() const = 0;
136
140 virtual bool IgnoreThroughVias() const = 0;
141
145 virtual bool IgnoreBlindBuriedVias() const = 0;
146
150 virtual bool IgnoreMicroVias() const = 0;
151
155 virtual bool IgnoreTracks() const = 0;
156
160 virtual bool IgnoreZoneFills() const = 0;
161
162 virtual double OnePixelInIU() const = 0;
163};
164
165
166
177{
178public:
185 BOARD_ITEM* operator[]( int ndx ) const override
186 {
187 if( (unsigned)ndx < (unsigned)GetCount() )
188 return (BOARD_ITEM*) m_list[ ndx ];
189
190 return nullptr;
191 }
192};
193
194
204{
205protected:
212 std::vector<BOARD_ITEM*> m_List2nd;
213
218
219public:
220
224 static const std::vector<KICAD_T> AllBoardItems;
225
229 static const std::vector<KICAD_T> Zones;
230
235 static const std::vector<KICAD_T> BoardLevelItems;
236
240 static const std::vector<KICAD_T> Footprints;
241
245 static const std::vector<KICAD_T> PadsOrTracks;
246
250 static const std::vector<KICAD_T> FootprintItems;
251
255 static const std::vector<KICAD_T> Tracks;
256
260 static const std::vector<KICAD_T> LockableItems;
261
265 static const std::vector<KICAD_T> Dimensions;
266
270 static const std::vector<KICAD_T> DraggableItems;
271
273 m_Guide( nullptr )
274 {
276 }
277
278 void Empty2nd()
279 {
280 m_List2nd.clear();
281 }
282
283 void Append2nd( BOARD_ITEM* item )
284 {
285 m_List2nd.push_back( item );
286 }
287
293 void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; }
294
295 const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; }
296
305 INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
306
316 void Collect( BOARD_ITEM* aItem, const std::vector<KICAD_T>& aScanList,
317 const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide );
318};
319
320
326{
327public:
328
337 GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
338 KIGFX::VIEW* aView )
339 {
340 VECTOR2I one( 1, 1 );
341
342 m_preferredLayer = aPreferredLayer;
343 m_visibleLayers = aVisibleLayerMask;
344 m_ignoreLockedItems = false;
345
346#if defined(USE_MATCH_LAYER)
347 m_includeSecondary = false;
348#else
349 m_includeSecondary = true;
350#endif
351
352 m_ignoreHiddenFPText = true; // g_ModuleTextNOVColor;
354 m_ignoreFPTextOnFront = false;
355 m_ignoreFootprintsOnBack = true; // !Show_footprints_Cmp;
357
358 m_ignorePadsOnFront = false;
359 m_ignorePadsOnBack = false;
361
362 m_ignoreFPValues = false;
363 m_ignoreFPReferences = false;
364
365 m_ignoreThroughVias = false;
367 m_ignoreMicroVias = false;
368 m_ignoreTracks = false;
369 m_ignoreZoneFills = true;
370
371 m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
372 }
373
377 bool IsLayerVisible( PCB_LAYER_ID aLayerId ) const override
378 {
379 return m_visibleLayers[aLayerId];
380 }
381 void SetLayerVisible( PCB_LAYER_ID aLayerId, bool isVisible )
382 {
383 m_visibleLayers.set( aLayerId, isVisible );
384 }
385 void SetLayerVisibleBits( LSET aLayerBits ) { m_visibleLayers = aLayerBits; }
386
392
396 bool IgnoreLockedItems() const override { return m_ignoreLockedItems; }
397 void SetIgnoreLockedItems( bool ignore ) { m_ignoreLockedItems = ignore; }
398
404 bool IncludeSecondary() const override { return m_includeSecondary; }
405 void SetIncludeSecondary( bool include ) { m_includeSecondary = include; }
406
410 bool IgnoreHiddenFPText() const override { return m_ignoreHiddenFPText; }
411 void SetIgnoreMTextsMarkedNoShow( bool ignore ) { m_ignoreHiddenFPText = ignore; }
412
416 bool IgnoreFPTextOnBack() const override { return m_ignoreFPTextOnBack; }
417 void SetIgnoreMTextsOnBack( bool ignore ) { m_ignoreFPTextOnBack = ignore; }
418
422 bool IgnoreFPTextOnFront() const override { return m_ignoreFPTextOnFront; }
423 void SetIgnoreMTextsOnFront( bool ignore ) { m_ignoreFPTextOnFront = ignore; }
424
428 bool IgnoreFootprintsOnBack() const override { return m_ignoreFootprintsOnBack; }
429 void SetIgnoreModulesOnBack( bool ignore ) { m_ignoreFootprintsOnBack = ignore; }
430
434 bool IgnoreFootprintsOnFront() const override { return m_ignoreFootprintsOnFront; }
435 void SetIgnoreModulesOnFront( bool ignore ) { m_ignoreFootprintsOnFront = ignore; }
436
440 bool IgnorePadsOnBack() const override { return m_ignorePadsOnBack; }
441 void SetIgnorePadsOnBack(bool ignore) { m_ignorePadsOnBack = ignore; }
442
446 bool IgnorePadsOnFront() const override { return m_ignorePadsOnFront; }
447 void SetIgnorePadsOnFront(bool ignore) { m_ignorePadsOnFront = ignore; }
448
452 bool IgnoreThroughHolePads() const override { return m_ignoreThroughHolePads; }
453 void SetIgnoreThroughHolePads(bool ignore) { m_ignoreThroughHolePads = ignore; }
454
458 bool IgnoreFPValues() const override { return m_ignoreFPValues; }
459 void SetIgnoreModulesVals(bool ignore) { m_ignoreFPValues = ignore; }
460
464 bool IgnoreFPReferences() const override { return m_ignoreFPReferences; }
465 void SetIgnoreModulesRefs(bool ignore) { m_ignoreFPReferences = ignore; }
466
467 bool IgnoreThroughVias() const override { return m_ignoreThroughVias; }
468 void SetIgnoreThroughVias( bool ignore ) { m_ignoreThroughVias = ignore; }
469
470 bool IgnoreBlindBuriedVias() const override { return m_ignoreBlindBuriedVias; }
471 void SetIgnoreBlindBuriedVias( bool ignore ) { m_ignoreBlindBuriedVias = ignore; }
472
473 bool IgnoreMicroVias() const override { return m_ignoreMicroVias; }
474 void SetIgnoreMicroVias( bool ignore ) { m_ignoreMicroVias = ignore; }
475
476 bool IgnoreTracks() const override { return m_ignoreTracks; }
477 void SetIgnoreTracks( bool ignore ) { m_ignoreTracks = ignore; }
478
479 bool IgnoreZoneFills() const override { return m_ignoreZoneFills; }
480 void SetIgnoreZoneFills( bool ignore ) { m_ignoreZoneFills = ignore; }
481
482 double OnePixelInIU() const override { return m_onePixelInIU; }
483 void SetOnePixelInIU( double aValue ) { m_onePixelInIU = aValue; }
484
485private:
486 // the storage architecture here is not important, since this is only
487 // a carrier object and its functions are what is used, and data only indirectly.
488
490
492
495
511
513};
514
515
522{
523public:
524
532 INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
533
540 void Collect( BOARD_ITEM* aBoard, const std::vector<KICAD_T>& aTypes );
541};
542
543
550{
551public:
553 m_layer_id( aLayerId )
554 { }
555
556 void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; }
557
565 INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
566
573 void Collect( BOARD_ITEM* aBoard, const std::vector<KICAD_T>& aTypes );
574
575private:
577};
578
579#endif // COLLECTORS_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR telling it what should ...
Definition: collectors.h:53
virtual bool IgnoreThroughVias() const =0
virtual bool IgnoreHiddenFPText() const =0
virtual bool IsLayerVisible(PCB_LAYER_ID layer) const =0
virtual bool IgnoreFPTextOnFront() const =0
virtual double OnePixelInIU() const =0
virtual bool IgnoreFPTextOnBack() const =0
virtual bool IgnoreLockedItems() const =0
virtual bool IgnoreZoneFills() const =0
virtual bool IgnoreMicroVias() const =0
virtual bool IgnoreFootprintsOnBack() const =0
virtual bool IgnoreBlindBuriedVias() const =0
virtual bool IgnoreThroughHolePads() const =0
virtual bool IgnorePadsOnBack() const =0
virtual bool IgnoreFPReferences() const =0
virtual bool IgnorePadsOnFront() const =0
virtual bool IgnoreFootprintsOnFront() const =0
virtual bool IgnorePads() const
Definition: collectors.h:122
virtual bool IgnoreTracks() const =0
virtual bool IncludeSecondary() const =0
Determine if the secondary criteria or 2nd choice items should be included.
virtual bool IgnoreFPValues() const =0
virtual ~COLLECTORS_GUIDE()
Definition: collectors.h:55
virtual PCB_LAYER_ID GetPreferredLayer() const =0
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:48
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
void SetScanTypes(const std::vector< KICAD_T > &aTypes)
Record the list of KICAD_T types to consider for collection by the Inspect() function.
Definition: collector.h:211
std::vector< EDA_ITEM * > m_list
Definition: collector.h:240
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:326
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:471
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:477
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:411
bool IgnoreFootprintsOnBack() const override
Definition: collectors.h:428
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:435
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:465
bool IgnorePadsOnFront() const override
Definition: collectors.h:446
bool IgnoreLockedItems() const override
Definition: collectors.h:396
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:474
LSET m_visibleLayers
bit-mapped layer visible bits
Definition: collectors.h:491
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:480
bool IgnoreTracks() const override
Definition: collectors.h:476
GENERAL_COLLECTORS_GUIDE(LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer, KIGFX::VIEW *aView)
Grab stuff from global preferences and uses reasonable defaults.
Definition: collectors.h:337
double OnePixelInIU() const override
Definition: collectors.h:482
bool IncludeSecondary() const override
Determine if the secondary criteria, or 2nd choice items should be included.
Definition: collectors.h:404
bool IgnoreFPTextOnBack() const override
Definition: collectors.h:416
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:441
void SetLayerVisible(PCB_LAYER_ID aLayerId, bool isVisible)
Definition: collectors.h:381
void SetIgnoreLockedItems(bool ignore)
Definition: collectors.h:397
bool IgnoreBlindBuriedVias() const override
Definition: collectors.h:470
bool IgnoreFPValues() const override
Definition: collectors.h:458
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:429
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:459
bool IgnoreFootprintsOnFront() const override
Definition: collectors.h:434
void SetPreferredLayer(PCB_LAYER_ID aLayer)
Definition: collectors.h:391
bool IgnoreThroughVias() const override
Definition: collectors.h:467
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:468
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:453
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:423
void SetIncludeSecondary(bool include)
Definition: collectors.h:405
void SetLayerVisibleBits(LSET aLayerBits)
Definition: collectors.h:385
void SetOnePixelInIU(double aValue)
Definition: collectors.h:483
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const override
Definition: collectors.h:377
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:417
bool IgnoreThroughHolePads() const override
Definition: collectors.h:452
bool IgnoreMicroVias() const override
Definition: collectors.h:473
bool IgnoreZoneFills() const override
Definition: collectors.h:479
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:447
bool IgnoreFPTextOnFront() const override
Definition: collectors.h:422
bool IgnorePadsOnBack() const override
Definition: collectors.h:440
bool IgnoreHiddenFPText() const override
Definition: collectors.h:410
PCB_LAYER_ID m_preferredLayer
Definition: collectors.h:489
PCB_LAYER_ID GetPreferredLayer() const override
Definition: collectors.h:390
bool IgnoreFPReferences() const override
Definition: collectors.h:464
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:204
static const std::vector< KICAD_T > BoardLevelItems
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition: collectors.h:235
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:293
static const std::vector< KICAD_T > PadsOrTracks
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:245
static const std::vector< KICAD_T > Zones
A scan list for zones outlines only.
Definition: collectors.h:229
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:283
const COLLECTORS_GUIDE * GetGuide() const
Definition: collectors.h:295
INSPECT_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the Iterate function.
Definition: collectors.cpp:160
static const std::vector< KICAD_T > LockableItems
A scan list for TRACKs, VIAs, FOOTPRINTs.
Definition: collectors.h:260
static const std::vector< KICAD_T > Footprints
A scan list for only FOOTPRINTs.
Definition: collectors.h:240
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition: collectors.h:224
std::vector< BOARD_ITEM * > m_List2nd
A place to hold collected objects which don't match precisely the search criteria,...
Definition: collectors.h:212
static const std::vector< KICAD_T > Tracks
A scan list for only TRACKs and ARCs.
Definition: collectors.h:255
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:596
static const std::vector< KICAD_T > Dimensions
A scan list for dimensions.
Definition: collectors.h:265
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition: collectors.h:250
const COLLECTORS_GUIDE * m_Guide
Determine which items are to be collected by Inspect().
Definition: collectors.h:217
static const std::vector< KICAD_T > DraggableItems
A scan list for items that can be dragged.
Definition: collectors.h:270
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
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:445
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
Collect BOARD_ITEM objects.
Definition: collectors.h:177
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:185
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:550
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Test a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:649
INSPECT_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the iterate function.
Definition: collectors.cpp:638
PCB_LAYER_COLLECTOR(PCB_LAYER_ID aLayerId=UNDEFINED_LAYER)
Definition: collectors.h:552
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:556
PCB_LAYER_ID m_layer_id
Definition: collectors.h:576
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:522
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
Definition: collectors.cpp:631
INSPECT_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
The examining function within the INSPECTOR which is passed to the Iterate function.
Definition: collectors.cpp:621
INSPECT_RESULT
Definition: eda_item.h:42
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401