31#include <wx/filename.h>
32#include <wx/filedlg.h>
42 if( !
m_libMgr->LibraryExists( libName ) )
43 libName =
SelectLibrary(
_(
"Import Symbol" ),
_(
"Import symbol to library:" ) );
45 if( !
m_libMgr->LibraryExists( libName ) )
48 wxString fileFiltersStr;
49 wxString allWildcardsStr;
51 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
63 if( !fileFiltersStr.IsEmpty() )
64 fileFiltersStr += wxChar(
'|' );
72 fileFiltersStr =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcardsStr + wxT(
"|" )
75 wxFileDialog fileDlg(
this,
_(
"Import Symbol" ),
m_mruPath, wxEmptyString, fileFiltersStr,
76 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
80 if( fileDlg.ShowModal() == wxID_CANCEL )
83 wxFileName fn( fileDlg.GetPath() );
89 if( piType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
91 msg.Printf(
_(
"Unable to find a reader for '%s'." ), fn.GetFullPath() );
103 if( selectedSymbols.empty() )
110 wxString firstImported;
111 int importedCount = 0;
112 int skippedCount = 0;
114 for(
const wxString& symbolName : selectedSymbols )
116 auto conflictIt = conflictResolutions.find( symbolName );
118 if( conflictIt != conflictResolutions.end()
127 LIB_SYMBOL* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName );
132 m_libMgr->UpdateSymbol( entry, libName );
134 if( firstImported.IsEmpty() )
135 firstImported = entry->
GetName();
142 msg.Printf(
_(
"Cannot import symbol '%s': %s" ), symbolName, ioe.
What() );
147 if( importedCount > 0 )
152 if( skippedCount > 0 )
154 msg.Printf(
_(
"Imported %d symbol(s), skipped %d." ), importedCount, skippedCount );
Dialog to select symbols for import from an external library file.
std::vector< wxString > GetSelectedSymbols() const
Get the list of symbols selected for import.
const std::map< wxString, CONFLICT_RESOLUTION > & GetConflictResolutions() const
Get the conflict resolutions chosen by the user.
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()
Define a library symbol object.
wxString GetName() const override
virtual void SetName(const wxString &aName)
wxString SelectLibrary(const wxString &aDialogTitle, const wxString &aListLabel, const std::vector< std::pair< wxString, bool * > > &aExtraCheckboxes={})
Display a list of loaded libraries and allows the user to select a library.
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.
wxString getTargetLib() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
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 ...
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
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.
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
wxString FileFilter() const
@ SKIP
Don't import this symbol.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
Definition of file extensions used in Kicad.