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 {
97  LIB_ITEM* item = (LIB_ITEM*) aItem;
98 
99 // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ),
100 // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() );
101 
102  if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) )
103  || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) )
104  || !item->HitTest( m_RefPos, -1, DefaultTransform ) )
105  return SEARCH_CONTINUE;
106 
107  Append( aItem );
108 
109  return SEARCH_CONTINUE;
110 }
111 
112 
113 void LIB_COLLECTOR::Collect( LIB_ITEMS& aItems, const KICAD_T aFilterList[],
114  const wxPoint& aPosition, int aUnit, int aConvert )
115 {
116  Empty(); // empty the collection just in case
117 
118  SetScanTypes( aFilterList );
119 
120  // remember where the snapshot was taken from and pass refPos to the Inspect() function.
121  SetRefPos( aPosition );
122 
123  m_data.m_unit = aUnit;
124  m_data.m_convert = aConvert;
125 
126  for( size_t i = 0; i < aItems.size(); i++ )
127  {
128  if( SEARCH_QUIT == aItems[i].Visit( m_inspector, NULL, m_ScanTypes ) )
129  break;
130  }
131 }
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:94
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 EditableItems[]
A scan list for all editable schematic items.
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
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.
boost::ptr_vector< LIB_ITEM > LIB_ITEMS
Helper for defining a list of library draw object pointers.
Definition: lib_draw_item.h:63
LIB_COLLECTOR_DATA m_data
TRANSFORM DefaultTransform
Definition: eeschema.cpp:57
void Collect(LIB_ITEMS &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...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
SEARCH_RESULT
Definition: base_struct.h:68
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...
int GetConvert() const