KiCad PCB EDA Suite
PANEL_FP_LIB_TABLE Class Reference

Dialog to show and edit symbol library tables. More...

#include <panel_fp_lib_table.h>

Inheritance diagram for PANEL_FP_LIB_TABLE:
PANEL_FP_LIB_TABLE_BASE

Public Member Functions

 PANEL_FP_LIB_TABLE (DIALOG_EDIT_LIBRARY_TABLES *aParent, FP_LIB_TABLE *aGlobal, const wxString &aGlobalTblPath, FP_LIB_TABLE *aProject, const wxString &aProjectTblPath, const wxString &aProjectBasePath)
 
 ~PANEL_FP_LIB_TABLE () override
 

Protected Attributes

wxAuiNotebook * m_auinotebook
 
wxPanel * m_global_panel
 
wxStaticText * m_staticText3
 
wxStaticText * m_GblTableFilename
 
WX_GRIDm_global_grid
 
wxPanel * m_project_panel
 
wxStaticText * m_staticText4
 
wxStaticText * m_PrjTableFilename
 
WX_GRIDm_project_grid
 
wxBitmapButton * m_append_button
 
SPLIT_BUTTONm_browseButton
 
wxBitmapButton * m_move_up_button
 
wxBitmapButton * m_move_down_button
 
wxBitmapButton * m_delete_button
 
WX_GRIDm_path_subs_grid
 

Private Member Functions

bool TransferDataFromWindow () override
 
bool verifyTables ()
 Trim important fields, removes blank row entries, and checks for duplicates. More...
 
void pageChangedHandler (wxAuiNotebookEvent &event) override
 
void appendRowHandler (wxCommandEvent &event) override
 
void browseLibrariesHandler (wxCommandEvent &event)
 
void deleteRowHandler (wxCommandEvent &event) override
 
void moveUpHandler (wxCommandEvent &event) override
 
void moveDownHandler (wxCommandEvent &event) override
 
void onSizeGrid (wxSizeEvent &event) override
 
void adjustPathSubsGridColumns (int aWidth)
 
void populateEnvironReadOnlyTable ()
 Populate the readonly environment variable table with names and values by examining all the full_uri columns. More...
 
FP_LIB_TABLE_GRIDglobal_model () const
 
FP_LIB_TABLE_GRIDproject_model () const
 
FP_LIB_TABLE_GRIDcur_model () const
 

Private Attributes

FP_LIB_TABLEm_global
 
FP_LIB_TABLEm_project
 
wxString m_projectBasePath
 
DIALOG_EDIT_LIBRARY_TABLESm_parent
 
WX_GRIDm_cur_grid
 

Static Private Attributes

static size_t m_pageNdx = 0
 
static wxString m_lastBrowseDir
 

Detailed Description

Dialog to show and edit symbol library tables.

Definition at line 34 of file panel_fp_lib_table.h.

Constructor & Destructor Documentation

◆ PANEL_FP_LIB_TABLE()

PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE ( DIALOG_EDIT_LIBRARY_TABLES aParent,
FP_LIB_TABLE aGlobal,
const wxString &  aGlobalTblPath,
FP_LIB_TABLE aProject,
const wxString &  aProjectTblPath,
const wxString &  aProjectBasePath 
)

Definition at line 359 of file panel_fp_lib_table.cpp.

362  :
363  PANEL_FP_LIB_TABLE_BASE( aParent ),
364  m_global( aGlobal ),
365  m_project( aProject ),
366  m_projectBasePath( aProjectBasePath ),
367  m_parent( aParent )
368 {
369  // For user info, shows the table filenames:
370  m_GblTableFilename->SetLabel( aGlobalTblPath );
371 
372  m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true );
373 
374  // add Cut, Copy, and Paste to wxGrids
375  m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
376 
377  wxArrayString choices;
378 
379  choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) );
380 #if defined(BUILD_GITHUB_PLUGIN)
381  choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
382 #endif
383  choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
384  choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
385  choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
386 
387  /* PCAD_PLUGIN does not support Footprint*() functions
388  choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) );
389  */
390 
391  auto setupGrid =
392  [&]( WX_GRID* aGrid )
393  {
394  // Give a bit more room for wxChoice editors
395  aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
396 
397  // add Cut, Copy, and Paste to wxGrids
398  aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
399 
400  aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
401  aGrid->AutoSizeColumns( false );
402 
403  wxGridCellAttr* attr;
404 
405  attr = new wxGridCellAttr;
406  attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &m_lastBrowseDir,
407  wxEmptyString ) );
408  aGrid->SetColAttr( COL_URI, attr );
409 
410  attr = new wxGridCellAttr;
411  attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
412  aGrid->SetColAttr( COL_TYPE, attr );
413 
414  attr = new wxGridCellAttr;
415  attr->SetRenderer( new wxGridCellBoolRenderer() );
416  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
417  aGrid->SetColAttr( COL_ENABLED, attr );
418 
419  // all but COL_OPTIONS, which is edited with Option Editor anyways.
420  aGrid->AutoSizeColumn( COL_NICKNAME, false );
421  aGrid->AutoSizeColumn( COL_TYPE, false );
422  aGrid->AutoSizeColumn( COL_URI, false );
423  aGrid->AutoSizeColumn( COL_DESCR, false );
424 
425  // would set this to width of title, if it was easily known.
426  aGrid->SetColSize( COL_OPTIONS, 80 );
427 
428  // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
429  // a currentCell which is sometimes not highlighted.
430  if( aGrid->GetNumberRows() > 0 )
431  aGrid->SelectRow( 0 );
432  };
433 
434  setupGrid( m_global_grid );
435 
437 
438  if( aProject )
439  {
440  m_PrjTableFilename->SetLabel( aProjectTblPath );
441  m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true );
442  setupGrid( m_project_grid );
443  }
444  else
445  {
446  m_pageNdx = 0;
447  m_auinotebook->DeletePage( 1 );
448  m_project_grid = nullptr;
449  }
450 
451  m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
452  m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
453 
454  // select the last selected page
455  m_auinotebook->SetSelection( m_pageNdx );
457 
458  // for ALT+A handling, we want the initial focus to be on the first selected grid.
460 
461  // Configure button logos
462  m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) );
463  m_delete_button->SetBitmap( KiBitmap( trash_xpm ) );
464  m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) );
465  m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) );
467 
468  // For aesthetic reasons, we must set the size of m_browseButton to match
469  // the other bitmaps manually (for instance m_append_button)
470  Layout(); // Needed at least on MSW to compute the actual buttons sizes,
471  // after initializing their bitmaps
472  wxSize buttonSize = m_append_button->GetSize();
473 
475  m_browseButton->SetMinSize( buttonSize );
476 
477  // Populate the browse library options
478  wxMenu* browseMenu = m_browseButton->GetSplitButtonMenu();
479 
480  for( auto& fileType : fileTypes() )
481  {
482  browseMenu->Append( fileType.first, fileType.second.m_Description );
483 
484  browseMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_FP_LIB_TABLE::browseLibrariesHandler,
485  this, fileType.first );
486  }
487 
488  Layout();
489 
490  // This is the button only press for the browse button instead of the menu
491  m_browseButton->Bind( wxEVT_BUTTON, &PANEL_FP_LIB_TABLE::browseLibrariesHandler, this );
492 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
void SetBitmap(const wxBitmap &aBmp)
static const std::map< int, supportedFileType > & fileTypes()
Map with event id as the key to supported file types that will be listed for the add a library option...
wxMenu * GetSplitButtonMenu()
FP_LIB_TABLE * m_project
void SetMinSize(const wxSize &aSize) override
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
static wxString m_lastBrowseDir
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:59
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:80
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
Geda PCB file formats.
Definition: io_mgr.h:63
static size_t m_pageNdx
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE small_down_xpm[1]
Definition: small_down.cpp:25
PANEL_FP_LIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:269
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:26
void browseLibrariesHandler(wxCommandEvent &event)
void SetWidthPadding(int aPadding)
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
#define _(s)
Definition: 3d_actions.cpp:33
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
S-expression Pcbnew file format.
Definition: io_mgr.h:57

References _, browseLibrariesHandler(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, IO_MGR::EAGLE, fileType(), fileTypes(), folder_xpm, IO_MGR::GEDA_PCB, SPLIT_BUTTON::GetSplitButtonMenu(), KiBitmap(), IO_MGR::KICAD_SEXP, IO_MGR::LEGACY, PANEL_FP_LIB_TABLE_BASE::m_append_button, PANEL_FP_LIB_TABLE_BASE::m_auinotebook, PANEL_FP_LIB_TABLE_BASE::m_browseButton, m_cur_grid, PANEL_FP_LIB_TABLE_BASE::m_delete_button, PANEL_FP_LIB_TABLE_BASE::m_GblTableFilename, PANEL_FP_LIB_TABLE_BASE::m_global_grid, m_lastBrowseDir, PANEL_FP_LIB_TABLE_BASE::m_move_down_button, PANEL_FP_LIB_TABLE_BASE::m_move_up_button, m_pageNdx, m_parent, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, PANEL_FP_LIB_TABLE_BASE::m_PrjTableFilename, PANEL_FP_LIB_TABLE_BASE::m_project_grid, populateEnvironReadOnlyTable(), SPLIT_BUTTON::SetBitmap(), DIALOG_SHIM::SetInitialFocus(), SPLIT_BUTTON::SetMinSize(), WX_GRID::SetTable(), SPLIT_BUTTON::SetWidthPadding(), IO_MGR::ShowType(), small_down_xpm, small_plus_xpm, small_up_xpm, and trash_xpm.

◆ ~PANEL_FP_LIB_TABLE()

PANEL_FP_LIB_TABLE::~PANEL_FP_LIB_TABLE ( )
override

Definition at line 495 of file panel_fp_lib_table.cpp.

496 {
497  // When the dialog is closed it will hide the current notebook page first, which will
498  // in turn select the other one. We then end up saving its index as the "current page".
499  // So flip them back again:
500  m_pageNdx = m_pageNdx == 1 ? 0 : 1;
501 
502  // Delete the GRID_TRICKS.
503  // Any additional event handlers should be popped before the window is deleted.
504  m_global_grid->PopEventHandler( true );
505 
506  if( m_project_grid )
507  m_project_grid->PopEventHandler( true );
508 
509  m_path_subs_grid->PopEventHandler( true );
510 }
static size_t m_pageNdx

References PANEL_FP_LIB_TABLE_BASE::m_global_grid, m_pageNdx, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, and PANEL_FP_LIB_TABLE_BASE::m_project_grid.

Member Function Documentation

◆ adjustPathSubsGridColumns()

void PANEL_FP_LIB_TABLE::adjustPathSubsGridColumns ( int  aWidth)
private

Definition at line 895 of file panel_fp_lib_table.cpp.

896 {
897  // Account for scroll bars
898  aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
899 
900  m_path_subs_grid->AutoSizeColumn( 0 );
901  m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) );
902 }

References PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid.

Referenced by onSizeGrid(), and populateEnvironReadOnlyTable().

◆ appendRowHandler()

void PANEL_FP_LIB_TABLE::appendRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 608 of file panel_fp_lib_table.cpp.

609 {
611  return;
612 
613  if( m_cur_grid->AppendRows( 1 ) )
614  {
615  int last_row = m_cur_grid->GetNumberRows() - 1;
616 
617  // wx documentation is wrong, SetGridCursor does not make visible.
618  m_cur_grid->MakeCellVisible( last_row, 0 );
619  m_cur_grid->SetGridCursor( last_row, 1 );
620  m_cur_grid->EnableCellEditControl( true );
621  m_cur_grid->ShowCellEditControl();
622  }
623 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ browseLibrariesHandler()

void PANEL_FP_LIB_TABLE::browseLibrariesHandler ( wxCommandEvent &  event)
private

Definition at line 746 of file panel_fp_lib_table.cpp.

747 {
749  return;
750 
751  std::map<int, supportedFileType>::const_iterator fileTypeIt;
752 
753  // We are bound both to the menu and button with this one handler
754  // So we must set the file type based on it
755  if( event.GetEventType() == wxEVT_BUTTON )
756  {
757  // Let's default to adding a kicad module for just the module
758  fileTypeIt = fileTypes().find( ID_PANEL_FPLIB_ADD_KICADMOD );
759  }
760  else
761  {
762  fileTypeIt = fileTypes().find( event.GetId() );
763  }
764 
765  if( fileTypeIt == fileTypes().end() )
766  {
767  wxLogWarning( "File type selection event received but could not find the file type in the table" );
768  return;
769  }
770 
771  supportedFileType fileType = fileTypeIt->second;
772 
773  if( m_lastBrowseDir.IsEmpty() )
775 
776  wxArrayString files;
777 
778  wxString title;
779 
780  title.Printf( _( "Select %s Library" ), fileType.m_Description );
781 
782  if( fileType.m_IsFile )
783  {
784  wxFileDialog dlg( this, title, m_lastBrowseDir, wxEmptyString,
785  fileType.m_FileFilter, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
786 
787  int result = dlg.ShowModal();
788 
789  if( result == wxID_CANCEL )
790  return;
791 
792  dlg.GetPaths( files );
793 
794  m_lastBrowseDir = dlg.GetDirectory();
795  }
796  else
797  {
798  wxDirDialog dlg( nullptr, title, m_lastBrowseDir,
799  wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
800 
801  int result = dlg.ShowModal();
802 
803  if( result == wxID_CANCEL )
804  return;
805 
806  // is there a file extension configured to hunt out their containing folders?
807  if( fileType.m_FolderSearchExtension != "" )
808  {
809  wxDir rootDir( dlg.GetPath() );
810 
811  LIBRARY_TRAVERSER traverser( fileType.m_FolderSearchExtension, rootDir.GetName() );
812  rootDir.Traverse( traverser );
813 
814  traverser.GetPaths( files );
815 
816  if( traverser.HasDirectoryOpenFailures() )
817  {
818  wxArrayString failedDirs;
819  traverser.GetPaths( failedDirs );
820  wxString detailedMsg = _( "The following directories could not be opened: \n" );
821 
822  for( auto& path : failedDirs )
823  detailedMsg << path << "\n";
824 
825  DisplayErrorMessage( this, _( "Failed to open directories to look for libraries" ),
826  detailedMsg );
827  }
828  }
829  else
830  {
831  files.Add( dlg.GetPath() );
832  }
833 
834  m_lastBrowseDir = dlg.GetPath();
835  }
836 
837  // Drop the last directory if the path is a .pretty folder
839  m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() );
840 
841  const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
842  bool addDuplicates = false;
843  bool applyToAll = false;
844  wxString warning = _( "Warning: Duplicate Nickname" );
845  wxString msg = _( "A library nicknamed \"%s\" already exists." );
846  wxString detailedMsg = _( "Please change the library nickname after adding this library." );
847 
848  for( const auto& filePath : files )
849  {
850  wxFileName fn( filePath );
851  wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB );
852  bool doAdd = true;
853 
854  if( cur_model()->ContainsNickname( nickname ) )
855  {
856  if( !applyToAll )
857  {
858  // The cancel button adds the library to the table anyway
859  addDuplicates = ( OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
860  detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL );
861  }
862 
863  doAdd = addDuplicates;
864  }
865 
866  if( doAdd && m_cur_grid->AppendRows( 1 ) )
867  {
868  int last_row = m_cur_grid->GetNumberRows() - 1;
869 
870  m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
871 
872  m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( fileType.m_Plugin ) );
873 
874  // try to use path normalized to an environmental variable or project path
875  wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );
876 
877  // Do not use the project path in the global library table. This will almost
878  // assuredly be wrong for a different project.
879  if( path.IsEmpty() || ( m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" ) ) )
880  path = fn.GetFullPath();
881 
882  m_cur_grid->SetCellValue( last_row, COL_URI, path );
883  }
884  }
885 
886  if( !files.IsEmpty() )
887  {
888  int new_row = m_cur_grid->GetNumberRows() - 1;
889  m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
890  m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
891  }
892 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
static const std::map< int, supportedFileType > & fileTypes()
Map with event id as the key to supported file types that will be listed for the add a library option...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
bool ContainsNickname(const wxString &aNickname)
static wxString m_lastBrowseDir
Container that describes file type info for the add a library options.
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:80
static size_t m_pageNdx
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:117
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:269
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Displays a warning dialog with aMessage and returns the user response.
Definition: confirm.cpp:214
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
void GetPaths(wxArrayString &aPathArray)
Traverser implementation that looks to find any and all "folder" libraries by looking for files with ...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
const std::string KiCadFootprintLibPathExtension
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes a file path to an environmental variable, if possible.
Definition: env_paths.cpp:68

References _, COL_NICKNAME, COL_TYPE, COL_URI, WX_GRID::CommitPendingChanges(), LIB_TABLE_GRID::ContainsNickname(), cur_model(), DisplayErrorMessage(), fileType(), fileTypes(), LIB_ID::FixIllegalChars(), Format(), LIBRARY_TRAVERSER::GetPaths(), ID_PANEL_FPLIB_ADD_KICADMOD, LIB_ID::ID_PCB, KiCadFootprintLibPathExtension, m_cur_grid, m_lastBrowseDir, m_pageNdx, m_projectBasePath, NormalizePath(), OKOrCancelDialog(), Pgm(), and IO_MGR::ShowType().

Referenced by PANEL_FP_LIB_TABLE().

◆ cur_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::cur_model ( ) const
inlineprivate

Definition at line 83 of file panel_fp_lib_table.h.

84  {
85  return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable();
86  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References m_cur_grid.

Referenced by browseLibrariesHandler(), moveDownHandler(), moveUpHandler(), and verifyTables().

◆ deleteRowHandler()

void PANEL_FP_LIB_TABLE::deleteRowHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 626 of file panel_fp_lib_table.cpp.

627 {
629  return;
630 
631  int curRow = m_cur_grid->GetGridCursorRow();
632  int curCol = m_cur_grid->GetGridCursorCol();
633 
634  // In a wxGrid, collect rows that have a selected cell, or are selected
635  // It is not so easy: it depends on the way the selection was made.
636  // Here, we collect rows selected by clicking on a row label, and rows that contain any
637  // previously-selected cells.
638  // If no candidate, just delete the row with the grid cursor.
639  wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
640  wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
641  wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
642  wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
643 
644  // Add all row having cell selected to list:
645  for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
646  selectedRows.Add( cells[ii].GetRow() );
647 
648  // Handle block selection
649  if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
650  {
651  for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
652  selectedRows.Add( i );
653  }
654 
655  // Use the row having the grid cursor only if we have no candidate:
656  if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
657  selectedRows.Add( m_cur_grid->GetGridCursorRow() );
658 
659  if( selectedRows.size() == 0 )
660  {
661  wxBell();
662  return;
663  }
664 
665  std::sort( selectedRows.begin(), selectedRows.end() );
666 
667  // Remove selected rows (note: a row can be stored more than once in list)
668  int last_row = -1;
669 
670  for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
671  {
672  int row = selectedRows[ii];
673 
674  if( row != last_row )
675  {
676  last_row = row;
677  m_cur_grid->DeleteRows( row, 1 );
678  }
679  }
680 
681  if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
682  m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
683 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

References WX_GRID::CommitPendingChanges(), and m_cur_grid.

◆ global_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::global_model ( ) const
inlineprivate

Definition at line 73 of file panel_fp_lib_table.h.

74  {
75  return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable();
76  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References PANEL_FP_LIB_TABLE_BASE::m_global_grid.

Referenced by populateEnvironReadOnlyTable(), TransferDataFromWindow(), and verifyTables().

◆ moveDownHandler()

void PANEL_FP_LIB_TABLE::moveDownHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 716 of file panel_fp_lib_table.cpp.

717 {
719  return;
720 
721  FP_LIB_TABLE_GRID* tbl = cur_model();
722  int curRow = m_cur_grid->GetGridCursorRow();
723 
724  // @todo: add multiple selection moves.
725  if( unsigned( curRow + 1 ) < tbl->rows.size() )
726  {
727  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
728  tbl->rows.release( tbl->rows.begin() + curRow );
729 
730  ++curRow;
731  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
732 
733  if( tbl->GetView() )
734  {
735  // Update the wxGrid
736  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
737  tbl->GetView()->ProcessTableMessage( msg );
738  }
739 
740  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
741  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
742  }
743 }
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References WX_GRID::CommitPendingChanges(), cur_model(), m_cur_grid, and LIB_TABLE::rows.

◆ moveUpHandler()

void PANEL_FP_LIB_TABLE::moveUpHandler ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 686 of file panel_fp_lib_table.cpp.

687 {
689  return;
690 
691  FP_LIB_TABLE_GRID* tbl = cur_model();
692  int curRow = m_cur_grid->GetGridCursorRow();
693 
694  // @todo: add multiple selection moves.
695  if( curRow >= 1 )
696  {
697  boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
698  tbl->rows.release( tbl->rows.begin() + curRow );
699 
700  --curRow;
701  tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
702 
703  if( tbl->GetView() )
704  {
705  // Update the wxGrid
706  wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
707  tbl->GetView()->ProcessTableMessage( msg );
708  }
709 
710  m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
711  m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
712  }
713 }
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * cur_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References WX_GRID::CommitPendingChanges(), cur_model(), m_cur_grid, and LIB_TABLE::rows.

◆ onSizeGrid()

void PANEL_FP_LIB_TABLE::onSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_LIB_TABLE_BASE.

Definition at line 905 of file panel_fp_lib_table.cpp.

906 {
907  adjustPathSubsGridColumns( event.GetSize().GetX() );
908 
909  event.Skip();
910 }
void adjustPathSubsGridColumns(int aWidth)

References adjustPathSubsGridColumns().

◆ pageChangedHandler()

void PANEL_FP_LIB_TABLE::pageChangedHandler ( wxAuiNotebookEvent &  event)
overrideprivatevirtual

◆ populateEnvironReadOnlyTable()

void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable ( )
private

Populate the readonly environment variable table with names and values by examining all the full_uri columns.

Definition at line 949 of file panel_fp_lib_table.cpp.

950 {
951  wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
952  wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
953 
954  std::set< wxString > unique;
955 
956  // clear the table
957  m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
958 
959  for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
960  {
961  if( !tbl )
962  continue;
963 
964  for( int row = 0; row < tbl->GetNumberRows(); ++row )
965  {
966  wxString uri = tbl->GetValue( row, COL_URI );
967 
968  while( re.Matches( uri ) )
969  {
970  wxString envvar = re.GetMatch( uri, 2 );
971 
972  // if not ${...} form then must be $(...)
973  if( envvar.IsEmpty() )
974  envvar = re.GetMatch( uri, 4 );
975 
976  // ignore duplicates
977  unique.insert( envvar );
978 
979  // delete the last match and search again
980  uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
981  }
982  }
983  }
984 
985  // Make sure this special environment variable shows up even if it was
986  // not used yet. It is automatically set by KiCad to the directory holding
987  // the current project.
988  unique.insert( PROJECT_VAR_NAME );
989  unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
990  // This special environment variable is used to locate 3d shapes
991  unique.insert( KISYS3DMOD );
992 
993  for( const wxString& evName : unique )
994  {
995  int row = m_path_subs_grid->GetNumberRows();
996  m_path_subs_grid->AppendRows( 1 );
997 
998  m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
999  m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
1000 
1001  wxString evValue;
1002  wxGetEnv( evName, &evValue );
1003  m_path_subs_grid->SetCellValue( row, 1, evValue );
1004  m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
1005  }
1006 
1007  // No combobox editors here, but it looks better if its consistent with the other
1008  // grids in the dialog.
1009  m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
1010 
1011  adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
1012 }
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
void adjustPathSubsGridColumns(int aWidth)
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References adjustPathSubsGridColumns(), COL_URI, global_model(), FP_LIB_TABLE::GlobalPathEnvVariableName(), KISYS3DMOD, PANEL_FP_LIB_TABLE_BASE::m_path_subs_grid, project_model(), and PROJECT_VAR_NAME.

Referenced by PANEL_FP_LIB_TABLE().

◆ project_model()

FP_LIB_TABLE_GRID* PANEL_FP_LIB_TABLE::project_model ( ) const
inlineprivate

Definition at line 78 of file panel_fp_lib_table.h.

79  {
80  return m_project_grid ? (FP_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
81  }
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References PANEL_FP_LIB_TABLE_BASE::m_project_grid.

Referenced by populateEnvironReadOnlyTable(), TransferDataFromWindow(), and verifyTables().

◆ TransferDataFromWindow()

bool PANEL_FP_LIB_TABLE::TransferDataFromWindow ( )
overrideprivate

Definition at line 913 of file panel_fp_lib_table.cpp.

914 {
916  return false;
917 
918  if( verifyTables() )
919  {
920  if( *global_model() != *m_global )
921  {
923 
924  m_global->Clear();
925  m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(),
926  global_model()->rows.end(), global_model()->rows );
927  m_global->reindex();
928  }
929 
930  if( project_model() && *project_model() != *m_project )
931  {
933 
934  m_project->Clear();
935  m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(),
936  project_model()->rows.end(), project_model()->rows );
937  m_project->reindex();
938  }
939 
940  return true;
941  }
942 
943  return false;
944 }
void Clear()
Delete all rows.
void reindex()
FP_LIB_TABLE * m_project
LIB_TABLE_ROWS rows
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
DIALOG_EDIT_LIBRARY_TABLES * m_parent
FP_LIB_TABLE * m_global

References LIB_TABLE::Clear(), WX_GRID::CommitPendingChanges(), global_model(), m_cur_grid, m_global, DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, m_parent, m_project, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, project_model(), LIB_TABLE::reindex(), LIB_TABLE::rows, and verifyTables().

◆ verifyTables()

bool PANEL_FP_LIB_TABLE::verifyTables ( )
private

Trim important fields, removes blank row entries, and checks for duplicates.

Returns
bool - true if tables are OK, else false.

Definition at line 513 of file panel_fp_lib_table.cpp.

514 {
515  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
516  {
517  if( !model )
518  continue;
519 
520  for( int r = 0; r < model->GetNumberRows(); )
521  {
522  wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
523  wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
524  unsigned illegalCh = 0;
525 
526  if( !nick || !uri )
527  {
528  // Delete the "empty" row, where empty means missing nick or uri.
529  // This also updates the UI which could be slow, but there should only be a few
530  // rows to delete, unless the user fell asleep on the Add Row
531  // button.
532  model->DeleteRows( r, 1 );
533  }
534  else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) )
535  {
536  wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
537  illegalCh,
538  nick );
539 
540  // show the tabbed panel holding the grid we have flunked:
541  if( model != cur_model() )
542  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
543 
544  m_cur_grid->MakeCellVisible( r, 0 );
545  m_cur_grid->SetGridCursor( r, 1 );
546 
547  wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
548  errdlg.ShowModal();
549  return false;
550  }
551  else
552  {
553  // set the trimmed values back into the table so they get saved to disk.
554  model->SetValue( r, COL_NICKNAME, nick );
555  model->SetValue( r, COL_URI, uri );
556  ++r; // this row was OK.
557  }
558  }
559  }
560 
561  // check for duplicate nickNames, separately in each table.
562  for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } )
563  {
564  if( !model )
565  continue;
566 
567  for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
568  {
569  wxString nick1 = model->GetValue( r1, COL_NICKNAME );
570 
571  for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 )
572  {
573  wxString nick2 = model->GetValue( r2, COL_NICKNAME );
574 
575  if( nick1 == nick2 )
576  {
577  wxString msg = wxString::Format( _( "Duplicate Nicknames \"%s\"." ), nick1 );
578 
579  // show the tabbed panel holding the grid we have flunked:
580  if( model != cur_model() )
581  m_auinotebook->SetSelection( model == global_model() ? 0 : 1 );
582 
583  // go to the lower of the two rows, it is technically the duplicate:
584  m_cur_grid->MakeCellVisible( r2, 0 );
585  m_cur_grid->SetGridCursor( r2, 1 );
586 
587  wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
588  errdlg.ShowModal();
589  return false;
590  }
591  }
592  }
593  }
594 
595  return true;
596 }
static unsigned FindIllegalLibNicknameChar(const UTF8 &aNickname, LIB_ID_TYPE aType)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:404
FP_LIB_TABLE_GRID * global_model() const
FP_LIB_TABLE_GRID * project_model() const
FP_LIB_TABLE_GRID * cur_model() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

References _, COL_NICKNAME, COL_URI, cur_model(), LIB_ID::FindIllegalLibNicknameChar(), Format(), global_model(), LIB_ID::ID_PCB, PANEL_FP_LIB_TABLE_BASE::m_auinotebook, m_cur_grid, and project_model().

Referenced by TransferDataFromWindow().

Member Data Documentation

◆ m_append_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_append_button
protectedinherited

◆ m_auinotebook

wxAuiNotebook* PANEL_FP_LIB_TABLE_BASE::m_auinotebook
protectedinherited

◆ m_browseButton

SPLIT_BUTTON* PANEL_FP_LIB_TABLE_BASE::m_browseButton
protectedinherited

◆ m_cur_grid

◆ m_delete_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_delete_button
protectedinherited

◆ m_GblTableFilename

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_GblTableFilename
protectedinherited

◆ m_global

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_global
private

Definition at line 69 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_global_grid

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_global_grid
protectedinherited

◆ m_global_panel

wxPanel* PANEL_FP_LIB_TABLE_BASE::m_global_panel
protectedinherited

◆ m_lastBrowseDir

wxString PANEL_FP_LIB_TABLE::m_lastBrowseDir
staticprivate

Definition at line 92 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler(), and PANEL_FP_LIB_TABLE().

