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 
134  SCH_ITEM* operator[]( int aIndex ) const
135  {
136  if( (unsigned)aIndex < (unsigned)GetCount() )
137  return (SCH_ITEM*) m_List[ aIndex ];
138 
139  return NULL;
140  }
141 
142  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
143 
153  void Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPosition );
154 
160  bool IsCorner() const;
161 
169  bool IsNode( bool aIncludePins = true ) const;
170 
184  bool IsDraggableJunction() const;
185 };
186 
187 
194 {
197 
199  wxString m_sheetPath;
200 
203 
204 public:
205  SCH_FIND_COLLECTOR_DATA( const wxPoint& aPosition = wxDefaultPosition,
206  const wxString& aSheetPath = wxEmptyString,
207  SCH_ITEM* aParent = NULL )
208  : m_position( aPosition )
209  , m_sheetPath( aSheetPath )
210  , m_parent( aParent )
211  { }
212 
213  wxPoint GetPosition() const { return m_position; }
214 
215  wxString GetSheetPath() const { return m_sheetPath; }
216 
217  SCH_ITEM* GetParent() const { return m_parent; }
218 };
219 
220 
227 {
229  std::vector< SCH_FIND_COLLECTOR_DATA > m_data;
230 
233 
236 
239 
243 
247 
252 #if defined(DEBUG)
253  void dump();
254 #endif
255 
256 public:
257 
262  {
263  SetScanTypes( aScanTypes );
264  m_foundIndex = 0;
265  SetForceSearch( false );
266  m_sheetPath = NULL;
267  m_lib_hash = 0;
268  }
269 
270  void Empty()
271  {
272  m_foundIndex = 0;
274  m_data.clear();
275  }
276 
277  void SetForceSearch( bool doSearch = true ) { m_forceSearch = doSearch; }
278 
279  int GetLibHash() const { return m_lib_hash; }
280  void SetLibHash( int aHash ) { m_lib_hash = aHash; }
281 
282  int GetFoundIndex() const { return m_foundIndex; }
283  void SetFoundIndex( int aIndex )
284  {
285  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
286  }
287 
295  bool PassedEnd() const;
296 
301  void UpdateIndex();
302 
311  SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
312 
323  bool IsSearchRequired( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
324  {
325  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
326  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
327  }
328 
335  wxString GetText();
336 
348 
355  bool ReplaceItem( SCH_SHEET_PATH* aSheetPath = NULL );
356 
357  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
358 
362  void SetReplaceString( const wxString &aReplaceString );
363 
373  void Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, SCH_SHEET_PATH* aSheetPath = NULL );
374 
375  void IncrementIndex() { m_foundIndex += 1; }
376 };
377 
378 
387 {
388 public:
399  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
400 
408  void Collect( SCH_ITEM* aBoard, const KICAD_T aScanList[] );
409 };
410 
411 
412 #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.
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:165
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.