2012-10-15 22:30:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2013-10-23 18:56:03 +00:00
|
|
|
* Copyright (C) 2013 CERN
|
2012-10-15 22:30:01 +00:00
|
|
|
* Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-01-21 03:12:16 +00:00
|
|
|
/* TODO:
|
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
*) After any change to uri, reparse the environment variables.
|
2013-01-21 03:27:01 +00:00
|
|
|
|
2013-01-21 03:12:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <set>
|
2013-10-23 18:56:03 +00:00
|
|
|
#include <wx/regex.h>
|
2013-01-21 03:12:16 +00:00
|
|
|
|
2012-10-16 06:56:57 +00:00
|
|
|
#include <fctsys.h>
|
2012-10-15 22:30:01 +00:00
|
|
|
#include <dialog_fp_lib_table_base.h>
|
|
|
|
#include <fp_lib_table.h>
|
2013-10-13 21:33:58 +00:00
|
|
|
#include <fp_lib_table_lexer.h>
|
|
|
|
#include <invoke_pcb_dialog.h>
|
2013-10-23 18:56:03 +00:00
|
|
|
#include <grid_tricks.h>
|
2013-11-20 16:35:03 +00:00
|
|
|
#include <confirm.h>
|
2013-09-24 21:23:13 +00:00
|
|
|
|
|
|
|
/// grid column order is established by this sequence
|
|
|
|
enum COL_ORDER
|
|
|
|
{
|
|
|
|
COL_NICKNAME,
|
|
|
|
COL_URI,
|
|
|
|
COL_TYPE,
|
|
|
|
COL_OPTIONS,
|
|
|
|
COL_DESCR,
|
|
|
|
COL_COUNT // keep as last
|
|
|
|
};
|
|
|
|
|
2012-10-17 01:00:25 +00:00
|
|
|
|
2012-10-17 15:12:17 +00:00
|
|
|
/**
|
|
|
|
* Class FP_TBL_MODEL
|
2013-10-30 15:33:51 +00:00
|
|
|
* mixes in FP_LIB_TABLE into wxGridTableBase so the result can be used
|
2012-10-18 15:28:50 +00:00
|
|
|
* as a table within wxGrid.
|
2012-10-17 15:12:17 +00:00
|
|
|
*/
|
2012-10-17 01:00:25 +00:00
|
|
|
class FP_TBL_MODEL : public wxGridTableBase, public FP_LIB_TABLE
|
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
friend class FP_GRID_TRICKS;
|
2012-10-17 01:00:25 +00:00
|
|
|
|
|
|
|
public:
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2012-10-17 01:00:25 +00:00
|
|
|
/**
|
|
|
|
* Constructor FP_TBL_MODEL
|
2012-10-18 15:28:50 +00:00
|
|
|
* is a copy constructor that builds a wxGridTableBase (table model) by wrapping
|
|
|
|
* an FP_LIB_TABLE.
|
2012-10-17 01:00:25 +00:00
|
|
|
*/
|
|
|
|
FP_TBL_MODEL( const FP_LIB_TABLE& aTableToEdit ) :
|
|
|
|
FP_LIB_TABLE( aTableToEdit ) // copy constructor
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----<wxGridTableBase overloads>-------------------------------------------
|
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
int GetNumberRows() { return rows.size(); }
|
|
|
|
int GetNumberCols() { return COL_COUNT; }
|
2012-10-17 01:00:25 +00:00
|
|
|
|
|
|
|
wxString GetValue( int aRow, int aCol )
|
|
|
|
{
|
|
|
|
if( unsigned( aRow ) < rows.size() )
|
|
|
|
{
|
|
|
|
const ROW& r = rows[aRow];
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2012-12-09 20:51:42 +00:00
|
|
|
case COL_NICKNAME: return r.GetNickName();
|
|
|
|
case COL_URI: return r.GetFullURI();
|
|
|
|
case COL_TYPE: return r.GetType();
|
|
|
|
case COL_OPTIONS: return r.GetOptions();
|
|
|
|
case COL_DESCR: return r.GetDescr();
|
2012-10-17 01:00:25 +00:00
|
|
|
default:
|
|
|
|
; // fall thru to wxEmptyString
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue )
|
|
|
|
{
|
|
|
|
if( unsigned( aRow ) < rows.size() )
|
|
|
|
{
|
|
|
|
ROW& r = rows[aRow];
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2012-12-09 20:51:42 +00:00
|
|
|
case COL_NICKNAME: r.SetNickName( aValue ); break;
|
|
|
|
case COL_URI: r.SetFullURI( aValue ); break;
|
|
|
|
case COL_TYPE: r.SetType( aValue ); break;
|
|
|
|
case COL_OPTIONS: r.SetOptions( aValue ); break;
|
|
|
|
case COL_DESCR: r.SetDescr( aValue ); break;
|
2012-10-17 01:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmptyCell( int aRow, int aCol )
|
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
return !GetValue( aRow, aCol );
|
2012-10-17 01:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InsertRows( size_t aPos = 0, size_t aNumRows = 1 )
|
|
|
|
{
|
|
|
|
if( aPos < rows.size() )
|
|
|
|
{
|
|
|
|
rows.insert( rows.begin() + aPos, aNumRows, ROW() );
|
2012-10-18 15:28:50 +00:00
|
|
|
|
|
|
|
// use the (wxGridStringTable) source Luke.
|
|
|
|
if( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this,
|
|
|
|
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
|
|
|
|
aPos,
|
|
|
|
aNumRows );
|
|
|
|
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:00:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppendRows( size_t aNumRows = 1 )
|
|
|
|
{
|
2012-10-18 15:28:50 +00:00
|
|
|
// do not modify aNumRows, original value needed for wxGridTableMessage below
|
|
|
|
for( int i = aNumRows; i; --i )
|
2012-10-17 01:00:25 +00:00
|
|
|
rows.push_back( ROW() );
|
2012-10-18 15:28:50 +00:00
|
|
|
|
|
|
|
if( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this,
|
|
|
|
wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
|
|
|
|
aNumRows );
|
|
|
|
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:00:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeleteRows( size_t aPos, size_t aNumRows )
|
|
|
|
{
|
|
|
|
if( aPos + aNumRows <= rows.size() )
|
|
|
|
{
|
|
|
|
ROWS_ITER start = rows.begin() + aPos;
|
|
|
|
rows.erase( start, start + aNumRows );
|
2012-10-18 15:28:50 +00:00
|
|
|
|
|
|
|
if( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this,
|
|
|
|
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
|
|
|
|
aPos,
|
|
|
|
aNumRows );
|
|
|
|
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:00:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
rows.clear();
|
|
|
|
nickIndex.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetColLabelValue( int aCol )
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2012-12-09 20:51:42 +00:00
|
|
|
case COL_NICKNAME: return _( "Nickname" );
|
|
|
|
case COL_URI: return _( "Library Path" );
|
2013-01-21 03:12:16 +00:00
|
|
|
|
2013-11-12 00:17:27 +00:00
|
|
|
// keep this "Plugin Type" text fairly long so column is sized wide enough
|
2013-01-21 03:12:16 +00:00
|
|
|
case COL_TYPE: return _( "Plugin Type" );
|
2012-12-09 20:51:42 +00:00
|
|
|
case COL_OPTIONS: return _( "Options" );
|
|
|
|
case COL_DESCR: return _( "Description" );
|
|
|
|
default: return wxEmptyString;
|
2012-10-17 01:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----</wxGridTableBase overloads>------------------------------------------
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
class FP_GRID_TRICKS : public GRID_TRICKS
|
2012-10-15 22:30:01 +00:00
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
public:
|
|
|
|
FP_GRID_TRICKS( wxGrid* aGrid ) :
|
|
|
|
GRID_TRICKS( aGrid )
|
2012-10-18 15:28:50 +00:00
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
}
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
protected:
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
/// handle specialized clipboard text, with leading "(fp_lib_table", OR
|
|
|
|
/// spreadsheet formatted text.
|
|
|
|
virtual void paste_text( const wxString& cb_text )
|
|
|
|
{
|
|
|
|
FP_TBL_MODEL* tbl = (FP_TBL_MODEL*) m_grid->GetTable();
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
size_t ndx = cb_text.find( wxT( "(fp_lib_table" ) );
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
if( ndx != std::string::npos )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
// paste the ROWs of s-expression (fp_lib_table), starting
|
|
|
|
// at column 0 regardless of current cursor column.
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
STRING_LINE_READER slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
|
|
|
|
FP_LIB_TABLE_LEXER lexer( &slr );
|
|
|
|
FP_LIB_TABLE tmp_tbl;
|
|
|
|
bool parsed = true;
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
tmp_tbl.Parse( &lexer );
|
|
|
|
}
|
|
|
|
catch( PARSE_ERROR& pe )
|
|
|
|
{
|
2013-11-20 16:35:03 +00:00
|
|
|
DisplayError( NULL, pe.errorText );
|
2013-10-23 18:56:03 +00:00
|
|
|
parsed = false;
|
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
if( parsed )
|
|
|
|
{
|
|
|
|
const int cur_row = std::max( getCursorRow(), 0 );
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
// if clipboard rows would extend past end of current table size...
|
|
|
|
if( tmp_tbl.GetCount() > tbl->GetNumberRows() - cur_row )
|
|
|
|
{
|
|
|
|
int newRowsNeeded = tmp_tbl.GetCount() - ( tbl->GetNumberRows() - cur_row );
|
|
|
|
tbl->AppendRows( newRowsNeeded );
|
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
for( int i = 0; i < tmp_tbl.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
tbl->At( cur_row+i ) = tmp_tbl.At( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_grid->AutoSizeColumns( false );
|
|
|
|
}
|
|
|
|
else
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
// paste spreadsheet formatted text.
|
|
|
|
GRID_TRICKS::paste_text( cb_text );
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
2013-10-23 18:56:03 +00:00
|
|
|
}
|
|
|
|
};
|
2012-12-09 20:51:42 +00:00
|
|
|
|
|
|
|
|
2012-10-15 22:30:01 +00:00
|
|
|
/**
|
|
|
|
* Class DIALOG_FP_LIB_TABLE
|
|
|
|
* shows and edits the PCB library tables. Two tables are expected, one global
|
|
|
|
* and one project specific.
|
|
|
|
*/
|
|
|
|
class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
|
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_FP_LIB_TABLE( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ) :
|
|
|
|
DIALOG_FP_LIB_TABLE_BASE( aParent ),
|
|
|
|
m_global( aGlobal ),
|
|
|
|
m_project( aProject )
|
|
|
|
{
|
|
|
|
// wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
|
|
|
|
// so make it a grid owned table.
|
|
|
|
m_global_grid->SetTable( new FP_TBL_MODEL( *aGlobal ), true );
|
|
|
|
m_project_grid->SetTable( new FP_TBL_MODEL( *aProject ), true );
|
|
|
|
|
|
|
|
// add Cut, Copy, and Paste to wxGrids
|
|
|
|
m_global_grid->PushEventHandler( new FP_GRID_TRICKS( m_global_grid ) );
|
|
|
|
m_project_grid->PushEventHandler( new FP_GRID_TRICKS( m_project_grid ) );
|
|
|
|
|
|
|
|
m_global_grid->AutoSizeColumns( false );
|
|
|
|
m_project_grid->AutoSizeColumns( false );
|
|
|
|
|
|
|
|
wxArrayString choices;
|
|
|
|
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::KICAD ) );
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );
|
|
|
|
|
|
|
|
/* PCAD_PLUGIN does not support Footprint*() functions
|
|
|
|
choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) );
|
|
|
|
*/
|
|
|
|
|
|
|
|
wxGridCellAttr* attr;
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
|
|
|
|
m_project_grid->SetColAttr( COL_TYPE, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
|
|
|
|
m_global_grid->SetColAttr( COL_TYPE, attr );
|
|
|
|
|
2013-11-12 20:49:17 +00:00
|
|
|
populateEnvironReadOnlyTable();
|
2013-10-30 15:33:51 +00:00
|
|
|
|
2013-11-12 20:49:17 +00:00
|
|
|
for( int i=0; i<2; ++i )
|
|
|
|
{
|
|
|
|
wxGrid* g = i==0 ? m_global_grid : m_project_grid;
|
2013-10-30 15:33:51 +00:00
|
|
|
|
2013-11-12 20:49:17 +00:00
|
|
|
// all but COL_OPTIONS, which is edited with Option Editor anyways.
|
2013-11-19 17:24:45 +00:00
|
|
|
g->AutoSizeColumn( COL_NICKNAME, false );
|
2013-11-12 20:49:17 +00:00
|
|
|
g->AutoSizeColumn( COL_TYPE, false );
|
|
|
|
g->AutoSizeColumn( COL_URI, false );
|
|
|
|
g->AutoSizeColumn( COL_DESCR, false );
|
2013-10-30 15:33:51 +00:00
|
|
|
|
2013-11-19 17:24:45 +00:00
|
|
|
// would set this to width of title, if it was easily known.
|
2013-11-12 20:49:17 +00:00
|
|
|
g->SetColSize( COL_OPTIONS, 80 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// This scrunches the dialog hideously, probably due to wxAUI container.
|
|
|
|
// Fit();
|
|
|
|
// We derive from DIALOG_SHIM so prior size will be used anyways.
|
2013-10-30 15:33:51 +00:00
|
|
|
|
|
|
|
// fire pageChangedHandler() so m_cur_grid gets set
|
|
|
|
wxAuiNotebookEvent uneventful;
|
|
|
|
pageChangedHandler( uneventful );
|
|
|
|
|
|
|
|
// for ALT+A handling, we want the initial focus to be on the first selected grid.
|
|
|
|
m_cur_grid->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
~DIALOG_FP_LIB_TABLE()
|
|
|
|
{
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
// Any additional event handlers should be popped before the window is deleted.
|
|
|
|
m_global_grid->PopEventHandler( true );
|
|
|
|
m_project_grid->PopEventHandler( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2012-10-17 15:12:17 +00:00
|
|
|
typedef FP_LIB_TABLE::ROW ROW;
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-22 19:29:37 +00:00
|
|
|
/// If the cursor is not on a valid cell, because there are no rows at all, return -1,
|
|
|
|
/// else return a 0 based column index.
|
2013-10-22 14:29:48 +00:00
|
|
|
int getCursorCol() const
|
2013-10-05 10:34:55 +00:00
|
|
|
{
|
2013-10-22 14:29:48 +00:00
|
|
|
return m_cur_grid->GetGridCursorCol();
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 19:29:37 +00:00
|
|
|
/// If the cursor is not on a valid cell, because there are no rows at all, return -1,
|
|
|
|
/// else return a 0 based row index.
|
2013-10-22 14:29:48 +00:00
|
|
|
int getCursorRow() const
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-22 14:29:48 +00:00
|
|
|
return m_cur_grid->GetGridCursorRow();
|
2013-10-05 10:34:55 +00:00
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
/**
|
|
|
|
* Function verifyTables
|
|
|
|
* trims important fields, removes blank row entries, and checks for duplicates.
|
|
|
|
* @return bool - true if tables are OK, else false.
|
|
|
|
*/
|
|
|
|
bool verifyTables()
|
|
|
|
{
|
|
|
|
for( int t=0; t<2; ++t )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL& model = t==0 ? *global_model() : *project_model();
|
2013-09-24 21:23:13 +00:00
|
|
|
|
|
|
|
for( int r = 0; r < model.GetNumberRows(); )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-09-24 21:23:13 +00:00
|
|
|
wxString nick = model.GetValue( r, COL_NICKNAME ).Trim( false ).Trim();
|
|
|
|
wxString uri = model.GetValue( r, COL_URI ).Trim( false ).Trim();
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
if( !nick || !uri )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-09-25 19:17:06 +00:00
|
|
|
// Delete the "empty" row, where empty means missing nick or uri.
|
2013-09-24 21:23:13 +00:00
|
|
|
// 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.
|
|
|
|
model.DeleteRows( r, 1 );
|
|
|
|
}
|
|
|
|
else if( nick.find(':') != size_t(-1) )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "Illegal character '%s' found in Nickname: '%s' in row %d" ),
|
|
|
|
wxT( ":" ), GetChars( nick ), r );
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
// show the tabbed panel holding the grid we have flunked:
|
2013-10-30 15:33:51 +00:00
|
|
|
if( &model != cur_model() )
|
2013-09-24 21:23:13 +00:00
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
// go to the problematic row
|
2013-10-13 21:33:58 +00:00
|
|
|
m_cur_grid->SetGridCursor( r, 0 );
|
2013-09-24 21:23:13 +00:00
|
|
|
m_cur_grid->SelectBlock( r, 0, r, 0 );
|
|
|
|
m_cur_grid->MakeCellVisible( r, 0 );
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) );
|
|
|
|
errdlg.ShowModal();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-09-24 21:23:13 +00:00
|
|
|
// set the trimmed values back into the table so they get saved to disk.
|
|
|
|
model.SetValue( r, COL_NICKNAME, nick );
|
|
|
|
model.SetValue( r, COL_URI, uri );
|
|
|
|
++r; // this row was OK.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
// check for duplicate nickNames, separately in each table.
|
|
|
|
for( int t=0; t<2; ++t )
|
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL& model = t==0 ? *global_model() : *project_model();
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
for( int r1 = 0; r1 < model.GetNumberRows() - 1; ++r1 )
|
|
|
|
{
|
2013-09-25 19:17:06 +00:00
|
|
|
wxString nick1 = model.GetValue( r1, COL_NICKNAME );
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
for( int r2=r1+1; r2 < model.GetNumberRows(); ++r2 )
|
|
|
|
{
|
|
|
|
wxString nick2 = model.GetValue( r2, COL_NICKNAME );
|
2012-12-21 05:29:40 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
if( nick1 == nick2 )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-09-24 21:23:13 +00:00
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "Duplicate Nickname: '%s' in rows %d and %d" ),
|
|
|
|
GetChars( nick1 ), r1+1, r2+1
|
|
|
|
);
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
// show the tabbed panel holding the grid we have flunked:
|
2013-10-30 15:33:51 +00:00
|
|
|
if( &model != cur_model() )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 );
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
2013-09-24 21:23:13 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
// go to the lower of the two rows, it is technically the duplicate:
|
2013-10-13 21:33:58 +00:00
|
|
|
m_cur_grid->SetGridCursor( r2, 0 );
|
2013-09-24 21:23:13 +00:00
|
|
|
m_cur_grid->SelectBlock( r2, 0, r2, 0 );
|
|
|
|
m_cur_grid->MakeCellVisible( r2, 0 );
|
|
|
|
|
|
|
|
wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) );
|
|
|
|
errdlg.ShowModal();
|
|
|
|
return false;
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 21:23:13 +00:00
|
|
|
|
|
|
|
return true;
|
2012-10-18 15:28:50 +00:00
|
|
|
}
|
2012-10-17 15:12:17 +00:00
|
|
|
|
2012-10-16 06:56:57 +00:00
|
|
|
//-----<event handlers>----------------------------------
|
|
|
|
|
2013-10-04 22:23:53 +00:00
|
|
|
void onKeyDown( wxKeyEvent& ev )
|
|
|
|
{
|
2013-10-23 18:56:03 +00:00
|
|
|
#if 0
|
|
|
|
// send the key to the current grid
|
|
|
|
((wxEvtHandler*)m_cur_grid)->ProcessEvent( ev );
|
|
|
|
#else
|
|
|
|
// or no:
|
|
|
|
// m_cur_grid has the focus most of the time anyways, so above not needed.
|
|
|
|
ev.Skip();
|
|
|
|
#endif
|
2013-10-04 22:23:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 06:56:57 +00:00
|
|
|
void pageChangedHandler( wxAuiNotebookEvent& event )
|
|
|
|
{
|
|
|
|
int pageNdx = m_auinotebook->GetSelection();
|
2012-12-09 20:51:42 +00:00
|
|
|
m_cur_grid = ( pageNdx == 0 ) ? m_global_grid : m_project_grid;
|
2012-10-16 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void appendRowHandler( wxMouseEvent& event )
|
|
|
|
{
|
2013-09-24 21:23:13 +00:00
|
|
|
if( m_cur_grid->AppendRows( 1 ) )
|
|
|
|
{
|
|
|
|
int last_row = m_cur_grid->GetNumberRows() - 1;
|
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
// wx documentation is wrong, SetGridCursor does not make visible.
|
2013-09-24 21:23:13 +00:00
|
|
|
m_cur_grid->MakeCellVisible( last_row, 0 );
|
2013-10-13 21:33:58 +00:00
|
|
|
m_cur_grid->SetGridCursor( last_row, 0 );
|
2013-09-24 21:23:13 +00:00
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void deleteRowHandler( wxMouseEvent& event )
|
|
|
|
{
|
2013-10-13 21:33:58 +00:00
|
|
|
int rowCount = m_cur_grid->GetNumberRows();
|
|
|
|
int curRow = getCursorRow();
|
|
|
|
|
2012-10-18 15:28:50 +00:00
|
|
|
m_cur_grid->DeleteRows( curRow );
|
2013-10-13 21:33:58 +00:00
|
|
|
|
|
|
|
if( curRow && curRow == rowCount - 1 )
|
|
|
|
m_cur_grid->SetGridCursor( curRow-1, getCursorCol() );
|
2012-10-16 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void moveUpHandler( wxMouseEvent& event )
|
|
|
|
{
|
2013-10-05 10:34:55 +00:00
|
|
|
int curRow = getCursorRow();
|
2012-10-18 15:28:50 +00:00
|
|
|
if( curRow >= 1 )
|
|
|
|
{
|
2013-10-05 10:34:55 +00:00
|
|
|
int curCol = getCursorCol();
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL* tbl = cur_model();
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2012-10-31 14:41:47 +00:00
|
|
|
ROW move_me = tbl->rows[curRow];
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2012-10-31 14:41:47 +00:00
|
|
|
tbl->rows.erase( tbl->rows.begin() + curRow );
|
|
|
|
--curRow;
|
|
|
|
tbl->rows.insert( tbl->rows.begin() + curRow, move_me );
|
2012-10-18 15:28:50 +00:00
|
|
|
|
|
|
|
if( tbl->GetView() )
|
|
|
|
{
|
2012-10-31 14:41:47 +00:00
|
|
|
// fire a msg to cause redrawing
|
2012-10-18 15:28:50 +00:00
|
|
|
wxGridTableMessage msg( tbl,
|
|
|
|
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
|
|
|
|
curRow,
|
|
|
|
0 );
|
|
|
|
|
|
|
|
tbl->GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
2012-10-31 14:41:47 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
m_cur_grid->MakeCellVisible( curRow, curCol );
|
2012-10-31 14:41:47 +00:00
|
|
|
m_cur_grid->SetGridCursor( curRow, curCol );
|
2012-10-18 15:28:50 +00:00
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void moveDownHandler( wxMouseEvent& event )
|
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL* tbl = cur_model();
|
2012-10-31 14:41:47 +00:00
|
|
|
|
2013-10-05 10:34:55 +00:00
|
|
|
int curRow = getCursorRow();
|
2012-10-31 14:41:47 +00:00
|
|
|
if( unsigned( curRow + 1 ) < tbl->rows.size() )
|
|
|
|
{
|
2013-10-05 10:34:55 +00:00
|
|
|
int curCol = getCursorCol();
|
2012-10-31 14:41:47 +00:00
|
|
|
|
|
|
|
ROW move_me = tbl->rows[curRow];
|
|
|
|
|
|
|
|
tbl->rows.erase( tbl->rows.begin() + curRow );
|
|
|
|
++curRow;
|
|
|
|
tbl->rows.insert( tbl->rows.begin() + curRow, move_me );
|
|
|
|
|
|
|
|
if( tbl->GetView() )
|
|
|
|
{
|
|
|
|
// fire a msg to cause redrawing
|
|
|
|
wxGridTableMessage msg( tbl,
|
|
|
|
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
|
|
|
|
curRow - 1,
|
|
|
|
0 );
|
|
|
|
|
|
|
|
tbl->GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
m_cur_grid->MakeCellVisible( curRow, curCol );
|
2012-10-31 14:41:47 +00:00
|
|
|
m_cur_grid->SetGridCursor( curRow, curCol );
|
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
void optionsEditor( wxMouseEvent& event )
|
2012-10-16 06:56:57 +00:00
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL* tbl = cur_model();
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
int curRow = getCursorRow();
|
|
|
|
ROW& row = tbl->rows[curRow];
|
2012-10-17 01:00:25 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
wxString result;
|
|
|
|
const wxString& options = row.GetOptions();
|
2012-10-17 01:00:25 +00:00
|
|
|
|
2013-11-12 00:17:27 +00:00
|
|
|
InvokePluginOptionsEditor( this, row.GetNickName(), row.GetType(), options, &result );
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
if( options != result )
|
2012-10-18 15:28:50 +00:00
|
|
|
{
|
2013-10-13 21:33:58 +00:00
|
|
|
row.SetOptions( result );
|
2013-11-12 00:17:27 +00:00
|
|
|
|
|
|
|
// all but options:
|
|
|
|
m_cur_grid->AutoSizeColumn( COL_NICKNAME, false );
|
|
|
|
m_cur_grid->AutoSizeColumn( COL_URI, false );
|
|
|
|
m_cur_grid->AutoSizeColumn( COL_TYPE, false );
|
2012-10-18 15:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
|
|
|
|
void onCancelButtonClick( wxCommandEvent& event )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2012-10-18 15:28:50 +00:00
|
|
|
EndModal( 0 );
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
void onCancelButtonClick( wxCloseEvent& event )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2013-10-13 21:33:58 +00:00
|
|
|
EndModal( 0 );
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 06:56:57 +00:00
|
|
|
void onOKButtonClick( wxCommandEvent& event )
|
2012-12-09 20:51:42 +00:00
|
|
|
{
|
2012-10-18 15:28:50 +00:00
|
|
|
int dialogRet = 0;
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-10-22 19:29:37 +00:00
|
|
|
// stuff any pending cell editor text into the table.
|
|
|
|
m_cur_grid->SaveEditControlValue();
|
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
if( verifyTables() )
|
2012-10-18 15:28:50 +00:00
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
if( *global_model() != *m_global )
|
2013-09-24 21:23:13 +00:00
|
|
|
{
|
|
|
|
dialogRet |= 1;
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
*m_global = *global_model();
|
2013-09-24 21:23:13 +00:00
|
|
|
m_global->reindex();
|
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
if( *project_model() != *m_project )
|
2013-09-24 21:23:13 +00:00
|
|
|
{
|
|
|
|
dialogRet |= 2;
|
2012-10-18 15:28:50 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
*m_project = *project_model();
|
2013-09-24 21:23:13 +00:00
|
|
|
m_project->reindex();
|
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
|
2013-09-24 21:23:13 +00:00
|
|
|
EndModal( dialogRet );
|
|
|
|
}
|
2012-12-09 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 03:12:16 +00:00
|
|
|
/// Populate the readonly environment variable table with names and values
|
|
|
|
/// by examining all the full_uri columns.
|
|
|
|
void populateEnvironReadOnlyTable()
|
|
|
|
{
|
|
|
|
wxRegEx re( wxT( ".*?\\$\\{(.+?)\\}.*?" ), wxRE_ADVANCED );
|
|
|
|
wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
|
|
|
|
|
|
|
|
std::set< wxString > unique;
|
|
|
|
typedef std::set<wxString>::const_iterator SET_CITER;
|
|
|
|
|
2013-10-23 18:56:03 +00:00
|
|
|
// clear the table
|
2013-01-21 03:12:16 +00:00
|
|
|
m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
|
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL* gbl = global_model();
|
|
|
|
FP_TBL_MODEL* prj = project_model();
|
|
|
|
|
|
|
|
int gblRowCount = gbl->GetNumberRows();
|
|
|
|
int prjRowCount = prj->GetNumberRows();
|
2013-01-21 03:12:16 +00:00
|
|
|
int row;
|
|
|
|
|
|
|
|
for( row = 0; row < gblRowCount; ++row )
|
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
wxString uri = gbl->GetValue( row, COL_URI );
|
2013-01-21 03:12:16 +00:00
|
|
|
|
|
|
|
while( re.Matches( uri ) )
|
|
|
|
{
|
|
|
|
wxString envvar = re.GetMatch( uri, 1 );
|
|
|
|
|
|
|
|
// ignore duplicates
|
|
|
|
unique.insert( envvar );
|
|
|
|
|
|
|
|
// delete the last match and search again
|
|
|
|
uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
|
|
|
|
}
|
|
|
|
}
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-01-21 03:12:16 +00:00
|
|
|
for( row = 0; row < prjRowCount; ++row )
|
|
|
|
{
|
2013-10-30 15:33:51 +00:00
|
|
|
wxString uri = prj->GetValue( row, COL_URI );
|
2013-01-21 03:12:16 +00:00
|
|
|
|
|
|
|
while( re.Matches( uri ) )
|
|
|
|
{
|
|
|
|
wxString envvar = re.GetMatch( uri, 1 );
|
|
|
|
|
|
|
|
// ignore duplicates
|
|
|
|
unique.insert( envvar );
|
|
|
|
|
|
|
|
// delete the last match and search again
|
|
|
|
uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 14:11:46 +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( FP_LIB_TABLE::ProjectPathEnvVariableName() );
|
2013-11-15 14:36:11 +00:00
|
|
|
unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
|
2013-11-15 14:11:46 +00:00
|
|
|
|
2013-01-21 03:12:16 +00:00
|
|
|
m_path_subs_grid->AppendRows( unique.size() );
|
|
|
|
|
|
|
|
row = 0;
|
|
|
|
for( SET_CITER it = unique.begin(); it != unique.end(); ++it, ++row )
|
|
|
|
{
|
|
|
|
wxString evName = *it;
|
|
|
|
wxString evValue;
|
|
|
|
|
|
|
|
m_path_subs_grid->SetCellValue( row, 0, evName );
|
|
|
|
|
|
|
|
if( wxGetEnv( evName, &evValue ) )
|
|
|
|
m_path_subs_grid->SetCellValue( row, 1, evValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_path_subs_grid->AutoSizeColumns();
|
|
|
|
}
|
|
|
|
|
2012-12-09 20:51:42 +00:00
|
|
|
//-----</event handlers>---------------------------------
|
2012-10-16 06:56:57 +00:00
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
// caller's tables are modified only on OK button and successful verification.
|
2012-10-16 06:56:57 +00:00
|
|
|
FP_LIB_TABLE* m_global;
|
|
|
|
FP_LIB_TABLE* m_project;
|
|
|
|
|
2013-10-30 15:33:51 +00:00
|
|
|
FP_TBL_MODEL* global_model() const { return (FP_TBL_MODEL*) m_global_grid->GetTable(); }
|
|
|
|
FP_TBL_MODEL* project_model() const { return (FP_TBL_MODEL*) m_project_grid->GetTable(); }
|
|
|
|
FP_TBL_MODEL* cur_model() const { return (FP_TBL_MODEL*) m_cur_grid->GetTable(); }
|
2012-10-16 06:56:57 +00:00
|
|
|
|
|
|
|
wxGrid* m_cur_grid; ///< changed based on tab choice
|
2012-10-15 22:30:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
int InvokePcbLibTableEditor( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject )
|
2012-10-15 22:30:01 +00:00
|
|
|
{
|
2012-10-18 15:28:50 +00:00
|
|
|
DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject );
|
2012-10-15 22:30:01 +00:00
|
|
|
|
2012-10-18 15:28:50 +00:00
|
|
|
int dialogRet = dlg.ShowModal(); // returns value passed to EndModal() above
|
2012-10-15 22:30:01 +00:00
|
|
|
|
2012-10-18 15:28:50 +00:00
|
|
|
return dialogRet;
|
2012-10-15 22:30:01 +00:00
|
|
|
}
|