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

212  :
213  PANEL_SYM_LIB_TABLE_BASE( aParent ),
214  m_globalTable( aGlobal ),
215  m_projectTable( aProject ),
216  m_projectBasePath( aProjectBasePath ),
217  m_parent( aParent ),
218  m_lastBrowseDir( aProjectBasePath )
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  auto setupGrid =
233  [&]( WX_GRID* aGrid )
234  {
235  // Give a bit more room for combobox editors
236  aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
237 
238  // add Cut, Copy, and Paste to wxGrids
239  aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, aGrid ) );
240 
241  aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
242  aGrid->AutoSizeColumns( false );
243 
244  // Set special attributes
245  wxGridCellAttr* attr;
246 
247  attr = new wxGridCellAttr;
248  attr->SetEditor( new GRID_CELL_SYMLIB_EDITOR( m_parent, &m_lastBrowseDir,
250  aGrid->SetColAttr( COL_URI, attr );
251 
252  attr = new wxGridCellAttr;
253  attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
254  aGrid->SetColAttr( COL_TYPE, attr );
255 
256  attr = new wxGridCellAttr;
257  attr->SetRenderer( new wxGridCellBoolRenderer() );
258  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
259  aGrid->SetColAttr( COL_ENABLED, attr );
260 
261  // all but COL_OPTIONS, which is edited with Option Editor anyways.
262  aGrid->AutoSizeColumn( COL_NICKNAME, false );
263  aGrid->AutoSizeColumn( COL_TYPE, false );
264  aGrid->AutoSizeColumn( COL_URI, false );
265  aGrid->AutoSizeColumn( COL_DESCR, false );
266  aGrid->AutoSizeColumn( COL_ENABLED, false );
267 
268  // would set this to width of title, if it was easily known.
269  aGrid->SetColSize( COL_OPTIONS, 80 );
270 
271  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
272  // a currentCell which is sometimes not highlighted.
273  if( aGrid->GetNumberRows() > 0 )
274  aGrid->SelectRow( 0 );
275  };
276 
277  setupGrid( m_global_grid );
278 
279  if( aProject )
280  {
281  m_PrjTableFilename->SetLabel( aProjectTablePath );
282  m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aProject ), true );
283  setupGrid( m_project_grid );
284  }
285  else
286  {
287  m_pageNdx = 0;
288  m_auinotebook->DeletePage( 1 );
289  m_project_grid = nullptr;
290  }
291 
292  // add Cut, Copy, and Paste to wxGrids
293  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
294 
296 
297  // select the last selected page
298  m_auinotebook->SetSelection( m_pageNdx );
300 
301  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
302  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
303 
304  // for ALT+A handling, we want the initial focus to be on the first selected grid.
306 
307  // Configure button logos
308  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
309  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
310  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
311  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
312  m_browse_button->SetBitmap( KiBitmap( folder_xpm ) );
313 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:81
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:51
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:59
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
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:25
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()
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:26
DIALOG_EDIT_LIBRARY_TABLES * m_parent
wxString m_lastBrowseDir
last browsed directory
#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 _, COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, folder_xpm, KiBitmap(), KiCadSymbolLibFileWildcard(), 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(), 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 316 of file panel_sym_lib_table.cpp.

317 {
318  // When the dialog is closed it will hide the current notebook page first, which will
319  // in turn select the other one. We then end up saving its index as the "current page".
320  // So flip them back again:
321  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
322 
323  // Delete the GRID_TRICKS.
324  // Any additional event handlers should be popped before the window is deleted.
325  m_global_grid->PopEventHandler( true );
326 
327  if( m_project_grid )
328  m_project_grid->PopEventHandler( true );
329 
330  m_path_subs_grid->PopEventHandler( true );
331 }
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 783 of file panel_sym_lib_table.cpp.

784 {
785  // Account for scroll bars
786  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
787 
788  m_path_subs_grid->AutoSizeColumn( 0 );
789  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
790 }

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

