KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
637 {
638 if( !table )
639 continue;
640
641 for( unsigned int r = 0; r < table->GetCount(); ++r )
642 {
643 DESIGN_BLOCK_LIB_TABLE_ROW& row = dynamic_cast<DESIGN_BLOCK_LIB_TABLE_ROW&>( table->At( r ) );
644
645 // Newly-added rows won't have set this yet
646 row.SetParent( table );
647
648 if( !row.GetIsEnabled() )
649 continue;
650
651 try
652 {
653 if( row.Refresh() )
654 {
655 if( table == global_model() )
657 else
659 }
660 }
661 catch( const IO_ERROR& ioe )
662 {
663 msg.Printf( _( "Design block library '%s' failed to load." ), row.GetNickName() );
664
665 wxWindow* topLevelParent = wxGetTopLevelParent( this );
666 wxMessageDialog errdlg( topLevelParent, msg + wxS( "\n" ) + ioe.What(), _( "Error Loading Library" ) );
667 errdlg.ShowModal();
668
669 return true;
670 }
671 }
672 }
673
674 return true;
675}
676
677
678void PANEL_DESIGN_BLOCK_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
679{
680 m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
682}
683
684
686{
688 return;
689
690 if( m_cur_grid->AppendRows( 1 ) )
691 {
692 int last_row = m_cur_grid->GetNumberRows() - 1;
693
694 // wx documentation is wrong, SetGridCursor does not make visible.
695 m_cur_grid->MakeCellVisible( last_row, COL_ENABLED );
696 m_cur_grid->SetGridCursor( last_row, COL_NICKNAME );
697 m_cur_grid->EnableCellEditControl( true );
698 m_cur_grid->ShowCellEditControl();
699 }
700}
701
702
704{
706 return;
707
708 wxGridUpdateLocker noUpdates( m_cur_grid );
709
710 int curRow = m_cur_grid->GetGridCursorRow();
711 int curCol = m_cur_grid->GetGridCursorCol();
712
713 // In a wxGrid, collect rows that have a selected cell, or are selected
714 // It is not so easy: it depends on the way the selection was made.
715 // Here, we collect rows selected by clicking on a row label, and rows that contain any
716 // previously-selected cells.
717 // If no candidate, just delete the row with the grid cursor.
718 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
719 wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
720 wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
721 wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
722
723 // Add all row having cell selected to list:
724 for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
725 selectedRows.Add( cells[ii].GetRow() );
726
727 // Handle block selection
728 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
729 {
730 for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
731 selectedRows.Add( i );
732 }
733
734 // Use the row having the grid cursor only if we have no candidate:
735 if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
736 selectedRows.Add( m_cur_grid->GetGridCursorRow() );
737
738 if( selectedRows.size() == 0 )
739 {
740 wxBell();
741 return;
742 }
743
744 std::sort( selectedRows.begin(), selectedRows.end() );
745
746 // Remove selected rows (note: a row can be stored more than once in list)
747 int last_row = -1;
748
749 // Needed to avoid a wxWidgets alert if the row to delete is the last row
750 // at least on wxMSW 3.2
751 m_cur_grid->ClearSelection();
752
753 for( int ii = selectedRows.GetCount() - 1; ii >= 0; ii-- )
754 {
755 int row = selectedRows[ii];
756
757 if( row != last_row )
758 {
759 last_row = row;
760 m_cur_grid->DeleteRows( row, 1 );
761 }
762 }
763
764 if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
765 m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
766}
767
768
770{
772 return;
773
775 int curRow = m_cur_grid->GetGridCursorRow();
776
777 // @todo: add multiple selection moves.
778 if( curRow >= 1 )
779 {
780 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
781 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
782
783 --curRow;
784 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
785
786 if( tbl->GetView() )
787 {
788 // Update the wxGrid
789 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
790 tbl->GetView()->ProcessTableMessage( msg );
791 }
792
793 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
794 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
795 }
796}
797
798
800{
802 return;
803
805 int curRow = m_cur_grid->GetGridCursorRow();
806
807 // @todo: add multiple selection moves.
808 if( unsigned( curRow + 1 ) < tbl->m_rows.size() )
809 {
810 boost::ptr_vector<LIB_TABLE_ROW>::auto_type move_me =
811 tbl->m_rows.release( tbl->m_rows.begin() + curRow );
812
813 ++curRow;
814 tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() );
815
816 if( tbl->GetView() )
817 {
818 // Update the wxGrid
819 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
820 tbl->GetView()->ProcessTableMessage( msg );
821 }
822
823 m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
824 m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
825 }
826}
827
828
829// @todo refactor this function into single location shared with PANEL_SYM_LIB_TABLE
831{
833 return;
834
835 wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
836
837 if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
838 selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
839
840 wxArrayInt rowsToMigrate;
842 wxString msg;
843
844 for( int row : selectedRows )
845 {
846 if( m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
847 rowsToMigrate.push_back( row );
848 }
849
850 if( rowsToMigrate.size() <= 0 )
851 {
852 wxMessageBox( wxString::Format( _( "Select one or more rows containing libraries "
853 "to save as current KiCad format." ) ) );
854 return;
855 }
856 else
857 {
858 if( rowsToMigrate.size() == 1 )
859 {
860 msg.Printf( _( "Save '%s' as current KiCad format "
861 "and replace entry in table?" ),
862 m_cur_grid->GetCellValue( rowsToMigrate[0], COL_NICKNAME ) );
863 }
864 else
865 {
866 msg.Printf( _( "Save %d libraries as current KiCad format "
867 "and replace entries in table?" ),
868 (int) rowsToMigrate.size() );
869 }
870
871 if( !IsOK( m_parent, msg ) )
872 return;
873 }
874
875 for( int row : rowsToMigrate )
876 {
877 wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
878 wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
879 wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
880 wxFileName legacyLib( resolvedPath );
881
882 if( !legacyLib.Exists() )
883 {
884 msg.Printf( _( "Library '%s' not found." ), relPath );
885 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
886 continue;
887 }
888
889 wxFileName newLib( resolvedPath );
890 newLib.AppendDir( newLib.GetName() + "." + FILEEXT::KiCadDesignBlockLibPathExtension );
891 newLib.SetName( "" );
892 newLib.ClearExt();
893
894 if( newLib.DirExists() )
895 {
896 msg.Printf( _( "Folder '%s' already exists. Do you want overwrite any existing design "
897 "blocks?" ),
898 newLib.GetFullPath() );
899
900 switch( wxMessageBox( msg, _( "Migrate Library" ),
901 wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
902 {
903 case wxYES: break;
904 case wxNO: continue;
905 case wxCANCEL: return;
906 }
907 }
908
909 wxString options = m_cur_grid->GetCellValue( row, COL_OPTIONS );
910 std::unique_ptr<std::map<std::string, UTF8>> props(
911 LIB_TABLE::ParseOptions( options.ToStdString() ) );
912
913 if( DESIGN_BLOCK_IO_MGR::ConvertLibrary( props.get(), legacyLib.GetFullPath(),
914 newLib.GetFullPath() ) )
915 {
916 relPath =
917 NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(), m_project );
918
919 // Do not use the project path in the global library table. This will almost
920 // assuredly be wrong for a different project.
921 if( m_cur_grid == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) )
922 relPath = newLib.GetFullPath();
923
924 m_cur_grid->SetCellValue( row, COL_URI, relPath );
925 m_cur_grid->SetCellValue( row, COL_TYPE, kicadType );
926 }
927 else
928 {
929 msg.Printf( _( "Failed to save design block library file '%s'." ),
930 newLib.GetFullPath() );
931 DisplayErrorMessage( wxGetTopLevelParent( this ), msg );
932 }
933 }
934}
935
936
938{
940 return;
941
943
944 // We are bound both to the menu and button with this one handler
945 // So we must set the file type based on it
946 if( event.GetEventType() == wxEVT_BUTTON )
947 {
948 // Let's default to adding a kicad design block file for just the design block
950 }
951 else
952 {
953 fileType = static_cast<DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T>( event.GetId() );
954 }
955
957 {
958 wxLogWarning( wxT( "File type selection event received but could not find the file type "
959 "in the table" ) );
960 return;
961 }
962
965 KICAD_SETTINGS* cfg = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
966
967 wxString title =
968 wxString::Format( _( "Select %s Library" ), DESIGN_BLOCK_IO_MGR::ShowType( fileType ) );
969 wxString openDir = cfg->m_lastDesignBlockLibDir;
970
972 openDir = m_lastProjectLibDir;
973
974 wxArrayString files;
975
976 wxWindow* topLevelParent = wxGetTopLevelParent( this );
977
978 if( fileDesc.m_IsFile )
979 {
980 wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
981 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
982
983 int result = dlg.ShowModal();
984
985 if( result == wxID_CANCEL )
986 return;
987
988 dlg.GetPaths( files );
989
991 cfg->m_lastDesignBlockLibDir = dlg.GetDirectory();
992 else
993 m_lastProjectLibDir = dlg.GetDirectory();
994 }
995 else
996 {
997 wxDirDialog dlg( topLevelParent, title, openDir,
998 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
999
1000 int result = dlg.ShowModal();
1001
1002 if( result == wxID_CANCEL )
1003 return;
1004
1005 dlg.GetPaths( files );
1006
1007 if( !files.IsEmpty() )
1008 {
1009 wxFileName first( files.front() );
1010
1011 if( m_cur_grid == m_global_grid )
1012 cfg->m_lastDesignBlockLibDir = first.GetPath();
1013 else
1014 m_lastProjectLibDir = first.GetPath();
1015 }
1016 }
1017
1018 // Drop the last directory if the path is a .pretty folder
1021 cfg->m_lastDesignBlockLibDir.BeforeLast( wxFileName::GetPathSeparator() );
1022
1023 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1024 bool addDuplicates = false;
1025 bool applyToAll = false;
1026 wxString warning = _( "Warning: Duplicate Nicknames" );
1027 wxString msg = _( "A library nicknamed '%s' already exists." );
1028 wxString detailedMsg = _( "One of the nicknames will need to be changed after "
1029 "adding this library." );
1030
1031 for( const wxString& filePath : files )
1032 {
1033 wxFileName fn( filePath );
1034 wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
1035 bool doAdd = true;
1036
1039 nickname = LIB_ID::FixIllegalChars( fn.GetFullName(), true ).wx_str();
1040
1041 if( cur_model()->ContainsNickname( nickname ) )
1042 {
1043 if( !applyToAll )
1044 {
1045 // The cancel button adds the library to the table anyway
1046 addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning,
1047 wxString::Format( msg, nickname ), detailedMsg,
1048 _( "Skip" ), _( "Add Anyway" ), &applyToAll )
1049 == wxID_CANCEL;
1050 }
1051
1052 doAdd = addDuplicates;
1053 }
1054
1055 if( doAdd && m_cur_grid->AppendRows( 1 ) )
1056 {
1057 int last_row = m_cur_grid->GetNumberRows() - 1;
1058
1059 m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
1060
1061 m_cur_grid->SetCellValue( last_row, COL_TYPE,
1063
1064 // try to use path normalized to an environmental variable or project path
1065 wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
1066
1067 // Do not use the project path in the global library table. This will almost
1068 // assuredly be wrong for a different project.
1069 if( m_pageNdx == 0 && path.Contains( wxT( "${KIPRJMOD}" ) ) )
1070 path = fn.GetFullPath();
1071
1072 m_cur_grid->SetCellValue( last_row, COL_URI, path );
1073 }
1074 }
1075
1076 if( !files.IsEmpty() )
1077 {
1078 int new_row = m_cur_grid->GetNumberRows() - 1;
1079 m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
1080 m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
1081 }
1082}
1083
1084
1086{
1087 // Account for scroll bars
1088 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
1089
1090 m_path_subs_grid->AutoSizeColumn( 0 );
1091 m_path_subs_grid->SetColSize( 0, std::max( 72, m_path_subs_grid->GetColSize( 0 ) ) );
1092 m_path_subs_grid->SetColSize( 1, std::max( 120, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
1093}
1094
1095
1097{
1098 adjustPathSubsGridColumns( event.GetSize().GetX() );
1099
1100 event.Skip();
1101}
1102
1103
1105{
1107 return false;
1108
1109 if( verifyTables() )
1110 {
1111 if( *global_model() != *m_globalTable )
1112 {
1114
1116 }
1117
1119 {
1121
1123 }
1124
1125 return true;
1126 }
1127
1128 return false;
1129}
1130
1131
1135{
1136 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
1137 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
1138
1139 std::set<wxString> unique;
1140
1141 // clear the table
1143
1145 {
1146 if( !tbl )
1147 continue;
1148
1149 for( int row = 0; row < tbl->GetNumberRows(); ++row )
1150 {
1151 wxString uri = tbl->GetValue( row, COL_URI );
1152
1153 while( re.Matches( uri ) )
1154 {
1155 wxString envvar = re.GetMatch( uri, 2 );
1156
1157 // if not ${...} form then must be $(...)
1158 if( envvar.IsEmpty() )
1159 envvar = re.GetMatch( uri, 4 );
1160
1161 // ignore duplicates
1162 unique.insert( envvar );
1163
1164 // delete the last match and search again
1165 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
1166 }
1167 }
1168 }
1169
1170 // Make sure this special environment variable shows up even if it was
1171 // not used yet. It is automatically set by KiCad to the directory holding
1172 // the current project.
1173 unique.insert( PROJECT_VAR_NAME );
1175
1176 // This special environment variable is used to locate 3d shapes
1177 unique.insert( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
1178
1179 for( const wxString& evName : unique )
1180 {
1181 int row = m_path_subs_grid->GetNumberRows();
1182 m_path_subs_grid->AppendRows( 1 );
1183
1184 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
1185 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1186
1187 wxString evValue;
1188 wxGetEnv( evName, &evValue );
1189 m_path_subs_grid->SetCellValue( row, 1, evValue );
1190 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1191 }
1192
1193 // No combobox editors here, but it looks better if its consistent with the other
1194 // grids in the dialog.
1195 m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1196
1197 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1198}
1199
1200//-----</event handlers>---------------------------------
1201
1202
1204
1205
1206void InvokeEditDesignBlockLibTable( KIWAY* aKiway, wxWindow *aParent )
1207{
1209 wxString globalTablePath = DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName();
1210 DESIGN_BLOCK_LIB_TABLE* projectTable = aKiway->Prj().DesignBlockLibs();
1211 wxString projectTablePath = aKiway->Prj().DesignBlockLibTblName();
1212 wxString msg;
1213
1214 DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Design Block Libraries" ) );
1215
1216 if( aKiway->Prj().IsNullProject() )
1217 projectTable = nullptr;
1218
1219 dlg.InstallPanel( new PANEL_DESIGN_BLOCK_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable,
1220 globalTablePath,
1221 projectTable, projectTablePath,
1222 aKiway->Prj().GetProjectPath() ) );
1223
1224 if( dlg.ShowModal() == wxID_CANCEL )
1225 return;
1226
1227 if( dlg.m_GlobalTableChanged )
1228 {
1229 try
1230 {
1231 globalTable->Save( globalTablePath );
1232 }
1233 catch( const IO_ERROR& ioe )
1234 {
1235 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1236 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1237 }
1238 }
1239
1240 if( projectTable && dlg.m_ProjectTableChanged )
1241 {
1242 try
1243 {
1244 projectTable->Save( projectTablePath );
1245 }
1246 catch( const IO_ERROR& ioe )
1247 {
1248 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1249 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1250 }
1251 }
1252
1253 std::string payload = "";
1254 aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload );
1255 aKiway->ExpressMail( FRAME_PCB_EDITOR, MAIL_RELOAD_LIB, payload );
1256
1257 return;
1258}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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...
bool Refresh() override
Attempt to reload the library.
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:66
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:241
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:192
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool AppendRows(size_t aNumRows=1) override
int GetNumberRows() override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
virtual const wxString GetType() const =0
Return the type of library represented by this row.
void SetParent(LIB_TABLE *aParent)
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
bool GetIsEnabled() 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:933
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 char *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:275
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:644
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:249
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
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_PCB_EDITOR
Definition: frame_type.h:42
@ 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:57
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Construct a versioned environment variable based on this KiCad major version.
Definition: env_vars.cpp:83
void InvokeEditDesignBlockLibTable(KIWAY *aKiway, wxWindow *aParent)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1071
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:403
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.