KiCad PCB EDA Suite
SCH_REFERENCE Class Reference

A helper to define a symbol's reference designator in a schematic. More...

#include <sch_reference_list.h>

Public Member Functions

 SCH_REFERENCE ()
 
 SCH_REFERENCE (SCH_SYMBOL *aSymbol, LIB_SYMBOL *aLibSymbol, const SCH_SHEET_PATH &aSheetPath)
 
SCH_SYMBOLGetSymbol () const
 
LIB_SYMBOLGetLibPart () const
 
const SCH_SHEET_PATHGetSheetPath () const
 
SCH_SHEET_PATHGetSheetPath ()
 
int GetUnit () const
 
void SetUnit (int aUnit)
 
const wxString GetValue () const
 
void SetValue (const wxString &aValue)
 
const wxString GetFootprint () const
 
void SetFootprint (const wxString &aFP)
 
void SetSheetNumber (int aSheetNumber)
 
const wxString GetPath () const
 
void Annotate ()
 Update the annotation of the symbol according the current object state. More...
 
void Split ()
 Attempt to split the reference designator into a name (U) and number (1). More...
 
void SetRef (const wxString &aReference)
 
wxString GetRef () const
 
void SetRefStr (const std::string &aReference)
 
const char * GetRefStr () const
 Return reference name with unit altogether. More...
 
wxString GetFullRef () const
 
wxString GetRefNumber () const
 
int CompareValue (const SCH_REFERENCE &item) const
 
int CompareRef (const SCH_REFERENCE &item) const
 
int CompareLibName (const SCH_REFERENCE &item) const
 
bool IsSameInstance (const SCH_REFERENCE &other) const
 Return whether this reference refers to the same symbol instance (symbol and sheet) as another. More...
 
bool IsUnitsLocked ()
 

Private Attributes

UTF8 m_ref
 Symbol reference prefix, without number (for IC1, this is IC) ) More...
 
SCH_SYMBOLm_rootSymbol
 The symbol associated the reference object. More...
 
LIB_SYMBOLm_libPart
 The source symbol from a library. More...
 
wxPoint m_symbolPos
 The physical position of the symbol in schematic used to annotate by X or Y position. More...
 
int m_unit
 The unit number for symbol with multiple parts per package. More...
 
wxString m_value
 The symbol value. More...
 
wxString m_footprint
 The footprint assigned. More...
 
SCH_SHEET_PATH m_sheetPath
 The sheet path for this reference. More...
 
bool m_isNew
 True if not yet annotated. More...
 
int m_sheetNum
 The sheet number for the reference. More...
 
KIID m_symbolUuid
 UUID of the symbol. More...
 
int m_numRef
 The numeric part of the reference designator. More...
 
int m_flag
 

Friends

class SCH_REFERENCE_LIST
 

Detailed Description

A helper to define a symbol's reference designator in a schematic.

This helper is required in a complex hierarchy because a symbol can be used more than once and its reference depends on the sheet path. This class is used to flatten the schematic hierarchy for annotation, net list generation, and bill of material generation.

Definition at line 45 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE() [1/2]

SCH_REFERENCE::SCH_REFERENCE ( )
inline

Definition at line 48 of file sch_reference_list.h.

48  :
49  m_sheetPath()
50  {
51  m_rootSymbol = nullptr;
52  m_libPart = nullptr;
53  m_unit = 0;
54  m_isNew = false;
55  m_numRef = 0;
56  m_flag = 0;
57  m_sheetNum = 0;
58  }
LIB_SYMBOL * m_libPart
The source symbol from a library.
int m_sheetNum
The sheet number for the reference.
int m_unit
The unit number for symbol with multiple parts per package.
bool m_isNew
True if not yet annotated.
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
int m_numRef
The numeric part of the reference designator.
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.

References m_flag, m_isNew, m_libPart, m_numRef, m_rootSymbol, m_sheetNum, and m_unit.

◆ SCH_REFERENCE() [2/2]

SCH_REFERENCE::SCH_REFERENCE ( SCH_SYMBOL aSymbol,
LIB_SYMBOL aLibSymbol,
const SCH_SHEET_PATH aSheetPath 
)

Definition at line 736 of file component_references_lister.cpp.

