KiCad PCB EDA Suite
PANEL_FP_LIB_TABLE Class Reference

Dialog to show and edit symbol library tables. More...

#include <panel_fp_lib_table.h>

Inheritance diagram for PANEL_FP_LIB_TABLE:
PANEL_FP_LIB_TABLE_BASE

Public Member Functions

 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)
 
 ~PANEL_FP_LIB_TABLE () override
 

Protected Attributes

wxNotebook * m_notebook
 
wxPanel * m_global_panel
 
WX_GRIDm_global_grid
 
wxPanel * m_project_panel
 
WX_GRIDm_project_grid
 
wxPanel * m_buttonsPanel
 
wxBitmapButton * m_append_button
 
SPLIT_BUTTONm_browseButton
 
wxBitmapButton * m_move_up_button
 
wxBitmapButton * m_move_down_button
 
wxBitmapButton * m_delete_button
 
WX_GRIDm_path_subs_grid
 

Private Member Functions

bool TransferDataFromWindow () override
 
bool verifyTables ()
 Trim important fields, removes blank row entries, and checks for duplicates. More...
 
void OnUpdateUI (wxUpdateUIEvent &event) override
 
void appendRowHandler (wxCommandEvent &event) override
 
void browseLibrariesHandler (wxCommandEvent &event)
 
void deleteRowHandler (wxCommandEvent &event) override
 
void moveUpHandler (wxCommandEvent &event) override
 
void moveDownHandler (wxCommandEvent &event) override
 
void onSizeGrid (wxSizeEvent &event) override
 
void adjustPathSubsGridColumns (int aWidth)
 
void populateEnvironReadOnlyTable ()
 Populate the readonly environment variable table with names and values by examining all the full_uri columns. More...
 
FP_LIB_TABLE_GRIDglobal_model () const
 
FP_LIB_TABLE_GRIDproject_model () const
 
FP_LIB_TABLE_GRIDcur_model () const
 

Private Attributes

FP_LIB_TABLEm_global
 
FP_LIB_TABLEm_project
 
wxString m_projectBasePath
 
DIALOG_EDIT_LIBRARY_TABLESm_parent
 
WX_GRIDm_cur_grid
 
wxString m_lastProjectLibDir
 

Static Private Attributes

static size_t m_pageNdx = 0
 

Detailed Description

Dialog to show and edit symbol library tables.

Definition at line 33 of file panel_fp_lib_table.h.

Constructor & Destructor Documentation

◆ PANEL_FP_LIB_TABLE()

PANEL_FP_LIB_TABLE::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 
)

Definition at line 355 of file panel_fp_lib_table.cpp.

