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

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, 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(), and SCH_IO_MGR::ShowType().

Referenced by InvokeSchEditSymbolLibTable().

149  :
150  PANEL_SYM_LIB_TABLE_BASE( aParent ),
151  m_globalTable( aGlobal ),
152  m_projectTable( aProject ),
153  m_projectBasePath( aProjectBasePath ),
154  m_parent( aParent )
155 {
156  // For user info, shows the table filenames:
157  m_GblTableFilename->SetLabel( aGlobalTablePath );
158  m_PrjTableFilename->SetLabel( aProjectTablePath );
159 
160  // wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
161  // so make it a grid owned table.
162  m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aGlobal ), true );
163  m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aProject ), true );
164 
165  // Give a bit more room for combobox editors
166  m_global_grid->SetDefaultRowSize( m_global_grid->GetDefaultRowSize() + 2 );
167  m_project_grid->SetDefaultRowSize( m_project_grid->GetDefaultRowSize() + 2 );
168 
169  // add Cut, Copy, and Paste to wxGrids
170  m_global_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, m_global_grid ) );
171  m_project_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, m_project_grid ) );
172  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
173 
174  m_global_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
175  m_project_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
176 
177  m_global_grid->AutoSizeColumns( false );
178  m_project_grid->AutoSizeColumns( false );
179 
180  wxArrayString pluginChoices;
181 
182 // pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD ) );
183  pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
184 
186 
187  for( wxGrid* g : { m_global_grid, m_project_grid } )
188  {
189  // Set special attributes
190  wxGridCellAttr* attr;
191 
192  attr = new wxGridCellAttr;
193  attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
194  g->SetColAttr( COL_TYPE, attr );
195 
196  attr = new wxGridCellAttr;
197  attr->SetRenderer( new wxGridCellBoolRenderer() );
198  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
199  g->SetColAttr( COL_ENABLED, attr );
200 
201  // all but COL_OPTIONS, which is edited with Option Editor anyways.
202  g->AutoSizeColumn( COL_NICKNAME, false );
203  g->AutoSizeColumn( COL_TYPE, false );
204  g->AutoSizeColumn( COL_URI, false );
205  g->AutoSizeColumn( COL_DESCR, false );
206  g->AutoSizeColumn( COL_ENABLED, false );
207 
208  // would set this to width of title, if it was easily known.
209  g->SetColSize( COL_OPTIONS, 80 );
210  }
211 
212  // select the last selected page
213  m_auinotebook->SetSelection( m_pageNdx );
215 
216  // for ALT+A handling, we want the initial focus to be on the first selected grid.
218 
219  // Configure button logos
220  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
221  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
222  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
223  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
224  m_browse_button->SetBitmap( KiBitmap( folder_xpm ) );
225 
226  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
227  // a currentCell which is sometimes not highlighted.
228  if( m_global_grid->GetNumberRows() > 0 )
229  m_global_grid->SelectRow( 0 );
230 
231  if( m_project_grid->GetNumberRows() > 0 )
232  m_project_grid->SelectRow( 0 );
233 }
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 cut, copy, and paste to an otherwise unmodied wxGrid instance...
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&#39;s SetTable() method with one which doesn&#39;t mess up the grid column widths when setting th...
Definition: wx_grid.cpp:46
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:86
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
DIALOG_EDIT_LIBRARY_TABLES * m_parent
SYMBOL_LIB_TABLE * m_globalTable
PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE ( )
virtual

Definition at line 236 of file panel_sym_lib_table.cpp.

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.

237 {
238  // When the dialog is closed it will hide the current notebook page first, which will
239  // in turn select the other one. We then end up saving its index as the "current page".
240  // So flip them back again:
241  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
242 
243  // Delete the GRID_TRICKS.
244  // Any additional event handlers should be popped before the window is deleted.
245  m_global_grid->PopEventHandler( true );
246  m_project_grid->PopEventHandler( true );
247  m_path_subs_grid->PopEventHandler( true );
248 }
static size_t m_pageNdx
Remember the last notebook page selected during a session.

Member Function Documentation

void PANEL_SYM_LIB_TABLE::adjustPathSubsGridColumns ( int  aWidth)
private

Definition at line 655 of file panel_sym_lib_table.cpp.

References PANEL_SYM_LIB_TABLE_BASE::m_path_subs_grid.

Referenced by onSizeGrid(), and populateEnvironReadOnlyTable().

656 {
657  // Account for scroll bars
658  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
659 
660  m_path_subs_grid->AutoSizeColumn( 0 );
661  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
662 }
void PANEL_SYM_LIB_TABLE::appendRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 422 of file panel_sym_lib_table.cpp.

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

423 {
425  return;
426 
427  if( m_cur_grid->AppendRows( 1 ) )
428  {
429  int row = m_cur_grid->GetNumberRows() - 1;
430  // Gives a default type (currently, only one type exists):
431  m_cur_grid->SetCellValue( row, COL_TYPE, SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
432 
433  // wx documentation is wrong, SetGridCursor does not make visible.
434  m_cur_grid->MakeCellVisible( row, 0 );
435  m_cur_grid->SetGridCursor( row, 1 );
436 
437  m_cur_grid->EnableCellEditControl( true );
438  m_cur_grid->ShowCellEditControl();
439  }
440 }
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:156
void PANEL_SYM_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 339 of file panel_sym_lib_table.cpp.

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_projectBasePath, NormalizePath(), Pgm(), SchematicLibraryFileWildcard(), SCH_IO_MGR::ShowType(), and YesOrCancelDialog().

340 {
341  if( m_lastBrowseDir.IsEmpty() )
343 
344  wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir,
345  wxEmptyString, SchematicLibraryFileWildcard(),
346  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
347 
348  auto result = dlg.ShowModal();
349 
350  if( result == wxID_CANCEL )
351  return;
352 
353  m_lastBrowseDir = dlg.GetDirectory();
354 
355  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
356  bool addDuplicates = false;
357  bool applyToAll = false;
358  wxString warning = _( "Warning: Duplicate Nickname" );
359  wxString msg = _( "A library nicknamed \"%s\" already exists." );
360  wxArrayString files;
361  dlg.GetFilenames( files );
362 
363  for( const auto& file : files )
364  {
365  wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
366  wxFileName fn( filePath );
367  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH );
368  bool doAdd = true;
369 
370  if( cur_model()->ContainsNickname( nickname ) )
371  {
372  if( !applyToAll )
373  {
374  int ret = YesOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
375  _( "Skip" ), _( "Add Anyway" ), &applyToAll );
376  addDuplicates = (ret == wxID_CANCEL );
377  }
378 
379  doAdd = addDuplicates;
380  }
381 
382  if( doAdd && m_cur_grid->AppendRows( 1 ) )
383  {
384  int last_row = m_cur_grid->GetNumberRows() - 1;
385 
386  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
387 
388  // TODO the following code can detect only schematic types, not libs
389  // SCH_IO_MGR needs to provide file extension information for libraries too
390 
391  // auto detect the plugin type
392  /*for( auto pluginType : SCH_IO_MGR::SCH_FILE_T_vector )
393  {
394  if( SCH_IO_MGR::GetFileExtension( pluginType ).Lower() == fn.GetExt().Lower() )
395  {
396  m_cur_grid->SetCellValue( last_row, COL_TYPE,
397  SCH_IO_MGR::ShowType( pluginType ) );
398  break;
399  }
400  }*/
401  m_cur_grid->SetCellValue( last_row, COL_TYPE,
402  SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
403 
404  // try to use path normalized to an environmental variable or project path
405  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
406 
407  if( path.IsEmpty() )
408  path = fn.GetFullPath();
409 
410  m_cur_grid->SetCellValue( last_row, COL_URI, path );
411  }
412  }
413 
414  if( !files.IsEmpty() )
415  {
416  m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 );
417  m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 );
418  }
419 }
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
SYMBOL_LIB_TABLE_GRID * cur_model() const
wxString SchematicLibraryFileWildcard()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
int YesOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Function YesOrCancelDialog displays a warning dialog with aMessage and returns the user response...
Definition: confirm.cpp:226
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:312
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:129
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 &#39;_&#39;.
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
SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::cur_model ( ) const
private

Definition at line 685 of file panel_sym_lib_table.cpp.

References m_cur_grid, and m_pageNdx.

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

686 {
687  return (SYMBOL_LIB_TABLE_GRID*) m_cur_grid->GetTable();
688 }
WX_GRID * m_cur_grid
changed based on tab choice
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
void PANEL_SYM_LIB_TABLE::deleteRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 443 of file panel_sym_lib_table.cpp.

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

444 {
446  return;
447 
448  int curRow = m_cur_grid->GetGridCursorRow();
449  int curCol = m_cur_grid->GetGridCursorCol();
450 
451  // In a wxGrid, collect rows that have a selected cell, or are selected
452  // is not so easy: it depend on the way the selection was made.
453  // Here, we collect row selected by clicking on a row label, and
454  // row that contain a cell previously selected.
455  // If no candidate, just delete the row with the grid cursor.
456  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
457  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
458  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
459  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
460 
461  // Add all row having cell selected to list:
462  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
463  selectedRows.Add( cells[ii].GetRow() );
464 
465  // Handle block selection
466  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
467  {
468  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
469  selectedRows.Add( i );
470  }
471 
472  // Use the row having the grid cursor only if we have no candidate:
473  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
474  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
475 
476  if( selectedRows.size() == 0 )
477  {
478  wxBell();
479  return;
480  }
481 
482  std::sort( selectedRows.begin(), selectedRows.end() );
483 
484  // Remove selected rows (note: a row can be stored more than once in list)
485  int last_row = -1;
486 
487  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
488  {
489  int row = selectedRows[ii];
490 
491  if( row != last_row )
492  {
493  last_row = row;
494  m_cur_grid->DeleteRows( row, 1 );
495  }
496  }
497 
498  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
499 }
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:156
size_t i
Definition: json11.cpp:597
#define min(a, b)
Definition: auxiliary.h:85
SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::global_model ( ) const
private

Definition at line 673 of file panel_sym_lib_table.cpp.

References PANEL_SYM_LIB_TABLE_BASE::m_global_grid.

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

674 {
675  return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();
676 }
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
void PANEL_SYM_LIB_TABLE::moveDownHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 532 of file panel_sym_lib_table.cpp.

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

533 {
535  return;
536 
538  int curRow = m_cur_grid->GetGridCursorRow();
539 
540  // @todo: add multiple selection moves.
541  if( unsigned( curRow + 1 ) < tbl->rows.size() )
542  {
543  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
544  tbl->rows.release( tbl->rows.begin() + curRow );
545 
546  ++curRow;
547  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
548 
549  if( tbl->GetView() )
550  {
551  // Update the wxGrid
552  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
553  tbl->GetView()->ProcessTableMessage( msg );
554  }
555 
556  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
557  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
558  }
559 }
WX_GRID * m_cur_grid
changed based on tab choice
SYMBOL_LIB_TABLE_GRID * cur_model() const
LIB_TABLE_ROWS rows
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
void PANEL_SYM_LIB_TABLE::moveUpHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 502 of file panel_sym_lib_table.cpp.

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

503 {
505  return;
506 
508  int curRow = m_cur_grid->GetGridCursorRow();
509 
510  // @todo: add multiple selection moves.
511  if( curRow >= 1 )
512  {
513  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
514  tbl->rows.release( tbl->rows.begin() + curRow );
515 
516  --curRow;
517  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
518 
519  if( tbl->GetView() )
520  {
521  // Update the wxGrid
522  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
523  tbl->GetView()->ProcessTableMessage( msg );
524  }
525 
526  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
527  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
528  }
529 }
WX_GRID * m_cur_grid
changed based on tab choice
SYMBOL_LIB_TABLE_GRID * cur_model() const
LIB_TABLE_ROWS rows
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
void PANEL_SYM_LIB_TABLE::onSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 665 of file panel_sym_lib_table.cpp.

References adjustPathSubsGridColumns().

666 {
667  adjustPathSubsGridColumns( event.GetSize().GetX() );
668 
669  event.Skip();
670 }
void adjustPathSubsGridColumns(int aWidth)
void PANEL_SYM_LIB_TABLE::pageChangedHandler ( wxAuiNotebookEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SYM_LIB_TABLE_BASE.

Definition at line 332 of file panel_sym_lib_table.cpp.

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.

333 {
334  m_pageNdx = (unsigned) std::max( 0, m_auinotebook->GetSelection() );
336 }
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
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 594 of file panel_sym_lib_table.cpp.

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

595 {
596  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
597  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
598 
599  std::set< wxString > unique;
600 
601  // clear the table
602  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
603 
604  for( SYMBOL_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
605  {
606  for( int row = 0; row < tbl->GetNumberRows(); ++row )
607  {
608  wxString uri = tbl->GetValue( row, COL_URI );
609 
610  while( re.Matches( uri ) )
611  {
612  wxString envvar = re.GetMatch( uri, 2 );
613 
614  // if not ${...} form then must be $(...)
615  if( envvar.IsEmpty() )
616  envvar = re.GetMatch( uri, 4 );
617 
618  // ignore duplicates
619  unique.insert( envvar );
620 
621  // delete the last match and search again
622  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
623  }
624  }
625  }
626 
627  // Make sure this special environment variable shows up even if it was
628  // not used yet. It is automatically set by KiCad to the directory holding
629  // the current project.
630  unique.insert( PROJECT_VAR_NAME );
632 
633  for( wxString evName : unique )
634  {
635  int row = m_path_subs_grid->GetNumberRows();
636  m_path_subs_grid->AppendRows( 1 );
637 
638  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
639  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
640 
641  wxString evValue;
642  wxGetEnv( evName, &evValue );
643  m_path_subs_grid->SetCellValue( row, 1, evValue );
644  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
645  }
646 
647  // No combobox editors here, but it looks better if its consistent with the other
648  // grids in the dialog.
649  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
650 
651  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
652 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
SYMBOL_LIB_TABLE_GRID * global_model() const
void adjustPathSubsGridColumns(int aWidth)
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
SYMBOL_LIB_TABLE_GRID * project_model() const
SYMBOL_LIB_TABLE_GRID * PANEL_SYM_LIB_TABLE::project_model ( ) const
private

Definition at line 679 of file panel_sym_lib_table.cpp.

References PANEL_SYM_LIB_TABLE_BASE::m_project_grid.

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

680 {
681  return (SYMBOL_LIB_TABLE_GRID*) m_project_grid->GetTable();
682 }
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow ( )
overrideprivate

Definition at line 562 of file panel_sym_lib_table.cpp.

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

563 {
565  return false;
566 
567  if( !verifyTables() )
568  return false;
569 
570  if( *global_model() != *m_globalTable )
571  {
573 
574  m_globalTable->Clear();
575  m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(),
576  global_model()->rows.end(), global_model()->rows );
578  }
579 
580  if( *project_model() != *m_projectTable )
581  {
583 
585  m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(),
586  project_model()->rows.end(), project_model()->rows );
588  }
589 
590  return true;
591 }
void Clear()
Delete all rows.
void reindex()
WX_GRID * m_cur_grid
changed based on tab choice
LIB_TABLE_ROWS rows
SYMBOL_LIB_TABLE_GRID * global_model() const
SYMBOL_LIB_TABLE * m_projectTable
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
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
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 251 of file panel_sym_lib_table.cpp.

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

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

Member Data Documentation

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_append_button
protectedinherited
wxAuiNotebook* PANEL_SYM_LIB_TABLE_BASE::m_auinotebook
protectedinherited
wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_browse_button
protectedinherited
wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_delete_button
protectedinherited
wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_GblTableFilename
protectedinherited
WX_GRID* PANEL_SYM_LIB_TABLE_BASE::m_global_grid
protectedinherited
wxPanel* PANEL_SYM_LIB_TABLE_BASE::m_global_panel
protectedinherited
SYMBOL_LIB_TABLE* PANEL_SYM_LIB_TABLE::m_globalTable
private

Definition at line 68 of file panel_sym_lib_table.h.

Referenced by TransferDataFromWindow().

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

wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_move_down_button
protectedinherited
wxBitmapButton* PANEL_SYM_LIB_TABLE_BASE::m_move_up_button
protectedinherited
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 cur_model(), pageChangedHandler(), PANEL_SYM_LIB_TABLE(), and ~PANEL_SYM_LIB_TABLE().

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

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_PrjTableFilename
protectedinherited
WX_GRID* PANEL_SYM_LIB_TABLE_BASE::m_project_grid
protectedinherited
wxPanel* PANEL_SYM_LIB_TABLE_BASE::m_project_panel
protectedinherited
wxString PANEL_SYM_LIB_TABLE::m_projectBasePath
private

Definition at line 70 of file panel_sym_lib_table.h.

Referenced by browseLibrariesHandler().

SYMBOL_LIB_TABLE* PANEL_SYM_LIB_TABLE::m_projectTable
private

Definition at line 69 of file panel_sym_lib_table.h.

Referenced by TransferDataFromWindow().

wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_staticText3
protectedinherited
wxStaticText* PANEL_SYM_LIB_TABLE_BASE::m_staticText4
protectedinherited

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