KiCad PCB EDA Suite
PANEL_SYM_LIB_TABLE Class Reference

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

#include <panel_sym_lib_table.h>

Inheritance diagram for PANEL_SYM_LIB_TABLE:
PANEL_SYM_LIB_TABLE_BASE

Public Member Functions

 PANEL_SYM_LIB_TABLE (DIALOG_EDIT_LIBRARY_TABLES *aParent, SYMBOL_LIB_TABLE *aGlobal, const wxString &aGlobalTablePath, SYMBOL_LIB_TABLE *aProject, const wxString &aProjectTablePath, const wxString &m_projectBasePath)
 
virtual ~PANEL_SYM_LIB_TABLE ()
 

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 verifyTables ()
 Trim important fields, removes blank row entries, and checks for duplicates. More...
 
void pageChangedHandler (wxAuiNotebookEvent &event) override
 
void browseLibrariesHandler (wxCommandEvent &event) override
 
void appendRowHandler (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)
 
bool TransferDataFromWindow () override
 
void populateEnvironReadOnlyTable ()
 Populate the readonly environment variable table with names and values by examining all the full_uri columns. More...
 
SYMBOL_LIB_TABLE_GRIDglobal_model () const
 
SYMBOL_LIB_TABLE_GRIDproject_model () const
 
SYMBOL_LIB_TABLE_GRIDcur_model () const
 

Private Attributes

SYMBOL_LIB_TABLEm_globalTable
 
SYMBOL_LIB_TABLEm_projectTable
 
wxString m_projectBasePath
 
DIALOG_EDIT_LIBRARY_TABLESm_parent
 
WX_GRIDm_cur_grid
 changed based on tab choice More...
 

Static Private Attributes

static size_t m_pageNdx = 0
 Remember the last notebook page selected during a session. More...
 

Detailed Description

Dialog to show and edit symbol library tables.

Definition at line 34 of file panel_sym_lib_table.h.

Constructor & Destructor Documentation

◆ PANEL_SYM_LIB_TABLE()

PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE ( DIALOG_EDIT_LIBRARY_TABLES aParent,
SYMBOL_LIB_TABLE aGlobal,
const wxString &  aGlobalTablePath,
SYMBOL_LIB_TABLE aProject,
const wxString &  aProjectTablePath,
const wxString &  m_projectBasePath 
)

Definition at line 208 of file panel_sym_lib_table.cpp.

