KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_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 <[email protected]>
5 * Copyright (C) 2013-2021 CERN
6 * Copyright (C) 2012-2024 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/dir.h>
36#include <wx/regex.h>
37#include <wx/grid.h>
38#include <wx/dirdlg.h>
39#include <wx/filedlg.h>
40#include <wx/msgdlg.h>
41
42#include <project.h>
43#include <env_vars.h>
45#include <panel_fp_lib_table.h>
46#include <lib_id.h>
47#include <fp_lib_table.h>
48#include <lib_table_lexer.h>
49#include <invoke_pcb_dialog.h>
50#include <bitmaps.h>
52#include <widgets/wx_grid.h>
54#include <confirm.h>
55#include <lib_table_grid.h>
57#include <pgm_base.h>
58#include <pcb_edit_frame.h>
59#include <env_paths.h>
65#include <kiway.h>
66#include <kiway_express.h>
69#include <pcbnew_id.h> // For ID_PCBNEW_END_LIST
71#include <paths.h>
72#include <macros.h>
73#include <project_pcb.h>
74#include <common.h>
77
78// clang-format off
79
84{
85 wxString m_Description;
86 wxString m_FileFilter;
88 bool m_IsFile;
90};
91
92// clang-format on
93
98class LIBRARY_TRAVERSER : public wxDirTraverser
99{
100public:
101 LIBRARY_TRAVERSER( std::vector<std::string> aSearchExtensions, wxString aInitialDir ) :
102 m_searchExtensions( aSearchExtensions ), m_currentDir( aInitialDir )
103 {
104 }
105
106 virtual wxDirTraverseResult OnFile( const wxString& aFileName ) override
107 {
108 wxFileName file( aFileName );
109
110 for( const std::string& ext : m_searchExtensions )
111 {
112 if( file.GetExt().IsSameAs( ext, false ) )
113 m_foundDirs.insert( { m_currentDir, 1 } );
114 }
115
116 return wxDIR_CONTINUE;
117 }
118
119 virtual wxDirTraverseResult OnOpenError( const wxString& aOpenErrorName ) override
120 {
121 m_failedDirs.insert( { aOpenErrorName, 1 } );
122 return wxDIR_IGNORE;
123 }
124
126 {
127 return m_failedDirs.size() > 0;
128 }
129
130 virtual wxDirTraverseResult OnDir( const wxString& aDirName ) override
131 {
132 m_currentDir = aDirName;
133 return wxDIR_CONTINUE;
134 }
135
136 void GetPaths( wxArrayString& aPathArray )
137 {
138 for( std::pair<const wxString, int>& foundDirsPair : m_foundDirs )
139 aPathArray.Add( foundDirsPair.first );
140 }
141
142 void GetFailedPaths( wxArrayString& aPathArray )
143 {
144 for( std::pair<const wxString, int>& failedDirsPair : m_failedDirs )
145 aPathArray.Add( failedDirsPair.first );
146 }
147
148private:
149 std::vector<std::string> m_searchExtensions;
150 wxString m_currentDir;
151 std::unordered_map<wxString, int> m_foundDirs;
152 std::unordered_map<wxString, int> m_failedDirs;
153};
154
155
160{
161 friend class PANEL_FP_LIB_TABLE;
162 friend class FP_GRID_TRICKS;
163
164protected:
165 LIB_TABLE_ROW* at( size_t aIndex ) override { return &m_rows.at( aIndex ); }
166
167 size_t size() const override { return m_rows.size(); }
168
170 {
171 return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
172 }
173
174 LIB_TABLE_ROWS_ITER begin() override { return m_rows.begin(); }
175
177 {
178 return m_rows.insert( aIterator, aRow );
179 }
180
181 void push_back( LIB_TABLE_ROW* aRow ) override { m_rows.push_back( aRow ); }
182
184 {
185 return m_rows.erase( aFirst, aLast );
186 }
187
188public:
189
190 FP_LIB_TABLE_GRID( const FP_LIB_TABLE& aTableToEdit )
191 {
192 m_rows = aTableToEdit.m_rows;
193 }
194
195 void SetValue( int aRow, int aCol, const wxString &aValue ) override
196 {
197 wxCHECK( aRow < (int) size(), /* void */ );
198
199 LIB_TABLE_GRID::SetValue( aRow, aCol, aValue );
200
201 // If setting a filepath, attempt to auto-detect the format
202 if( aCol == COL_URI )
203 {
204 LIB_TABLE_ROW* row = at( (size_t) aRow );
205 wxString fullURI = row->GetFullURI( true );
206
208
209 if( pluginType == PCB_IO_MGR::FILE_TYPE_NONE )
210 pluginType = PCB_IO_MGR::KICAD_SEXP;
211
212 SetValue( aRow, COL_TYPE, PCB_IO_MGR::ShowType( pluginType ) );
213 }
214 }
215};
216
217
218
220{
221public:
223 LIB_TABLE_GRID_TRICKS( aGrid ),
224 m_dialog( aParent )
225 { }
226
227protected:
229
230 void optionsEditor( int aRow ) override
231 {
232 FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
233
234 if( tbl->GetNumberRows() > aRow )
235 {
236 LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
237 const wxString& options = row->GetOptions();
238 wxString result = options;
239 std::map<std::string, UTF8> choices;
240
243 pi->GetLibraryOptions( &choices );
244
245 DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result );
246 dlg.ShowModal();
247
248 if( options != result )
249 {
250 row->SetOptions( result );
251 m_grid->Refresh();
252 }
253 }
254 }
255
258 void paste_text( const wxString& cb_text ) override
259 {
260 FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
261 size_t ndx = cb_text.find( "(fp_lib_table" );
262
263 if( ndx != std::string::npos )
264 {
265 // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
266 // at column 0 regardless of current cursor column.
267
268 STRING_LINE_READER slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
269 LIB_TABLE_LEXER lexer( &slr );
270 FP_LIB_TABLE tmp_tbl;
271 bool parsed = true;
272
273 try
274 {
275 tmp_tbl.Parse( &lexer );
276 }
277 catch( PARSE_ERROR& pe )
278 {
279 DisplayError( m_dialog, pe.What() );
280 parsed = false;
281 }
282
283 if( parsed )
284 {
285 // make sure the table is big enough...
286 if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
287 tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
288
289 for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
290 tbl->m_rows.replace( i, tmp_tbl.At( i ).clone() );
291 }
292
293 m_grid->AutoSizeColumns( false );
294 }
295 else
296 {
297 // paste spreadsheet formatted text.
298 GRID_TRICKS::paste_text( cb_text );
299
300 m_grid->AutoSizeColumns( false );
301 }
302 }
303
304
305 bool toggleCell( int aRow, int aCol, bool aPreserveSelection ) override
306 {
307 if( aCol == COL_VISIBLE )
308 {
309 m_dialog->ShowInfoBarError( _( "Hidden footprint libraries are not yet supported." ) );
310 return true;
311 }
312
313 return LIB_TABLE_GRID_TRICKS::toggleCell( aRow, aCol, aPreserveSelection );
314 }
315};
316
317
319{
321
322 auto autoSizeCol = [&]( WX_GRID* aLocGrid, int aCol )
323 {
324 int prevWidth = aLocGrid->GetColSize( aCol );
325
326 aLocGrid->AutoSizeColumn( aCol, false );
327 aLocGrid->SetColSize( aCol, std::max( prevWidth, aLocGrid->GetColSize( aCol ) ) );
328 };
329
330 // Give a bit more room for wxChoice editors
331 for( int ii = 0; ii < aGrid->GetNumberRows(); ++ii )
332 aGrid->SetRowSize( ii, aGrid->GetDefaultRowSize() + 4 );
333
334 // add Cut, Copy, and Paste to wxGrids
335 aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
336
337 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
338
339 wxGridCellAttr* attr;
340
341 attr = new wxGridCellAttr;
342 attr->SetEditor( new GRID_CELL_PATH_EDITOR(
344 [this]( WX_GRID* grid, int row ) -> wxString
345 {
346 auto* libTable = static_cast<FP_LIB_TABLE_GRID*>( grid->GetTable() );
347 auto* tableRow = static_cast<FP_LIB_TABLE_ROW*>( libTable->at( row ) );
348 PCB_IO_MGR::PCB_FILE_T fileType = tableRow->GetFileType();
349 const IO_BASE::IO_FILE_DESC& pluginDesc = m_supportedFpFiles.at( fileType );
350
351 if( pluginDesc.m_IsFile )
352 return pluginDesc.FileFilter();
353 else
354 return wxEmptyString;
355 } ) );
356 aGrid->SetColAttr( COL_URI, attr );
357
358 attr = new wxGridCellAttr;
359 attr->SetEditor( new wxGridCellChoiceEditor( m_pluginChoices ) );
360 aGrid->SetColAttr( COL_TYPE, attr );
361
362 attr = new wxGridCellAttr;
363 attr->SetRenderer( new wxGridCellBoolRenderer() );
364 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
365 aGrid->SetColAttr( COL_ENABLED, attr );
366
367 attr = new wxGridCellAttr;
368 attr->SetRenderer( new wxGridCellBoolRenderer() );
369 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
370 aGrid->SetColAttr( COL_VISIBLE, attr );
371 // No visibility control for footprint libraries yet; this feature is primarily
372 // useful for database libraries and it's only implemented for schematic symbols
373 // at the moment.
374 aGrid->HideCol( COL_VISIBLE );
375
376 // all but COL_OPTIONS, which is edited with Option Editor anyways.
377 autoSizeCol( aGrid, COL_NICKNAME );
378 autoSizeCol( aGrid, COL_TYPE );
379 autoSizeCol( aGrid, COL_URI );
380 autoSizeCol( aGrid, COL_DESCR );
381
382 // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
383 // a currentCell which is sometimes not highlighted.
384 if( aGrid->GetNumberRows() > 0 )
385 aGrid->SelectRow( 0 );
386};
387
388
390 FP_LIB_TABLE* aGlobalTable, const wxString& aGlobalTblPath,
391 FP_LIB_TABLE* aProjectTable, const wxString& aProjectTblPath,
392 const wxString& aProjectBasePath ) :
393 PANEL_FP_LIB_TABLE_BASE( aParent ),
394 m_globalTable( aGlobalTable ),
395 m_projectTable( aProjectTable ),
396 m_project( aProject ),
397 m_projectBasePath( aProjectBasePath ),
398 m_parent( aParent )
399{
400 m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobalTable ), true );
401
402 // add Cut, Copy, and Paste to wxGrids
403 m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
404
406
407 for( auto& [fileType, desc] : m_supportedFpFiles )
409
410
412
413 if( cfg->m_lastFootprintLibDir.IsEmpty() )
415
417
419
421
422 if( aProjectTable )
423 {
424 m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProjectTable ), true );
426 }
427 else
428 {
429 m_pageNdx = 0;
430 m_notebook->DeletePage( 1 );
431 m_project_grid = nullptr;
432 }
433
434 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
435 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
436
437 // select the last selected page
438 m_notebook->SetSelection( m_pageNdx );
440
441 // for ALT+A handling, we want the initial focus to be on the first selected grid.
443
444 // Configure button logos
445 m_append_button->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
446 m_delete_button->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
447 m_move_up_button->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
448 m_move_down_button->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
449 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
450
451 // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
452 // manually (for instance m_append_button)
453 Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
454 // their bitmaps
455 wxSize buttonSize = m_append_button->GetSize();
456
458 m_browseButton->SetMinSize( buttonSize );
459
460 // Populate the browse library options
461 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
462
463 auto joinExts = []( const std::vector<std::string>& aExts )
464 {
465 wxString joined;
466 for( const std::string& ext : aExts )
467 {
468 if( !joined.empty() )
469 joined << wxS( ", " );
470
471 joined << wxS( "*." ) << ext;
472 }
473
474 return joined;
475 };
476
477 for( auto& [type, desc] : m_supportedFpFiles )
478 {
479 wxString entryStr = PCB_IO_MGR::ShowType( type );
480
481 if( desc.m_IsFile && !desc.m_FileExtensions.empty() )
482 {
483 entryStr << wxString::Format( wxS( " (%s)" ),
484 joinExts( desc.m_FileExtensions ) );
485 }
486 else if( !desc.m_IsFile && !desc.m_ExtensionsInDir.empty() )
487 {
488 wxString midPart = wxString::Format( _( "folder with %s files" ),
489 joinExts( desc.m_ExtensionsInDir ) );
490
491 entryStr << wxString::Format( wxS( " (%s)" ), midPart );
492 }
493
494 browseMenu->Append( type, entryStr );
495
496 browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_FP_LIB_TABLE::browseLibrariesHandler,
497 this, type );
498 }
499
500 Layout();
501
502 // This is the button only press for the browse button instead of the menu
504}
505
506
508{
509 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
510 for( auto& [type, desc] : m_supportedFpFiles )
511 {
512 browseMenu->Unbind( wxEVT_COMMAND_MENU_SELECTED,
514 }
515 m_browseButton->Unbind( wxEVT_BUTTON, &PANEL_FP_LIB_TABLE::browseLibrariesHandler, this );
516
517 // Delete the GRID_TRICKS.
518 // Any additional event handlers should be popped before the window is deleted.
519 m_global_grid->PopEventHandler( true );
520
521 if( m_project_grid )
522 m_project_grid->PopEventHandler( true );
523
524 m_path_subs_grid->PopEventHandler( true );
525}
526
527
529{
530 for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() )
531 {
532 IO_RELEASER<PCB_IO> pi( plugin.m_createFunc() );
533
534 if( !pi )
535 continue;
536
537 if( const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc() )
538 m_supportedFpFiles.emplace( plugin.m_type, desc );
539 }
540}
541
542
544{
545 wxString msg;
546
547 for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
548 {
549 if( !model )
550 continue;
551
552 for( int r = 0; r < model->GetNumberRows(); )
553 {
554 wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
555 wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
556 unsigned illegalCh = 0;
557
558 if( !nick || !uri )
559 {
560 if( !nick && !uri )
561 msg = _( "A library table row nickname and path cells are empty." );
562 else if( !nick )
563 msg = _( "A library table row nickname cell is empty." );
564 else
565 msg = _( "A library table row path cell is empty." );
566
567 wxWindow* topLevelParent = wxGetTopLevelParent( this );
568
569 wxMessageDialog badCellDlg( topLevelParent, msg, _( "Invalid Row Definition" ),
570 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
571 badCellDlg.SetExtendedMessage( _( "Empty cells will result in all rows that are "
572 "invalid to be removed from the table." ) );
573 badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Remove Invalid Cells" ) ),
574 wxMessageDialog::ButtonLabel( _( "Cancel Table Update" ) ) );
575
576 if( badCellDlg.ShowModal() == wxID_NO )
577 return false;
578
579 // Delete the "empty" row, where empty means missing nick or uri.
580 // This also updates the UI which could be slow, but there should only be a few
581 // rows to delete, unless the user fell asleep on the Add Row
582 // button.
583 model->DeleteRows( r, 1 );
584 }
585 else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
586 {
587 msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ),
588 illegalCh,
589 nick );
590
591 // show the tabbed panel holding the grid we have flunked:
592 if( model != cur_model() )
593 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
594
595 m_cur_grid->MakeCellVisible( r, 0 );
596 m_cur_grid->SetGridCursor( r, 1 );
597
598 wxWindow* topLevelParent = wxGetTopLevelParent( this );
599
600 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
601 errdlg.ShowModal();
602 return false;
603 }
604 else
605 {
606 // set the trimmed values back into the table so they get saved to disk.
607 model->SetValue( r, COL_NICKNAME, nick );
608 model->SetValue( r, COL_URI, uri );
609
610 // Make sure to not save a hidden flag
611 model->SetValue( r, COL_VISIBLE, wxS( "1" ) );
612
613 ++r; // this row was OK.
614 }
615 }
616 }
617
618 // check for duplicate nickNames, separately in each table.
619 for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
620 {
621 if( !model )
622 continue;
623
624 for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
625 {
626 wxString nick1 = model->GetValue( r1, COL_NICKNAME );
627
628 for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
629 {
630 wxString nick2 = model->GetValue( r2, COL_NICKNAME );
631
632 if( nick1 == nick2 )
633 {
634 msg = wxString::Format( _( "Multiple libraries cannot share the same "
635 "nickname ('%s')." ),
636 nick1 );
637
638 // show the tabbed panel holding the grid we have flunked:
639 if( model != cur_model() )
640 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
641
642 // go to the lower of the two rows, it is technically the duplicate:
643 m_cur_grid->MakeCellVisible( r2, 0 );
644 m_cur_grid->SetGridCursor( r2, 1 );
645
646 wxWindow* topLevelParent = wxGetTopLevelParent( this );
647
648 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
649 errdlg.ShowModal();
650 return false;
651 }
652 }
653 }
654 }
655
656 return true;
657}
658
659
660void PANEL_FP_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
661{
662}
663
664
665void PANEL_FP_LIB_TABLE::appendRowHandler( wxCommandEvent& event )
666{
668 return;
669
670 if( m_cur_grid->AppendRows( 1 ) )
671 {
672 int last_row = m_cur_grid->GetNumberRows() - 1;
673
674 // wx documentation is wrong, SetGridCursor does not make visible.
675 m_cur_grid->MakeCellVisible( last_row, COL_ENABLED );
676 m_cur_grid->SetGridCursor( last_row, COL_NICKNAME );
677 m_cur_grid->EnableCellEditControl( true );
678 m_cur_grid->ShowCellEditControl();
679 }
680}
681
682
683void PANEL_FP_LIB_TABLE::deleteRowHandler( wxCommandEvent& event )
684{
686 return;
687
688 int curRow = m_cur_grid->GetGridCursorRow();
689 int curCol = m_cur_grid->GetGridCursorCol();
690
691 // In a wxGrid, collect rows that have a selected cell, or are selected
692 // It is not so easy: it depends on the way the selection was made.
693 // Here, we collect rows selected by clicking on a row label, and rows that contain any
694 // previously-selected cells.
695 // If no candidate, just delete the row with the grid cursor.
696 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
697 wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
698 wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
699 wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
700
701 // Add all row having cell selected to list:
702 for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
703 selectedRows.Add( cells[ii].GetRow() );
704
705 // Handle block selection
706 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
707 {
708 for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
709 selectedRows.Add( i );
710 }
711
712 // Use the row having the grid cursor only if we have no candidate:
713 if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
714 selectedRows.Add( m_cur_grid->GetGridCursorRow() );
715
716 if( selectedRows.size() == 0 )
717 {
718 wxBell();
719 return;
720 }
721
722 std::sort( selectedRows.begin(), selectedRows.end() );
723
724 // Remove selected rows (note: a row can be stored more than once in list)
725 int last_row = -1;
726
727 // Needed to avoid a wxWidgets alert if the row to delete is the last row
728 // at least on wxMSW 3.2
729 m_cur_grid->ClearSelection();
730
731 for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
732 {
733 int row = selectedRows[ii];
734
735 if( row != last_row )
736 {
737 last_row = row;
738 m_cur_grid->DeleteRows( row, 1 );
739 }
740 }
741
742 if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
743 m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
744}
745
746
747void PANEL_FP_LIB_TABLE::moveUpHandler( wxCommandEvent& event )
748{
750 return;
751
753 int curRow = m_cur_grid->GetGridCursorRow();
754
755 // @todo: add multiple selection moves.
756 if( curRow >= 1 )
757 {
758 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
759 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
760
761 --curRow;
762 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
763
764 if( tbl->GetView() )
765 {
766 // Update the wxGrid
767 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
768 tbl->GetView()->ProcessTableMessage( msg );
769 }
770
771 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
772 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
773 }
774}
775
776
777void PANEL_FP_LIB_TABLE::moveDownHandler( wxCommandEvent& event )
778{
780 return;
781
783 int curRow = m_cur_grid->GetGridCursorRow();
784
785 // @todo: add multiple selection moves.
786 if( unsigned( curRow + 1 ) < tbl->m_rows.size() )
787 {
788 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
789 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
790
791 ++curRow;
792 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
793
794 if( tbl->GetView() )
795 {
796 // Update the wxGrid
797 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
798 tbl->GetView()->ProcessTableMessage( msg );
799 }
800
801 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
802 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
803 }
804}
805
806
807// @todo refactor this function into single location shared with PANEL_SYM_LIB_TABLE
808void PANEL_FP_LIB_TABLE::onMigrateLibraries( wxCommandEvent& event )
809{
811 return;
812
813 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
814
815 if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
816 selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
817
818 wxArrayInt rowsToMigrate;
819 wxString kicadType = PCB_IO_MGR::ShowType( PCB_IO_MGR::KICAD_SEXP );
820 wxString msg;
821 DIALOG_HTML_REPORTER errorReporter( this );
822
823 for( int row : selectedRows )
824 {
825 if( m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
826 rowsToMigrate.push_back( row );
827 }
828
829 if( rowsToMigrate.size() <= 0 )
830 {
831 wxMessageBox( wxString::Format( _( "Select one or more rows containing libraries "
832 "to save as current KiCad format." ) ) );
833 return;
834 }
835 else
836 {
837 if( rowsToMigrate.size() == 1 )
838 {
839 msg.Printf( _( "Save '%s' as current KiCad format "
840 "and replace entry in table?" ),
841 m_cur_grid->GetCellValue( rowsToMigrate[0], COL_NICKNAME ) );
842 }
843 else
844 {
845 msg.Printf( _( "Save %d libraries as current KiCad format "
846 "and replace entries in table?" ),
847 (int) rowsToMigrate.size() );
848 }
849
850 if( !IsOK( m_parent, msg ) )
851 return;
852 }
853
854 for( int row : rowsToMigrate )
855 {
856 wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
857 wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
858 wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
859 wxFileName legacyLib( resolvedPath );
860
861 if( !legacyLib.Exists() )
862 {
863 msg.Printf( _( "Library '%s' not found." ), relPath );
864 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
865 continue;
866 }
867
868 wxFileName newLib( resolvedPath );
869 newLib.AppendDir( newLib.GetName() + "." + FILEEXT::KiCadFootprintLibPathExtension );
870 newLib.SetName( "" );
871 newLib.ClearExt();
872
873 if( newLib.DirExists() )
874 {
875 msg.Printf( _( "Folder '%s' already exists. Do you want overwrite any existing footprints?" ),
876 newLib.GetFullPath() );
877
878 switch( wxMessageBox( msg, _( "Migrate Library" ),
879 wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
880 {
881 case wxYES: break;
882 case wxNO: continue;
883 case wxCANCEL: return;
884 }
885 }
886
887 wxString options = m_cur_grid->GetCellValue( row, COL_OPTIONS );
888 std::unique_ptr<std::map<std::string, UTF8>> props( LIB_TABLE::ParseOptions( options.ToStdString() ) );
889
890 if( PCB_IO_MGR::ConvertLibrary( props.get(), legacyLib.GetFullPath(),
891 newLib.GetFullPath(), errorReporter.m_Reporter ) )
892 {
893 relPath = NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(),
894 m_project );
895
896 // Do not use the project path in the global library table. This will almost
897 // assuredly be wrong for a different project.
898 if( m_cur_grid == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) )
899 relPath = newLib.GetFullPath();
900
901 m_cur_grid->SetCellValue( row, COL_URI, relPath );
902 m_cur_grid->SetCellValue( row, COL_TYPE, kicadType );
903 }
904 else
905 {
906 msg.Printf( _( "Failed to save footprint library file '%s'." ), newLib.GetFullPath() );
907 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
908 }
909 }
910
911 if( errorReporter.m_Reporter->HasMessage() )
912 {
913 errorReporter.m_Reporter->Flush(); // Build HTML messages
914 errorReporter.ShowModal();
915 }
916}
917
918
920{
922 return;
923
925
926 // We are bound both to the menu and button with this one handler
927 // So we must set the file type based on it
928 if( event.GetEventType() == wxEVT_BUTTON )
929 {
930 // Let's default to adding a kicad footprint file for just the footprint
932 }
933 else
934 {
935 fileType = static_cast<PCB_IO_MGR::PCB_FILE_T>( event.GetId() );
936 }
937
939 {
940 wxLogWarning( wxT( "File type selection event received but could not find the file type "
941 "in the table" ) );
942 return;
943 }
944
945 const IO_BASE::IO_FILE_DESC& fileDesc = m_supportedFpFiles.at( fileType );
947
948 wxString title = wxString::Format( _( "Select %s Library" ), PCB_IO_MGR::ShowType( fileType ) );
949 wxString openDir = cfg->m_lastFootprintLibDir;
950
952 openDir = m_lastProjectLibDir;
953
954 wxArrayString files;
955
956 wxWindow* topLevelParent = wxGetTopLevelParent( this );
957
958 if( fileDesc.m_IsFile )
959 {
960 wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
961 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
962
963 int result = dlg.ShowModal();
964
965 if( result == wxID_CANCEL )
966 return;
967
968 dlg.GetPaths( files );
969
971 cfg->m_lastFootprintLibDir = dlg.GetDirectory();
972 else
973 m_lastProjectLibDir = dlg.GetDirectory();
974 }
975 else
976 {
977 wxDirDialog dlg( topLevelParent, title, openDir,
978 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
979
980 int result = dlg.ShowModal();
981
982 if( result == wxID_CANCEL )
983 return;
984
985 dlg.GetPaths( files );
986
987 if( !files.IsEmpty() )
988 {
989 wxFileName first( files.front() );
990
992 cfg->m_lastFootprintLibDir = first.GetPath();
993 else
994 m_lastProjectLibDir = first.GetPath();
995 }
996 }
997
998 // Drop the last directory if the path is a .pretty folder
1000 cfg->m_lastFootprintLibDir = cfg->m_lastFootprintLibDir.BeforeLast( wxFileName::GetPathSeparator() );
1001
1002 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1003 bool addDuplicates = false;
1004 bool applyToAll = false;
1005 wxString warning = _( "Warning: Duplicate Nicknames" );
1006 wxString msg = _( "A library nicknamed '%s' already exists." );
1007 wxString detailedMsg = _( "One of the nicknames will need to be changed after "
1008 "adding this library." );
1009
1010 for( const wxString& filePath : files )
1011 {
1012 wxFileName fn( filePath );
1013 wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
1014 bool doAdd = true;
1015
1017 && fn.GetExt() != FILEEXT::KiCadFootprintLibPathExtension )
1018 nickname = LIB_ID::FixIllegalChars( fn.GetFullName(), true ).wx_str();
1019
1020 if( cur_model()->ContainsNickname( nickname ) )
1021 {
1022 if( !applyToAll )
1023 {
1024 // The cancel button adds the library to the table anyway
1025 addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning,
1026 wxString::Format( msg, nickname ),
1027 detailedMsg, _( "Skip" ), _( "Add Anyway" ),
1028 &applyToAll ) == wxID_CANCEL;
1029 }
1030
1031 doAdd = addDuplicates;
1032 }
1033
1034 if( doAdd && m_cur_grid->AppendRows( 1 ) )
1035 {
1036 int last_row = m_cur_grid->GetNumberRows() - 1;
1037
1038 m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
1039
1040 m_cur_grid->SetCellValue( last_row, COL_TYPE, PCB_IO_MGR::ShowType( fileType ) );
1041
1042 // try to use path normalized to an environmental variable or project path
1043 wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
1044
1045 // Do not use the project path in the global library table. This will almost
1046 // assuredly be wrong for a different project.
1047 if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
1048 path = fn.GetFullPath();
1049
1050 m_cur_grid->SetCellValue( last_row, COL_URI, path );
1051 }
1052 }
1053
1054 if( !files.IsEmpty() )
1055 {
1056 int new_row = m_cur_grid->GetNumberRows() - 1;
1057 m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
1058 m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
1059 }
1060}
1061
1062
1064{
1065 // Account for scroll bars
1066 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
1067
1068 m_path_subs_grid->AutoSizeColumn( 0 );
1069 m_path_subs_grid->SetColSize( 0, std::max( 72, m_path_subs_grid->GetColSize( 0 ) ) );
1070 m_path_subs_grid->SetColSize( 1, std::max( 120, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
1071}
1072
1073
1074void PANEL_FP_LIB_TABLE::onSizeGrid( wxSizeEvent& event )
1075{
1076 adjustPathSubsGridColumns( event.GetSize().GetX() );
1077
1078 event.Skip();
1079}
1080
1081
1082void PANEL_FP_LIB_TABLE::onReset( wxCommandEvent& event )
1083{
1085 return;
1086
1087 // No need to prompt to preserve an empty table
1088 if( m_global_grid->GetNumberRows() > 0 &&
1089 !IsOK( this, wxString::Format( _( "This action will reset your global library table on "
1090 "disk and cannot be undone." ) ) ) )
1091 {
1092 return;
1093 }
1094
1096
1097 if( dlg.ShowModal() == wxID_OK )
1098 {
1099 m_global_grid->Freeze();
1100
1101 wxGridTableBase* table = m_global_grid->GetTable();
1102 m_global_grid->DestroyTable( table );
1103
1105 m_global_grid->PopEventHandler( true );
1108
1109 m_global_grid->Thaw();
1110 }
1111}
1112
1113
1114void PANEL_FP_LIB_TABLE::onPageChange( wxBookCtrlEvent& event )
1115{
1116 m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
1117
1118 if( m_pageNdx == 0 )
1119 {
1121 m_resetGlobal->Enable();
1122 }
1123 else
1124 {
1126 m_resetGlobal->Disable();
1127 }
1128}
1129
1130
1132{
1134 return false;
1135
1136 if( verifyTables() )
1137 {
1138 if( *global_model() != *m_globalTable )
1139 {
1142 }
1143
1145 {
1148 }
1149
1150 return true;
1151 }
1152
1153 return false;
1154}
1155
1156
1160{
1161 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1162 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1163
1164 std::set< wxString > unique;
1165
1166 // clear the table
1168
1169 for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
1170 {
1171 if( !tbl )
1172 continue;
1173
1174 for( int row = 0; row < tbl->GetNumberRows(); ++row )
1175 {
1176 wxString uri = tbl->GetValue( row, COL_URI );
1177
1178 while( re.Matches( uri ) )
1179 {
1180 wxString envvar = re.GetMatch( uri, 2 );
1181
1182 // if not ${...} form then must be $(...)
1183 if( envvar.IsEmpty() )
1184 envvar = re.GetMatch( uri, 4 );
1185
1186 // ignore duplicates
1187 unique.insert( envvar );
1188
1189 // delete the last match and search again
1190 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1191 }
1192 }
1193 }
1194
1195 // Make sure this special environment variable shows up even if it was
1196 // not used yet. It is automatically set by KiCad to the directory holding
1197 // the current project.
1198 unique.insert( PROJECT_VAR_NAME );
1199 unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
1200
1201 // This special environment variable is used to locate 3d shapes
1202 unique.insert( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
1203
1204 for( const wxString& evName : unique )
1205 {
1206 int row = m_path_subs_grid->GetNumberRows();
1207 m_path_subs_grid->AppendRows( 1 );
1208
1209 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1210 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1211
1212 wxString evValue;
1213 wxGetEnv( evName, &evValue );
1214 m_path_subs_grid->SetCellValue( row, 1, evValue );
1215 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1216 }
1217
1218 // No combobox editors here, but it looks better if its consistent with the other
1219 // grids in the dialog.
1220 m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1221
1222 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1223}
1224
1225//-----</event handlers>---------------------------------
1226
1227
1228
1230
1231
1232void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller )
1233{
1234 FP_LIB_TABLE* globalTable = &GFootprintTable;
1235 wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
1236 FP_LIB_TABLE* projectTable = PROJECT_PCB::PcbFootprintLibs( &aKiway->Prj() );
1237 wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
1238 wxString msg;
1239
1240 DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
1241 dlg.SetKiway( &dlg, aKiway );
1242
1243 if( aKiway->Prj().IsNullProject() )
1244 projectTable = nullptr;
1245
1246 dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1247 projectTable, projectTablePath,
1248 aKiway->Prj().GetProjectPath() ) );
1249
1250 if( dlg.ShowModal() == wxID_CANCEL )
1251 return;
1252
1253 if( dlg.m_GlobalTableChanged )
1254 {
1255 try
1256 {
1257 globalTable->Save( globalTablePath );
1258 }
1259 catch( const IO_ERROR& ioe )
1260 {
1261 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1262 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1263 }
1264 }
1265
1266 if( projectTable && dlg.m_ProjectTableChanged )
1267 {
1268 try
1269 {
1270 projectTable->Save( projectTablePath );
1271 }
1272 catch( const IO_ERROR& ioe )
1273 {
1274 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1275 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1276 }
1277 }
1278
1279 std::string payload = "";
1282 aKiway->ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload );
1283}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Class DIALOG_HTML_REPORTER.
WX_HTML_REPORT_BOX * m_Reporter
DIALOG_PLUGIN_OPTIONS is an options editor in the form of a two column name/value spreadsheet like (t...
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void paste_text(const wxString &cb_text) override
handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text.
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
FP_GRID_TRICKS(DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
void optionsEditor(int aRow) override
bool toggleCell(int aRow, int aCol, bool aPreserveSelection) override
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
size_t size() const override
FP_LIB_TABLE_GRID(const FP_LIB_TABLE &aTableToEdit)
void SetValue(int aRow, int aCol, const wxString &aValue) override
LIB_TABLE_ROWS_ITER begin() override
LIB_TABLE_ROWS_ITER erase(LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
LIB_TABLE_ROW * makeNewRow() override
LIB_TABLE_ROW * at(size_t aIndex) override
void push_back(LIB_TABLE_ROW *aRow) override
LIB_TABLE_ROWS_ITER insert(LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
Hold a record identifying a library accessed by the appropriate footprint library #PLUGIN object in t...
Definition: fp_lib_table.h:42
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
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...
static wxString GetGlobalTableFileName()
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
virtual void paste_text(const wxString &cb_text)
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:125
virtual bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:527
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:196
Traverser implementation that looks to find any and all "folder" libraries by looking for files with ...
void GetPaths(wxArrayString &aPathArray)
virtual wxDirTraverseResult OnOpenError(const wxString &aOpenErrorName) override
std::unordered_map< wxString, int > m_failedDirs
std::vector< std::string > m_searchExtensions
void GetFailedPaths(wxArrayString &aPathArray)
LIBRARY_TRAVERSER(std::vector< std::string > aSearchExtensions, wxString aInitialDir)
std::unordered_map< wxString, int > m_foundDirs
virtual wxDirTraverseResult OnDir(const wxString &aDirName) override
virtual wxDirTraverseResult OnFile(const wxString &aFileName) override
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:243
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:191
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool AppendRows(size_t aNumRows=1) override
int GetNumberRows() override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
virtual const wxString GetType() const =0
Return the type of library represented by this row.
const wxString & GetNickName() const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_TABLE_ROW * clone() const
void SetOptions(const wxString &aOptions)
Change the library options strings.
static std::map< std::string, UTF8 > * ParseOptions(const std::string &aOptionsList)
Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
void TransferRows(LIB_TABLE_ROWS &aRowsList)
Takes ownership of another list of rows; the original list will be freed.
LIB_TABLE_ROWS m_rows
Owning set of rows.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Class PANEL_FP_LIB_TABLE_BASE.
STD_BITMAP_BUTTON * m_move_up_button
STD_BITMAP_BUTTON * m_append_button
STD_BITMAP_BUTTON * m_move_down_button
STD_BITMAP_BUTTON * m_delete_button
Dialog to show and edit symbol library tables.
FP_LIB_TABLE * m_globalTable
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
std::map< PCB_IO_MGR::PCB_FILE_T, IO_BASE::IO_FILE_DESC > m_supportedFpFiles
void onSizeGrid(wxSizeEvent &event) override
void moveUpHandler(wxCommandEvent &event) override
void adjustPathSubsGridColumns(int aWidth)
FP_LIB_TABLE_GRID * cur_model() const
FP_LIB_TABLE_GRID * project_model() const
void moveDownHandler(wxCommandEvent &event) override
wxArrayString m_pluginChoices
void setupGrid(WX_GRID *aGrid)
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 ...
FP_LIB_TABLE * m_projectTable
void deleteRowHandler(wxCommandEvent &event) override
void onReset(wxCommandEvent &event) override
void onMigrateLibraries(wxCommandEvent &event) override
void browseLibrariesHandler(wxCommandEvent &event)
bool TransferDataFromWindow() override
PANEL_FP_LIB_TABLE(DIALOG_EDIT_LIBRARY_TABLES *aParent, PROJECT *aProject, FP_LIB_TABLE *aGlobalTable, const wxString &aGlobalTblPath, FP_LIB_TABLE *aProjectTable, const wxString &aProjectTblPath, const wxString &aProjectBasePath)
DIALOG_EDIT_LIBRARY_TABLES * m_parent
void OnUpdateUI(wxUpdateUIEvent &event) override
void onPageChange(wxBookCtrlEvent &event) override
void appendRowHandler(wxCommandEvent &event) override
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:98
wxString m_lastFootprintLibDir
static PLUGIN_REGISTRY * Instance()
Definition: pcb_io_mgr.h:93
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: pcb_io_mgr.cpp:66
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
Definition: pcb_io_mgr.cpp:91
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
Definition: pcb_io_mgr.h:56
@ FILE_TYPE_NONE
Definition: pcb_io_mgr.h:76
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: pcb_io_mgr.h:58
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath, REPORTER *aReporter)
Convert a schematic symbol library to the latest KiCad format.
Definition: pcb_io_mgr.cpp:188
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
Definition: pcb_io_mgr.cpp:133
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: pcb_io_mgr.cpp:75
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:923
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Container for project specific data.
Definition: project.h:63
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:134
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:164
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:152
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
void SetBitmap(const wxBitmapBundle &aBmp)
void SetWidthPadding(int aPadding)
wxMenu * GetSplitButtonMenu()
void SetMinSize(const wxSize &aSize) override
void SetBitmap(const wxBitmapBundle &aBmp)
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
wxString wx_str() const
Definition: utf8.cpp:45
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:270
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:443
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:637
void Flush()
Build the HTML messages page.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:343
The common library.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
Definition: confirm.cpp:143
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:250
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:150
#define _(s)
Declaration of the eda_3d_viewer class.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71
Functions related to environment variables, including help functions.
@ FRAME_FOOTPRINT_VIEWER
Definition: frame_type.h:45
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
@ FRAME_CVPCB
Definition: frame_type.h:52
static const std::string KiCadFootprintLibPathExtension
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
@ COL_DESCR
@ COL_NICKNAME
@ COL_OPTIONS
@ COL_ENABLED
@ COL_URI
This file contains miscellaneous commonly used macros and functions.
@ MAIL_RELOAD_LIB
Definition: mail_type.h:56
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Constructs a versioned environment variable based on this KiCad major version.
Definition: env_vars.cpp:74
void InvokePcbLibTableEditor(KIWAY *aKiway, wxWindow *aCaller)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the glob...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:40
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:391
Container that describes file type info.
Definition: io_base.h:42
bool m_IsFile
Whether the library is a folder or a file.
Definition: io_base.h:46
wxString FileFilter() const
Definition: io_base.cpp:40
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
Container that describes file type info for the add a library options.
bool m_IsFile
Whether the library is a folder or a file.
PCB_IO_MGR::PCB_FILE_T m_Plugin
wxString m_Description
Description shown in the file picker dialog.
wxString m_FileFilter
Filter used for file pickers if m_IsFile is true.
wxString m_FolderSearchExtension
In case of folders it stands for extensions of files stored inside.
Definition of file extensions used in Kicad.