◆ m_move_down_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_down_button
protectedinherited

◆ m_move_up_button

wxBitmapButton* PANEL_FP_LIB_TABLE_BASE::m_move_up_button
protectedinherited

◆ m_pageNdx

size_t PANEL_FP_LIB_TABLE::m_pageNdx = 0
staticprivate

◆ m_parent

DIALOG_EDIT_LIBRARY_TABLES* PANEL_FP_LIB_TABLE::m_parent
private

Definition at line 88 of file panel_fp_lib_table.h.

Referenced by PANEL_FP_LIB_TABLE(), and TransferDataFromWindow().

◆ m_path_subs_grid

◆ m_PrjTableFilename

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_PrjTableFilename
protectedinherited

◆ m_project

FP_LIB_TABLE* PANEL_FP_LIB_TABLE::m_project
private

Definition at line 70 of file panel_fp_lib_table.h.

Referenced by TransferDataFromWindow().

◆ m_project_grid

WX_GRID* PANEL_FP_LIB_TABLE_BASE::m_project_grid
protectedinherited

◆ m_project_panel

wxPanel* PANEL_FP_LIB_TABLE_BASE::m_project_panel
protectedinherited

◆ m_projectBasePath

wxString PANEL_FP_LIB_TABLE::m_projectBasePath
private

Definition at line 71 of file panel_fp_lib_table.h.

Referenced by browseLibrariesHandler().

◆ m_staticText3

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText3
protectedinherited

◆ m_staticText4

wxStaticText* PANEL_FP_LIB_TABLE_BASE::m_staticText4
protectedinherited

The documentation for this class was generated from the following files: