KiCad PCB EDA Suite
lib_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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2004-2011 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 <macros.h>
26 #include <general.h>
27 #include <transform.h>
28 #include <lib_collectors.h>
29 
30 
32  LIB_ARC_T,
34  LIB_TEXT_T,
38  LIB_PIN_T,
40  EOT
41 };
42 
43 
45  LIB_ARC_T,
47  LIB_TEXT_T,
52  EOT
53 };
54 
55 
57  LIB_ARC_T,
59  LIB_TEXT_T,
63  LIB_PIN_T,
65  EOT
66 };
67 
68 
70  LIB_ARC_T,
72  LIB_TEXT_T,
76  LIB_PIN_T,
78  EOT
79 };
80 
81 
83  LIB_ARC_T,
85  LIB_TEXT_T,
89  LIB_PIN_T,
91  EOT
92 };
93 
94 
96  LIB_PIN_T,
97  LIB_ARC_T,
101  LIB_TEXT_T,
102  LIB_FIELD_T,
103  EOT
104 };
105 
106 
108 {
109  LIB_ITEM* item = (LIB_ITEM*) aItem;
110 
111 // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ),
112 // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() );
113 
114  if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) )
115  || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) )
116  || !item->HitTest( m_RefPos, -1, DefaultTransform ) )
117  return SEARCH_CONTINUE;
118 
119  Append( aItem );
120 
121  return SEARCH_CONTINUE;
122 }
123 
124 
125 void LIB_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[],
126  const wxPoint& aPosition, int aUnit, int aConvert )
127 {
128  Empty(); // empty the collection just in case
129 
130  SetScanTypes( aFilterList );
131 
132  // remember where the snapshot was taken from and pass refPos to the Inspect() function.
133  SetRefPos( aPosition );
134 
135  m_data.m_unit = aUnit;
136  m_data.m_convert = aConvert;
137 
138  for( LIB_ITEM& item : aItems )
139  {
140  if( SEARCH_QUIT == item.Visit( m_inspector, NULL, m_ScanTypes ) )
141  break;
142  }
143 }
void Empty()
Function Empty sets the list to empty.
int GetUnit() const
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
static const KICAD_T AllItemsButPins[]
A scan list for all schematic items except pins.
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
static const KICAD_T EditableItems[]
A scan list for all editable schematic items.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
This file contains miscellaneous commonly used macros and functions.
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
static const KICAD_T RotatableItems[]
A scan list for all rotatable schematic items.
static const KICAD_T AllItems[]
A scan list for all schematic items.
INSPECTOR_FUNC m_inspector
a class common bridge into the polymorphic Inspect()
void SetRefPos(const wxPoint &aRefPos)
static const KICAD_T MovableItems[]
A scan list for all movable schematic items.
void Collect(LIB_ITEMS_CONTAINER &aItem, const KICAD_T aFilterList[], const wxPoint &aPosition, int aUnit=0, int aConvert=0)
Function Collect scans a SCH_ITEM using this class's Inspector method, which does the collection...
LIB_COLLECTOR_DATA m_data
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
SEARCH_RESULT
Definition: base_struct.h:82
const KICAD_T * m_ScanTypes
Which object types to scan.
SEARCH_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
Function Inspect is the examining function within the INSPECTOR which is passed to the Iterate functi...
static const KICAD_T DoubleClickItems[]
A scan list for all double-clickable library items.
int GetConvert() const