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();
124 wxFileName prjSymLibTableFileName(
Prj().GetProjectPath(),
128 if( prjSymLibTableFileName.FileExists() )
129 wxRemoveFile( prjSymLibTableFileName.GetFullPath() );
139 wxArrayString libNames;
161 wxString libFileName = lib.GetFullFileName();
164 aLibs.push_back( &lib );
173 std::vector<SYMBOL_LIB*> libs;
183 wxString libName = lib->GetName();
185 int libNameLen = libName.Length();
189 libName.Replace( wxS(
" " ), wxS(
"-" ) );
194 libName = libName.Left( libNameLen );
195 libName << libNameInc;
200 wxFileName fn( lib->GetFullFileName() );
206 wxFileName normalizedFn( normalizedPath );
210 && normalizedFn.FileExists() )
212 aReporter.
Report( wxString::Format(
_(
"Adding library '%s', file '%s' to project "
213 "symbol library table." ),
222 aReporter.
Report( wxString::Format(
_(
"Library '%s' not found." ),
236 libTable.
Format( &formatter, 0 );
240 aReporter.
ReportTail( wxString::Format(
_(
"Error writing project symbol library "
246 aReporter.
ReportTail(
_(
"Created project symbol library table.\n" ),
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();
338 static wxString backupFolder =
"rescue-backup";
341 wxFileName srcFileName;
342 wxFileName destFileName;
343 wxFileName backupPath;
347 destFileName.SetPath(
Prj().GetProjectPath() );
348 destFileName.AppendDir( backupFolder );
349 backupPath = destFileName;
351 if( !destFileName.DirExists() )
353 if( !destFileName.Mkdir() )
355 errorMsg.Printf(
_(
"Cannot create project remap back up folder '%s'." ),
356 destFileName.GetPath() );
358 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
359 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
360 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
361 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
363 if( dlg.ShowModal() == wxID_NO )
372 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
375 srcFileName.SetPath(
Prj().GetProjectPath() );
377 destFileName = srcFileName;
378 destFileName.AppendDir( backupFolder );
379 destFileName.SetName( destFileName.GetName() + timeStamp );
381 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
382 srcFileName.GetFullPath(),
383 destFileName.GetFullPath() ),
386 if( wxFileName::Exists( srcFileName.GetFullPath() )
387 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
389 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
390 srcFileName.GetFullPath() );
396 destFileName = screen->GetFileName();
397 destFileName.SetName( destFileName.GetName() + timeStamp );
400 if( destFileName.GetPath() != backupPath.GetPath() )
402 destFileName.SetPath( backupPath.GetPath() );
404 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
405 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
407 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
408 destFileName.AppendDir( srcDirs[i] );
412 destFileName.AppendDir( backupFolder );
415 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
416 screen->GetFileName(),
417 destFileName.GetFullPath() ),
420 if( !destFileName.DirExists()
421 && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
423 errorMsg += wxString::Format(
_(
"Failed to create backup folder '%s'.\n" ),
424 destFileName.GetPath() );
428 if( wxFileName::Exists( screen->GetFileName() )
429 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
431 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
432 screen->GetFileName() );
438 destFileName.SetName( destFileName.GetName() + timeStamp );
439 destFileName.AppendDir( backupFolder );
441 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
442 Prj().GetProjectFullName(),
443 destFileName.GetFullPath() ),
446 if( wxFileName::Exists(
Prj().GetProjectFullName() )
447 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
449 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
450 Prj().GetProjectFullName() );
454 srcFileName.SetPath(
Prj().GetProjectPath() );
455 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-cache" ) );
458 destFileName = srcFileName;
459 destFileName.SetName( destFileName.GetName() + timeStamp );
460 destFileName.AppendDir( backupFolder );
462 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
463 srcFileName.GetFullPath(),
464 destFileName.GetFullPath() ),
467 if( srcFileName.Exists()
468 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
470 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
471 srcFileName.GetFullPath() );
475 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-rescue" ) );
476 destFileName.SetName( srcFileName.GetName() + timeStamp );
478 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
479 srcFileName.GetFullPath(),
480 destFileName.GetFullPath() ),
483 if( srcFileName.Exists()
484 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
486 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
487 srcFileName.GetFullPath() );
492 destFileName.SetExt( srcFileName.GetExt() );
494 aReporter.
Report( wxString::Format(
_(
"Backing up file '%s' to '%s'." ),
495 srcFileName.GetFullPath(),
496 destFileName.GetFullPath() ),
499 if( srcFileName.Exists()
500 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
502 errorMsg += wxString::Format(
_(
"Failed to back up file '%s'.\n" ),
503 srcFileName.GetFullPath() );
507 if( !errorMsg.IsEmpty() )
509 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
511 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
513 dlg.SetExtendedMessage( errorMsg );
514 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
515 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
517 if( dlg.ShowModal() == wxID_NO )
void SetContentModified(bool aModified=true)
Class DIALOG_SYMBOL_REMAP_BASE.
WX_HTML_REPORT_PANEL * m_messagePanel
void OnUpdateUIRemapButton(wxUpdateUIEvent &aEvent) override
void remapSymbolsToLibTable(REPORTER &aReporter)
void createProjectSymbolLibTable(REPORTER &aReporter)
bool remapSymbolToLibTable(SCH_SYMBOL *aSymbol)
size_t getLibsNotInGlobalSymbolLibTable(std::vector< SYMBOL_LIB * > &aLibs)
Add libraries found in the legacy library list to aLibs that are not found in the global symbol libra...
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
bool AppendToPage(const wxString &aSource)
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()
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.
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.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetNickName() const
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
static SYMBOL_LIBS * SchLibs(PROJECT *aProject)
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 & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
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()
Gets the full RTree, usually for iterating.
void SetLibId(const LIB_ID &aName)
const LIB_ID & GetLibId() const override
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString GetSymbolLibTableFileName()
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
Object used to load, save, search, and otherwise manipulate symbol library files.
Symbol library viewer main window.
void SetFileName(const wxString &aReportFileName)
Set the report full file name to the string.
REPORTER & Reporter()
Return the reporter object that reports to this panel.
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 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 for symbol library class.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().