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 #include <lib_items.h>
30 
31 
33  LIB_ARC_T,
35  LIB_TEXT_T,
39  LIB_PIN_T,
41  EOT
42 };
43 
44 
46  LIB_ARC_T,
48  LIB_TEXT_T,
53  EOT
54 };
55 
56 
58  LIB_ARC_T,
60  LIB_TEXT_T,
64  LIB_PIN_T,
66  EOT
67 };
68 
69 
71  LIB_ARC_T,
73  LIB_TEXT_T,
77  LIB_PIN_T,
79  EOT
80 };
81 
82 
84  LIB_ARC_T,
86  LIB_TEXT_T,
90  LIB_PIN_T,
92  EOT
93 };
94 
95 
97 {
98  LIB_ITEM* item = (LIB_ITEM*) aItem;
99 
100 // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ),
101 // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() );
102 
103  if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) )
104  || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) )
105  || !item->HitTest( m_RefPos, -1, DefaultTransform ) )
106  return SEARCH_CONTINUE;
107 
108  Append( aItem );
109 
110  return SEARCH_CONTINUE;
111 }
112 
113 
114 void LIB_COLLECTOR::Collect( LIB_ITEMS_LIST& aItems, const KICAD_T aFilterList[],
115  const wxPoint& aPosition, int aUnit, int aConvert )
116 {
117  Empty(); // empty the collection just in case
118 
119  SetScanTypes( aFilterList );
120 
121  // remember where the snapshot was taken from and pass refPos to the Inspect() function.
122  SetRefPos( aPosition );
123 
124  m_data.m_unit = aUnit;
125  m_data.m_convert = aConvert;
126 
127  for( size_t i = 0; i < aItems.size(); i++ )
128  {
129  if( SEARCH_QUIT == aItems[i].Visit( m_inspector, NULL, m_ScanTypes ) )
130  break;
131  }
132 }
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:67
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()
size_t size() const
Definition: lib_items.cpp:119
void SetRefPos(const wxPoint &aRefPos)
static const KICAD_T MovableItems[]
A scan list for all movable schematic items.
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: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...
void Collect(LIB_ITEMS_LIST &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...
Wrapper for LIB_ITEMS_MAP to provide flat (list-like) access to the items stored in the map (...
Definition: lib_items.h:55
int GetConvert() const