KiCad PCB EDA Suite
dialog_fp_lib_table.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2013 CERN
6  * Copyright (C) 2012-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 /* TODO:
28 
29 *) After any change to uri, reparse the environment variables.
30 
31 */
32 
33 
34 #include <set>
35 #include <wx/regex.h>
36 
37 #include <fctsys.h>
38 #include <project.h>
39 #include <3d_viewer.h> // for KISYS3DMOD
41 #include <fp_lib_table.h>
42 #include <lib_table_lexer.h>
43 #include <invoke_pcb_dialog.h>
44 #include <grid_tricks.h>
45 #include <confirm.h>
46 #include <wizard_add_fplib.h>
47 #include <lib_table_grid.h>
48 
49 
54 {
55  friend class FP_GRID_TRICKS;
56 
57 protected:
58  LIB_TABLE_ROW* at( size_t aIndex ) override { return &rows.at( aIndex ); }
59 
60  size_t size() const override { return rows.size(); }
61 
63  {
64  return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
65  }
66 
67  LIB_TABLE_ROWS_ITER begin() override { return rows.begin(); }
68 
70  {
71  return rows.insert( aIterator, aRow );
72  }
73 
74  void push_back( LIB_TABLE_ROW* aRow ) override { rows.push_back( aRow ); }
75 
77  {
78  return rows.erase( aFirst, aLast );
79  }
80 
81 public:
82 
83  FP_LIB_TABLE_GRID( const FP_LIB_TABLE& aTableToEdit )
84  {
85  rows = aTableToEdit.rows;
86  }
87 };
88 
89 
91 {
92 public:
93  FP_GRID_TRICKS( wxGrid* aGrid ) :
94  GRID_TRICKS( aGrid )
95  {
96  }
97 
98 protected:
99 
102  virtual void paste_text( const wxString& cb_text ) override
103  {
104  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
105 
106  size_t ndx = cb_text.find( "(fp_lib_table" );
107 
108  if( ndx != std::string::npos )
109  {
110  // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
111  // at column 0 regardless of current cursor column.
112 
113  STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
114  LIB_TABLE_LEXER lexer( &slr );
115  FP_LIB_TABLE tmp_tbl;
116  bool parsed = true;
117 
118  try
119  {
120  tmp_tbl.Parse( &lexer );
121  }
122  catch( PARSE_ERROR& pe )
123  {
124  DisplayError( NULL, pe.What() );
125  parsed = false;
126  }
127 
128  if( parsed )
129  {
130  const int cur_row = std::max( getCursorRow(), 0 );
131 
132  // if clipboard rows would extend past end of current table size...
133  if( tmp_tbl.GetCount() > tbl->GetNumberRows() - cur_row )
134  {
135  int newRowsNeeded = tmp_tbl.GetCount() - ( tbl->GetNumberRows() - cur_row );
136  tbl->AppendRows( newRowsNeeded );
137  }
138 
139  for( int i = 0; i < tmp_tbl.GetCount(); ++i )
140  {
141  tbl->rows.replace( cur_row+i, tmp_tbl.At( i ) );
142  }
143  }
144 
145  m_grid->AutoSizeColumns( false );
146  }
147  else
148  {
149  // paste spreadsheet formatted text.
150  GRID_TRICKS::paste_text( cb_text );
151  }
152  }
153 };
154 
155 
162 {
163 
164 public:
165  DIALOG_FP_LIB_TABLE( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ) :
166  DIALOG_FP_LIB_TABLE_BASE( aParent ),
167  m_global( aGlobal ),
168  m_project( aProject )
169  {
170  // For user info, shows the table filenames:
171  m_PrjTableFilename->SetLabel( Prj().FootprintLibTblName() );
172  m_GblTableFilename->SetLabel( FP_LIB_TABLE::GetGlobalTableFileName() );
173 
174  // wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
175  // so make it a grid owned table.
176  m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true );
177  m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true );
178 
179  // add Cut, Copy, and Paste to wxGrids
180  m_global_grid->PushEventHandler( new FP_GRID_TRICKS( m_global_grid ) );
181  m_project_grid->PushEventHandler( new FP_GRID_TRICKS( m_project_grid ) );
182 
183  m_global_grid->AutoSizeColumns( false );
184  m_project_grid->AutoSizeColumns( false );
185 
186  wxArrayString choices;
187 
188  choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) );
189  choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
190  choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
191  choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
192  choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
193 
194  /* PCAD_PLUGIN does not support Footprint*() functions
195  choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
196  */
197 
198  populateEnvironReadOnlyTable();
199 
200  for( int i=0; i<2; ++i )
201  {
202  wxGrid* g = i==0 ? m_global_grid : m_project_grid;
203 
204  wxGridCellAttr* attr;
205 
206  attr = new wxGridCellAttr;
207  attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
208  g->SetColAttr( COL_TYPE, attr );
209 
210  attr = new wxGridCellAttr;
211  attr->SetEditor( new wxGridCellBoolEditor() );
212  attr->SetRenderer( new wxGridCellBoolRenderer() );
213  g->SetColAttr( COL_ENABLED, attr );
214 
215  // all but COL_OPTIONS, which is edited with Option Editor anyways.
216  g->AutoSizeColumn( COL_NICKNAME, false );
217  g->AutoSizeColumn( COL_TYPE, false );
218  g->AutoSizeColumn( COL_URI, false );
219  g->AutoSizeColumn( COL_DESCR, false );
220 
221  // would set this to width of title, if it was easily known.
222  g->SetColSize( COL_OPTIONS, 80 );
223  }
224 
225  // This scrunches the dialog hideously, probably due to wxAUI container.
226  // Fit();
227  // We derive from DIALOG_SHIM so prior size will be used anyways.
228 
229  // select the last selected page
230  m_auinotebook->SetSelection( m_pageNdx );
231 
232  // fire pageChangedHandler() so m_cur_grid gets set
233  // m_auinotebook->SetSelection will generate a pageChangedHandler()
234  // event call later, but too late.
235  wxAuiNotebookEvent uneventful;
236  pageChangedHandler( uneventful );
237 
238  // Gives a selection for each grid, mainly for delete lib button.
239  // Without that, we do not see what lib will be deleted
240  m_global_grid->SelectRow( 0 );
241  m_project_grid->SelectRow( 0 );
242 
243  // for ALT+A handling, we want the initial focus to be on the first selected grid.
244  m_cur_grid->SetFocus();
245 
246  SetSizeInDU( 450, 380 );
247 
248  // On some windows manager (Unity, XFCE), this dialog is
249  // not always raised, depending on this dialog is run.
250  // Force it to be raised
251  Raise();
252  }
253 
255  {
256  // Delete the GRID_TRICKS.
257  // Any additional event handlers should be popped before the window is deleted.
258  m_global_grid->PopEventHandler( true );
259  m_project_grid->PopEventHandler( true );
260  }
261 
262 
263 private:
266  int getCursorCol() const
267  {
268  return m_cur_grid->GetGridCursorCol();
269  }
270 
273  int getCursorRow() const
274  {
275  return m_cur_grid->GetGridCursorRow();
276  }
277 
284  {
285  for( int t=0; t<2; ++t )
286  {
287  FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model();
288 
289  for( int r = 0; r < model.GetNumberRows(); )
290  {
291  wxString nick = model.GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
292  wxString uri = model.GetValue( r, COL_URI ).Trim( false ).Trim();
293 
294  if( !nick || !uri )
295  {
296  // Delete the "empty" row, where empty means missing nick or uri.
297  // This also updates the UI which could be slow, but there should only be a few
298  // rows to delete, unless the user fell asleep on the Add Row
299  // button.
300  model.DeleteRows( r, 1 );
301  }
302  else if( nick.find( ':' ) != size_t( -1 ) )
303  {
304  wxString msg = wxString::Format(
305  _( "Illegal character \"%s\" found in Nickname: \"%s\" in row %d" ),
306  ":", GetChars( nick ), r );
307 
308  // show the tabbed panel holding the grid we have flunked:
309  if( &model != cur_model() )
310  {
311  m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
312  }
313 
314  // go to the problematic row
315  m_cur_grid->SetGridCursor( r, 0 );
316  m_cur_grid->SelectBlock( r, 0, r, 0 );
317  m_cur_grid->MakeCellVisible( r, 0 );
318 
319  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
320  errdlg.ShowModal();
321  return false;
322  }
323  else
324  {
325  // set the trimmed values back into the table so they get saved to disk.
326  model.SetValue( r, COL_NICKNAME, nick );
327  model.SetValue( r, COL_URI, uri );
328  ++r; // this row was OK.
329  }
330  }
331  }
332 
333  // check for duplicate nickNames, separately in each table.
334  for( int t=0; t<2; ++t )
335  {
336  FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model();
337 
338  for( int r1 = 0; r1 < model.GetNumberRows() - 1; ++r1 )
339  {
340  wxString nick1 = model.GetValue( r1, COL_NICKNAME );
341 
342  for( int r2=r1+1; r2 < model.GetNumberRows(); ++r2 )
343  {
344  wxString nick2 = model.GetValue( r2, COL_NICKNAME );
345 
346  if( nick1 == nick2 )
347  {
348  wxString msg = wxString::Format(
349  _( "Duplicate Nickname: \"%s\" in rows %d and %d" ),
350  GetChars( nick1 ), r1+1, r2+1
351  );
352 
353  // show the tabbed panel holding the grid we have flunked:
354  if( &model != cur_model() )
355  {
356  m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
357  }
358 
359  // go to the lower of the two rows, it is technically the duplicate:
360  m_cur_grid->SetGridCursor( r2, 0 );
361  m_cur_grid->SelectBlock( r2, 0, r2, 0 );
362  m_cur_grid->MakeCellVisible( r2, 0 );
363 
364  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
365  errdlg.ShowModal();
366  return false;
367  }
368  }
369  }
370  }
371 
372  return true;
373  }
374 
375  //-----<event handlers>----------------------------------
376 
377  void onKeyDown( wxKeyEvent& ev ) override
378  {
379 #if 0
380  // send the key to the current grid
381  ((wxEvtHandler*)m_cur_grid)->ProcessEvent( ev );
382 #else
383  // or no:
384  // m_cur_grid has the focus most of the time anyways, so above not needed.
385  ev.Skip();
386 #endif
387  }
388 
389  void pageChangedHandler( wxAuiNotebookEvent& event ) override
390  {
391  m_pageNdx = m_auinotebook->GetSelection();
392  m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid;
393  }
394 
395  void appendRowHandler( wxCommandEvent& event ) override
396  {
397  if( m_cur_grid->AppendRows( 1 ) )
398  {
399  int last_row = m_cur_grid->GetNumberRows() - 1;
400 
401  // wx documentation is wrong, SetGridCursor does not make visible.
402  m_cur_grid->MakeCellVisible( last_row, 0 );
403  m_cur_grid->SetGridCursor( last_row, 0 );
404  m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
405  }
406  }
407 
408  void deleteRowHandler( wxCommandEvent& event ) override
409  {
410  int currRow = getCursorRow();
411 
412  // In a wxGrid, collect rows that have a selected cell, or are selected
413  // is not so easy: it depend on the way the selection was made.
414  // Here, we collect row selected by clicking on a row label, and
415  // row that contain a cell previously selected.
416  // If no candidate, just delete the row with the grid cursor.
417  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
418  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
419  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
420  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
421 
422  // Add all row having cell selected to list:
423  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
424  selectedRows.Add( cells[ii].GetRow() );
425 
426  // Handle block selection
427  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
428  {
429  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
430  selectedRows.Add( i );
431  }
432 
433  // Use the row having the grid cursor only if we have no candidate:
434  if( selectedRows.size() == 0 && getCursorRow() >= 0 )
435  selectedRows.Add( getCursorRow() );
436 
437  std::sort( selectedRows.begin(), selectedRows.end() );
438 
439  // Remove selected rows (note: a row can be stored more than once in list)
440  int last_row = -1;
441  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
442  {
443  int row = selectedRows[ii];
444 
445  if( row != last_row )
446  {
447  last_row = row;
448  m_cur_grid->DeleteRows( row, 1 );
449  }
450  }
451 
452  if( currRow >= m_cur_grid->GetNumberRows() )
453  m_cur_grid->SetGridCursor(m_cur_grid->GetNumberRows()-1, getCursorCol() );
454 
455  m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
456  }
457 
458  void moveUpHandler( wxCommandEvent& event ) override
459  {
460  wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows();
461 
462  if( rowsSelected.GetCount() == 0 )
463  return;
464 
465  // @todo: add multiple selection moves.
466  int curRow = rowsSelected[0];
467 
468  if( curRow >= 1 )
469  {
470  int curCol = getCursorCol();
471 
472  FP_LIB_TABLE_GRID* tbl = cur_model();
473 
474  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
475  tbl->rows.release( tbl->rows.begin() + curRow );
476 
477  --curRow;
478  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
479 
480  if( tbl->GetView() )
481  {
482  // fire a msg to cause redrawing
483  wxGridTableMessage msg( tbl,
484  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
485  curRow,
486  0 );
487 
488  tbl->GetView()->ProcessTableMessage( msg );
489  }
490 
491  m_cur_grid->MakeCellVisible( curRow, curCol );
492  m_cur_grid->SetGridCursor( curRow, curCol );
493  m_cur_grid->SelectRow( getCursorRow() );
494  }
495  }
496 
497  void moveDownHandler( wxCommandEvent& event ) override
498  {
499  wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows();
500 
501  if( rowsSelected.GetCount() == 0 )
502  return;
503 
504  FP_LIB_TABLE_GRID* tbl = cur_model();
505 
506  // @todo: add multiple selection moves.
507  int curRow = rowsSelected[0];
508 
509  if( unsigned( curRow + 1 ) < tbl->rows.size() )
510  {
511  int curCol = getCursorCol();
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  // fire a msg to cause redrawing
522  wxGridTableMessage msg( tbl,
523  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
524  curRow - 1,
525  0 );
526 
527  tbl->GetView()->ProcessTableMessage( msg );
528  }
529 
530  m_cur_grid->MakeCellVisible( curRow, curCol );
531  m_cur_grid->SetGridCursor( curRow, curCol );
532  m_cur_grid->SelectRow( getCursorRow() );
533  }
534  }
535 
536  void optionsEditor( wxCommandEvent& event ) override
537  {
538  FP_LIB_TABLE_GRID* tbl = cur_model();
539 
540  if( tbl->GetNumberRows() )
541  {
542  int curRow = getCursorRow();
543  LIB_TABLE_ROW* row = &tbl->rows[curRow];
544 
545  wxString result;
546  const wxString& options = row->GetOptions();
547 
548  InvokePluginOptionsEditor( this, row->GetNickName(), row->GetType(), options, &result );
549 
550  if( options != result )
551  {
552  row->SetOptions( result );
553 
554  // all but options:
555  m_cur_grid->AutoSizeColumn( COL_NICKNAME, false );
556  m_cur_grid->AutoSizeColumn( COL_URI, false );
557  m_cur_grid->AutoSizeColumn( COL_TYPE, false );
558 
559  // On Windows, the grid is not refresh,
560  // so force resfresh after a change
561 #ifdef __WINDOWS__
562  Refresh();
563 #endif
564  }
565  }
566  }
567 
568  void OnClickLibraryWizard( wxCommandEvent& event ) override;
569 
570  void onCancelButtonClick( wxCommandEvent& event ) override
571  {
572  EndModal( 0 );
573  }
574 
575  void onCancelCaptionButtonClick( wxCloseEvent& event ) override
576  {
577  EndModal( 0 );
578  }
579 
580  void onOKButtonClick( wxCommandEvent& event ) override
581  {
582  int dialogRet = 0;
583 
584  // stuff any pending cell editor text into the table.
585  m_cur_grid->SaveEditControlValue();
586 
587  if( verifyTables() )
588  {
589  if( *global_model() != *m_global )
590  {
591  dialogRet |= 1;
592 
593  m_global->Clear();
594  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
595  global_model()->rows.end(), global_model()->rows );
596  m_global->reindex();
597  }
598 
599  if( *project_model() != *m_project )
600  {
601  dialogRet |= 2;
602 
603  m_project->Clear();
604  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
605  project_model()->rows.end(), project_model()->rows );
606  m_project->reindex();
607  }
608 
609  EndModal( dialogRet );
610  }
611  }
612 
616  {
617  wxRegEx re( ".*?\\$\\{(.+?)\\}.*?", wxRE_ADVANCED );
618  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
619 
620  std::set< wxString > unique;
621  typedef std::set<wxString>::const_iterator SET_CITER;
622 
623  // clear the table
624  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
625 
626  FP_LIB_TABLE_GRID* gbl = global_model();
627  FP_LIB_TABLE_GRID* prj = project_model();
628 
629  int gblRowCount = gbl->GetNumberRows();
630  int prjRowCount = prj->GetNumberRows();
631  int row;
632 
633  for( row = 0; row < gblRowCount; ++row )
634  {
635  wxString uri = gbl->GetValue( row, COL_URI );
636 
637  while( re.Matches( uri ) )
638  {
639  wxString envvar = re.GetMatch( uri, 1 );
640 
641  // ignore duplicates
642  unique.insert( envvar );
643 
644  // delete the last match and search again
645  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
646  }
647  }
648 
649  for( row = 0; row < prjRowCount; ++row )
650  {
651  wxString uri = prj->GetValue( row, COL_URI );
652 
653  while( re.Matches( uri ) )
654  {
655  wxString envvar = re.GetMatch( uri, 1 );
656 
657  // ignore duplicates
658  unique.insert( envvar );
659 
660  // delete the last match and search again
661  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
662  }
663  }
664 
665  // Make sure this special environment variable shows up even if it was
666  // not used yet. It is automatically set by KiCad to the directory holding
667  // the current project.
668  unique.insert( PROJECT_VAR_NAME );
669  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
670  // This special environment variable is used to locate 3d shapes
671  unique.insert( KISYS3DMOD );
672 
673  m_path_subs_grid->AppendRows( unique.size() );
674 
675  row = 0;
676 
677  for( SET_CITER it = unique.begin(); it != unique.end(); ++it, ++row )
678  {
679  wxString evName = *it;
680  wxString evValue;
681 
682  m_path_subs_grid->SetCellValue( row, 0, evName );
683 
684  if( wxGetEnv( evName, &evValue ) )
685  m_path_subs_grid->SetCellValue( row, 1, evValue );
686  }
687 
688  m_path_subs_grid->AutoSizeColumns();
689  }
690 
691  //-----</event handlers>---------------------------------
692 
693  // caller's tables are modified only on OK button and successful verification.
696 
698  {
699  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
700  }
701 
703  {
704  return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable();
705  }
706 
708  {
709  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
710  }
711 
712  wxGrid* m_cur_grid;
713  static int m_pageNdx;
714 };
715 
716 
718 
719 
720 void DIALOG_FP_LIB_TABLE::OnClickLibraryWizard( wxCommandEvent& event )
721 {
722  WIZARD_FPLIB_TABLE dlg( this );
723 
724  if( !dlg.RunWizard( dlg.GetFirstPage() ) )
725  return; // Aborted by user
726 
727  const std::vector<WIZARD_FPLIB_TABLE::LIBRARY>& libs = dlg.GetLibraries();
728  bool global_scope = dlg.GetLibScope() == WIZARD_FPLIB_TABLE::GLOBAL;
729  wxGrid* libgrid = global_scope ? m_global_grid : m_project_grid;
730  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) libgrid->GetTable();
731 
732  for( std::vector<WIZARD_FPLIB_TABLE::LIBRARY>::const_iterator it = libs.begin();
733  it != libs.end(); ++it )
734  {
735  if( it->GetStatus() == WIZARD_FPLIB_TABLE::LIBRARY::INVALID )
736  continue;
737 
738  if( libgrid->AppendRows( 1 ) )
739  {
740  int last_row = libgrid->GetNumberRows() - 1;
741 
742  // Add the nickname: currently make it from filename
743  tbl->SetValue( last_row, COL_NICKNAME, it->GetDescription() );
744 
745  // Add the path:
746  tbl->SetValue( last_row, COL_URI, it->GetAutoPath( dlg.GetLibScope() ) );
747 
748  // Add the plugin name:
749  tbl->SetValue( last_row, COL_TYPE, it->GetPluginName() );
750 
751  libgrid->MakeCellVisible( last_row, 0 );
752  libgrid->SetGridCursor( last_row, 0 );
753  }
754  }
755 
756  // Switch to the current scope tab
757  if( global_scope )
758  m_auinotebook->SetSelection( 0 );
759  else
760  m_auinotebook->SetSelection( 1 );
761 
762  libgrid->SelectRow( libgrid->GetGridCursorRow() );
763 }
764 
765 
766 int InvokePcbLibTableEditor( wxTopLevelWindow* aCaller, FP_LIB_TABLE* aGlobal,
767  FP_LIB_TABLE* aProject )
768 {
769  DIALOG_FP_LIB_TABLE dlg( aCaller, aGlobal, aProject );
770 
771  int dialogRet = dlg.ShowModal(); // returns value passed to EndModal() above
772 
773  return dialogRet;
774 }
775 
776 
777 int InvokeFootprintWizard( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal,
778  FP_LIB_TABLE* aProject )
779 {
780  WIZARD_FPLIB_TABLE dlg( aParent );
781 
782  if( !dlg.RunWizard( dlg.GetFirstPage() ) )
783  return 0; // Aborted by user
784 
785  const std::vector<WIZARD_FPLIB_TABLE::LIBRARY>& libs = dlg.GetLibraries();
787  FP_LIB_TABLE* fp_tbl = ( scope == WIZARD_FPLIB_TABLE::GLOBAL ? aGlobal : aProject );
788 
789  if( fp_tbl )
790  {
791  for( std::vector<WIZARD_FPLIB_TABLE::LIBRARY>::const_iterator it = libs.begin();
792  it != libs.end(); ++it )
793  {
794  if( it->GetStatus() == WIZARD_FPLIB_TABLE::LIBRARY::INVALID )
795  continue;
796 
797  FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( it->GetDescription(),
798  it->GetAutoPath( scope ),
799  it->GetPluginName(),
800  wxEmptyString ); // options
801  fp_tbl->InsertRow( row );
802  }
803  }
804 
805  return scope;
806 }
int GetCount()
FP_LIB_TABLE_GRID * project_model() const
int getCursorCol() const
If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based column index.
void push_back(LIB_TABLE_ROW *aRow) override
int getCursorRow() const
If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based row index.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
LIB_SCOPE GetLibScope() const
Function GetLibScope Returns the scope for the added libraries (global / project specific).
void OnClickLibraryWizard(wxCommandEvent &event) override
void appendRowHandler(wxCommandEvent &event) override
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
This file is part of the common library.
PROJECT & Prj()
Definition: kicad.cpp:270
void onCancelCaptionButtonClick(wxCloseEvent &event) override
void InvokePluginOptionsEditor(wxTopLevelWindow *aCaller, const wxString &aNickname, const wxString &aPluginType, const wxString &aOptions, wxString *aResult)
Function InvokePluginOptionsEditor calls DIALOG_FP_PLUGIN_OPTIONS dialog so that plugin options set c...
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:36
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:34
void deleteRowHandler(wxCommandEvent &event) override
bool DeleteRows(size_t aPos, size_t aNumRows) override
Class DIALOG_FP_LIB_TABLE shows and edits the PCB library tables.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
LIB_TABLE_ROW * At(int aIndex)
LIB_TABLE_ROWS rows
void moveUpHandler(wxCommandEvent &event) override
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
virtual const wxString GetType() const =0
Return the type of library represented by this row.
int InvokeFootprintWizard(wxTopLevelWindow *aParent, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
Function InvokeFootprintWizard Runs the footprint library wizard for easy library addition...
int GetNumberRows() override
void moveDownHandler(wxCommandEvent &event) override
Geda PCB file formats.
Definition: io_mgr.h:58
size_t size() const override
FP_LIB_TABLE_GRID * global_model() const
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
LIB_TABLE_ROWS_ITER insert(LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
virtual void paste_text(const wxString &cb_text)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
virtual void paste_text(const wxString &cb_text) override
handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text...
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
LIB_SCOPE
Scope (global/project)
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: 3d_viewer.h:38
int InvokePcbLibTableEditor(wxTopLevelWindow *aCaller, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing two lib ...
void pageChangedHandler(wxAuiNotebookEvent &event) override
const std::vector< LIBRARY > & GetLibraries() const
Function GetLibraries Returns libraries selected by the user.
bool AppendRows(size_t aNumRows=1) override
FP_LIB_TABLE_GRID * cur_model() const
DIALOG_FP_LIB_TABLE(wxTopLevelWindow *aParent, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
void onKeyDown(wxKeyEvent &ev) override
LIB_TABLE_ROWS_ITER begin() override
Class DIALOG_FP_LIB_TABLE_BASE.
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxString GetValue(int aRow, int aCol) override
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
const wxString & GetNickName() const
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
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
LIB_TABLE_ROW * makeNewRow() override
#define max(a, b)
Definition: auxiliary.h:86
FP_LIB_TABLE_GRID(const FP_LIB_TABLE &aTableToEdit)
wxWizardPage * GetFirstPage() const
Function GetFirstPage Returns the welcoming page for the wizard.
static int m_pageNdx
Remember the last notebook page selected during a session.
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
LIB_TABLE_ROWS_ITER erase(LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
FP_GRID_TRICKS(wxGrid *aGrid)
wxGrid * m_cur_grid
changed based on tab choice
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void SetOptions(const wxString &aOptions)
Change the library options strings.
void onOKButtonClick(wxCommandEvent &event) override
void onCancelButtonClick(wxCommandEvent &event) override
bool verifyTables()
Function verifyTables trims important fields, removes blank row entries, and checks for duplicates...
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:59
LIB_TABLE_ROW * at(size_t aIndex) override
Declaration of the eda_3d_viewer class.
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
void optionsEditor(wxCommandEvent &event) override
S-expression Pcbnew file format.
Definition: io_mgr.h:55