61 if( !wxFileName::IsDirWritable( projectPath ) )
64 wxString::Format(
_(
"Remapping is not possible because you have insufficient "
65 "privileges to the project folder '%s'." ),
76 text =
_(
"This schematic currently uses the project symbol library list look up method "
77 "for loading library symbols. KiCad will attempt to map the existing symbols "
78 "to use the new symbol library table. Remapping will change some project files "
79 "and schematics may not be compatible with older versions of KiCad. All files "
80 "that are changed will be backed up to the \"rescue-backup\" folder in the project "
81 "folder should you need to revert any changes. If you choose to skip this step, "
82 "you will be responsible for manually remapping the symbols." );
94 wxCHECK_RET( parent !=
nullptr,
"Parent window is not type SCH_EDIT_FRAME." );
113 viewer->ReCreateLibList();
125 wxFileName prjSymLibTableFileName(
Prj().GetProjectPath(),
129 if( prjSymLibTableFileName.FileExists() )
130 wxRemoveFile( prjSymLibTableFileName.GetFullPath() );
140 wxArrayString libNames;
157 for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
164 wxString libFileName = it->GetFullFileName();
167 aLibs.push_back( &(*it) );
176 std::vector<SYMBOL_LIB*> libs;
187 wxString libName = lib->GetName();
189 int libNameLen = libName.Length();
193 libName.Replace( wxS(
" " ), wxS(
"-" ) );
198 libName = libName.Left( libNameLen );
199 libName << libNameInc;
204 wxFileName fn( lib->GetFullFileName() );
210 wxFileName normalizedFn( normalizedPath );
214 && normalizedFn.FileExists() )
216 msg.Printf(
_(
"Adding library '%s', file '%s' to project symbol library table." ),
225 msg.Printf(
_(
"Library '%s' not found." ), normalizedPath );
238 libTable.
Format( &formatter, 0 );
242 msg.Printf(
_(
"Error writing project symbol library table.\n %s" ), ioe.
What() );
246 aReporter.
ReportTail(
_(
"Created project symbol library table.\n" ),
261 for( screen = schematic.
GetFirst(); screen; screen = schematic.
GetNext() )
267 wxCHECK2( symbol,
continue );
271 msg.Printf(
_(
"No symbol %s found in symbol library table." ),
277 msg.Printf(
_(
"Symbol %s mapped to symbol library '%s'." ),
293 wxCHECK_MSG( aSymbol !=
nullptr,
false,
"Null pointer passed to remapSymbolToLibTable." );
295 "Cannot remap symbol that is already mapped." );
297 "The symbol LIB_ID name is empty." );
301 for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
315 wxString libFileName = it->GetFullFileName();
338 static wxString backupFolder =
"rescue-backup";
342 wxFileName srcFileName;
343 wxFileName destFileName;
344 wxFileName backupPath;
348 destFileName.SetPath(
Prj().GetProjectPath() );
349 destFileName.AppendDir( backupFolder );
350 backupPath = destFileName;
352 if( !destFileName.DirExists() )
354 if( !destFileName.Mkdir() )
356 errorMsg.Printf(
_(
"Cannot create project remap back up folder '%s'." ),
357 destFileName.GetPath() );
359 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
360 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
361 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
362 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
364 if( dlg.ShowModal() == wxID_NO )
373 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
376 srcFileName.SetPath(
Prj().GetProjectPath() );
378 destFileName = srcFileName;
379 destFileName.AppendDir( backupFolder );
380 destFileName.SetName( destFileName.GetName() + timeStamp );
382 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
383 srcFileName.GetFullPath(),
384 destFileName.GetFullPath() );
387 if( wxFileName::Exists( srcFileName.GetFullPath() )
388 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
390 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ),
391 srcFileName.GetFullPath() );
398 destFileName = screen->GetFileName();
399 destFileName.SetName( destFileName.GetName() + timeStamp );
402 if( destFileName.GetPath() != backupPath.GetPath() )
404 destFileName.SetPath( backupPath.GetPath() );
406 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
407 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
409 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
410 destFileName.AppendDir( srcDirs[i] );
414 destFileName.AppendDir( backupFolder );
417 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
418 screen->GetFileName(),
419 destFileName.GetFullPath() );
422 if( !destFileName.DirExists() && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
424 tmp.Printf(
_(
"Failed to create backup folder '%s'.\n" ), destFileName.GetPath() );
429 if( wxFileName::Exists( screen->GetFileName() )
430 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
432 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), screen->GetFileName() );
439 destFileName.SetName( destFileName.GetName() + timeStamp );
440 destFileName.AppendDir( backupFolder );
442 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
443 Prj().GetProjectFullName(),
444 destFileName.GetFullPath() );
447 if( wxFileName::Exists(
Prj().GetProjectFullName() )
448 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
450 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ),
Prj().GetProjectFullName() );
455 srcFileName.SetPath(
Prj().GetProjectPath() );
456 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-cache" ) );
459 destFileName = srcFileName;
460 destFileName.SetName( destFileName.GetName() + timeStamp );
461 destFileName.AppendDir( backupFolder );
463 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
464 srcFileName.GetFullPath(),
465 destFileName.GetFullPath() );
468 if( srcFileName.Exists()
469 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
471 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
476 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-rescue" ) );
477 destFileName.SetName( srcFileName.GetName() + timeStamp );
479 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
480 srcFileName.GetFullPath(),
481 destFileName.GetFullPath() );
484 if( srcFileName.Exists()
485 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
487 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
493 destFileName.SetExt( srcFileName.GetExt() );
495 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
496 srcFileName.GetFullPath(),
497 destFileName.GetFullPath() );
500 if( srcFileName.Exists()
501 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
503 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
508 if( !errorMsg.IsEmpty() )
510 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
512 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
514 dlg.SetExtendedMessage( errorMsg );
515 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
516 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
518 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
A collection of SYMBOL_LIB objects.
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)
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.
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().