Fix a few more symbol library inheritance bugs.

Replace some C casts with C++ dynamic_cast.

Fix iterator bug when deleting inherited symbols from legacy file format
symbol library cache.

Remove unnecessary const when return wxString object instead of reference.
This commit is contained in:
Wayne Stambaugh 2019-11-08 15:50:04 -05:00
parent 8e150521a2
commit 9fe2c4b21f
6 changed files with 19 additions and 19 deletions

View File

@ -112,7 +112,7 @@ LIB_PART::LIB_PART( const wxString& aName, LIB_PART* aParent, PART_LIB* aLibrary
}
LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
LIB_PART::LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary ) :
EDA_ITEM( aPart ),
m_me( this, null_deleter() )
{
@ -134,7 +134,7 @@ LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
m_keyWords = aPart.m_keyWords;
m_docFileName = aPart.m_docFileName;
for( LIB_ITEM& oldItem : aPart.m_drawings )
for( const LIB_ITEM& oldItem : aPart.m_drawings )
{
if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
continue;
@ -278,7 +278,7 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
wxString::Format( "Parent of derived symbol '%s' undefined", m_name ) );
// Copy the parent.
retv.reset( new LIB_PART( *const_cast< LIB_PART* >( parent.get() ) ) );
retv.reset( new LIB_PART( *parent.get() ) );
// Now add the inherited part (this) information.
retv->SetName( m_name );
@ -291,7 +291,7 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
}
else
{
retv.reset( new LIB_PART( *const_cast< LIB_PART* >( this ) ) );
retv.reset( new LIB_PART( *this ) );
}
return retv;

View File

@ -129,7 +129,7 @@ public:
/**
* Copy constructor.
*/
LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary = NULL );
virtual ~LIB_PART();
@ -144,7 +144,7 @@ public:
}
virtual void SetName( const wxString& aName );
const wxString GetName() const override { return m_name; }
wxString GetName() const override { return m_name; }
LIB_ID GetLibId() const override { return m_libId; }
void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
@ -156,21 +156,21 @@ public:
m_description = aDescription;
}
const wxString GetDescription() override { return m_description; }
wxString GetDescription() override { return m_description; }
void SetKeyWords( const wxString& aKeyWords )
{
m_keyWords = aKeyWords;
}
const wxString GetKeyWords() const { return m_keyWords; }
wxString GetKeyWords() const { return m_keyWords; }
void SetDocFileName( const wxString& aDocFileName )
{
m_docFileName = aDocFileName;
}
const wxString GetDocFileName() const { return m_docFileName; }
wxString GetDocFileName() const { return m_docFileName; }
wxString GetSearchText() override;

View File

@ -4183,12 +4183,12 @@ void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
{
if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
{
delete it->second;
it = m_symbols.erase( it );
delete it1->second;
it1 = m_symbols.erase( it1 );
}
else
{
it++;
it1++;
}
}

View File

@ -141,7 +141,7 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
if( item.Type() != LIB_FIELD_T )
continue;
LIB_FIELD* field = (LIB_FIELD*) &item;
LIB_FIELD* field = dynamic_cast< LIB_FIELD* >( &item );
if( field->GetId() < MANDATORY_FIELDS )
Add( &item );
@ -162,7 +162,7 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
// The mandatory fields are already in place so we only add user defined fields.
if( item.Type() == LIB_FIELD_T )
{
LIB_FIELD* field = (LIB_FIELD*) &item;
LIB_FIELD* field = dynamic_cast< LIB_FIELD* >( &item );
if( field->GetId() < MANDATORY_FIELDS )
continue;

View File

@ -81,7 +81,7 @@ public:
return m_nickname;
}
const wxString GetName() const override
wxString GetName() const override
{
return m_fpname;
}
@ -91,13 +91,13 @@ public:
return LIB_ID( m_nickname, m_fpname );
}
const wxString GetDescription() override
wxString GetDescription() override
{
ensure_loaded();
return m_doc;
}
const wxString GetKeywords()
wxString GetKeywords()
{
ensure_loaded();
return m_keywords;

View File

@ -41,10 +41,10 @@ class APIEXPORT LIB_TREE_ITEM
public:
virtual LIB_ID GetLibId() const = 0;
virtual const wxString GetName() const = 0;
virtual wxString GetName() const = 0;
virtual wxString GetLibNickname() const = 0;
virtual const wxString GetDescription() = 0;
virtual wxString GetDescription() = 0;
virtual wxString GetSearchText() { return wxEmptyString; }