43 #include <lib_table_lexer.h> 93 static const std::map<int, SUPPORTED_FILE_TYPE>&
fileTypes()
102 static const std::map<int, SUPPORTED_FILE_TYPE>
fileTypes =
146 virtual wxDirTraverseResult
OnFile(
const wxString& aFileName )
override 148 wxFileName file( aFileName );
153 return wxDIR_CONTINUE;
156 virtual wxDirTraverseResult
OnOpenError(
const wxString& aOpenErrorName )
override 167 virtual wxDirTraverseResult
OnDir(
const wxString& aDirName )
override 170 return wxDIR_CONTINUE;
175 for( std::pair<const wxString, int>& foundDirsPair :
m_foundDirs )
176 aPathArray.Add( foundDirsPair.first );
181 for( std::pair<const wxString, int>& failedDirsPair :
m_failedDirs )
182 aPathArray.Add( failedDirsPair.first );
204 size_t size()
const override {
return rows.size(); }
215 return rows.insert( aIterator, aRow );
222 return rows.erase( aFirst, aLast );
234 #define MYID_OPTIONS_EDITOR 15151 256 wxString result = options;
261 if( options != result )
285 menu.AppendSeparator();
304 size_t ndx = cb_text.find(
"(fp_lib_table" );
306 if( ndx != std::string::npos )
312 LIB_TABLE_LEXER lexer( &slr );
318 tmp_tbl.
Parse( &lexer );
332 for(
unsigned i = 0; i < tmp_tbl.
GetCount(); ++i )
336 m_grid->AutoSizeColumns(
false );
343 m_grid->AutoSizeColumns(
false );
351 FP_LIB_TABLE* aProject,
const wxString& aProjectTblPath,
352 const wxString& aProjectBasePath ) :
355 m_project( aProject ),
356 m_projectBasePath( aProjectBasePath ),
364 wxArrayString choices;
385 aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
390 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
391 aGrid->AutoSizeColumns(
false );
393 wxGridCellAttr* attr;
395 attr =
new wxGridCellAttr;
400 aGrid->SetColAttr(
COL_URI, attr );
402 attr =
new wxGridCellAttr;
403 attr->SetEditor(
new wxGridCellChoiceEditor( choices ) );
404 aGrid->SetColAttr(
COL_TYPE, attr );
406 attr =
new wxGridCellAttr;
407 attr->SetRenderer(
new wxGridCellBoolRenderer() );
413 aGrid->AutoSizeColumn(
COL_TYPE,
false );
414 aGrid->AutoSizeColumn(
COL_URI,
false );
415 aGrid->AutoSizeColumn(
COL_DESCR,
false );
422 if( aGrid->GetNumberRows() > 0 )
423 aGrid->SelectRow( 0 );
516 for(
int r = 0; r < model->GetNumberRows(); )
518 wxString nick = model->GetValue( r,
COL_NICKNAME ).Trim(
false ).Trim();
519 wxString uri = model->GetValue( r,
COL_URI ).Trim(
false ).Trim();
520 unsigned illegalCh = 0;
528 model->DeleteRows( r, 1 );
532 wxString msg =
wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ),
543 wxMessageDialog errdlg(
this, msg,
_(
"Library Nickname Error" ) );
551 model->SetValue( r,
COL_URI, uri );
563 for(
int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
567 for(
int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
574 "nickname ('%s')." ),
585 wxMessageDialog errdlg(
this, msg,
_(
"Library Nickname Error" ) );
611 int last_row =
m_cur_grid->GetNumberRows() - 1;
635 wxArrayInt selectedRows =
m_cur_grid->GetSelectedRows();
636 wxGridCellCoordsArray cells =
m_cur_grid->GetSelectedCells();
637 wxGridCellCoordsArray blockTopLeft =
m_cur_grid->GetSelectionBlockTopLeft();
638 wxGridCellCoordsArray blockBotRight =
m_cur_grid->GetSelectionBlockBottomRight();
641 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
642 selectedRows.Add( cells[ii].GetRow() );
645 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
647 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
648 selectedRows.Add( i );
652 if( selectedRows.size() == 0 &&
m_cur_grid->GetGridCursorRow() >= 0 )
653 selectedRows.Add(
m_cur_grid->GetGridCursorRow() );
655 if( selectedRows.size() == 0 )
661 std::sort( selectedRows.begin(), selectedRows.end() );
666 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
668 int row = selectedRows[ii];
670 if( row != last_row )
677 if(
m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
693 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
694 tbl->
rows.release( tbl->
rows.begin() + curRow );
697 tbl->
rows.insert( tbl->
rows.begin() + curRow, move_me.release() );
702 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
703 tbl->GetView()->ProcessTableMessage( msg );
721 if(
unsigned( curRow + 1 ) < tbl->
rows.size() )
723 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
724 tbl->
rows.release( tbl->
rows.begin() + curRow );
727 tbl->
rows.insert( tbl->
rows.begin() + curRow, move_me.release() );
732 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
733 tbl->GetView()->ProcessTableMessage( msg );
747 std::map<int, SUPPORTED_FILE_TYPE>::const_iterator fileTypeIt;
751 if( event.GetEventType() == wxEVT_BUTTON )
758 fileTypeIt =
fileTypes().find( event.GetId() );
763 wxLogWarning(
"File type selection event received but could not find the file type in the table" );
775 title.Printf(
_(
"Select %s Library" ),
fileType.m_Description );
785 wxFileDialog dlg(
this, title, openDir, wxEmptyString,
787 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
789 int result = dlg.ShowModal();
791 if( result == wxID_CANCEL )
794 dlg.GetPaths( files );
800 wxDirDialog dlg(
nullptr, title, openDir,
801 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
803 int result = dlg.ShowModal();
805 if( result == wxID_CANCEL )
809 if(
fileType.m_FolderSearchExtension !=
"" )
811 wxDir rootDir( dlg.GetPath() );
814 rootDir.Traverse( traverser );
818 if( traverser.HasDirectoryOpenFailures() )
820 wxArrayString failedDirs;
821 traverser.GetPaths( failedDirs );
822 wxString detailedMsg =
_(
"The following directories could not be opened: \n" );
824 for(
const wxString& path : failedDirs )
825 detailedMsg << path <<
"\n";
833 files.Add( dlg.GetPath() );
851 bool addDuplicates =
false;
852 bool applyToAll =
false;
853 wxString warning =
_(
"Warning: Duplicate Nicknames" );
854 wxString msg =
_(
"A library nicknamed '%s' already exists." );
855 wxString detailedMsg =
_(
"One of the nicknames will need to be changed after " 856 "adding this library." );
858 for(
const wxString& filePath : files )
860 wxFileName fn( filePath );
870 detailedMsg,
_(
"Skip" ),
_(
"Add Anyway" ),
871 &applyToAll ) == wxID_CANCEL;
874 doAdd = addDuplicates;
879 int last_row =
m_cur_grid->GetNumberRows() - 1;
890 if( path.IsEmpty() || (
m_pageNdx == 0 && path.Contains(
"${KIPRJMOD}" ) ) )
891 path = fn.GetFullPath();
897 if( !files.IsEmpty() )
899 int new_row =
m_cur_grid->GetNumberRows() - 1;
966 wxRegEx re(
".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
967 wxASSERT( re.IsValid() );
969 std::set< wxString > unique;
979 for(
int row = 0; row < tbl->GetNumberRows(); ++row )
981 wxString uri = tbl->GetValue( row,
COL_URI );
983 while( re.Matches( uri ) )
985 wxString envvar = re.GetMatch( uri, 2 );
988 if( envvar.IsEmpty() )
989 envvar = re.GetMatch( uri, 4 );
992 unique.insert( envvar );
995 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1008 for(
const wxString& evName : unique )
1013 m_path_subs_grid->SetCellValue( row, 0, wxT(
"${" ) + evName + wxT(
"}" ) );
1017 wxGetEnv( evName, &evValue );
1048 projectTable =
nullptr;
1051 projectTable, projectTablePath,
1054 if( dlg.ShowModal() == wxID_CANCEL )
1061 globalTable->
Save( globalTablePath );
1065 msg.Printf(
_(
"Error saving global library table:\n\n%s" ), ioe.
What() );
1066 wxMessageBox( msg,
_(
"File Save Error" ), wxOK | wxICON_ERROR );
1074 projectTable->
Save( projectTablePath );
1078 msg.Printf(
_(
"Error saving project-specific library table:\n\n%s" ), ioe.
What() );
1079 wxMessageBox( msg,
_(
"File Save Error" ), wxOK | wxICON_ERROR );
1086 editor->SyncLibraryTree(
true );
1091 viewer->ReCreateLibraryList();
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
FP_GRID_TRICKS(DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
wxString m_projectBasePath
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
void push_back(LIB_TABLE_ROW *aRow) override
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
void moveDownHandler(wxCommandEvent &event) override
wxBitmapButton * m_move_down_button
wxString EagleFootprintLibPathWildcard()
void InvokePluginOptionsEditor(wxWindow *aCaller, const wxString &aNickname, const wxString &aPluginType, const wxString &aOptions, wxString *aResult)
Function InvokePluginOptionsEditor calls DIALOG_FP_PLUGIN_OPTIONS dialog so that plugin options set c...
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
Container that describes file type info for the add a library options.
void Clear()
Delete all rows.
void GetFailedPaths(wxArrayString &aPathArray)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
WX_GRID * m_path_subs_grid
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
This file is part of the common library.
const BITMAP_OPAQUE small_folder_xpm[1]
void showPopupMenu(wxMenu &menu) override
const std::string KiCadFootprintFileExtension
bool ContainsNickname(const wxString &aNickname)
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
unsigned GetCount() const
Get the number of rows contained in the table.
virtual wxDirTraverseResult OnFile(const wxString &aFileName) override
wxString m_searchExtension
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
void appendRowHandler(wxCommandEvent &event) override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
void adjustPathSubsGridColumns(int aWidth)
wxBitmapButton * m_append_button
bool HasDirectoryOpenFailures()
#define MYID_OPTIONS_EDITOR
wxString m_lastProjectLibDir
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
static const std::map< int, SUPPORTED_FILE_TYPE > & fileTypes()
Map with event id as the key to supported file types that will be listed for the add a library option...
IO_MGR::PCB_FILE_T m_Plugin
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
virtual const wxString GetType() const =0
Return the type of library represented by this row.
int GetNumberRows() override
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxString LegacyFootprintLibPathWildcard()
virtual const wxString GetProjectPath() const
Return the full path of the project.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
size_t size() const override
SPLIT_BUTTON * m_browseButton
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
LIB_TABLE_ROWS_ITER insert(LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
void InvokePcbLibTableEditor(KIWAY *aKiway, wxWindow *aCaller)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the glob...
WX_GRID * m_grid
I don't own the grid, but he owns me.
virtual void paste_text(const wxString &cb_text)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
void moveUpHandler(wxCommandEvent &event) override
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
void InstallPanel(wxPanel *aPanel)
const wxString & GetNickName() const
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
LIB_TABLE_ROW * clone() const
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
PANEL_FP_LIB_TABLE(DIALOG_EDIT_LIBRARY_TABLES *aParent, FP_LIB_TABLE *aGlobal, const wxString &aGlobalTblPath, FP_LIB_TABLE *aProject, const wxString &aProjectTblPath, const wxString &aProjectBasePath)
virtual const wxString What() const
A composite of Problem() and Where()
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
FP_LIB_TABLE_GRID * global_model() const
wxBitmapButton * m_move_up_button
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
std::unordered_map< wxString, int > m_foundDirs
FP_LIB_TABLE_GRID * project_model() const
FP_LIB_TABLE_GRID * cur_model() const
const BITMAP_OPAQUE small_down_xpm[1]
void paste_text(const wxString &cb_text) override
handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text.
Definition of file extensions used in Kicad.
bool m_IsFile
Whether the library is a folder or a file.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
void deleteRowHandler(wxCommandEvent &event) override
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
bool AppendRows(size_t aNumRows=1) override
void optionsEditor(int aRow)
FormatType fileType(const char *aFileName)
const BITMAP_OPAQUE small_up_xpm[1]
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
void browseLibrariesHandler(wxCommandEvent &event)
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
const BITMAP_OPAQUE small_trash_xpm[1]
Class PANEL_FP_LIB_TABLE_BASE.
LIB_TABLE_ROWS_ITER begin() override
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void OnUpdateUI(wxUpdateUIEvent &event) override
wxString m_FolderSearchExtension
In case of folders it stands for extensions of files stored inside.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, wxString aDetailedMessage, wxString aOKLabel, wxString aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
bool m_GlobalTableChanged
bool TransferDataFromWindow() override
virtual wxDirTraverseResult OnDir(const wxString &aDirName) override
LIBRARY_TRAVERSER(wxString aSearchExtension, wxString aInitialDir)
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
A filename or source description, a problem input line, a line number, a byte offset,...
Legacy Pcbnew file formats prior to s-expression.
virtual void doPopupSelection(wxCommandEvent &event)
Declaration of the eda_3d_viewer class.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
LIB_TABLE_ROW * makeNewRow() override
virtual void showPopupMenu(wxMenu &menu)
FP_LIB_TABLE_GRID(const FP_LIB_TABLE &aTableToEdit)
virtual wxDirTraverseResult OnOpenError(const wxString &aOpenErrorName) override
wxBitmapButton * m_delete_button
void GetPaths(wxArrayString &aPathArray)
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Traverser implementation that looks to find any and all "folder" libraries by looking for files with ...
LIB_TABLE_ROWS_ITER erase(LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
const std::string GedaPcbFootprintLibFileExtension
DIALOG_EDIT_LIBRARY_TABLES * m_parent
void SetOptions(const wxString &aOptions)
Change the library options strings.
void onSizeGrid(wxSizeEvent &event) override
Dialog to show and edit symbol library tables.
wxString m_Description
Description shown in the file picker dialog.
wxString m_lastFootprintLibDir
wxString m_FileFilter
Filter used for file pickers if m_IsFile is true.
std::unordered_map< wxString, int > m_failedDirs
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
bool handleDoubleClick(wxGridEvent &aEvent) override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
const std::string KiCadFootprintLibPathExtension
bool m_ProjectTableChanged
const BITMAP_OPAQUE small_plus_xpm[1]
void doPopupSelection(wxCommandEvent &event) override
LIB_TABLE_ROW * at(size_t aIndex) override
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
static wxString GetGlobalTableFileName()
~PANEL_FP_LIB_TABLE() override
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
S-expression Pcbnew file format.
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.