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...
 
wxString m_lastBrowseDir
 last browsed directory 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 148 of file panel_sym_lib_table.cpp.

153  :
154  PANEL_SYM_LIB_TABLE_BASE( aParent ),
155  m_globalTable( aGlobal ),
156  m_projectTable( aProject ),
157  m_projectBasePath( aProjectBasePath ),
158  m_parent( aParent ),
159  m_lastBrowseDir( aProjectBasePath )
160 {
161  // For user info, shows the table filenames:
162  m_GblTableFilename->SetLabel( aGlobalTablePath );
163  m_PrjTableFilename->SetLabel( aProjectTablePath );
164 
165  // wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
166  // so make it a grid owned table.
167  m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aGlobal ), true );
168  m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aProject ), true );
169 
170  // Give a bit more room for combobox editors
171  m_global_grid->SetDefaultRowSize( m_global_grid->GetDefaultRowSize() + 4 );
172  m_project_grid->SetDefaultRowSize( m_project_grid->GetDefaultRowSize() + 4 );
173 
174  // add Cut, Copy, and Paste to wxGrids
175  m_global_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, m_global_grid ) );
176  m_project_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, m_project_grid ) );
177  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
178 
179  m_global_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
180  m_project_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
181 
182  m_global_grid->AutoSizeColumns( false );
183  m_project_grid->AutoSizeColumns( false );
184 
185  wxArrayString pluginChoices;
186 
187 // pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD ) );
188  pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
189 
191 
192  for( wxGrid* g : { m_global_grid, m_project_grid } )
193  {
194  // Set special attributes
195  wxGridCellAttr* attr;
196 
197  attr = new wxGridCellAttr;
198  attr->SetEditor( new GRID_CELL_SYMLIB_EDITOR( m_parent, &m_lastBrowseDir,
200  g->SetColAttr( COL_URI, attr );
201 
202  attr = new wxGridCellAttr;
203  attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
204  g->SetColAttr( COL_TYPE, attr );
205 
206  attr = new wxGridCellAttr;
207  attr->SetRenderer( new wxGridCellBoolRenderer() );
208  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
209  g->SetColAttr( COL_ENABLED, attr );
210 
211  // all but COL_OPTIONS, which is edited with Option Editor anyways.
212  g->AutoSizeColumn( COL_NICKNAME, false );
213  g->AutoSizeColumn( COL_TYPE, false );
214  g->AutoSizeColumn( COL_URI, false );
215  g->AutoSizeColumn( COL_DESCR, false );
216  g->AutoSizeColumn( COL_ENABLED, false );
217 
218  // would set this to width of title, if it was easily known.
219  g->SetColSize( COL_OPTIONS, 80 );
220  }
221 
222  // select the last selected page
223  m_auinotebook->SetSelection( m_pageNdx );
225 
226  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
227  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
228 
229  // for ALT+A handling, we want the initial focus to be on the first selected grid.
231 
232  // Configure button logos
233  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
234  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
235  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
236  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
237  m_browse_button->SetBitmap( KiBitmap( folder_xpm ) );
238 
239  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
240  // a currentCell which is sometimes not highlighted.
241  if( m_global_grid->GetNumberRows() > 0 )
242  m_global_grid->SelectRow( 0 );
243 
244  if( m_project_grid->GetNumberRows() > 0 )
245  m_project_grid->SelectRow( 0 );
246 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
PANEL_SYM_LIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 300), long style=wxTAB_TRAVERSAL)
WX_GRID * m_cur_grid
changed based on tab choice
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
wxString SchematicLibraryFileWildcard()
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:57
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:118
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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
#define _(s)
DIALOG_EDIT_LIBRARY_TABLES * m_parent
wxString m_lastBrowseDir
last browsed directory
SYMBOL_LIB_TABLE * m_globalTable

References _, COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, KiBitmap(), 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, m_lastBrowseDir, 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, populateEnvironReadOnlyTable(), SchematicLibraryFileWildcard(), DIALOG_SHIM::SetInitialFocus(), WX_GRID::SetTable(), and SCH_IO_MGR::ShowType().

◆ ~PANEL_SYM_LIB_TABLE()

PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE ( )
virtual

Definition at line 249 of file panel_sym_lib_table.cpp.

