Fix more bugs in the schematic symbol rescuer.

In the rare case when something goes wrong with the symbol library
table remapping, do not attempt to rescue symbols that are neither
in the cache nor in any of the libraries.

The legacy rescue library code overwrote the existing library so
previous rescues would get lost.  If the rescue library exists,
copy it's contents into the new rescue library before adding the
new rescued symbols so no previously rescued symbols are lost.

Fix a null pointer bug in the symbol library editor when no symbol
is loaded.

Set LIB_ID item name to name passed to LIB_PART ctor.

Copy LIB_ID in LIB_PART copy ctor.
This commit is contained in:
Wayne Stambaugh 2017-11-09 21:24:43 -05:00
parent 6d63873128
commit 610ff7485f
4 changed files with 36 additions and 1 deletions

View File

@ -190,6 +190,8 @@ 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 ) );
@ -222,6 +224,7 @@ LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
m_showPinNames = aPart.m_showPinNames;
m_dateModified = aPart.m_dateModified;
m_options = aPart.m_options;
m_libId = aPart.m_libId;
for( LIB_ITEM& oldItem : aPart.m_drawings )
{

View File

@ -49,6 +49,8 @@ DIALOG_SYMBOL_REMAP::DIALOG_SYMBOL_REMAP( SCH_EDIT_FRAME* aParent ) :
void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
{
wxBusyCursor busy;
// The schematic is fully loaded, any legacy library symbols have been rescued. Now
// check to see if the schematic has not been converted to the symbol library table
// method for looking up symbols.

View File

@ -163,7 +163,10 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
// Get the name of the current part to preselect it
LIB_PART* current_part = GetCurPart();
LIB_ID id = current_part->GetLibId();
LIB_ID id;
if( current_part )
id = current_part->GetLibId();
SCH_BASE_FRAME::HISTORY_LIST dummyHistoryList;
SCHLIB_FILTER filter;

View File

@ -255,6 +255,9 @@ void RESCUE_CACHE_CANDIDATE::FindRescues( RESCUER& aRescuer,
cache_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), true );
lib_match = find_component( part_name, aRescuer.GetPrj()->SchLibs(), false );
if( !cache_match && !lib_match )
continue;
// Test whether there is a conflict or if the symbol can only be found in the cache.
if( ( cache_match && lib_match
&& !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
@ -364,6 +367,9 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
lib_match = aRescuer.GetFrame()->GetLibPart( part_id );
if( !cache_match && !lib_match )
continue;
// Test whether there is a conflict or if the symbol can only be found in the cache.
if( ( cache_match && lib_match
&& !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
@ -609,6 +615,27 @@ void LEGACY_RESCUER::OpenRescueLibrary()
m_rescue_lib = std::move( rescue_lib );
m_rescue_lib->EnableBuffering();
// If a rescue library already exists copy the contents of that library so we do not
// lose an previous rescues.
PART_LIB* rescueLib = m_prj->SchLibs()->FindLibrary( fn.GetName() );
if( rescueLib )
{
// For items in the rescue library, aliases are the root symbol.
std::vector< LIB_ALIAS* > aliases;
rescueLib->GetAliases( aliases );
for( auto alias : aliases )
{
LIB_PART* part = alias->GetPart();
wxCHECK2( part, continue );
m_rescue_lib->AddPart( new LIB_PART( *part, m_rescue_lib.get() ) );
}
}
}