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 
124  {
125  SetScanTypes( aScanTypes );
126  }
127 
135  SCH_ITEM* operator[]( int aIndex ) const
136  {
137  if( (unsigned)aIndex < (unsigned)GetCount() )
138  return (SCH_ITEM*) m_List[ aIndex ];
139 
140  return NULL;
141  }
142 
143  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
144 
154  void Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPosition );
155 
161  bool IsCorner() const;
162 
170  bool IsNode( bool aIncludePins = true ) const;
171 
185  bool IsDraggableJunction() const;
186 };
187 
188 
195 {
198 
200  wxString m_sheetPath;
201 
204 
205 public:
206  SCH_FIND_COLLECTOR_DATA( const wxPoint& aPosition = wxDefaultPosition,
207  const wxString& aSheetPath = wxEmptyString,
208  SCH_ITEM* aParent = NULL )
209  : m_position( aPosition )
210  , m_sheetPath( aSheetPath )
211  , m_parent( aParent )
212  { }
213 
214  wxPoint GetPosition() const { return m_position; }
215 
216  wxString GetSheetPath() const { return m_sheetPath; }
217 
218  SCH_ITEM* GetParent() const { return m_parent; }
219 };
220 
221 
228 {
230  std::vector< SCH_FIND_COLLECTOR_DATA > m_data;
231 
234 
237 
240 
244 
248 
253 #if defined(DEBUG)
254  void dump();
255 #endif
256 
257 public:
258 
263  {
264  SetScanTypes( aScanTypes );
265  m_foundIndex = 0;
266  SetForceSearch( false );
267  m_sheetPath = NULL;
268  m_lib_hash = 0;
269  }
270 
271  void Empty()
272  {
273  m_foundIndex = 0;
275  m_data.clear();
276  }
277 
278  void SetForceSearch( bool doSearch = true ) { m_forceSearch = doSearch; }
279 
280  int GetLibHash() const { return m_lib_hash; }
281  void SetLibHash( int aHash ) { m_lib_hash = aHash; }
282 
283  int GetFoundIndex() const { return m_foundIndex; }
284  void SetFoundIndex( int aIndex )
285  {
286  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
287  }
288 
296  bool PassedEnd() const;
297 
302  void UpdateIndex();
303 
312  SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
313 
324  bool IsSearchRequired( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
325  {
326  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
327  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
328  }
329 
336  wxString GetText();
337 
349 
356  bool ReplaceItem( SCH_SHEET_PATH* aSheetPath = NULL );
357 
358  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
359 
363  void SetReplaceString( const wxString &aReplaceString );
364 
374  void Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, SCH_SHEET_PATH* aSheetPath = NULL );
375 
376  void IncrementIndex() { m_foundIndex += 1; }
377 };
378 
379 
388 {
389 public:
400  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
401 
409  void Collect( SCH_ITEM* aBoard, const KICAD_T aScanList[] );
410 };
411 
412 
413 #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
Operator [] overloads COLLECTOR::operator[](int) to return a SCH_ITEM* instead of an EDA_ITEM* type...
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.
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:90
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:151
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:68
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.