61 if( !wxFileName::IsDirWritable( projectPath ) )
63 wxString msg = wxString::Format(
_(
"Remapping is not possible because you have "
64 "insufficient privileges to the project folder '%s'." ),
75 text =
_(
"This schematic currently uses the project symbol library list look up method "
76 "for loading library symbols. KiCad will attempt to map the existing symbols "
77 "to use the new symbol library table. Remapping will change some project files "
78 "and schematics may not be compatible with older versions of KiCad. All files "
79 "that are changed will be backed up to the \"rescue-backup\" folder in the project "
80 "folder should you need to revert any changes. If you choose to skip this step, "
81 "you will be responsible for manually remapping the symbols." );
93 wxCHECK_RET( parent !=
nullptr,
"Parent window is not type SCH_EDIT_FRAME." );
112 viewer->ReCreateLibList();
127 if( prjSymLibTableFileName.FileExists() )
128 wxRemoveFile( prjSymLibTableFileName.GetFullPath() );
136 wxArrayString libNames;
160 wxString libFileName = lib.GetFullFileName();
163 aLibs.push_back( &lib );
176 wxCHECK( optTable, );
179 std::vector<LEGACY_SYMBOL_LIB*> libs;
188 wxString libName = lib->GetName();
190 int libNameLen = libName.Length();
194 libName.Replace( wxS(
" " ), wxS(
"-" ) );
199 libName = libName.Left( libNameLen );
200 libName << libNameInc;
205 wxFileName fn( lib->GetFullFileName() );
211 wxFileName normalizedFn( normalizedPath );
215 && normalizedFn.FileExists() )
217 aReporter.
Report( wxString::Format(
_(
"Adding library '%s', file '%s' to project "
218 "symbol library table." ),
225 newRow.
SetURI( normalizedPath );
230 aReporter.
Report( wxString::Format(
_(
"Library '%s' not found." ), normalizedPath ),
236 if( !projectTable->
Rows().empty() )
238 projectTable->
Save().map_error(
260 for( screen = schematic.
GetFirst(); screen; screen = schematic.
GetNext() )
266 wxCHECK2( symbol,
continue );
270 aReporter.
Report( wxString::Format(
_(
"No symbol %s found in symbol library "
277 aReporter.
Report( wxString::Format(
_(
"Symbol %s mapped to symbol library '%s'." ),
294 wxCHECK_MSG( aSymbol !=
nullptr,
false,
"Null pointer passed to remapSymbolToLibTable." );
296 "Cannot remap symbol that is already mapped." );
298 "The symbol LIB_ID name is empty." );
314 wxString libFileName = lib.GetFullFileName();
316 if( std::optional<wxString> nickname =
336 static wxString backupFolder =
"rescue-backup";
339 wxFileName srcFileName;
340 wxFileName destFileName;
341 wxFileName backupPath;
345 destFileName.SetPath(
Prj().GetProjectPath() );
346 destFileName.AppendDir( backupFolder );
347 backupPath = destFileName;
349 if( !destFileName.DirExists() )
351 if( !destFileName.Mkdir() )
353 errorMsg.Printf(
_(
"Cannot create project remap back up folder '%s'." ),
354 destFileName.GetPath() );
356 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
357 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
358 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
359 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
361 if( dlg.ShowModal() == wxID_NO )
370 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
373 srcFileName.SetPath(
Prj().GetProjectPath() );
375 destFileName = srcFileName;
376 destFileName.AppendDir( backupFolder );
377 destFileName.SetName( destFileName.GetName() + timeStamp );
379 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
380 srcFileName.GetFullPath(),
381 destFileName.GetFullPath() ),
384 if( wxFileName::Exists( srcFileName.GetFullPath() )
385 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
387 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
388 srcFileName.GetFullPath() );
394 destFileName = screen->GetFileName();
395 destFileName.SetName( destFileName.GetName() + timeStamp );
398 if( destFileName.GetPath() != backupPath.GetPath() )
400 destFileName.SetPath( backupPath.GetPath() );
402 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
403 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
405 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
406 destFileName.AppendDir( srcDirs[i] );
410 destFileName.AppendDir( backupFolder );
413 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
414 screen->GetFileName(),
415 destFileName.GetFullPath() ),
418 if( !destFileName.DirExists()
419 && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
421 errorMsg += wxString::Format(
_(
"Failed to create backup folder '%s'.\n" ),
422 destFileName.GetPath() );
426 if( wxFileName::Exists( screen->GetFileName() )
427 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
429 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
430 screen->GetFileName() );
436 destFileName.SetName( destFileName.GetName() + timeStamp );
437 destFileName.AppendDir( backupFolder );
439 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
440 Prj().GetProjectFullName(),
441 destFileName.GetFullPath() ),
444 if( wxFileName::Exists(
Prj().GetProjectFullName() )
445 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
447 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
448 Prj().GetProjectFullName() );
452 srcFileName.SetPath(
Prj().GetProjectPath() );
453 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-cache" ) );
456 destFileName = srcFileName;
457 destFileName.SetName( destFileName.GetName() + timeStamp );
458 destFileName.AppendDir( backupFolder );
460 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
461 srcFileName.GetFullPath(),
462 destFileName.GetFullPath() ),
465 if( srcFileName.Exists()
466 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
468 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
469 srcFileName.GetFullPath() );
473 srcFileName.SetPath(
Prj().GetProjectPath() );
474 srcFileName.SetName(
Prj().GetProjectName() + wxS(
".cache" ) );
477 destFileName = srcFileName;
478 destFileName.SetName( destFileName.GetName() + timeStamp );
479 destFileName.AppendDir( backupFolder );
481 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
482 srcFileName.GetFullPath(),
483 destFileName.GetFullPath() ),
486 if( srcFileName.Exists()
487 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
489 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
490 srcFileName.GetFullPath() );
494 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-rescue" ) );
495 destFileName.SetName( srcFileName.GetName() + timeStamp );
497 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
498 srcFileName.GetFullPath(),
499 destFileName.GetFullPath() ),
502 if( srcFileName.Exists()
503 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
505 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
506 srcFileName.GetFullPath() );
511 destFileName.SetExt( srcFileName.GetExt() );
513 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
514 srcFileName.GetFullPath(),
515 destFileName.GetFullPath() ),
518 if( srcFileName.Exists()
519 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
521 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
522 srcFileName.GetFullPath() );
526 if( !errorMsg.IsEmpty() )
528 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
530 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
532 dlg.SetExtendedMessage( errorMsg );
533 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
534 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
536 if( dlg.ShowModal() == wxID_NO )
void SetContentModified(bool aModified=true)
DIALOG_SYMBOL_REMAP_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Remap Symbols"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
WX_HTML_REPORT_PANEL * m_messagePanel
void OnUpdateUIRemapButton(wxUpdateUIEvent &aEvent) override
void remapSymbolsToLibTable(REPORTER &aReporter)
size_t getLibsNotInGlobalSymbolLibTable(std::vector< LEGACY_SYMBOL_LIB * > &aLibs)
Add libraries found in the legacy library list to aLibs that are not found in the global symbol libra...
void createProjectSymbolLibTable(REPORTER &aReporter)
bool remapSymbolToLibTable(SCH_SYMBOL *aSymbol)
DIALOG_SYMBOL_REMAP(SCH_EDIT_FRAME *aParent)
void OnRemapSymbols(wxCommandEvent &aEvent) override
bool backupProject(REPORTER &aReporter)
Backup all of the files that could be modified by the remapping with a time stamp appended to the fil...
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
EE_TYPE OfType(KICAD_T aType) const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
Object used to load, save, search, and otherwise manipulate symbol library files.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
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 * > FindRowByURI(LIBRARY_TABLE_TYPE aType, const wxString &aUri, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
void ProjectChanged()
Notify all adapters that the project has changed.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
LIBRARY_RESULT< void > Save()
LIBRARY_TABLE_ROW & InsertRow()
Builds a new row and inserts it at the end of the table; returning a reference to the row.
const std::vector< LIBRARY_TABLE_ROW > & Rows() const
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
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...
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
virtual const wxString GetProjectPath() const
Return the full path of the project.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SyncView()
Mark all items for refresh.
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
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.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
void SetLibId(const LIB_ID &aName)
const LIB_ID & GetLibId() const override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Symbol library viewer main window.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
This file is part of the common library.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Helper functions to substitute paths with environmental variables.
static const std::string SymbolLibraryTableFileName
static const std::string LegacySymbolLibFileExtension
static const std::string LegacySymbolDocumentFileExtension
This file contains miscellaneous commonly used macros and functions.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().