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