KiCad PCB EDA Suite
collectors.cpp
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 
25 #include <collectors.h>
26 #include <class_board_item.h> // class BOARD_ITEM
27 
28 #include <class_module.h>
29 #include <class_pad.h>
30 #include <class_track.h>
31 #include <class_marker_pcb.h>
32 
33 
34 /* This module contains out of line member functions for classes given in
35  * collectors.h. Those classes augment the functionality of class PCB_EDIT_FRAME.
36  */
37 
38 
40  // there are some restrictions on the order of items in the general case.
41  // all items in m_Drawings for instance should be contiguous.
42  // *** all items in a same list (shown here) must be contiguous ****
43  PCB_MARKER_T, // in m_markers
44  PCB_TEXT_T, // in m_Drawings
45  PCB_LINE_T, // in m_Drawings
46  PCB_DIMENSION_T, // in m_Drawings
47  PCB_TARGET_T, // in m_Drawings
48  PCB_VIA_T, // in m_Tracks
49  PCB_TRACE_T, // in m_Tracks
50  PCB_PAD_T, // in modules
51  PCB_MODULE_TEXT_T, // in modules
52  PCB_MODULE_T, // in m_Modules
53  PCB_ZONE_T, // in m_Zones
54  PCB_ZONE_AREA_T, // in m_ZoneDescriptorList
55  EOT
56 };
57 
58 
61  PCB_TEXT_T,
62  PCB_LINE_T,
65  PCB_VIA_T,
68  PCB_ZONE_T,
70  EOT
71 };
72 
73 
76  PCB_TEXT_T,
77  PCB_LINE_T,
80  PCB_VIA_T,
82  PCB_PAD_T,
85  PCB_ZONE_AREA_T, // if it is visible on screen, it should be selectable
86  EOT
87 };
88 
89 
92  EOT
93 };
94 
95 
97  PCB_PAD_T,
99  EOT
100 };
101 
102 
104  PCB_PAD_T,
105  PCB_VIA_T,
106  PCB_TRACE_T,
107  PCB_ZONE_T,
109  EOT
110 };
111 
112 
116  PCB_PAD_T,
117  PCB_MODULE_T,
118  EOT
119 };
120 
121 
125  PCB_PAD_T,
126  EOT
127 };
128 
129 
131  PCB_TRACE_T,
132  PCB_VIA_T,
133  EOT
134 };
135 
136 
139  EOT
140 };
141 
142 
143 
145 {
146  BOARD_ITEM* item = (BOARD_ITEM*) testItem;
147  MODULE* module = NULL;
148  D_PAD* pad = NULL;
149  bool pad_through = false;
150  VIA* via = NULL;
151  MARKER_PCB* marker = NULL;
152 
153 #if 0 // debugging
154  static int breakhere = 0;
155 
156  switch( item->Type() )
157  {
158  case PCB_PAD_T:
159  {
160  MODULE* m = (MODULE*) item->GetParent();
161 
162  if( m->GetReference() == wxT( "Y2" ) )
163  {
164  breakhere++;
165  }
166  }
167  break;
168 
169  case PCB_VIA_T:
170  breakhere++;
171  break;
172 
173  case PCB_TRACE_T:
174  breakhere++;
175  break;
176 
177  case PCB_ZONE_T:
178  breakhere++;
179  break;
180 
181  case PCB_TEXT_T:
182  breakhere++;
183  break;
184 
185  case PCB_LINE_T:
186  breakhere++;
187  break;
188 
189  case PCB_DIMENSION_T:
190  breakhere++;
191  break;
192 
193  case PCB_MODULE_TEXT_T:
194  {
195  TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
196 
197  if( tm->GetText() == wxT( "10uH" ) )
198  {
199  breakhere++;
200  }
201  }
202  break;
203 
204  case PCB_MODULE_T:
205  {
206  MODULE* m = (MODULE*) item;
207 
208  if( m->GetReference() == wxT( "C98" ) )
209  {
210  breakhere++;
211  }
212  }
213  break;
214 
215  case PCB_MARKER_T:
216  breakhere++;
217  break;
218 
219  default:
220  breakhere++;
221  break;
222  }
223 
224 #endif
225 
226 
227  switch( item->Type() )
228  {
229  case PCB_PAD_T:
230  // there are pad specific visibility controls.
231  // Criterias to select a pad is:
232  // for smd pads: the module parent must be seen, and pads on the corresponding
233  // board side must be seen
234  // if pad is a thru hole, then it can be visible when its parent module is not.
235  // for through pads: pads on Front or Back board sides must be seen
236  pad = (D_PAD*) item;
237 
238  if( (pad->GetAttribute() != PAD_ATTRIB_SMD) &&
239  (pad->GetAttribute() != PAD_ATTRIB_CONN) ) // a hole is present, so multiple layers
240  {
241  // proceed to the common tests below, but without the parent module test,
242  // by leaving module==NULL, but having pad != null
243  pad_through = true;
244  }
245  else // smd, so use pads test after module test
246  {
247  module = static_cast<MODULE*>( item->GetParent() );
248  }
249 
250  break;
251 
252  case PCB_VIA_T: // vias are on many layers, so layer test is specific
253  via = static_cast<VIA*>( item );
254  break;
255 
256  case PCB_TRACE_T:
257  break;
258 
259  case PCB_ZONE_T:
260  break;
261 
262  case PCB_ZONE_AREA_T:
263  break;
264 
265  case PCB_TEXT_T:
266  break;
267 
268  case PCB_LINE_T:
269  break;
270 
271  case PCB_DIMENSION_T:
272  break;
273 
274  case PCB_TARGET_T:
275  break;
276 
277  case PCB_MODULE_TEXT_T:
278  {
279  TEXTE_MODULE *text = static_cast<TEXTE_MODULE*>( item );
280  if( m_Guide->IgnoreMTextsMarkedNoShow() && !text->IsVisible() )
281  goto exit;
282 
283  if( m_Guide->IgnoreMTextsOnBack() && IsBackLayer( text->GetLayer() ) )
284  goto exit;
285 
286  if( m_Guide->IgnoreMTextsOnFront() && IsFrontLayer( text->GetLayer() ) )
287  goto exit;
288 
289  /* The three text types have different criteria: reference
290  * and value have their own ignore flags; user text instead
291  * follows their layer visibility. Checking this here is
292  * simpler than later (when layer visibility is checked for
293  * other entities) */
294 
295  switch( text->GetType() )
296  {
298  if( m_Guide->IgnoreModulesRefs() )
299  goto exit;
300  break;
301 
303  if( m_Guide->IgnoreModulesVals() )
304  goto exit;
305  break;
306 
308  if( !m_Guide->IsLayerVisible( text->GetLayer() )
310  goto exit;
311  break;
312  }
313 
314  // Extract the module since it could be hidden
315  module = static_cast<MODULE*>( item->GetParent() );
316  }
317  break;
318 
319  case PCB_MODULE_T:
320  module = static_cast<MODULE*>( item );
321  break;
322 
323  case PCB_MARKER_T:
324  marker = static_cast<MARKER_PCB*>( item );
325  break;
326 
327  default:
328  break;
329  }
330 
331  // common tests:
332 
333  if( module ) // true from case PCB_PAD_T, PCB_MODULE_TEXT_T, or PCB_MODULE_T
334  {
335  if( m_Guide->IgnoreModulesOnBack() && (module->GetLayer() == B_Cu) )
336  goto exit;
337 
338  if( m_Guide->IgnoreModulesOnFront() && (module->GetLayer() == F_Cu) )
339  goto exit;
340  }
341 
342  // Pads are not sensitive to the layer visibility controls.
343  // They all have their own separate visibility controls
344  // skip them if not visible
345  if( pad )
346  {
347  if( m_Guide->IgnorePads() )
348  goto exit;
349 
350  if( ! pad_through )
351  {
352  if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(F_Cu ) )
353  goto exit;
354 
355  if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(B_Cu ) )
356  goto exit;
357  }
358  }
359 
360  if( marker )
361  {
362  // Markers are not sensitive to the layer
363  if( marker->HitTest( m_RefPos ) )
364  Append( item );
365 
366  goto exit;
367  }
368 
369  if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) ||
371  {
372  PCB_LAYER_ID layer = item->GetLayer();
373 
374  /* Modules and their subcomponents: reference, value and pads
375  * are not sensitive to the layer visibility controls. They all
376  * have their own separate visibility controls for vias,
377  * GetLayer() has no meaning, but IsOnLayer() works fine. User
378  * text in module *is* sensitive to layer visibility but that
379  * was already handled */
380 
381  if( via || module || pad || m_Guide->IsLayerVisible( layer )
383  {
384  if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
385  {
386  if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
387  {
388  if( item->HitTest( m_RefPos ) )
389  {
390  Append( item );
391  goto exit;
392  }
393  }
394  }
395  }
396  }
397 
398 
399  if( m_Guide->IncludeSecondary() )
400  {
401  // for now, "secondary" means "tolerate any layer". It has
402  // no effect on other criteria, since there is a separate "ignore" control for
403  // those in the COLLECTORS_GUIDE
404 
405  PCB_LAYER_ID layer = item->GetLayer();
406 
407  /* Modules and their subcomponents: reference, value and pads
408  * are not sensitive to the layer visibility controls. They all
409  * have their own separate visibility controls. User texts
410  * follows layer visibility controls (but that was already
411  * checked) */
412 
413  if( via || module || pad || m_Guide->IsLayerVisible( layer )
415  {
416  if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
417  {
418  if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
419  {
420  if( item->HitTest( m_RefPos ) )
421  {
422  Append2nd( item );
423  goto exit;
424  }
425  }
426  }
427  }
428  }
429 
430 exit:
431  return SEARCH_CONTINUE; // always when collecting
432 }
433 
434 
435 void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
436  const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide )
437 {
438  Empty(); // empty the collection, primary criteria list
439  Empty2nd(); // empty the collection, secondary criteria list
440 
441  // remember guide, pass it to Inspect()
442  SetGuide( &aGuide );
443 
444  SetScanTypes( aScanList );
445 
446  // remember where the snapshot was taken from and pass refPos to
447  // the Inspect() function.
448  SetRefPos( aRefPos );
449 
450  aItem->Visit( m_inspector, NULL, m_ScanTypes );
451 
452  SetTimeNow(); // when snapshot was taken
453 
454  // record the length of the primary list before concatenating on to it.
455  m_PrimaryLength = m_List.size();
456 
457  // append 2nd list onto end of the first list
458  for( unsigned i = 0; i<m_List2nd.size(); ++i )
459  Append( m_List2nd[i] );
460 
461  Empty2nd();
462 }
463 
464 
466 {
467  // The Visit() function only visits the testItem if its type was in the
468  // the scanList, so therefore we can collect anything given to us here.
469  Append( testItem );
470 
471  return SEARCH_CONTINUE; // always when collecting
472 }
473 
474 
475 void PCB_TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] )
476 {
477  Empty(); // empty any existing collection
478 
479  aBoard->Visit( m_inspector, NULL, aScanList );
480 }
481 
482 
484 {
485  BOARD_ITEM* item = (BOARD_ITEM*) testItem;
486 
487  if( item->GetLayer() == m_layer_id )
488  Append( testItem );
489 
490  return SEARCH_CONTINUE;
491 }
492 
493 
494 void PCB_LAYER_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] )
495 {
496  Empty();
497 
498  aBoard->Visit( m_inspector, NULL, aScanList );
499 }
void Empty()
Function Empty sets the list to empty.
virtual bool IsLayerLocked(PCB_LAYER_ID layer) const =0
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
BOARD_ITEM_CONTAINER * GetParent() const
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
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
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
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:398
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
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
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
TEXT_TYPE GetType() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
virtual bool IgnoreNonVisibleLayers() const =0
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
void Append2nd(BOARD_ITEM *item)
Definition: collectors.h:302
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
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
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
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual bool IgnoreModulesVals() const =0
virtual bool IgnorePads() const
Definition: collectors.h:151
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
virtual bool IgnorePreferredLayer() const =0
Provide wildcard behavior regarding the preferred layer.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
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 Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:312
class MODULE, a footprint
Definition: typeinfo.h:89
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
Markers used to show a drc problem on boards.
INSPECTOR_FUNC m_inspector
a class common bridge into the polymorphic Inspect()
PCB_LAYER_ID
A quick note on layer IDs:
virtual bool IgnoreMTextsOnBack() const =0
void SetRefPos(const wxPoint &aRefPos)
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:249
class SEGZONE, a segment used to fill a zone area (segment on a copper layer)
Definition: typeinfo.h:97
const COLLECTORS_GUIDE * m_Guide
Determines which items are to be collected by Inspect()
Definition: collectors.h:226
virtual bool IgnoreMTextsMarkedNoShow() const =0
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:62
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
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
Pad object description.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
virtual bool IgnoreModulesRefs() const =0
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
void SetTimeNow()
static const KICAD_T PadsOrModules[]
A scan list for PADs or MODULEs.
Definition: collectors.h:265
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:439
virtual bool IsLocked() const
Function IsLocked.
bool IsVisible() const
Definition: eda_text.h:176
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:280
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
virtual bool IsLayerVisible(PCB_LAYER_ID layer) const =0
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
virtual bool IgnorePadsOnBack() const =0
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Module description (excepted pads)
An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, telling GENERAL_COLLEC...
Definition: collectors.h:63
virtual bool IgnoreLockedItems() const =0
virtual bool IgnoreLockedLayers() const =0
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.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_pad.h:637
virtual bool IgnoreModulesOnBack() const =0
virtual bool IgnoreMTextsOnFront() const =0
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
virtual bool IncludeSecondary() const =0
Determine if the secondary criteria or 2nd choice items should be included.
const KICAD_T * m_ScanTypes
Which object types to scan.
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