738 {
739  wxASSERT( aSymbol != nullptr );
740 
741  m_rootSymbol = aSymbol;
742  m_libPart = aLibSymbol; // Warning: can be nullptr for orphan symbols
743  // (i.e. with a symbol library not found)
744  m_unit = aSymbol->GetUnitSelection( &aSheetPath );
745  m_footprint = aSymbol->GetFootprint( &aSheetPath, true );
746  m_sheetPath = aSheetPath;
747  m_isNew = false;
748  m_flag = 0;
749  m_symbolUuid = aSymbol->m_Uuid;
750  m_symbolPos = aSymbol->GetPosition();
751  m_sheetNum = 0;
752 
753  if( aSymbol->GetRef( &aSheetPath ).IsEmpty() )
754  aSymbol->SetRef( &aSheetPath, wxT( "DefRef?" ) );
755 
756  wxString ref = aSymbol->GetRef( &aSheetPath );
757  SetRef( ref );
758 
759  m_numRef = -1;
760 
761  if( aSymbol->GetValue( &aSheetPath, false ).IsEmpty() )
762  aSymbol->SetValue( &aSheetPath, wxT( "~" ) );
763 
764  m_value = aSymbol->GetValue( &aSheetPath, false );
765 }
LIB_SYMBOL * m_libPart
The source symbol from a library.
wxPoint m_symbolPos
The physical position of the symbol in schematic used to annotate by X or Y position.
int m_sheetNum
The sheet number for the reference.
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:594
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:441
int m_unit
The unit number for symbol with multiple parts per package.
bool m_isNew
True if not yet annotated.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:531
wxString m_footprint
The footprint assigned.
KIID m_symbolUuid
UUID of the symbol.
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
Return the instance-specific value for the given sheet path.
Definition: sch_symbol.cpp:573
wxString m_value
The symbol value.
const KIID m_Uuid
Definition: eda_item.h:475
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
int m_numRef
The numeric part of the reference designator.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:481
wxPoint GetPosition() const override
Definition: sch_symbol.h:644
void SetRef(const wxString &aReference)
const wxString GetFootprint(const SCH_SHEET_PATH *sheet, bool aResolve) const
Return the instance-specific footprint assignment for the given sheet path.
Definition: sch_symbol.cpp:624
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.

References SCH_SYMBOL::GetFootprint(), SCH_SYMBOL::GetPosition(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::GetUnitSelection(), SCH_SYMBOL::GetValue(), m_flag, m_footprint, m_isNew, m_libPart, m_numRef, m_rootSymbol, m_sheetNum, m_sheetPath, m_symbolPos, m_symbolUuid, m_unit, EDA_ITEM::m_Uuid, m_value, SetRef(), SCH_SYMBOL::SetRef(), and SCH_SYMBOL::SetValue().

Member Function Documentation

◆ Annotate()

void SCH_REFERENCE::Annotate ( )

Update the annotation of the symbol according the current object state.

Definition at line 768 of file component_references_lister.cpp.

769 {
770  if( m_numRef < 0 )
771  m_ref += '?';
772  else
773  m_ref = TO_UTF8( GetRef() << GetRefNumber() );
774 
778 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:331
wxString GetRefNumber() const
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
Definition: sch_symbol.cpp:547
const char * c_str() const
Definition: utf8.h:102
int m_unit
The unit number for symbol with multiple parts per package.
wxString GetRef() const
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
UTF8 m_ref
Symbol reference prefix, without number (for IC1, this is IC) )
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
int m_numRef
The numeric part of the reference designator.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:481
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.

References UTF8::c_str(), FROM_UTF8(), GetRef(), GetRefNumber(), m_numRef, m_ref, m_rootSymbol, m_sheetPath, m_unit, SCH_SYMBOL::SetRef(), SCH_SYMBOL::SetUnit(), SCH_SYMBOL::SetUnitSelection(), and TO_UTF8.

Referenced by SCH_EDIT_FRAME::AnnotateSymbols().

◆ CompareLibName()

int SCH_REFERENCE::CompareLibName ( const SCH_REFERENCE item) const
inline

Definition at line 140 of file sch_reference_list.h.

141  {
144  }
int compare(const std::string &s) const
Definition: utf8.h:111
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:147

References UTF8::compare(), SCH_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), and m_rootSymbol.

Referenced by SCH_REFERENCE_LIST::Annotate().

◆ CompareRef()

int SCH_REFERENCE::CompareRef ( const SCH_REFERENCE item) const
inline

Definition at line 135 of file sch_reference_list.h.

136  {
137  return m_ref.compare( item.m_ref );
138  }
int compare(const std::string &s) const
Definition: utf8.h:111
UTF8 m_ref
Symbol reference prefix, without number (for IC1, this is IC) )

References UTF8::compare(), and m_ref.

Referenced by SCH_REFERENCE_LIST::sortByRefAndValue(), SCH_REFERENCE_LIST::sortByXPosition(), and SCH_REFERENCE_LIST::sortByYPosition().

◆ CompareValue()

int SCH_REFERENCE::CompareValue ( const SCH_REFERENCE item) const
inline

Definition at line 130 of file sch_reference_list.h.

131  {
132  return m_value.Cmp( item.m_value );
133  }
wxString m_value
The symbol value.

References m_value.

Referenced by SCH_REFERENCE_LIST::Annotate(), and SCH_REFERENCE_LIST::sortByRefAndValue().

◆ GetFootprint()

const wxString SCH_REFERENCE::GetFootprint ( ) const
inline

Definition at line 76 of file sch_reference_list.h.

76 { return m_footprint; }
wxString m_footprint
The footprint assigned.

References m_footprint.

Referenced by BACK_ANNOTATE::applyChangelist(), and ERC_TESTER::TestMultiunitFootprints().

◆ GetFullRef()

wxString SCH_REFERENCE::GetFullRef ( ) const
inline

Definition at line 107 of file sch_reference_list.h.

108  {
109  if( GetSymbol()->GetUnitCount() > 1 )
110  return GetRef() + LIB_SYMBOL::SubReference( GetUnit() );
111  else
112  return GetRef();
113  }
int GetUnit() const
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:444
SCH_SYMBOL * GetSymbol() const
wxString GetRef() const

References GetRef(), GetSymbol(), GetUnit(), and LIB_SYMBOL::SubReference().

Referenced by BACK_ANNOTATE::applyChangelist().

◆ GetLibPart()

LIB_SYMBOL* SCH_REFERENCE::GetLibPart ( ) const
inline

Definition at line 64 of file sch_reference_list.h.

64 { return m_libPart; }
LIB_SYMBOL * m_libPart
The source symbol from a library.

References m_libPart.

Referenced by GetRefNumber().

◆ GetPath()

const wxString SCH_REFERENCE::GetPath ( ) const
inline

Definition at line 81 of file sch_reference_list.h.

82  {
84  }
wxString AsString() const
Definition: kiid.cpp:218
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
const KIID m_Uuid
Definition: eda_item.h:475
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.

References KIID::AsString(), m_rootSymbol, m_sheetPath, EDA_ITEM::m_Uuid, and SCH_SHEET_PATH::PathAsString().

◆ GetRef()

◆ GetRefNumber()

wxString SCH_REFERENCE::GetRefNumber ( ) const
inline

Definition at line 115 of file sch_reference_list.h.

116  {
117  wxString ref;
118 
119  if( m_numRef < 0 )
120  return wxT( "?" );
121 
122  // To avoid a risk of duplicate, for power symbols the ref number is 0nnn instead of nnn.
123  // Just because sometimes only power symbols are annotated
124  if( GetLibPart() && GetLibPart()->IsPower() )
125  ref = wxT( "0" );
126 
127  return ref << m_numRef;
128  }
int m_numRef
The numeric part of the reference designator.
LIB_SYMBOL * GetLibPart() const

References GetLibPart(), and m_numRef.

Referenced by Annotate(), buildFullReference(), FIELDS_EDITOR_GRID_DATA_MODEL::GetValue(), and FIELDS_EDITOR_GRID_DATA_MODEL::unitMatch().

◆ GetRefStr()

const char* SCH_REFERENCE::GetRefStr ( ) const
inline

Return reference name with unit altogether.

Definition at line 104 of file sch_reference_list.h.

References UTF8::c_str(), and m_ref.

Referenced by Split().

◆ GetSheetPath() [1/2]

◆ GetSheetPath() [2/2]

SCH_SHEET_PATH& SCH_REFERENCE::GetSheetPath ( )
inline

Definition at line 68 of file sch_reference_list.h.

68 { return m_sheetPath; }
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.

References m_sheetPath.

◆ GetSymbol()

◆ GetUnit()

int SCH_REFERENCE::GetUnit ( ) const
inline

Definition at line 70 of file sch_reference_list.h.

70 { return m_unit; }
int m_unit
The unit number for symbol with multiple parts per package.

References m_unit.

Referenced by buildFullReference(), CollectOtherUnits(), and GetFullRef().

◆ GetValue()

const wxString SCH_REFERENCE::GetValue ( ) const
inline

Definition at line 73 of file sch_reference_list.h.

73 { return m_value; }
wxString m_value
The symbol value.

References m_value.

Referenced by BACK_ANNOTATE::applyChangelist().

◆ IsSameInstance()

bool SCH_REFERENCE::IsSameInstance ( const SCH_REFERENCE other) const
inline

Return whether this reference refers to the same symbol instance (symbol and sheet) as another.

Definition at line 150 of file sch_reference_list.h.

151  {
152  // Only compare symbol and path.
153  // We may have changed the unit number or the designator but
154  // can still be referencing the same instance.
155  return GetSymbol() == other.GetSymbol()
156  && GetSheetPath().Path() == other.GetSheetPath().Path();
157  }
const SCH_SHEET_PATH & GetSheetPath() const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SYMBOL * GetSymbol() const

References GetSheetPath(), GetSymbol(), and SCH_SHEET_PATH::Path().

Referenced by SCH_REFERENCE_LIST::Annotate().

◆ IsUnitsLocked()

bool SCH_REFERENCE::IsUnitsLocked ( )
inline

Definition at line 159 of file sch_reference_list.h.

160  {
161  if( m_libPart )
162  return m_libPart->UnitsLocked();
163  else
164  return true; // Assume units locked when we don't have a library
165  }
LIB_SYMBOL * m_libPart
The source symbol from a library.
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:241

References m_libPart, and LIB_SYMBOL::UnitsLocked().

◆ SetFootprint()

void SCH_REFERENCE::SetFootprint ( const wxString &  aFP)
inline

Definition at line 77 of file sch_reference_list.h.

77 { m_footprint = aFP; }
wxString m_footprint
The footprint assigned.

References m_footprint.

◆ SetRef()

void SCH_REFERENCE::SetRef ( const wxString &  aReference)
inline

Definition at line 100 of file sch_reference_list.h.

100 { m_ref = aReference; }
UTF8 m_ref
Symbol reference prefix, without number (for IC1, this is IC) )

References m_ref.

Referenced by SCH_REFERENCE().

◆ SetRefStr()

void SCH_REFERENCE::SetRefStr ( const std::string &  aReference)
inline

Definition at line 103 of file sch_reference_list.h.

103 { m_ref = aReference; }
UTF8 m_ref
Symbol reference prefix, without number (for IC1, this is IC) )

References m_ref.

Referenced by Split().

◆ SetSheetNumber()

void SCH_REFERENCE::SetSheetNumber ( int  aSheetNumber)
inline

Definition at line 79 of file sch_reference_list.h.

79 { m_sheetNum = aSheetNumber; }
int m_sheetNum
The sheet number for the reference.

References m_sheetNum.

Referenced by SCH_SHEET_PATH::AppendMultiUnitSymbol(), SCH_SHEET_PATH::AppendSymbol(), and SCH_EDITOR_CONTROL::Paste().

◆ SetUnit()

void SCH_REFERENCE::SetUnit ( int  aUnit)
inline

Definition at line 71 of file sch_reference_list.h.

71 { m_unit = aUnit; }
int m_unit
The unit number for symbol with multiple parts per package.

References m_unit.

◆ SetValue()

void SCH_REFERENCE::SetValue ( const wxString &  aValue)
inline

Definition at line 74 of file sch_reference_list.h.

74 { m_value = aValue; }
wxString m_value
The symbol value.

References m_value.

◆ Split()

void SCH_REFERENCE::Split ( )

Attempt to split the reference designator into a name (U) and number (1).

If the last character is '?' or not a digit, the reference is tagged as not annotated. For symbols with multiple parts per package that are not already annotated, keeps the unit number the same. E.g. U?A or U?B

Definition at line 781 of file component_references_lister.cpp.

782 {
783  std::string refText = GetRefStr();
784 
785  m_numRef = -1;
786 
787  int ll = refText.length() - 1;
788 
789  if( refText[ll] == '?' )
790  {
791  m_isNew = true;
792 
793  refText.erase( ll ); // delete last char
794 
795  SetRefStr( refText );
796  }
797  else if( isdigit( refText[ll] ) == 0 )
798  {
799  m_isNew = true;
800  }
801  else
802  {
803  while( ll >= 0 )
804  {
805  if( (refText[ll] <= ' ' ) || isdigit( refText[ll] ) )
806  ll--;
807  else
808  {
809  if( isdigit( refText[ll + 1] ) )
810  {
811  // null terminated C string into cp
812  const char* cp = refText.c_str() + ll + 1;
813 
814  m_numRef = atoi( cp );
815  }
816 
817  refText.erase( ll+1 ); // delete from ll+1 to end
818  break;
819  }
820  }
821 
822  SetRefStr( refText );
823  }
824 }
void SetRefStr(const std::string &aReference)
bool m_isNew
True if not yet annotated.
const char * GetRefStr() const
Return reference name with unit altogether.
int m_numRef
The numeric part of the reference designator.

References GetRefStr(), m_isNew, m_numRef, and SetRefStr().

Referenced by SCH_REFERENCE_LIST::Annotate().

Friends And Related Function Documentation

◆ SCH_REFERENCE_LIST

friend class SCH_REFERENCE_LIST
friend

Definition at line 168 of file sch_reference_list.h.

Member Data Documentation

◆ m_flag

int SCH_REFERENCE::m_flag
private

Definition at line 185 of file sch_reference_list.h.

Referenced by SCH_REFERENCE().

◆ m_footprint

wxString SCH_REFERENCE::m_footprint
private

The footprint assigned.

Definition at line 179 of file sch_reference_list.h.

Referenced by GetFootprint(), SCH_REFERENCE(), and SetFootprint().

◆ m_isNew

bool SCH_REFERENCE::m_isNew
private

True if not yet annotated.

Definition at line 181 of file sch_reference_list.h.

Referenced by SCH_REFERENCE_LIST::Annotate(), SCH_REFERENCE_LIST::ReannotateDuplicates(), SCH_REFERENCE(), and Split().

◆ m_libPart

LIB_SYMBOL* SCH_REFERENCE::m_libPart
private

The source symbol from a library.

Definition at line 173 of file sch_reference_list.h.

Referenced by GetLibPart(), IsUnitsLocked(), and SCH_REFERENCE().

◆ m_numRef

int SCH_REFERENCE::m_numRef
private

The numeric part of the reference designator.

Definition at line 184 of file sch_reference_list.h.

Referenced by Annotate(), GetRefNumber(), SCH_REFERENCE(), and Split().

◆ m_ref

UTF8 SCH_REFERENCE::m_ref
private

Symbol reference prefix, without number (for IC1, this is IC) )

Definition at line 171 of file sch_reference_list.h.

Referenced by Annotate(), CompareRef(), GetRef(), GetRefStr(), SetRef(), and SetRefStr().

◆ m_rootSymbol

SCH_SYMBOL* SCH_REFERENCE::m_rootSymbol
private

The symbol associated the reference object.

Definition at line 172 of file sch_reference_list.h.

Referenced by Annotate(), CompareLibName(), GetPath(), GetSymbol(), and SCH_REFERENCE().

◆ m_sheetNum

int SCH_REFERENCE::m_sheetNum
private

◆ m_sheetPath

SCH_SHEET_PATH SCH_REFERENCE::m_sheetPath
private

The sheet path for this reference.

Definition at line 180 of file sch_reference_list.h.

Referenced by Annotate(), GetPath(), GetSheetPath(), SCH_REFERENCE(), and SCH_REFERENCE_LIST::sortByTimeStamp().

◆ m_symbolPos

wxPoint SCH_REFERENCE::m_symbolPos
private

The physical position of the symbol in schematic used to annotate by X or Y position.

Definition at line 174 of file sch_reference_list.h.

Referenced by SCH_REFERENCE(), SCH_REFERENCE_LIST::sortByRefAndValue(), SCH_REFERENCE_LIST::sortByXPosition(), and SCH_REFERENCE_LIST::sortByYPosition().

◆ m_symbolUuid

◆ m_unit

int SCH_REFERENCE::m_unit
private

The unit number for symbol with multiple parts per package.

Definition at line 176 of file sch_reference_list.h.

Referenced by Annotate(), SCH_REFERENCE_LIST::Annotate(), GetUnit(), SCH_REFERENCE(), SetUnit(), SCH_REFERENCE_LIST::sortByRefAndValue(), and SCH_REFERENCE_LIST::sortByReferenceOnly().

◆ m_value

wxString SCH_REFERENCE::m_value
private

The symbol value.

Definition at line 178 of file sch_reference_list.h.

Referenced by CompareValue(), GetValue(), SCH_REFERENCE(), and SetValue().


The documentation for this class was generated from the following files: