38 #include <wx/dirdlg.h> 39 #include <wx/filedlg.h> 46 #include <lib_table_lexer.h> 97 static const std::map<int, SUPPORTED_FILE_TYPE>&
fileTypes()
106 static const std::map<int, SUPPORTED_FILE_TYPE>
fileTypes =
110 wxT(
"KiCad (folder with .kicad_mod files)" ), wxEmptyString,
128 wxT(
"Geda (folder with *.fp files)" ), wxEmptyString,
152 virtual wxDirTraverseResult
OnFile(
const wxString& aFileName )
override 154 wxFileName file( aFileName );
159 return wxDIR_CONTINUE;
162 virtual wxDirTraverseResult
OnOpenError(
const wxString& aOpenErrorName )
override 173 virtual wxDirTraverseResult
OnDir(
const wxString& aDirName )
override 176 return wxDIR_CONTINUE;
181 for( std::pair<const wxString, int>& foundDirsPair :
m_foundDirs )
182 aPathArray.Add( foundDirsPair.first );
187 for( std::pair<const wxString, int>& failedDirsPair :
m_failedDirs )
188 aPathArray.Add( failedDirsPair.first );
210 size_t size()
const override {
return rows.size(); }
221 return rows.insert( aIterator, aRow );
228 return rows.erase( aFirst, aLast );
240 #define MYID_OPTIONS_EDITOR 15151 262 wxString result = options;
267 if( options != result )
291 menu.AppendSeparator();
310 size_t ndx = cb_text.find(
"(fp_lib_table" );
312 if( ndx != std::string::npos )
318 LIB_TABLE_LEXER lexer( &slr );
324 tmp_tbl.
Parse( &lexer );
338 for(
unsigned i = 0; i < tmp_tbl.
GetCount(); ++i )
342 m_grid->AutoSizeColumns(
false );
349 m_grid->AutoSizeColumns(
false );
357 FP_LIB_TABLE* aProject,
const wxString& aProjectTblPath,
358 const wxString& aProjectBasePath ) :
361 m_project( aProject ),
362 m_projectBasePath( aProjectBasePath ),
370 wxArrayString choices;
391 aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
396 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
397 aGrid->AutoSizeColumns(
false );
399 wxGridCellAttr* attr;
401 attr =
new wxGridCellAttr;
406 aGrid->SetColAttr(
COL_URI, attr );
408 attr =
new wxGridCellAttr;
409 attr->SetEditor(
new wxGridCellChoiceEditor( choices ) );
410 aGrid->SetColAttr(
COL_TYPE, attr );
412 attr =
new wxGridCellAttr;
413 attr->SetRenderer(
new wxGridCellBoolRenderer() );
419 aGrid->AutoSizeColumn(
COL_TYPE,
false );
420 aGrid->AutoSizeColumn(
COL_URI,
false );
421 aGrid->AutoSizeColumn(
COL_DESCR,
false );
428 if( aGrid->GetNumberRows() > 0 )
429 aGrid->SelectRow( 0 );
524 for(
int r = 0;
r < model->GetNumberRows(); )
526 wxString nick = model->GetValue(
r,
COL_NICKNAME ).Trim(
false ).Trim();
527 wxString uri = model->GetValue(
r,
COL_URI ).Trim(
false ).Trim();
528 unsigned illegalCh = 0;
533 msg =
_(
"A library table row nickname and path cells are empty." );
535 msg =
_(
"A library table row nickname cell is empty." );
537 msg =
_(
"A library table row path cell is empty." );
539 wxMessageDialog badCellDlg(
this, msg,
_(
"Invalid Row Definition" ),
540 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
541 badCellDlg.SetExtendedMessage(
_(
"Empty cells will result in all rows that are " 542 "invalid to be removed from the table." ) );
543 badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Remove Invalid Cells" ) ),
544 wxMessageDialog::ButtonLabel(
_(
"Cancel Table Update" ) ) );
546 if( badCellDlg.ShowModal() == wxID_NO )
553 model->DeleteRows(
r, 1 );
568 wxMessageDialog errdlg(
this, msg,
_(
"Library Nickname Error" ) );
588 for(
int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
592 for(
int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
599 "nickname ('%s')." ),
610 wxMessageDialog errdlg(
this, msg,
_(
"Library Nickname Error" ) );
636 int last_row =
m_cur_grid->GetNumberRows() - 1;
660 wxArrayInt selectedRows =
m_cur_grid->GetSelectedRows();
661 wxGridCellCoordsArray cells =
m_cur_grid->GetSelectedCells();
662 wxGridCellCoordsArray blockTopLeft =
m_cur_grid->GetSelectionBlockTopLeft();
663 wxGridCellCoordsArray blockBotRight =
m_cur_grid->GetSelectionBlockBottomRight();
666 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
667 selectedRows.Add( cells[ii].GetRow() );
670 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
672 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
673 selectedRows.Add( i );
677 if( selectedRows.size() == 0 &&
m_cur_grid->GetGridCursorRow() >= 0 )
678 selectedRows.Add(
m_cur_grid->GetGridCursorRow() );
680 if( selectedRows.size() == 0 )
686 std::sort( selectedRows.begin(), selectedRows.end() );
691 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
693 int row = selectedRows[ii];
695 if( row != last_row )
702 if(
m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
718 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
719 tbl->
rows.release( tbl->
rows.begin() + curRow );
722 tbl->
rows.insert( tbl->
rows.begin() + curRow, move_me.release() );
727 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
728 tbl->GetView()->ProcessTableMessage( msg );
746 if(
unsigned( curRow + 1 ) < tbl->
rows.size() )
748 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
749 tbl->
rows.release( tbl->
rows.begin() + curRow );
752 tbl->
rows.insert( tbl->
rows.begin() + curRow, move_me.release() );
757 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
758 tbl->GetView()->ProcessTableMessage( msg );
772 std::map<int, SUPPORTED_FILE_TYPE>::const_iterator fileTypeIt;
776 if( event.GetEventType() == wxEVT_BUTTON )
783 fileTypeIt =
fileTypes().find( event.GetId() );
788 wxLogWarning( wxT(
"File type selection event received but could not find the file type " 801 title.Printf(
_(
"Select %s Library" ),
fileType.m_Description );
810 wxFileDialog dlg(
this, title, openDir, wxEmptyString,
fileType.m_FileFilter,
811 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
813 int result = dlg.ShowModal();
815 if( result == wxID_CANCEL )
818 dlg.GetPaths( files );
827 #if wxCHECK_VERSION( 3, 1, 4 ) // 3.1.4 required for wxDD_MULTIPLE 828 wxDirDialog dlg(
nullptr, title, openDir,
829 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
831 int result = dlg.ShowModal();
833 if( result == wxID_CANCEL )
836 dlg.GetPaths( files );
838 wxDirDialog dlg(
nullptr, title, openDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
840 int result = dlg.ShowModal();
842 if( result == wxID_CANCEL )
846 if(
fileType.m_FolderSearchExtension !=
"" )
848 wxDir rootDir( dlg.GetPath() );
851 rootDir.Traverse( traverser );
855 if( traverser.HasDirectoryOpenFailures() )
857 wxArrayString failedDirs;
858 traverser.GetPaths( failedDirs );
859 wxString detailedMsg =
_(
"The following directories could not be opened: \n" );
861 for(
const wxString&
path : failedDirs )
862 detailedMsg <<
path << wxT(
"\n" );
870 files.Add( dlg.GetPath() );
874 if( !files.IsEmpty() )
876 wxFileName first( files.front() );
890 bool addDuplicates =
false;
891 bool applyToAll =
false;
892 wxString warning =
_(
"Warning: Duplicate Nicknames" );
893 wxString msg =
_(
"A library nicknamed '%s' already exists." );
894 wxString detailedMsg =
_(
"One of the nicknames will need to be changed after " 895 "adding this library." );
897 for(
const wxString& filePath : files )
899 wxFileName fn( filePath );
909 detailedMsg,
_(
"Skip" ),
_(
"Add Anyway" ),
910 &applyToAll ) == wxID_CANCEL;
913 doAdd = addDuplicates;
918 int last_row =
m_cur_grid->GetNumberRows() - 1;
929 if(
m_pageNdx == 0 &&
path.Contains( wxT(
"${KIPRJMOD}" ) ) )
930 path = fn.GetFullPath();
936 if( !files.IsEmpty() )
938 int new_row =
m_cur_grid->GetNumberRows() - 1;
1005 wxRegEx re(
".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1006 wxASSERT( re.IsValid() );
1008 std::set< wxString > unique;
1018 for(
int row = 0; row < tbl->GetNumberRows(); ++row )
1020 wxString uri = tbl->GetValue( row,
COL_URI );
1022 while( re.Matches( uri ) )
1024 wxString envvar = re.GetMatch( uri, 2 );
1027 if( envvar.IsEmpty() )
1028 envvar = re.GetMatch( uri, 4 );
1031 unique.insert( envvar );
1034 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1047 for(
const wxString& evName : unique )
1052 m_path_subs_grid->SetCellValue( row, 0, wxT(
"${" ) + evName + wxT(
"}" ) );
1056 wxGetEnv( evName, &evValue );
1087 projectTable =
nullptr;
1090 projectTable, projectTablePath,
1093 if( dlg.ShowModal() == wxID_CANCEL )
1100 globalTable->
Save( globalTablePath );
1104 msg.Printf(
_(
"Error saving global library table:\n\n%s" ), ioe.
What() );
1105 wxMessageBox( msg,
_(
"File Save Error" ), wxOK | wxICON_ERROR );
1113 projectTable->
Save( projectTablePath );
1117 msg.Printf(
_(
"Error saving project-specific library table:\n\n%s" ), ioe.
What() );
1118 wxMessageBox( msg,
_(
"File Save Error" ), wxOK | wxICON_ERROR );
1126 editor->SyncLibraryTree(
true );
1127 editor->RefreshLibraryTree();
1133 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
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
The global footprint library table.
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
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
This file is part of the common library.
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 file contains miscellaneous commonly used macros and functions.
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
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()
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
void paste_text(const wxString &cb_text) override
handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text.
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
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)
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
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.
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.
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)
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
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 ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
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
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.