358  :
359  PANEL_FP_LIB_TABLE_BASE( aParent ),
360  m_global( aGlobal ),
361  m_project( aProject ),
362  m_projectBasePath( aProjectBasePath ),
363  m_parent( aParent )
364 {
365  m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true );
366 
367  // add Cut, Copy, and Paste to wxGrids
368  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
369 
370  wxArrayString choices;
371 
372  choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) );
373  choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
374  choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
375  choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
376 
377  /* PCAD_PLUGIN does not support Footprint*() functions
378  choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) );
379  */
380  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
381 
382  if( cfg->m_lastFootprintLibDir.IsEmpty() )
384 
386 
387  auto setupGrid =
388  [&]( WX_GRID* aGrid )
389  {
390  // Give a bit more room for wxChoice editors
391  aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
392 
393  // add Cut, Copy, and Paste to wxGrids
394  aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
395 
396  aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
397  aGrid->AutoSizeColumns( false );
398 
399  wxGridCellAttr* attr;
400 
401  attr = new wxGridCellAttr;
402  attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
403  &cfg->m_lastFootprintLibDir,
404  wxEmptyString, true,
405  m_projectBasePath ) );
406  aGrid->SetColAttr( COL_URI, attr );
407 
408  attr = new wxGridCellAttr;
409  attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
410  aGrid->SetColAttr( COL_TYPE, attr );
411 
412  attr = new wxGridCellAttr;
413  attr->SetRenderer( new wxGridCellBoolRenderer() );
414  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
415  aGrid->SetColAttr( COL_ENABLED, attr );
416 
417  // all but COL_OPTIONS, which is edited with Option Editor anyways.
418  aGrid->AutoSizeColumn( COL_NICKNAME, false );
419  aGrid->AutoSizeColumn( COL_TYPE, false );
420  aGrid->AutoSizeColumn( COL_URI, false );
421  aGrid->AutoSizeColumn( COL_DESCR, false );
422 
423  // would set this to width of title, if it was easily known.
424  aGrid->SetColSize( COL_OPTIONS, 80 );
425 
426  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
427  // a currentCell which is sometimes not highlighted.
428  if( aGrid->GetNumberRows() > 0 )
429  aGrid->SelectRow( 0 );
430  };
431 
432  setupGrid( m_global_grid );
433 
435 
436  if( aProject )
437  {
438  m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true );
439  setupGrid( m_project_grid );
440  }
441  else
442  {
443  m_pageNdx = 0;
444  m_notebook->DeletePage( 1 );
445  m_project_grid = nullptr;
446  }
447 
448  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
449  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
450 
451  // select the last selected page
452  m_notebook->SetSelection( m_pageNdx );
454 
455  // for ALT+A handling, we want the initial focus to be on the first selected grid.
457 
458  // Configure button logos
464 
465  // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
466  // manually (for instance m_append_button)
467  Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
468  // their bitmaps
469  wxSize buttonSize = m_append_button->GetSize();
470 
472  m_browseButton->SetMinSize( buttonSize );
473 
474  // Populate the browse library options
475  wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
476 
477  for( const std::pair<const int, SUPPORTED_FILE_TYPE>& fileType : fileTypes() )
478  {
479  browseMenu->Append( fileType.first, fileType.second.m_Description );
480 
481  browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_FP_LIB_TABLE::browseLibrariesHandler,
482  this, fileType.first );
483  }
484 
485  Layout();
486 
487  // Hack to make buttons lay out correctly the first time on Mac
488  wxSize hackSize = m_buttonsPanel->GetSize();
489  m_buttonsPanel->SetSize( wxSize( hackSize.x - 5, hackSize.y ) );
490  Layout();
491 
492  // This is the button only press for the browse button instead of the menu
493  m_browseButton->Bind( wxEVT_BUTTON, &PANEL_FP_LIB_TABLE::browseLibrariesHandler, this );
494 }
void SetBitmap(const wxBitmap &aBmp)
wxMenu * GetSplitButtonMenu()
FP_LIB_TABLE * m_project
void SetMinSize(const wxSize &aSize) override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
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...
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...
Definition: wx_grid.cpp:93
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: io_mgr.cpp:77
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
Geda PCB file formats.
Definition: io_mgr.h:64
static size_t m_pageNdx
PANEL_FP_LIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
#define _(s)
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:278
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
void browseLibrariesHandler(wxCommandEvent &event)
void SetWidthPadding(int aPadding)
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:108
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global
wxString m_lastFootprintLibDir
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
S-expression Pcbnew file format.
Definition: io_mgr.h:56

References _, browseLibrariesHandler(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, IO_MGR::EAGLE, fileType(), fileTypes(), IO_MGR::GEDA_PCB, PATHS::GetDefaultUserFootprintsPath(), SPLIT_BUTTON::GetSplitButtonMenu(), KiBitmap(), IO_MGR::KICAD_SEXP, IO_MGR::LEGACY, PANEL_FP_LIB_TABLE_BASE::m_append_button, PANEL_FP_LIB_TABLE_BASE::m_browseButton, PANEL_FP_LIB_TABLE_BASE::m_buttonsPanel, m_cur_grid, PANEL_FP_LIB_TABLE_BASE::m_delete_button, PANEL_FP_LIB_TABLE_BASE::m_global_grid, PCBNEW_SETTINGS::m_lastFootprintLibDir, m_lastProjectLibDir, PANEL_FP_LIB_TABLE_BASE::m_move_down_button, PANEL_FP_LIB_TABLE_BASE::m_move_up_button, PANEL_FP_LIB_TABLE_BASE::m_notebook, m_pageNdx, m_parent, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, PANEL_FP_LIB_TABLE_BASE::m_project_grid, m_projectBasePath, Pgm(), populateEnvironReadOnlyTable(), SPLIT_BUTTON::SetBitmap(), DIALOG_SHIM::SetInitialFocus(), SPLIT_BUTTON::SetMinSize(), WX_GRID::SetTable(), SPLIT_BUTTON::SetWidthPadding(), IO_MGR::ShowType(), small_down, small_folder, small_plus, small_trash, and small_up.

◆ ~PANEL_FP_LIB_TABLE()

PANEL_FP_LIB_TABLE::~PANEL_FP_LIB_TABLE ( )
override

Definition at line 497 of file panel_fp_lib_table.cpp.

498 {
499  // When the dialog is closed it will hide the current notebook page first, which will
500  // in turn select the other one. We then end up saving its index as the "current page".
501  // So flip them back again:
502  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
503 
504  // Delete the GRID_TRICKS.
505  // Any additional event handlers should be popped before the window is deleted.
506  m_global_grid->PopEventHandler( true );
507 
508  if( m_project_grid )
509  m_project_grid->PopEventHandler( true );
510 
511  m_path_subs_grid->PopEventHandler( true );
512 }
static size_t m_pageNdx

References PANEL_FP_LIB_TABLE_BASE::m_global_grid, m_pageNdx, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, and PANEL_FP_LIB_TABLE_BASE::m_project_grid.

Member Function Documentation

◆ adjustPathSubsGridColumns()

void PANEL_FP_LIB_TABLE::adjustPathSubsGridColumns ( int  aWidth)
private

Definition at line 945 of file panel_fp_lib_table.cpp.

946 {
947  // Account for scroll bars
948  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
949 
950  m_path_subs_grid->AutoSizeColumn( 0 );
951 
952  if( aWidth - m_path_subs_grid->GetColSize( 0 ) < 60 )
953  m_path_subs_grid->SetColSize( 0, aWidth / 2 );
954 
955  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
956 }

References PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid.

Referenced by onSizeGrid(), and populateEnvironReadOnlyTable().

◆ appendRowHandler()

void PANEL_FP_LIB_TABLE::appendRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 629 of file panel_fp_lib_table.cpp.

630 {
632  return;
633 
634  if( m_cur_grid->AppendRows( 1 ) )
635  {
636  int last_row = m_cur_grid->GetNumberRows() - 1;
637 
638  // wx documentation is wrong, SetGridCursor does not make visible.
639  m_cur_grid->MakeCellVisible( last_row, 0 );
640  m_cur_grid->SetGridCursor( last_row, 1 );
641  m_cur_grid->EnableCellEditControl( true );
642  m_cur_grid->ShowCellEditControl();
643  }
644 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ browseLibrariesHandler()

void PANEL_FP_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
private

Definition at line 767 of file panel_fp_lib_table.cpp.

768 {
770  return;
771 
772  std::map<int, SUPPORTED_FILE_TYPE>::const_iterator fileTypeIt;
773 
774  // We are bound both to the menu and button with this one handler
775  // So we must set the file type based on it
776  if( event.GetEventType() == wxEVT_BUTTON )
777  {
778  // Let's default to adding a kicad footprint file for just the footprint
779  fileTypeIt = fileTypes().find( ID_PANEL_FPLIB_ADD_KICADMOD );
780  }
781  else
782  {
783  fileTypeIt = fileTypes().find( event.GetId() );
784  }
785 
786  if( fileTypeIt == fileTypes().end() )
787  {
788  wxLogWarning( wxT( "File type selection event received but could not find the file type "
789  "in the table" ) );
790  return;
791  }
792 
793  SUPPORTED_FILE_TYPE fileType = fileTypeIt->second;
794 
795  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
796 
797  wxArrayString files;
798 
799  wxString title;
800 
801  title.Printf( _( "Select %s Library" ), fileType.m_Description );
802 
803  wxString openDir = cfg->m_lastFootprintLibDir;
804 
805  if( m_cur_grid == m_project_grid )
806  openDir = m_lastProjectLibDir;
807 
808  if( fileType.m_IsFile )
809  {
810  wxFileDialog dlg( this, title, openDir, wxEmptyString, fileType.m_FileFilter,
811  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
812 
813  int result = dlg.ShowModal();
814 
815  if( result == wxID_CANCEL )
816  return;
817 
818  dlg.GetPaths( files );
819 
820  if( m_cur_grid == m_global_grid )
821  cfg->m_lastFootprintLibDir = dlg.GetDirectory();
822  else
823  m_lastProjectLibDir = dlg.GetDirectory();
824  }
825  else
826  {
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 );
830 
831  int result = dlg.ShowModal();
832 
833  if( result == wxID_CANCEL )
834  return;
835 
836  dlg.GetPaths( files );
837 #else
838  wxDirDialog dlg( nullptr, title, openDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
839 
840  int result = dlg.ShowModal();
841 
842  if( result == wxID_CANCEL )
843  return;
844 
845  // is there a file extension configured to hunt out their containing folders?
846  if( fileType.m_FolderSearchExtension != "" )
847  {
848  wxDir rootDir( dlg.GetPath() );
849 
850  LIBRARY_TRAVERSER traverser( fileType.m_FolderSearchExtension, rootDir.GetName() );
851  rootDir.Traverse( traverser );
852 
853  traverser.GetPaths( files );
854 
855  if( traverser.HasDirectoryOpenFailures() )
856  {
857  wxArrayString failedDirs;
858  traverser.GetPaths( failedDirs );
859  wxString detailedMsg = _( "The following directories could not be opened: \n" );
860 
861  for( const wxString& path : failedDirs )
862  detailedMsg << path << wxT( "\n" );
863 
864  DisplayErrorMessage( this, _( "Failed to open directories to look for libraries" ),
865  detailedMsg );
866  }
867  }
868  else
869  {
870  files.Add( dlg.GetPath() );
871  }
872 #endif
873 
874  if( !files.IsEmpty() )
875  {
876  wxFileName first( files.front() );
877 
878  if( m_cur_grid == m_global_grid )
879  cfg->m_lastFootprintLibDir = first.GetPath();
880  else
881  m_lastProjectLibDir = first.GetPath();
882  }
883  }
884 
885  // Drop the last directory if the path is a .pretty folder
887  cfg->m_lastFootprintLibDir = cfg->m_lastFootprintLibDir.BeforeLast( wxFileName::GetPathSeparator() );
888 
889  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
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." );
896 
897  for( const wxString& filePath : files )
898  {
899  wxFileName fn( filePath );
900  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
901  bool doAdd = true;
902 
903  if( cur_model()->ContainsNickname( nickname ) )
904  {
905  if( !applyToAll )
906  {
907  // The cancel button adds the library to the table anyway
908  addDuplicates = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
909  detailedMsg, _( "Skip" ), _( "Add Anyway" ),
910  &applyToAll ) == wxID_CANCEL;
911  }
912 
913  doAdd = addDuplicates;
914  }
915 
916  if( doAdd && m_cur_grid->AppendRows( 1 ) )
917  {
918  int last_row = m_cur_grid->GetNumberRows() - 1;
919 
920  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
921 
922  m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( fileType.m_Plugin ) );
923 
924  // try to use path normalized to an environmental variable or project path
925  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
926 
927  // Do not use the project path in the global library table. This will almost
928  // assuredly be wrong for a different project.
929  if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
930  path = fn.GetFullPath();
931 
932  m_cur_grid->SetCellValue( last_row, COL_URI, path );
933  }
934  }
935 
936  if( !files.IsEmpty() )
937  {
938  int new_row = m_cur_grid->GetNumberRows() - 1;
939  m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
940  m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
941  }
942 }
Container that describes file type info for the add a library options.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:189
bool ContainsNickname(const wxString &aNickname)
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...
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: io_mgr.cpp:77
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static size_t m_pageNdx
FP_LIB_TABLE_GRID * cur_model() const
#define _(s)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:278
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.
Definition: confirm.cpp:252
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
void GetPaths(wxArrayString &aPathArray)
Traverser implementation that looks to find any and all "folder" libraries by looking for files with ...
wxString m_lastFootprintLibDir
const std::string KiCadFootprintLibPathExtension
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71

References _, COL_NICKNAME, COL_TYPE, COL_URI, WX_GRID::CommitPendingChanges(), LIB_TABLE_GRID::ContainsNickname(), cur_model(), DisplayErrorMessage(), fileType(), fileTypes(), LIB_ID::FixIllegalChars(), Format(), LIBRARY_TRAVERSER::GetPaths(), ID_PANEL_FPLIB_ADD_KICADMOD, KiCadFootprintLibPathExtension, m_cur_grid, PANEL_FP_LIB_TABLE_BASE::m_global_grid, PCBNEW_SETTINGS::m_lastFootprintLibDir, m_lastProjectLibDir, m_pageNdx, PANEL_FP_LIB_TABLE_BASE::m_project_grid, m_projectBasePath, NormalizePath(), OKOrCancelDialog(), path, Pgm(), and IO_MGR::ShowType().

Referenced by PANEL_FP_LIB_TABLE().

◆ cur_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::cur_model ( ) const
inlineprivate

Definition at line 77 of file panel_fp_lib_table.h.

78  {
79  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
80  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References m_cur_grid.

Referenced by browseLibrariesHandler(), moveDownHandler(), moveUpHandler(), and verifyTables().

◆ deleteRowHandler()

void PANEL_FP_LIB_TABLE::deleteRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 647 of file panel_fp_lib_table.cpp.

648 {
650  return;
651 
652  int curRow = m_cur_grid->GetGridCursorRow();
653  int curCol = m_cur_grid->GetGridCursorCol();
654 
655  // In a wxGrid, collect rows that have a selected cell, or are selected
656  // It is not so easy: it depends on the way the selection was made.
657  // Here, we collect rows selected by clicking on a row label, and rows that contain any
658  // previously-selected cells.
659  // If no candidate, just delete the row with the grid cursor.
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();
664 
665  // Add all row having cell selected to list:
666  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
667  selectedRows.Add( cells[ii].GetRow() );
668 
669  // Handle block selection
670  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
671  {
672  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
673  selectedRows.Add( i );
674  }
675 
676  // Use the row having the grid cursor only if we have no candidate:
677  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
678  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
679 
680  if( selectedRows.size() == 0 )
681  {
682  wxBell();
683  return;
684  }
685 
686  std::sort( selectedRows.begin(), selectedRows.end() );
687 
688  // Remove selected rows (note: a row can be stored more than once in list)
689  int last_row = -1;
690 
691  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
692  {
693  int row = selectedRows[ii];
694 
695  if( row != last_row )
696  {
697  last_row = row;
698  m_cur_grid->DeleteRows( row, 1 );
699  }
700  }
701 
702  if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
703  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
704 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ global_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::global_model ( ) const
inlineprivate

Definition at line 67 of file panel_fp_lib_table.h.

68  {
69  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
70  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References PANEL_FP_LIB_TABLE_BASE::m_global_grid.

Referenced by populateEnvironReadOnlyTable(), TransferDataFromWindow(), and verifyTables().

◆ moveDownHandler()

void PANEL_FP_LIB_TABLE::moveDownHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 737 of file panel_fp_lib_table.cpp.

738 {
740  return;
741 
742  FP_LIB_TABLE_GRID* tbl = cur_model();
743  int curRow = m_cur_grid->GetGridCursorRow();
744 
745  // @todo: add multiple selection moves.
746  if( unsigned( curRow + 1 ) < tbl->rows.size() )
747  {
748  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
749  tbl->rows.release( tbl->rows.begin() + curRow );
750 
751  ++curRow;
752  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
753 
754  if( tbl->GetView() )
755  {
756  // Update the wxGrid
757  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
758  tbl->GetView()->ProcessTableMessage( msg );
759  }
760 
761  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
762  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
763  }
764 }
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References WX_GRID::CommitPendingChanges(), cur_model(), m_cur_grid, and LIB_TABLE::rows.

◆ moveUpHandler()

void PANEL_FP_LIB_TABLE::moveUpHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 707 of file panel_fp_lib_table.cpp.

708 {
710  return;
711 
712  FP_LIB_TABLE_GRID* tbl = cur_model();
713  int curRow = m_cur_grid->GetGridCursorRow();
714 
715  // @todo: add multiple selection moves.
716  if( curRow >= 1 )
717  {
718  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
719  tbl->rows.release( tbl->rows.begin() + curRow );
720 
721  --curRow;
722  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
723 
724  if( tbl->GetView() )
725  {
726  // Update the wxGrid
727  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
728  tbl->GetView()->ProcessTableMessage( msg );
729  }
730 
731  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
732  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
733  }
734 }
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References WX_GRID::CommitPendingChanges(), cur_model(), m_cur_grid, and LIB_TABLE::rows.

◆ onSizeGrid()

void PANEL_FP_LIB_TABLE::onSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 959 of file panel_fp_lib_table.cpp.

960 {
961  adjustPathSubsGridColumns( event.GetSize().GetX() );
962 
963  event.Skip();
964 }
void adjustPathSubsGridColumns(int aWidth)

References adjustPathSubsGridColumns().

◆ OnUpdateUI()

void PANEL_FP_LIB_TABLE::OnUpdateUI ( wxUpdateUIEvent &  event)
overrideprivatevirtual

◆ populateEnvironReadOnlyTable()

void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable ( )
private

Populate the readonly environment variable table with names and values by examining all the full_uri columns.

Definition at line 1003 of file panel_fp_lib_table.cpp.

1004 {
1005  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1006  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1007 
1008  std::set< wxString > unique;
1009 
1010  // clear the table
1012 
1013  for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
1014  {
1015  if( !tbl )
1016  continue;
1017 
1018  for( int row = 0; row < tbl->GetNumberRows(); ++row )
1019  {
1020  wxString uri = tbl->GetValue( row, COL_URI );
1021 
1022  while( re.Matches( uri ) )
1023  {
1024  wxString envvar = re.GetMatch( uri, 2 );
1025 
1026  // if not ${...} form then must be $(...)
1027  if( envvar.IsEmpty() )
1028  envvar = re.GetMatch( uri, 4 );
1029 
1030  // ignore duplicates
1031  unique.insert( envvar );
1032 
1033  // delete the last match and search again
1034  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1035  }
1036  }
1037  }
1038 
1039  // Make sure this special environment variable shows up even if it was
1040  // not used yet. It is automatically set by KiCad to the directory holding
1041  // the current project.
1042  unique.insert( PROJECT_VAR_NAME );
1043  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
1044  // This special environment variable is used to locate 3d shapes
1045  unique.insert( KICAD6_3DMODEL_DIR );
1046 
1047  for( const wxString& evName : unique )
1048  {
1049  int row = m_path_subs_grid->GetNumberRows();
1050  m_path_subs_grid->AppendRows( 1 );
1051 
1052  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1053  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1054 
1055  wxString evValue;
1056  wxGetEnv( evName, &evValue );
1057  m_path_subs_grid->SetCellValue( row, 1, evValue );
1058  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1059  }
1060 
1061  // No combobox editors here, but it looks better if its consistent with the other
1062  // grids in the dialog.
1063  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1064 
1065  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1066 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
void adjustPathSubsGridColumns(int aWidth)
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:109

References adjustPathSubsGridColumns(), WX_GRID::ClearRows(), COL_URI, global_model(), FP_LIB_TABLE::GlobalPathEnvVariableName(), KICAD6_3DMODEL_DIR, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, project_model(), and PROJECT_VAR_NAME.

Referenced by PANEL_FP_LIB_TABLE().

◆ project_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::project_model ( ) const
inlineprivate

Definition at line 72 of file panel_fp_lib_table.h.

73  {
74  return m_project_grid ? (FP_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
75  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References PANEL_FP_LIB_TABLE_BASE::m_project_grid.

Referenced by populateEnvironReadOnlyTable(), TransferDataFromWindow(), and verifyTables().

◆ TransferDataFromWindow()

bool PANEL_FP_LIB_TABLE::TransferDataFromWindow ( )
overrideprivate

Definition at line 967 of file panel_fp_lib_table.cpp.

968 {
970  return false;
971 
972  if( verifyTables() )
973  {
974  if( *global_model() != *m_global )
975  {
977 
978  m_global->Clear();
979  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
980  global_model()->rows.end(), global_model()->rows );
981  m_global->reindex();
982  }
983 
984  if( project_model() && *project_model() != *m_project )
985  {
987 
988  m_project->Clear();
989  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
990  project_model()->rows.end(), project_model()->rows );
991  m_project->reindex();
992  }
993 
994  return true;
995  }
996 
997  return false;
998 }
void Clear()
Delete all rows.
void reindex()
FP_LIB_TABLE * m_project
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global

References LIB_TABLE::Clear(), WX_GRID::CommitPendingChanges(), global_model(), m_cur_grid, m_global, DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, m_parent, m_project, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, project_model(), LIB_TABLE::reindex(), LIB_TABLE::rows, and verifyTables().

◆ verifyTables()

bool PANEL_FP_LIB_TABLE::verifyTables ( )
private

Trim important fields, removes blank row entries, and checks for duplicates.

Returns
bool - true if tables are OK, else false.

Definition at line 515 of file panel_fp_lib_table.cpp.

516 {
517  wxString msg;
518 
519  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
520  {
521  if( !model )
522  continue;
523 
524  for( int r = 0; r < model->GetNumberRows(); )
525  {
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;
529 
530  if( !nick || !uri )
531  {
532  if( !nick && !uri )
533  msg = _( "A library table row nickname and path cells are empty." );
534  else if( !nick )
535  msg = _( "A library table row nickname cell is empty." );
536  else
537  msg = _( "A library table row path cell is empty." );
538 
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" ) ) );
545 
546  if( badCellDlg.ShowModal() == wxID_NO )
547  return false;
548 
549  // Delete the "empty" row, where empty means missing nick or uri.
550  // This also updates the UI which could be slow, but there should only be a few
551  // rows to delete, unless the user fell asleep on the Add Row
552  // button.
553  model->DeleteRows( r, 1 );
554  }
555  else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
556  {
557  msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ),
558  illegalCh,
559  nick );
560 
561  // show the tabbed panel holding the grid we have flunked:
562  if( model != cur_model() )
563  m_notebook->SetSelection( model == global_model() ? 0 : 1 );
564 
565  m_cur_grid->MakeCellVisible( r, 0 );
566  m_cur_grid->SetGridCursor( r, 1 );
567 
568  wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
569  errdlg.ShowModal();
570  return false;
571  }
572  else
573  {
574  // set the trimmed values back into the table so they get saved to disk.
575  model->SetValue( r, COL_NICKNAME, nick );
576  model->SetValue( r, COL_URI, uri );
577  ++r; // this row was OK.
578  }
579  }
580  }
581 
582  // check for duplicate nickNames, separately in each table.
583  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
584  {
585  if( !model )
586  continue;
587 
588  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
589  {
590  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
591 
592  for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
593  {
594  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
595 
596  if( nick1 == nick2 )
597  {
598  msg = wxString::Format( _( "Multiple libraries cannot share the same "
599  "nickname ('%s')." ),
600  nick1 );
601 
602  // show the tabbed panel holding the grid we have flunked:
603  if( model != cur_model() )
604  m_notebook->SetSelection( model == global_model() ? 0 : 1 );
605 
606  // go to the lower of the two rows, it is technically the duplicate:
607  m_cur_grid->MakeCellVisible( r2, 0 );
608  m_cur_grid->SetGridCursor( r2, 1 );
609 
610  wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
611  errdlg.ShowModal();
612  return false;
613  }
614  }
615  }
616  }
617 
618  return true;
619 }
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
FP_LIB_TABLE_GRID * cur_model() const
#define _(s)
E_SERIE r
Definition: eserie.cpp:41
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:240

References _, COL_NICKNAME, COL_URI, cur_model(), LIB_ID::FindIllegalLibraryNameChar(), Format(), global_model(), m_cur_grid, PANEL_FP_LIB_TABLE_BASE::m_notebook, project_model(), and r.

Referenced by TransferDataFromWindow().

Member Data Documentation

◆ m_append_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_append_button
protectedinherited

◆ m_browseButton

SPLIT_BUTTON* PANEL_FP_LIB_TABLE_BASE::m_browseButton
protectedinherited

◆ m_buttonsPanel

wxPanel* PANEL_FP_LIB_TABLE_BASE::m_buttonsPanel
protectedinherited

◆ m_cur_grid

◆ m_delete_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_delete_button
protectedinherited

◆ m_global

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_global
private

Definition at line 83 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_global_grid

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_global_grid
protectedinherited

◆ m_global_panel

wxPanel* PANEL_FP_LIB_TABLE_BASE::m_global_panel
protectedinherited

◆ m_lastProjectLibDir

wxString PANEL_FP_LIB_TABLE::m_lastProjectLibDir
private

Definition at line 93 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler(), and PANEL_FP_LIB_TABLE().

◆ m_move_down_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_down_button
protectedinherited

◆ m_move_up_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_up_button
protectedinherited

◆ m_notebook

wxNotebook* PANEL_FP_LIB_TABLE_BASE::m_notebook
protectedinherited

◆ m_pageNdx

size_t PANEL_FP_LIB_TABLE::m_pageNdx = 0
staticprivate

◆ m_parent

DIALOG_EDIT_LIBRARY_TABLES* PANEL_FP_LIB_TABLE::m_parent
private

Definition at line 87 of file panel_fp_lib_table.h.

Referenced by PANEL_FP_LIB_TABLE(), and TransferDataFromWindow().

◆ m_path_subs_grid

◆ m_project

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_project
private

Definition at line 84 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_project_grid

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_project_grid
protectedinherited

◆ m_project_panel

wxPanel* PANEL_FP_LIB_TABLE_BASE::m_project_panel
protectedinherited

◆ m_projectBasePath

wxString PANEL_FP_LIB_TABLE::m_projectBasePath
private

Definition at line 85 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler(), and PANEL_FP_LIB_TABLE().


The documentation for this class was generated from the following files: