2017-08-12 12:09:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-02-18 11:17:20 +00:00
|
|
|
* Copyright (C) 2021 CERN
|
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-08-12 12:09:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <wx/regex.h>
|
|
|
|
|
2021-04-02 23:29:47 +00:00
|
|
|
#include <common.h> // For ExpandEnvVarSubstitutions
|
2017-08-12 12:09:39 +00:00
|
|
|
#include <project.h>
|
2018-07-20 17:46:56 +00:00
|
|
|
#include <panel_sym_lib_table.h>
|
2017-08-12 12:09:39 +00:00
|
|
|
#include <lib_id.h>
|
|
|
|
#include <symbol_lib_table.h>
|
|
|
|
#include <lib_table_lexer.h>
|
|
|
|
#include <grid_tricks.h>
|
2018-08-19 16:10:14 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2017-08-12 12:09:39 +00:00
|
|
|
#include <confirm.h>
|
2018-03-14 04:51:59 +00:00
|
|
|
#include <bitmaps.h>
|
2017-08-12 12:09:39 +00:00
|
|
|
#include <lib_table_grid.h>
|
2017-11-14 10:18:45 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <env_paths.h>
|
2020-02-28 14:03:09 +00:00
|
|
|
#include <eeschema_id.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2019-04-30 17:03:19 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-08-06 18:33:28 +00:00
|
|
|
#include <kiway.h>
|
2021-01-31 23:59:47 +00:00
|
|
|
#include <paths.h>
|
2020-09-01 02:00:38 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2018-09-12 12:59:33 +00:00
|
|
|
#include <widgets/grid_readonly_text_helpers.h>
|
2018-11-24 14:40:02 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2020-12-13 11:39:53 +00:00
|
|
|
#include <sch_file_versions.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container that describes file type info for the add a library options
|
|
|
|
*/
|
2021-02-18 11:17:20 +00:00
|
|
|
struct SUPPORTED_FILE_TYPE
|
2020-02-28 14:03:09 +00:00
|
|
|
{
|
|
|
|
wxString m_Description; ///< Description shown in the file picker dialog
|
|
|
|
wxString m_FileFilter; ///< Filter used for file pickers if m_IsFile is true
|
|
|
|
wxString m_FolderSearchExtension; ///< In case of folders it stands for extensions of files stored inside
|
|
|
|
bool m_IsFile; ///< Whether the library is a folder or a file
|
|
|
|
SCH_IO_MGR::SCH_FILE_T m_Plugin;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event IDs for the menu items in the split button menu for add a library
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
ID_PANEL_SYM_LIB_KICAD = ID_END_EESCHEMA_ID_LIST,
|
|
|
|
ID_PANEL_SYM_LIB_LEGACY,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
/**
|
|
|
|
* Build a wxGridTableBase by wrapping an #SYMBOL_LIB_TABLE object.
|
|
|
|
*/
|
|
|
|
class SYMBOL_LIB_TABLE_GRID : public LIB_TABLE_GRID, public SYMBOL_LIB_TABLE
|
|
|
|
{
|
|
|
|
friend class SYMBOL_GRID_TRICKS;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LIB_TABLE_ROW* at( size_t aIndex ) override { return &rows.at( aIndex ); }
|
|
|
|
|
|
|
|
size_t size() const override { return rows.size(); }
|
|
|
|
|
|
|
|
LIB_TABLE_ROW* makeNewRow() override
|
|
|
|
{
|
|
|
|
return dynamic_cast< LIB_TABLE_ROW* >( new SYMBOL_LIB_TABLE_ROW );
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_TABLE_ROWS_ITER begin() override { return rows.begin(); }
|
|
|
|
|
|
|
|
LIB_TABLE_ROWS_ITER insert( LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW* aRow ) override
|
|
|
|
{
|
|
|
|
return rows.insert( aIterator, aRow );
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_back( LIB_TABLE_ROW* aRow ) override { rows.push_back( aRow ); }
|
|
|
|
|
|
|
|
LIB_TABLE_ROWS_ITER erase( LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast ) override
|
|
|
|
{
|
|
|
|
return rows.erase( aFirst, aLast );
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-07-04 17:20:30 +00:00
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
|
|
|
{
|
|
|
|
LIB_TABLE_GRID::SetValue( aRow, aCol, aValue );
|
|
|
|
|
|
|
|
// If setting a filepath, attempt to auto-detect the format
|
|
|
|
if( aCol == COL_URI )
|
|
|
|
{
|
|
|
|
wxFileName fn( aValue );
|
|
|
|
|
|
|
|
for( SCH_IO_MGR::SCH_FILE_T piType : SCH_IO_MGR::SCH_FILE_T_vector )
|
|
|
|
{
|
|
|
|
if( SCH_IO_MGR::GetLibraryFileExtension( piType ).Lower() == fn.GetExt().Lower() )
|
|
|
|
{
|
|
|
|
SetValue( aRow, COL_TYPE, SCH_IO_MGR::ShowType( piType ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE_GRID( const SYMBOL_LIB_TABLE& aTableToEdit )
|
|
|
|
{
|
|
|
|
rows = aTableToEdit.rows;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SYMBOL_GRID_TRICKS : public GRID_TRICKS
|
|
|
|
{
|
|
|
|
public:
|
2019-03-04 11:02:12 +00:00
|
|
|
SYMBOL_GRID_TRICKS( DIALOG_EDIT_LIBRARY_TABLES* aParent, WX_GRID* aGrid ) :
|
2018-07-20 17:46:56 +00:00
|
|
|
GRID_TRICKS( aGrid ),
|
|
|
|
m_dialog( aParent )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-07-20 17:46:56 +00:00
|
|
|
DIALOG_EDIT_LIBRARY_TABLES* m_dialog;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
/// handle specialized clipboard text, with leading "(sym_lib_table" or
|
|
|
|
/// spreadsheet formatted text.
|
|
|
|
virtual void paste_text( const wxString& cb_text ) override
|
|
|
|
{
|
2018-07-20 17:46:56 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* tbl = (SYMBOL_LIB_TABLE_GRID*) m_grid->GetTable();
|
|
|
|
size_t ndx = cb_text.find( "(sym_lib_table" );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
if( ndx != std::string::npos )
|
|
|
|
{
|
|
|
|
// paste the SYMBOL_LIB_TABLE_ROWs of s-expression (sym_lib_table), starting
|
|
|
|
// at column 0 regardless of current cursor column.
|
|
|
|
|
|
|
|
STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
|
|
|
|
LIB_TABLE_LEXER lexer( &slr );
|
|
|
|
SYMBOL_LIB_TABLE tmp_tbl;
|
|
|
|
bool parsed = true;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tmp_tbl.Parse( &lexer );
|
|
|
|
}
|
|
|
|
catch( PARSE_ERROR& pe )
|
|
|
|
{
|
2018-07-20 17:46:56 +00:00
|
|
|
DisplayError( m_dialog, pe.What() );
|
2017-08-12 12:09:39 +00:00
|
|
|
parsed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parsed )
|
|
|
|
{
|
2018-03-14 04:51:59 +00:00
|
|
|
// make sure the table is big enough...
|
2019-02-02 21:50:36 +00:00
|
|
|
if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
|
2018-03-14 04:51:59 +00:00
|
|
|
tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2019-02-02 21:50:36 +00:00
|
|
|
for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
|
|
|
|
tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_grid->AutoSizeColumns( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// paste spreadsheet formatted text.
|
|
|
|
GRID_TRICKS::paste_text( cb_text );
|
2018-03-14 04:51:59 +00:00
|
|
|
|
|
|
|
m_grid->AutoSizeColumns( false );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-04 17:20:30 +00:00
|
|
|
PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject,
|
2020-12-13 11:39:53 +00:00
|
|
|
SYMBOL_LIB_TABLE* aGlobalTable,
|
2018-08-06 18:33:28 +00:00
|
|
|
const wxString& aGlobalTablePath,
|
2020-12-13 11:39:53 +00:00
|
|
|
SYMBOL_LIB_TABLE* aProjectTable,
|
|
|
|
const wxString& aProjectTablePath ) :
|
2018-07-20 17:46:56 +00:00
|
|
|
PANEL_SYM_LIB_TABLE_BASE( aParent ),
|
2020-12-13 11:39:53 +00:00
|
|
|
m_globalTable( aGlobalTable ),
|
|
|
|
m_projectTable( aProjectTable ),
|
|
|
|
m_project( aProject ),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_parent( aParent )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
// wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
|
|
|
|
// so make it a grid owned table.
|
2020-12-13 11:39:53 +00:00
|
|
|
m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *m_globalTable ), true );
|
2020-08-07 19:22:15 +00:00
|
|
|
|
|
|
|
wxArrayString pluginChoices;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD ) );
|
|
|
|
pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
|
2018-03-14 04:51:59 +00:00
|
|
|
|
2020-09-01 02:00:38 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
|
|
|
|
|
|
|
if( cfg->m_lastSymbolLibDir.IsEmpty() )
|
2021-01-31 23:59:47 +00:00
|
|
|
cfg->m_lastSymbolLibDir = PATHS::GetDefaultUserSymbolsPath();
|
|
|
|
|
|
|
|
m_lastProjectLibDir = m_project->GetProjectPath();
|
2020-09-01 02:00:38 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
auto setupGrid =
|
|
|
|
[&]( WX_GRID* aGrid )
|
|
|
|
{
|
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
// add Cut, Copy, and Paste to wxGrids
|
|
|
|
aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, aGrid ) );
|
2018-08-19 16:10:42 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
|
|
|
aGrid->AutoSizeColumns( false );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
// Set special attributes
|
|
|
|
wxGridCellAttr* attr;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
attr = new wxGridCellAttr;
|
2020-09-01 02:00:38 +00:00
|
|
|
|
|
|
|
wxString wildcards = AllSymbolLibFilesWildcard()
|
|
|
|
+ "|" + KiCadSymbolLibFileWildcard()
|
|
|
|
+ "|" + LegacySymbolLibFileWildcard();
|
2021-02-17 14:06:19 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
|
|
|
|
&cfg->m_lastSymbolLibDir, wildcards,
|
|
|
|
true, m_project->GetProjectPath() ) );
|
2020-08-07 19:22:15 +00:00
|
|
|
aGrid->SetColAttr( COL_URI, attr );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
|
|
|
|
aGrid->SetColAttr( COL_TYPE, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
aGrid->SetColAttr( COL_ENABLED, attr );
|
|
|
|
|
|
|
|
// all but COL_OPTIONS, which is edited with Option Editor anyways.
|
|
|
|
aGrid->AutoSizeColumn( COL_NICKNAME, false );
|
|
|
|
aGrid->AutoSizeColumn( COL_TYPE, false );
|
|
|
|
aGrid->AutoSizeColumn( COL_URI, false );
|
|
|
|
aGrid->AutoSizeColumn( COL_DESCR, false );
|
|
|
|
aGrid->AutoSizeColumn( COL_ENABLED, false );
|
|
|
|
|
|
|
|
// would set this to width of title, if it was easily known.
|
|
|
|
aGrid->SetColSize( COL_OPTIONS, 80 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
// Gives a selection to each grid, mainly for delete button. wxGrid's wake up with
|
|
|
|
// a currentCell which is sometimes not highlighted.
|
|
|
|
if( aGrid->GetNumberRows() > 0 )
|
|
|
|
aGrid->SelectRow( 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
setupGrid( m_global_grid );
|
|
|
|
|
2020-12-13 11:39:53 +00:00
|
|
|
if( m_projectTable )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-12-13 11:39:53 +00:00
|
|
|
m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *m_projectTable ), true );
|
2020-08-07 19:22:15 +00:00
|
|
|
setupGrid( m_project_grid );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
2020-08-07 19:22:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pageNdx = 0;
|
2020-11-01 13:30:27 +00:00
|
|
|
m_notebook->DeletePage( 1 );
|
2020-08-07 19:22:15 +00:00
|
|
|
m_project_grid = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add Cut, Copy, and Paste to wxGrids
|
|
|
|
m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
|
|
|
|
|
|
|
|
populateEnvironReadOnlyTable();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// select the last selected page
|
2020-11-01 13:30:27 +00:00
|
|
|
m_notebook->SetSelection( m_pageNdx );
|
2018-07-23 22:06:26 +00:00
|
|
|
m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid;
|
|
|
|
|
2019-05-14 11:57:27 +00:00
|
|
|
m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
|
|
|
|
m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
|
|
|
|
|
2018-07-23 22:06:26 +00:00
|
|
|
// for ALT+A handling, we want the initial focus to be on the first selected grid.
|
|
|
|
m_parent->SetInitialFocus( m_cur_grid );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
// Configure button logos
|
2021-03-08 02:59:07 +00:00
|
|
|
m_append_button->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_delete_button->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_move_up_button->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
|
|
|
m_move_down_button->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
|
|
|
m_browse_button->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE()
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-06 18:33:28 +00:00
|
|
|
// When the dialog is closed it will hide the current notebook page first, which will
|
|
|
|
// in turn select the other one. We then end up saving its index as the "current page".
|
|
|
|
// So flip them back again:
|
|
|
|
m_pageNdx = m_pageNdx == 1 ? 0 : 1;
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
// Any additional event handlers should be popped before the window is deleted.
|
|
|
|
m_global_grid->PopEventHandler( true );
|
2020-08-07 19:22:15 +00:00
|
|
|
|
|
|
|
if( m_project_grid )
|
|
|
|
m_project_grid->PopEventHandler( true );
|
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
m_path_subs_grid->PopEventHandler( true );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
bool PANEL_SYM_LIB_TABLE::verifyTables()
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2021-05-08 12:58:54 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
if( !model )
|
|
|
|
continue;
|
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
for( int r = 0; r < model->GetNumberRows(); )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-09-12 12:59:33 +00:00
|
|
|
wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
|
|
|
|
wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim();
|
2018-04-13 09:26:28 +00:00
|
|
|
unsigned illegalCh = 0;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
if( !nick || !uri )
|
|
|
|
{
|
2021-05-08 12:58:54 +00:00
|
|
|
if( !nick && !uri )
|
|
|
|
msg = _( "A library table row nickname and path cells are empty." );
|
|
|
|
else if( !nick )
|
|
|
|
msg = _( "A library table row nickname cell is empty." );
|
|
|
|
else
|
|
|
|
msg = _( "A library table row path cell is empty." );
|
|
|
|
|
|
|
|
wxMessageDialog badCellDlg( this, msg, _( "Invalid Row Definition" ),
|
|
|
|
wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
|
|
|
|
badCellDlg.SetExtendedMessage( _( "Empty cells will result in all rows that are "
|
|
|
|
"invalid to be removed from the table." ) );
|
|
|
|
badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( "Remove Invalid Cells" ),
|
|
|
|
wxMessageDialog::ButtonLabel( "Cancel Table Update" ) );
|
|
|
|
|
|
|
|
if( badCellDlg.ShowModal() == wxID_NO )
|
|
|
|
return false;
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
// Delete the "empty" row, where empty means missing nick or uri.
|
|
|
|
// This also updates the UI which could be slow, but there should only be a few
|
|
|
|
// rows to delete, unless the user fell asleep on the Add Row
|
|
|
|
// button.
|
2018-09-12 12:59:33 +00:00
|
|
|
model->DeleteRows( r, 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
2020-12-17 23:32:23 +00:00
|
|
|
else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2021-05-08 12:58:54 +00:00
|
|
|
msg = wxString::Format( _( "Illegal character '%c' in nickname '%s'" ),
|
|
|
|
illegalCh,
|
|
|
|
nick );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// show the tabbed panel holding the grid we have flunked:
|
2018-09-12 12:59:33 +00:00
|
|
|
if( model != cur_model() )
|
2020-11-01 13:30:27 +00:00
|
|
|
m_notebook->SetSelection( model == global_model() ? 0 : 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
m_cur_grid->MakeCellVisible( r, 0 );
|
2018-03-14 04:51:59 +00:00
|
|
|
m_cur_grid->SetGridCursor( r, 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-12-18 00:25:51 +00:00
|
|
|
wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
|
2017-08-12 12:09:39 +00:00
|
|
|
errdlg.ShowModal();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// set the trimmed values back into the table so they get saved to disk.
|
2018-09-12 12:59:33 +00:00
|
|
|
model->SetValue( r, COL_NICKNAME, nick );
|
|
|
|
model->SetValue( r, COL_URI, uri );
|
2017-08-12 12:09:39 +00:00
|
|
|
++r; // this row was OK.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for duplicate nickNames, separately in each table.
|
2018-09-12 12:59:33 +00:00
|
|
|
for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
if( !model )
|
|
|
|
continue;
|
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-09-12 12:59:33 +00:00
|
|
|
wxString nick1 = model->GetValue( r1, COL_NICKNAME );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
for( int r2=r1+1; r2 < model->GetNumberRows(); ++r2 )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-09-12 12:59:33 +00:00
|
|
|
wxString nick2 = model->GetValue( r2, COL_NICKNAME );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
if( nick1 == nick2 )
|
|
|
|
{
|
2021-05-08 12:58:54 +00:00
|
|
|
msg = wxString::Format( _( "Multiple libraries cannot share the same "
|
|
|
|
"nickname ('%s')." ), nick1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// show the tabbed panel holding the grid we have flunked:
|
2018-09-12 12:59:33 +00:00
|
|
|
if( model != cur_model() )
|
2020-11-01 13:30:27 +00:00
|
|
|
m_notebook->SetSelection( model == global_model() ? 0 : 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// go to the lower of the two rows, it is technically the duplicate:
|
|
|
|
m_cur_grid->MakeCellVisible( r2, 0 );
|
2018-03-14 04:51:59 +00:00
|
|
|
m_cur_grid->SetGridCursor( r2, 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2020-12-18 00:25:51 +00:00
|
|
|
wxMessageDialog errdlg( this, msg, _( "Library Nickname Error" ) );
|
2017-08-12 12:09:39 +00:00
|
|
|
errdlg.ShowModal();
|
2018-03-14 04:51:59 +00:00
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 17:32:16 +00:00
|
|
|
for( SYMBOL_LIB_TABLE* table : { global_model(), project_model() } )
|
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
if( !table )
|
|
|
|
continue;
|
|
|
|
|
2020-07-17 17:32:16 +00:00
|
|
|
for( unsigned int r = 0; r < table->GetCount(); ++r )
|
|
|
|
{
|
|
|
|
SYMBOL_LIB_TABLE_ROW& row = dynamic_cast<SYMBOL_LIB_TABLE_ROW&>( table->At( r ) );
|
|
|
|
|
|
|
|
if( !row.GetIsEnabled() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( row.Refresh() )
|
|
|
|
{
|
|
|
|
if( table == global_model() )
|
|
|
|
m_parent->m_GlobalTableChanged = true;
|
|
|
|
else
|
|
|
|
m_parent->m_ProjectTableChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
msg.Printf( _( "Symbol library '%s' failed to load." ), row.GetNickName() );
|
2020-07-17 17:32:16 +00:00
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
wxMessageDialog errdlg( this, msg + wxS( "\n" ) + ioe.What(),
|
|
|
|
_( "Error Loading Library" ) );
|
2020-07-17 17:32:16 +00:00
|
|
|
errdlg.ShowModal();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-14 20:12:49 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-11-01 13:30:27 +00:00
|
|
|
m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
|
2018-07-23 22:06:26 +00:00
|
|
|
m_cur_grid = m_pageNdx == 0 ? m_global_grid : m_project_grid;
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-07-17 17:32:16 +00:00
|
|
|
wxString wildcards = AllSymbolLibFilesWildcard()
|
|
|
|
+ "|" + KiCadSymbolLibFileWildcard()
|
|
|
|
+ "|" + LegacySymbolLibFileWildcard();
|
2020-02-28 14:03:09 +00:00
|
|
|
|
2020-09-01 02:00:38 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
2021-01-31 23:59:47 +00:00
|
|
|
|
|
|
|
wxString openDir = cfg->m_lastSymbolLibDir;
|
2021-07-04 17:20:30 +00:00
|
|
|
|
2021-01-31 23:59:47 +00:00
|
|
|
if( m_cur_grid == m_project_grid )
|
|
|
|
openDir = m_lastProjectLibDir;
|
|
|
|
|
2021-07-04 17:20:30 +00:00
|
|
|
wxFileDialog dlg( this, _( "Select Library" ), openDir, wxEmptyString, wildcards,
|
2018-07-20 17:46:56 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
|
2017-11-14 10:18:45 +00:00
|
|
|
|
2021-02-18 11:17:20 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2017-11-14 10:18:45 +00:00
|
|
|
return;
|
|
|
|
|
2021-01-31 23:59:47 +00:00
|
|
|
if( m_cur_grid == m_global_grid )
|
|
|
|
cfg->m_lastSymbolLibDir = dlg.GetPath();
|
|
|
|
else
|
|
|
|
m_lastProjectLibDir = dlg.GetPath();
|
2018-01-26 17:39:02 +00:00
|
|
|
|
2020-02-14 19:07:27 +00:00
|
|
|
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
|
|
|
|
bool addDuplicates = false;
|
|
|
|
bool applyToAll = false;
|
|
|
|
wxString warning = _( "Warning: Duplicate Nickname" );
|
2020-12-18 00:25:51 +00:00
|
|
|
wxString msg = _( "A library nicknamed '%s' already exists." );
|
|
|
|
wxString detailedMsg = _( "One of the nicknames will need to be changed after "
|
|
|
|
"adding this library." );
|
2020-02-14 19:07:27 +00:00
|
|
|
|
2017-11-14 10:18:45 +00:00
|
|
|
wxArrayString files;
|
|
|
|
dlg.GetFilenames( files );
|
|
|
|
|
2020-12-18 00:25:51 +00:00
|
|
|
for( const wxString& file : files )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-12-18 00:25:51 +00:00
|
|
|
wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
|
2018-05-02 20:20:21 +00:00
|
|
|
wxFileName fn( filePath );
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), true );
|
2020-12-18 00:25:51 +00:00
|
|
|
bool doAdd = true;
|
2018-05-02 20:20:21 +00:00
|
|
|
|
|
|
|
if( cur_model()->ContainsNickname( nickname ) )
|
|
|
|
{
|
2018-08-01 23:06:12 +00:00
|
|
|
if( !applyToAll )
|
2018-05-02 20:20:21 +00:00
|
|
|
{
|
2020-02-14 19:07:27 +00:00
|
|
|
// The cancel button adds the library to the table anyway
|
2020-12-18 00:25:51 +00:00
|
|
|
addDuplicates = OKOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
|
|
|
|
detailedMsg, _( "Skip" ), _( "Add Anyway" ),
|
|
|
|
&applyToAll ) == wxID_CANCEL;
|
2018-05-02 20:20:21 +00:00
|
|
|
}
|
2018-08-01 23:06:12 +00:00
|
|
|
|
|
|
|
doAdd = addDuplicates;
|
2018-05-02 20:20:21 +00:00
|
|
|
}
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-08-01 23:06:12 +00:00
|
|
|
if( doAdd && m_cur_grid->AppendRows( 1 ) )
|
2017-11-14 10:18:45 +00:00
|
|
|
{
|
|
|
|
int last_row = m_cur_grid->GetNumberRows() - 1;
|
|
|
|
|
2018-05-02 20:20:21 +00:00
|
|
|
m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
|
2017-11-14 10:18:45 +00:00
|
|
|
|
2021-07-04 17:20:30 +00:00
|
|
|
// attempt to auto-detect the plugin type
|
2021-02-18 11:17:20 +00:00
|
|
|
for( SCH_IO_MGR::SCH_FILE_T piType : SCH_IO_MGR::SCH_FILE_T_vector )
|
2017-11-14 10:18:45 +00:00
|
|
|
{
|
2021-02-18 11:17:20 +00:00
|
|
|
if( SCH_IO_MGR::GetLibraryFileExtension( piType ).Lower() == fn.GetExt().Lower() )
|
2017-11-14 10:18:45 +00:00
|
|
|
{
|
2021-02-18 11:17:20 +00:00
|
|
|
m_cur_grid->SetCellValue( last_row, COL_TYPE, SCH_IO_MGR::ShowType( piType ) );
|
2017-11-14 10:18:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-28 14:03:09 +00:00
|
|
|
}
|
2017-11-14 10:18:45 +00:00
|
|
|
|
|
|
|
// try to use path normalized to an environmental variable or project path
|
2020-12-13 11:39:53 +00:00
|
|
|
wxString path = NormalizePath( filePath, &envVars, m_project->GetProjectPath() );
|
2018-07-20 17:46:56 +00:00
|
|
|
|
2019-06-25 12:36:32 +00:00
|
|
|
// Do not use the project path in the global library table. This will almost
|
|
|
|
// assuredly be wrong for a different project.
|
2021-09-23 15:44:39 +00:00
|
|
|
if( m_pageNdx == 0 && path.Contains( "${KIPRJMOD}" ) )
|
2018-07-20 17:46:56 +00:00
|
|
|
path = fn.GetFullPath();
|
|
|
|
|
|
|
|
m_cur_grid->SetCellValue( last_row, COL_URI, path );
|
2017-11-14 10:18:45 +00:00
|
|
|
}
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
2017-11-14 10:18:45 +00:00
|
|
|
|
|
|
|
if( !files.IsEmpty() )
|
2018-03-14 04:51:59 +00:00
|
|
|
{
|
|
|
|
m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 );
|
|
|
|
m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 );
|
|
|
|
}
|
2017-11-14 10:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::appendRowHandler( wxCommandEvent& event )
|
2017-11-14 10:18:45 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2017-11-14 10:18:45 +00:00
|
|
|
if( m_cur_grid->AppendRows( 1 ) )
|
2017-11-19 09:04:38 +00:00
|
|
|
{
|
|
|
|
int row = m_cur_grid->GetNumberRows() - 1;
|
2018-03-14 04:51:59 +00:00
|
|
|
|
|
|
|
// wx documentation is wrong, SetGridCursor does not make visible.
|
|
|
|
m_cur_grid->MakeCellVisible( row, 0 );
|
|
|
|
m_cur_grid->SetGridCursor( row, 1 );
|
|
|
|
m_cur_grid->EnableCellEditControl( true );
|
|
|
|
m_cur_grid->ShowCellEditControl();
|
2017-11-19 09:04:38 +00:00
|
|
|
}
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::deleteRowHandler( wxCommandEvent& event )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
int curRow = m_cur_grid->GetGridCursorRow();
|
|
|
|
int curCol = m_cur_grid->GetGridCursorCol();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// In a wxGrid, collect rows that have a selected cell, or are selected
|
2019-08-20 17:22:30 +00:00
|
|
|
// It is not so easy: it depends on the way the selection was made.
|
|
|
|
// Here, we collect rows selected by clicking on a row label, and rows that contain
|
|
|
|
// previously-selected cells.
|
2017-08-12 12:09:39 +00:00
|
|
|
// If no candidate, just delete the row with the grid cursor.
|
|
|
|
wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
|
|
|
|
wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells();
|
2018-01-17 08:59:02 +00:00
|
|
|
wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft();
|
|
|
|
wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// Add all row having cell selected to list:
|
|
|
|
for( unsigned ii = 0; ii < cells.GetCount(); ii++ )
|
|
|
|
selectedRows.Add( cells[ii].GetRow() );
|
|
|
|
|
2018-01-17 08:59:02 +00:00
|
|
|
// Handle block selection
|
|
|
|
if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
|
|
|
|
{
|
|
|
|
for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
|
|
|
|
selectedRows.Add( i );
|
|
|
|
}
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
// Use the row having the grid cursor only if we have no candidate:
|
2018-03-14 04:51:59 +00:00
|
|
|
if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.Add( m_cur_grid->GetGridCursorRow() );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-08-19 16:10:42 +00:00
|
|
|
if( selectedRows.size() == 0 )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
std::sort( selectedRows.begin(), selectedRows.end() );
|
|
|
|
|
|
|
|
// Remove selected rows (note: a row can be stored more than once in list)
|
|
|
|
int last_row = -1;
|
|
|
|
|
|
|
|
for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
|
|
|
|
{
|
|
|
|
int row = selectedRows[ii];
|
|
|
|
|
|
|
|
if( row != last_row )
|
|
|
|
{
|
|
|
|
last_row = row;
|
|
|
|
m_cur_grid->DeleteRows( row, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 15:39:19 +00:00
|
|
|
if( m_cur_grid->GetNumberRows() > 0 && curRow >= 0 )
|
|
|
|
m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::moveUpHandler( wxCommandEvent& event )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* tbl = cur_model();
|
|
|
|
int curRow = m_cur_grid->GetGridCursorRow();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// @todo: add multiple selection moves.
|
|
|
|
if( curRow >= 1 )
|
|
|
|
{
|
|
|
|
boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
|
|
|
|
tbl->rows.release( tbl->rows.begin() + curRow );
|
|
|
|
|
|
|
|
--curRow;
|
|
|
|
tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
|
|
|
|
|
|
|
|
if( tbl->GetView() )
|
|
|
|
{
|
2018-03-14 04:51:59 +00:00
|
|
|
// Update the wxGrid
|
|
|
|
wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 );
|
2017-08-12 12:09:39 +00:00
|
|
|
tbl->GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
|
|
|
|
m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::moveDownHandler( wxCommandEvent& event )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2017-08-12 12:09:39 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* tbl = cur_model();
|
2018-03-14 04:51:59 +00:00
|
|
|
int curRow = m_cur_grid->GetGridCursorRow();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// @todo: add multiple selection moves.
|
|
|
|
if( unsigned( curRow + 1 ) < tbl->rows.size() )
|
|
|
|
{
|
|
|
|
boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me =
|
|
|
|
tbl->rows.release( tbl->rows.begin() + curRow );
|
|
|
|
|
|
|
|
++curRow;
|
|
|
|
tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() );
|
|
|
|
|
|
|
|
if( tbl->GetView() )
|
|
|
|
{
|
2018-03-14 04:51:59 +00:00
|
|
|
// Update the wxGrid
|
|
|
|
wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 );
|
2017-08-12 12:09:39 +00:00
|
|
|
tbl->GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() );
|
|
|
|
m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-13 11:39:53 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxArrayInt selectedRows = m_cur_grid->GetSelectedRows();
|
|
|
|
|
2020-12-23 22:10:09 +00:00
|
|
|
if( selectedRows.empty() && m_cur_grid->GetGridCursorRow() >= 0 )
|
2020-12-13 11:39:53 +00:00
|
|
|
selectedRows.push_back( m_cur_grid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
wxArrayInt legacyRows;
|
|
|
|
wxString legacyType = SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY );
|
|
|
|
wxString kicadType = SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD );
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
for( int row : selectedRows )
|
|
|
|
{
|
|
|
|
if( m_cur_grid->GetCellValue( row, COL_TYPE ) == legacyType )
|
|
|
|
legacyRows.push_back( row );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( legacyRows.size() <= 0 )
|
|
|
|
{
|
2021-06-09 18:20:09 +00:00
|
|
|
wxMessageBox( _( "Select one or more rows containing libraries in Legacy format (*.lib) "
|
|
|
|
"to save as current KiCad format (*.kicad_sym)." ) );
|
2020-12-13 11:39:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( legacyRows.size() == 1 )
|
|
|
|
{
|
2021-06-09 18:20:09 +00:00
|
|
|
msg.Printf( _( "Save '%s' as current KiCad format (*.kicad_sym) "
|
|
|
|
"and replace legacy entry in table?" ),
|
2020-12-13 11:39:53 +00:00
|
|
|
m_cur_grid->GetCellValue( legacyRows[0], COL_NICKNAME ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-09 18:20:09 +00:00
|
|
|
msg.Printf( _( "Save %d Legacy format libraries as current KiCad format (*.kicad_sym) "
|
|
|
|
"and replace legacy entries in table?" ),
|
2021-05-08 22:09:23 +00:00
|
|
|
(int) legacyRows.size() );
|
2020-12-13 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !IsOK( m_parent, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int row : legacyRows )
|
|
|
|
{
|
|
|
|
wxString libName = m_cur_grid->GetCellValue( row, COL_NICKNAME );
|
|
|
|
wxString relPath = m_cur_grid->GetCellValue( row, COL_URI );
|
|
|
|
wxString resolvedPath = ExpandEnvVarSubstitutions( relPath, m_project );
|
|
|
|
wxFileName legacyLib( resolvedPath );
|
|
|
|
|
|
|
|
if( !legacyLib.Exists() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Library '%s' not found." ), relPath );
|
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName newLib( resolvedPath );
|
|
|
|
newLib.SetExt( "kicad_sym" );
|
|
|
|
|
2021-05-08 22:09:23 +00:00
|
|
|
if( newLib.Exists() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "File '%s' already exists. Do you want overwrite this file?" ),
|
|
|
|
newLib.GetFullPath() );
|
|
|
|
|
|
|
|
switch( wxMessageBox( msg, _( "Migrate Library" ),
|
|
|
|
wxYES_NO | wxCANCEL | wxICON_QUESTION, m_parent ) )
|
|
|
|
{
|
|
|
|
case wxYES: break;
|
|
|
|
case wxNO: continue;
|
|
|
|
case wxCANCEL: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 11:39:53 +00:00
|
|
|
if( convertLibrary( libName, legacyLib.GetFullPath(), newLib.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
relPath = NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(),
|
|
|
|
m_project );
|
|
|
|
|
2021-02-05 05:52:41 +00:00
|
|
|
// Do not use the project path in the global library table. This will almost
|
|
|
|
// assuredly be wrong for a different project.
|
2021-09-23 15:44:39 +00:00
|
|
|
if( m_cur_grid == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) )
|
2021-02-05 05:52:41 +00:00
|
|
|
relPath = newLib.GetFullPath();
|
|
|
|
|
2021-02-05 12:12:11 +00:00
|
|
|
m_cur_grid->SetCellValue( row, COL_URI, relPath );
|
|
|
|
m_cur_grid->SetCellValue( row, COL_TYPE, kicadType );
|
2020-12-13 11:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Failed to save symbol library file '%s'." ), newLib.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_SYM_LIB_TABLE::convertLibrary( const wxString& aLibrary, const wxString& legacyFilepath,
|
|
|
|
const wxString& newFilepath )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER legacyPI( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER kicadPI( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
|
|
|
std::vector<LIB_SYMBOL*> symbols;
|
|
|
|
std::vector<LIB_SYMBOL*> newSymbols;
|
2021-08-12 21:07:30 +00:00
|
|
|
std::map<LIB_SYMBOL*, LIB_SYMBOL*> symbolMap;
|
2020-12-13 11:39:53 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Write a stub file; SaveSymbol() expects something to be there already.
|
|
|
|
FILE_OUTPUTFORMATTER* formatter = new FILE_OUTPUTFORMATTER( newFilepath );
|
|
|
|
|
|
|
|
formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator kicad_converter))",
|
|
|
|
SEXPR_SYMBOL_LIB_FILE_VERSION );
|
|
|
|
|
|
|
|
// This will write the file
|
|
|
|
delete formatter;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
legacyPI->EnumerateSymbolLib( symbols, legacyFilepath );
|
2020-12-13 11:39:53 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Copy non-aliases first so we can build a map from symbols to newSymbols
|
|
|
|
for( LIB_SYMBOL* symbol : symbols )
|
2021-02-16 12:48:18 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
if( symbol->IsAlias() )
|
2021-02-16 12:48:18 +00:00
|
|
|
continue;
|
|
|
|
|
2021-08-12 21:07:30 +00:00
|
|
|
symbol->SetName( EscapeString( symbol->GetName(), CTX_LIBID ) );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
newSymbols.push_back( new LIB_SYMBOL( *symbol ) );
|
|
|
|
symbolMap[symbol] = newSymbols.back();
|
2021-02-16 12:48:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Now do the aliases using the map to hook them up to their newSymbol parents
|
|
|
|
for( LIB_SYMBOL* symbol : symbols )
|
2021-02-16 12:48:18 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !symbol->IsAlias() )
|
2021-02-16 12:48:18 +00:00
|
|
|
continue;
|
|
|
|
|
2021-08-12 21:07:30 +00:00
|
|
|
symbol->SetName( EscapeString( symbol->GetName(), CTX_LIBID ) );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
newSymbols.push_back( new LIB_SYMBOL( *symbol ) );
|
|
|
|
newSymbols.back()->SetParent( symbolMap[ symbol->GetParent().lock().get() ] );
|
2021-02-16 12:48:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Finally write out newSymbols
|
|
|
|
for( LIB_SYMBOL* symbol : newSymbols )
|
2021-02-16 12:48:18 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
kicadPI->SaveSymbol( newFilepath, symbol );
|
2021-02-16 12:48:18 +00:00
|
|
|
}
|
2020-12-13 11:39:53 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow()
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_cur_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
if( !verifyTables() )
|
2017-08-12 12:09:39 +00:00
|
|
|
return false;
|
|
|
|
|
2018-08-06 18:33:28 +00:00
|
|
|
if( *global_model() != *m_globalTable )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-06 18:33:28 +00:00
|
|
|
m_parent->m_GlobalTableChanged = true;
|
|
|
|
|
|
|
|
m_globalTable->Clear();
|
|
|
|
m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(),
|
2020-07-17 17:32:16 +00:00
|
|
|
global_model()->rows.end(), global_model()->rows );
|
2018-08-06 18:33:28 +00:00
|
|
|
m_globalTable->reindex();
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
if( project_model() && *project_model() != *m_projectTable )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-08-06 18:33:28 +00:00
|
|
|
m_parent->m_ProjectTableChanged = true;
|
|
|
|
|
|
|
|
m_projectTable->Clear();
|
|
|
|
m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(),
|
2020-07-17 17:32:16 +00:00
|
|
|
project_model()->rows.end(), project_model()->rows );
|
2018-08-06 18:33:28 +00:00
|
|
|
m_projectTable->reindex();
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::populateEnvironReadOnlyTable()
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-05-05 22:39:43 +00:00
|
|
|
wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
|
2017-08-12 12:09:39 +00:00
|
|
|
wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
|
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
std::set< wxString > unique;
|
2017-08-12 12:09:39 +00:00
|
|
|
|
|
|
|
// clear the table
|
2021-08-10 11:59:53 +00:00
|
|
|
m_path_subs_grid->ClearRows();
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-09-12 12:59:33 +00:00
|
|
|
for( SYMBOL_LIB_TABLE_GRID* tbl : { global_model(), project_model() } )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
if( !tbl )
|
|
|
|
continue;
|
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
for( int row = 0; row < tbl->GetNumberRows(); ++row )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-05-05 22:39:43 +00:00
|
|
|
wxString uri = tbl->GetValue( row, COL_URI );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
while( re.Matches( uri ) )
|
|
|
|
{
|
|
|
|
wxString envvar = re.GetMatch( uri, 2 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
// if not ${...} form then must be $(...)
|
|
|
|
if( envvar.IsEmpty() )
|
|
|
|
envvar = re.GetMatch( uri, 4 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
// ignore duplicates
|
|
|
|
unique.insert( envvar );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-05-05 22:39:43 +00:00
|
|
|
// delete the last match and search again
|
|
|
|
uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
|
|
|
|
}
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this special environment variable shows up even if it was
|
|
|
|
// not used yet. It is automatically set by KiCad to the directory holding
|
|
|
|
// the current project.
|
|
|
|
unique.insert( PROJECT_VAR_NAME );
|
|
|
|
unique.insert( SYMBOL_LIB_TABLE::GlobalPathEnvVariableName() );
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const wxString& evName : unique )
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2018-03-14 04:51:59 +00:00
|
|
|
int row = m_path_subs_grid->GetNumberRows();
|
|
|
|
m_path_subs_grid->AppendRows( 1 );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
|
2018-09-12 12:59:33 +00:00
|
|
|
m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
|
2017-08-12 12:09:39 +00:00
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
wxString evValue;
|
|
|
|
wxGetEnv( evName, &evValue );
|
|
|
|
m_path_subs_grid->SetCellValue( row, 1, evValue );
|
2018-09-12 12:59:33 +00:00
|
|
|
m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 04:51:59 +00:00
|
|
|
// No combobox editors here, but it looks better if its consistent with the other
|
|
|
|
// grids in the dialog.
|
2018-09-12 12:59:33 +00:00
|
|
|
m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 );
|
2018-03-14 04:51:59 +00:00
|
|
|
|
|
|
|
adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::adjustPathSubsGridColumns( int aWidth )
|
2017-11-14 10:18:45 +00:00
|
|
|
{
|
2018-03-14 04:51:59 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
|
|
|
|
|
|
|
|
m_path_subs_grid->AutoSizeColumn( 0 );
|
2020-11-19 23:17:56 +00:00
|
|
|
|
|
|
|
int remaining_width = aWidth - m_path_subs_grid->GetColSize( 0 );
|
|
|
|
|
|
|
|
if( remaining_width < 0 )
|
|
|
|
m_path_subs_grid->SetColSize( 1, -1 );
|
|
|
|
else
|
|
|
|
m_path_subs_grid->SetColSize( 1, remaining_width );
|
2018-03-14 04:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
void PANEL_SYM_LIB_TABLE::onSizeGrid( wxSizeEvent& event )
|
2018-03-14 04:51:59 +00:00
|
|
|
{
|
|
|
|
adjustPathSubsGridColumns( event.GetSize().GetX() );
|
|
|
|
|
|
|
|
event.Skip();
|
2017-11-14 10:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* PANEL_SYM_LIB_TABLE::global_model() const
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
|
|
|
return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* PANEL_SYM_LIB_TABLE::project_model() const
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
2020-08-07 19:22:15 +00:00
|
|
|
return m_project_grid ? (SYMBOL_LIB_TABLE_GRID*) m_project_grid->GetTable() : nullptr;
|
2017-08-12 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
SYMBOL_LIB_TABLE_GRID* PANEL_SYM_LIB_TABLE::cur_model() const
|
2017-08-12 12:09:39 +00:00
|
|
|
{
|
|
|
|
return (SYMBOL_LIB_TABLE_GRID*) m_cur_grid->GetTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-20 17:46:56 +00:00
|
|
|
size_t PANEL_SYM_LIB_TABLE::m_pageNdx = 0;
|
2018-08-06 18:33:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent )
|
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
auto* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
|
|
|
|
auto* symbolEditor = (SYMBOL_EDIT_FRAME*) aKiway->Player( FRAME_SCH_SYMBOL_EDITOR, false );
|
2020-12-25 23:37:01 +00:00
|
|
|
auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
|
2019-06-02 23:17:27 +00:00
|
|
|
|
2018-08-06 18:33:28 +00:00
|
|
|
SYMBOL_LIB_TABLE* globalTable = &SYMBOL_LIB_TABLE::GetGlobalLibTable();
|
|
|
|
wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
|
2020-08-07 19:22:15 +00:00
|
|
|
SYMBOL_LIB_TABLE* projectTable = nullptr;
|
2018-08-06 18:33:28 +00:00
|
|
|
wxString projectPath = aKiway->Prj().GetProjectPath();
|
|
|
|
wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
wxString msg;
|
2019-06-13 11:44:12 +00:00
|
|
|
wxString currentLib;
|
2018-08-06 18:33:28 +00:00
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
// Don't allow editing project tables if no project is open
|
|
|
|
if( !aKiway->Prj().IsNullProject() )
|
|
|
|
projectTable = aKiway->Prj().SchSymbolLibTable();
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditor )
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
currentLib = symbolEditor->GetCurLib();
|
2019-06-13 11:44:12 +00:00
|
|
|
|
|
|
|
// This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
|
2021-03-17 14:53:27 +00:00
|
|
|
symbolEditor->FreezeLibraryTree();
|
2019-06-02 23:17:27 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditor->HasLibModifications() )
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
2019-07-15 08:33:03 +00:00
|
|
|
msg = _( "Modifications have been made to one or more symbol libraries.\n"
|
|
|
|
"Changes must be saved or discarded before the symbol library "
|
|
|
|
"table can be modified." );
|
2019-07-14 20:39:44 +00:00
|
|
|
|
|
|
|
switch( UnsavedChangesDialog( aParent, msg ) )
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
2021-03-17 14:53:27 +00:00
|
|
|
case wxID_YES: symbolEditor->SaveAll(); break;
|
|
|
|
case wxID_NO: symbolEditor->RevertAll(); break;
|
2019-07-14 20:39:44 +00:00
|
|
|
default:
|
2021-03-17 14:53:27 +00:00
|
|
|
case wxID_CANCEL: symbolEditor->ThawLibraryTree(); return;
|
2019-06-13 11:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:33:28 +00:00
|
|
|
DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
|
2021-03-01 14:46:07 +00:00
|
|
|
dlg.SetKiway( &dlg, aKiway );
|
2018-08-06 18:33:28 +00:00
|
|
|
|
2020-12-13 11:39:53 +00:00
|
|
|
dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
|
|
|
|
projectTable, projectTableFn.GetFullPath() ) );
|
2018-08-06 18:33:28 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditor )
|
2021-03-17 14:53:27 +00:00
|
|
|
symbolEditor->ThawLibraryTree();
|
2019-06-13 11:44:12 +00:00
|
|
|
|
2018-08-06 18:33:28 +00:00
|
|
|
return;
|
2019-06-13 11:44:12 +00:00
|
|
|
}
|
2018-08-06 18:33:28 +00:00
|
|
|
|
|
|
|
if( dlg.m_GlobalTableChanged )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
globalTable->Save( globalTablePath );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
|
|
|
|
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 19:22:15 +00:00
|
|
|
if( projectTable && dlg.m_ProjectTableChanged )
|
2018-08-06 18:33:28 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
projectTable->Save( projectTableFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
|
|
|
|
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 17:03:19 +00:00
|
|
|
if( schEditor )
|
|
|
|
schEditor->SyncView();
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditor )
|
2019-06-02 23:17:27 +00:00
|
|
|
{
|
2019-06-13 11:44:12 +00:00
|
|
|
// Check if the currently selected symbol library been removed or disabled.
|
2020-08-07 19:22:15 +00:00
|
|
|
if( !currentLib.empty() && projectTable && !projectTable->HasLibrary( currentLib, true ) )
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
symbolEditor->SetCurLib( wxEmptyString );
|
|
|
|
symbolEditor->emptyScreen();
|
2019-06-13 11:44:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
symbolEditor->SyncLibraries( true );
|
2021-03-17 14:53:27 +00:00
|
|
|
symbolEditor->ThawLibraryTree();
|
|
|
|
symbolEditor->RefreshLibraryTree();
|
2019-06-02 23:17:27 +00:00
|
|
|
}
|
2018-08-06 18:33:28 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolViewer )
|
2020-12-17 23:56:47 +00:00
|
|
|
symbolViewer->ReCreateLibList();
|
2018-08-06 18:33:28 +00:00
|
|
|
}
|