35#include <wx/filename.h>
36#include <wx/filedlg.h>
45 if( !
m_libMgr->LibraryExists( libName ) )
46 libName =
SelectLibrary(
_(
"Import Symbol" ),
_(
"Import symbol to library:" ) );
48 if( !
m_libMgr->LibraryExists( libName ) )
51 wxString fileFiltersStr;
52 wxString allWildcardsStr;
54 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
66 if( !fileFiltersStr.IsEmpty() )
67 fileFiltersStr += wxChar(
'|' );
75 fileFiltersStr =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcardsStr + wxT(
"|" )
78 wxFileDialog fileDlg(
this,
_(
"Import Symbol" ),
m_mruPath, wxEmptyString, fileFiltersStr,
79 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
81 if( fileDlg.ShowModal() == wxID_CANCEL )
84 wxFileName fn( fileDlg.GetPath() );
90 if( piType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
92 msg.Printf(
_(
"Unable to find a reader for '%s'." ), fn.GetFullPath() );
104 if( selectedSymbols.empty() )
111 wxString firstImported;
112 int importedCount = 0;
113 int skippedCount = 0;
115 for(
const wxString& symbolName : selectedSymbols )
117 auto conflictIt = conflictResolutions.find( symbolName );
119 if( conflictIt != conflictResolutions.end()
128 LIB_SYMBOL* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName );
133 m_libMgr->UpdateSymbol( entry, libName );
135 if( firstImported.IsEmpty() )
136 firstImported = entry->
GetName();
143 msg.Printf(
_(
"Cannot import symbol '%s': %s" ), symbolName, ioe.
What() );
148 if( importedCount > 0 )
153 if( skippedCount > 0 )
155 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
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.