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

wxAuiNotebook * m_auinotebook
 
wxPanel * m_global_panel
 
wxStaticText * m_staticText3
 
wxStaticText * m_GblTableFilename
 
WX_GRIDm_global_grid
 
wxPanel * m_project_panel
 
wxStaticText * m_staticText4
 
wxStaticText * m_PrjTableFilename
 
WX_GRIDm_project_grid
 
wxBitmapButton * m_append_button
 
wxBitmapButton * m_browse_button
 
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 pageChangedHandler (wxAuiNotebookEvent &event) override
 
void appendRowHandler (wxCommandEvent &event) override
 
void browseLibrariesHandler (wxCommandEvent &event) override
 
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
 

Static Private Attributes

static size_t m_pageNdx = 0
 
static wxString m_lastBrowseDir
 

Detailed Description

Dialog to show and edit symbol library tables.

Definition at line 34 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 268 of file panel_fp_lib_table.cpp.

271  :
272  PANEL_FP_LIB_TABLE_BASE( aParent ),
273  m_global( aGlobal ),
274  m_project( aProject ),
275  m_projectBasePath( aProjectBasePath ),
276  m_parent( aParent )
277 {
278  // For user info, shows the table filenames:
279  m_GblTableFilename->SetLabel( aGlobalTblPath );
280  m_PrjTableFilename->SetLabel( aProjectTblPath );
281 
282  m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true );
283  m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true );
284 
285  // Give a bit more room for wxChoice editors
286  m_global_grid->SetDefaultRowSize( m_global_grid->GetDefaultRowSize() + 4 );
287  m_project_grid->SetDefaultRowSize( m_project_grid->GetDefaultRowSize() + 4 );
288 
289  // add Cut, Copy, and Paste to wxGrids
290  m_global_grid->PushEventHandler( new FP_GRID_TRICKS( m_parent, m_global_grid ) );
291  m_project_grid->PushEventHandler( new FP_GRID_TRICKS( m_parent, m_project_grid ) );
292  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
293 
294  m_global_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
295  m_project_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
296 
297  m_global_grid->AutoSizeColumns( false );
298  m_project_grid->AutoSizeColumns( false );
299 
300  wxArrayString choices;
301 
302  choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) );
303 #if defined(BUILD_GITHUB_PLUGIN)
304  choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
305 #endif
306  choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
307  choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
308  choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
309 
310  /* PCAD_PLUGIN does not support Footprint*() functions
311  choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) );
312  */
313 
315 
316  for( wxGrid* g : { m_global_grid, m_project_grid } )
317  {
318  wxGridCellAttr* attr;
319 
320  attr = new wxGridCellAttr;
321  attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &m_lastBrowseDir ) );
322  g->SetColAttr( COL_URI, attr );
323 
324  attr = new wxGridCellAttr;
325  attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
326  g->SetColAttr( COL_TYPE, attr );
327 
328  attr = new wxGridCellAttr;
329  attr->SetRenderer( new wxGridCellBoolRenderer() );
330  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
331  g->SetColAttr( COL_ENABLED, attr );
332 
333  // all but COL_OPTIONS, which is edited with Option Editor anyways.
334  g->AutoSizeColumn( COL_NICKNAME, false );
335  g->AutoSizeColumn( COL_TYPE, false );
336  g->AutoSizeColumn( COL_URI, false );
337  g->AutoSizeColumn( COL_DESCR, false );
338 
339  // would set this to width of title, if it was easily known.
340  g->SetColSize( COL_OPTIONS, 80 );
341  }
342 
343  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
344  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
345 
346  // select the last selected page
347  m_auinotebook->SetSelection( m_pageNdx );
349 
350  // for ALT+A handling, we want the initial focus to be on the first selected grid.
352 
353  // Configure button logos
354  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
355  m_browse_button->SetBitmap( KiBitmap( folder_xpm ) );
356  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
357  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
358  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
359 
360  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
361  // a currentCell which is sometimes not highlighted.
362  if( m_global_grid->GetNumberRows() > 0 )
363  m_global_grid->SelectRow( 0 );
364 
365  if( m_project_grid->GetNumberRows() > 0 )
366  m_project_grid->SelectRow( 0 );
367 }
FP_LIB_TABLE * m_project
Class GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GR...
Definition: grid_tricks.h:51
static wxString m_lastBrowseDir
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:57
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
Geda PCB file formats.
Definition: io_mgr.h:60
static size_t m_pageNdx
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
#define _(s)
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
PANEL_FP_LIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 300), long style=wxTAB_TRAVERSAL)
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global
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:57

