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 KICAD_SETTINGS* cfg = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
319
320 if( cfg->m_lastDesignBlockLibDir.IsEmpty() )
322
324
325 auto autoSizeCol = [&]( WX_GRID* aGrid, int aCol )
326 {
327 int prevWidth = aGrid->GetColSize( aCol );
328
329 aGrid->AutoSizeColumn( aCol, false );
330 aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
331 };
332
333 auto setupGrid = [&]( WX_GRID* aGrid )
334 {
335 // Give a bit more room for wxChoice editors
336 aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
337
338 // add Cut, Copy, and Paste to wxGrids
339 aGrid->PushEventHandler( new DESIGN_BLOCK_GRID_TRICKS( m_parent, aGrid ) );
340
341 aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
342
343 wxGridCellAttr* attr;
344
345 attr = new wxGridCellAttr;
346 attr->SetEditor( new GRID_CELL_PATH_EDITOR(
348 [this]( WX_GRID* grid, int row ) -> wxString
349 {
350 auto* libTable = static_cast<DESIGN_BLOCK_LIB_TABLE_GRID*>( grid->GetTable() );
351 auto* tableRow =
352 static_cast<DESIGN_BLOCK_LIB_TABLE_ROW*>( libTable->at( row ) );
353 DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T fileType = tableRow->GetFileType();
354 const IO_BASE::IO_FILE_DESC& pluginDesc =
356
357 if( pluginDesc.m_IsFile )
358 return pluginDesc.FileFilter();
359 else
360 return wxEmptyString;
361 } ) );
362 aGrid->SetColAttr( COL_URI, attr );
363
364 attr = new wxGridCellAttr;
365 attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
366 aGrid->SetColAttr( COL_TYPE, attr );
367
368 attr = new wxGridCellAttr;
369 attr->SetRenderer( new wxGridCellBoolRenderer() );
370 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
371 aGrid->SetColAttr( COL_ENABLED, attr );
372
373 // No visibility control for design block libraries yet; this feature is primarily
374 // useful for database libraries and it's only implemented for schematic symbols
375 // at the moment.
376 aGrid->HideCol( COL_VISIBLE );
377
378 // all but COL_OPTIONS, which is edited with Option Editor anyways.
379 autoSizeCol( aGrid, COL_NICKNAME );
380 autoSizeCol( aGrid, COL_TYPE );
381 autoSizeCol( aGrid, COL_URI );
382 autoSizeCol( aGrid, COL_DESCR );
383
384 // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
385 // a currentCell which is sometimes not highlighted.
386 if( aGrid->GetNumberRows() > 0 )
387 aGrid->SelectRow( 0 );
388 };
389
390 setupGrid( m_global_grid );
391
393
394 if( aProjectTable )
395 {
396 m_project_grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID( *aProjectTable ), true );
397 setupGrid( m_project_grid );
398 }
399 else
400 {
401 m_pageNdx = 0;
402 m_notebook->DeletePage( 1 );
403 m_project_grid = nullptr;
404 }
405
406 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
407 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
408
409 // select the last selected page
410 m_notebook->SetSelection( m_pageNdx );
412
413 // for ALT+A handling, we want the initial focus to be on the first selected grid.
415
416 // Configure button logos
417 m_append_button->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
418 m_delete_button->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
419 m_move_up_button->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
420 m_move_down_button->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
421 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
422
423 // For aesthetic reasons, we must set the size of m_browseButton to match the other bitmaps
424 // manually (for instance m_append_button)
425 Layout(); // Needed at least on MSW to compute the actual buttons sizes, after initializing
426 // their bitmaps
427 wxSize buttonSize = m_append_button->GetSize();
428
430 m_browseButton->SetMinSize( buttonSize );
431
432 // Populate the browse library options
433 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
434
435 auto joinExts = []( const std::vector<std::string>& aExts )
436 {
437 wxString joined;
438 for( const std::string& ext : aExts )
439 {
440 if( !joined.empty() )
441 joined << wxS( ", " );
442
443 joined << wxS( "*." ) << ext;
444 }
445
446 return joined;
447 };
448
449 for( auto& [type, desc] : m_supportedDesignBlockFiles )
450 {
451 wxString entryStr = DESIGN_BLOCK_IO_MGR::ShowType( type );
452
453 if( desc.m_IsFile && !desc.m_FileExtensions.empty() )
454 {
455 entryStr << wxString::Format( wxS( " (%s)" ), joinExts( desc.m_FileExtensions ) );
456 }
457 else if( !desc.m_IsFile && !desc.m_ExtensionsInDir.empty() )
458 {
459 wxString midPart = wxString::Format( _( "folder with %s files" ),
460 joinExts( desc.m_ExtensionsInDir ) );
461
462 entryStr << wxString::Format( wxS( " (%s)" ), midPart );
463 }
464
465 browseMenu->Append( type, entryStr );
466
467 browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED,
469 }
470
471 Layout();
472
473 // This is the button only press for the browse button instead of the menu
475 this );
476}
477
478
480{
481 wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
482 for( auto& [type, desc] : m_supportedDesignBlockFiles )
483 {
484 browseMenu->Unbind( wxEVT_COMMAND_MENU_SELECTED,
486 }
488 this );
489
490 // Delete the GRID_TRICKS.
491 // Any additional event handlers should be popped before the window is deleted.
492 m_global_grid->PopEventHandler( true );
493
494 if( m_project_grid )
495 m_project_grid->PopEventHandler( true );
496
497 m_path_subs_grid->PopEventHandler( true );
498}
499
500
502{
505 {
507
508 if( !pi )
509 continue;
510
511 if( const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc() )
512 m_supportedDesignBlockFiles.emplace( type, desc );
513 }
514}
515
516
518{
519 wxString msg;
520
522 {
523 if( !model )
524 continue;
525
526 for( int r = 0; r < model->GetNumberRows(); )
527 {
528 wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
529 wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
530 unsigned illegalCh = 0;
531
532 if( !nick || !uri )
533 {
534 if( !nick && !uri )
535 msg = _( "A library table row nickname and path cells are empty." );
536 else if( !nick )
537 msg = _( "A library table row nickname cell is empty." );
538 else
539 msg = _( "A library table row path cell is empty." );
540
541 wxWindow* topLevelParent = wxGetTopLevelParent( this );
542
543 wxMessageDialog badCellDlg( topLevelParent, msg, _( "Invalid Row Definition" ),
544 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
545 badCellDlg.SetExtendedMessage( _( "Empty cells will result in all rows that are "
546 "invalid to be removed from the table." ) );
547 badCellDlg.SetYesNoLabels(
548 wxMessageDialog::ButtonLabel( _( "Remove Invalid Cells" ) ),
549 wxMessageDialog::ButtonLabel( _( "Cancel Table Update" ) ) );
550
551 if( badCellDlg.ShowModal() == wxID_NO )
552 return false;
553
554 // Delete the "empty" row, where empty means missing nick or uri.
555 // This also updates the UI which could be slow, but there should only be a few
556 // rows to delete, unless the user fell asleep on the Add Row
557 // button.
558 model->DeleteRows( r, 1 );
559 }
560 else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
561 {
562 msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'." ), illegalCh,
563 nick );
564
565 // show the tabbed panel holding the grid we have flunked:
566 if( model != cur_model() )
567 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
568
569 m_cur_grid->MakeCellVisible( r, 0 );
570 m_cur_grid->SetGridCursor( r, 1 );
571
572 wxWindow* topLevelParent = wxGetTopLevelParent( this );
573
574 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
575 errdlg.ShowModal();
576 return false;
577 }
578 else
579 {
580 // set the trimmed values back into the table so they get saved to disk.
581 model->SetValue( r, COL_NICKNAME, nick );
582 model->SetValue( r, COL_URI, uri );
583
584 // Make sure to not save a hidden flag
585 model->SetValue( r, COL_VISIBLE, wxS( "1" ) );
586
587 ++r; // this row was OK.
588 }
589 }
590 }
591
592 // check for duplicate nickNames, separately in each table.
594 {
595 if( !model )
596 continue;
597
598 for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
599 {
600 wxString nick1 = model->GetValue( r1, COL_NICKNAME );
601
602 for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
603 {
604 wxString nick2 = model->GetValue( r2, COL_NICKNAME );
605
606 if( nick1 == nick2 )
607 {
608 msg = wxString::Format( _( "Multiple libraries cannot share the same "
609 "nickname ('%s')." ),
610 nick1 );
611
612 // show the tabbed panel holding the grid we have flunked:
613 if( model != cur_model() )
614 m_notebook->SetSelection( model == global_model() ? 0 : 1 );
615
616 // go to the lower of the two rows, it is technically the duplicate:
617 m_cur_grid->MakeCellVisible( r2, 0 );
618 m_cur_grid->SetGridCursor( r2, 1 );
619
620 wxWindow* topLevelParent = wxGetTopLevelParent( this );
621
622 wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
623 errdlg.ShowModal();
624 return false;
625 }
626 }
627 }
628 }
629
630 return true;
631}
632
633
634void PANEL_DESIGN_BLOCK_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
635{
636 m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
638}
639
640
642{
644 return;
645
646 if( m_cur_grid->AppendRows( 1 ) )
647 {
648 int last_row = m_cur_grid->GetNumberRows() - 1;
649
650 // wx documentation is wrong, SetGridCursor does not make visible.
651 m_cur_grid->MakeCellVisible( last_row, COL_ENABLED );
652 m_cur_grid->SetGridCursor( last_row, COL_NICKNAME );
653 m_cur_grid->EnableCellEditControl( true );
654 m_cur_grid->ShowCellEditControl();
655 }
656}
657
658
660{
662 return;
663
664 wxGridUpdateLocker noUpdates( m_cur_grid );
665
666 int curRow = m_cur_grid->GetGridCursorRow();
667 int curCol = m_cur_grid->GetGridCursorCol();
668
669 // In a wxGrid, collect rows that have a selected cell, or are selected
670 // It is not so easy: it depends on the way the selection was made.
671 // Here, we collect rows selected by clicking on a row label, and rows that contain any
672 // previously-selected cells.
673 // If no candidate, just delete the row with the grid cursor.
674 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
675 wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
676 wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
677 wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
678
679 // Add all row having cell selected to list:
680 for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
681 selectedRows.Add( cells[ii].GetRow() );
682
683 // Handle block selection
684 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
685 {
686 for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
687 selectedRows.Add( i );
688 }
689
690 // Use the row having the grid cursor only if we have no candidate:
691 if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
692 selectedRows.Add( m_cur_grid->GetGridCursorRow() );
693
694 if( selectedRows.size() == 0 )
695 {
696 wxBell();
697 return;
698 }
699
700 std::sort( selectedRows.begin(), selectedRows.end() );
701
702 // Remove selected rows (note: a row can be stored more than once in list)
703 int last_row = -1;
704
705 // Needed to avoid a wxWidgets alert if the row to delete is the last row
706 // at least on wxMSW 3.2
707 m_cur_grid->ClearSelection();
708
709 for( int ii = selectedRows.GetCount() - 1; ii >= 0; ii-- )
710 {
711 int row = selectedRows[ii];
712
713 if( row != last_row )
714 {
715 last_row = row;
716 m_cur_grid->DeleteRows( row, 1 );
717 }
718 }
719
720 if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
721 m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
722}
723
724
726{
728 return;
729
731 int curRow = m_cur_grid->GetGridCursorRow();
732
733 // @todo: add multiple selection moves.
734 if( curRow >= 1 )
735 {
736 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
737 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
738
739 --curRow;
740 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
741
742 if( tbl->GetView() )
743 {
744 // Update the wxGrid
745 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
746 tbl->GetView()->ProcessTableMessage( msg );
747 }
748
749 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
750 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
751 }
752}
753
754
756{
758 return;
759
761 int curRow = m_cur_grid->GetGridCursorRow();
762
763 // @todo: add multiple selection moves.
764 if( unsigned( curRow + 1 ) < tbl->m_rows.size() )
765 {
766 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
767 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
768
769 ++curRow;
770 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
771
772 if( tbl->GetView() )
773 {
774 // Update the wxGrid
775 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
776 tbl->GetView()->ProcessTableMessage( msg );
777 }
778
779 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
780 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
781 }
782}
783
784
785// @todo refactor this function into single location shared with PANEL_SYM_LIB_TABLE
787{
789 return;
790
791 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
792
793 if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
794 selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
795
796 wxArrayInt rowsToMigrate;
798 wxString msg;
799
800 for( int row : selectedRows )
801 {
802 if( m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
803 rowsToMigrate.push_back( row );
804 }
805
806 if( rowsToMigrate.size() <= 0 )
807 {
808 wxMessageBox( wxString::Format( _( "Select one or more rows containing libraries "
809 "to save as current KiCad format." ) ) );
810 return;
811 }
812 else
813 {
814 if( rowsToMigrate.size() == 1 )
815 {
816 msg.Printf( _( "Save '%s' as current KiCad format "
817 "and replace entry in table?" ),
818 m_cur_grid->GetCellValue( rowsToMigrate[0], COL_NICKNAME ) );
819 }
820 else
821 {
822 msg.Printf( _( "Save %d libraries as current KiCad format "
823 "and replace entries in table?" ),
824 (int) rowsToMigrate.size() );
825 }
826
827 if( !IsOK( m_parent, msg ) )
828 return;
829 }
830
831 for( int row : rowsToMigrate )
832 {
833 wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
834 wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
835 wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
836 wxFileName legacyLib( resolvedPath );
837
838 if( !legacyLib.Exists() )
839 {
840 msg.Printf( _( "Library '%s' not found." ), relPath );
841 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
842 continue;
843 }
844
845 wxFileName newLib( resolvedPath );
846 newLib.AppendDir( newLib.GetName() + "." + FILEEXT::KiCadDesignBlockLibPathExtension );
847 newLib.SetName( "" );
848 newLib.ClearExt();
849
850 if( newLib.DirExists() )
851 {
852 msg.Printf( _( "Folder '%s' already exists. Do you want overwrite any existing design "
853 "blocks?" ),
854 newLib.GetFullPath() );
855
856 switch( wxMessageBox( msg, _( "Migrate Library" ),
857 wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
858 {
859 case wxYES: break;
860 case wxNO: continue;
861 case wxCANCEL: return;
862 }
863 }
864
865 wxString options = m_cur_grid->GetCellValue( row, COL_OPTIONS );
866 std::unique_ptr<std::map<std::string, UTF8>> props(
867 LIB_TABLE::ParseOptions( options.ToStdString() ) );
868
869 if( DESIGN_BLOCK_IO_MGR::ConvertLibrary( props.get(), legacyLib.GetFullPath(),
870 newLib.GetFullPath() ) )
871 {
872 relPath =
873 NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(), m_project );
874
875 // Do not use the project path in the global library table. This will almost
876 // assuredly be wrong for a different project.
877 if( m_cur_grid == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) )
878 relPath = newLib.GetFullPath();
879
880 m_cur_grid->SetCellValue( row, COL_URI, relPath );
881 m_cur_grid->SetCellValue( row, COL_TYPE, kicadType );
882 }
883 else
884 {
885 msg.Printf( _( "Failed to save design block library file '%s'." ),
886 newLib.GetFullPath() );
887 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
888 }
889 }
890}
891
892
894{
896 return;
897
899
900 // We are bound both to the menu and button with this one handler
901 // So we must set the file type based on it
902 if( event.GetEventType() == wxEVT_BUTTON )
903 {
904 // Let's default to adding a kicad design block file for just the design block
906 }
907 else
908 {
909 fileType = static_cast<DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T>( event.GetId() );
910 }
911
913 {
914 wxLogWarning( wxT( "File type selection event received but could not find the file type "
915 "in the table" ) );
916 return;
917 }
918
921 KICAD_SETTINGS* cfg = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
922
923 wxString title =
924 wxString::Format( _( "Select %s Library" ), DESIGN_BLOCK_IO_MGR::ShowType( fileType ) );
925 wxString openDir = cfg->m_lastDesignBlockLibDir;
926
928 openDir = m_lastProjectLibDir;
929
930 wxArrayString files;
931
932 wxWindow* topLevelParent = wxGetTopLevelParent( this );
933
934 if( fileDesc.m_IsFile )
935 {
936 wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
937 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
938
939 int result = dlg.ShowModal();
940
941 if( result == wxID_CANCEL )
942 return;
943
944 dlg.GetPaths( files );
945
947 cfg->m_lastDesignBlockLibDir = dlg.GetDirectory();
948 else
949 m_lastProjectLibDir = dlg.GetDirectory();
950 }
951 else
952 {
953 wxDirDialog dlg( topLevelParent, title, openDir,
954 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
955
956 int result = dlg.ShowModal();
957
958 if( result == wxID_CANCEL )
959 return;
960
961 dlg.GetPaths( files );
962
963 if( !files.IsEmpty() )
964 {
965 wxFileName first( files.front() );
966
968 cfg->m_lastDesignBlockLibDir = first.GetPath();
969 else
970 m_lastProjectLibDir = first.GetPath();
971 }
972 }
973
974 // Drop the last directory if the path is a .pretty folder
977 cfg->m_lastDesignBlockLibDir.BeforeLast( wxFileName::GetPathSeparator() );
978
979 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
980 bool addDuplicates = false;
981 bool applyToAll = false;
982 wxString warning = _( "Warning: Duplicate Nicknames" );
983 wxString msg = _( "A library nicknamed '%s' already exists." );
984 wxString detailedMsg = _( "One of the nicknames will need to be changed after "
985 "adding this library." );
986
987 for( const wxString& filePath : files )
988 {
989 wxFileName fn( filePath );
990 wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
991 bool doAdd = true;
992
995 nickname = LIB_ID::FixIllegalChars( fn.GetFullName(), true ).wx_str();
996
997 if( cur_model()->ContainsNickname( nickname ) )
998 {
999 if( !applyToAll )
1000 {
1001 // The cancel button adds the library to the table anyway
1002 addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning,
1003 wxString::Format( msg, nickname ), detailedMsg,
1004 _( "Skip" ), _( "Add Anyway" ), &applyToAll )
1005 == wxID_CANCEL;
1006 }
1007
1008 doAdd = addDuplicates;
1009 }
1010
1011 if( doAdd && m_cur_grid->AppendRows( 1 ) )
1012 {
1013 int last_row = m_cur_grid->GetNumberRows() - 1;
1014
1015 m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
1016
1017 m_cur_grid->SetCellValue( last_row, COL_TYPE,
1019
1020 // try to use path normalized to an environmental variable or project path
1021 wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
1022
1023 // Do not use the project path in the global library table. This will almost
1024 // assuredly be wrong for a different project.
1025 if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
1026 path = fn.GetFullPath();
1027
1028 m_cur_grid->SetCellValue( last_row, COL_URI, path );
1029 }
1030 }
1031
1032 if( !files.IsEmpty() )
1033 {
1034 int new_row = m_cur_grid->GetNumberRows() - 1;
1035 m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
1036 m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
1037 }
1038}
1039
1040
1042{
1043 // Account for scroll bars
1044 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
1045
1046 m_path_subs_grid->AutoSizeColumn( 0 );
1047 m_path_subs_grid->SetColSize( 0, std::max( 72, m_path_subs_grid->GetColSize( 0 ) ) );
1048 m_path_subs_grid->SetColSize( 1, std::max( 120, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
1049}
1050
1051
1053{
1054 adjustPathSubsGridColumns( event.GetSize().GetX() );
1055
1056 event.Skip();
1057}
1058
1059
1061{
1063 return false;
1064
1065 if( verifyTables() )
1066 {
1067 if( *global_model() != *m_globalTable )
1068 {
1070
1072 }
1073
1075 {
1077
1079 }
1080
1081 return true;
1082 }
1083
1084 return false;
1085}
1086
1087
1091{
1092 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1093 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1094
1095 std::set<wxString> unique;
1096
1097 // clear the table
1099
1101 {
1102 if( !tbl )
1103 continue;
1104
1105 for( int row = 0; row < tbl->GetNumberRows(); ++row )
1106 {
1107 wxString uri = tbl->GetValue( row, COL_URI );
1108
1109 while( re.Matches( uri ) )
1110 {
1111 wxString envvar = re.GetMatch( uri, 2 );
1112
1113 // if not ${...} form then must be $(...)
1114 if( envvar.IsEmpty() )
1115 envvar = re.GetMatch( uri, 4 );
1116
1117 // ignore duplicates
1118 unique.insert( envvar );
1119
1120 // delete the last match and search again
1121 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1122 }
1123 }
1124 }
1125
1126 // Make sure this special environment variable shows up even if it was
1127 // not used yet. It is automatically set by KiCad to the directory holding
1128 // the current project.
1129 unique.insert( PROJECT_VAR_NAME );
1131
1132 // This special environment variable is used to locate 3d shapes
1133 unique.insert( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
1134
1135 for( const wxString& evName : unique )
1136 {
1137 int row = m_path_subs_grid->GetNumberRows();
1138 m_path_subs_grid->AppendRows( 1 );
1139
1140 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1141 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1142
1143 wxString evValue;
1144 wxGetEnv( evName, &evValue );
1145 m_path_subs_grid->SetCellValue( row, 1, evValue );
1146 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1147 }
1148
1149 // No combobox editors here, but it looks better if its consistent with the other
1150 // grids in the dialog.
1151 m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1152
1153 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1154}
1155
1156//-----</event handlers>---------------------------------
1157
1158
1160
1161
1162void InvokeEditDesignBlockLibTable( KIWAY* aKiway, wxWindow *aParent )
1163{
1165 wxString globalTablePath = DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName();
1166 DESIGN_BLOCK_LIB_TABLE* projectTable = aKiway->Prj().DesignBlockLibs();
1167 wxString projectTablePath = aKiway->Prj().DesignBlockLibTblName();
1168 wxString msg;
1169
1170 DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Design Block Libraries" ) );
1171
1172 if( aKiway->Prj().IsNullProject() )
1173 projectTable = nullptr;
1174
1175 dlg.InstallPanel( new PANEL_DESIGN_BLOCK_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1176 projectTable, projectTablePath,
1177 aKiway->Prj().GetProjectPath() ) );
1178
1179 if( dlg.ShowModal() == wxID_CANCEL )
1180 return;
1181
1182 if( dlg.m_GlobalTableChanged )
1183 {
1184 try
1185 {
1186 globalTable->Save( globalTablePath );
1187 }
1188 catch( const IO_ERROR& ioe )
1189 {
1190 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1191 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1192 }
1193 }
1194
1195 if( projectTable && dlg.m_ProjectTableChanged )
1196 {
1197 try
1198 {
1199 projectTable->Save( projectTablePath );
1200 }
1201 catch( const IO_ERROR& ioe )
1202 {
1203 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1204 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1205 }
1206 }
1207
1208 std::string payload = "";
1209 aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload );
1210 aKiway->ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload );
1211
1212 return;
1213}
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:285
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(const wxString &aFilename)
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.