KiCad PCB EDA Suite
sch_reference_list.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) 1992-2011 jean-pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
5  * Copyright (C) 1992-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2015 KiCad Developers, see authors.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
31 #ifndef _SCH_REFERENCE_LIST_H_
32 #define _SCH_REFERENCE_LIST_H_
33 
34 
35 #include <macros.h>
36 
37 #include <class_libentry.h>
38 #include <sch_sheet_path.h>
39 #include <sch_component.h>
40 #include <sch_text.h>
41 
42 #include <map>
43 
44 class SCH_REFERENCE;
45 class SCH_REFERENCE_LIST;
46 
56 {
58  UTF8 m_Ref; // it's private, use the accessors please
62  int m_Unit;
66  bool m_IsNew;
67  int m_SheetNum;
68  time_t m_TimeStamp;
70  int m_NumRef;
72  int m_Flag;
73 
74  friend class SCH_REFERENCE_LIST;
75 
76 
77 public:
78 
80  m_SheetPath()
81  {
82  m_RootCmp = NULL;
83  m_Entry = NULL;
84  m_Unit = 0;
85  m_TimeStamp = 0;
86  m_IsNew = false;
87  m_Value = NULL;
88  m_NumRef = 0;
89  m_Flag = 0;
90  m_SheetNum = 0;
91  }
92 
93  SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent,
94  SCH_SHEET_PATH& aSheetPath );
95 
96  SCH_COMPONENT* GetComp() const { return m_RootCmp; }
97 
98  LIB_PART* GetLibPart() const { return m_Entry; }
99 
101 
102  int GetUnit() const { return m_Unit; }
103 
104  void SetSheetNumber( int aSheetNumber ) { m_SheetNum = aSheetNumber; }
105 
110  void Annotate();
111 
119  void Split();
120 
121  /* Some accessors which hide the strategy of how the reference is stored,
122  thereby making it easy to change that strategy.
123  */
124 
125  void SetRef( const wxString& aReference )
126  {
127  m_Ref = aReference;
128  }
129 
130  wxString GetRef() const
131  {
132  return m_Ref;
133  }
134  void SetRefStr( const std::string& aReference )
135  {
136  m_Ref = aReference;
137  }
138  const char* GetRefStr() const
139  {
140  return m_Ref.c_str();
141  }
142 
143  int CompareValue( const SCH_REFERENCE& item ) const
144  {
145  return m_Value->GetText().Cmp( item.m_Value->GetText() );
146  }
147 
148  int CompareRef( const SCH_REFERENCE& item ) const
149  {
150  return m_Ref.compare( item.m_Ref );
151  }
152 
153  int CompareLibName( const SCH_REFERENCE& item ) const
154  {
155  return m_RootCmp->GetLibId().GetLibItemName().compare(
156  item.m_RootCmp->GetLibId().GetLibItemName() );
157  }
158 
164  bool IsSameInstance( const SCH_REFERENCE& other ) const
165  {
166  return GetComp() == other.GetComp() && GetSheetPath().Path() == other.GetSheetPath().Path();
167  }
168 
170  {
171  return m_Entry->UnitsLocked();
172  }
173 };
174 
175 
184 {
185 private:
186  std::vector <SCH_REFERENCE> componentFlatList;
187 
188 public:
192  {
193  }
194 
195  SCH_REFERENCE& operator[]( int aIndex )
196  {
197  return componentFlatList[ aIndex ];
198  }
199 
204  unsigned GetCount()
205  {
206  return componentFlatList.size();
207  }
208 
213  SCH_REFERENCE& GetItem( int aIdx )
214  {
215  return componentFlatList[aIdx];
216  }
217 
223  void AddItem( SCH_REFERENCE& aItem )
224  {
225  componentFlatList.push_back( aItem );
226  }
227 
234  void RemoveItem( unsigned int aIndex );
235 
243 
244  /* Sort functions:
245  * Sort functions are used to sort components for annotation or BOM generation.
246  * Because sorting depend on we want to do, there are many sort functions.
247  * Note:
248  * When creating BOM, components are fully annotated.
249  * references are something like U3, U5 or R4, R8
250  * When annotating, some or all components are not annotated,
251  * i.e. ref is only U or R, with no number.
252  */
253 
263  {
264  for( unsigned ii = 0; ii < GetCount(); ii++ )
265  componentFlatList[ii].Split();
266  }
267 
276  {
277  /* update the reference numbers */
278  for( unsigned ii = 0; ii < GetCount(); ii++ )
279  {
280  componentFlatList[ii].Annotate();
281  }
282  }
283 
300  void Annotate( bool aUseSheetNum, int aSheetIntervalId, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap );
301 
317  int CheckAnnotation( wxArrayString* aMessageList );
318 
334  {
335  sort( componentFlatList.begin(), componentFlatList.end(), sortByXPosition );
336  }
337 
353  {
354  sort( componentFlatList.begin(), componentFlatList.end(), sortByYPosition );
355  }
356 
363  {
364  sort( componentFlatList.begin(), componentFlatList.end(), sortByTimeStamp );
365  }
366 
383  {
384  sort( componentFlatList.begin(), componentFlatList.end(), sortByRefAndValue );
385  }
386 
399  {
400  sort( componentFlatList.begin(), componentFlatList.end(), sortByReferenceOnly );
401  }
402 
412  int FindUnit( size_t aIndex, int aUnit );
413 
422  void GetRefsInUse( int aIndex, std::vector< int >& aIdList, int aMinRefId );
423 
433  int GetLastReference( int aIndex, int aMinValue );
434 
435 #if defined(DEBUG)
436  void Show( const char* aPrefix = "" )
437  {
438  printf( "%s\n", aPrefix );
439 
440  for( unsigned i=0; i<componentFlatList.size(); ++i )
441  {
442  SCH_REFERENCE& schref = componentFlatList[i];
443 
444  printf( " [%-2d] ref:%-8s num:%-3d lib_part:%s\n",
445  i,
446  schref.m_Ref.c_str(),
447  schref.m_NumRef,
448  TO_UTF8( schref.GetLibPart()->GetName() )
449  );
450  }
451  }
452 #endif
453 
454 private:
455  /* sort functions used to sort componentFlatList
456  */
457 
458  static bool sortByRefAndValue( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
459 
460  static bool sortByXPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
461 
462  static bool sortByYPosition( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
463 
464  static bool sortByTimeStamp( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
465 
466  static bool sortByReferenceOnly( const SCH_REFERENCE& item1, const SCH_REFERENCE& item2 );
467 
479  int CreateFirstFreeRefId( std::vector<int>& aIdList, int aFirstValue );
480 };
481 
482 #endif // _SCH_REFERENCE_LIST_H_
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
const char * GetRefStr() const
void SetSheetNumber(int aSheetNumber)
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
int CompareLibName(const SCH_REFERENCE &item) const
bool UnitsLocked() const
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
void SortByYCoordinate()
Function sortByYCoordinate sorts the list of references by Y position.
SCH_REFERENCE & GetItem(int aIdx)
Function GetItem.
std::vector< SCH_REFERENCE > componentFlatList
void RemoveSubComponentsFromList()
Function RemoveSubComponentsFromList Remove sub components from the list, when multiples parts per pa...
int CompareValue(const SCH_REFERENCE &item) const
void RemoveItem(unsigned int aIndex)
Function RemoveItem removes an item from the list of references.
void Split()
Function Split attempts to split the reference designator into a name (U) and number (1)...
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
int m_NumRef
The numeric part of the reference designator.
time_t m_TimeStamp
The time stamp for the reference.
void AddItem(SCH_REFERENCE &aItem)
Function AddItem adds a SCH_REFERENCE object to the list of references.
int m_SheetNum
The sheet number for the reference.
int CheckAnnotation(wxArrayString *aMessageList)
Function CheckAnnotation check for annotations errors.
bool IsSameInstance(const SCH_REFERENCE &other) const
Function IsSameInstance returns whether this reference refers to the same component instance (compone...
int GetUnit() const
void SortByRefAndValue()
Function SortByRefAndValue sorts the list of references by value.
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
This file contains miscellaneous commonly used macros and functions.
void SetRefStr(const std::string &aReference)
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
void GetRefsInUse(int aIndex, std::vector< int > &aIdList, int aMinRefId)
Function GetRefsInUse adds all the reference designator numbers greater than aMinRefId to aIdList ski...
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
int m_Unit
The unit number for components with multiple parts per package.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void UpdateAnnotation()
function UpdateAnnotation Updates the reference components for the schematic project (or the current ...
void SortByTimeStamp()
Function SortComponentsByTimeStamp sort the flat list by Time Stamp.
int CompareRef(const SCH_REFERENCE &item) const
void SortByXCoordinate()
Function sortByXCoordinate sorts the list of references by X position.
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
EDA_TEXT * m_Value
The component value of the reference.
void Annotate(bool aUseSheetNum, int aSheetIntervalId, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
Function Annotate set the reference designators in the list that have not been annotated.
const wxString & GetName() const
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
static bool sortByRefAndValue(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
Class LIB_ITEM definition.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
LIB_PART * m_Entry
The source component from a library.
void Annotate()
Function Annotate updates the annotation of the component according the the current object state...
int compare(const std::string &s) const
Definition: utf8.h:116
Class LIB_PART defines a library part object.
int FindUnit(size_t aIndex, int aUnit)
Function GetUnit searches the sorted list of components for a another component with the same referen...
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
Class SCH_SHEET_PATH.
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
wxString GetRef() const
Definition the SCH_COMPONENT class for Eeschema.
SCH_REFERENCE & operator[](int aIndex)
void SortByReferenceOnly()
Function SortByReferenceOnly sorts the list of references by reference.
SCH_SHEET_PATH GetSheetPath() const
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1)...
const char * c_str() const
Definition: utf8.h:107
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
const LIB_ID & GetLibId() const
int CreateFirstFreeRefId(std::vector< int > &aIdList, int aFirstValue)
Function CreateFirstFreeRefId searches for the first free reference number in aListId of reference nu...
void SetRef(const wxString &aReference)
LIB_PART * GetLibPart() const
int GetLastReference(int aIndex, int aMinValue)
Function GetLastReference returns the last used (greatest) reference number in the reference list for...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_REFERENCE_LIST()
Constructor.
unsigned GetCount()
Function GetCount.
SCH_COMPONENT * GetComp() const
Implementation of the label properties dialog.
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic...
bool m_IsNew
True if not yet annotated.
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)