33#include <wx/filename.h>
34#include <wx/filedlg.h>
51 wxString fileFiltersStr;
52 wxString allWildcardsStr;
54 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
56 if(
fileType == SCH_IO_MGR::SCH_KICAD ||
fileType == SCH_IO_MGR::SCH_LEGACY )
69 if( !fileFiltersStr.IsEmpty() )
70 fileFiltersStr += wxChar(
'|' );
78 fileFiltersStr =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcardsStr + wxT(
"|" )
81 wxFileDialog dlg(
this,
_(
"Import Symbol" ),
m_mruPath, wxEmptyString, fileFiltersStr,
82 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
84 if( dlg.ShowModal() == wxID_CANCEL )
89 if( dlg.GetFilterIndex() == 0 )
96 wxArrayString symbols;
99 if( piType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
101 msg.Printf(
_(
"Unable to find a reader for '%s'." ), fn.GetFullPath() );
115 msg.Printf(
_(
"Cannot import symbol library '%s'." ), fn.GetFullPath() );
120 if( symbols.empty() )
122 msg.Printf(
_(
"Symbol library file '%s' is empty." ), fn.GetFullPath() );
127 wxString symbolName = symbols[0];
134 msg.Printf(
_(
"Symbol %s already exists in library '%s'." ), symbolName, libName );
136 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
137 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
140 if( errorDlg.
ShowModal() == wxID_CANCEL )
163 fn.SetName( symbol->
GetName().Lower() );
166 wxFileDialog dlg(
this,
_(
"Export Symbol" ),
m_mruPath, fn.GetFullName(),
169 if( dlg.ShowModal() == wxID_CANCEL )
178 if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
179 pluginType = SCH_IO_MGR::SCH_KICAD;
183 if( fn.FileExists() )
191 msg.Printf(
_(
"Error occurred attempting to load symbol library file '%s'." ),
199 msg.Printf(
_(
"Symbol %s already exists in library '%s'." ),
203 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
204 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
207 if( errorDlg.
ShowModal() == wxID_CANCEL )
212 if( fn.Exists() && !fn.IsDirWritable() )
214 msg.Printf(
_(
"Insufficient permissions to save library '%s'." ),
222 if( !fn.FileExists() )
232 msg.Printf(
_(
"Failed to create symbol library file '%s'." ), fn.GetFullPath() );
234 msg.Printf(
_(
"Error creating symbol library '%s'." ), fn.GetFullName() );
235 SetStatusText( msg );
241 msg.Printf(
_(
"Symbol %s saved to library '%s'." ),
244 SetStatusText( msg );
253 DisplayError(
this,
_(
"Could not open the library file." ) );
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
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()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Define a library symbol object.
wxString GetName() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
virtual void SetName(const wxString &aName)
SYMBOL_LIB_TABLE * SelectSymLibTable(bool aOptional=false)
Display a dialog asking the user to select a symbol library table.
wxString SelectLibraryFromList()
Display a list of loaded libraries and allows the user to select a library.
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Save Symbol Library Tables to disk.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
virtual const PLUGIN_FILE_DESC GetLibraryFileDesc() const
Returns symbol library description for the SCH_PLUGIN.
wxString getTargetLib() const
LIB_SYMBOL_LIBRARY_MANAGER * m_libMgr
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
void SyncLibraries(bool aShowProgress, bool aPreloadCancelled=false, const wxString &aForceRefresh=wxEmptyString)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
LIB_SYMBOL * getTargetSymbol() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Add an existing library.
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
const std::string KiCadSymbolLibFileExtension
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
const std::string LegacySymbolLibFileExtension
wxString KiCadSymbolLibFileWildcard()
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Container that describes file type info.
wxString FileFilter() const
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition for symbol library class.
Definition of file extensions used in Kicad.