65 aSymbols.push_back(
static_cast<SCH_SYMBOL*
>( aItem ) );
68 if( aSymbols.empty() )
89 if( aCached && !each_lib.IsCache() )
92 if( !aCached && each_lib.IsCache() )
95 symbol = each_lib.FindSymbol( aName );
108 fn.SetName( fn.GetName() + wxT(
"-rescue" ) );
115 LIB_SYMBOL* aLibCandidate,
int aUnit,
int aBodyStyle ) :
116 RESCUE_CANDIDATE( aRequestedName, aNewName, aLibCandidate, aUnit, aBodyStyle )
122 std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map;
127 std::vector<LIB_SYMBOL*> case_insensitive_matches;
129 wxString symbol_name;
130 wxString last_symbol_name;
134 symbol_name = eachSymbol->GetLibId().GetUniStringLibItemName();
136 if( last_symbol_name != symbol_name )
140 last_symbol_name = symbol_name;
141 case_insensitive_matches.clear();
143 LIB_ID id( wxEmptyString, symbol_name );
147 if( case_sensitive_match )
155 if( !case_insensitive_matches.size() )
159 case_insensitive_matches[0], eachSymbol->GetUnit(),
160 eachSymbol->GetBodyStyle() );
162 candidate_map[symbol_name] = candidate;
167 for(
const auto& [
name, candidate ] : candidate_map )
196 eachSymbol->SetLibId( libId );
197 eachSymbol->ClearFlags();
207 std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map;
213 wxString symbol_name;
214 wxString old_symbol_name;
218 symbol_name = eachSymbol->GetLibId().GetUniStringLibItemName();
220 if( old_symbol_name != symbol_name )
224 old_symbol_name = symbol_name;
233 wxString tmp = wxString::Format( wxT(
"%s-%s" ),
234 eachSymbol->GetLibId().GetLibNickname().wx_str(),
235 eachSymbol->GetLibId().GetLibItemName().wx_str() );
242 if( cache_match && lib_match
243 && !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
248 if( !cache_match && lib_match )
253 eachSymbol->
GetUnit(), eachSymbol->GetBodyStyle() );
255 candidate_map[symbol_name] = candidate;
260 for(
const auto& [
name, candidate] : candidate_map )
271 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or the cache." ),
276 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
282 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
299 std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->
Flatten();
311 eachSymbol->SetLibId( libId );
312 eachSymbol->ClearFlags();
324 int aUnit,
int aBodyStyle ) :
341 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
343 std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map;
355 const LIB_ID& symbol_id = eachSymbol->GetLibId();
357 if( old_symbol_id != symbol_id )
361 old_symbol_id = symbol_id;
374 symbolName.Printf( wxT(
"%s-%s" ),
383 if( !cache_match && !lib_match )
386 std::shared_ptr<LIB_SYMBOL> lib_match_parent;
389 if( lib_match && lib_match->
IsDerived() )
393 if( !lib_match_parent )
396 lib_match = lib_match_parent.get();
402 if( cache_match && lib_match
403 && !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
408 if( !cache_match && lib_match )
420 LIB_ID new_id( libNickname, wxString::Format( wxT(
"%s-%s" ),
426 eachSymbol->GetBodyStyle() );
428 candidate_map[symbol_id] = candidate;
433 for(
const auto& [
name, candidate] : candidate_map )
444 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or the cache." ),
449 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
455 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
468 wxCHECK_MSG( tmp,
false, wxS(
"Both cache and library symbols undefined." ) );
470 std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->
Flatten();
472 new_symbol->SetName(
m_new_id.GetLibItemName() );
481 eachSymbol->ClearFlags();
519 if( ! each_candidate->PerformAction(
this ) )
534 each_logitem.symbol->SetLibId( libId );
535 each_logitem.symbol->ClearFlags();
546 if( aRunningOnDemand )
549 _(
"Project Rescue Helper" ) );
564 _(
"Project Rescue Helper" ) );
588 std::vector<wxString> names_seen;
590 for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it =
m_all_candidates.begin();
593 bool seen_already =
false;
595 for( wxString& name_seen : names_seen )
597 if( name_seen == it->GetRequestedName() )
610 names_seen.push_back( it->GetRequestedName() );
635 std::unique_ptr<LEGACY_SYMBOL_LIB> rescue_lib =
648 std::vector< LIB_SYMBOL* > symbols;
669 DisplayError( aParent, wxString::Format(
_(
"Failed to create symbol library file '%s'." ),
674 wxArrayString libNames;
691 while( libNames.Index( libName ) != wxNOT_FOUND )
692 libNames.Remove( libName );
695 libNames.Insert( libName, 0 );
706 boost::ptr_vector<LEGACY_SYMBOL_LIB> libsSave;
707 libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
726 libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
734 schematic.UpdateSymbolLinks();
741 wxCHECK_RET( aNewSymbol, wxS(
"Invalid LIB_SYMBOL pointer." ) );
751 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
753 m_properties = std::make_unique<std::map<std::string, UTF8>>();
781 if( std::optional<const LIBRARY_TABLE_ROW*> optRow =
812 pi->SaveLibrary( fn.GetFullPath() );
817 msg.Printf(
_(
"Failed to save rescue library %s." ), fn.GetFullPath() );
826 wxString uri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
827 wxString libNickname = fn.GetName();
831 wxCHECK( optTable,
false );
835 if( std::optional<LIBRARY_TABLE_ROW*> oldRow = projectTable->
Row( libNickname ); oldRow )
842 row->
SetType( wxT(
"KiCad" ) );
846 projectTable->
Save().map_error(
849 wxMessageBox(
_(
"Error saving library table:\n\n" ) + aError.
message,
850 _(
"File Save Error" ), wxOK | wxICON_ERROR );
861 schematic.UpdateSymbolLinks();
868 wxCHECK_RET( aNewSymbol, wxS(
"Invalid LIB_SYMBOL pointer." ) );
A base class for most all the KiCad significant classes used in schematics and boards.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Write the rescue library.
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::unique_ptr< LEGACY_SYMBOL_LIB > m_rescue_lib
virtual void OpenRescueLibrary() override
A collection of #SYMBOL_LIB objects.
void FindLibraryNearEntries(std::vector< LIB_SYMBOL * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a LIB_SYMBOL using a case insensitive comparison.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
LEGACY_SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
Object used to load, save, search, and otherwise manipulate symbol library files.
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
std::optional< LIBRARY_TABLE_ROW * > GetRow(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
const wxString & Type() const
void SetURI(const wxString &aUri)
LIBRARY_RESULT< void > Save()
std::optional< LIBRARY_TABLE_ROW * > Row(const wxString &aNickname)
LIBRARY_TABLE_ROW & InsertRow()
Builds a new row and inserts it at the end of the table; returning a reference to the row.
A logical library item identifier and consists of various portions much like a URI.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
bool IsValid() const
Check if this LID_ID is valid.
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
const LIB_ID & GetLibId() const override
bool PinsConflictWith(const LIB_SYMBOL &aOtherSymbol, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength) const
Return true if this symbol's pins do not match another symbol's pins.
void SetLib(LEGACY_SYMBOL_LIB *aLibrary)
std::shared_ptr< LIB_SYMBOL > GetRootSymbol() const
Get the parent symbol that does not have another parent.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
Container for project specific data.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol)=0
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Write the rescue library.
std::vector< RESCUE_LOG > m_rescue_log
void UndoRescues()
Reverse the effects of all rescues on the project.
bool DoRescues()
Perform all chosen rescue actions, logging them to be undone if necessary.
std::vector< SCH_SYMBOL * > m_symbols
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
void LogRescue(SCH_SYMBOL *aSymbol, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
SCH_SHEET_PATH * m_currentSheet
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
size_t GetCandidateCount()
Return the number of rescue candidates found.
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain)=0
Display a dialog to allow the user to select rescues.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
virtual void OpenRescueLibrary()=0
size_t GetChosenCandidateCount()
Get the number of rescue candidates chosen by the user.
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
virtual void FindCandidates()=0
Populate the RESCUER with all possible candidates.
void RemoveDuplicates()
Filter out duplicately named rescue candidates.
LIB_SYMBOL * m_cache_candidate
RESCUE_CACHE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create a RESCUE_CACHE_CANDIDATE.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CACHE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
RESCUE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aLibCandidate, int aUnit, int aBodyStyle)
wxString m_requested_name
LIB_SYMBOL * m_lib_candidate
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
RESCUE_CASE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create a RESCUE_CANDIDATE.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(const LIB_ID &aRequestedId, const LIB_ID &aNewId, LIB_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create RESCUE_CANDIDATE.
LIB_SYMBOL * m_cache_candidate
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector.
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE()
Holds all the data relating to one schematic.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
SCHEMATIC * Schematic() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
const LIB_ID & GetLibId() const override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::vector< LIB_SYMBOL * > GetSymbols(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
virtual void OpenRescueLibrary() override
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Write the rescue library.
SYMBOL_LIB_TABLE_RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library plugin properties.
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::vector< std::unique_ptr< LIB_SYMBOL > > m_rescueLibSymbols
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
static bool sort_by_libid(const SYMBOL_CANDIDATE &candidate1, const SYMBOL_CANDIDATE &candidate2)
int InvokeDialogRescueEach(wxWindow *aParent, RESCUER &aRescuer, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain)
This dialog asks the user which rescuable, cached parts he wants to rescue.
static const std::string LegacySymbolLibFileExtension
static const std::string KiCadSymbolLibFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
PGM_BASE & Pgm()
The global program "get" accessor.
static bool sort_by_libid(const SCH_SYMBOL *ref, SCH_SYMBOL *cmp)
static LIB_SYMBOL * findSymbol(const wxString &aName, LEGACY_SYMBOL_LIBS *aLibs, bool aCached)
Search the libraries for the first symbol with a given name.
static void getSymbols(SCHEMATIC *aSchematic, std::vector< SCH_SYMBOL * > &aSymbols)
Fill a vector with all of the project's symbols, to ease iterating over them.
static wxFileName GetRescueLibraryFileName(SCHEMATIC *aSchematic)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIBRARY_ADAPTER *aLibMgr, LEGACY_SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
A filename or source description, a problem input line, a line number, a byte offset,...
Definition of file extensions used in Kicad.