KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_design_block_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-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25/* TODO:
26
27*) After any change to uri, reparse the environment variables.
28
29*/
30
31
32#include <set>
33#include <wx/dir.h>
34#include <wx/log.h>
35#include <wx/regex.h>
36#include <wx/grid.h>
37#include <wx/dirdlg.h>
38#include <wx/filedlg.h>
39#include <wx/msgdlg.h>
40
41#include <common.h>
42#include <project.h>
43#include <env_vars.h>
44#include <lib_id.h>
46#include <lib_table_lexer.h>
47#include <bitmaps.h>
49#include <widgets/wx_grid.h>
51#include <confirm.h>
52#include <lib_table_grid.h>
54#include <pgm_base.h>
55#include <env_paths.h>
59#include <kiway.h>
60#include <kiway_express.h>
65#include <paths.h>
66#include <macros.h>
67
68// clang-format off
69
74{
75 wxString m_Description;
76 wxString m_FileFilter;
78 bool m_IsFile;
80};
81
82// clang-format on
83
88class LIBRARY_TRAVERSER : public wxDirTraverser
89{
90public:
91 LIBRARY_TRAVERSER( std::vector<std::string> aSearchExtensions, wxString aInitialDir ) :
92 m_searchExtensions( aSearchExtensions ), m_currentDir( aInitialDir )
93 {
94 }
95
96 virtual wxDirTraverseResult OnFile( const wxString& aFileName ) override
97 {
98 wxFileName file( aFileName );
99
100 for( const std::string& ext : m_searchExtensions )
101 {
102 if( file.GetExt().IsSameAs( ext, false ) )
103 m_foundDirs.insert( { m_currentDir, 1 } );
104 }
105
106 return wxDIR_CONTINUE;
107 }
108
109 virtual wxDirTraverseResult OnOpenError( const wxString& aOpenErrorName ) override
110 {
111 m_failedDirs.insert( { aOpenErrorName, 1 } );
112 return wxDIR_IGNORE;
113 }
114
115 bool HasDirectoryOpenFailures() { return m_failedDirs.size() > 0; }
116
117 virtual wxDirTraverseResult OnDir( const wxString& aDirName ) override
118 {
119 m_currentDir = aDirName;
120 return wxDIR_CONTINUE;
121 }
122
123 void GetPaths( wxArrayString& aPathArray )
124 {
125 for( std::pair<const wxString, int>& foundDirsPair : m_foundDirs )
126 aPathArray.Add( foundDirsPair.first );
127 }
128
129 void GetFailedPaths( wxArrayString& aPathArray )
130 {
131 for( std::pair<const wxString, int>& failedDirsPair : m_failedDirs )
132 aPathArray.Add( failedDirsPair.first );
133 }
134
135private:
136 std::vector<std::string> m_searchExtensions;
137 wxString m_currentDir;
138 std::unordered_map<wxString, int> m_foundDirs;
139 std::unordered_map<wxString, int> m_failedDirs;
140};
141
142
147{
150
151protected:
152 LIB_TABLE_ROW* at( size_t aIndex ) override { return &m_rows.at( aIndex ); }
153
154 size_t size() const override { return m_rows.size(); }
155
157 {
158 return dynamic_cast<LIB_TABLE_ROW*>( new DESIGN_BLOCK_LIB_TABLE_ROW );
159 }
160
161 LIB_TABLE_ROWS_ITER begin() override { return m_rows.begin(); }
162
164 {
165 return m_rows.insert( aIterator, aRow );
166 }
167
168 void push_back( LIB_TABLE_ROW* aRow ) override { m_rows.push_back( aRow ); }
169
171 {
172 return m_rows.erase( aFirst, aLast );
173 }
174
175public:
177 {
178 m_rows = aTableToEdit.m_rows;
179 }
180
181 void SetValue( int aRow, int aCol, const wxString& aValue ) override
182 {
183 wxCHECK( aRow < (int) size(), /* void */ );
184
185 LIB_TABLE_GRID::SetValue( aRow, aCol, aValue );
186
187 // If setting a filepath, attempt to auto-detect the format
188 if( aCol == COL_URI )
189 {
190 LIB_TABLE_ROW* row = at( (size_t) aRow );
191 wxString fullURI = row->GetFullURI( true );
192
195
196 if( pluginType == DESIGN_BLOCK_IO_MGR::FILE_TYPE_NONE )
198
199 SetValue( aRow, COL_TYPE, DESIGN_BLOCK_IO_MGR::ShowType( pluginType ) );
200 }
201 }
202};
203
204
206{
207public:
209 LIB_TABLE_GRID_TRICKS( aGrid ), m_dialog( aParent )
210 {
211 }
212
213protected:
215
216 void optionsEditor( int aRow ) override
217 {
219
220 if( tbl->GetNumberRows() > aRow )
221 {
222 LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
223 const wxString& options = row->GetOptions();
224 wxString result = options;
225 std::map<std::string, UTF8> choices;
226
230 pi->GetLibraryOptions( &choices );
231
232 DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result );
233 dlg.ShowModal();
234
235 if( options != result )
236 {
237 row->SetOptions( result );
238 m_grid->Refresh();
239 }
240 }
241 }
242
245 void paste_text( const wxString& cb_text ) override
246 {
248 size_t ndx = cb_text.find( "(design_block_lib_table" );
249
250 if( ndx != std::string::npos )
251 {
252 // paste the DESIGN_BLOCK_LIB_TABLE_ROWs of s-expression (design_block_lib_table), starting
253 // at column 0 regardless of current cursor column.
254
255 STRING_LINE_READER slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
256 LIB_TABLE_LEXER lexer( &slr );
258 bool parsed = true;
259
260 try
261 {
262 tmp_tbl.Parse( &lexer );
263 }
264 catch( PARSE_ERROR& pe )
265 {
266 DisplayError( m_dialog, pe.What() );
267 parsed = false;
268 }
269
270 if( parsed )
271 {
272 // make sure the table is big enough...
273 if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
274 tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
275
276 for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
277 tbl->m_rows.replace( i, tmp_tbl.At( i ).clone() );
278 }
279
280 m_grid->AutoSizeColumns( false );
281 }
282 else
283 {
284 // paste spreadsheet formatted text.
285 GRID_TRICKS::paste_text( cb_text );
286
287 m_grid->AutoSizeColumns( false );
288 }
289 }
290};
291
292
294 PROJECT* aProject,
295 DESIGN_BLOCK_LIB_TABLE* aGlobalTable,
296 const wxString& aGlobalTblPath,
297 DESIGN_BLOCK_LIB_TABLE* aProjectTable,
298 const wxString& aProjectTblPath,
299 const wxString& aProjectBasePath ) :
301 m_globalTable( aGlobalTable ), m_projectTable( aProjectTable ), m_project( aProject ),
302 m_projectBasePath( aProjectBasePath ), m_parent( aParent )
303{
304 m_global_grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID( *aGlobalTable ), true );
305
306 // add Cut, Copy, and Paste to wxGrids
307 m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
308
310
311 wxArrayString choices;
312
313 for( auto& [fileType, desc] : m_supportedDesignBlockFiles )
314 choices.Add( DESIGN_BLOCK_IO_MGR::ShowType( fileType ) );
315
316
318
319 if( cfg->m_lastDesignBlockLibDir.IsEmpty() )
321
323
324 auto autoSizeCol = [&]( WX_GRID* aGrid, int aCol )
325 {
326 int prevWidth = aGrid->GetColSize( aCol );
327
328 aGrid->AutoSizeColumn( aCol, false );
329 aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
330 };
331
332 auto setupGrid = [&]( WX_GRID* aGrid )
333 {
334 // Give a bit more room for wxChoice editors
335 aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
336
337 // add Cut, Copy, and Paste to wxGrids
338 aGrid->PushEventHandler( new DESIGN_BLOCK_GRID_TRICKS( m_parent, aGrid ) );
339
340 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
341
342 wxGridCellAttr* attr;
343
344 attr = new wxGridCellAttr;
345 attr->SetEditor( new GRID_CELL_PATH_EDITOR(
347 [this]( WX_GRID* grid, int row ) -> wxString
348 {
349 auto* libTable = static_cast<DESIGN_BLOCK_LIB_TABLE_GRID*>( grid->GetTable() );
350 auto* tableRow =
351 static_cast<DESIGN_BLOCK_LIB_TABLE_ROW*>( libTable->at( row ) );
352 DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T fileType = tableRow->GetFileType();
353 const IO_BASE::IO_FILE_DESC& pluginDesc =
355
356 if( pluginDesc.m_IsFile )
357 return pluginDesc.FileFilter();
358 else
359 return wxEmptyString;
360 } ) );
361 aGrid->SetColAttr( COL_URI, attr );
362
363 attr = new wxGridCellAttr;
364 attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
365 aGrid->SetColAttr( COL_TYPE, attr );
366
367 attr = new wxGridCellAttr;
368 attr->SetRenderer( new wxGridCellBoolRenderer() );
369 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
370 aGrid->SetColAttr( COL_ENABLED, attr );
371
372 // No visibility control for design block libraries yet; this feature is primarily
373 // useful for database libraries and it's only implemented for schematic symbols
374 // at the moment.
375 aGrid->HideCol( COL_VISIBLE );
376
377 // all but COL_OPTIONS, which is edited with Option Editor anyways.
378 autoSizeCol( aGrid, COL_NICKNAME );
379 autoSizeCol( aGrid, COL_TYPE );
380 autoSizeCol( aGrid, COL_URI );
381 autoSizeCol( aGrid, COL_DESCR );
382
383 // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
384 // a currentCell which is sometimes not highlighted.
385 if( aGrid->GetNumberRows() > 0 )
386 aGrid->SelectRow( 0 );
387 };
388
389 setupGrid( m_global_grid );
390
392
393 if( aProjectTable )
394 {
395 m_project_grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID( *aProjectTable ), true );
396 setupGrid( m_project_grid );
397 }
398 else
399 {
400 m_pageNdx = 0;
401 m_notebook->DeletePage( 1 );
402 m_project_grid = nullptr;
403 }
404
405 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
406 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
407
408 // select the last selected page
409 m_notebook->SetSelection( m_pageNdx );
411
412 // for ALT+A handling, we want the initial focus to be on the first selected grid.
414
415 // Configure button logos
416 m_append_button->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
417 m_delete_button->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
418 m_move_up_button->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
419 m_move_down_button->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
420 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
421
422 // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
423 // manually (for instance m_append_button)
424 Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
425 // their bitmaps
426 wxSize buttonSize = m_append_button->GetSize();
427
429 m_browseButton->SetMinSize( buttonSize );
430
431 // Populate the browse library options
432 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
433
434 auto joinExts = []( const std::vector<std::string>& aExts )
435 {
436 wxString joined;
437 for( const std::string& ext : aExts )
438 {
439 if( !joined.empty() )
440 joined << wxS( ", " );
441
442 joined << wxS( "*." ) << ext;
443 }
444
445 return joined;
446 };
447
448 for( auto& [type, desc] : m_supportedDesignBlockFiles )
449 {
450 wxString entryStr = DESIGN_BLOCK_IO_MGR::ShowType( type );
451
452 if( desc.m_IsFile && !desc.m_FileExtensions.empty() )
453 {
454 entryStr << wxString::Format( wxS( " (%s)" ), joinExts( desc.m_FileExtensions ) );
455 }
456 else if( !desc.m_IsFile && !desc.m_ExtensionsInDir.empty() )
457 {
458 wxString midPart = wxString::Format( _( "folder with %s files" ),
459 joinExts( desc.m_ExtensionsInDir ) );
460
461 entryStr << wxString::Format( wxS( " (%s)" ), midPart );
462 }
463
464 browseMenu->Append( type, entryStr );
465
466 browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED,
468 }
469
470 Layout();
471
472 // This is the button only press for the browse button instead of the menu
474 this );
475}
476
477
479{
480 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
481 for( auto& [type, desc] : m_supportedDesignBlockFiles )
482 {
483 browseMenu->Unbind( wxEVT_COMMAND_MENU_SELECTED,
485 }
487 this );
488
489 // Delete the GRID_TRICKS.
490 // Any additional event handlers should be popped before the window is deleted.
491 m_global_grid->PopEventHandler( true );
492
493 if( m_project_grid )
494 m_project_grid->PopEventHandler( true );
495
496 m_path_subs_grid->PopEventHandler( true );
497}
498
499
501{
504 {
506
507 if( !pi )
508 continue;
509
510 if( const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc() )
511 m_supportedDesignBlockFiles.emplace( type, desc );
512 }
513}
514
515
517{
518 wxString msg;
519
521 {
522 if( !model )
523 continue;
524
525 for( int r = 0; r < model->GetNumberRows(); )
526 {
527 wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
528 wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
529 unsigned illegalCh = 0;
530
531 if( !nick || !uri )
532 {
533 if( !nick && !uri )
534 msg = _( "A library table row nickname and path cells are empty." );
535 else if( !nick )
536 msg = _( "A library table row nickname cell is empty." );
537 else
538 msg = _( "A library table row path cell is empty." );
539
540 wxWindow* topLevelParent = wxGetTopLevelParent( this );
541
542 wxMessageDialog badCellDlg( topLevelParent, msg, _( "Invalid Row Definition" ),
543 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
544 badCellDlg.SetExtendedMessage( _( "Empty cells will result in all rows that are "
545 "invalid to be removed from the table." ) );
546 badCellDlg.SetYesNoLabels(
547 wxMessageDialog::ButtonLabel( _( "Remove Invalid Cells" ) ),
548 wxMessageDialog::ButtonLabel( _( "Cancel Table Update" ) ) );
549
550 if( badCellDlg.ShowModal() == wxID_NO )
551 return false;
552
553 // Delete the "empty" row, where empty means missing nick or uri.
554 // This also updates the UI which could be slow, but there should only be a few
555 // rows to delete, unless the user fell asleep on the Add Row
556 // button.
557 model->DeleteRows( r, 1 );
558 }
559 else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
560 {
561 msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ), illegalCh,
562 nick );
563
564 // show the tabbed panel holding the grid we have flunked:
565 if( model != cur_model() )
566 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
567
568 m_cur_grid->MakeCellVisible( r, 0 );
569 m_cur_grid->SetGridCursor( r, 1 );
570
571 wxWindow* topLevelParent = wxGetTopLevelParent( this );
572
573 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
574 errdlg.ShowModal();
575 return false;
576 }
577 else
578 {
579 // set the trimmed values back into the table so they get saved to disk.
580 model->SetValue( r, COL_NICKNAME, nick );
581 model->SetValue( r, COL_URI, uri );
582
583 // Make sure to not save a hidden flag
584 model->SetValue( r, COL_VISIBLE, wxS( "1" ) );
585
586 ++r; // this row was OK.
587 }
588 }
589 }
590
591 // check for duplicate nickNames, separately in each table.
593 {
594 if( !model )
595 continue;
596
597 for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
598 {
599 wxString nick1 = model->GetValue( r1, COL_NICKNAME );
600
601 for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
602 {
603 wxString nick2 = model->GetValue( r2, COL_NICKNAME );
604
605 if( nick1 == nick2 )
606 {
607 msg = wxString::Format( _( "Multiple libraries cannot share the same "
608 "nickname ('%s')." ),
609 nick1 );
610
611 // show the tabbed panel holding the grid we have flunked:
612 if( model != cur_model() )
613 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
614
615 // go to the lower of the two rows, it is technically the duplicate:
616 m_cur_grid->MakeCellVisible( r2, 0 );
617 m_cur_grid->SetGridCursor( r2, 1 );
618
619 wxWindow* topLevelParent = wxGetTopLevelParent( this );
620
621 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
622 errdlg.ShowModal();
623 return false;
624 }
625 }
626 }
627 }
628
629 return true;
630}
631
632
633void PANEL_DESIGN_BLOCK_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
634{
635 m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
637}
638
639
641{
643 return;
644
645 if( m_cur_grid->AppendRows( 1 ) )
646 {
647 int last_row = m_cur_grid->GetNumberRows() - 1;
648
649 // wx documentation is wrong, SetGridCursor does not make visible.
650 m_cur_grid->MakeCellVisible( last_row, COL_ENABLED );
651 m_cur_grid->SetGridCursor( last_row, COL_NICKNAME );
652 m_cur_grid->EnableCellEditControl( true );
653 m_cur_grid->ShowCellEditControl();
654 }
655}
656
657
659{
661 return;
662
663 wxGridUpdateLocker noUpdates( m_cur_grid );
664
665 int curRow = m_cur_grid->GetGridCursorRow();
666 int curCol = m_cur_grid->GetGridCursorCol();
667
668 // In a wxGrid, collect rows that have a selected cell, or are selected
669 // It is not so easy: it depends on the way the selection was made.
670 // Here, we collect rows selected by clicking on a row label, and rows that contain any
671 // previously-selected cells.
672 // If no candidate, just delete the row with the grid cursor.
673 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
674 wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
675 wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
676 wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
677
678 // Add all row having cell selected to list:
679 for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
680 selectedRows.Add( cells[ii].GetRow() );
681
682 // Handle block selection
683 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
684 {
685 for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
686 selectedRows.Add( i );
687 }
688
689 // Use the row having the grid cursor only if we have no candidate:
690 if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
691 selectedRows.Add( m_cur_grid->GetGridCursorRow() );
692
693 if( selectedRows.size() == 0 )
694 {
695 wxBell();
696 return;
697 }
698
699 std::sort( selectedRows.begin(), selectedRows.end() );
700
701 // Remove selected rows (note: a row can be stored more than once in list)
702 int last_row = -1;
703
704 // Needed to avoid a wxWidgets alert if the row to delete is the last row
705 // at least on wxMSW 3.2
706 m_cur_grid->ClearSelection();
707
708 for( int ii = selectedRows.GetCount() - 1; ii >= 0; ii-- )
709 {
710 int row = selectedRows[ii];
711
712 if( row != last_row )
713 {
714 last_row = row;
715 m_cur_grid->DeleteRows( row, 1 );
716 }
717 }
718
719 if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
720 m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
721}
722
723
725{
727 return;
728
730 int curRow = m_cur_grid->GetGridCursorRow();
731
732 // @todo: add multiple selection moves.
733 if( curRow >= 1 )
734 {
735 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
736 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
737
738 --curRow;
739 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
740
741 if( tbl->GetView() )
742 {
743 // Update the wxGrid
744 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
745 tbl->GetView()->ProcessTableMessage( msg );
746 }
747
748 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
749 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
750 }
751}
752
753
755{
757 return;
758
760 int curRow = m_cur_grid->GetGridCursorRow();
761
762 // @todo: add multiple selection moves.
763 if( unsigned( curRow + 1 ) < tbl->m_rows.size() )
764 {
765 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
766 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
767
768 ++curRow;
769 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
770
771 if( tbl->GetView() )
772 {
773 // Update the wxGrid
774 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
775 tbl->GetView()->ProcessTableMessage( msg );
776 }
777
778 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
779 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
780 }
781}
782
783
784// @todo refactor this function into single location shared with PANEL_SYM_LIB_TABLE
786{
788 return;
789
790 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
791
792 if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
793 selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
794
795 wxArrayInt rowsToMigrate;
797 wxString msg;
798
799 for( int row : selectedRows )
800 {
801 if( m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
802 rowsToMigrate.push_back( row );
803 }
804
805 if( rowsToMigrate.size() <= 0 )
806 {
807 wxMessageBox( wxString::Format( _( "Select one or more rows containing libraries "
808 "to save as current KiCad format." ) ) );
809 return;
810 }
811 else
812 {
813 if( rowsToMigrate.size() == 1 )
814 {
815 msg.Printf( _( "Save '%s' as current KiCad format "
816 "and replace entry in table?" ),
817 m_cur_grid->GetCellValue( rowsToMigrate[0], COL_NICKNAME ) );
818 }
819 else
820 {
821 msg.Printf( _( "Save %d libraries as current KiCad format "
822 "and replace entries in table?" ),
823 (int) rowsToMigrate.size() );
824 }
825
826 if( !IsOK( m_parent, msg ) )
827 return;
828 }
829
830 for( int row : rowsToMigrate )
831 {
832 wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
833 wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
834 wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
835 wxFileName legacyLib( resolvedPath );
836
837 if( !legacyLib.Exists() )
838 {
839 msg.Printf( _( "Library '%s' not found." ), relPath );
840 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
841 continue;
842 }
843
844 wxFileName newLib( resolvedPath );
845 newLib.AppendDir( newLib.GetName() + "." + FILEEXT::KiCadDesignBlockLibPathExtension );
846 newLib.SetName( "" );
847 newLib.ClearExt();
848
849 if( newLib.DirExists() )
850 {
851 msg.Printf( _( "Folder '%s' already exists. Do you want overwrite any existing design "
852 "blocks?" ),
853 newLib.GetFullPath() );
854
855 switch( wxMessageBox( msg, _( "Migrate Library" ),
856 wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
857 {
858 case wxYES: break;
859 case wxNO: continue;
860 case wxCANCEL: return;
861 }
862 }
863
864 wxString options = m_cur_grid->GetCellValue( row, COL_OPTIONS );
865 std::unique_ptr<std::map<std::string, UTF8>> props(
866 LIB_TABLE::ParseOptions( options.ToStdString() ) );
867
868 if( DESIGN_BLOCK_IO_MGR::ConvertLibrary( props.get(), legacyLib.GetFullPath(),
869 newLib.GetFullPath() ) )
870 {
871 relPath =
872 NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(), 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 design block library file '%s'." ),
885 newLib.GetFullPath() );
886 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
887 }
888 }
889}
890
891
893{
895 return;
896
898
899 // We are bound both to the menu and button with this one handler
900 // So we must set the file type based on it
901 if( event.GetEventType() == wxEVT_BUTTON )
902 {
903 // Let's default to adding a kicad design block file for just the design block
905 }
906 else
907 {
908 fileType = static_cast<DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T>( event.GetId() );
909 }
910
912 {
913 wxLogWarning( wxT( "File type selection event received but could not find the file type "
914 "in the table" ) );
915 return;
916 }
917
920
921 wxString title =
922 wxString::Format( _( "Select %s Library" ), DESIGN_BLOCK_IO_MGR::ShowType( fileType ) );
923 wxString openDir = cfg->m_lastDesignBlockLibDir;
924
926 openDir = m_lastProjectLibDir;
927
928 wxArrayString files;
929
930 wxWindow* topLevelParent = wxGetTopLevelParent( this );
931
932 if( fileDesc.m_IsFile )
933 {
934 wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
935 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
936
937 int result = dlg.ShowModal();
938
939 if( result == wxID_CANCEL )
940 return;
941
942 dlg.GetPaths( files );
943
945 cfg->m_lastDesignBlockLibDir = dlg.GetDirectory();
946 else
947 m_lastProjectLibDir = dlg.GetDirectory();
948 }
949 else
950 {
951 wxDirDialog dlg( topLevelParent, title, openDir,
952 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
953
954 int result = dlg.ShowModal();
955
956 if( result == wxID_CANCEL )
957 return;
958
959 dlg.GetPaths( files );
960
961 if( !files.IsEmpty() )
962 {
963 wxFileName first( files.front() );
964
966 cfg->m_lastDesignBlockLibDir = first.GetPath();
967 else
968 m_lastProjectLibDir = first.GetPath();
969 }
970 }
971
972 // Drop the last directory if the path is a .pretty folder
975 cfg->m_lastDesignBlockLibDir.BeforeLast( wxFileName::GetPathSeparator() );
976
977 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
978 bool addDuplicates = false;
979 bool applyToAll = false;
980 wxString warning = _( "Warning: Duplicate Nicknames" );
981 wxString msg = _( "A library nicknamed '%s' already exists." );
982 wxString detailedMsg = _( "One of the nicknames will need to be changed after "
983 "adding this library." );
984
985 for( const wxString& filePath : files )
986 {
987 wxFileName fn( filePath );
988 wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
989 bool doAdd = true;
990
993 nickname = LIB_ID::FixIllegalChars( fn.GetFullName(), true ).wx_str();
994
995 if( cur_model()->ContainsNickname( nickname ) )
996 {
997 if( !applyToAll )
998 {
999 // The cancel button adds the library to the table anyway
1000 addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning,
1001 wxString::Format( msg, nickname ), detailedMsg,
1002 _( "Skip" ), _( "Add Anyway" ), &applyToAll )
1003 == wxID_CANCEL;
1004 }
1005
1006 doAdd = addDuplicates;
1007 }
1008
1009 if( doAdd && m_cur_grid->AppendRows( 1 ) )
1010 {
1011 int last_row = m_cur_grid->GetNumberRows() - 1;
1012
1013 m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
1014
1015 m_cur_grid->SetCellValue( last_row, COL_TYPE,
1017
1018 // try to use path normalized to an environmental variable or project path
1019 wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
1020
1021 // Do not use the project path in the global library table. This will almost
1022 // assuredly be wrong for a different project.
1023 if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
1024 path = fn.GetFullPath();
1025
1026 m_cur_grid->SetCellValue( last_row, COL_URI, path );
1027 }
1028 }
1029
1030 if( !files.IsEmpty() )
1031 {
1032 int new_row = m_cur_grid->GetNumberRows() - 1;
1033 m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
1034 m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
1035 }
1036}
1037
1038
1040{
1041 // Account for scroll bars
1042 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
1043
1044 m_path_subs_grid->AutoSizeColumn( 0 );
1045 m_path_subs_grid->SetColSize( 0, std::max( 72, m_path_subs_grid->GetColSize( 0 ) ) );
1046 m_path_subs_grid->SetColSize( 1, std::max( 120, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
1047}
1048
1049
1051{
1052 adjustPathSubsGridColumns( event.GetSize().GetX() );
1053
1054 event.Skip();
1055}
1056
1057
1059{
1061 return false;
1062
1063 if( verifyTables() )
1064 {
1065 if( *global_model() != *m_globalTable )
1066 {
1068
1070 }
1071
1073 {
1075
1077 }
1078
1079 return true;
1080 }
1081
1082 return false;
1083}
1084
1085
1089{
1090 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1091 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1092
1093 std::set<wxString> unique;
1094
1095 // clear the table
1097
1099 {
1100 if( !tbl )
1101 continue;
1102
1103 for( int row = 0; row < tbl->GetNumberRows(); ++row )
1104 {
1105 wxString uri = tbl->GetValue( row, COL_URI );
1106
1107 while( re.Matches( uri ) )
1108 {
1109 wxString envvar = re.GetMatch( uri, 2 );
1110
1111 // if not ${...} form then must be $(...)
1112 if( envvar.IsEmpty() )
1113 envvar = re.GetMatch( uri, 4 );
1114
1115 // ignore duplicates
1116 unique.insert( envvar );
1117
1118 // delete the last match and search again
1119 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1120 }
1121 }
1122 }
1123
1124 // Make sure this special environment variable shows up even if it was
1125 // not used yet. It is automatically set by KiCad to the directory holding
1126 // the current project.
1127 unique.insert( PROJECT_VAR_NAME );
1129
1130 // This special environment variable is used to locate 3d shapes
1131 unique.insert( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
1132
1133 for( const wxString& evName : unique )
1134 {
1135 int row = m_path_subs_grid->GetNumberRows();
1136 m_path_subs_grid->AppendRows( 1 );
1137
1138 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1139 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1140
1141 wxString evValue;
1142 wxGetEnv( evName, &evValue );
1143 m_path_subs_grid->SetCellValue( row, 1, evValue );
1144 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1145 }
1146
1147 // No combobox editors here, but it looks better if its consistent with the other
1148 // grids in the dialog.
1149 m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1150
1151 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1152}
1153
1154//-----</event handlers>---------------------------------
1155
1156
1158
1159
1160void InvokeEditDesignBlockLibTable( KIWAY* aKiway, wxWindow *aParent )
1161{
1163 wxString globalTablePath = DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName();
1164 DESIGN_BLOCK_LIB_TABLE* projectTable = aKiway->Prj().DesignBlockLibs();
1165 wxString projectTablePath = aKiway->Prj().DesignBlockLibTblName();
1166 wxString msg;
1167
1168 DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Design Block Libraries" ) );
1169
1170 if( aKiway->Prj().IsNullProject() )
1171 projectTable = nullptr;
1172
1173 dlg.InstallPanel( new PANEL_DESIGN_BLOCK_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1174 projectTable, projectTablePath,
1175 aKiway->Prj().GetProjectPath() ) );
1176
1177 if( dlg.ShowModal() == wxID_CANCEL )
1178 return;
1179
1180 if( dlg.m_GlobalTableChanged )
1181 {
1182 try
1183 {
1184 globalTable->Save( globalTablePath );
1185 }
1186 catch( const IO_ERROR& ioe )
1187 {
1188 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1189 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1190 }
1191 }
1192
1193 if( projectTable && dlg.m_ProjectTableChanged )
1194 {
1195 try
1196 {
1197 projectTable->Save( projectTablePath );
1198 }
1199 catch( const IO_ERROR& ioe )
1200 {
1201 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1202 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1203 }
1204 }
1205
1206 std::string payload = "";
1207 aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload );
1208 aKiway->ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload );
1209
1210 return;
1211}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
void paste_text(const wxString &cb_text) override
handle specialized clipboard text, with leading "(design_block_lib_table", OR spreadsheet formatted t...
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
DESIGN_BLOCK_GRID_TRICKS(DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
@ KICAD_SEXP
S-expression KiCad file format.
static const wxString ShowType(DESIGN_BLOCK_FILE_T aFileType)
static DESIGN_BLOCK_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
static DESIGN_BLOCK_FILE_T EnumFromStr(const wxString &aFileType)
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath)
Convert a design block library to the latest KiCad format.
static DESIGN_BLOCK_IO * FindPlugin(DESIGN_BLOCK_FILE_T aFileType)
This class builds a wxGridTableBase by wrapping an DESIGN_BLOCK_LIB_TABLE object.
LIB_TABLE_ROW * at(size_t aIndex) override
void push_back(LIB_TABLE_ROW *aRow) override
DESIGN_BLOCK_LIB_TABLE_GRID(const DESIGN_BLOCK_LIB_TABLE &aTableToEdit)
LIB_TABLE_ROWS_ITER erase(LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
LIB_TABLE_ROWS_ITER insert(LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
LIB_TABLE_ROWS_ITER begin() override
Hold a record identifying a library accessed by the appropriate design block library #PLUGIN object i...
static wxString GetGlobalTableFileName()
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 const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
static DESIGN_BLOCK_LIB_TABLE & GetGlobalLibTable()
DIALOG_PLUGIN_OPTIONS is an options editor in the form of a two column name/value spreadsheet like (t...
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
int ShowModal() override
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
wxString m_lastDesignBlockLibDir
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:527
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:196
Traverser implementation that looks to find any and all "folder" libraries by looking for files with ...
void GetPaths(wxArrayString &aPathArray)
virtual wxDirTraverseResult OnOpenError(const wxString &aOpenErrorName) override
std::unordered_map< wxString, int > m_failedDirs
void GetFailedPaths(wxArrayString &aPathArray)
std::unordered_map< wxString, int > m_foundDirs
LIBRARY_TRAVERSER(std::vector< std::string > aSearchExtensions, wxString aInitialDir)
virtual wxDirTraverseResult OnDir(const wxString &aDirName) override
virtual wxDirTraverseResult OnFile(const wxString &aFileName) override
std::vector< std::string > m_searchExtensions
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:243
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:191
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool AppendRows(size_t aNumRows=1) override
int GetNumberRows() override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
virtual const wxString GetType() const =0
Return the type of library represented by this row.
const wxString & GetNickName() const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_TABLE_ROW * clone() const
void SetOptions(const wxString &aOptions)
Change the library options strings.
static std::map< std::string, UTF8 > * ParseOptions(const std::string &aOptionsList)
Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
void TransferRows(LIB_TABLE_ROWS &aRowsList)
Takes ownership of another list of rows; the original list will be freed.
LIB_TABLE_ROWS m_rows
Owning set of rows.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Class PANEL_DESIGN_BLOCK_LIB_TABLE_BASE.
Dialog to show and edit symbol library tables.
void moveUpHandler(wxCommandEvent &event) override
void onMigrateLibraries(wxCommandEvent &event) override
DESIGN_BLOCK_LIB_TABLE_GRID * project_model() const
void browseLibrariesHandler(wxCommandEvent &event)
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
DESIGN_BLOCK_LIB_TABLE_GRID * cur_model() const
std::map< DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T, IO_BASE::IO_FILE_DESC > m_supportedDesignBlockFiles
void moveDownHandler(wxCommandEvent &event) override
PANEL_DESIGN_BLOCK_LIB_TABLE(DIALOG_EDIT_LIBRARY_TABLES *aParent, PROJECT *aProject, DESIGN_BLOCK_LIB_TABLE *aGlobalTable, const wxString &aGlobalTblPath, DESIGN_BLOCK_LIB_TABLE *aProjectTable, const wxString &aProjectTblPath, const wxString &aProjectBasePath)
DIALOG_EDIT_LIBRARY_TABLES * m_parent
void OnUpdateUI(wxUpdateUIEvent &event) override
void appendRowHandler(wxCommandEvent &event) override
DESIGN_BLOCK_LIB_TABLE_GRID * global_model() const
void onSizeGrid(wxSizeEvent &event) override
void deleteRowHandler(wxCommandEvent &event) override
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
static wxString GetDefaultUserDesignBlocksPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:109
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:924
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
Container for project specific data.
Definition: project.h:64
virtual const wxString DesignBlockLibTblName() const
Return the path and file name of this projects design block library table.
Definition: project.cpp:171
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual DESIGN_BLOCK_LIB_TABLE * DesignBlockLibs()
Return the table of design block libraries.
Definition: project.cpp:418
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:153
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
void SetBitmap(const wxBitmapBundle &aBmp)
void SetWidthPadding(int aPadding)
wxMenu * GetSplitButtonMenu()
void SetMinSize(const wxSize &aSize) override
void SetBitmap(const wxBitmapBundle &aBmp)
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
wxString wx_str() const
Definition: utf8.cpp:45
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:270
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:637
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:348
The common library.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
Definition: confirm.cpp:143
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:250
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
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_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34
static const std::string KiCadDesignBlockLibPathExtension
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
@ COL_DESCR
@ COL_NICKNAME
@ COL_OPTIONS
@ COL_ENABLED
@ COL_URI
This file contains miscellaneous commonly used macros and functions.
@ MAIL_RELOAD_LIB
Definition: mail_type.h:56
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Constructs a versioned environment variable based on this KiCad major version.
Definition: env_vars.cpp:74
void InvokeEditDesignBlockLibTable(KIWAY *aKiway, wxWindow *aParent)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:40
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
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:47
wxString FileFilter() const
Definition: io_base.cpp:40
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
Container that describes file type info for the add a library options.
bool m_IsFile
Whether the library is a folder or a file.
wxString m_Description
Description shown in the file picker dialog.
wxString m_FileFilter
Filter used for file pickers if m_IsFile is true.
DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T m_Plugin
wxString m_FolderSearchExtension
In case of folders it stands for extensions of files stored inside.
Definition of file extensions used in Kicad.