KiCad PCB EDA Suite
PANEL_FP_LIB_TABLE Class Reference

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

#include <panel_fp_lib_table.h>

Inheritance diagram for PANEL_FP_LIB_TABLE:
PANEL_FP_LIB_TABLE_BASE

Public Member Functions

 PANEL_FP_LIB_TABLE (DIALOG_EDIT_LIBRARY_TABLES *aParent, FP_LIB_TABLE *aGlobal, const wxString &aGlobalTblPath, FP_LIB_TABLE *aProject, const wxString &aProjectTblPath, const wxString &aProjectBasePath)
 
 ~PANEL_FP_LIB_TABLE () override
 

Protected Attributes

wxAuiNotebook * m_auinotebook
 
wxPanel * m_global_panel
 
wxStaticText * m_staticText3
 
wxStaticText * m_GblTableFilename
 
WX_GRIDm_global_grid
 
wxPanel * m_project_panel
 
wxStaticText * m_staticText4
 
wxStaticText * m_PrjTableFilename
 
WX_GRIDm_project_grid
 
wxBitmapButton * m_append_button
 
wxBitmapButton * m_browse_button
 
wxBitmapButton * m_move_up_button
 
wxBitmapButton * m_move_down_button
 
wxBitmapButton * m_delete_button
 
WX_GRIDm_path_subs_grid
 

Private Member Functions

bool TransferDataFromWindow () override
 
bool verifyTables ()
 Trim important fields, removes blank row entries, and checks for duplicates. More...
 
void pageChangedHandler (wxAuiNotebookEvent &event) override
 
void appendRowHandler (wxCommandEvent &event) override
 
void browseLibrariesHandler (wxCommandEvent &event) override
 
void deleteRowHandler (wxCommandEvent &event) override
 
void moveUpHandler (wxCommandEvent &event) override
 
void moveDownHandler (wxCommandEvent &event) override
 
void onSizeGrid (wxSizeEvent &event) override
 
void adjustPathSubsGridColumns (int aWidth)
 
void populateEnvironReadOnlyTable ()
 Populate the readonly environment variable table with names and values by examining all the full_uri columns. More...
 
FP_LIB_TABLE_GRIDglobal_model () const
 
FP_LIB_TABLE_GRIDproject_model () const
 
FP_LIB_TABLE_GRIDcur_model () const
 

Private Attributes

FP_LIB_TABLEm_global
 
FP_LIB_TABLEm_project
 
wxString m_projectBasePath
 
DIALOG_EDIT_LIBRARY_TABLESm_parent
 
WX_GRIDm_cur_grid
 

Static Private Attributes

static size_t m_pageNdx = 0
 
static wxString m_lastBrowseDir
 

Detailed Description

Dialog to show and edit symbol library tables.

Definition at line 34 of file panel_fp_lib_table.h.

Constructor & Destructor Documentation

PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE ( DIALOG_EDIT_LIBRARY_TABLES aParent,
FP_LIB_TABLE aGlobal,
const wxString &  aGlobalTblPath,
FP_LIB_TABLE aProject,
const wxString &  aProjectTblPath,
const wxString &  aProjectBasePath 
)

Definition at line 267 of file panel_fp_lib_table.cpp.

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

Referenced by InvokePcbLibTableEditor().

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

Definition at line 360 of file panel_fp_lib_table.cpp.

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

361 {
362  // When the dialog is closed it will hide the current notebook page first, which will
363  // in turn select the other one. We then end up saving its index as the "current page".
364  // So flip them back again:
365  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
366 
367  // Delete the GRID_TRICKS.
368  // Any additional event handlers should be popped before the window is deleted.
369  m_global_grid->PopEventHandler( true );
370  m_project_grid->PopEventHandler( true );
371  m_path_subs_grid->PopEventHandler( true );
372 }
static size_t m_pageNdx

Member Function Documentation

void PANEL_FP_LIB_TABLE::adjustPathSubsGridColumns ( int  aWidth)
private

Definition at line 675 of file panel_fp_lib_table.cpp.

References PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid.

Referenced by onSizeGrid(), and populateEnvironReadOnlyTable().

676 {
677  // Account for scroll bars
678  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
679 
680  m_path_subs_grid->AutoSizeColumn( 0 );
681  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
682 }
void PANEL_FP_LIB_TABLE::appendRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 464 of file panel_fp_lib_table.cpp.

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

