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 AUTHORS.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 <collector.h>
34 #include <sch_item_struct.h>
35 #include <sch_sheet_path.h>
37 
38 
42 class SCH_COLLECTOR : public COLLECTOR
43 {
44 public:
45 
49  static const KICAD_T AllItems[];
50 
54  static const KICAD_T EditableItems[];
55 
59  static const KICAD_T CmpFieldValueOnly[];
60 
65 
70 
74  static const KICAD_T MovableItems[];
75 
79  static const KICAD_T DraggableItems[];
80 
84  static const KICAD_T RotatableItems[];
85 
89  static const KICAD_T ParentItems[];
90 
94  static const KICAD_T AllItemsButPins[];
95 
99  static const KICAD_T ComponentsOnly[];
100 
104  static const KICAD_T SheetsOnly[];
105 
110 
114  static const KICAD_T OrientableItems[];
115 
119  static const KICAD_T CopyableItems[];
120 
124  static const KICAD_T DoubleClickItems[];
125 
130  {
131  SetScanTypes( aScanTypes );
132  }
133 
140  SCH_ITEM* operator[]( int aIndex ) const
141  {
142  if( (unsigned)aIndex < (unsigned)GetCount() )
143  return (SCH_ITEM*) m_List[ aIndex ];
144 
145  return NULL;
146  }
147 
148  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
149 
159  void Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPosition );
160 
166  bool IsCorner() const;
167 
175  bool IsNode( bool aIncludePins = true ) const;
176 
190  bool IsDraggableJunction() const;
191 };
192 
193 
200 {
203 
205  wxString m_sheetPath;
206 
209 
210 public:
211  SCH_FIND_COLLECTOR_DATA( const wxPoint& aPosition = wxDefaultPosition,
212  const wxString& aSheetPath = wxEmptyString,
213  SCH_ITEM* aParent = NULL )
214  : m_position( aPosition )
215  , m_sheetPath( aSheetPath )
216  , m_parent( aParent )
217  { }
218 
219  wxPoint GetPosition() const { return m_position; }
220 
221  wxString GetSheetPath() const { return m_sheetPath; }
222 
223  SCH_ITEM* GetParent() const { return m_parent; }
224 };
225 
226 
233 {
235  std::vector< SCH_FIND_COLLECTOR_DATA > m_data;
236 
239 
242 
245 
248 
252 
256 
261 #if defined(DEBUG)
262  void dump();
263 #endif
264 
265 public:
266 
271  {
272  SetScanTypes( aScanTypes );
273  m_foundIndex = 0;
274  SetForceSearch( false );
275  m_currentSheetPath = NULL;
276  m_lib_hash = 0;
277  }
278 
279  void Empty()
280  {
281  m_foundIndex = 0;
283  m_data.clear();
284  }
285 
286  SCH_ITEM* GetItem( int ndx ) const;
287  SCH_ITEM* operator[]( int ndx ) const;
288 
289  void SetForceSearch( bool doSearch = true ) { m_forceSearch = doSearch; }
290 
291  int GetLibHash() const { return m_lib_hash; }
292  void SetLibHash( int aHash ) { m_lib_hash = aHash; }
293 
294  int GetFoundIndex() const { return m_foundIndex; }
295  void SetFoundIndex( int aIndex )
296  {
297  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
298  }
299 
307  bool PassedEnd() const;
308 
313  void UpdateIndex();
314 
323  SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
324 
335  bool IsSearchRequired( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
336  {
337  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
338  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
339  }
340 
347  wxString GetText();
348 
359  EDA_ITEM* GetItem( SCH_FIND_COLLECTOR_DATA& aFindData );
360 
367  bool ReplaceItem( SCH_SHEET_PATH* aSheetPath = NULL );
368 
369  SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override;
370 
374  void SetReplaceString( const wxString &aReplaceString );
375 
385  void Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, SCH_SHEET_PATH* aSheetPath = NULL );
386 
387  void IncrementIndex() { m_foundIndex += 1; }
388 };
389 
390 
399 {
400 public:
411  SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override;
412 
420  void Collect( SCH_ITEM* aBoard, const KICAD_T aScanList[] );
421 };
422 
423 
424 #endif // _SCH_COLLECTORS_H_
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:115
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:106
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...
COLLECTOR class definition.
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)
Base schematic object class definition.
static const KICAD_T DoubleClickItems[]
A scan list for schematic items that react to a double-click.
SCH_SHEET_PATH * m_currentSheetPath
The path of the sheet currently being iterated over.
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...
Definition: collector.h:207
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...
void Collect(SCH_ITEM *aItem, const KICAD_T aFilterList[], const wxPoint &aPosition)
Function Collect scans a SCH_ITEM using this class&#39;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
SCH_SHEET_PATHS m_sheetPaths
The paths of the all the sheets in the collector.
bool IsDraggableJunction() const
Function IsDraggableJunction tests to see if the collected items form a draggable junction...
void SetForceSearch(bool doSearch=true)
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
bool IsCorner() const
Function IsCorner tests if the collected items forms as corner of two line segments.
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...
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.
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
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.
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
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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
Definition: collector.h:55
static const KICAD_T SheetsOnly[]
A scan list for schematic sheet items only.
SEARCH_RESULT
Definition: base_struct.h:64
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
bool m_forceSearch
A flag to indicate that the schemtic has been modified and a new search must be performed even if the...
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.