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-2017 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() );
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 
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  // On some windows manager (Unity, XFCE), this dialog is
247  // not always raised, depending on this dialog is run.
248  // Force it to be raised
249  Raise();
250  }
251 
253  {
254  // Delete the GRID_TRICKS.
255  // Any additional event handlers should be popped before the window is deleted.
256  m_global_grid->PopEventHandler( true );
257  m_project_grid->PopEventHandler( true );
258  }
259 
260 
261 private:
264  int getCursorCol() const
265  {
266  return m_cur_grid->GetGridCursorCol();
267  }
268 
271  int getCursorRow() const
272  {
273  return m_cur_grid->GetGridCursorRow();
274  }
275 
282  {
283  for( int t=0; t<2; ++t )
284  {
285  FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model();
286 
287  for( int r = 0; r < model.GetNumberRows(); )
288  {
289  wxString nick = model.GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
290  wxString uri = model.GetValue( r, COL_URI ).Trim( false ).Trim();
291 
292  if( !nick || !uri )
293  {
294  // Delete the "empty" row, where empty means missing nick or uri.
295  // This also updates the UI which could be slow, but there should only be a few
296  // rows to delete, unless the user fell asleep on the Add Row
297  // button.
298  model.DeleteRows( r, 1 );
299  }
300  else if( nick.find( ':' ) != size_t( -1 ) )
301  {
302  wxString msg = wxString::Format(
303  _( "Illegal character '%s' found in Nickname: '%s' in row %d" ),
304  ":", GetChars( nick ), r );
305 
306  // show the tabbed panel holding the grid we have flunked:
307  if( &model != cur_model() )
308  {
309  m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
310  }
311 
312  // go to the problematic row
313  m_cur_grid->SetGridCursor( r, 0 );
314  m_cur_grid->SelectBlock( r, 0, r, 0 );
315  m_cur_grid->MakeCellVisible( r, 0 );
316 
317  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
318  errdlg.ShowModal();
319  return false;
320  }
321  else
322  {
323  // set the trimmed values back into the table so they get saved to disk.
324  model.SetValue( r, COL_NICKNAME, nick );
325  model.SetValue( r, COL_URI, uri );
326  ++r; // this row was OK.
327  }
328  }
329  }
330 
331  // check for duplicate nickNames, separately in each table.
332  for( int t=0; t<2; ++t )
333  {
334  FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model();
335 
336  for( int r1 = 0; r1 < model.GetNumberRows() - 1; ++r1 )
337  {
338  wxString nick1 = model.GetValue( r1, COL_NICKNAME );
339 
340  for( int r2=r1+1; r2 < model.GetNumberRows(); ++r2 )
341  {
342  wxString nick2 = model.GetValue( r2, COL_NICKNAME );
343 
344  if( nick1 == nick2 )
345  {
346  wxString msg = wxString::Format(
347  _( "Duplicate Nickname: '%s' in rows %d and %d" ),
348  GetChars( nick1 ), r1+1, r2+1
349  );
350 
351  // show the tabbed panel holding the grid we have flunked:
352  if( &model != cur_model() )
353  {
354  m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
355  }
356 
357  // go to the lower of the two rows, it is technically the duplicate:
358  m_cur_grid->SetGridCursor( r2, 0 );
359  m_cur_grid->SelectBlock( r2, 0, r2, 0 );
360  m_cur_grid->MakeCellVisible( r2, 0 );
361 
362  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
363  errdlg.ShowModal();
364  return false;
365  }
366  }
367  }
368  }
369 
370  return true;
371  }
372 
373  //-----<event handlers>----------------------------------
374 
375  void onKeyDown( wxKeyEvent& ev ) override
376  {
377 #if 0
378  // send the key to the current grid
379  ((wxEvtHandler*)m_cur_grid)->ProcessEvent( ev );
380 #else
381  // or no:
382  // m_cur_grid has the focus most of the time anyways, so above not needed.
383  ev.Skip();
384 #endif
385  }
386 
387  void pageChangedHandler( wxAuiNotebookEvent& event ) override
388  {
389  m_pageNdx = m_auinotebook->GetSelection();
391  }
392 
393  void appendRowHandler( wxCommandEvent& event ) override
394  {
395  if( m_cur_grid->AppendRows( 1 ) )
396  {
397  int last_row = m_cur_grid->GetNumberRows() - 1;
398 
399  // wx documentation is wrong, SetGridCursor does not make visible.
400  m_cur_grid->MakeCellVisible( last_row, 0 );
401  m_cur_grid->SetGridCursor( last_row, 0 );
402  m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
403  }
404  }
405 
406  void deleteRowHandler( wxCommandEvent& event ) override
407  {
408  int currRow = getCursorRow();
409 
410  // In a wxGrid, collect rows that have a selected cell, or are selected
411  // is not so easy: it depend on the way the selection was made.
412  // Here, we collect row selected by clicking on a row label, and
413  // row that contain a cell previously selected.
414  // If no candidate, just delete the row with the grid cursor.
415  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
416  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
417  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
418  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
419 
420  // Add all row having cell selected to list:
421  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
422  selectedRows.Add( cells[ii].GetRow() );
423 
424  // Handle block selection
425  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
426  {
427  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
428  selectedRows.Add( i );
429  }
430 
431  // Use the row having the grid cursor only if we have no candidate:
432  if( selectedRows.size() == 0 && getCursorRow() >= 0 )
433  selectedRows.Add( getCursorRow() );
434 
435  std::sort( selectedRows.begin(), selectedRows.end() );
436 
437  // Remove selected rows (note: a row can be stored more than once in list)
438  int last_row = -1;
439  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
440  {
441  int row = selectedRows[ii];
442 
443  if( row != last_row )
444  {
445  last_row = row;
446  m_cur_grid->DeleteRows( row, 1 );
447  }
448  }
449 
450  if( currRow >= m_cur_grid->GetNumberRows() )
451  m_cur_grid->SetGridCursor(m_cur_grid->GetNumberRows()-1, getCursorCol() );
452 
453  m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
454  }
455 
456  void moveUpHandler( wxCommandEvent& event ) override
457  {
458  wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows();
459 
460  if( rowsSelected.GetCount() == 0 )
461  return;
462 
463  // @todo: add multiple selection moves.
464  int curRow = rowsSelected[0];
465 
466  if( curRow >= 1 )
467  {
468  int curCol = getCursorCol();
469 
470  FP_LIB_TABLE_GRID* tbl = cur_model();
471 
472  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
473  tbl->rows.release( tbl->rows.begin() + curRow );
474 
475  --curRow;
476  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
477 
478  if( tbl->GetView() )
479  {
480  // fire a msg to cause redrawing
481  wxGridTableMessage msg( tbl,
482  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
483  curRow,
484  0 );
485 
486  tbl->GetView()->ProcessTableMessage( msg );
487  }
488 
489  m_cur_grid->MakeCellVisible( curRow, curCol );
490  m_cur_grid->SetGridCursor( curRow, curCol );
491  m_cur_grid->SelectRow( getCursorRow() );
492  }
493  }
494 
495  void moveDownHandler( wxCommandEvent& event ) override
496  {
497  wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows();
498 
499  if( rowsSelected.GetCount() == 0 )
500  return;
501 
502  FP_LIB_TABLE_GRID* tbl = cur_model();
503 
504  // @todo: add multiple selection moves.
505  int curRow = rowsSelected[0];
506 
507  if( unsigned( curRow + 1 ) < tbl->rows.size() )
508  {
509  int curCol = getCursorCol();
510 
511  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
512  tbl->rows.release( tbl->rows.begin() + curRow );
513 
514  ++curRow;
515  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
516 
517  if( tbl->GetView() )
518  {
519  // fire a msg to cause redrawing
520  wxGridTableMessage msg( tbl,
521  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
522  curRow - 1,
523  0 );
524 
525  tbl->GetView()->ProcessTableMessage( msg );
526  }
527 
528  m_cur_grid->MakeCellVisible( curRow, curCol );
529  m_cur_grid->SetGridCursor( curRow, curCol );
530  m_cur_grid->SelectRow( getCursorRow() );
531  }
532  }
533 
534  void optionsEditor( wxCommandEvent& event ) override
535  {
536  FP_LIB_TABLE_GRID* tbl = cur_model();
537 
538  if( tbl->GetNumberRows() )
539  {
540  int curRow = getCursorRow();
541  LIB_TABLE_ROW* row = &tbl->rows[curRow];
542 
543  wxString result;
544  const wxString& options = row->GetOptions();
545 
546  InvokePluginOptionsEditor( this, row->GetNickName(), row->GetType(), options, &result );
547 
548  if( options != result )
549  {
550  row->SetOptions( result );
551 
552  // all but options:
553  m_cur_grid->AutoSizeColumn( COL_NICKNAME, false );
554  m_cur_grid->AutoSizeColumn( COL_URI, false );
555  m_cur_grid->AutoSizeColumn( COL_TYPE, false );
556 
557  // On Windows, the grid is not refresh,
558  // so force resfresh after a change
559 #ifdef __WINDOWS__
560  Refresh();
561 #endif
562  }
563  }
564  }
565 
566  void OnClickLibraryWizard( wxCommandEvent& event ) override;
567 
568  void onCancelButtonClick( wxCommandEvent& event ) override
569  {
570  EndModal( 0 );
571  }
572 
573  void onCancelCaptionButtonClick( wxCloseEvent& event ) override
574  {
575  EndModal( 0 );
576  }
577 
578  void onOKButtonClick( wxCommandEvent& event ) override
579  {
580  int dialogRet = 0;
581 
582  // stuff any pending cell editor text into the table.
583  m_cur_grid->SaveEditControlValue();
584 
585  if( verifyTables() )
586  {
587  if( *global_model() != *m_global )
588  {
589  dialogRet |= 1;
590 
591  m_global->Clear();
592  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
593  global_model()->rows.end(), global_model()->rows );
594  m_global->reindex();
595  }
596 
597  if( *project_model() != *m_project )
598  {
599  dialogRet |= 2;
600 
601  m_project->Clear();
602  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
603  project_model()->rows.end(), project_model()->rows );
604  m_project->reindex();
605  }
606 
607  EndModal( dialogRet );
608  }
609  }
610 
614  {
615  wxRegEx re( ".*?\\$\\{(.+?)\\}.*?", wxRE_ADVANCED );
616  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
617 
618  std::set< wxString > unique;
619  typedef std::set<wxString>::const_iterator SET_CITER;
620 
621  // clear the table
622  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
623 
626 
627  int gblRowCount = gbl->GetNumberRows();
628  int prjRowCount = prj->GetNumberRows();
629  int row;
630 
631  for( row = 0; row < gblRowCount; ++row )
632  {
633  wxString uri = gbl->GetValue( row, COL_URI );
634 
635  while( re.Matches( uri ) )
636  {
637  wxString envvar = re.GetMatch( uri, 1 );
638 
639  // ignore duplicates
640  unique.insert( envvar );
641 
642  // delete the last match and search again
643  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
644  }
645  }
646 
647  for( row = 0; row < prjRowCount; ++row )
648  {
649  wxString uri = prj->GetValue( row, COL_URI );
650 
651  while( re.Matches( uri ) )
652  {
653  wxString envvar = re.GetMatch( uri, 1 );
654 
655  // ignore duplicates
656  unique.insert( envvar );
657 
658  // delete the last match and search again
659  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
660  }
661  }
662 
663  // Make sure this special environment variable shows up even if it was
664  // not used yet. It is automatically set by KiCad to the directory holding
665  // the current project.
666  unique.insert( PROJECT_VAR_NAME );
667  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
668  // This special environment variable is used to locate 3d shapes
669  unique.insert( KISYS3DMOD );
670 
671  m_path_subs_grid->AppendRows( unique.size() );
672 
673  row = 0;
674 
675  for( SET_CITER it = unique.begin(); it != unique.end(); ++it, ++row )
676  {
677  wxString evName = *it;
678  wxString evValue;
679 
680  m_path_subs_grid->SetCellValue( row, 0, evName );
681 
682  if( wxGetEnv( evName, &evValue ) )
683  m_path_subs_grid->SetCellValue( row, 1, evValue );
684  }
685 
686  m_path_subs_grid->AutoSizeColumns();
687  }
688 
689  //-----</event handlers>---------------------------------
690 
691  // caller's tables are modified only on OK button and successful verification.
694 
696  {
697  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
698  }
699 
701  {
702  return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable();
703  }
704 
706  {
707  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
708  }
709 
710  wxGrid* m_cur_grid;
711  static int m_pageNdx;
712 };
713 
714 
716 
717 
718 void DIALOG_FP_LIB_TABLE::OnClickLibraryWizard( wxCommandEvent& event )
719 {
720  WIZARD_FPLIB_TABLE dlg( this );
721 
722  if( !dlg.RunWizard( dlg.GetFirstPage() ) )
723  return; // Aborted by user
724 
725  const std::vector<WIZARD_FPLIB_TABLE::LIBRARY>& libs = dlg.GetLibraries();
726  bool global_scope = dlg.GetLibScope() == WIZARD_FPLIB_TABLE::GLOBAL;
727  wxGrid* libgrid = global_scope ? m_global_grid : m_project_grid;
728  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) libgrid->GetTable();
729 
730  for( std::vector<WIZARD_FPLIB_TABLE::LIBRARY>::const_iterator it = libs.begin();
731  it != libs.end(); ++it )
732  {
733  if( it->GetStatus() == WIZARD_FPLIB_TABLE::LIBRARY::INVALID )
734  continue;
735 
736  if( libgrid->AppendRows( 1 ) )
737  {
738  int last_row = libgrid->GetNumberRows() - 1;
739 
740  // Add the nickname: currently make it from filename
741  tbl->SetValue( last_row, COL_NICKNAME, it->GetDescription() );
742 
743  // Add the path:
744  tbl->SetValue( last_row, COL_URI, it->GetAutoPath( dlg.GetLibScope() ) );
745 
746  // Add the plugin name:
747  tbl->SetValue( last_row, COL_TYPE, it->GetPluginName() );
748 
749  libgrid->MakeCellVisible( last_row, 0 );
750  libgrid->SetGridCursor( last_row, 0 );
751  }
752  }
753 
754  // Switch to the current scope tab
755  if( global_scope )
756  m_auinotebook->SetSelection( 0 );
757  else
758  m_auinotebook->SetSelection( 1 );
759 
760  libgrid->SelectRow( libgrid->GetGridCursorRow() );
761 }
762 
763 
764 int InvokePcbLibTableEditor( wxTopLevelWindow* aCaller, FP_LIB_TABLE* aGlobal,
765  FP_LIB_TABLE* aProject )
766 {
767  DIALOG_FP_LIB_TABLE dlg( aCaller, aGlobal, aProject );
768 
769  int dialogRet = dlg.ShowModal(); // returns value passed to EndModal() above
770 
771  return dialogRet;
772 }
773 
774 
775 int InvokeFootprintWizard( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal,
776  FP_LIB_TABLE* aProject )
777 {
778  WIZARD_FPLIB_TABLE dlg( aParent );
779 
780  if( !dlg.RunWizard( dlg.GetFirstPage() ) )
781  return 0; // Aborted by user
782 
783  const std::vector<WIZARD_FPLIB_TABLE::LIBRARY>& libs = dlg.GetLibraries();
785  FP_LIB_TABLE* fp_tbl = ( scope == WIZARD_FPLIB_TABLE::GLOBAL ? aGlobal : aProject );
786 
787  if( fp_tbl )
788  {
789  for( std::vector<WIZARD_FPLIB_TABLE::LIBRARY>::const_iterator it = libs.begin();
790  it != libs.end(); ++it )
791  {
792  if( it->GetStatus() == WIZARD_FPLIB_TABLE::LIBRARY::INVALID )
793  continue;
794 
795  FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( it->GetDescription(),
796  it->GetAutoPath( scope ),
797  it->GetPluginName(),
798  wxEmptyString ); // options
799  fp_tbl->InsertRow( row );
800  }
801  }
802 
803  return scope;
804 }
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.
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
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...
void Clear()
Delete all rows.
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.
void reindex()
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:57
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
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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 object...
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.
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.
Definition: grid_tricks.h:60
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'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:53
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.
Class LIB_TABLE_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/lib_table.keywords.
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:73
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
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:54