References _, COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, IO_MGR::EAGLE, IO_MGR::GEDA_PCB, KiBitmap(), IO_MGR::KICAD_SEXP, IO_MGR::LEGACY, PANEL_FP_LIB_TABLE_BASE::m_append_button, PANEL_FP_LIB_TABLE_BASE::m_auinotebook, PANEL_FP_LIB_TABLE_BASE::m_browse_button, m_cur_grid, PANEL_FP_LIB_TABLE_BASE::m_delete_button, PANEL_FP_LIB_TABLE_BASE::m_GblTableFilename, PANEL_FP_LIB_TABLE_BASE::m_global_grid, m_lastBrowseDir, PANEL_FP_LIB_TABLE_BASE::m_move_down_button, PANEL_FP_LIB_TABLE_BASE::m_move_up_button, m_pageNdx, m_parent, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, PANEL_FP_LIB_TABLE_BASE::m_PrjTableFilename, PANEL_FP_LIB_TABLE_BASE::m_project_grid, populateEnvironReadOnlyTable(), DIALOG_SHIM::SetInitialFocus(), WX_GRID::SetTable(), and IO_MGR::ShowType().

◆ ~PANEL_FP_LIB_TABLE()

PANEL_FP_LIB_TABLE::~PANEL_FP_LIB_TABLE ( )
override

Definition at line 370 of file panel_fp_lib_table.cpp.

371 {
372  // When the dialog is closed it will hide the current notebook page first, which will
373  // in turn select the other one. We then end up saving its index as the "current page".
374  // So flip them back again:
375  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
376 
377  // Delete the GRID_TRICKS.
378  // Any additional event handlers should be popped before the window is deleted.
379  m_global_grid->PopEventHandler( true );
380  m_project_grid->PopEventHandler( true );
381  m_path_subs_grid->PopEventHandler( true );
382 }
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 687 of file panel_fp_lib_table.cpp.

688 {
689  // Account for scroll bars
690  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
691 
692  m_path_subs_grid->AutoSizeColumn( 0 );
693  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
694 }

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