465 {
467  return;
468 
469  if( m_cur_grid->AppendRows( 1 ) )
470  {
471  int last_row = m_cur_grid->GetNumberRows() - 1;
472 
473  // wx documentation is wrong, SetGridCursor does not make visible.
474  m_cur_grid->MakeCellVisible( last_row, 0 );
475  m_cur_grid->SetGridCursor( last_row, 1 );
476  m_cur_grid->EnableCellEditControl( true );
477  m_cur_grid->ShowCellEditControl();
478  }
479 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
void PANEL_FP_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 600 of file panel_fp_lib_table.cpp.

References COL_NICKNAME, COL_TYPE, COL_URI, WX_GRID::CommitPendingChanges(), LIB_TABLE_GRID::ContainsNickname(), cur_model(), FD_MULTIPLE, LIB_ID::FixIllegalChars(), Format(), DIALOG_FILE_DIR_PICKER::GetDirectory(), DIALOG_FILE_DIR_PICKER::GetFilenames(), getFilterString(), PGM_BASE::GetLocalEnvVariables(), IO_MGR::GuessPluginTypeFromLibPath(), LIB_ID::ID_PCB, KiCadFootprintLibPathExtension, m_cur_grid, m_lastBrowseDir, m_projectBasePath, NormalizePath(), Pgm(), IO_MGR::ShowType(), and YesOrCancelDialog().

601 {
603  return;
604 
605  if( m_lastBrowseDir.IsEmpty() )
607 
608  DIALOG_FILE_DIR_PICKER dlg( this, _( "Select Library" ), m_lastBrowseDir,
610 
611  auto result = dlg.ShowModal();
612 
613  if( result == wxID_CANCEL )
614  return;
615 
616  m_lastBrowseDir = dlg.GetDirectory();
617 
618  // Drop the last directory if the path is a .pretty folder
620  m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() );
621 
622  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
623  bool addDuplicates = false;
624  bool applyToAll = false;
625  wxString warning = _( "Warning: Duplicate Nickname" );
626  wxString msg = _( "A library nicknamed \"%s\" already exists." );
627  wxArrayString files;
628  dlg.GetFilenames( files );
629 
630  for( const auto& filePath : files )
631  {
632  wxFileName fn( filePath );
633  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB );
634  bool doAdd = true;
635 
636  if( cur_model()->ContainsNickname( nickname ) )
637  {
638  if( !applyToAll )
639  {
640  int ret = YesOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
641  _( "Skip" ), _( "Add Anyway" ), &applyToAll );
642  addDuplicates = (ret == wxID_CANCEL );
643  }
644 
645  doAdd = addDuplicates;
646  }
647 
648  if( doAdd && m_cur_grid->AppendRows( 1 ) )
649  {
650  int last_row = m_cur_grid->GetNumberRows() - 1;
651 
652  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
653 
654  auto type = IO_MGR::GuessPluginTypeFromLibPath( filePath );
655  m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( type ) );
656 
657  // try to use path normalized to an environmental variable or project path
658  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
659 
660  if( path.IsEmpty() )
661  path = fn.GetFullPath();
662 
663  m_cur_grid->SetCellValue( last_row, COL_URI, path );
664  }
665  }
666 
667  if( !files.IsEmpty() )
668  {
669  int new_row = m_cur_grid->GetNumberRows() - 1;
670  m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
671  m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
672  }
673 }
FP_LIB_TABLE_GRID * cur_model() const
bool ContainsNickname(const wxString &aNickname)
static wxString m_lastBrowseDir
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
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library&#39;s libPath...
Definition: io_mgr.cpp:124
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
static wxString getFilterString()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
Dialog that can select both files and directories.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
const std::string KiCadFootprintLibPathExtension
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes a file path to an environmental variable, if possible.
Definition: env_paths.cpp:67
FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::cur_model ( ) const
inlineprivate

Definition at line 83 of file panel_fp_lib_table.h.

References m_cur_grid.

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

84  {
85  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
86  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void PANEL_FP_LIB_TABLE::deleteRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 482 of file panel_fp_lib_table.cpp.

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

483 {
485  return;
486 
487  int curRow = m_cur_grid->GetGridCursorRow();
488  int curCol = m_cur_grid->GetGridCursorCol();
489 
490  // In a wxGrid, collect rows that have a selected cell, or are selected
491  // is not so easy: it depend on the way the selection was made.
492  // Here, we collect row selected by clicking on a row label, and
493  // row that contain a cell previously selected.
494  // If no candidate, just delete the row with the grid cursor.
495  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
496  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
497  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
498  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
499 
500  // Add all row having cell selected to list:
501  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
502  selectedRows.Add( cells[ii].GetRow() );
503 
504  // Handle block selection
505  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
506  {
507  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
508  selectedRows.Add( i );
509  }
510 
511  // Use the row having the grid cursor only if we have no candidate:
512  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
513  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
514 
515  if( selectedRows.size() == 0 )
516  {
517  wxBell();
518  return;
519  }
520 
521  std::sort( selectedRows.begin(), selectedRows.end() );
522 
523  // Remove selected rows (note: a row can be stored more than once in list)
524  int last_row = -1;
525  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
526  {
527  int row = selectedRows[ii];
528 
529  if( row != last_row )
530  {
531  last_row = row;
532  m_cur_grid->DeleteRows( row, 1 );
533  }
534  }
535 
536  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
537 }
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
FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::global_model ( ) const
inlineprivate

Definition at line 73 of file panel_fp_lib_table.h.

References PANEL_FP_LIB_TABLE_BASE::m_global_grid.

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

74  {
75  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
76  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void PANEL_FP_LIB_TABLE::moveDownHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 570 of file panel_fp_lib_table.cpp.

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

571 {
573  return;
574 
575  FP_LIB_TABLE_GRID* tbl = cur_model();
576  int curRow = m_cur_grid->GetGridCursorRow();
577 
578  // @todo: add multiple selection moves.
579  if( unsigned( curRow + 1 ) < tbl->rows.size() )
580  {
581  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
582  tbl->rows.release( tbl->rows.begin() + curRow );
583 
584  ++curRow;
585  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
586 
587  if( tbl->GetView() )
588  {
589  // Update the wxGrid
590  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
591  tbl->GetView()->ProcessTableMessage( msg );
592  }
593 
594  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
595  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
596  }
597 }
FP_LIB_TABLE_GRID * cur_model() const
LIB_TABLE_ROWS rows
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void PANEL_FP_LIB_TABLE::moveUpHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 540 of file panel_fp_lib_table.cpp.

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

541 {
543  return;
544 
545  FP_LIB_TABLE_GRID* tbl = cur_model();
546  int curRow = m_cur_grid->GetGridCursorRow();
547 
548  // @todo: add multiple selection moves.
549  if( curRow >= 1 )
550  {
551  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
552  tbl->rows.release( tbl->rows.begin() + curRow );
553 
554  --curRow;
555  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
556 
557  if( tbl->GetView() )
558  {
559  // Update the wxGrid
560  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
561  tbl->GetView()->ProcessTableMessage( msg );
562  }
563 
564  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
565  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
566  }
567 }
FP_LIB_TABLE_GRID * cur_model() const
LIB_TABLE_ROWS rows
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void PANEL_FP_LIB_TABLE::onSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 685 of file panel_fp_lib_table.cpp.

References adjustPathSubsGridColumns().

686 {
687  adjustPathSubsGridColumns( event.GetSize().GetX() );
688 
689  event.Skip();
690 }
void adjustPathSubsGridColumns(int aWidth)
void PANEL_FP_LIB_TABLE::pageChangedHandler ( wxAuiNotebookEvent &  event)
overrideprivatevirtual
void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable ( )
private

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

Definition at line 729 of file panel_fp_lib_table.cpp.

References adjustPathSubsGridColumns(), COL_URI, global_model(), FP_LIB_TABLE::GlobalPathEnvVariableName(), KISYS3DMOD, m_lastBrowseDir, m_pageNdx, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, project_model(), and PROJECT_VAR_NAME.

Referenced by PANEL_FP_LIB_TABLE().

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

Definition at line 78 of file panel_fp_lib_table.h.

References PANEL_FP_LIB_TABLE_BASE::m_project_grid.

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

79  {
80  return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable();
81  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
bool PANEL_FP_LIB_TABLE::TransferDataFromWindow ( )
overrideprivate

Definition at line 693 of file panel_fp_lib_table.cpp.

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

694 {
696  return false;
697 
698  if( verifyTables() )
699  {
700  if( *global_model() != *m_global )
701  {
703 
704  m_global->Clear();
705  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
706  global_model()->rows.end(), global_model()->rows );
707  m_global->reindex();
708  }
709 
710  if( *project_model() != *m_project )
711  {
713 
714  m_project->Clear();
715  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
716  project_model()->rows.end(), project_model()->rows );
717  m_project->reindex();
718  }
719 
720  return true;
721  }
722 
723  return false;
724 }
FP_LIB_TABLE_GRID * global_model() const
void Clear()
Delete all rows.
void reindex()
FP_LIB_TABLE * m_project
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * project_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global
bool PANEL_FP_LIB_TABLE::verifyTables ( )
private

Trim important fields, removes blank row entries, and checks for duplicates.

Returns
bool - true if tables are OK, else false.

Definition at line 375 of file panel_fp_lib_table.cpp.

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

Referenced by TransferDataFromWindow().

376 {
377  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
378  {
379  for( int r = 0; r < model->GetNumberRows(); )
380  {
381  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
382  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
383  unsigned illegalCh = 0;
384 
385  if( !nick || !uri )
386  {
387  // Delete the "empty" row, where empty means missing nick or uri.
388  // This also updates the UI which could be slow, but there should only be a few
389  // rows to delete, unless the user fell asleep on the Add Row
390  // button.
391  model->DeleteRows( r, 1 );
392  }
393  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) )
394  {
395  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
396  illegalCh,
397  nick );
398 
399  // show the tabbed panel holding the grid we have flunked:
400  if( model != cur_model() )
401  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
402 
403  m_cur_grid->MakeCellVisible( r, 0 );
404  m_cur_grid->SetGridCursor( r, 1 );
405 
406  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
407  errdlg.ShowModal();
408  return false;
409  }
410  else
411  {
412  // set the trimmed values back into the table so they get saved to disk.
413  model->SetValue( r, COL_NICKNAME, nick );
414  model->SetValue( r, COL_URI, uri );
415  ++r; // this row was OK.
416  }
417  }
418  }
419 
420  // check for duplicate nickNames, separately in each table.
421  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
422  {
423  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
424  {
425  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
426 
427  for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
428  {
429  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
430 
431  if( nick1 == nick2 )
432  {
433  wxString msg = wxString::Format( _( "Duplicate Nicknames \"%s\"." ), nick1 );
434 
435  // show the tabbed panel holding the grid we have flunked:
436  if( model != cur_model() )
437  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
438 
439  // go to the lower of the two rows, it is technically the duplicate:
440  m_cur_grid->MakeCellVisible( r2, 0 );
441  m_cur_grid->SetGridCursor( r2, 1 );
442 
443  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
444  errdlg.ShowModal();
445  return false;
446  }
447  }
448  }
449  }
450 
451  return true;
452 }
FP_LIB_TABLE_GRID * global_model() const
FP_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
FP_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
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

Member Data Documentation

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_append_button
protectedinherited
wxAuiNotebook* PANEL_FP_LIB_TABLE_BASE::m_auinotebook
protectedinherited
wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_browse_button
protectedinherited
wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_delete_button
protectedinherited
wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_GblTableFilename
protectedinherited
FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_global
private

Definition at line 69 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_global_grid
protectedinherited
wxPanel* PANEL_FP_LIB_TABLE_BASE::m_global_panel
protectedinherited
wxString PANEL_FP_LIB_TABLE::m_lastBrowseDir
staticprivate

Definition at line 92 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler(), and populateEnvironReadOnlyTable().

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_down_button
protectedinherited
wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_up_button
protectedinherited
size_t PANEL_FP_LIB_TABLE::m_pageNdx = 0
staticprivate
DIALOG_EDIT_LIBRARY_TABLES* PANEL_FP_LIB_TABLE::m_parent
private

Definition at line 88 of file panel_fp_lib_table.h.

Referenced by PANEL_FP_LIB_TABLE(), and TransferDataFromWindow().

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_PrjTableFilename
protectedinherited
FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_project
private

Definition at line 70 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_project_grid
protectedinherited
wxPanel* PANEL_FP_LIB_TABLE_BASE::m_project_panel
protectedinherited
wxString PANEL_FP_LIB_TABLE::m_projectBasePath
private

Definition at line 71 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler().

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText3
protectedinherited
wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText4
protectedinherited

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