74 aSymbols.push_back(
static_cast<SCH_SYMBOL*
>( aItem ) );
77 if( aSymbols.empty() )
98 if( aCached && !each_lib.IsCache() )
101 if( !aCached && each_lib.IsCache() )
104 symbol = each_lib.FindSymbol( aName );
117 fn.SetName( fn.GetName() + wxT(
"-rescue" ) );
124 const wxString& aNewName,
138 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
140 typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
141 candidate_map_t candidate_map;
146 std::vector<LIB_SYMBOL*> case_insensitive_matches;
148 wxString symbol_name;
149 wxString last_symbol_name;
155 if( last_symbol_name != symbol_name )
159 last_symbol_name = symbol_name;
160 case_insensitive_matches.clear();
162 LIB_ID id( wxEmptyString, symbol_name );
166 if( case_sensitive_match )
175 if( !case_insensitive_matches.size() )
179 case_insensitive_matches[0],
180 eachSymbol->GetUnit(),
181 eachSymbol->GetConvert() );
183 candidate_map[symbol_name] = candidate;
188 for(
const candidate_map_t::value_type& each_pair : candidate_map )
219 eachSymbol->SetLibId( libId );
220 eachSymbol->ClearFlags();
229 const wxString& aNewName,
252 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
254 typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
255 candidate_map_t candidate_map;
261 wxString symbol_name;
262 wxString old_symbol_name;
268 if( old_symbol_name != symbol_name )
272 old_symbol_name = symbol_name;
283 tmp = eachSymbol->GetLibId().GetLibNickname().wx_str() + wxT(
"_" ) +
284 eachSymbol->GetLibId().GetLibItemName().wx_str();
290 if( cache_match && lib_match &&
291 !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
294 if( !cache_match && lib_match )
299 eachSymbol->GetUnit(),
300 eachSymbol->GetConvert() );
302 candidate_map[symbol_name] = candidate;
307 for(
const candidate_map_t::value_type& each_pair : candidate_map )
319 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or "
322 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
325 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
340 std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->
Flatten();
352 eachSymbol->SetLibId( libId );
353 eachSymbol->ClearFlags();
362 const LIB_ID& aRequestedId,
388 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
390 typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
392 candidate_map_t candidate_map;
404 const LIB_ID& symbol_id = eachSymbol->GetLibId();
406 if( old_symbol_id != symbol_id )
410 old_symbol_id = symbol_id;
431 if( !cache_match && !lib_match )
437 if( lib_match && lib_match->
IsAlias() )
441 if( !lib_match_parent )
444 lib_match = lib_match_parent.get();
450 if( cache_match && lib_match &&
451 !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
456 if( !cache_match && lib_match )
471 eachSymbol->GetUnit(),
472 eachSymbol->GetConvert() );
474 candidate_map[symbol_id] = candidate;
479 for(
const candidate_map_t::value_type& each_pair : candidate_map )
492 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or "
498 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
504 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
517 wxCHECK_MSG( tmp,
false, wxS(
"Both cache and library symbols undefined." ) );
519 std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->
Flatten();
530 eachSymbol->ClearFlags();
555 const wxString &aNewName )
569 if( ! each_candidate->PerformAction(
this ) )
584 each_logitem.symbol->SetLibId( libId );
585 each_logitem.symbol->ClearFlags();
596 if( aRunningOnDemand )
598 wxMessageDialog dlg( aParent,
_(
"This project has nothing to rescue." ),
599 _(
"Project Rescue Helper" ) );
613 wxMessageDialog dlg( aParent,
_(
"No symbols were rescued." ),
614 _(
"Project Rescue Helper" ) );
638 std::vector<wxString> names_seen;
640 for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it =
m_all_candidates.begin();
643 bool seen_already =
false;
645 for( wxString& name_seen : names_seen )
647 if( name_seen == it->GetRequestedName() )
660 names_seen.push_back( it->GetRequestedName() );
685 std::unique_ptr<SYMBOL_LIB> rescue_lib = std::make_unique<SYMBOL_LIB>( SCH_LIB_TYPE::LT_EESCHEMA,
698 std::vector< LIB_SYMBOL* > symbols;
721 msg.Printf(
_(
"Failed to create symbol library file '%s'." ),
727 wxArrayString libNames;
744 while( libNames.Index( libName ) != wxNOT_FOUND )
745 libNames.Remove( libName );
748 libNames.Insert( libName, 0 );
759 boost::ptr_vector<SYMBOL_LIB> libsSave;
760 libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
779 libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
794 wxCHECK_RET( aNewSymbol, wxS(
"Invalid LIB_SYMBOL pointer." ) );
804 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
838 std::vector<LIB_SYMBOL*> symbols;
874 msg.Printf(
_(
"Failed to save rescue library %s." ), fn.GetFullPath() );
883 wxString uri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
884 wxString libNickname = fn.GetName();
897 msg.Printf(
_(
"Error occurred saving project specific symbol library table." ) );
918 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< SYMBOL_LIB > m_rescue_lib
virtual void OpenRescueLibrary() override
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 wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
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.
LIB_ID GetLibId() const override
void SetLib(SYMBOL_LIB *aLibrary)
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
static SYMBOL_LIBS * SchLibs(PROJECT *aProject)
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
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
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.
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.
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.
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 override
Helper to retrieve the filename from the root sheet screen.
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
virtual void SaveLibrary(const wxString &aFileName, const STRING_UTF8_MAP *aProperties=nullptr)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
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
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 SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
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.
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library plugin properties.
std::vector< std::unique_ptr< LIB_SYMBOL > > m_rescueLibSymbols
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString GetType() const override
Return the type of symbol library table represented by this row.
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
static const wxString & GetSymbolLibTableFileName()
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
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.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
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.
const std::string KiCadSymbolLibFileExtension
const std::string LegacySymbolLibFileExtension
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
static bool sort_by_libid(const SCH_SYMBOL *ref, SCH_SYMBOL *cmp)
static LIB_SYMBOL * findSymbol(const wxString &aName, 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)
std::pair< SCH_SYMBOL *, wxString > SYMBOL_NAME_PAIR
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, 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 for symbol library class.
Definition of file extensions used in Kicad.