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() );
139 wxArrayString libNames;
163 wxString libFileName = lib.GetFullFileName();
166 aLibs.push_back( &lib );
177 std::optional<LIBRARY_TABLE*> optTable =
179 wxCHECK( optTable, );
182 std::vector<LEGACY_SYMBOL_LIB*> libs;
191 wxString libName = lib->GetName();
193 int libNameLen = libName.Length();
197 libName.Replace( wxS(
" " ), wxS(
"-" ) );
202 libName = libName.Left( libNameLen );
203 libName << libNameInc;
208 wxFileName fn( lib->GetFullFileName() );
214 wxFileName normalizedFn( normalizedPath );
218 && normalizedFn.FileExists() )
220 aReporter.
Report( wxString::Format(
_(
"Adding library '%s', file '%s' to project "
221 "symbol library table." ),
228 newRow.
SetURI( normalizedPath );
233 aReporter.
Report( wxString::Format(
_(
"Library '%s' not found." ),
240 if( !projectTable->
Rows().empty() )
242 projectTable->
Save().map_error(
245 aReporter.
ReportTail( wxString::Format(
_(
"Error saving project-specific library table:\n\n%s" ),
252 aReporter.
ReportTail(
_(
"Created project symbol library table.\n" ),
266 for( screen = schematic.
GetFirst(); screen; screen = schematic.
GetNext() )
272 wxCHECK2( symbol,
continue );
276 aReporter.
Report( wxString::Format(
_(
"No symbol %s found in symbol library "
283 aReporter.
Report( wxString::Format(
_(
"Symbol %s mapped to symbol library '%s'." ),
300 wxCHECK_MSG( aSymbol !=
nullptr,
false,
"Null pointer passed to remapSymbolToLibTable." );
302 "Cannot remap symbol that is already mapped." );
304 "The symbol LIB_ID name is empty." );
320 wxString libFileName = lib.GetFullFileName();
322 if( std::optional<wxString> nickname =
342 static wxString backupFolder =
"rescue-backup";
345 wxFileName srcFileName;
346 wxFileName destFileName;
347 wxFileName backupPath;
351 destFileName.SetPath(
Prj().GetProjectPath() );
352 destFileName.AppendDir( backupFolder );
353 backupPath = destFileName;
355 if( !destFileName.DirExists() )
357 if( !destFileName.Mkdir() )
359 errorMsg.Printf(
_(
"Cannot create project remap back up folder '%s'." ),
360 destFileName.GetPath() );
362 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
363 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
364 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
365 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
367 if( dlg.ShowModal() == wxID_NO )
376 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
379 srcFileName.SetPath(
Prj().GetProjectPath() );
381 destFileName = srcFileName;
382 destFileName.AppendDir( backupFolder );
383 destFileName.SetName( destFileName.GetName() + timeStamp );
385 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
386 srcFileName.GetFullPath(),
387 destFileName.GetFullPath() ),
390 if( wxFileName::Exists( srcFileName.GetFullPath() )
391 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
393 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
394 srcFileName.GetFullPath() );
400 destFileName = screen->GetFileName();
401 destFileName.SetName( destFileName.GetName() + timeStamp );
404 if( destFileName.GetPath() != backupPath.GetPath() )
406 destFileName.SetPath( backupPath.GetPath() );
408 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
409 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
411 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
412 destFileName.AppendDir( srcDirs[i] );
416 destFileName.AppendDir( backupFolder );
419 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
420 screen->GetFileName(),
421 destFileName.GetFullPath() ),
424 if( !destFileName.DirExists()
425 && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
427 errorMsg += wxString::Format(
_(
"Failed to create backup folder '%s'.\n" ),
428 destFileName.GetPath() );
432 if( wxFileName::Exists( screen->GetFileName() )
433 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
435 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
436 screen->GetFileName() );
442 destFileName.SetName( destFileName.GetName() + timeStamp );
443 destFileName.AppendDir( backupFolder );
445 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
446 Prj().GetProjectFullName(),
447 destFileName.GetFullPath() ),
450 if( wxFileName::Exists(
Prj().GetProjectFullName() )
451 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
453 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
454 Prj().GetProjectFullName() );
458 srcFileName.SetPath(
Prj().GetProjectPath() );
459 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-cache" ) );
462 destFileName = srcFileName;
463 destFileName.SetName( destFileName.GetName() + timeStamp );
464 destFileName.AppendDir( backupFolder );
466 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
467 srcFileName.GetFullPath(),
468 destFileName.GetFullPath() ),
471 if( srcFileName.Exists()
472 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
474 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
475 srcFileName.GetFullPath() );
479 srcFileName.SetPath(
Prj().GetProjectPath() );
480 srcFileName.SetName(
Prj().GetProjectName() + wxS(
".cache" ) );
483 destFileName = srcFileName;
484 destFileName.SetName( destFileName.GetName() + timeStamp );
485 destFileName.AppendDir( backupFolder );
487 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
488 srcFileName.GetFullPath(),
489 destFileName.GetFullPath() ),
492 if( srcFileName.Exists()
493 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
495 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
496 srcFileName.GetFullPath() );
500 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-rescue" ) );
501 destFileName.SetName( srcFileName.GetName() + timeStamp );
503 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
504 srcFileName.GetFullPath(),
505 destFileName.GetFullPath() ),
508 if( srcFileName.Exists()
509 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
511 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
512 srcFileName.GetFullPath() );
517 destFileName.SetExt( srcFileName.GetExt() );
519 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
520 srcFileName.GetFullPath(),
521 destFileName.GetFullPath() ),
524 if( srcFileName.Exists()
525 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
527 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
528 srcFileName.GetFullPath() );
532 if( !errorMsg.IsEmpty() )
534 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
536 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
538 dlg.SetExtendedMessage( errorMsg );
539 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
540 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
542 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().