Unified way of setting LIB_PART name
LIB_PART name is stored in three places that might be changed independently: - the first LIB_ALIAS in m_aliases - LIB_FIELD with VALUE ID - m_name wxString field This is potentially leads to an incoherent LIB_PART state. To prevent this, all fields are changed using only one method: LIB_PART::SetName(). LIB_PART::m_name has been removed as the same information is available in two other variables.
This commit is contained in:
parent
3589244ff3
commit
4c4f5ae962
|
@ -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_name = aName;
|
||||
m_library = aLibrary;
|
||||
m_dateModified = 0;
|
||||
m_unitCount = 1;
|
||||
|
@ -190,21 +189,16 @@ LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
|
|||
m_showPinNumbers = true;
|
||||
m_showPinNames = true;
|
||||
|
||||
m_libId.SetLibItemName( aName, false );
|
||||
|
||||
// Create the default alias if the name parameter is not empty.
|
||||
if( !aName.IsEmpty() )
|
||||
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
|
||||
wxASSERT( !aName.IsEmpty() );
|
||||
|
||||
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
|
||||
// when the field editors are invoked.
|
||||
LIB_FIELD* value = new LIB_FIELD( this, VALUE );
|
||||
value->SetText( aName );
|
||||
m_drawings[LIB_FIELD_T].push_back( value );
|
||||
|
||||
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, VALUE ) );
|
||||
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, REFERENCE ) );
|
||||
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, FOOTPRINT ) );
|
||||
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, DATASHEET ) );
|
||||
|
||||
SetName( aName );
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,7 +209,6 @@ LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
|
|||
LIB_ITEM* newItem;
|
||||
|
||||
m_library = aLibrary;
|
||||
m_name = aPart.m_name;
|
||||
m_FootprintList = aPart.m_FootprintList;
|
||||
m_unitCount = aPart.m_unitCount;
|
||||
m_unitsLocked = aPart.m_unitsLocked;
|
||||
|
@ -305,7 +298,6 @@ wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
|
|||
|
||||
void LIB_PART::SetName( const wxString& aName )
|
||||
{
|
||||
m_name = aName;
|
||||
GetValueField().SetText( aName );
|
||||
|
||||
// The LIB_ALIAS that is the LIB_PART name has to be created so create it.
|
||||
|
@ -897,23 +889,16 @@ bool LIB_PART::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
|
|||
m_showPinNames = ( drawname == 'N' ) ? false : true;
|
||||
|
||||
// Copy part name and prefix.
|
||||
LIB_FIELD& value = GetValueField();
|
||||
|
||||
if( componentName[0] != '~' )
|
||||
{
|
||||
m_name = FROM_UTF8( componentName );
|
||||
value.SetText( m_name );
|
||||
SetName( FROM_UTF8( componentName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_name = FROM_UTF8( &componentName[1] );
|
||||
value.SetText( m_name );
|
||||
value.SetVisible( false );
|
||||
SetName( FROM_UTF8( &componentName[1] ) );
|
||||
GetValueField().SetVisible( false );
|
||||
}
|
||||
|
||||
// Add the root alias to the alias list.
|
||||
m_aliases.push_back( new LIB_ALIAS( m_name, this ) );
|
||||
|
||||
LIB_FIELD& reference = GetReferenceField();
|
||||
|
||||
if( strcmp( prefix, "~" ) == 0 )
|
||||
|
@ -1111,7 +1096,7 @@ bool LIB_PART::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
|
|||
*fixedField = *field;
|
||||
|
||||
if( field->GetId() == VALUE )
|
||||
m_name = field->GetText();
|
||||
SetName( field->GetText() );
|
||||
|
||||
delete field;
|
||||
}
|
||||
|
@ -1708,6 +1693,7 @@ void LIB_PART::SetAliases( const wxArrayString& aAliasList )
|
|||
{
|
||||
wxCHECK_RET( !m_library,
|
||||
wxT( "Part aliases cannot be changed when they are owned by a library." ) );
|
||||
wxCHECK_RET( !aAliasList.IsEmpty(), wxT( "Alias list cannot be empty" ) );
|
||||
|
||||
if( aAliasList == GetAliasNames() )
|
||||
return;
|
||||
|
@ -1782,7 +1768,7 @@ LIB_ALIAS* LIB_PART::RemoveAlias( LIB_ALIAS* aAlias )
|
|||
wxLogTrace( traceSchLibMem,
|
||||
wxT( "%s: part:'%s', alias:'%s', alias count %llu, reference count %ld." ),
|
||||
GetChars( wxString::FromAscii( __WXFUNCTION__ ) ),
|
||||
GetChars( m_name ),
|
||||
GetChars( GetName() ),
|
||||
GetChars( aAlias->GetName() ),
|
||||
(long long unsigned) m_aliases.size(),
|
||||
m_me.use_count() );
|
||||
|
|
|
@ -231,7 +231,6 @@ class LIB_PART : public EDA_ITEM
|
|||
friend class SCH_LEGACY_PLUGIN_CACHE;
|
||||
|
||||
PART_SPTR m_me; ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
|
||||
wxString m_name;
|
||||
LIB_ID m_libId;
|
||||
int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to 0
|
||||
///< to draw the pin name above the pin.
|
||||
|
@ -280,7 +279,7 @@ public:
|
|||
|
||||
virtual void SetName( const wxString& aName );
|
||||
|
||||
const wxString& GetName() const { return m_name; }
|
||||
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; }
|
||||
|
|
|
@ -2476,25 +2476,20 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader )
|
|||
part->SetUnitCount( 1 );
|
||||
|
||||
// Copy part name and prefix.
|
||||
LIB_FIELD& value = part->GetValueField();
|
||||
|
||||
// The root alias is added to the alias list by SetName() which is called by SetText().
|
||||
if( name.IsEmpty() )
|
||||
{
|
||||
part->m_name = "~";
|
||||
value.SetText( "~" );
|
||||
part->SetName( "~" );
|
||||
}
|
||||
else if( name[0] != '~' )
|
||||
{
|
||||
part->m_name = name;
|
||||
value.SetText( name );
|
||||
part->SetName( name );
|
||||
}
|
||||
else
|
||||
{
|
||||
name = name.Right( name.Length() - 1 );
|
||||
part->m_name = name;
|
||||
value.SetText( name );
|
||||
value.SetVisible( false );
|
||||
part->SetName( name.Right( name.Length() - 1 ) );
|
||||
part->GetValueField().SetVisible( false );
|
||||
}
|
||||
|
||||
// Don't set the library alias, this is determined by the symbol library table.
|
||||
|
@ -2766,7 +2761,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadField( std::unique_ptr< LIB_PART >& aPart,
|
|||
// Ensure the VALUE field = the part name (can be not the case
|
||||
// with malformed libraries: edited by hand, or converted from other tools)
|
||||
if( fixedField->GetId() == VALUE )
|
||||
fixedField->m_Text = aPart->m_name;
|
||||
fixedField->m_Text = aPart->GetName();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue