56 if( !wxFileName::IsDirWritable(
Prj().GetProjectPath() ) )
59 "write privileges to the project folder \"%s\"." ) );
67 text =
_(
"This schematic currently uses the project symbol library list look up method " 68 "for loading library symbols. KiCad will attempt to map the existing symbols " 69 "to use the new symbol library table. Remapping will change some project files " 70 "and schematics may not be compatible with older versions of KiCad. All files " 71 "that are changed will be backed up to the \"remap_backup\" folder in the project " 72 "folder should you need to revert any changes. If you choose to skip this step, " 73 "you will be responsible for manually remapping the symbols." );
83 SCH_EDIT_FRAME* parent = dynamic_cast< SCH_EDIT_FRAME* >( GetParent() );
85 wxCHECK_RET( parent !=
nullptr,
"Parent window is not type SCH_EDIT_FRAME." );
103 viewer->ReCreateLibList();
114 wxFileName prjSymLibTableFileName(
Prj().GetProjectPath(),
118 if( prjSymLibTableFileName.FileExists() )
120 wxRemoveFile( prjSymLibTableFileName.GetFullPath() );
125 Prj().SchSymbolLibTable();
131 wxArrayString libNames;
148 for( PART_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
155 wxString libFileName = it->GetFullFileName();
158 aLibs.push_back( &(*it) );
168 std::vector< PART_LIB* > libs;
175 for(
auto lib : libs )
177 wxString libName = lib->GetName();
179 int libNameLen = libName.Length();
183 libName.Replace(
" ",
"-" );
188 libName = libName.Left( libNameLen );
189 libName << libNameInc;
194 wxFileName fn = lib->GetFullFileName();
202 if( fullFileName.IsEmpty() )
203 fullFileName = lib->GetFullFileName();
205 wxFileName tmpFn = fullFileName;
208 if( tmpFn.Normalize() && tmpFn.FileExists() )
210 msg.Printf(
_(
"Adding library \"%s\", file \"%s\" to project symbol library table." ),
211 libName, fullFileName );
219 msg.Printf(
_(
"Library \"%s\" not found." ), fullFileName );
232 prjLibTable.
Format( &formatter, 0 );
236 msg.Printf(
_(
"Failed to write project symbol library table. Error:\n %s" ),
254 for( screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
258 symbol = dynamic_cast<SCH_COMPONENT*>( item );
262 msg.Printf(
_(
"No symbol \"%s\" found in symbol library table." ),
263 symbol->GetLibId().GetLibItemName().wx_str() );
268 msg.Printf(
_(
"Symbol \"%s\" mapped to symbol library \"%s\"." ),
269 symbol->GetLibId().GetLibItemName().wx_str(),
270 symbol->GetLibId().GetLibNickname().wx_str() );
278 schematic.UpdateSymbolLinks();
284 wxCHECK_MSG( aSymbol !=
NULL,
false,
"Null pointer passed to remapSymbolToLibTable." );
286 "Cannot remap symbol that is already mapped." );
288 "The symbol LIB_ID name is empty." );
292 for( PART_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
306 wxString libFileName = it->GetFullFileName();
308 const LIB_TABLE_ROW* row =
Prj().SchSymbolLibTable()->FindRowByURI( libFileName );
329 static wxString backupFolder =
"rescue-backup";
333 wxFileName srcFileName;
334 wxFileName destFileName;
335 wxFileName backupPath;
339 destFileName.SetPath(
Prj().GetProjectPath() );
340 destFileName.AppendDir( backupFolder );
341 backupPath = destFileName;
343 if( !destFileName.DirExists() )
345 if( !destFileName.Mkdir() )
347 errorMsg.Printf(
_(
"Cannot create project remap back up folder \"%s\"." ),
348 destFileName.GetPath() );
350 wxMessageDialog dlg(
this, errorMsg,
_(
"Backup Error" ),
351 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
352 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
353 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
355 if( dlg.ShowModal() == wxID_NO )
361 wxString timeStamp = wxDateTime::Now().Format(
"-%Y-%m-%d-%H-%M-%S" );
364 srcFileName.SetPath(
Prj().GetProjectPath() );
366 destFileName = srcFileName;
367 destFileName.AppendDir( backupFolder );
368 destFileName.SetName( destFileName.GetName() + timeStamp );
370 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
371 srcFileName.GetFullPath(), destFileName.GetFullPath() );
374 if( wxFileName::Exists( srcFileName.GetFullPath() )
375 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
377 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() );
382 for(
SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
384 destFileName = screen->GetFileName();
385 destFileName.SetName( destFileName.GetName() + timeStamp );
388 if( destFileName.GetPath() != backupPath.GetPath() )
390 destFileName.SetPath( backupPath.GetPath() );
392 wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
393 wxArrayString destDirs = wxFileName(
Prj().GetProjectPath() ).GetDirs();
395 for(
size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
396 destFileName.AppendDir( srcDirs[i] );
400 destFileName.AppendDir( backupFolder );
403 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
404 screen->GetFileName(), destFileName.GetFullPath() );
407 if( !destFileName.DirExists() && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
409 tmp.Printf(
_(
"Failed to create backup folder \"%s\"\n" ), destFileName.GetPath() );
414 if( wxFileName::Exists( screen->GetFileName() )
415 && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
417 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ), screen->GetFileName() );
424 destFileName.SetName( destFileName.GetName() + timeStamp );
425 destFileName.AppendDir( backupFolder );
427 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
428 Prj().GetProjectFullName(), destFileName.GetFullPath() );
431 if( wxFileName::Exists(
Prj().GetProjectFullName() )
432 && !wxCopyFile(
Prj().GetProjectFullName(), destFileName.GetFullPath() ) )
434 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ),
Prj().GetProjectFullName() );
439 srcFileName.SetPath(
Prj().GetProjectPath() );
440 srcFileName.SetName(
Prj().GetProjectName() +
"-cache" );
443 destFileName = srcFileName;
444 destFileName.SetName( destFileName.GetName() + timeStamp );
445 destFileName.AppendDir( backupFolder );
447 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
448 srcFileName.GetFullPath(), destFileName.GetFullPath() );
451 if( srcFileName.Exists()
452 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
454 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() );
459 srcFileName.SetName(
Prj().GetProjectName() +
"-rescue" );
460 destFileName.SetName( srcFileName.GetName() + timeStamp );
462 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
463 srcFileName.GetFullPath(),
464 destFileName.GetFullPath() );
467 if( srcFileName.Exists()
468 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
470 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() );
475 srcFileName.SetExt(
"dcm" );
476 destFileName.SetExt( srcFileName.GetExt() );
478 tmp.Printf(
_(
"Backing up file \"%s\" to file \"%s\"." ),
479 srcFileName.GetFullPath(),
480 destFileName.GetFullPath() );
483 if( srcFileName.Exists()
484 && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) )
486 tmp.Printf(
_(
"Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() );
490 if( !errorMsg.IsEmpty() )
492 wxMessageDialog dlg(
this,
_(
"Some of the project files could not be backed up." ),
494 wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION );
496 dlg.SetExtendedMessage( errorMsg );
497 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Continue with Rescue" ) ),
498 wxMessageDialog::ButtonLabel(
_(
"Abort Rescue" ) ) );
500 if( dlg.ShowModal() == wxID_NO )
EE_TYPE OfType(KICAD_T aType) const
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
wxHtmlWindow * m_htmlCtrl
const UTF8 & GetLibItemName() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
void SetLibId(const LIB_ID &aName)
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
void OnUpdateUIRemapButton(wxUpdateUIEvent &aEvent) override
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
This file is part of the common library.
const std::string LegacySymbolLibFileExtension
size_t getLibsNotInGlobalSymbolLibTable(std::vector< PART_LIB * > &aLibs)
Add libraries found in the legacy library list to aLibs that are not found in the global symbol libra...
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
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.
Symbol library viewer main window.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Schematic editor (Eeschema) main window.
A pure virtual class used to derive REPORTER objects from.
A logical library item identifier and consists of various portions much like a URI.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
This file contains miscellaneous commonly used macros and functions.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Class DIALOG_SYMBOL_REMAP_BASE.
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
const wxString & GetNickName() const
void OnRemapSymbols(wxCommandEvent &aEvent) override
void createProjectSymbolLibTable(REPORTER &aReporter)
virtual const wxString What() const
A composite of Problem() and Where()
void SyncView()
Mark all items for refresh.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void remapSymbolsToLibTable(REPORTER &aReporter)
SCHEMATIC & Schematic() const
Define a library symbol object.
Definition of file extensions used in Kicad.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
DIALOG_SYMBOL_REMAP(SCH_EDIT_FRAME *aParent)
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
WX_HTML_REPORT_PANEL * m_messagePanel
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
A collection of PART_LIB objects.
bool backupProject(REPORTER &aReporter)
Backup all of the files that could be modified by the remapping with a time stamp appended to the fil...
bool remapSymbolToLibTable(SCH_COMPONENT *aSymbol)
SCH_SHEET_PATH & GetCurrentSheet() const
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
Definition for part library class.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
void SetFileName(const wxString &aReportFileName)
const LIB_ID & GetLibId() const
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.