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 351 of file panel_fp_lib_table.cpp.

354  :
355  PANEL_FP_LIB_TABLE_BASE( aParent ),
356  m_global( aGlobal ),
357  m_project( aProject ),
358  m_projectBasePath( aProjectBasePath ),
359  m_parent( aParent )
360 {
361  m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true );
362 
363  // add Cut, Copy, and Paste to wxGrids
364  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
365 
366  wxArrayString choices;
367 
368  choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) );
369  choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
370  choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
371  choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
372 
373  /* PCAD_PLUGIN does not support Footprint*() functions
374  choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) );
375  */
376  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
377 
378  if( cfg->m_lastFootprintLibDir.IsEmpty() )
380 
382 
383  auto setupGrid =
384  [&]( WX_GRID* aGrid )
385  {
386  // Give a bit more room for wxChoice editors
387  aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
388 
389  // add Cut, Copy, and Paste to wxGrids
390  aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
391 
392  aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
393  aGrid->AutoSizeColumns( false );
394 
395  wxGridCellAttr* attr;
396 
397  attr = new wxGridCellAttr;
398  attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
399  &cfg->m_lastFootprintLibDir,
400  wxEmptyString, true,
401  m_projectBasePath ) );
402  aGrid->SetColAttr( COL_URI, attr );
403 
404  attr = new wxGridCellAttr;
405  attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
406  aGrid->SetColAttr( COL_TYPE, attr );
407 
408  attr = new wxGridCellAttr;
409  attr->SetRenderer( new wxGridCellBoolRenderer() );
410  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
411  aGrid->SetColAttr( COL_ENABLED, attr );
412 
413  // all but COL_OPTIONS, which is edited with Option Editor anyways.
414  aGrid->AutoSizeColumn( COL_NICKNAME, false );
415  aGrid->AutoSizeColumn( COL_TYPE, false );
416  aGrid->AutoSizeColumn( COL_URI, false );
417  aGrid->AutoSizeColumn( COL_DESCR, false );
418 
419  // would set this to width of title, if it was easily known.
420  aGrid->SetColSize( COL_OPTIONS, 80 );
421 
422  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
423  // a currentCell which is sometimes not highlighted.
424  if( aGrid->GetNumberRows() > 0 )
425  aGrid->SelectRow( 0 );
426  };
427 
428  setupGrid( m_global_grid );
429 
431 
432  if( aProject )
433  {
434  m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true );
435  setupGrid( m_project_grid );
436  }
437  else
438  {
439  m_pageNdx = 0;
440  m_notebook->DeletePage( 1 );
441  m_project_grid = nullptr;
442  }
443 
444  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
445  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
446 
447  // select the last selected page
448  m_notebook->SetSelection( m_pageNdx );
450 
451  // for ALT+A handling, we want the initial focus to be on the first selected grid.
453 
454  // Configure button logos
460 
461  // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
462  // manually (for instance m_append_button)
463  Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
464  // their bitmaps
465  wxSize buttonSize = m_append_button->GetSize();
466 
468  m_browseButton->SetMinSize( buttonSize );
469 
470  // Populate the browse library options
471  wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
472 
473  for( const std::pair<const int, SUPPORTED_FILE_TYPE>& fileType : fileTypes() )
474  {
475  browseMenu->Append( fileType.first, fileType.second.m_Description );
476 
477  browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_FP_LIB_TABLE::browseLibrariesHandler,
478  this, fileType.first );
479  }
480 
481  Layout();
482 
483  // Hack to make buttons lay out correctly the first time on Mac
484  wxSize hackSize = m_buttonsPanel->GetSize();
485  m_buttonsPanel->SetSize( wxSize( hackSize.x - 5, hackSize.y ) );
486  Layout();
487 
488  // This is the button only press for the browse button instead of the menu
489  m_browseButton->Bind( wxEVT_BUTTON, &PANEL_FP_LIB_TABLE::browseLibrariesHandler, this );
490 }
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:52
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:65
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:98
Geda PCB file formats.
Definition: io_mgr.h:63
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)
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:273
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:54
#define _(s)
Definition: 3d_actions.cpp:33
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:55
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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 493 of file panel_fp_lib_table.cpp.

494 {
495  // When the dialog is closed it will hide the current notebook page first, which will
496  // in turn select the other one. We then end up saving its index as the "current page".
497  // So flip them back again:
498  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
499 
500  // Delete the GRID_TRICKS.
501  // Any additional event handlers should be popped before the window is deleted.
502  m_global_grid->PopEventHandler( true );
503 
504  if( m_project_grid )
505  m_project_grid->PopEventHandler( true );
506 
507  m_path_subs_grid->PopEventHandler( true );
508 }
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 908 of file panel_fp_lib_table.cpp.

909 {
910  // Account for scroll bars
911  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
912 
913  m_path_subs_grid->AutoSizeColumn( 0 );
914 
915  if( aWidth - m_path_subs_grid->GetColSize( 0 ) < 60 )
916  m_path_subs_grid->SetColSize( 0, aWidth / 2 );
917 
918  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
919 }

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 606 of file panel_fp_lib_table.cpp.

607 {
609  return;
610 
611  if( m_cur_grid->AppendRows( 1 ) )
612  {
613  int last_row = m_cur_grid->GetNumberRows() - 1;
614 
615  // wx documentation is wrong, SetGridCursor does not make visible.
616  m_cur_grid->MakeCellVisible( last_row, 0 );
617  m_cur_grid->SetGridCursor( last_row, 1 );
618  m_cur_grid->EnableCellEditControl( true );
619  m_cur_grid->ShowCellEditControl();
620  }
621 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ browseLibrariesHandler()

void PANEL_FP_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
private

Definition at line 744 of file panel_fp_lib_table.cpp.

745 {
747  return;
748 
749  std::map<int, SUPPORTED_FILE_TYPE>::const_iterator fileTypeIt;
750 
751  // We are bound both to the menu and button with this one handler
752  // So we must set the file type based on it
753  if( event.GetEventType() == wxEVT_BUTTON )
754  {
755  // Let's default to adding a kicad footprint file for just the footprint
756  fileTypeIt = fileTypes().find( ID_PANEL_FPLIB_ADD_KICADMOD );
757  }
758  else
759  {
760  fileTypeIt = fileTypes().find( event.GetId() );
761  }
762 
763  if( fileTypeIt == fileTypes().end() )
764  {
765  wxLogWarning( "File type selection event received but could not find the file type in the table" );
766  return;
767  }
768 
769  SUPPORTED_FILE_TYPE fileType = fileTypeIt->second;
770 
771  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
772 
773  wxArrayString files;
774 
775  wxString title;
776 
777  title.Printf( _( "Select %s Library" ), fileType.m_Description );
778 
779  wxString openDir = cfg->m_lastFootprintLibDir;
780  if( m_cur_grid == m_project_grid )
781  {
782  openDir = m_lastProjectLibDir;
783  }
784 
785  if( fileType.m_IsFile )
786  {
787  wxFileDialog dlg( this, title, openDir, wxEmptyString,
788  fileType.m_FileFilter,
789  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
790 
791  int result = dlg.ShowModal();
792 
793  if( result == wxID_CANCEL )
794  return;
795 
796  dlg.GetPaths( files );
797 
798  cfg->m_lastFootprintLibDir = dlg.GetDirectory();
799  }
800  else
801  {
802  wxDirDialog dlg( nullptr, title, openDir,
803  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
804 
805  int result = dlg.ShowModal();
806 
807  if( result == wxID_CANCEL )
808  return;
809 
810  // is there a file extension configured to hunt out their containing folders?
811  if( fileType.m_FolderSearchExtension != "" )
812  {
813  wxDir rootDir( dlg.GetPath() );
814 
815  LIBRARY_TRAVERSER traverser( fileType.m_FolderSearchExtension, rootDir.GetName() );
816  rootDir.Traverse( traverser );
817 
818  traverser.GetPaths( files );
819 
820  if( traverser.HasDirectoryOpenFailures() )
821  {
822  wxArrayString failedDirs;
823  traverser.GetPaths( failedDirs );
824  wxString detailedMsg = _( "The following directories could not be opened: \n" );
825 
826  for( const wxString& path : failedDirs )
827  detailedMsg << path << "\n";
828 
829  DisplayErrorMessage( this, _( "Failed to open directories to look for libraries" ),
830  detailedMsg );
831  }
832  }
833  else
834  {
835  files.Add( dlg.GetPath() );
836  }
837 
838  if( m_cur_grid == m_global_grid )
839  {
840  cfg->m_lastFootprintLibDir = dlg.GetPath();
841  }
842  else
843  {
844  m_lastProjectLibDir = dlg.GetPath();
845  }
846  }
847 
848  // Drop the last directory if the path is a .pretty folder
850  cfg->m_lastFootprintLibDir = cfg->m_lastFootprintLibDir.BeforeLast( wxFileName::GetPathSeparator() );
851 
852  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
853  bool addDuplicates = false;
854  bool applyToAll = false;
855  wxString warning = _( "Warning: Duplicate Nicknames" );
856  wxString msg = _( "A library nicknamed '%s' already exists." );
857  wxString detailedMsg = _( "One of the nicknames will need to be changed after "
858  "adding this library." );
859 
860  for( const wxString& filePath : files )
861  {
862  wxFileName fn( filePath );
863  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName() );
864  bool doAdd = true;
865 
866  if( cur_model()->ContainsNickname( nickname ) )
867  {
868  if( !applyToAll )
869  {
870  // The cancel button adds the library to the table anyway
871  addDuplicates = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
872  detailedMsg, _( "Skip" ), _( "Add Anyway" ),
873  &applyToAll ) == wxID_CANCEL;
874  }
875 
876  doAdd = addDuplicates;
877  }
878 
879  if( doAdd && m_cur_grid->AppendRows( 1 ) )
880  {
881  int last_row = m_cur_grid->GetNumberRows() - 1;
882 
883  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
884 
885  m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( fileType.m_Plugin ) );
886 
887  // try to use path normalized to an environmental variable or project path
888  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
889 
890  // Do not use the project path in the global library table. This will almost
891  // assuredly be wrong for a different project.
892  if( path.IsEmpty() || ( m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" ) ) )
893  path = fn.GetFullPath();
894 
895  m_cur_grid->SetCellValue( last_row, COL_URI, path );
896  }
897  }
898 
899  if( !files.IsEmpty() )
900  {
901  int new_row = m_cur_grid->GetNumberRows() - 1;
902  m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
903  m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
904  }
905 }
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:347
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:265
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
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:112
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:273
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
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.
Definition: confirm.cpp:220
#define _(s)
Definition: 3d_actions.cpp:33
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:67

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 82 of file panel_fp_lib_table.h.

83  {
84  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
85  }
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 624 of file panel_fp_lib_table.cpp.

625 {
627  return;
628 
629  int curRow = m_cur_grid->GetGridCursorRow();
630  int curCol = m_cur_grid->GetGridCursorCol();
631 
632  // In a wxGrid, collect rows that have a selected cell, or are selected
633  // It is not so easy: it depends on the way the selection was made.
634  // Here, we collect rows selected by clicking on a row label, and rows that contain any
635  // previously-selected cells.
636  // If no candidate, just delete the row with the grid cursor.
637  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
638  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
639  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
640  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
641 
642  // Add all row having cell selected to list:
643  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
644  selectedRows.Add( cells[ii].GetRow() );
645 
646  // Handle block selection
647  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
648  {
649  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
650  selectedRows.Add( i );
651  }
652 
653  // Use the row having the grid cursor only if we have no candidate:
654  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
655  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
656 
657  if( selectedRows.size() == 0 )
658  {
659  wxBell();
660  return;
661  }
662 
663  std::sort( selectedRows.begin(), selectedRows.end() );
664 
665  // Remove selected rows (note: a row can be stored more than once in list)
666  int last_row = -1;
667 
668  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
669  {
670  int row = selectedRows[ii];
671 
672  if( row != last_row )
673  {
674  last_row = row;
675  m_cur_grid->DeleteRows( row, 1 );
676  }
677  }
678 
679  if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
680  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
681 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182

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 72 of file panel_fp_lib_table.h.

73  {
74  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
75  }
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 714 of file panel_fp_lib_table.cpp.

715 {
717  return;
718 
719  FP_LIB_TABLE_GRID* tbl = cur_model();
720  int curRow = m_cur_grid->GetGridCursorRow();
721 
722  // @todo: add multiple selection moves.
723  if( unsigned( curRow + 1 ) < tbl->rows.size() )
724  {
725  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
726  tbl->rows.release( tbl->rows.begin() + curRow );
727 
728  ++curRow;
729  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
730 
731  if( tbl->GetView() )
732  {
733  // Update the wxGrid
734  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
735  tbl->GetView()->ProcessTableMessage( msg );
736  }
737 
738  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
739  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
740  }
741 }
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:182
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 684 of file panel_fp_lib_table.cpp.

685 {
687  return;
688 
689  FP_LIB_TABLE_GRID* tbl = cur_model();
690  int curRow = m_cur_grid->GetGridCursorRow();
691 
692  // @todo: add multiple selection moves.
693  if( curRow >= 1 )
694  {
695  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
696  tbl->rows.release( tbl->rows.begin() + curRow );
697 
698  --curRow;
699  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
700 
701  if( tbl->GetView() )
702  {
703  // Update the wxGrid
704  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
705  tbl->GetView()->ProcessTableMessage( msg );
706  }
707 
708  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
709  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
710  }
711 }
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:182
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 922 of file panel_fp_lib_table.cpp.

923 {
924  adjustPathSubsGridColumns( event.GetSize().GetX() );
925 
926  event.Skip();
927 }
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 966 of file panel_fp_lib_table.cpp.

967 {
968  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
969  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
970 
971  std::set< wxString > unique;
972 
973  // clear the table
974  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
975 
976  for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
977  {
978  if( !tbl )
979  continue;
980 
981  for( int row = 0; row < tbl->GetNumberRows(); ++row )
982  {
983  wxString uri = tbl->GetValue( row, COL_URI );
984 
985  while( re.Matches( uri ) )
986  {
987  wxString envvar = re.GetMatch( uri, 2 );
988 
989  // if not ${...} form then must be $(...)
990  if( envvar.IsEmpty() )
991  envvar = re.GetMatch( uri, 4 );
992 
993  // ignore duplicates
994  unique.insert( envvar );
995 
996  // delete the last match and search again
997  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
998  }
999  }
1000  }
1001 
1002  // Make sure this special environment variable shows up even if it was
1003  // not used yet. It is automatically set by KiCad to the directory holding
1004  // the current project.
1005  unique.insert( PROJECT_VAR_NAME );
1006  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
1007  // This special environment variable is used to locate 3d shapes
1008  unique.insert( KICAD6_3DMODEL_DIR );
1009 
1010  for( const wxString& evName : unique )
1011  {
1012  int row = m_path_subs_grid->GetNumberRows();
1013  m_path_subs_grid->AppendRows( 1 );
1014 
1015  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1016  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1017 
1018  wxString evValue;
1019  wxGetEnv( evName, &evValue );
1020  m_path_subs_grid->SetCellValue( row, 1, evValue );
1021  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1022  }
1023 
1024  // No combobox editors here, but it looks better if its consistent with the other
1025  // grids in the dialog.
1026  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1027 
1028  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1029 }
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
#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
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References adjustPathSubsGridColumns(), 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 77 of file panel_fp_lib_table.h.

78  {
79  return m_project_grid ? (FP_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
80  }
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 930 of file panel_fp_lib_table.cpp.

931 {
933  return false;
934 
935  if( verifyTables() )
936  {
937  if( *global_model() != *m_global )
938  {
940 
941  m_global->Clear();
942  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
943  global_model()->rows.end(), global_model()->rows );
944  m_global->reindex();
945  }
946 
947  if( project_model() && *project_model() != *m_project )
948  {
950 
951  m_project->Clear();
952  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
953  project_model()->rows.end(), project_model()->rows );
954  m_project->reindex();
955  }
956 
957  return true;
958  }
959 
960  return false;
961 }
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:182
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 511 of file panel_fp_lib_table.cpp.

512 {
513  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
514  {
515  if( !model )
516  continue;
517 
518  for( int r = 0; r < model->GetNumberRows(); )
519  {
520  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
521  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
522  unsigned illegalCh = 0;
523 
524  if( !nick || !uri )
525  {
526  // Delete the "empty" row, where empty means missing nick or uri.
527  // This also updates the UI which could be slow, but there should only be a few
528  // rows to delete, unless the user fell asleep on the Add Row
529  // button.
530  model->DeleteRows( r, 1 );
531  }
532  else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
533  {
534  wxString msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ),
535  illegalCh,
536  nick );
537 
538  // show the tabbed panel holding the grid we have flunked:
539  if( model != cur_model() )
540  m_notebook->SetSelection( model == global_model() ? 0 : 1 );
541 
542  m_cur_grid->MakeCellVisible( r, 0 );
543  m_cur_grid->SetGridCursor( r, 1 );
544 
545  wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
546  errdlg.ShowModal();
547  return false;
548  }
549  else
550  {
551  // set the trimmed values back into the table so they get saved to disk.
552  model->SetValue( r, COL_NICKNAME, nick );
553  model->SetValue( r, COL_URI, uri );
554  ++r; // this row was OK.
555  }
556  }
557  }
558 
559  // check for duplicate nickNames, separately in each table.
560  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
561  {
562  if( !model )
563  continue;
564 
565  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
566  {
567  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
568 
569  for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
570  {
571  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
572 
573  if( nick1 == nick2 )
574  {
575  wxString msg = wxString::Format( _( "Multiple libraries cannot share the same "
576  "nickname ('%s')." ),
577  nick1 );
578 
579  // show the tabbed panel holding the grid we have flunked:
580  if( model != cur_model() )
581  m_notebook->SetSelection( model == global_model() ? 0 : 1 );
582 
583  // go to the lower of the two rows, it is technically the duplicate:
584  m_cur_grid->MakeCellVisible( r2, 0 );
585  m_cur_grid->SetGridCursor( r2, 1 );
586 
587  wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
588  errdlg.ShowModal();
589  return false;
590  }
591  }
592  }
593  }
594 
595  return true;
596 }
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
FP_LIB_TABLE_GRID * cur_model() const
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
#define _(s)
Definition: 3d_actions.cpp:33
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:398

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

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 68 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 92 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 69 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 70 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: