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
41#include <project.h>
42#include <env_vars.h>
44#include <panel_fp_lib_table.h>
45#include <lib_id.h>
46#include <fp_lib_table.h>
47#include <lib_table_lexer.h>
48#include <invoke_pcb_dialog.h>
49#include <bitmaps.h>
51#include <widgets/wx_grid.h>
53#include <confirm.h>
54#include <lib_table_grid.h>
56#include <pgm_base.h>
57#include <pcb_edit_frame.h>
58#include <env_paths.h>
63#include <kiway.h>
64#include <kiway_express.h>
67#include <pcbnew_id.h> // For ID_PCBNEW_END_LIST
69#include <paths.h>
70#include <macros.h>
71#include <project_pcb.h>
72
73// clang-format off
74
79{
80 wxString m_Description;
81 wxString m_FileFilter;
83 bool m_IsFile;
85};
86
87// clang-format on
88
93class LIBRARY_TRAVERSER : public wxDirTraverser
94{
95public:
96 LIBRARY_TRAVERSER( std::vector<std::string> aSearchExtensions, wxString aInitialDir ) :
97 m_searchExtensions( aSearchExtensions ), m_currentDir( aInitialDir )
98 {
99 }
100
101 virtual wxDirTraverseResult OnFile( const wxString& aFileName ) override
102 {
103 wxFileName file( aFileName );
104
105 for( const std::string& ext : m_searchExtensions )
106 {
107 if( file.GetExt().IsSameAs( ext, false ) )
108 m_foundDirs.insert( { m_currentDir, 1 } );
109 }
110
111 return wxDIR_CONTINUE;
112 }
113
114 virtual wxDirTraverseResult OnOpenError( const wxString& aOpenErrorName ) override
115 {
116 m_failedDirs.insert( { aOpenErrorName, 1 } );
117 return wxDIR_IGNORE;
118 }
119
121 {
122 return m_failedDirs.size() > 0;
123 }
124
125 virtual wxDirTraverseResult OnDir( const wxString& aDirName ) override
126 {
127 m_currentDir = aDirName;
128 return wxDIR_CONTINUE;
129 }
130
131 void GetPaths( wxArrayString& aPathArray )
132 {
133 for( std::pair<const wxString, int>& foundDirsPair : m_foundDirs )
134 aPathArray.Add( foundDirsPair.first );
135 }
136
137 void GetFailedPaths( wxArrayString& aPathArray )
138 {
139 for( std::pair<const wxString, int>& failedDirsPair : m_failedDirs )
140 aPathArray.Add( failedDirsPair.first );
141 }
142
143private:
144 std::vector<std::string> m_searchExtensions;
145 wxString m_currentDir;
146 std::unordered_map<wxString, int> m_foundDirs;
147 std::unordered_map<wxString, int> m_failedDirs;
148};
149
150
155{
156 friend class PANEL_FP_LIB_TABLE;
157 friend class FP_GRID_TRICKS;
158
159protected:
160 LIB_TABLE_ROW* at( size_t aIndex ) override { return &m_rows.at( aIndex ); }
161
162 size_t size() const override { return m_rows.size(); }
163
165 {
166 return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
167 }
168
169 LIB_TABLE_ROWS_ITER begin() override { return m_rows.begin(); }
170
172 {
173 return m_rows.insert( aIterator, aRow );
174 }
175
176 void push_back( LIB_TABLE_ROW* aRow ) override { m_rows.push_back( aRow ); }
177
179 {
180 return m_rows.erase( aFirst, aLast );
181 }
182
183public:
184
185 FP_LIB_TABLE_GRID( const FP_LIB_TABLE& aTableToEdit )
186 {
187 m_rows = aTableToEdit.m_rows;
188 }
189
190 void SetValue( int aRow, int aCol, const wxString &aValue ) override
191 {
192 wxCHECK( aRow < (int) size(), /* void */ );
193
194 LIB_TABLE_GRID::SetValue( aRow, aCol, aValue );
195
196 // If setting a filepath, attempt to auto-detect the format
197 if( aCol == COL_URI )
198 {
199 LIB_TABLE_ROW* row = at( (size_t) aRow );
200 wxString fullURI = row->GetFullURI( true );
201
203
204 if( pluginType == PCB_IO_MGR::FILE_TYPE_NONE )
205 pluginType = PCB_IO_MGR::KICAD_SEXP;
206
207 SetValue( aRow, COL_TYPE, PCB_IO_MGR::ShowType( pluginType ) );
208 }
209 }
210};
211
212
213
215{
216public:
218 LIB_TABLE_GRID_TRICKS( aGrid ), m_dialog( aParent )
219 { }
220
221protected:
223
224 void optionsEditor( int aRow ) override
225 {
226 FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
227
228 if( tbl->GetNumberRows() > aRow )
229 {
230 LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
231 const wxString& options = row->GetOptions();
232 wxString result = options;
233 STRING_UTF8_MAP choices;
234
237 pi->GetLibraryOptions( &choices );
238
239 DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result );
240 dlg.ShowModal();
241
242 if( options != result )
243 {
244 row->SetOptions( result );
245 m_grid->Refresh();
246 }
247 }
248 }
249
252 void paste_text( const wxString& cb_text ) override
253 {
254 FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
255 size_t ndx = cb_text.find( "(fp_lib_table" );
256
257 if( ndx != std::string::npos )
258 {
259 // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
260 // at column 0 regardless of current cursor column.
261
262 STRING_LINE_READER slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
263 LIB_TABLE_LEXER lexer( &slr );
264 FP_LIB_TABLE tmp_tbl;
265 bool parsed = true;
266
267 try
268 {
269 tmp_tbl.Parse( &lexer );
270 }
271 catch( PARSE_ERROR& pe )
272 {
273 DisplayError( m_dialog, pe.What() );
274 parsed = false;
275 }
276
277 if( parsed )
278 {
279 // make sure the table is big enough...
280 if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
281 tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
282
283 for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
284 tbl->m_rows.replace( i, tmp_tbl.At( i ).clone() );
285 }
286
287 m_grid->AutoSizeColumns( false );
288 }
289 else
290 {
291 // paste spreadsheet formatted text.
292 GRID_TRICKS::paste_text( cb_text );
293
294 m_grid->AutoSizeColumns( false );
295 }
296 }
297};
298
299
301 FP_LIB_TABLE* aGlobalTable, const wxString& aGlobalTblPath,
302 FP_LIB_TABLE* aProjectTable, const wxString& aProjectTblPath,
303 const wxString& aProjectBasePath ) :
304 PANEL_FP_LIB_TABLE_BASE( aParent ),
305 m_globalTable( aGlobalTable ),
306 m_projectTable( aProjectTable ),
307 m_project( aProject ),
308 m_projectBasePath( aProjectBasePath ),
309 m_parent( aParent )
310{
311 m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobalTable ), true );
312
313 // add Cut, Copy, and Paste to wxGrids
314 m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
315
317
318 wxArrayString choices;
319
320 for( auto& [fileType, desc] : m_supportedFpFiles )
321 choices.Add( PCB_IO_MGR::ShowType( fileType ) );
322
323
324 PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
325
326 if( cfg->m_lastFootprintLibDir.IsEmpty() )
328
330
331 auto autoSizeCol =
332 [&]( WX_GRID* aGrid, int aCol )
333 {
334 int prevWidth = aGrid->GetColSize( aCol );
335
336 aGrid->AutoSizeColumn( aCol, false );
337 aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
338 };
339
340 auto setupGrid =
341 [&]( WX_GRID* aGrid )
342 {
343 // Give a bit more room for wxChoice editors
344 aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
345
346 // add Cut, Copy, and Paste to wxGrids
347 aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
348
349 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
350
351 wxGridCellAttr* attr;
352
353 attr = new wxGridCellAttr;
354 attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
356 [this]( WX_GRID* grid, int row ) -> wxString
357 {
358 auto* libTable = static_cast<FP_LIB_TABLE_GRID*>( grid->GetTable() );
359 auto* tableRow = static_cast<FP_LIB_TABLE_ROW*>( libTable->at( row ) );
360 PCB_IO_MGR::PCB_FILE_T fileType = tableRow->GetFileType();
361 const IO_BASE::IO_FILE_DESC& pluginDesc = m_supportedFpFiles.at( fileType );
362
363 if( pluginDesc.m_IsFile )
364 return pluginDesc.FileFilter();
365 else
366 return wxEmptyString;
367 } ) );
368 aGrid->SetColAttr( COL_URI, attr );
369
370 attr = new wxGridCellAttr;
371 attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
372 aGrid->SetColAttr( COL_TYPE, attr );
373
374 attr = new wxGridCellAttr;
375 attr->SetRenderer( new wxGridCellBoolRenderer() );
376 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
377 aGrid->SetColAttr( COL_ENABLED, attr );
378
379 // No visibility control for footprint libraries yet; this feature is primarily
380 // useful for database libraries and it's only implemented for schematic symbols
381 // at the moment.
382 aGrid->HideCol( COL_VISIBLE );
383
384 // all but COL_OPTIONS, which is edited with Option Editor anyways.
385 autoSizeCol( aGrid, COL_NICKNAME );
386 autoSizeCol( aGrid, COL_TYPE );
387 autoSizeCol( aGrid, COL_URI );
388 autoSizeCol( aGrid, COL_DESCR );
389
390 // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
391 // a currentCell which is sometimes not highlighted.
392 if( aGrid->GetNumberRows() > 0 )
393 aGrid->SelectRow( 0 );
394 };
395
396 setupGrid( m_global_grid );
397
399
400 if( aProjectTable )
401 {
402 m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProjectTable ), true );
403 setupGrid( m_project_grid );
404 }
405 else
406 {
407 m_pageNdx = 0;
408 m_notebook->DeletePage( 1 );
409 m_project_grid = nullptr;
410 }
411
412 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
413 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
414
415 // select the last selected page
416 m_notebook->SetSelection( m_pageNdx );
418
419 // for ALT+A handling, we want the initial focus to be on the first selected grid.
421
422 // Configure button logos
423 m_append_button->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
424 m_delete_button->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
425 m_move_up_button->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
426 m_move_down_button->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
427 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
428
429 // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
430 // manually (for instance m_append_button)
431 Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
432 // their bitmaps
433 wxSize buttonSize = m_append_button->GetSize();
434
436 m_browseButton->SetMinSize( buttonSize );
437
438 // Populate the browse library options
439 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
440
441 auto joinExts = []( const std::vector<std::string>& aExts )
442 {
443 wxString joined;
444 for( const std::string& ext : aExts )
445 {
446 if( !joined.empty() )
447 joined << wxS( ", " );
448
449 joined << wxS( "*." ) << ext;
450 }
451
452 return joined;
453 };
454
455 for( auto& [type, desc] : m_supportedFpFiles )
456 {
457 wxString entryStr = PCB_IO_MGR::ShowType( type );
458
459 if( desc.m_IsFile && !desc.m_FileExtensions.empty() )
460 {
461 entryStr << wxString::Format( wxS( " (%s)" ),
462 joinExts( desc.m_FileExtensions ) );
463 }
464 else if( !desc.m_IsFile && !desc.m_ExtensionsInDir.empty() )
465 {
466 wxString midPart = wxString::Format( _( "folder with %s files" ),
467 joinExts( desc.m_ExtensionsInDir ) );
468
469 entryStr << wxString::Format( wxS( " (%s)" ), midPart );
470 }
471
472 browseMenu->Append( type, entryStr );
473
474 browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_FP_LIB_TABLE::browseLibrariesHandler,
475 this, type );
476 }
477
478 Layout();
479
480 // This is the button only press for the browse button instead of the menu
482}
483
484
486{
487 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
488 for( auto& [type, desc] : m_supportedFpFiles )
489 {
490 browseMenu->Unbind( wxEVT_COMMAND_MENU_SELECTED,
492 }
493 m_browseButton->Unbind( wxEVT_BUTTON, &PANEL_FP_LIB_TABLE::browseLibrariesHandler, this );
494
495 // Delete the GRID_TRICKS.
496 // Any additional event handlers should be popped before the window is deleted.
497 m_global_grid->PopEventHandler( true );
498
499 if( m_project_grid )
500 m_project_grid->PopEventHandler( true );
501
502 m_path_subs_grid->PopEventHandler( true );
503}
504
505
507{
508 for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() )
509 {
510 IO_RELEASER<PCB_IO> pi( plugin.m_createFunc() );
511
512 if( !pi )
513 continue;
514
515 if( const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc() )
516 m_supportedFpFiles.emplace( plugin.m_type, desc );
517 }
518}
519
520
522{
523 wxString msg;
524
525 for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
526 {
527 if( !model )
528 continue;
529
530 for( int r = 0; r < model->GetNumberRows(); )
531 {
532 wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
533 wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
534 unsigned illegalCh = 0;
535
536 if( !nick || !uri )
537 {
538 if( !nick && !uri )
539 msg = _( "A library table row nickname and path cells are empty." );
540 else if( !nick )
541 msg = _( "A library table row nickname cell is empty." );
542 else
543 msg = _( "A library table row path cell is empty." );
544
545 wxWindow* topLevelParent = wxGetTopLevelParent( this );
546
547 wxMessageDialog badCellDlg( topLevelParent, msg, _( "Invalid Row Definition" ),
548 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
549 badCellDlg.SetExtendedMessage( _( "Empty cells will result in all rows that are "
550 "invalid to be removed from the table." ) );
551 badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Remove Invalid Cells" ) ),
552 wxMessageDialog::ButtonLabel( _( "Cancel Table Update" ) ) );
553
554 if( badCellDlg.ShowModal() == wxID_NO )
555 return false;
556
557 // Delete the "empty" row, where empty means missing nick or uri.
558 // This also updates the UI which could be slow, but there should only be a few
559 // rows to delete, unless the user fell asleep on the Add Row
560 // button.
561 model->DeleteRows( r, 1 );
562 }
563 else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
564 {
565 msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ),
566 illegalCh,
567 nick );
568
569 // show the tabbed panel holding the grid we have flunked:
570 if( model != cur_model() )
571 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
572
573 m_cur_grid->MakeCellVisible( r, 0 );
574 m_cur_grid->SetGridCursor( r, 1 );
575
576 wxWindow* topLevelParent = wxGetTopLevelParent( this );
577
578 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
579 errdlg.ShowModal();
580 return false;
581 }
582 else
583 {
584 // set the trimmed values back into the table so they get saved to disk.
585 model->SetValue( r, COL_NICKNAME, nick );
586 model->SetValue( r, COL_URI, uri );
587
588 // Make sure to not save a hidden flag
589 model->SetValue( r, COL_VISIBLE, wxS( "1" ) );
590
591 ++r; // this row was OK.
592 }
593 }
594 }
595
596 // check for duplicate nickNames, separately in each table.
597 for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
598 {
599 if( !model )
600 continue;
601
602 for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
603 {
604 wxString nick1 = model->GetValue( r1, COL_NICKNAME );
605
606 for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
607 {
608 wxString nick2 = model->GetValue( r2, COL_NICKNAME );
609
610 if( nick1 == nick2 )
611 {
612 msg = wxString::Format( _( "Multiple libraries cannot share the same "
613 "nickname ('%s')." ),
614 nick1 );
615
616 // show the tabbed panel holding the grid we have flunked:
617 if( model != cur_model() )
618 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
619
620 // go to the lower of the two rows, it is technically the duplicate:
621 m_cur_grid->MakeCellVisible( r2, 0 );
622 m_cur_grid->SetGridCursor( r2, 1 );
623
624 wxWindow* topLevelParent = wxGetTopLevelParent( this );
625
626 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
627 errdlg.ShowModal();
628 return false;
629 }
630 }
631 }
632 }
633
634 return true;
635}
636
637
638void PANEL_FP_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
639{
640 m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
642}
643
644
645void PANEL_FP_LIB_TABLE::appendRowHandler( wxCommandEvent& event )
646{
648 return;
649
650 if( m_cur_grid->AppendRows( 1 ) )
651 {
652 int last_row = m_cur_grid->GetNumberRows() - 1;
653
654 // wx documentation is wrong, SetGridCursor does not make visible.
655 m_cur_grid->MakeCellVisible( last_row, COL_ENABLED );
656 m_cur_grid->SetGridCursor( last_row, COL_NICKNAME );
657 m_cur_grid->EnableCellEditControl( true );
658 m_cur_grid->ShowCellEditControl();
659 }
660}
661
662
663void PANEL_FP_LIB_TABLE::deleteRowHandler( wxCommandEvent& event )
664{
666 return;
667
668 int curRow = m_cur_grid->GetGridCursorRow();
669 int curCol = m_cur_grid->GetGridCursorCol();
670
671 // In a wxGrid, collect rows that have a selected cell, or are selected
672 // It is not so easy: it depends on the way the selection was made.
673 // Here, we collect rows selected by clicking on a row label, and rows that contain any
674 // previously-selected cells.
675 // If no candidate, just delete the row with the grid cursor.
676 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
677 wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
678 wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
679 wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
680
681 // Add all row having cell selected to list:
682 for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
683 selectedRows.Add( cells[ii].GetRow() );
684
685 // Handle block selection
686 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
687 {
688 for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
689 selectedRows.Add( i );
690 }
691
692 // Use the row having the grid cursor only if we have no candidate:
693 if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
694 selectedRows.Add( m_cur_grid->GetGridCursorRow() );
695
696 if( selectedRows.size() == 0 )
697 {
698 wxBell();
699 return;
700 }
701
702 std::sort( selectedRows.begin(), selectedRows.end() );
703
704 // Remove selected rows (note: a row can be stored more than once in list)
705 int last_row = -1;
706
707 // Needed to avoid a wxWidgets alert if the row to delete is the last row
708 // at least on wxMSW 3.2
709 m_cur_grid->ClearSelection();
710
711 for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
712 {
713 int row = selectedRows[ii];
714
715 if( row != last_row )
716 {
717 last_row = row;
718 m_cur_grid->DeleteRows( row, 1 );
719 }
720 }
721
722 if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
723 m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
724}
725
726
727void PANEL_FP_LIB_TABLE::moveUpHandler( wxCommandEvent& event )
728{
730 return;
731
733 int curRow = m_cur_grid->GetGridCursorRow();
734
735 // @todo: add multiple selection moves.
736 if( curRow >= 1 )
737 {
738 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
739 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
740
741 --curRow;
742 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
743
744 if( tbl->GetView() )
745 {
746 // Update the wxGrid
747 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
748 tbl->GetView()->ProcessTableMessage( msg );
749 }
750
751 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
752 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
753 }
754}
755
756
757void PANEL_FP_LIB_TABLE::moveDownHandler( wxCommandEvent& event )
758{
760 return;
761
763 int curRow = m_cur_grid->GetGridCursorRow();
764
765 // @todo: add multiple selection moves.
766 if( unsigned( curRow + 1 ) < tbl->m_rows.size() )
767 {
768 boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
769 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
770
771 ++curRow;
772 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
773
774 if( tbl->GetView() )
775 {
776 // Update the wxGrid
777 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
778 tbl->GetView()->ProcessTableMessage( msg );
779 }
780
781 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
782 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
783 }
784}
785
786
787// @todo refactor this function into single location shared with PANEL_SYM_LIB_TABLE
788void PANEL_FP_LIB_TABLE::onMigrateLibraries( wxCommandEvent& event )
789{
791 return;
792
793 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
794
795 if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
796 selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
797
798 wxArrayInt rowsToMigrate;
799 wxString kicadType = PCB_IO_MGR::ShowType( PCB_IO_MGR::KICAD_SEXP );
800 wxString msg;
801
802 for( int row : selectedRows )
803 {
804 if( m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
805 rowsToMigrate.push_back( row );
806 }
807
808 if( rowsToMigrate.size() <= 0 )
809 {
810 wxMessageBox( wxString::Format( _( "Select one or more rows containing libraries "
811 "to save as current KiCad format." ) ) );
812 return;
813 }
814 else
815 {
816 if( rowsToMigrate.size() == 1 )
817 {
818 msg.Printf( _( "Save '%s' as current KiCad format "
819 "and replace entry in table?" ),
820 m_cur_grid->GetCellValue( rowsToMigrate[0], COL_NICKNAME ) );
821 }
822 else
823 {
824 msg.Printf( _( "Save %d libraries as current KiCad format "
825 "and replace entries in table?" ),
826 (int) rowsToMigrate.size() );
827 }
828
829 if( !IsOK( m_parent, msg ) )
830 return;
831 }
832
833 for( int row : rowsToMigrate )
834 {
835 wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
836 wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
837 wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
838 wxFileName legacyLib( resolvedPath );
839
840 if( !legacyLib.Exists() )
841 {
842 msg.Printf( _( "Library '%s' not found." ), relPath );
843 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
844 continue;
845 }
846
847 wxFileName newLib( resolvedPath );
848 newLib.AppendDir( newLib.GetName() + "." + FILEEXT::KiCadFootprintLibPathExtension );
849 newLib.SetName( "" );
850 newLib.ClearExt();
851
852 if( newLib.DirExists() )
853 {
854 msg.Printf( _( "Folder '%s' already exists. Do you want overwrite any existing footprints?" ),
855 newLib.GetFullPath() );
856
857 switch( wxMessageBox( msg, _( "Migrate Library" ),
858 wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
859 {
860 case wxYES: break;
861 case wxNO: continue;
862 case wxCANCEL: return;
863 }
864 }
865
866 wxString options = m_cur_grid->GetCellValue( row, COL_OPTIONS );
867 std::unique_ptr<STRING_UTF8_MAP> props( LIB_TABLE::ParseOptions( options.ToStdString() ) );
868
869 if( convertLibrary( props.get(), legacyLib.GetFullPath(), newLib.GetFullPath() ) )
870 {
871 relPath = NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(),
872 m_project );
873
874 // Do not use the project path in the global library table. This will almost
875 // assuredly be wrong for a different project.
876 if( m_cur_grid == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) )
877 relPath = newLib.GetFullPath();
878
879 m_cur_grid->SetCellValue( row, COL_URI, relPath );
880 m_cur_grid->SetCellValue( row, COL_TYPE, kicadType );
881 }
882 else
883 {
884 msg.Printf( _( "Failed to save footprint library file '%s'." ), newLib.GetFullPath() );
885 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
886 }
887 }
888}
889
890
892 const wxString& aOldFilePath,
893 const wxString& aNewFilePath)
894{
896
897 if( oldFileType == PCB_IO_MGR::FILE_TYPE_NONE )
898 return false;
899
900
901 IO_RELEASER<PCB_IO> oldFilePI( PCB_IO_MGR::PluginFind( oldFileType ) );
903 wxArrayString fpNames;
904 wxFileName newFileName( aNewFilePath );
905
906 if( !newFileName.DirExists() && !wxFileName::Mkdir( aNewFilePath, wxS_DIR_DEFAULT ) )
907 return false;
908
909 try
910 {
911 bool bestEfforts = false; // throw on first error
912 oldFilePI->FootprintEnumerate( fpNames, aOldFilePath, bestEfforts, aOldFileProps );
913
914 for ( const wxString& fpName : fpNames )
915 {
916 std::unique_ptr<const FOOTPRINT> fp( oldFilePI->GetEnumeratedFootprint( aOldFilePath, fpName, aOldFileProps ) );
917 kicadPI->FootprintSave( aNewFilePath, fp.get() );
918 }
919
920 }
921 catch( ... )
922 {
923 return false;
924 }
925
926 return true;
927}
928
929
931{
933 return;
934
936
937 // We are bound both to the menu and button with this one handler
938 // So we must set the file type based on it
939 if( event.GetEventType() == wxEVT_BUTTON )
940 {
941 // Let's default to adding a kicad footprint file for just the footprint
943 }
944 else
945 {
946 fileType = static_cast<PCB_IO_MGR::PCB_FILE_T>( event.GetId() );
947 }
948
950 {
951 wxLogWarning( wxT( "File type selection event received but could not find the file type "
952 "in the table" ) );
953 return;
954 }
955
956 const IO_BASE::IO_FILE_DESC& fileDesc = m_supportedFpFiles.at( fileType );
957 PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
958
959 wxString title = wxString::Format( _( "Select %s Library" ), PCB_IO_MGR::ShowType( fileType ) );
960 wxString openDir = cfg->m_lastFootprintLibDir;
961
963 openDir = m_lastProjectLibDir;
964
965 wxArrayString files;
966
967 wxWindow* topLevelParent = wxGetTopLevelParent( this );
968
969 if( fileDesc.m_IsFile )
970 {
971 wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
972 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
973
974 int result = dlg.ShowModal();
975
976 if( result == wxID_CANCEL )
977 return;
978
979 dlg.GetPaths( files );
980
982 cfg->m_lastFootprintLibDir = dlg.GetDirectory();
983 else
984 m_lastProjectLibDir = dlg.GetDirectory();
985 }
986 else
987 {
988 wxDirDialog dlg( topLevelParent, title, openDir,
989 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
990
991 int result = dlg.ShowModal();
992
993 if( result == wxID_CANCEL )
994 return;
995
996 dlg.GetPaths( files );
997
998 if( !files.IsEmpty() )
999 {
1000 wxFileName first( files.front() );
1001
1002 if( m_cur_grid == m_global_grid )
1003 cfg->m_lastFootprintLibDir = first.GetPath();
1004 else
1005 m_lastProjectLibDir = first.GetPath();
1006 }
1007 }
1008
1009 // Drop the last directory if the path is a .pretty folder
1011 cfg->m_lastFootprintLibDir = cfg->m_lastFootprintLibDir.BeforeLast( wxFileName::GetPathSeparator() );
1012
1013 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1014 bool addDuplicates = false;
1015 bool applyToAll = false;
1016 wxString warning = _( "Warning: Duplicate Nicknames" );
1017 wxString msg = _( "A library nicknamed '%s' already exists." );
1018 wxString detailedMsg = _( "One of the nicknames will need to be changed after "
1019 "adding this library." );
1020
1021 for( const wxString& filePath : files )
1022 {
1023 wxFileName fn( filePath );
1024 wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
1025 bool doAdd = true;
1026
1028 && fn.GetExt() != FILEEXT::KiCadFootprintLibPathExtension )
1029 nickname = LIB_ID::FixIllegalChars( fn.GetFullName(), true ).wx_str();
1030
1031 if( cur_model()->ContainsNickname( nickname ) )
1032 {
1033 if( !applyToAll )
1034 {
1035 // The cancel button adds the library to the table anyway
1036 addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning,
1037 wxString::Format( msg, nickname ),
1038 detailedMsg, _( "Skip" ), _( "Add Anyway" ),
1039 &applyToAll ) == wxID_CANCEL;
1040 }
1041
1042 doAdd = addDuplicates;
1043 }
1044
1045 if( doAdd && m_cur_grid->AppendRows( 1 ) )
1046 {
1047 int last_row = m_cur_grid->GetNumberRows() - 1;
1048
1049 m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
1050
1051 m_cur_grid->SetCellValue( last_row, COL_TYPE, PCB_IO_MGR::ShowType( fileType ) );
1052
1053 // try to use path normalized to an environmental variable or project path
1054 wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
1055
1056 // Do not use the project path in the global library table. This will almost
1057 // assuredly be wrong for a different project.
1058 if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
1059 path = fn.GetFullPath();
1060
1061 m_cur_grid->SetCellValue( last_row, COL_URI, path );
1062 }
1063 }
1064
1065 if( !files.IsEmpty() )
1066 {
1067 int new_row = m_cur_grid->GetNumberRows() - 1;
1068 m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
1069 m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
1070 }
1071}
1072
1073
1075{
1076 // Account for scroll bars
1077 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
1078
1079 m_path_subs_grid->AutoSizeColumn( 0 );
1080 m_path_subs_grid->SetColSize( 0, std::max( 72, m_path_subs_grid->GetColSize( 0 ) ) );
1081 m_path_subs_grid->SetColSize( 1, std::max( 120, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
1082}
1083
1084
1085void PANEL_FP_LIB_TABLE::onSizeGrid( wxSizeEvent& event )
1086{
1087 adjustPathSubsGridColumns( event.GetSize().GetX() );
1088
1089 event.Skip();
1090}
1091
1092
1094{
1096 return false;
1097
1098 if( verifyTables() )
1099 {
1100 if( *global_model() != *m_globalTable )
1101 {
1103
1106 }
1107
1109 {
1111
1114 }
1115
1116 return true;
1117 }
1118
1119 return false;
1120}
1121
1122
1126{
1127 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1128 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1129
1130 std::set< wxString > unique;
1131
1132 // clear the table
1134
1135 for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
1136 {
1137 if( !tbl )
1138 continue;
1139
1140 for( int row = 0; row < tbl->GetNumberRows(); ++row )
1141 {
1142 wxString uri = tbl->GetValue( row, COL_URI );
1143
1144 while( re.Matches( uri ) )
1145 {
1146 wxString envvar = re.GetMatch( uri, 2 );
1147
1148 // if not ${...} form then must be $(...)
1149 if( envvar.IsEmpty() )
1150 envvar = re.GetMatch( uri, 4 );
1151
1152 // ignore duplicates
1153 unique.insert( envvar );
1154
1155 // delete the last match and search again
1156 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1157 }
1158 }
1159 }
1160
1161 // Make sure this special environment variable shows up even if it was
1162 // not used yet. It is automatically set by KiCad to the directory holding
1163 // the current project.
1164 unique.insert( PROJECT_VAR_NAME );
1165 unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
1166
1167 // This special environment variable is used to locate 3d shapes
1168 unique.insert( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
1169
1170 for( const wxString& evName : unique )
1171 {
1172 int row = m_path_subs_grid->GetNumberRows();
1173 m_path_subs_grid->AppendRows( 1 );
1174
1175 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1176 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1177
1178 wxString evValue;
1179 wxGetEnv( evName, &evValue );
1180 m_path_subs_grid->SetCellValue( row, 1, evValue );
1181 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1182 }
1183
1184 // No combobox editors here, but it looks better if its consistent with the other
1185 // grids in the dialog.
1186 m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1187
1188 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1189}
1190
1191//-----</event handlers>---------------------------------
1192
1193
1194
1196
1197
1198void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller )
1199{
1200 FP_LIB_TABLE* globalTable = &GFootprintTable;
1201 wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
1202 FP_LIB_TABLE* projectTable = PROJECT_PCB::PcbFootprintLibs( &aKiway->Prj() );
1203 wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
1204 wxString msg;
1205
1206 DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
1207 dlg.SetKiway( &dlg, aKiway );
1208
1209 if( aKiway->Prj().IsNullProject() )
1210 projectTable = nullptr;
1211
1212 dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1213 projectTable, projectTablePath,
1214 aKiway->Prj().GetProjectPath() ) );
1215
1216 if( dlg.ShowModal() == wxID_CANCEL )
1217 return;
1218
1219 if( dlg.m_GlobalTableChanged )
1220 {
1221 try
1222 {
1223 globalTable->Save( globalTablePath );
1224 }
1225 catch( const IO_ERROR& ioe )
1226 {
1227 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1228 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1229 }
1230 }
1231
1232 if( projectTable && dlg.m_ProjectTableChanged )
1233 {
1234 try
1235 {
1236 projectTable->Save( projectTablePath );
1237 }
1238 catch( const IO_ERROR& ioe )
1239 {
1240 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1241 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1242 }
1243 }
1244
1245 std::string payload = "";
1248 aKiway->ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload );
1249}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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:97
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
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
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:553
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.
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.
void Clear()
Delete all 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.
static STRING_UTF8_MAP * ParseOptions(const std::string &aOptionsList)
Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
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
FP_LIB_TABLE_GRID * global_model() const
static size_t m_pageNdx
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 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)
bool convertLibrary(STRING_UTF8_MAP *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath)
DIALOG_EDIT_LIBRARY_TABLES * m_parent
void OnUpdateUI(wxUpdateUIEvent &event) override
void appendRowHandler(wxCommandEvent &event) override
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:109
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:65
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:90
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 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:132
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: pcb_io_mgr.cpp:74
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:62
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:165
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:153
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
A name/value tuple with unique names and optional values.
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:156
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:147
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:462
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:334
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:253
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:169
#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
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...
see class PGM_BASE
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:39
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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:39
bool m_IsFile
Whether the library is a folder or a file.
Definition: io_base.h:43
wxString FileFilter() const
Definition: io_base.cpp:38
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.