213  :
214  PANEL_SYM_LIB_TABLE_BASE( aParent ),
215  m_globalTable( aGlobal ),
216  m_projectTable( aProject ),
217  m_projectBasePath( aProjectBasePath ),
218  m_parent( aParent )
219 {
220  // wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
221  // so make it a grid owned table.
222  m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aGlobal ), true );
223 
224  // For user info, shows the table filenames:
225  m_GblTableFilename->SetLabel( aGlobalTablePath );
226 
227  wxArrayString pluginChoices;
228 
229  pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD ) );
230  pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
231 
232  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
233 
234  if( cfg->m_lastSymbolLibDir.IsEmpty() )
235  {
237  }
238 
239  auto setupGrid =
240  [&]( WX_GRID* aGrid )
241  {
242  // Give a bit more room for combobox editors
243  aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
244 
245  // add Cut, Copy, and Paste to wxGrids
246  aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, aGrid ) );
247 
248  aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
249  aGrid->AutoSizeColumns( false );
250 
251  // Set special attributes
252  wxGridCellAttr* attr;
253 
254  attr = new wxGridCellAttr;
255 
256  wxString wildcards = AllSymbolLibFilesWildcard()
258  + "|" + LegacySymbolLibFileWildcard();
259  attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &cfg->m_lastSymbolLibDir,
260  wildcards,
261  true, m_projectBasePath ) );
262  aGrid->SetColAttr( COL_URI, attr );
263 
264  attr = new wxGridCellAttr;
265  attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
266  aGrid->SetColAttr( COL_TYPE, attr );
267 
268  attr = new wxGridCellAttr;
269  attr->SetRenderer( new wxGridCellBoolRenderer() );
270  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
271  aGrid->SetColAttr( COL_ENABLED, attr );
272 
273  // all but COL_OPTIONS, which is edited with Option Editor anyways.
274  aGrid->AutoSizeColumn( COL_NICKNAME, false );
275  aGrid->AutoSizeColumn( COL_TYPE, false );
276  aGrid->AutoSizeColumn( COL_URI, false );
277  aGrid->AutoSizeColumn( COL_DESCR, false );
278  aGrid->AutoSizeColumn( COL_ENABLED, false );
279 
280  // would set this to width of title, if it was easily known.
281  aGrid->SetColSize( COL_OPTIONS, 80 );
282 
283  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
284  // a currentCell which is sometimes not highlighted.
285  if( aGrid->GetNumberRows() > 0 )
286  aGrid->SelectRow( 0 );
287  };
288 
289  setupGrid( m_global_grid );
290 
291  if( aProject )
292  {
293  m_PrjTableFilename->SetLabel( aProjectTablePath );
294  m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aProject ), true );
295  setupGrid( m_project_grid );
296  }
297  else
298  {
299  m_pageNdx = 0;
300  m_auinotebook->DeletePage( 1 );
301  m_project_grid = nullptr;
302  }
303 
304  // add Cut, Copy, and Paste to wxGrids
305  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
306 
308 
309  // select the last selected page
310  m_auinotebook->SetSelection( m_pageNdx );
312 
313  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
314  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
315 
316  // for ALT+A handling, we want the initial focus to be on the first selected grid.
318 
319  // Configure button logos
320  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
321  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
322  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
323  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
324  m_browse_button->SetBitmap( KiBitmap( folder_xpm ) );
325 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:34
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
wxString AllSymbolLibFilesWildcard()
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:87
WX_GRID * m_cur_grid
changed based on tab choice
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:52
static size_t m_pageNdx
Remember the last notebook page selected during a session.
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
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE * m_projectTable
const BITMAP_OPAQUE small_down_xpm[1]
Definition: small_down.cpp:24
PANEL_SYM_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)
wxString KiCadSymbolLibFileWildcard()
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
wxString LegacySymbolLibFileWildcard()
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:25
DIALOG_EDIT_LIBRARY_TABLES * m_parent
#define _(s)
Definition: 3d_actions.cpp:33
SYMBOL_LIB_TABLE * m_globalTable
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20

References _, AllSymbolLibFilesWildcard(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, folder_xpm, KiBitmap(), KiCadSymbolLibFileWildcard(), LegacySymbolLibFileWildcard(), PANEL_SYM_LIB_TABLE_BASE::m_append_button, PANEL_SYM_LIB_TABLE_BASE::m_auinotebook, PANEL_SYM_LIB_TABLE_BASE::m_browse_button, m_cur_grid, PANEL_SYM_LIB_TABLE_BASE::m_delete_button, PANEL_SYM_LIB_TABLE_BASE::m_GblTableFilename, PANEL_SYM_LIB_TABLE_BASE::m_global_grid, EESCHEMA_SETTINGS::m_lastSymbolLibDir, PANEL_SYM_LIB_TABLE_BASE::m_move_down_button, PANEL_SYM_LIB_TABLE_BASE::m_move_up_button, m_pageNdx, m_parent, PANEL_SYM_LIB_TABLE_BASE::m_path_subs_grid, PANEL_SYM_LIB_TABLE_BASE::m_PrjTableFilename, PANEL_SYM_LIB_TABLE_BASE::m_project_grid, m_projectBasePath, Pgm(), populateEnvironReadOnlyTable(), DIALOG_SHIM::SetInitialFocus(), WX_GRID::SetTable(), SCH_IO_MGR::ShowType(), small_down_xpm, small_plus_xpm, small_up_xpm, and trash_xpm.

◆ ~PANEL_SYM_LIB_TABLE()

PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE ( )
virtual

Definition at line 328 of file panel_sym_lib_table.cpp.

329 {
330  // When the dialog is closed it will hide the current notebook page first, which will
331  // in turn select the other one. We then end up saving its index as the "current page".
332  // So flip them back again:
333  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
334 
335  // Delete the GRID_TRICKS.
336  // Any additional event handlers should be popped before the window is deleted.
337  m_global_grid->PopEventHandler( true );
338 
339  if( m_project_grid )
340  m_project_grid->PopEventHandler( true );
341 
342  m_path_subs_grid->PopEventHandler( true );
343 }
static size_t m_pageNdx
Remember the last notebook page selected during a session.

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

Member Function Documentation

◆ adjustPathSubsGridColumns()

void PANEL_SYM_LIB_TABLE::adjustPathSubsGridColumns ( int  aWidth)
private

Definition at line 796 of file panel_sym_lib_table.cpp.

797 {
798  // Account for scroll bars
799  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
800 
801  m_path_subs_grid->AutoSizeColumn( 0 );
802  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
803 }

References PANEL_SYM_LIB_TABLE_BASE::m_path_subs_grid.

Referenced by onSizeGrid(), and populateEnvironReadOnlyTable().

◆ appendRowHandler()

void PANEL_SYM_LIB_TABLE::appendRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 562 of file panel_sym_lib_table.cpp.

563 {
565  return;
566 
567  if( m_cur_grid->AppendRows( 1 ) )
568  {
569  int row = m_cur_grid->GetNumberRows() - 1;
570 
571  // wx documentation is wrong, SetGridCursor does not make visible.
572  m_cur_grid->MakeCellVisible( row, 0 );
573  m_cur_grid->SetGridCursor( row, 1 );
574  m_cur_grid->EnableCellEditControl( true );
575  m_cur_grid->ShowCellEditControl();
576  }
577 }
WX_GRID * m_cur_grid
changed based on tab choice
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ browseLibrariesHandler()

void PANEL_SYM_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 476 of file panel_sym_lib_table.cpp.

477 {
478  wxString wildcards = AllSymbolLibFilesWildcard()
480  + "|" + LegacySymbolLibFileWildcard();
481 
482  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
483  wxFileDialog dlg( this, _( "Select Library" ), cfg->m_lastSymbolLibDir, wxEmptyString, wildcards,
484  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
485 
486  auto result = dlg.ShowModal();
487 
488  if( result == wxID_CANCEL )
489  return;
490 
491  cfg->m_lastSymbolLibDir = dlg.GetDirectory();
492 
493  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
494  bool addDuplicates = false;
495  bool applyToAll = false;
496  wxString warning = _( "Warning: Duplicate Nickname" );
497  wxString msg = _( "A library nicknamed \"%s\" already exists." );
498  wxString detailedMsg = _( "Please change the library nickname after adding this library." );
499 
500  wxArrayString files;
501  dlg.GetFilenames( files );
502 
503  for( const auto& file : files )
504  {
505  wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
506  wxFileName fn( filePath );
507  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH );
508  bool doAdd = true;
509 
510  if( cur_model()->ContainsNickname( nickname ) )
511  {
512  if( !applyToAll )
513  {
514  // The cancel button adds the library to the table anyway
515  addDuplicates = ( OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
516  detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL );
517  }
518 
519  doAdd = addDuplicates;
520  }
521 
522  if( doAdd && m_cur_grid->AppendRows( 1 ) )
523  {
524  int last_row = m_cur_grid->GetNumberRows() - 1;
525 
526  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
527 
528  // TODO the following code can detect only schematic types, not libs
529  // SCH_IO_MGR needs to provide file extension information for libraries too
530 
531  // auto detect the plugin type
532  for( auto pluginType : SCH_IO_MGR::SCH_FILE_T_vector )
533  {
534  if( SCH_IO_MGR::GetLibraryFileExtension( pluginType ).Lower() == fn.GetExt().Lower() )
535  {
536  m_cur_grid->SetCellValue( last_row, COL_TYPE,
537  SCH_IO_MGR::ShowType( pluginType ) );
538  break;
539  }
540  }
541 
542  // try to use path normalized to an environmental variable or project path
543  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
544 
545  // Do not use the project path in the global library table. This will almost
546  // assuredly be wrong for a different project.
547  if( path.IsEmpty() || (m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" )) )
548  path = fn.GetFullPath();
549 
550  m_cur_grid->SetCellValue( last_row, COL_URI, path );
551  }
552  }
553 
554  if( !files.IsEmpty() )
555  {
556  m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 );
557  m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 );
558  }
559 }
wxString AllSymbolLibFilesWildcard()
bool ContainsNickname(const wxString &aNickname)
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:87
WX_GRID * m_cur_grid
changed based on tab choice
static const wxString GetLibraryFileExtension(SCH_FILE_T aFileType)
Return the symbol library file extension (if any) for aFileType.
Definition: sch_io_mgr.cpp:154
static size_t m_pageNdx
Remember the last notebook page selected during a session.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:117
SYMBOL_LIB_TABLE_GRID * cur_model() const
wxString KiCadSymbolLibFileWildcard()
wxString LegacySymbolLibFileWildcard()
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Displays a warning dialog with aMessage and returns the user response.
Definition: confirm.cpp:215
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:201
#define _(s)
Definition: 3d_actions.cpp:33
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
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:68

References _, AllSymbolLibFilesWildcard(), COL_NICKNAME, COL_TYPE, COL_URI, LIB_TABLE_GRID::ContainsNickname(), cur_model(), LIB_ID::FixIllegalChars(), Format(), SCH_IO_MGR::GetLibraryFileExtension(), LIB_ID::ID_SCH, KiCadSymbolLibFileWildcard(), LegacySymbolLibFileWildcard(), m_cur_grid, EESCHEMA_SETTINGS::m_lastSymbolLibDir, m_pageNdx, m_projectBasePath, NormalizePath(), OKOrCancelDialog(), Pgm(), and SCH_IO_MGR::ShowType().

◆ cur_model()

SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::cur_model ( ) const
private

Definition at line 826 of file panel_sym_lib_table.cpp.

827 {
828  return (SYMBOL_LIB_TABLE_GRID*) m_cur_grid->GetTable();
829 }
WX_GRID * m_cur_grid
changed based on tab choice
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.

References m_cur_grid.

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

◆ deleteRowHandler()

void PANEL_SYM_LIB_TABLE::deleteRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 580 of file panel_sym_lib_table.cpp.

581 {
583  return;
584 
585  int curRow = m_cur_grid->GetGridCursorRow();
586  int curCol = m_cur_grid->GetGridCursorCol();
587 
588  // In a wxGrid, collect rows that have a selected cell, or are selected
589  // It is not so easy: it depends on the way the selection was made.
590  // Here, we collect rows selected by clicking on a row label, and rows that contain
591  // previously-selected cells.
592  // If no candidate, just delete the row with the grid cursor.
593  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
594  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
595  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
596  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
597 
598  // Add all row having cell selected to list:
599  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
600  selectedRows.Add( cells[ii].GetRow() );
601 
602  // Handle block selection
603  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
604  {
605  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
606  selectedRows.Add( i );
607  }
608 
609  // Use the row having the grid cursor only if we have no candidate:
610  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
611  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
612 
613  if( selectedRows.size() == 0 )
614  {
615  wxBell();
616  return;
617  }
618 
619  std::sort( selectedRows.begin(), selectedRows.end() );
620 
621  // Remove selected rows (note: a row can be stored more than once in list)
622  int last_row = -1;
623 
624  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
625  {
626  int row = selectedRows[ii];
627 
628  if( row != last_row )
629  {
630  last_row = row;
631  m_cur_grid->DeleteRows( row, 1 );
632  }
633  }
634 
635  if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
636  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
637 }
WX_GRID * m_cur_grid
changed based on tab choice
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ global_model()

SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::global_model ( ) const
private

Definition at line 814 of file panel_sym_lib_table.cpp.

815 {
816  return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();
817 }
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.

References PANEL_SYM_LIB_TABLE_BASE::m_global_grid.

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

◆ moveDownHandler()

void PANEL_SYM_LIB_TABLE::moveDownHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 670 of file panel_sym_lib_table.cpp.

671 {
673  return;
674 
676  int curRow = m_cur_grid->GetGridCursorRow();
677 
678  // @todo: add multiple selection moves.
679  if( unsigned( curRow + 1 ) < tbl->rows.size() )
680  {
681  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
682  tbl->rows.release( tbl->rows.begin() + curRow );
683 
684  ++curRow;
685  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
686 
687  if( tbl->GetView() )
688  {
689  // Update the wxGrid
690  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
691  tbl->GetView()->ProcessTableMessage( msg );
692  }
693 
694  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
695  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
696  }
697 }
WX_GRID * m_cur_grid
changed based on tab choice
LIB_TABLE_ROWS rows
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180

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

◆ moveUpHandler()

void PANEL_SYM_LIB_TABLE::moveUpHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 640 of file panel_sym_lib_table.cpp.

641 {
643  return;
644 
646  int curRow = m_cur_grid->GetGridCursorRow();
647 
648  // @todo: add multiple selection moves.
649  if( curRow >= 1 )
650  {
651  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
652  tbl->rows.release( tbl->rows.begin() + curRow );
653 
654  --curRow;
655  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
656 
657  if( tbl->GetView() )
658  {
659  // Update the wxGrid
660  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
661  tbl->GetView()->ProcessTableMessage( msg );
662  }
663 
664  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
665  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
666  }
667 }
WX_GRID * m_cur_grid
changed based on tab choice
LIB_TABLE_ROWS rows
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180

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

◆ onSizeGrid()

void PANEL_SYM_LIB_TABLE::onSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 806 of file panel_sym_lib_table.cpp.

807 {
808  adjustPathSubsGridColumns( event.GetSize().GetX() );
809 
810  event.Skip();
811 }
void adjustPathSubsGridColumns(int aWidth)

References adjustPathSubsGridColumns().

◆ pageChangedHandler()

void PANEL_SYM_LIB_TABLE::pageChangedHandler ( wxAuiNotebookEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 469 of file panel_sym_lib_table.cpp.

470 {
471  m_pageNdx = (unsigned) std::max( 0, m_auinotebook->GetSelection() );
473 }
WX_GRID * m_cur_grid
changed based on tab choice
static size_t m_pageNdx
Remember the last notebook page selected during a session.

References PANEL_SYM_LIB_TABLE_BASE::m_auinotebook, m_cur_grid, PANEL_SYM_LIB_TABLE_BASE::m_global_grid, m_pageNdx, and PANEL_SYM_LIB_TABLE_BASE::m_project_grid.

◆ populateEnvironReadOnlyTable()

void PANEL_SYM_LIB_TABLE::populateEnvironReadOnlyTable ( )
private

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

Definition at line 732 of file panel_sym_lib_table.cpp.

733 {
734  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
735  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
736 
737  std::set< wxString > unique;
738 
739  // clear the table
740  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
741 
742  for( SYMBOL_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
743  {
744  if( !tbl )
745  continue;
746 
747  for( int row = 0; row < tbl->GetNumberRows(); ++row )
748  {
749  wxString uri = tbl->GetValue( row, COL_URI );
750 
751  while( re.Matches( uri ) )
752  {
753  wxString envvar = re.GetMatch( uri, 2 );
754 
755  // if not ${...} form then must be $(...)
756  if( envvar.IsEmpty() )
757  envvar = re.GetMatch( uri, 4 );
758 
759  // ignore duplicates
760  unique.insert( envvar );
761 
762  // delete the last match and search again
763  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
764  }
765  }
766  }
767 
768  // Make sure this special environment variable shows up even if it was
769  // not used yet. It is automatically set by KiCad to the directory holding
770  // the current project.
771  unique.insert( PROJECT_VAR_NAME );
773 
774  for( const wxString& evName : unique )
775  {
776  int row = m_path_subs_grid->GetNumberRows();
777  m_path_subs_grid->AppendRows( 1 );
778 
779  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
780  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
781 
782  wxString evValue;
783  wxGetEnv( evName, &evValue );
784  m_path_subs_grid->SetCellValue( row, 1, evValue );
785  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
786  }
787 
788  // No combobox editors here, but it looks better if its consistent with the other
789  // grids in the dialog.
790  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
791 
792  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
793 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
SYMBOL_LIB_TABLE_GRID * global_model() const
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
void adjustPathSubsGridColumns(int aWidth)
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE_GRID * project_model() const

References adjustPathSubsGridColumns(), COL_URI, global_model(), SYMBOL_LIB_TABLE::GlobalPathEnvVariableName(), PANEL_SYM_LIB_TABLE_BASE::m_path_subs_grid, project_model(), and PROJECT_VAR_NAME.

Referenced by PANEL_SYM_LIB_TABLE().

◆ project_model()

SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::project_model ( ) const
private

Definition at line 820 of file panel_sym_lib_table.cpp.

821 {
822  return m_project_grid ? (SYMBOL_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
823 }
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.

References PANEL_SYM_LIB_TABLE_BASE::m_project_grid.

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

◆ TransferDataFromWindow()

bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow ( )
overrideprivate

Definition at line 700 of file panel_sym_lib_table.cpp.

701 {
703  return false;
704 
705  if( !verifyTables() )
706  return false;
707 
708  if( *global_model() != *m_globalTable )
709  {
711 
712  m_globalTable->Clear();
713  m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(),
714  global_model()->rows.end(), global_model()->rows );
716  }
717 
718  if( project_model() && *project_model() != *m_projectTable )
719  {
721 
723  m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(),
724  project_model()->rows.end(), project_model()->rows );
726  }
727 
728  return true;
729 }
void Clear()
Delete all rows.
void reindex()
WX_GRID * m_cur_grid
changed based on tab choice
SYMBOL_LIB_TABLE_GRID * global_model() const
LIB_TABLE_ROWS rows
SYMBOL_LIB_TABLE * m_projectTable
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180
DIALOG_EDIT_LIBRARY_TABLES * m_parent
SYMBOL_LIB_TABLE_GRID * project_model() const
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
SYMBOL_LIB_TABLE * m_globalTable

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

◆ verifyTables()

bool PANEL_SYM_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 346 of file panel_sym_lib_table.cpp.

347 {
348  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
349  {
350  if( !model )
351  continue;
352 
353  for( int r = 0; r < model->GetNumberRows(); )
354  {
355  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
356  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
357  unsigned illegalCh = 0;
358 
359  if( !nick || !uri )
360  {
361  // Delete the "empty" row, where empty means missing nick or uri.
362  // This also updates the UI which could be slow, but there should only be a few
363  // rows to delete, unless the user fell asleep on the Add Row
364  // button.
365  model->DeleteRows( r, 1 );
366  }
367  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) )
368  {
369  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
370  illegalCh,
371  nick );
372 
373  // show the tabbed panel holding the grid we have flunked:
374  if( model != cur_model() )
375  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
376 
377  m_cur_grid->MakeCellVisible( r, 0 );
378  m_cur_grid->SetGridCursor( r, 1 );
379 
380  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
381  errdlg.ShowModal();
382  return false;
383  }
384  else
385  {
386  // set the trimmed values back into the table so they get saved to disk.
387  model->SetValue( r, COL_NICKNAME, nick );
388  model->SetValue( r, COL_URI, uri );
389  ++r; // this row was OK.
390  }
391  }
392  }
393 
394  // check for duplicate nickNames, separately in each table.
395  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
396  {
397  if( !model )
398  continue;
399 
400  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
401  {
402  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
403 
404  for( int r2=r1+1; r2 < model->GetNumberRows(); ++r2 )
405  {
406  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
407 
408  if( nick1 == nick2 )
409  {
410  wxString msg = wxString::Format( _( "Duplicate Nickname: \"%s\"." ), nick1 );
411 
412  // show the tabbed panel holding the grid we have flunked:
413  if( model != cur_model() )
414  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
415 
416  // go to the lower of the two rows, it is technically the duplicate:
417  m_cur_grid->MakeCellVisible( r2, 0 );
418  m_cur_grid->SetGridCursor( r2, 1 );
419 
420  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
421  errdlg.ShowModal();
422 
423  return false;
424  }
425  }
426  }
427  }
428 
429  for( SYMBOL_LIB_TABLE* table : { global_model(), project_model() } )
430  {
431  if( !table )
432  continue;
433 
434  for( unsigned int r = 0; r < table->GetCount(); ++r )
435  {
436  SYMBOL_LIB_TABLE_ROW& row = dynamic_cast<SYMBOL_LIB_TABLE_ROW&>( table->At( r ) );
437 
438  if( !row.GetIsEnabled() )
439  continue;
440 
441  try
442  {
443  if( row.Refresh() )
444  {
445  if( table == global_model() )
447  else
449  }
450  }
451  catch( const IO_ERROR& ioe )
452  {
453  wxString msg = wxString::Format( _( "Symbol library \"%s\" failed to load.\n %s" ),
454  row.GetNickName(),
455  ioe.What() );
456 
457  wxMessageDialog errdlg( this, msg, _( "Error Loading Library" ) );
458  errdlg.ShowModal();
459 
460  return false;
461  }
462  }
463  }
464 
465  return true;
466 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
WX_GRID * m_cur_grid
changed based on tab choice
static unsigned FindIllegalLibNicknameChar(const UTF8 &aNickname, LIB_ID_TYPE aType)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:404
SYMBOL_LIB_TABLE_GRID * global_model() const
const wxString & GetNickName() const
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
bool GetIsEnabled() const
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
SYMBOL_LIB_TABLE_GRID * cur_model() const
bool Refresh()
Attempt to reload the library.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
SYMBOL_LIB_TABLE_GRID * project_model() const
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:201
#define _(s)
Definition: 3d_actions.cpp:33
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, COL_NICKNAME, COL_URI, cur_model(), LIB_ID::FindIllegalLibNicknameChar(), Format(), LIB_TABLE_ROW::GetIsEnabled(), LIB_TABLE_ROW::GetNickName(), global_model(), LIB_ID::ID_SCH, PANEL_SYM_LIB_TABLE_BASE::m_auinotebook, m_cur_grid, DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, m_parent, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, project_model(), SYMBOL_LIB_TABLE_ROW::Refresh(), and IO_ERROR::What().

Referenced by TransferDataFromWindow().

Member Data Documentation

◆ m_append_button

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_append_button
protectedinherited

◆ m_auinotebook

wxAuiNotebook* PANEL_SYM_LIB_TABLE_BASE::m_auinotebook
protectedinherited

◆ m_browse_button

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_browse_button
protectedinherited

◆ m_cur_grid

◆ m_delete_button

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_delete_button
protectedinherited

◆ m_GblTableFilename

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_GblTableFilename
protectedinherited

◆ m_global_grid

WX_GRID* PANEL_SYM_LIB_TABLE_BASE::m_global_grid
protectedinherited

◆ m_global_panel

wxPanel* PANEL_SYM_LIB_TABLE_BASE::m_global_panel
protectedinherited

◆ m_globalTable

SYMBOL_LIB_TABLE* PANEL_SYM_LIB_TABLE::m_globalTable
private

Definition at line 68 of file panel_sym_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_move_down_button

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_move_down_button
protectedinherited

◆ m_move_up_button

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_move_up_button
protectedinherited

◆ m_pageNdx

size_t PANEL_SYM_LIB_TABLE::m_pageNdx = 0
staticprivate

Remember the last notebook page selected during a session.

Definition at line 81 of file panel_sym_lib_table.h.

Referenced by browseLibrariesHandler(), pageChangedHandler(), PANEL_SYM_LIB_TABLE(), and ~PANEL_SYM_LIB_TABLE().

◆ m_parent

DIALOG_EDIT_LIBRARY_TABLES* PANEL_SYM_LIB_TABLE::m_parent
private

Definition at line 78 of file panel_sym_lib_table.h.

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

◆ m_path_subs_grid

◆ m_PrjTableFilename

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_PrjTableFilename
protectedinherited

◆ m_project_grid

WX_GRID* PANEL_SYM_LIB_TABLE_BASE::m_project_grid
protectedinherited

◆ m_project_panel

wxPanel* PANEL_SYM_LIB_TABLE_BASE::m_project_panel
protectedinherited

◆ m_projectBasePath

wxString PANEL_SYM_LIB_TABLE::m_projectBasePath
private

Definition at line 70 of file panel_sym_lib_table.h.

Referenced by browseLibrariesHandler(), and PANEL_SYM_LIB_TABLE().

◆ m_projectTable

SYMBOL_LIB_TABLE* PANEL_SYM_LIB_TABLE::m_projectTable
private

Definition at line 69 of file panel_sym_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_staticText3

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_staticText3
protectedinherited

◆ m_staticText4

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_staticText4
protectedinherited

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