68 for(
SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
71 aComponents.push_back( static_cast<SCH_COMPONENT*>( aItem ) );
74 if( aComponents.empty() )
78 std::sort( aComponents.begin(), aComponents.end(),
sort_by_libid );
96 if( aCached && !each_lib.IsCache() )
99 if( !aCached && each_lib.IsCache() )
102 part = each_lib.FindPart( new_name );
115 fn.SetName( fn.GetName() + wxT(
"-rescue" ) );
122 const wxString& aNewName,
136 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
138 typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
139 candidate_map_t candidate_map;
142 LIB_PART* case_sensitive_match =
nullptr;
143 std::vector<LIB_PART*> case_insensitive_matches;
146 wxString search_name;
147 wxString last_part_name;
154 if( last_part_name != part_name )
158 last_part_name = part_name;
159 case_insensitive_matches.clear();
161 LIB_ID id( wxEmptyString, search_name );
163 case_sensitive_match = aRescuer.
GetPrj()->SchLibs()->FindLibPart(
id );
166 if( !case_sensitive_match )
167 aRescuer.
GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches,
171 if( case_sensitive_match || !( case_insensitive_matches.size() ) )
175 case_insensitive_matches[0],
176 each_component->GetUnit(),
177 each_component->GetConvert() );
179 candidate_map[part_name] = candidate;
183 for(
const candidate_map_t::value_type& each_pair : candidate_map )
208 each_component->SetLibId( libId );
209 each_component->ClearFlags();
218 const wxString& aNewName,
241 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
243 typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
244 candidate_map_t candidate_map;
251 wxString search_name;
252 wxString old_part_name;
259 if( old_part_name != part_name )
263 old_part_name = part_name;
267 if( !cache_match && !lib_match )
272 if( cache_match && lib_match &&
273 !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
276 if( !cache_match && lib_match )
281 each_component->GetUnit(),
282 each_component->GetConvert() );
284 candidate_map[part_name] = candidate;
289 for(
const candidate_map_t::value_type& each_pair : candidate_map )
301 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or " 304 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
307 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
318 wxCHECK_MSG( tmp,
false,
"Both cache and library symbols undefined." );
320 std::unique_ptr<LIB_PART> new_part = tmp->
Flatten();
322 aRescuer->
AddPart( new_part.get() );
332 each_component->SetLibId( libId );
333 each_component->ClearFlags();
342 const LIB_ID& aRequestedId,
368 boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
370 typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
372 candidate_map_t candidate_map;
382 const LIB_ID& part_id = each_component->GetLibId();
384 if( old_part_id != part_id )
388 old_part_id = part_id;
398 if( !cache_match && !lib_match )
404 if( lib_match && lib_match->IsAlias() )
406 lib_match_parent = lib_match->
GetParent().lock();
408 if( !lib_match_parent )
414 lib_match = lib_match_parent.get();
421 if( cache_match && lib_match &&
422 !cache_match->
PinsConflictWith( *lib_match,
true,
true,
true,
true,
false ) )
425 if( !cache_match && lib_match )
438 libNickname.Replace(
" ",
"-" );
442 each_component->GetUnit(),
443 each_component->GetConvert() );
445 candidate_map[part_id] = candidate;
450 for(
const candidate_map_t::value_type& each_pair : candidate_map )
462 action.Printf(
_(
"Cannot rescue symbol %s which is not available in any library or " 465 action.Printf(
_(
"Rescue symbol %s found only in cache library to %s." ),
468 action.Printf(
_(
"Rescue modified symbol %s to %s" ),
479 wxCHECK_MSG( tmp,
false,
"Both cache and library symbols undefined." );
481 std::unique_ptr<LIB_PART> new_part = tmp->
Flatten();
484 aRescuer->
AddPart( new_part.get() );
491 each_component->SetLibId(
m_new_id );
492 each_component->ClearFlags();
517 const wxString &aNewName )
531 if( ! each_candidate->PerformAction(
this ) )
546 each_logitem.component->SetLibId( libId );
547 each_logitem.component->ClearFlags();
558 if( aRunningOnDemand )
560 wxMessageDialog dlg( aParent,
_(
"This project has nothing to rescue." ),
561 _(
"Project Rescue Helper" ) );
575 wxMessageDialog dlg( aParent,
_(
"No symbols were rescued." ),
576 _(
"Project Rescue Helper" ) );
600 std::vector<wxString> names_seen;
602 for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it =
m_all_candidates.begin();
605 bool seen_already =
false;
607 for( wxString& name_seen : names_seen )
609 if( name_seen == it->GetRequestedName() )
622 names_seen.push_back( it->GetRequestedName() );
655 PART_LIB* rescueLib =
m_prj->SchLibs()->FindLibrary( fn.GetName() );
660 std::vector< LIB_PART* > symbols;
664 for(
auto symbol : symbols )
683 msg.Printf(
_(
"Failed to create symbol library file \"%s\"" ),
689 wxArrayString libNames;
706 while( libNames.Index( libName ) != wxNOT_FOUND )
707 libNames.Remove( libName );
710 libNames.Insert( libName, 0 );
721 boost::ptr_vector<PART_LIB> libsSave;
722 libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
741 libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
756 wxCHECK_RET( aNewPart,
"Invalid LIB_PART pointer." );
766 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
787 m_pi.
set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
799 if( !
m_prj->SchSymbolLibTable()->HasLibrary( fn.GetName() ) )
803 m_pi->SaveLibrary( fn.GetFullPath() );
807 msg.Printf(
_(
"Failed to save rescue library %s." ), fn.GetFullPath() );
812 wxString uri =
"${KIPRJMOD}/" + fn.GetFullName();
813 wxString libNickname = fn.GetName();
817 libNickname.Replace(
" ",
"-" );
820 wxString(
"Legacy" ) );
821 m_prj->SchSymbolLibTable()->InsertRow( row );
827 m_prj->SchSymbolLibTable()->Save( fn.GetFullPath() );
831 msg.Printf(
_(
"Error occurred saving project specific symbol library table." ) );
841 if( !
m_prj->SchSymbolLibTable() )
853 wxCHECK_RET( aNewPart,
"Invalid LIB_PART pointer." );
859 if( !
m_prj->SchSymbolLibTable()->HasLibrary( fn.GetName() ) )
862 m_prj->SchSymbolLibTable()->SaveSymbol( fn.GetName(),
new LIB_PART( *aNewPart ) );
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
void SetLib(PART_LIB *aLibrary)
static const wxString & GetSymbolLibTableFileName()
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part's pins do not match another part's pins.
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Writes out the rescue library.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
virtual void FindCandidates()=0
Populate the RESCUER with all possible candidates.
const UTF8 & GetLibItemName() const
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
size_t GetChosenCandidateCount()
Get the number of resuce candidates chosen by the user.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_PART * m_cache_candidate
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
LIB_ID GetLibId() const override
Container for project specific data.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
This file is part of the common library.
const std::string LegacySymbolLibFileExtension
LIB_PART * m_cache_candidate
static wxFileName GetRescueLibraryFileName(SCHEMATIC *aSchematic)
virtual void OpenRescueLibrary() override
static bool sort_by_libid(const SCH_COMPONENT *ref, SCH_COMPONENT *cmp)
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain)=0
Display a dialog to allow the user to select rescues.
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
void set(SCH_PLUGIN *aPlugin)
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
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.
A logical library item identifier and consists of various portions much like a URI.
virtual const wxString GetProjectPath() const
Return the full path of the project.
SYMBOL_LIB_TABLE_RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
LIB_PART * m_lib_candidate
SCH_COMPONENT * component
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE()
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RemoveDuplicates()
Filter out duplicately named rescue candidates.
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
SCH_SHEET_PATH * m_currentSheet
virtual const wxString What() const
A composite of Problem() and Where()
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CACHE_CANDIDATE objectss into a vector.
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
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.
size_t GetCandidateCount()
Returen the number of rescue candidates found.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
Define a library symbol object.
Definition of file extensions used in Kicad.
std::pair< SCH_COMPONENT *, wxString > COMPONENT_NAME_PAIR
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
std::vector< SCH_COMPONENT * > m_components
static LIB_PART * find_component(const wxString &aName, PART_LIBS *aLibs, bool aCached)
Search the libraries for the first component with a given name.
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
virtual void OpenRescueLibrary()=0
void GetParts(std::vector< LIB_PART * > &aPart) const
Load a vector with all the entries in this library.
A collection of PART_LIB objects.
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
A filename or source description, a problem input line, a line number, a byte offset,...
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Writes out the rescue library.
std::unique_ptr< PART_LIB > m_rescue_lib
virtual void OpenRescueLibrary() override
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
SCH_SCREEN * LastScreen()
bool DoRescues()
Perform all chosen rescue actions, logging them to be undone if necessary.
SCHEMATIC * Schematic() const
virtual void AddPart(LIB_PART *aNewPart)=0
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Writes out the rescue library.
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
std::vector< RESCUE_LOG > m_rescue_log
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
wxString m_requested_name
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
virtual void AddPart(LIB_PART *aNewPart) override
LIB_PART * SchGetLibPart(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, PART_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.
Definition for part library class.
virtual void AddPart(LIB_PART *aNewPart) override
void UndoRescues()
Reverse the effects of all rescues on the project.
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_PART reference for each SCH_COMPONENT found in the full schematic.
const LIB_ID & GetLibId() const
Object used to load, save, search, and otherwise manipulate symbol library files.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
static void get_components(SCHEMATIC *aSchematic, std::vector< SCH_COMPONENT * > &aComponents)
Fill a vector with all of the project's symbols, to ease iterating over them.
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.