250 {
251  // When the dialog is closed it will hide the current notebook page first, which will
252  // in turn select the other one. We then end up saving its index as the "current page".
253  // So flip them back again:
254  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
255 
256  // Delete the GRID_TRICKS.
257  // Any additional event handlers should be popped before the window is deleted.
258  m_global_grid->PopEventHandler( true );
259  m_project_grid->PopEventHandler( true );
260  m_path_subs_grid->PopEventHandler( true );
261 }
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 667 of file panel_sym_lib_table.cpp.

668 {
669  // Account for scroll bars
670  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
671 
672  m_path_subs_grid->AutoSizeColumn( 0 );
673  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
674 }

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 434 of file panel_sym_lib_table.cpp.

435 {
437  return;
438 
439  if( m_cur_grid->AppendRows( 1 ) )
440  {
441  int row = m_cur_grid->GetNumberRows() - 1;
442  // Gives a default type (currently, only one type exists):
443  m_cur_grid->SetCellValue( row, COL_TYPE, SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
444 
445  // wx documentation is wrong, SetGridCursor does not make visible.
446  m_cur_grid->MakeCellVisible( row, 0 );
447  m_cur_grid->SetGridCursor( row, 1 );
448 
449  m_cur_grid->EnableCellEditControl( true );
450  m_cur_grid->ShowCellEditControl();
451  }
452 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
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:172

References COL_TYPE, WX_GRID::CommitPendingChanges(), m_cur_grid, and SCH_IO_MGR::ShowType().

◆ browseLibrariesHandler()

void PANEL_SYM_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 352 of file panel_sym_lib_table.cpp.

353 {
354  wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir,
355  wxEmptyString, SchematicLibraryFileWildcard(),
356  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
357 
358  auto result = dlg.ShowModal();
359 
360  if( result == wxID_CANCEL )
361  return;
362 
363  m_lastBrowseDir = dlg.GetDirectory();
364 
365  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
366  bool addDuplicates = false;
367  bool applyToAll = false;
368  wxString warning = _( "Warning: Duplicate Nickname" );
369  wxString msg = _( "A library nicknamed \"%s\" already exists." );
370  wxArrayString files;
371  dlg.GetFilenames( files );
372 
373  for( const auto& file : files )
374  {
375  wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
376  wxFileName fn( filePath );
377  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH );
378  bool doAdd = true;
379 
380  if( cur_model()->ContainsNickname( nickname ) )
381  {
382  if( !applyToAll )
383  {
384  int ret = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
385  _( "Skip" ), _( "Add Anyway" ), &applyToAll );
386  addDuplicates = (ret == wxID_CANCEL );
387  }
388 
389  doAdd = addDuplicates;
390  }
391 
392  if( doAdd && m_cur_grid->AppendRows( 1 ) )
393  {
394  int last_row = m_cur_grid->GetNumberRows() - 1;
395 
396  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
397 
398  // TODO the following code can detect only schematic types, not libs
399  // SCH_IO_MGR needs to provide file extension information for libraries too
400 
401  // auto detect the plugin type
402  /*for( auto pluginType : SCH_IO_MGR::SCH_FILE_T_vector )
403  {
404  if( SCH_IO_MGR::GetFileExtension( pluginType ).Lower() == fn.GetExt().Lower() )
405  {
406  m_cur_grid->SetCellValue( last_row, COL_TYPE,
407  SCH_IO_MGR::ShowType( pluginType ) );
408  break;
409  }
410  }*/
411  m_cur_grid->SetCellValue( last_row, COL_TYPE,
412  SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
413 
414  // try to use path normalized to an environmental variable or project path
415  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
416 
417  // Do not use the project path in the global library table. This will almost
418  // assuredly be wrong for a different project.
419  if( path.IsEmpty() || (m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" )) )
420  path = fn.GetFullPath();
421 
422  m_cur_grid->SetCellValue( last_row, COL_URI, path );
423  }
424  }
425 
426  if( !files.IsEmpty() )
427  {
428  m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 );
429  m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 );
430  }
431 }
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:76
WX_GRID * m_cur_grid
changed based on tab choice
wxString SchematicLibraryFileWildcard()
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 size_t m_pageNdx
Remember the last notebook page selected during a session.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:146
SYMBOL_LIB_TABLE_GRID * cur_model() const
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:325
#define _(s)
wxString m_lastBrowseDir
last browsed directory
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
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, LIB_TABLE_GRID::ContainsNickname(), cur_model(), LIB_ID::FixIllegalChars(), Format(), PGM_BASE::GetLocalEnvVariables(), LIB_ID::ID_SCH, m_cur_grid, m_lastBrowseDir, m_pageNdx, m_projectBasePath, NormalizePath(), OKOrCancelDialog(), Pgm(), SchematicLibraryFileWildcard(), and SCH_IO_MGR::ShowType().

◆ cur_model()

SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::cur_model ( ) const
private

Definition at line 697 of file panel_sym_lib_table.cpp.

698 {
699  return (SYMBOL_LIB_TABLE_GRID*) m_cur_grid->GetTable();
700 }
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 455 of file panel_sym_lib_table.cpp.

456 {
458  return;
459 
460  int curRow = m_cur_grid->GetGridCursorRow();
461  int curCol = m_cur_grid->GetGridCursorCol();
462 
463  // In a wxGrid, collect rows that have a selected cell, or are selected
464  // It is not so easy: it depends on the way the selection was made.
465  // Here, we collect rows selected by clicking on a row label, and rows that contain
466  // previously-selected cells.
467  // If no candidate, just delete the row with the grid cursor.
468  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
469  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
470  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
471  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
472 
473  // Add all row having cell selected to list:
474  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
475  selectedRows.Add( cells[ii].GetRow() );
476 
477  // Handle block selection
478  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
479  {
480  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
481  selectedRows.Add( i );
482  }
483 
484  // Use the row having the grid cursor only if we have no candidate:
485  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
486  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
487 
488  if( selectedRows.size() == 0 )
489  {
490  wxBell();
491  return;
492  }
493 
494  std::sort( selectedRows.begin(), selectedRows.end() );
495 
496  // Remove selected rows (note: a row can be stored more than once in list)
497  int last_row = -1;
498 
499  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
500  {
501  int row = selectedRows[ii];
502 
503  if( row != last_row )
504  {
505  last_row = row;
506  m_cur_grid->DeleteRows( row, 1 );
507  }
508  }
509 
510  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
511 }
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: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()

SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::global_model ( ) const
private

Definition at line 685 of file panel_sym_lib_table.cpp.

686 {
687  return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();
688 }
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 544 of file panel_sym_lib_table.cpp.

545 {
547  return;
548 
550  int curRow = m_cur_grid->GetGridCursorRow();
551 
552  // @todo: add multiple selection moves.
553  if( unsigned( curRow + 1 ) < tbl->rows.size() )
554  {
555  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
556  tbl->rows.release( tbl->rows.begin() + curRow );
557 
558  ++curRow;
559  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
560 
561  if( tbl->GetView() )
562  {
563  // Update the wxGrid
564  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
565  tbl->GetView()->ProcessTableMessage( msg );
566  }
567 
568  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
569  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
570  }
571 }
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:172

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 514 of file panel_sym_lib_table.cpp.

515 {
517  return;
518 
520  int curRow = m_cur_grid->GetGridCursorRow();
521 
522  // @todo: add multiple selection moves.
523  if( curRow >= 1 )
524  {
525  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
526  tbl->rows.release( tbl->rows.begin() + curRow );
527 
528  --curRow;
529  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
530 
531  if( tbl->GetView() )
532  {
533  // Update the wxGrid
534  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
535  tbl->GetView()->ProcessTableMessage( msg );
536  }
537 
538  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
539  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
540  }
541 }
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:172

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 677 of file panel_sym_lib_table.cpp.

678 {
679  adjustPathSubsGridColumns( event.GetSize().GetX() );
680 
681  event.Skip();
682 }
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 345 of file panel_sym_lib_table.cpp.

346 {
347  m_pageNdx = (unsigned) std::max( 0, m_auinotebook->GetSelection() );
349 }
WX_GRID * m_cur_grid
changed based on tab choice
static size_t m_pageNdx
Remember the last notebook page selected during a session.
#define max(a, b)
Definition: auxiliary.h:86

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

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

607 {
608  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
609  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
610 
611  std::set< wxString > unique;
612 
613  // clear the table
614  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
615 
616  for( SYMBOL_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
617  {
618  for( int row = 0; row < tbl->GetNumberRows(); ++row )
619  {
620  wxString uri = tbl->GetValue( row, COL_URI );
621 
622  while( re.Matches( uri ) )
623  {
624  wxString envvar = re.GetMatch( uri, 2 );
625 
626  // if not ${...} form then must be $(...)
627  if( envvar.IsEmpty() )
628  envvar = re.GetMatch( uri, 4 );
629 
630  // ignore duplicates
631  unique.insert( envvar );
632 
633  // delete the last match and search again
634  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
635  }
636  }
637  }
638 
639  // Make sure this special environment variable shows up even if it was
640  // not used yet. It is automatically set by KiCad to the directory holding
641  // the current project.
642  unique.insert( PROJECT_VAR_NAME );
644 
645  for( wxString evName : unique )
646  {
647  int row = m_path_subs_grid->GetNumberRows();
648  m_path_subs_grid->AppendRows( 1 );
649 
650  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
651  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
652 
653  wxString evValue;
654  wxGetEnv( evName, &evValue );
655  m_path_subs_grid->SetCellValue( row, 1, evValue );
656  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
657  }
658 
659  // No combobox editors here, but it looks better if its consistent with the other
660  // grids in the dialog.
661  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
662 
663  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
664 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
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 691 of file panel_sym_lib_table.cpp.

692 {
693  return (SYMBOL_LIB_TABLE_GRID*) m_project_grid->GetTable();
694 }
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 574 of file panel_sym_lib_table.cpp.

575 {
577  return false;
578 
579  if( !verifyTables() )
580  return false;
581 
582  if( *global_model() != *m_globalTable )
583  {
585 
586  m_globalTable->Clear();
587  m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(),
588  global_model()->rows.end(), global_model()->rows );
590  }
591 
592  if( *project_model() != *m_projectTable )
593  {
595 
597  m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(),
598  project_model()->rows.end(), project_model()->rows );
600  }
601 
602  return true;
603 }
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:172
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 264 of file panel_sym_lib_table.cpp.

265 {
266  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
267  {
268  for( int r = 0; r < model->GetNumberRows(); )
269  {
270  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
271  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
272  unsigned illegalCh = 0;
273 
274  if( !nick || !uri )
275  {
276  // Delete the "empty" row, where empty means missing nick or uri.
277  // This also updates the UI which could be slow, but there should only be a few
278  // rows to delete, unless the user fell asleep on the Add Row
279  // button.
280  model->DeleteRows( r, 1 );
281  }
282  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) )
283  {
284  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
285  illegalCh,
286  nick );
287 
288  // show the tabbed panel holding the grid we have flunked:
289  if( model != cur_model() )
290  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
291 
292  m_cur_grid->MakeCellVisible( r, 0 );
293  m_cur_grid->SetGridCursor( r, 1 );
294 
295  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
296  errdlg.ShowModal();
297  return false;
298  }
299  else
300  {
301  // set the trimmed values back into the table so they get saved to disk.
302  model->SetValue( r, COL_NICKNAME, nick );
303  model->SetValue( r, COL_URI, uri );
304  ++r; // this row was OK.
305  }
306  }
307  }
308 
309  // check for duplicate nickNames, separately in each table.
310  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
311  {
312  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
313  {
314  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
315 
316  for( int r2=r1+1; r2 < model->GetNumberRows(); ++r2 )
317  {
318  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
319 
320  if( nick1 == nick2 )
321  {
322  wxString msg = wxString::Format( _( "Duplicate Nickname: \"%s\"." ), nick1 );
323 
324  // show the tabbed panel holding the grid we have flunked:
325  if( model != cur_model() )
326  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
327 
328  // go to the lower of the two rows, it is technically the duplicate:
329  m_cur_grid->MakeCellVisible( r2, 0 );
330  m_cur_grid->SetGridCursor( r2, 1 );
331 
332  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
333  errdlg.ShowModal();
334 
335  return false;
336  }
337  }
338  }
339  }
340 
341  return true;
342 }
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
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE_GRID * cur_model() const
#define _(s)
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:205

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

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_lastBrowseDir

wxString PANEL_SYM_LIB_TABLE::m_lastBrowseDir
private

last browsed directory

Definition at line 82 of file panel_sym_lib_table.h.

Referenced by browseLibrariesHandler(), and PANEL_SYM_LIB_TABLE().

◆ 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(), and TransferDataFromWindow().

◆ 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().

◆ 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: