KiCad PCB EDA Suite
SCH_REFERENCE Class Reference

Class 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, SCH_SHEET_PATH &aSheetPath)
 
SCH_COMPONENTGetComp () const
 
LIB_PARTGetLibPart () const
 
SCH_SHEET_PATH GetSheetPath () const
 
int GetUnit () const
 
void SetSheetNumber (int aSheetNumber)
 
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 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...
 
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...
 
timestamp_t m_TimeStamp
 The time stamp for the reference. More...
 
EDA_TEXTm_Value
 The component value of the reference. More...
 
int m_NumRef
 The numeric part of the reference designator. More...
 
int m_Flag
 

Friends

class SCH_REFERENCE_LIST
 

Detailed Description

Class 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 55 of file sch_reference_list.h.

Constructor & Destructor Documentation

SCH_REFERENCE::SCH_REFERENCE ( )
inline

Definition at line 79 of file sch_reference_list.h.

79  :
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  }
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.
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
EDA_TEXT * m_Value
The component value of the reference.
LIB_PART * m_Entry
The source component from a library.
timestamp_t m_TimeStamp
The time stamp for the reference.
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
bool m_IsNew
True if not yet annotated.
SCH_REFERENCE::SCH_REFERENCE ( SCH_COMPONENT aComponent,
LIB_PART aLibComponent,
SCH_SHEET_PATH aSheetPath 
)

Definition at line 670 of file component_references_lister.cpp.

References SCH_COMPONENT::GetField(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetRef(), EDA_TEXT::GetText(), EDA_ITEM::GetTimeStamp(), SCH_COMPONENT::GetUnitSelection(), SCH_COMPONENT::SetRef(), EDA_TEXT::SetText(), and VALUE.

672 {
673  wxASSERT( aComponent != NULL && aLibPart != NULL );
674 
675  m_RootCmp = aComponent;
676  m_Entry = aLibPart;
677  m_Unit = aComponent->GetUnitSelection( &aSheetPath );
678  m_SheetPath = aSheetPath;
679  m_IsNew = false;
680  m_Flag = 0;
681  m_TimeStamp = aComponent->GetTimeStamp();
682  m_CmpPos = aComponent->GetPosition();
683  m_SheetNum = 0;
684 
685  if( aComponent->GetRef( &aSheetPath ).IsEmpty() )
686  aComponent->SetRef( &aSheetPath, wxT( "DefRef?" ) );
687 
688  wxString ref = aComponent->GetRef( &aSheetPath );
689  SetRef( ref );
690 
691  m_NumRef = -1;
692 
693  if( aComponent->GetField( VALUE )->GetText().IsEmpty() )
694  aComponent->GetField( VALUE )->SetText( wxT( "~" ) );
695 
696  m_Value = aComponent->GetField( VALUE );
697 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
int m_NumRef
The numeric part of the reference designator.
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
int m_SheetNum
The sheet number for the reference.
int m_Unit
The unit number for components with multiple parts per package.
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
EDA_TEXT * m_Value
The component value of the reference.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
LIB_PART * m_Entry
The source component from a library.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
timestamp_t m_TimeStamp
The time stamp for the reference.
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
Function GetPosition.
void SetRef(const wxString &aReference)
#define VALUE
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
bool m_IsNew
True if not yet annotated.
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139

Member Function Documentation

void SCH_REFERENCE::Annotate ( )

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

Definition at line 700 of file component_references_lister.cpp.

References FROM_UTF8(), and TO_UTF8.

Referenced by SetSheetNumber(), and SCH_REFERENCE_LIST::UpdateAnnotation().

701 {
702  if( m_NumRef < 0 )
703  m_Ref += '?';
704  else
705  {
706  m_Ref = TO_UTF8( GetRef() << GetRefNumber() );
707  }
708 
712 }
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:53
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
int m_NumRef
The numeric part of the reference designator.
void SetUnitSelection(SCH_SHEET_PATH *aSheet, int aUnitSelection)
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
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.
wxString GetRef() const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
const char * c_str() const
Definition: utf8.h:107
wxString GetRefNumber() const
int SCH_REFERENCE::CompareLibName ( const SCH_REFERENCE item) const
inline

Definition at line 166 of file sch_reference_list.h.

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

Referenced by SCH_REFERENCE_LIST::Annotate().

167  {
169  item.m_RootCmp->GetLibId().GetLibItemName() );
170  }
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
int compare(const std::string &s) const
Definition: utf8.h:116
const LIB_ID & GetLibId() const
int SCH_REFERENCE::CompareRef ( const SCH_REFERENCE item) const
inline

Definition at line 161 of file sch_reference_list.h.

References UTF8::compare(), and m_Ref.

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

162  {
163  return m_Ref.compare( item.m_Ref );
164  }
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
int compare(const std::string &s) const
Definition: utf8.h:116
int SCH_REFERENCE::CompareValue ( const SCH_REFERENCE item) const
inline

Definition at line 156 of file sch_reference_list.h.

References EDA_TEXT::GetText(), and m_Value.

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

157  {
158  return m_Value->GetText().Cmp( item.m_Value->GetText() );
159  }
EDA_TEXT * m_Value
The component value of the reference.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
SCH_COMPONENT* SCH_REFERENCE::GetComp ( ) const
inline

Definition at line 96 of file sch_reference_list.h.

References m_RootCmp.

Referenced by DIALOG_EDIT_COMPONENTS_LIBID::initDlg(), IsSameInstance(), FIELDS_EDITOR_GRID_DATA_MODEL::match(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick(), and TestMultiunitFootprints().

96 { return m_RootCmp; }
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
LIB_PART* SCH_REFERENCE::GetLibPart ( ) const
inline

Definition at line 98 of file sch_reference_list.h.

References m_Entry.

Referenced by GetRefNumber(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick(), and SCH_REFERENCE_LIST::SortByReferenceOnly().

98 { return m_Entry; }
LIB_PART * m_Entry
The source component from a library.
wxString SCH_REFERENCE::GetRef ( ) const
inline
wxString SCH_REFERENCE::GetRefNumber ( ) const
inline

Definition at line 143 of file sch_reference_list.h.

References GetLibPart(), and m_NumRef.

Referenced by FIELDS_EDITOR_GRID_DATA_MODEL::match(), and FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows().

144  {
145  wxString ref;
146 
147  // To avoid a risk of duplicate, for power components
148  // the ref number is 0nnn instead of nnn.
149  // Just because sometimes only power components are annotated
150  if( GetLibPart() && GetLibPart()->IsPower() )
151  ref = wxT( "0" );
152 
153  return ref << m_NumRef;
154  }
int m_NumRef
The numeric part of the reference designator.
LIB_PART * GetLibPart() const
const char* SCH_REFERENCE::GetRefStr ( ) const
inline

Definition at line 138 of file sch_reference_list.h.

References UTF8::c_str().

139  {
140  return m_Ref.c_str();
141  }
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
const char * c_str() const
Definition: utf8.h:107
SCH_SHEET_PATH SCH_REFERENCE::GetSheetPath ( ) const
inline

Definition at line 100 of file sch_reference_list.h.

References m_SheetPath.

Referenced by DIALOG_EDIT_COMPONENTS_LIBID::initDlg(), IsSameInstance(), and TestMultiunitFootprints().

100 { return m_SheetPath; }
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
int SCH_REFERENCE::GetUnit ( ) const
inline

Definition at line 102 of file sch_reference_list.h.

References m_Unit.

Referenced by DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick().

102 { return m_Unit; }
int m_Unit
The unit number for components with multiple parts per package.
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 177 of file sch_reference_list.h.

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

Referenced by SCH_REFERENCE_LIST::Annotate().

178  {
179  return GetComp() == other.GetComp() && GetSheetPath().Path() == other.GetSheetPath().Path();
180  }
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
SCH_SHEET_PATH GetSheetPath() const
SCH_COMPONENT * GetComp() const
bool SCH_REFERENCE::IsUnitsLocked ( )
inline

Definition at line 182 of file sch_reference_list.h.

References LIB_PART::UnitsLocked().

183  {
184  return m_Entry->UnitsLocked();
185  }
bool UnitsLocked() const
Check whether part units are interchangeable.
LIB_PART * m_Entry
The source component from a library.
void SCH_REFERENCE::SetRef ( const wxString &  aReference)
inline

Definition at line 125 of file sch_reference_list.h.

126  {
127  m_Ref = aReference;
128  }
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
void SCH_REFERENCE::SetRefStr ( const std::string &  aReference)
inline

Definition at line 134 of file sch_reference_list.h.

135  {
136  m_Ref = aReference;
137  }
UTF8 m_Ref
Component reference prefix, without number (for IC1, this is IC) )
void SCH_REFERENCE::SetSheetNumber ( int  aSheetNumber)
inline

Definition at line 104 of file sch_reference_list.h.

References Annotate(), and Split().

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

104 { m_SheetNum = aSheetNumber; }
int m_SheetNum
The sheet number for the reference.
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 715 of file component_references_lister.cpp.

Referenced by SetSheetNumber(), and SCH_REFERENCE_LIST::SplitReferences().

716 {
717  std::string refText = GetRefStr();
718 
719  m_NumRef = -1;
720 
721  int ll = refText.length() - 1;
722 
723  if( refText[ll] == '?' )
724  {
725  m_IsNew = true;
726 
727  if( !IsUnitsLocked() )
728  m_Unit = 0x7FFFFFFF;
729 
730  refText.erase( ll ); // delete last char
731 
732  SetRefStr( refText );
733  }
734  else if( isdigit( refText[ll] ) == 0 )
735  {
736  m_IsNew = true;
737 
738  if( !IsUnitsLocked() )
739  m_Unit = 0x7FFFFFFF;
740  }
741  else
742  {
743  while( ll >= 0 )
744  {
745  if( (refText[ll] <= ' ' ) || isdigit( refText[ll] ) )
746  ll--;
747  else
748  {
749  if( isdigit( refText[ll + 1] ) )
750  {
751  // null terminated C string into cp
752  const char* cp = refText.c_str() + ll + 1;
753 
754  m_NumRef = atoi( cp );
755  }
756 
757  refText.erase( ll+1 ); // delete from ll+1 to end
758  break;
759  }
760  }
761 
762  SetRefStr( refText );
763  }
764 }
const char * GetRefStr() const
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.
bool m_IsNew
True if not yet annotated.

Friends And Related Function Documentation

friend class SCH_REFERENCE_LIST
friend

Definition at line 74 of file sch_reference_list.h.

Member Data Documentation

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 61 of file sch_reference_list.h.

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

LIB_PART* SCH_REFERENCE::m_Entry
private

The source component from a library.

Definition at line 60 of file sch_reference_list.h.

Referenced by GetLibPart().

int SCH_REFERENCE::m_Flag
private

Definition at line 72 of file sch_reference_list.h.

bool SCH_REFERENCE::m_IsNew
private

True if not yet annotated.

Definition at line 66 of file sch_reference_list.h.

int SCH_REFERENCE::m_NumRef
private

The numeric part of the reference designator.

Definition at line 71 of file sch_reference_list.h.

Referenced by GetRefNumber(), and SCH_REFERENCE_LIST::SortByReferenceOnly().

UTF8 SCH_REFERENCE::m_Ref
private

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

Definition at line 58 of file sch_reference_list.h.

Referenced by CompareRef(), GetRef(), and SCH_REFERENCE_LIST::SortByReferenceOnly().

SCH_COMPONENT* SCH_REFERENCE::m_RootCmp
private

The component associated the reference object.

Definition at line 59 of file sch_reference_list.h.

Referenced by CompareLibName(), GetComp(), and SCH_REFERENCE_LIST::sortByReferenceOnly().

int SCH_REFERENCE::m_SheetNum
private

The sheet number for the reference.

Definition at line 67 of file sch_reference_list.h.

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

SCH_SHEET_PATH SCH_REFERENCE::m_SheetPath
private

The sheet path for this reference.

Definition at line 65 of file sch_reference_list.h.

Referenced by GetSheetPath(), and SCH_REFERENCE_LIST::sortByTimeStamp().

timestamp_t SCH_REFERENCE::m_TimeStamp
private
int SCH_REFERENCE::m_Unit
private

The unit number for components with multiple parts per package.

Definition at line 63 of file sch_reference_list.h.

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

EDA_TEXT* SCH_REFERENCE::m_Value
private

The component value of the reference.

It is the same for all instances.

Definition at line 69 of file sch_reference_list.h.

Referenced by CompareValue().


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