KiCad PCB EDA Suite
SCH_REFERENCE Class Reference

SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic. More...

#include <sch_reference_list.h>

Public Member Functions

 SCH_REFERENCE ()
 
 SCH_REFERENCE (SCH_COMPONENT *aComponent, LIB_PART *aLibComponent, const SCH_SHEET_PATH &aSheetPath)
 
SCH_COMPONENTGetComp () const
 
LIB_PARTGetLibPart () 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 ()
 Function Annotate updates the annotation of the component according the the current object state. More...
 
void Split ()
 Function Split attempts 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
 
wxString GetFullRef ()
 

Return reference name with unit altogether

More...
 
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
 Function IsSameInstance returns whether this reference refers to the same component instance (component and sheet) as another. More...
 
bool IsUnitsLocked ()
 

Private Attributes

UTF8 m_Ref
 Component reference prefix, without number (for IC1, this is IC) ) More...
 
SCH_COMPONENTm_RootCmp
 The component associated the reference object. More...
 
LIB_PARTm_Entry
 The source component from a library. More...
 
wxPoint m_CmpPos
 The physical position of the component in schematic used to annotate by X or Y position. More...
 
int m_Unit
 The unit number for components with multiple parts per package. More...
 
wxString m_Value
 The component 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_Uuid
 UUID of the component. More...
 
int m_NumRef
 The numeric part of the reference designator. More...
 
int m_Flag
 

Friends

class SCH_REFERENCE_LIST
 

Detailed Description

SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

This helper is required in a complex hierarchy because a component 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 47 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE() [1/2]

SCH_REFERENCE::SCH_REFERENCE ( )
inline

Definition at line 70 of file sch_reference_list.h.

70  :
71  m_SheetPath()
72  {
73  m_RootCmp = NULL;
74  m_Entry = NULL;
75  m_Unit = 0;
76  m_IsNew = false;
77  m_NumRef = 0;
78  m_Flag = 0;
79  m_SheetNum = 0;
80  }
int m_NumRef
The numeric part of the reference designator.
int m_SheetNum
The sheet number for the reference.
int m_Unit
The unit number for components with multiple parts per package.
#define NULL
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
LIB_PART * m_Entry
The source component from a library.
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
bool m_IsNew
True if not yet annotated.

References m_Entry, m_Flag, m_IsNew, m_NumRef, m_RootCmp, m_SheetNum, m_Unit, and NULL.

◆ SCH_REFERENCE() [2/2]

SCH_REFERENCE::SCH_REFERENCE ( SCH_COMPONENT aComponent,
LIB_PART aLibComponent,
const SCH_SHEET_PATH aSheetPath 
)

Definition at line 664 of file component_references_lister.cpp.

666 {
667  wxASSERT( aComponent != NULL );
668 
669  m_RootCmp = aComponent;
670  m_Entry = aLibPart; // Warning: can be nullptr for orphan components
671  // (i.e. with a symbol library not found)
672  m_Unit = aComponent->GetUnitSelection( &aSheetPath );
673  m_Footprint = aComponent->GetFootprint( &aSheetPath );
674  m_SheetPath = aSheetPath;
675  m_IsNew = false;
676  m_Flag = 0;
677  m_Uuid = aComponent->m_Uuid;
678  m_CmpPos = aComponent->GetPosition();
679  m_SheetNum = 0;
680 
681  if( aComponent->GetRef( &aSheetPath ).IsEmpty() )
682  aComponent->SetRef( &aSheetPath, wxT( "DefRef?" ) );
683 
684  wxString ref = aComponent->GetRef( &aSheetPath );
685  SetRef( ref );
686 
687  m_NumRef = -1;
688 
689  if( aComponent->GetValue( &aSheetPath ).IsEmpty() )
690  aComponent->SetValue( &aSheetPath, wxT( "~" ) );
691 
692  m_Value = aComponent->GetValue( &aSheetPath );
693 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
KIID m_Uuid
UUID of the component.
int m_NumRef
The numeric part of the reference designator.
wxString m_Footprint
The footprint assigned.
const wxString GetValue(const SCH_SHEET_PATH *sheet) const
int m_SheetNum
The sheet number for the reference.
int m_Unit
The unit number for components with multiple parts per package.
#define NULL
const wxString GetFootprint(const SCH_SHEET_PATH *sheet) const
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
LIB_PART * m_Entry
The source component from a library.
wxString m_Value
The component value.
const KIID m_Uuid
Definition: base_struct.h:162
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
wxPoint GetPosition() const override
void SetRef(const wxString &aReference)
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
bool m_IsNew
True if not yet annotated.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.

References SCH_COMPONENT::GetFootprint(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetRef(), SCH_COMPONENT::GetUnitSelection(), SCH_COMPONENT::GetValue(), m_CmpPos, m_Entry, m_Flag, m_Footprint, m_IsNew, m_NumRef, m_RootCmp, m_SheetNum, m_SheetPath, m_Unit, m_Uuid, EDA_ITEM::m_Uuid, m_Value, NULL, SetRef(), SCH_COMPONENT::SetRef(), and SCH_COMPONENT::SetValue().

Member Function Documentation

◆ Annotate()

void SCH_REFERENCE::Annotate ( )

Function Annotate updates the annotation of the component according the the current object state.

Definition at line 696 of file component_references_lister.cpp.

697 {
698  if( m_NumRef < 0 )
699  m_Ref += '?';
700  else
701  m_Ref = TO_UTF8( GetRef() << GetRefNumber() );
702 
706 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
int m_NumRef
The numeric part of the reference designator.
wxString GetRefNumber() const
const char * c_str() const
Definition: utf8.h:107
int m_Unit
The unit number for components with multiple parts per package.
wxString GetRef() const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
void SetUnit(int aUnit)
Change the unit number to aUnit.
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)

References UTF8::c_str(), FROM_UTF8(), GetRef(), GetRefNumber(), m_NumRef, m_Ref, m_RootCmp, m_SheetPath, m_Unit, SCH_COMPONENT::SetRef(), SCH_COMPONENT::SetUnit(), SCH_COMPONENT::SetUnitSelection(), and TO_UTF8.

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

◆ CompareLibName()

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

Definition at line 183 of file sch_reference_list.h.

184  {
186  item.m_RootCmp->GetLibId().GetLibItemName() );
187  }
int compare(const std::string &s) const
Definition: utf8.h:116
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
const LIB_ID & GetLibId() const

References UTF8::compare(), SCH_COMPONENT::GetLibId(), LIB_ID::GetLibItemName(), and m_RootCmp.

Referenced by SCH_REFERENCE_LIST::Annotate().

◆ CompareRef()

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

Definition at line 178 of file sch_reference_list.h.

179  {
180  return m_Ref.compare( item.m_Ref );
181  }
int compare(const std::string &s) const
Definition: utf8.h:116
UTF8 m_Ref
Component 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 173 of file sch_reference_list.h.

174  {
175  return m_Value.Cmp( item.m_Value );
176  }
wxString m_Value
The component value.

References m_Value.

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

◆ GetComp()

◆ GetFootprint()

const wxString SCH_REFERENCE::GetFootprint ( ) const
inline

Definition at line 99 of file sch_reference_list.h.

99 { return m_Footprint; }
wxString m_Footprint
The footprint assigned.

References m_Footprint.

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

◆ GetFullRef()

wxString SCH_REFERENCE::GetFullRef ( )
inline

Return reference name with unit altogether

Definition at line 149 of file sch_reference_list.h.

150  {
151  if( GetComp()->GetUnitCount() > 1 )
152  return GetRef() + LIB_PART::SubReference( GetUnit() );
153  else
154  return GetRef();
155  }
SCH_COMPONENT * GetComp() const
int GetUnit() const
wxString GetRef() const
static wxString SubReference(int aUnit, bool aAddSeparator=true)

References GetComp(), GetRef(), GetUnit(), and LIB_PART::SubReference().

Referenced by BACK_ANNOTATE::applyChangelist().

◆ GetLibPart()

LIB_PART* SCH_REFERENCE::GetLibPart ( ) const
inline

Definition at line 87 of file sch_reference_list.h.

87 { return m_Entry; }
LIB_PART * m_Entry
The source component from a library.

References m_Entry.

Referenced by GetRefNumber().

◆ GetPath()

const wxString SCH_REFERENCE::GetPath ( ) const
inline

Definition at line 104 of file sch_reference_list.h.

105  {
107  }
wxString AsString() const
Definition: common.cpp:165
wxString PathAsString() const
Function PathAsString the path uses the time stamps which do not changes even when editing sheet para...
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
const KIID m_Uuid
Definition: base_struct.h:162
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.

References KIID::AsString(), m_RootCmp, m_SheetPath, EDA_ITEM::m_Uuid, and SCH_SHEET_PATH::PathAsString().

◆ GetRef()

◆ GetRefNumber()

wxString SCH_REFERENCE::GetRefNumber ( ) const
inline

Definition at line 157 of file sch_reference_list.h.

158  {
159  wxString ref;
160 
161  if( m_NumRef < 0 )
162  return wxT( "?" );
163 
164  // To avoid a risk of duplicate, for power components
165  // the ref number is 0nnn instead of nnn.
166  // Just because sometimes only power components are annotated
167  if( GetLibPart() && GetLibPart()->IsPower() )
168  ref = wxT( "0" );
169 
170  return ref << m_NumRef;
171  }
int m_NumRef
The numeric part of the reference designator.
LIB_PART * 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

Definition at line 143 of file sch_reference_list.h.

144  {
145  return m_Ref.c_str();
146  }
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
const char * c_str() const
Definition: utf8.h:107

References UTF8::c_str(), and m_Ref.

Referenced by Split().

◆ GetSheetPath() [1/2]

const SCH_SHEET_PATH& SCH_REFERENCE::GetSheetPath ( ) const
inline

◆ GetSheetPath() [2/2]

SCH_SHEET_PATH& SCH_REFERENCE::GetSheetPath ( )
inline

Definition at line 91 of file sch_reference_list.h.

91 { return m_SheetPath; }
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.

References m_SheetPath.

◆ GetUnit()

int SCH_REFERENCE::GetUnit ( ) const
inline

Definition at line 93 of file sch_reference_list.h.

93 { return m_Unit; }
int m_Unit
The unit number for components with multiple parts per package.

References m_Unit.

Referenced by buildFullReference(), CollectOtherUnits(), GetFullRef(), and SCH_EDITOR_CONTROL::updatePastedInstances().

◆ GetValue()

const wxString SCH_REFERENCE::GetValue ( ) const
inline

Definition at line 96 of file sch_reference_list.h.

96 { return m_Value; }
wxString m_Value
The component value.

References m_Value.

Referenced by BACK_ANNOTATE::applyChangelist(), and SCH_EDITOR_CONTROL::updatePastedInstances().

◆ IsSameInstance()

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

Function IsSameInstance returns whether this reference refers to the same component instance (component and sheet) as another.

Definition at line 194 of file sch_reference_list.h.

195  {
196  // JEY TODO: should this be checking unit as well?
197  return GetComp() == other.GetComp()
198  && GetSheetPath().Path() == other.GetSheetPath().Path();
199  }
const SCH_SHEET_PATH & GetSheetPath() const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_COMPONENT * GetComp() const

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

Referenced by SCH_REFERENCE_LIST::Annotate().

◆ IsUnitsLocked()

bool SCH_REFERENCE::IsUnitsLocked ( )
inline

Definition at line 201 of file sch_reference_list.h.

202  {
203  return m_Entry->UnitsLocked();
204  }
LIB_PART * m_Entry
The source component from a library.
bool UnitsLocked() const
Check whether part units are interchangeable.

References m_Entry, and LIB_PART::UnitsLocked().

Referenced by Split().

◆ SetFootprint()

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

Definition at line 100 of file sch_reference_list.h.

100 { m_Footprint = aFP; }
wxString m_Footprint
The footprint assigned.

References m_Footprint.

◆ SetRef()

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

Definition at line 128 of file sch_reference_list.h.

129  {
130  m_Ref = aReference;
131  }
UTF8 m_Ref
Component 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 138 of file sch_reference_list.h.

139  {
140  m_Ref = aReference;
141  }
UTF8 m_Ref
Component 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 102 of file sch_reference_list.h.

102 { m_SheetNum = aSheetNumber; }
int m_SheetNum
The sheet number for the reference.

References m_SheetNum.

Referenced by SCH_SHEET_PATH::GetComponents(), and SCH_SHEET_PATH::GetMultiUnitComponents().

◆ SetUnit()

void SCH_REFERENCE::SetUnit ( int  aUnit)
inline

Definition at line 94 of file sch_reference_list.h.

94 { m_Unit = aUnit; }
int m_Unit
The unit number for components with multiple parts per package.

References m_Unit.

◆ SetValue()

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

Definition at line 97 of file sch_reference_list.h.

97 { m_Value = aValue; }
wxString m_Value
The component value.

References m_Value.

◆ Split()

void SCH_REFERENCE::Split ( )

Function Split attempts 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 components with multiple parts per package that are not already annotated, set m_Unit to a max value (0x7FFFFFFF).

Definition at line 709 of file component_references_lister.cpp.

710 {
711  std::string refText = GetRefStr();
712 
713  m_NumRef = -1;
714 
715  int ll = refText.length() - 1;
716 
717  if( refText[ll] == '?' )
718  {
719  m_IsNew = true;
720 
721  if( !IsUnitsLocked() )
722  m_Unit = 0x7FFFFFFF;
723 
724  refText.erase( ll ); // delete last char
725 
726  SetRefStr( refText );
727  }
728  else if( isdigit( refText[ll] ) == 0 )
729  {
730  m_IsNew = true;
731 
732  if( !IsUnitsLocked() )
733  m_Unit = 0x7FFFFFFF;
734  }
735  else
736  {
737  while( ll >= 0 )
738  {
739  if( (refText[ll] <= ' ' ) || isdigit( refText[ll] ) )
740  ll--;
741  else
742  {
743  if( isdigit( refText[ll + 1] ) )
744  {
745  // null terminated C string into cp
746  const char* cp = refText.c_str() + ll + 1;
747 
748  m_NumRef = atoi( cp );
749  }
750 
751  refText.erase( ll+1 ); // delete from ll+1 to end
752  break;
753  }
754  }
755 
756  SetRefStr( refText );
757  }
758 }
int m_NumRef
The numeric part of the reference designator.
void SetRefStr(const std::string &aReference)
int m_Unit
The unit number for components with multiple parts per package.
const char * GetRefStr() const
bool m_IsNew
True if not yet annotated.

References GetRefStr(), IsUnitsLocked(), m_IsNew, m_NumRef, m_Unit, and SetRefStr().

Friends And Related Function Documentation

◆ SCH_REFERENCE_LIST

friend class SCH_REFERENCE_LIST
friend

Definition at line 66 of file sch_reference_list.h.

Member Data Documentation

◆ m_CmpPos

wxPoint SCH_REFERENCE::m_CmpPos
private

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

Definition at line 53 of file sch_reference_list.h.

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

◆ m_Entry

LIB_PART* SCH_REFERENCE::m_Entry
private

The source component from a library.

Definition at line 52 of file sch_reference_list.h.

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

◆ m_Flag

int SCH_REFERENCE::m_Flag
private

◆ m_Footprint

wxString SCH_REFERENCE::m_Footprint
private

The footprint assigned.

Definition at line 58 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 60 of file sch_reference_list.h.

Referenced by SCH_REFERENCE(), and Split().

◆ m_NumRef

int SCH_REFERENCE::m_NumRef
private

The numeric part of the reference designator.

Definition at line 63 of file sch_reference_list.h.

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

◆ m_Ref

UTF8 SCH_REFERENCE::m_Ref
private

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

Definition at line 50 of file sch_reference_list.h.

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

◆ m_RootCmp

SCH_COMPONENT* SCH_REFERENCE::m_RootCmp
private

The component associated the reference object.

Definition at line 51 of file sch_reference_list.h.

Referenced by Annotate(), CompareLibName(), GetComp(), GetPath(), 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 59 of file sch_reference_list.h.

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

◆ m_Unit

int SCH_REFERENCE::m_Unit
private

The unit number for components with multiple parts per package.

Definition at line 55 of file sch_reference_list.h.

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

◆ m_Uuid

◆ m_Value

wxString SCH_REFERENCE::m_Value
private

The component value.

Definition at line 57 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: