From b33cf23bda2a5083cfe266ae8304c57c9729e958 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 21 Jan 2023 10:35:14 -0500 Subject: [PATCH] Fix library symbol rescue issues. Fixes https://gitlab.com/kicad/code/kicad/-/issues/13602 (cherry picked from commit 0a7bd85cd6c90e81eccdab018af847f8d05f19fa) --- eeschema/project_rescue.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index c12598803c..e3add8cd6b 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Chris Pavlina - * Copyright (C) 2015-2022 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2015-2023 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -144,7 +144,6 @@ void RESCUE_CASE_CANDIDATE::FindRescues( RESCUER& aRescuer, std::vector case_insensitive_matches; wxString symbol_name; - wxString search_name; wxString last_symbol_name; for( SCH_SYMBOL* eachSymbol : *( aRescuer.GetSymbols() ) ) @@ -164,9 +163,22 @@ void RESCUE_CASE_CANDIDATE::FindRescues( RESCUER& aRescuer, case_sensitive_match = aRescuer.GetPrj()->SchLibs()->FindLibSymbol( id ); // If the case sensitive match failed, try a case insensitive match. - if( !case_sensitive_match ) - aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches, - search_name ); + if( case_sensitive_match ) + continue; + + aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches, + symbol_name ); + + // If there are not case insensitive matches either, the symbol cannot be rescued. + if( !case_insensitive_matches.size() ) + continue; + + RESCUE_CASE_CANDIDATE candidate( symbol_name, case_insensitive_matches[0]->GetName(), + case_insensitive_matches[0], + eachSymbol->GetUnit(), + eachSymbol->GetConvert() ); + + candidate_map[symbol_name] = candidate; } if( case_sensitive_match || !( case_insensitive_matches.size() ) ) @@ -198,6 +210,12 @@ wxString RESCUE_CASE_CANDIDATE::GetActionDescription() const bool RESCUE_CASE_CANDIDATE::PerformAction( RESCUER* aRescuer ) { + wxCHECK( m_lib_candidate, true ); + + std::unique_ptr new_symbol = m_lib_candidate->Flatten(); + new_symbol->SetName( m_new_name ); + aRescuer->AddSymbol( new_symbol.get() ); + for( SCH_SYMBOL* eachSymbol : *aRescuer->GetSymbols() ) { if( eachSymbol->GetLibId().GetLibItemName() != UTF8( m_requested_name ) ) @@ -316,7 +334,9 @@ bool RESCUE_CACHE_CANDIDATE::PerformAction( RESCUER* aRescuer ) { LIB_SYMBOL* tmp = ( m_cache_candidate ) ? m_cache_candidate : m_lib_candidate; - wxCHECK_MSG( tmp, false, wxT( "Both cache and library symbols undefined." ) ); + // A symbol that cannot be rescued is a valid condition so just bail out here. + if( !tmp ) + return true; std::unique_ptr new_symbol = tmp->Flatten(); new_symbol->SetName( m_new_name );