Keep LIB_ID and LIB_PART name/library in sync

Updates LIB_ID::LibItemName field when a part is renamed and LIB_PART
name when a new LIB_ID is set.

Similarly, LIB_ID::LibNickName field is updated when a library set, but
there is no easy way to assign library when LIB_ID::LibNickName is
modified.
This commit is contained in:
Maciej Suminski 2017-11-12 20:54:04 +01:00
parent 4c4f5ae962
commit 445ac50588
2 changed files with 29 additions and 6 deletions

View File

@ -180,7 +180,6 @@ LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
EDA_ITEM( LIB_PART_T ),
m_me( this, null_deleter() )
{
m_library = aLibrary;
m_dateModified = 0;
m_unitCount = 1;
m_pinNameOffset = 40;
@ -189,8 +188,6 @@ LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
m_showPinNumbers = true;
m_showPinNames = true;
wxASSERT( !aName.IsEmpty() );
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
// when the field editors are invoked.
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, VALUE ) );
@ -198,6 +195,7 @@ LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, FOOTPRINT ) );
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, DATASHEET ) );
SetLib( aLibrary );
SetName( aName );
}
@ -298,13 +296,29 @@ wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
void LIB_PART::SetName( const wxString& aName )
{
GetValueField().SetText( aName );
m_libId.SetLibItemName( aName, false );
// The LIB_ALIAS that is the LIB_PART name has to be created so create it.
if( m_aliases.size() == 0 )
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
else
m_aliases[0]->SetName( aName );
LIB_FIELD& valueField = GetValueField();
// LIB_FIELD::SetText() calls LIB_PART::SetName(),
// the following if-clause is to break an infinite loop
if( valueField.GetText() != aName )
valueField.SetText( aName );
}
void LIB_PART::SetLibId( const LIB_ID& aLibId )
{
m_libId.SetLibNickname( aLibId.GetLibNickname() );
// SetName() sets LibItemName in m_libId
SetName( aLibId.GetLibItemName() );
}
@ -1656,6 +1670,15 @@ void LIB_PART::SetConversion( bool aSetConvert )
}
void LIB_PART::SetLib( PART_LIB* aLibrary )
{
m_library = aLibrary;
if( aLibrary )
m_libId.SetLibNickname( aLibrary->GetName() );
}
wxArrayString LIB_PART::GetAliasNames( bool aIncludeRoot ) const
{
wxArrayString names;

View File

@ -282,13 +282,13 @@ public:
const wxString& GetName() const { return m_aliases[0]->GetName(); }
const LIB_ID& GetLibId() const { return m_libId; }
void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
void SetLibId( const LIB_ID& aLibId );
const wxString GetLibraryName();
PART_LIB* GetLib() { return m_library; }
void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
void SetLib( PART_LIB* aLibrary );
wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;