KiCad PCB EDA Suite
sch_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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2011-2015 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 
29 #ifndef _SCH_COLLECTORS_H_
30 #define _SCH_COLLECTORS_H_
31 
32 
33 #include <class_collector.h>
34 #include <sch_item_struct.h>
36 
37 
41 class SCH_COLLECTOR : public COLLECTOR
42 {
43 public:
44 
48  static const KICAD_T AllItems[];
49 
53  static const KICAD_T EditableItems[];
54 
58  static const KICAD_T CmpFieldValueOnly[];
59 
64 
69 
73  static const KICAD_T MovableItems[];
74 
78  static const KICAD_T DraggableItems[];
79 
83  static const KICAD_T RotatableItems[];
84 
88  static const KICAD_T ParentItems[];
89 
93  static const KICAD_T AllItemsButPins[];
94 
98  static const KICAD_T ComponentsOnly[];
99 
103  static const KICAD_T SheetsOnly[];
104 
109 
113  static const KICAD_T OrientableItems[];
114 
118  static const KICAD_T CopyableItems[];
119 
123  static const KICAD_T DoubleClickItems[];
124 
129  {
130  SetScanTypes( aScanTypes );
131  }
132 
139  SCH_ITEM* operator[]( int aIndex ) const
140  {
141  if( (unsigned)aIndex < (unsigned)GetCount() )
142  return (SCH_ITEM*) m_List[ aIndex ];
143 
144  return NULL;
145  }
146 
147  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
148 
158  void Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPosition );
159 
165  bool IsCorner() const;
166 
174  bool IsNode( bool aIncludePins = true ) const;
175 
189  bool IsDraggableJunction() const;
190 };
191 
192 
199 {
202 
204  wxString m_sheetPath;
205 
208 
209 public:
210  SCH_FIND_COLLECTOR_DATA( const wxPoint& aPosition = wxDefaultPosition,
211  const wxString& aSheetPath = wxEmptyString,
212  SCH_ITEM* aParent = NULL )
213  : m_position( aPosition )
214  , m_sheetPath( aSheetPath )
215  , m_parent( aParent )
216  { }
217 
218  wxPoint GetPosition() const { return m_position; }
219 
220  wxString GetSheetPath() const { return m_sheetPath; }
221 
222  SCH_ITEM* GetParent() const { return m_parent; }
223 };
224 
225 
232 {
234  std::vector< SCH_FIND_COLLECTOR_DATA > m_data;
235 
238 
241 
244 
248 
252 
257 #if defined(DEBUG)
258  void dump();
259 #endif
260 
261 public:
262 
267  {
268  SetScanTypes( aScanTypes );
269  m_foundIndex = 0;
270  SetForceSearch( false );
271  m_sheetPath = NULL;
272  m_lib_hash = 0;
273  }
274 
275  void Empty()
276  {
277  m_foundIndex = 0;
279  m_data.clear();
280  }
281 
282  void SetForceSearch( bool doSearch = true ) { m_forceSearch = doSearch; }
283 
284  int GetLibHash() const { return m_lib_hash; }
285  void SetLibHash( int aHash ) { m_lib_hash = aHash; }
286 
287  int GetFoundIndex() const { return m_foundIndex; }
288  void SetFoundIndex( int aIndex )
289  {
290  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
291  }
292 
300  bool PassedEnd() const;
301 
306  void UpdateIndex();
307 
316  SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
317 
328  bool IsSearchRequired( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
329  {
330  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
331  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
332  }
333 
340  wxString GetText();
341 
353 
360  bool ReplaceItem( SCH_SHEET_PATH* aSheetPath = NULL );
361 
362  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
363 
367  void SetReplaceString( const wxString &aReplaceString );
368 
378  void Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, SCH_SHEET_PATH* aSheetPath = NULL );
379 
380  void IncrementIndex() { m_foundIndex += 1; }
381 };
382 
383 
392 {
393 public:
404  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
405 
413  void Collect( SCH_ITEM* aBoard, const KICAD_T aScanList[] );
414 };
415 
416 
417 #endif // _SCH_COLLECTORS_H_
void Empty()
Function Empty sets the list to empty.
int GetCount() const
Function GetCount returns the number of objects in the list.
static const KICAD_T ParentItems[]
A scan list for only parent schematic items.
static const KICAD_T SheetsAndSheetLabels[]
A scan list for schematic sheet and sheet label items.
Class SCH_FIND_COLLECTOR is used to iterate over all of the items in a schematic or sheet and collect...
Class TYPE_COLLECTOR merely gathers up all SCH_ITEMs of a given set of KICAD_T type(s).
SCH_ITEM * operator[](int aIndex) const
Overload COLLECTOR::operator[](int) to return a SCH_ITEM instead of an EDA_ITEM.
bool IsSearchRequired(const SCH_FIND_REPLACE_DATA &aFindReplaceData)
Function IsSearchRequired checks the current collector state against aFindReplaceData to see if a new...
static const KICAD_T RotatableItems[]
A scan list for all rotatable schematic items.
SEARCH_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
static const KICAD_T AllItems[]
A scan list for all schematic items.
SCH_FIND_COLLECTOR_DATA(const wxPoint &aPosition=wxDefaultPosition, const wxString &aSheetPath=wxEmptyString, SCH_ITEM *aParent=NULL)
SCH_SHEET_PATH * m_sheetPath
The path of the sheet currently being iterated over.
Base schematic object class definition.
static const KICAD_T DoubleClickItems[]
A scan list for schematic items that react to a double-click.
SCH_COLLECTOR(const KICAD_T *aScanTypes=SCH_COLLECTOR::AllItems)
Constructor SCH_COLLECTOR.
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
void SetFoundIndex(int aIndex)
wxString GetSheetPath() const
wxString m_sheetPath
The human readable sheet path.
bool ChangesCompare(const SCH_FIND_REPLACE_DATA &aFindReplaceData)
Function ChangesCompare tests aFindReplaceData to see if it would result in a change in the search st...
SEARCH_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
Function Inspect is the examining function within the INSPECTOR which is passed to the Iterate functi...
void Collect(SCH_ITEM *aItem, const KICAD_T aFilterList[], const wxPoint &aPosition)
Function Collect scans a SCH_ITEM using this class's Inspector method, which does the collection...
static const KICAD_T ComponentsOnly[]
A scan list for schematic component items only.
static const KICAD_T AllItemsButPins[]
A scan list for all schematic items except pins.
Class SCH_FIND_COLLECTOR_DATA is used as a data container for the associated item found by the SCH_FI...
static const KICAD_T MovableItems[]
A scan list for all movable schematic items.
int GetLibHash() const
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Class SCH_COLLECTOR.
static const KICAD_T CmpFieldValueOnly[]
A scan list for a specific editable field: Value.
void SetLibHash(int aHash)
wxPoint GetPosition() const
SCH_ITEM * GetParent() const
bool IsDraggableJunction() const
Function IsDraggableJunction tests to see if the collected items form a draggable junction...
void SetForceSearch(bool doSearch=true)
SCH_FIND_COLLECTOR_DATA GetFindData(int aIndex)
Function GetFindData returns the data associated with the item found at aIndex.
bool IsCorner() const
Function IsCorner tests if the collected items forms as corner of two line segments.
COLLECTOR class definition.
void UpdateIndex()
Function UpdateIndex updates the list index according to the current find and replace criteria...
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...
bool ReplaceItem(SCH_SHEET_PATH *aSheetPath=NULL)
Function ReplaceItem performs a string replace of the item at the current index.
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
static const KICAD_T CmpFieldFootprintOnly[]
A scan list for a specific editable field: Footprint.
Class SCH_SHEET_PATH.
wxPoint m_position
The position in drawing units of the found item.
SCH_FIND_COLLECTOR(const KICAD_T *aScanTypes=SCH_COLLECTOR::AllItems)
Function dump is a helper to dump the items in the find list for debugging purposes.
static const KICAD_T EditableItems[]
A scan list for all editable schematic items.
bool IsNode(bool aIncludePins=true) const
Function IsNode tests if the collected items form a node.
void SetReplaceString(const wxString &aReplaceString)
Update the replace string without changing anything else.
static const KICAD_T DraggableItems[]
A scan list for all draggable schematic items.
SCH_ITEM * m_parent
The parent object if the item found is a child object.
int GetFoundIndex() const
void Collect(SCH_FIND_REPLACE_DATA &aFindReplaceData, SCH_SHEET_PATH *aSheetPath=NULL)
Function Collect scans aSheetPath using this class's Inspector method for items matching aFindReplace...
EDA_ITEM * GetItem(SCH_FIND_COLLECTOR_DATA &aFindData)
Function GetItem returns the item and associated data of the current index.
int m_foundIndex
The current found item list index.
static const KICAD_T CmpFieldReferenceOnly[]
A scan list for a specific editable field: Reference.
Class SCH_FIND_REPLACE_DATA adds missing useful comparison and assignment operators to the wxFindRepl...
static const KICAD_T CopyableItems[]
A scan list for schematic items that can be copied/duplicated.
SEARCH_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
void Collect(SCH_ITEM *aBoard, const KICAD_T aScanList[])
Function Collect scans a BOARD_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:178
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
static const KICAD_T SheetsOnly[]
A scan list for schematic sheet items only.
wxString GetText()
Function GetText()
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 m_forceSearch
A flag to indicate that the schemtic has been modified and a new search must be performed even if the...
bool PassedEnd() const
Function PassedEnd tests if m_foundIndex is beyond the end of the list give the current find/replace ...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
static const KICAD_T OrientableItems[]
A scan list for schematic items that can be mirrored.
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.