57 if( !wxFileName::IsDirWritable(
Prj().GetProjectPath() ) )
60 "privileges to the project folder '%s'." ) );
68 text =
_(
"This schematic currently uses the project symbol library list look up method "
69 "for loading library symbols. KiCad will attempt to map the existing symbols "
70 "to use the new symbol library table. Remapping will change some project files "
71 "and schematics may not be compatible with older versions of KiCad. All files "
72 "that are changed will be backed up to the \"remap_backup\" folder in the project "
73 "folder should you need to revert any changes. If you choose to skip this step, "
74 "you will be responsible for manually remapping the symbols." );
86 wxCHECK_RET( parent !=
nullptr,
"Parent window is not type SCH_EDIT_FRAME." );
105 viewer->ReCreateLibList();
117 wxFileName prjSymLibTableFileName(
Prj().GetProjectPath(),
121 if( prjSymLibTableFileName.FileExists() )
122 wxRemoveFile( prjSymLibTableFileName.GetFullPath() );
126 Prj().SchSymbolLibTable();
132 wxArrayString libNames;
149 for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
156 wxString libFileName = it->GetFullFileName();
159 aLibs.push_back( &(*it) );
168 std::vector<SYMBOL_LIB*> libs;
179 wxString libName = lib->GetName();
181 int libNameLen = libName.Length();
185 libName.Replace( wxS(
" " ), wxS(
"-" ) );
190 libName = libName.Left( libNameLen );
191 libName << libNameInc;
196 wxFileName fn( lib->GetFullFileName() );
202 wxFileName normalizedFn( normalizedPath );
206 && normalizedFn.FileExists() )
208 msg.Printf(
_(
"Adding library '%s', file '%s' to project symbol library table." ),
217 msg.Printf(
_(
"Library '%s' not found." ), normalizedPath );
230 libTable.
Format( &formatter, 0 );
234 msg.Printf(
_(
"Error writing project symbol library table.\n %s" ), ioe.
What() );
238 aReporter.
ReportTail(
_(
"Created project symbol library table.\n" ),
253 for( screen = schematic.
GetFirst(); screen; screen = schematic.
GetNext() )
259 wxCHECK2( symbol,
continue );
263 msg.Printf(
_(
"No symbol %s found in symbol library table." ),
269 msg.Printf(
_(
"Symbol %s mapped to symbol library '%s'." ),
285 wxCHECK_MSG( aSymbol !=
nullptr,
false,
"Null pointer passed to remapSymbolToLibTable." );
287 "Cannot remap symbol that is already mapped." );
289 "The symbol LIB_ID name is empty." );
293 for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
307 wxString libFileName = it->GetFullFileName();
309 const LIB_TABLE_ROW* row =
Prj().SchSymbolLibTable()->FindRowByURI( libFileName );
330 static wxString backupFolder =
"rescue-backup";
334 wxFileName srcFileName;
335 wxFileName destFileName;
336 wxFileName backupPath;
340 destFileName.SetPath(
Prj().GetProjectPath() );
341 destFileName.AppendDir( backupFolder );
342 backupPath = destFileName;
344 if( !destFileName.DirExists() )
346 if( !destFileName.Mkdir() )
348 errorMsg.Printf(
_(
"Cannot create project remap back up folder '%s'." ),
349 destFileName.GetPath() );
351 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
352 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
353 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
354 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
356 if( dlg.ShowModal() == wxID_NO )
365 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
368 srcFileName.SetPath(
Prj().GetProjectPath() );
370 destFileName = srcFileName;
371 destFileName.AppendDir( backupFolder );
372 destFileName.SetName( destFileName.GetName() + timeStamp );
374 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
375 srcFileName.GetFullPath(),
376 destFileName.GetFullPath() );
379 if( wxFileName::Exists( srcFileName.GetFullPath() )
380 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
382 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ),
383 srcFileName.GetFullPath() );
390 destFileName = screen->GetFileName();
391 destFileName.SetName( destFileName.GetName() + timeStamp );
394 if( destFileName.GetPath() != backupPath.GetPath() )
396 destFileName.SetPath( backupPath.GetPath() );
398 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
399 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
401 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
402 destFileName.AppendDir( srcDirs[i] );
406 destFileName.AppendDir( backupFolder );
409 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
410 screen->GetFileName(),
411 destFileName.GetFullPath() );
414 if( !destFileName.DirExists() && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
416 tmp.Printf(
_(
"Failed to create backup folder '%s'.\n" ), destFileName.GetPath() );
421 if( wxFileName::Exists( screen->GetFileName() )
422 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
424 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), screen->GetFileName() );
431 destFileName.SetName( destFileName.GetName() + timeStamp );
432 destFileName.AppendDir( backupFolder );
434 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
435 Prj().GetProjectFullName(),
436 destFileName.GetFullPath() );
439 if( wxFileName::Exists(
Prj().GetProjectFullName() )
440 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
442 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ),
Prj().GetProjectFullName() );
447 srcFileName.SetPath(
Prj().GetProjectPath() );
448 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-cache" ) );
451 destFileName = srcFileName;
452 destFileName.SetName( destFileName.GetName() + timeStamp );
453 destFileName.AppendDir( backupFolder );
455 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
456 srcFileName.GetFullPath(),
457 destFileName.GetFullPath() );
460 if( srcFileName.Exists()
461 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
463 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
468 srcFileName.SetName(
Prj().GetProjectName() + wxS(
"-rescue" ) );
469 destFileName.SetName( srcFileName.GetName() + timeStamp );
471 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
472 srcFileName.GetFullPath(),
473 destFileName.GetFullPath() );
476 if( srcFileName.Exists()
477 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
479 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
485 destFileName.SetExt( srcFileName.GetExt() );
487 tmp.Printf(
_(
"Backing up file '%s' to '%s'." ),
488 srcFileName.GetFullPath(),
489 destFileName.GetFullPath() );
492 if( srcFileName.Exists()
493 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
495 tmp.Printf(
_(
"Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() );
500 if( !errorMsg.IsEmpty() )
502 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
504 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
506 dlg.SetExtendedMessage( errorMsg );
507 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
508 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
510 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 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
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.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
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
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_PLUGIN obje...
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.
const std::string LegacySymbolDocumentFileExtension
const std::string LegacySymbolLibFileExtension
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
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().