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