550 {
552  return;
553 
554  if( m_cur_grid->AppendRows( 1 ) )
555  {
556  int row = m_cur_grid->GetNumberRows() - 1;
557 
558  // wx documentation is wrong, SetGridCursor does not make visible.
559  m_cur_grid->MakeCellVisible( row, 0 );
560  m_cur_grid->SetGridCursor( row, 1 );
561  m_cur_grid->EnableCellEditControl( true );
562  m_cur_grid->ShowCellEditControl();
563  }
564 }
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:174

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

465 {
466  wxString wildcards = AllSymbolLibFilesWildcard()
468  + "|" + LegacySymbolLibFileWildcard();
469 
470  wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, wxEmptyString, wildcards,
471  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
472 
473  auto result = dlg.ShowModal();
474 
475  if( result == wxID_CANCEL )
476  return;
477 
478  m_lastBrowseDir = dlg.GetDirectory();
479 
480  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
481  bool addDuplicates = false;
482  bool applyToAll = false;
483  wxString warning = _( "Warning: Duplicate Nickname" );
484  wxString msg = _( "A library nicknamed \"%s\" already exists." );
485  wxString detailedMsg = _( "Please change the library nickname after adding this library." );
486 
487  wxArrayString files;
488  dlg.GetFilenames( files );
489 
490  for( const auto& file : files )
491  {
492  wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
493  wxFileName fn( filePath );
494  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH );
495  bool doAdd = true;
496 
497  if( cur_model()->ContainsNickname( nickname ) )
498  {
499  if( !applyToAll )
500  {
501  // The cancel button adds the library to the table anyway
502  addDuplicates = ( OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
503  detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL );
504  }
505 
506  doAdd = addDuplicates;
507  }
508 
509  if( doAdd && m_cur_grid->AppendRows( 1 ) )
510  {
511  int last_row = m_cur_grid->GetNumberRows() - 1;
512 
513  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
514 
515  // TODO the following code can detect only schematic types, not libs
516  // SCH_IO_MGR needs to provide file extension information for libraries too
517 
518  // auto detect the plugin type
519  for( auto pluginType : SCH_IO_MGR::SCH_FILE_T_vector )
520  {
521  if( SCH_IO_MGR::GetLibraryFileExtension( pluginType ).Lower() == fn.GetExt().Lower() )
522  {
523  m_cur_grid->SetCellValue( last_row, COL_TYPE,
524  SCH_IO_MGR::ShowType( pluginType ) );
525  break;
526  }
527  }
528 
529  // try to use path normalized to an environmental variable or project path
530  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
531 
532  // Do not use the project path in the global library table. This will almost
533  // assuredly be wrong for a different project.
534  if( path.IsEmpty() || (m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" )) )
535  path = fn.GetFullPath();
536 
537  m_cur_grid->SetCellValue( last_row, COL_URI, path );
538  }
539  }
540 
541  if( !files.IsEmpty() )
542  {
543  m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 );
544  m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 );
545  }
546 }
wxString AllSymbolLibFilesWildcard()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
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:81
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:138
static size_t m_pageNdx
Remember the last notebook page selected during a session.
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:214
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
#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, m_lastBrowseDir, 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 813 of file panel_sym_lib_table.cpp.

814 {
815  return (SYMBOL_LIB_TABLE_GRID*) m_cur_grid->GetTable();
816 }
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 567 of file panel_sym_lib_table.cpp.

568 {
570  return;
571 
572  int curRow = m_cur_grid->GetGridCursorRow();
573  int curCol = m_cur_grid->GetGridCursorCol();
574 
575  // In a wxGrid, collect rows that have a selected cell, or are selected
576  // It is not so easy: it depends on the way the selection was made.
577  // Here, we collect rows selected by clicking on a row label, and rows that contain
578  // previously-selected cells.
579  // If no candidate, just delete the row with the grid cursor.
580  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
581  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
582  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
583  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
584 
585  // Add all row having cell selected to list:
586  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
587  selectedRows.Add( cells[ii].GetRow() );
588 
589  // Handle block selection
590  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
591  {
592  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
593  selectedRows.Add( i );
594  }
595 
596  // Use the row having the grid cursor only if we have no candidate:
597  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
598  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
599 
600  if( selectedRows.size() == 0 )
601  {
602  wxBell();
603  return;
604  }
605 
606  std::sort( selectedRows.begin(), selectedRows.end() );
607 
608  // Remove selected rows (note: a row can be stored more than once in list)
609  int last_row = -1;
610 
611  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
612  {
613  int row = selectedRows[ii];
614 
615  if( row != last_row )
616  {
617  last_row = row;
618  m_cur_grid->DeleteRows( row, 1 );
619  }
620  }
621 
622  if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
623  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
624 }
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:174

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

802 {
803  return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();
804 }
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 657 of file panel_sym_lib_table.cpp.

658 {
660  return;
661 
663  int curRow = m_cur_grid->GetGridCursorRow();
664 
665  // @todo: add multiple selection moves.
666  if( unsigned( curRow + 1 ) < tbl->rows.size() )
667  {
668  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
669  tbl->rows.release( tbl->rows.begin() + curRow );
670 
671  ++curRow;
672  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
673 
674  if( tbl->GetView() )
675  {
676  // Update the wxGrid
677  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
678  tbl->GetView()->ProcessTableMessage( msg );
679  }
680 
681  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
682  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
683  }
684 }
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:174

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

628 {
630  return;
631 
633  int curRow = m_cur_grid->GetGridCursorRow();
634 
635  // @todo: add multiple selection moves.
636  if( curRow >= 1 )
637  {
638  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
639  tbl->rows.release( tbl->rows.begin() + curRow );
640 
641  --curRow;
642  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
643 
644  if( tbl->GetView() )
645  {
646  // Update the wxGrid
647  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
648  tbl->GetView()->ProcessTableMessage( msg );
649  }
650 
651  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
652  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
653  }
654 }
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:174

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

794 {
795  adjustPathSubsGridColumns( event.GetSize().GetX() );
796 
797  event.Skip();
798 }
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 457 of file panel_sym_lib_table.cpp.

458 {
459  m_pageNdx = (unsigned) std::max( 0, m_auinotebook->GetSelection() );
461 }
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 719 of file panel_sym_lib_table.cpp.

720 {
721  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
722  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
723 
724  std::set< wxString > unique;
725 
726  // clear the table
727  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
728 
729  for( SYMBOL_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
730  {
731  if( !tbl )
732  continue;
733 
734  for( int row = 0; row < tbl->GetNumberRows(); ++row )
735  {
736  wxString uri = tbl->GetValue( row, COL_URI );
737 
738  while( re.Matches( uri ) )
739  {
740  wxString envvar = re.GetMatch( uri, 2 );
741 
742  // if not ${...} form then must be $(...)
743  if( envvar.IsEmpty() )
744  envvar = re.GetMatch( uri, 4 );
745 
746  // ignore duplicates
747  unique.insert( envvar );
748 
749  // delete the last match and search again
750  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
751  }
752  }
753  }
754 
755  // Make sure this special environment variable shows up even if it was
756  // not used yet. It is automatically set by KiCad to the directory holding
757  // the current project.
758  unique.insert( PROJECT_VAR_NAME );
760 
761  for( const wxString& evName : unique )
762  {
763  int row = m_path_subs_grid->GetNumberRows();
764  m_path_subs_grid->AppendRows( 1 );
765 
766  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
767  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
768 
769  wxString evValue;
770  wxGetEnv( evName, &evValue );
771  m_path_subs_grid->SetCellValue( row, 1, evValue );
772  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
773  }
774 
775  // No combobox editors here, but it looks better if its consistent with the other
776  // grids in the dialog.
777  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
778 
779  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
780 }
#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 807 of file panel_sym_lib_table.cpp.

808 {
809  return m_project_grid ? (SYMBOL_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
810 }
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 687 of file panel_sym_lib_table.cpp.

688 {
690  return false;
691 
692  if( !verifyTables() )
693  return false;
694 
695  if( *global_model() != *m_globalTable )
696  {
698 
699  m_globalTable->Clear();
700  m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(),
701  global_model()->rows.end(), global_model()->rows );
703  }
704 
705  if( project_model() && *project_model() != *m_projectTable )
706  {
708 
710  m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(),
711  project_model()->rows.end(), project_model()->rows );
713  }
714 
715  return true;
716 }
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:174
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 334 of file panel_sym_lib_table.cpp.

335 {
336  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
337  {
338  if( !model )
339  continue;
340 
341  for( int r = 0; r < model->GetNumberRows(); )
342  {
343  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
344  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
345  unsigned illegalCh = 0;
346 
347  if( !nick || !uri )
348  {
349  // Delete the "empty" row, where empty means missing nick or uri.
350  // This also updates the UI which could be slow, but there should only be a few
351  // rows to delete, unless the user fell asleep on the Add Row
352  // button.
353  model->DeleteRows( r, 1 );
354  }
355  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) )
356  {
357  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
358  illegalCh,
359  nick );
360 
361  // show the tabbed panel holding the grid we have flunked:
362  if( model != cur_model() )
363  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
364 
365  m_cur_grid->MakeCellVisible( r, 0 );
366  m_cur_grid->SetGridCursor( r, 1 );
367 
368  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
369  errdlg.ShowModal();
370  return false;
371  }
372  else
373  {
374  // set the trimmed values back into the table so they get saved to disk.
375  model->SetValue( r, COL_NICKNAME, nick );
376  model->SetValue( r, COL_URI, uri );
377  ++r; // this row was OK.
378  }
379  }
380  }
381 
382  // check for duplicate nickNames, separately in each table.
383  for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
384  {
385  if( !model )
386  continue;
387 
388  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
389  {
390  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
391 
392  for( int r2=r1+1; r2 < model->GetNumberRows(); ++r2 )
393  {
394  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
395 
396  if( nick1 == nick2 )
397  {
398  wxString msg = wxString::Format( _( "Duplicate Nickname: \"%s\"." ), nick1 );
399 
400  // show the tabbed panel holding the grid we have flunked:
401  if( model != cur_model() )
402  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
403 
404  // go to the lower of the two rows, it is technically the duplicate:
405  m_cur_grid->MakeCellVisible( r2, 0 );
406  m_cur_grid->SetGridCursor( r2, 1 );
407 
408  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
409  errdlg.ShowModal();
410 
411  return false;
412  }
413  }
414  }
415  }
416 
417  for( SYMBOL_LIB_TABLE* table : { global_model(), project_model() } )
418  {
419  if( !table )
420  continue;
421 
422  for( unsigned int r = 0; r < table->GetCount(); ++r )
423  {
424  SYMBOL_LIB_TABLE_ROW& row = dynamic_cast<SYMBOL_LIB_TABLE_ROW&>( table->At( r ) );
425 
426  if( !row.GetIsEnabled() )
427  continue;
428 
429  try
430  {
431  if( row.Refresh() )
432  {
433  if( table == global_model() )
435  else
437  }
438  }
439  catch( const IO_ERROR& ioe )
440  {
441  wxString msg = wxString::Format( _( "Symbol library \"%s\" failed to load.\n %s" ),
442  row.GetNickName(),
443  ioe.What() );
444 
445  wxMessageDialog errdlg( this, msg, _( "Error Loading Library" ) );
446  errdlg.ShowModal();
447 
448  return false;
449  }
450  }
451  }
452 
453  return true;
454 }
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:205
#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_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(), 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().

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