475 {
477  return;
478 
479  if( m_cur_grid->AppendRows( 1 ) )
480  {
481  int last_row = m_cur_grid->GetNumberRows() - 1;
482 
483  // wx documentation is wrong, SetGridCursor does not make visible.
484  m_cur_grid->MakeCellVisible( last_row, 0 );
485  m_cur_grid->SetGridCursor( last_row, 1 );
486  m_cur_grid->EnableCellEditControl( true );
487  m_cur_grid->ShowCellEditControl();
488  }
489 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ browseLibrariesHandler()

void PANEL_FP_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 610 of file panel_fp_lib_table.cpp.

611 {
613  return;
614 
615  if( m_lastBrowseDir.IsEmpty() )
617 
618  DIALOG_FILE_DIR_PICKER dlg( this, _( "Select Library" ), m_lastBrowseDir,
620 
621  auto result = dlg.ShowModal();
622 
623  if( result == wxID_CANCEL )
624  return;
625 
626  m_lastBrowseDir = dlg.GetDirectory();
627 
628  // Drop the last directory if the path is a .pretty folder
630  m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() );
631 
632  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
633  bool addDuplicates = false;
634  bool applyToAll = false;
635  wxString warning = _( "Warning: Duplicate Nickname" );
636  wxString msg = _( "A library nicknamed \"%s\" already exists." );
637  wxArrayString files;
638  dlg.GetFilenames( files );
639 
640  for( const auto& filePath : files )
641  {
642  wxFileName fn( filePath );
643  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB );
644  bool doAdd = true;
645 
646  if( cur_model()->ContainsNickname( nickname ) )
647  {
648  if( !applyToAll )
649  {
650  int ret = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
651  _( "Skip" ), _( "Add Anyway" ), &applyToAll );
652  addDuplicates = (ret == wxID_CANCEL );
653  }
654 
655  doAdd = addDuplicates;
656  }
657 
658  if( doAdd && m_cur_grid->AppendRows( 1 ) )
659  {
660  int last_row = m_cur_grid->GetNumberRows() - 1;
661 
662  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
663 
664  auto type = IO_MGR::GuessPluginTypeFromLibPath( filePath );
665  m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( type ) );
666 
667  // try to use path normalized to an environmental variable or project path
668  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
669 
670  // Do not use the project path in the global library table. This will almost
671  // assuredly be wrong for a different project.
672  if( path.IsEmpty() || (m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" )) )
673  path = fn.GetFullPath();
674 
675  m_cur_grid->SetCellValue( last_row, COL_URI, path );
676  }
677  }
678 
679  if( !files.IsEmpty() )
680  {
681  int new_row = m_cur_grid->GetNumberRows() - 1;
682  m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
683  m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
684  }
685 }
bool ContainsNickname(const wxString &aNickname)
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Displays a warning dialog with aMessage and returns the user response.
Definition: confirm.cpp:214
static wxString m_lastBrowseDir
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath.
Definition: io_mgr.cpp:124
static size_t m_pageNdx
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:136
static wxString getFilterString()
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:315
#define _(s)
Dialog that can select both files and directories.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
const std::string KiCadFootprintLibPathExtension
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes 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(), FD_MULTIPLE, LIB_ID::FixIllegalChars(), Format(), DIALOG_FILE_DIR_PICKER::GetDirectory(), DIALOG_FILE_DIR_PICKER::GetFilenames(), getFilterString(), PGM_BASE::GetLocalEnvVariables(), IO_MGR::GuessPluginTypeFromLibPath(), LIB_ID::ID_PCB, KiCadFootprintLibPathExtension, m_cur_grid, m_lastBrowseDir, m_pageNdx, m_projectBasePath, NormalizePath(), OKOrCancelDialog(), Pgm(), and IO_MGR::ShowType().

◆ cur_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::cur_model ( ) const
inlineprivate

Definition at line 83 of file panel_fp_lib_table.h.

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

493 {
495  return;
496 
497  int curRow = m_cur_grid->GetGridCursorRow();
498  int curCol = m_cur_grid->GetGridCursorCol();
499 
500  // In a wxGrid, collect rows that have a selected cell, or are selected
501  // It is not so easy: it depends on the way the selection was made.
502  // Here, we collect rows selected by clicking on a row label, and rows that contain any
503  // previously-selected cells.
504  // If no candidate, just delete the row with the grid cursor.
505  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
506  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
507  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
508  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
509 
510  // Add all row having cell selected to list:
511  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
512  selectedRows.Add( cells[ii].GetRow() );
513 
514  // Handle block selection
515  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
516  {
517  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
518  selectedRows.Add( i );
519  }
520 
521  // Use the row having the grid cursor only if we have no candidate:
522  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
523  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
524 
525  if( selectedRows.size() == 0 )
526  {
527  wxBell();
528  return;
529  }
530 
531  std::sort( selectedRows.begin(), selectedRows.end() );
532 
533  // Remove selected rows (note: a row can be stored more than once in list)
534  int last_row = -1;
535  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
536  {
537  int row = selectedRows[ii];
538 
539  if( row != last_row )
540  {
541  last_row = row;
542  m_cur_grid->DeleteRows( row, 1 );
543  }
544  }
545 
546  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
547 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172
size_t i
Definition: json11.cpp:649
#define min(a, b)
Definition: auxiliary.h:85

References WX_GRID::CommitPendingChanges(), i, m_cur_grid, and min.

◆ global_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::global_model ( ) const
inlineprivate

Definition at line 73 of file panel_fp_lib_table.h.

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

581 {
583  return;
584 
585  FP_LIB_TABLE_GRID* tbl = cur_model();
586  int curRow = m_cur_grid->GetGridCursorRow();
587 
588  // @todo: add multiple selection moves.
589  if( unsigned( curRow + 1 ) < tbl->rows.size() )
590  {
591  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
592  tbl->rows.release( tbl->rows.begin() + curRow );
593 
594  ++curRow;
595  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
596 
597  if( tbl->GetView() )
598  {
599  // Update the wxGrid
600  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
601  tbl->GetView()->ProcessTableMessage( msg );
602  }
603 
604  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
605  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
606  }
607 }
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:172
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 550 of file panel_fp_lib_table.cpp.

551 {
553  return;
554 
555  FP_LIB_TABLE_GRID* tbl = cur_model();
556  int curRow = m_cur_grid->GetGridCursorRow();
557 
558  // @todo: add multiple selection moves.
559  if( curRow >= 1 )
560  {
561  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
562  tbl->rows.release( tbl->rows.begin() + curRow );
563 
564  --curRow;
565  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
566 
567  if( tbl->GetView() )
568  {
569  // Update the wxGrid
570  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
571  tbl->GetView()->ProcessTableMessage( msg );
572  }
573 
574  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
575  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
576  }
577 }
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:172
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 697 of file panel_fp_lib_table.cpp.

698 {
699  adjustPathSubsGridColumns( event.GetSize().GetX() );
700 
701  event.Skip();
702 }
void adjustPathSubsGridColumns(int aWidth)

References adjustPathSubsGridColumns().

◆ pageChangedHandler()

void PANEL_FP_LIB_TABLE::pageChangedHandler ( wxAuiNotebookEvent &  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 741 of file panel_fp_lib_table.cpp.

742 {
743  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
744  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
745 
746  std::set< wxString > unique;
747 
748  // clear the table
749  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
750 
751  for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
752  {
753  for( int row = 0; row < tbl->GetNumberRows(); ++row )
754  {
755  wxString uri = tbl->GetValue( row, COL_URI );
756 
757  while( re.Matches( uri ) )
758  {
759  wxString envvar = re.GetMatch( uri, 2 );
760 
761  // if not ${...} form then must be $(...)
762  if( envvar.IsEmpty() )
763  envvar = re.GetMatch( uri, 4 );
764 
765  // ignore duplicates
766  unique.insert( envvar );
767 
768  // delete the last match and search again
769  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
770  }
771  }
772  }
773 
774  // Make sure this special environment variable shows up even if it was
775  // not used yet. It is automatically set by KiCad to the directory holding
776  // the current project.
777  unique.insert( PROJECT_VAR_NAME );
778  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
779  // This special environment variable is used to locate 3d shapes
780  unique.insert( KISYS3DMOD );
781 
782  for( const wxString& evName : unique )
783  {
784  int row = m_path_subs_grid->GetNumberRows();
785  m_path_subs_grid->AppendRows( 1 );
786 
787  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
788  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
789 
790  wxString evValue;
791  wxGetEnv( evName, &evValue );
792  m_path_subs_grid->SetCellValue( row, 1, evValue );
793  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
794  }
795 
796  // No combobox editors here, but it looks better if its consistent with the other
797  // grids in the dialog.
798  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
799 
800  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
801 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
void adjustPathSubsGridColumns(int aWidth)
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:44
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
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(), KISYS3DMOD, 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 78 of file panel_fp_lib_table.h.

79  {
80  return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable();
81  }
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 705 of file panel_fp_lib_table.cpp.

706 {
708  return false;
709 
710  if( verifyTables() )
711  {
712  if( *global_model() != *m_global )
713  {
715 
716  m_global->Clear();
717  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
718  global_model()->rows.end(), global_model()->rows );
719  m_global->reindex();
720  }
721 
722  if( *project_model() != *m_project )
723  {
725 
726  m_project->Clear();
727  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
728  project_model()->rows.end(), project_model()->rows );
729  m_project->reindex();
730  }
731 
732  return true;
733  }
734 
735  return false;
736 }
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:172
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 385 of file panel_fp_lib_table.cpp.

386 {
387  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
388  {
389  for( int r = 0; r < model->GetNumberRows(); )
390  {
391  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
392  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
393  unsigned illegalCh = 0;
394 
395  if( !nick || !uri )
396  {
397  // Delete the "empty" row, where empty means missing nick or uri.
398  // This also updates the UI which could be slow, but there should only be a few
399  // rows to delete, unless the user fell asleep on the Add Row
400  // button.
401  model->DeleteRows( r, 1 );
402  }
403  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) )
404  {
405  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
406  illegalCh,
407  nick );
408 
409  // show the tabbed panel holding the grid we have flunked:
410  if( model != cur_model() )
411  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
412 
413  m_cur_grid->MakeCellVisible( r, 0 );
414  m_cur_grid->SetGridCursor( r, 1 );
415 
416  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
417  errdlg.ShowModal();
418  return false;
419  }
420  else
421  {
422  // set the trimmed values back into the table so they get saved to disk.
423  model->SetValue( r, COL_NICKNAME, nick );
424  model->SetValue( r, COL_URI, uri );
425  ++r; // this row was OK.
426  }
427  }
428  }
429 
430  // check for duplicate nickNames, separately in each table.
431  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
432  {
433  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
434  {
435  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
436 
437  for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
438  {
439  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
440 
441  if( nick1 == nick2 )
442  {
443  wxString msg = wxString::Format( _( "Duplicate Nicknames \"%s\"." ), nick1 );
444 
445  // show the tabbed panel holding the grid we have flunked:
446  if( model != cur_model() )
447  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
448 
449  // go to the lower of the two rows, it is technically the duplicate:
450  m_cur_grid->MakeCellVisible( r2, 0 );
451  m_cur_grid->SetGridCursor( r2, 1 );
452 
453  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
454  errdlg.ShowModal();
455  return false;
456  }
457  }
458  }
459  }
460 
461  return true;
462 }
static unsigned FindIllegalLibNicknameChar(const UTF8 &aNickname, LIB_ID_TYPE aType)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:404
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
FP_LIB_TABLE_GRID * cur_model() const
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References _, COL_NICKNAME, COL_URI, cur_model(), LIB_ID::FindIllegalLibNicknameChar(), Format(), global_model(), LIB_ID::ID_PCB, PANEL_FP_LIB_TABLE_BASE::m_auinotebook, m_cur_grid, and project_model().

Referenced by TransferDataFromWindow().

Member Data Documentation

◆ m_append_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_append_button
protectedinherited

◆ m_auinotebook

wxAuiNotebook* PANEL_FP_LIB_TABLE_BASE::m_auinotebook
protectedinherited

◆ m_browse_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_browse_button
protectedinherited

◆ m_cur_grid

◆ m_delete_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_delete_button
protectedinherited

◆ m_GblTableFilename

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_GblTableFilename
protectedinherited

◆ m_global

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_global
private

Definition at line 69 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_lastBrowseDir

wxString PANEL_FP_LIB_TABLE::m_lastBrowseDir
staticprivate

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

Referenced by PANEL_FP_LIB_TABLE(), and TransferDataFromWindow().

◆ m_path_subs_grid

◆ m_PrjTableFilename

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_PrjTableFilename
protectedinherited

◆ m_project

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_project
private

Definition at line 70 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 71 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler().

◆ m_staticText3

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText3
protectedinherited

◆ m_staticText4

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText4
protectedinherited

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