Commit 8fd0c322 authored by Dick Hollenbeck's avatar Dick Hollenbeck

more fp lib table work

parent 75072f43
...@@ -24,12 +24,27 @@ ...@@ -24,12 +24,27 @@
*/ */
/* TODO:
*) Check for duplicate nicknames per table
*) Grab text from any pending ChoiceEditor when OK button pressed.
*) Test wxRE_ADVANCED on Windows.
*/
#include <fctsys.h> #include <fctsys.h>
#include <dialog_fp_lib_table_base.h> #include <dialog_fp_lib_table_base.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
#include <wx/grid.h> #include <wx/grid.h>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#include <wx/arrstr.h>
#include <wx/regex.h>
#include <set>
/** /**
* Class FP_TBL_MODEL * Class FP_TBL_MODEL
...@@ -184,18 +199,32 @@ public: ...@@ -184,18 +199,32 @@ public:
{ {
case COL_NICKNAME: return _( "Nickname" ); case COL_NICKNAME: return _( "Nickname" );
case COL_URI: return _( "Library Path" ); case COL_URI: return _( "Library Path" );
case COL_TYPE: return _( "Plugin" );
// keep this text fairly long so column is sized wide enough
case COL_TYPE: return _( "Plugin Type" );
case COL_OPTIONS: return _( "Options" ); case COL_OPTIONS: return _( "Options" );
case COL_DESCR: return _( "Description" ); case COL_DESCR: return _( "Description" );
default: return wxEmptyString; default: return wxEmptyString;
} }
} }
/*
wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) const // overload
{
if( aCol != COL_TYPE )
return wxGridTableBase::GetAttr( aRow, aCol, aKind );
else
{
}
}
*/
//-----</wxGridTableBase overloads>------------------------------------------ //-----</wxGridTableBase overloads>------------------------------------------
}; };
// It works for table data on clipboard for an excell spreadsheet, // It works for table data on clipboard for an Excell spreadsheet,
// why not us too for now. // why not us too for now.
#define COL_SEP wxT( '\t' ) #define COL_SEP wxT( '\t' )
#define ROW_SEP wxT( '\n' ) #define ROW_SEP wxT( '\n' )
...@@ -509,6 +538,71 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE ...@@ -509,6 +538,71 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
event.Skip(); event.Skip();
} }
/// 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;
m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );
int gblRowCount = m_global_model.GetNumberRows();
int prjRowCount = m_project_model.GetNumberRows();
int row;
for( row = 0; row < gblRowCount; ++row )
{
wxString uri = m_global_model.GetValue( row, FP_TBL_MODEL::COL_URI );
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 );
}
}
for( row = 0; row < prjRowCount; ++row )
{
wxString uri = m_project_model.GetValue( row, FP_TBL_MODEL::COL_URI );
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 );
}
}
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();
}
//-----</event handlers>--------------------------------- //-----</event handlers>---------------------------------
// caller's tables are modified only on OK button. // caller's tables are modified only on OK button.
...@@ -540,14 +634,38 @@ public: ...@@ -540,14 +634,38 @@ public:
m_project_grid->SetTable( (wxGridTableBase*) &m_project_model ); m_project_grid->SetTable( (wxGridTableBase*) &m_project_model );
m_global_grid->AutoSizeColumns( false ); m_global_grid->AutoSizeColumns( false );
m_project_grid->AutoSizeColumns( false ); m_project_grid->AutoSizeColumns( false );
m_path_subs_grid->AutoSizeColumns( false ); wxArrayString choices;
choices.Add( IO_MGR::ShowType( IO_MGR::KICAD ) );
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 ) );
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
m_project_grid->SetColAttr( FP_TBL_MODEL::COL_TYPE, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
m_global_grid->SetColAttr( FP_TBL_MODEL::COL_TYPE, attr );
m_global_grid->AutoSizeColumns();
m_project_grid->AutoSizeColumns();
m_path_subs_grid->AutoSizeColumns();
Connect( ID_CUT, ID_PASTE, wxEVT_COMMAND_MENU_SELECTED, Connect( ID_CUT, ID_PASTE, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler( DIALOG_FP_LIB_TABLE::onPopupSelection ), NULL, this ); wxCommandEventHandler( DIALOG_FP_LIB_TABLE::onPopupSelection ), NULL, this );
populateEnvironReadOnlyTable();
/* This scrunches the dialog hideously
Fit();
*/
// fire pageChangedHandler() so m_cur_grid gets set // fire pageChangedHandler() so m_cur_grid gets set
wxAuiNotebookEvent uneventful; wxAuiNotebookEvent uneventful;
pageChangedHandler( uneventful ); pageChangedHandler( uneventful );
...@@ -555,18 +673,18 @@ public: ...@@ -555,18 +673,18 @@ public:
~DIALOG_FP_LIB_TABLE() ~DIALOG_FP_LIB_TABLE()
{ {
// Destroy the gui stuff first, with a goal of destroying the two wxGrids now, Disconnect( ID_CUT, ID_PASTE, wxEVT_COMMAND_MENU_SELECTED,
// since the ~wxGrid() wants the wxGridTableBase to still be non-destroyed. wxCommandEventHandler( DIALOG_FP_LIB_TABLE::onPopupSelection ), NULL, this );
// Without this call, the wxGridTableBase objects are destroyed first
// (i.e. destructor called) and there is a segfault since wxGridTableBase's vtable // ~wxGrid() examines its table, and the tables will have been destroyed before
// is then no longer valid. If ~wxGrid() would not examine a wxGridTableBase that // the wxGrids are, so remove the tables from the wxGrids' awareness.
// it does not own, then this would not be a concern. But it is, since it does. // Otherwise there is a segfault.
DestroyChildren(); m_global_grid->SetTable( NULL );
m_project_grid->SetTable( NULL );
} }
}; };
int InvokePcbLibTableEditor( wxFrame* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ) int InvokePcbLibTableEditor( wxFrame* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject )
{ {
DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject ); DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject );
......
...@@ -142,7 +142,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID ...@@ -142,7 +142,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
m_path_subs_grid = new wxGrid( m_bottom, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_path_subs_grid = new wxGrid( m_bottom, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid // Grid
m_path_subs_grid->CreateGrid( 2, 2 ); m_path_subs_grid->CreateGrid( 1, 2 );
m_path_subs_grid->EnableEditing( true ); m_path_subs_grid->EnableEditing( true );
m_path_subs_grid->EnableGridLines( true ); m_path_subs_grid->EnableGridLines( true );
m_path_subs_grid->EnableDragGridSize( false ); m_path_subs_grid->EnableDragGridSize( false );
...@@ -155,15 +155,13 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID ...@@ -155,15 +155,13 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
m_path_subs_grid->EnableDragColMove( false ); m_path_subs_grid->EnableDragColMove( false );
m_path_subs_grid->EnableDragColSize( true ); m_path_subs_grid->EnableDragColSize( true );
m_path_subs_grid->SetColLabelSize( 30 ); m_path_subs_grid->SetColLabelSize( 30 );
m_path_subs_grid->SetColLabelValue( 0, _("Category") ); m_path_subs_grid->SetColLabelValue( 0, _("Environment Variable") );
m_path_subs_grid->SetColLabelValue( 1, _("Path Segment") ); m_path_subs_grid->SetColLabelValue( 1, _("Path Segment") );
m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Rows // Rows
m_path_subs_grid->EnableDragRowSize( true ); m_path_subs_grid->EnableDragRowSize( true );
m_path_subs_grid->SetRowLabelSize( 40 ); m_path_subs_grid->SetRowLabelSize( 40 );
m_path_subs_grid->SetRowLabelValue( 0, _("%S") );
m_path_subs_grid->SetRowLabelValue( 1, _("%P") );
m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Label Appearance // Label Appearance
...@@ -188,7 +186,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID ...@@ -188,7 +186,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
m_bottom->SetSizer( m_bottom_sizer ); m_bottom->SetSizer( m_bottom_sizer );
m_bottom->Layout(); m_bottom->Layout();
m_bottom_sizer->Fit( m_bottom ); m_bottom_sizer->Fit( m_bottom );
m_splitter->SplitHorizontally( m_top, m_bottom, 343 ); m_splitter->SplitHorizontally( m_top, m_bottom, 398 );
bSizer1->Add( m_splitter, 2, wxEXPAND, 5 ); bSizer1->Add( m_splitter, 2, wxEXPAND, 5 );
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">DIALOG_FP_LIB_TABLE_BASE</property> <property name="name">DIALOG_FP_LIB_TABLE_BASE</property>
<property name="pos"></property> <property name="pos"></property>
<property name="size">864,652</property> <property name="size">996,652</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property> <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property> <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">PCB Library Tables</property> <property name="title">PCB Library Tables</property>
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
<property name="pos"></property> <property name="pos"></property>
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="sashgravity">0.0</property> <property name="sashgravity">0.0</property>
<property name="sashpos">343</property> <property name="sashpos">398</property>
<property name="sashsize">-1</property> <property name="sashsize">-1</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
...@@ -1297,7 +1297,7 @@ ...@@ -1297,7 +1297,7 @@
<property name="close_button">1</property> <property name="close_button">1</property>
<property name="col_label_horiz_alignment">wxALIGN_CENTRE</property> <property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="col_label_size">30</property> <property name="col_label_size">30</property>
<property name="col_label_values">&quot;Category&quot; &quot;Path Segment&quot;</property> <property name="col_label_values">&quot;Environment Variable&quot; &quot;Path Segment&quot;</property>
<property name="col_label_vert_alignment">wxALIGN_CENTRE</property> <property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="cols">2</property> <property name="cols">2</property>
<property name="column_sizes">150,500</property> <property name="column_sizes">150,500</property>
...@@ -1343,10 +1343,10 @@ ...@@ -1343,10 +1343,10 @@
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="row_label_horiz_alignment">wxALIGN_CENTRE</property> <property name="row_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="row_label_size">40</property> <property name="row_label_size">40</property>
<property name="row_label_values">&quot;%S&quot; &quot;%P&quot;</property> <property name="row_label_values"></property>
<property name="row_label_vert_alignment">wxALIGN_CENTRE</property> <property name="row_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="row_sizes"></property> <property name="row_sizes"></property>
<property name="rows">2</property> <property name="rows">1</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
<property name="subclass"></property> <property name="subclass"></property>
......
...@@ -75,12 +75,12 @@ class DIALOG_FP_LIB_TABLE_BASE : public DIALOG_SHIM ...@@ -75,12 +75,12 @@ class DIALOG_FP_LIB_TABLE_BASE : public DIALOG_SHIM
public: public:
DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("PCB Library Tables"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 864,652 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("PCB Library Tables"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 996,652 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_FP_LIB_TABLE_BASE(); ~DIALOG_FP_LIB_TABLE_BASE();
void m_splitterOnIdle( wxIdleEvent& ) void m_splitterOnIdle( wxIdleEvent& )
{ {
m_splitter->SetSashPosition( 343 ); m_splitter->SetSashPosition( 398 );
m_splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitterOnIdle ), NULL, this ); m_splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitterOnIdle ), NULL, this );
} }
......
...@@ -51,6 +51,8 @@ public: ...@@ -51,6 +51,8 @@ public:
LEGACY, //< Legacy Pcbnew file formats prior to s-expression. LEGACY, //< Legacy Pcbnew file formats prior to s-expression.
KICAD, //< S-expression Pcbnew file format. KICAD, //< S-expression Pcbnew file format.
EAGLE, EAGLE,
PCAD,
GEDA_PCB, //< Geda PCB file formats.
// add your type here. // add your type here.
......
...@@ -45,9 +45,7 @@ ...@@ -45,9 +45,7 @@
#include <class_board.h> #include <class_board.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
#if defined(DEBUG) #include <fp_lib_table_lexer.h>
#include <fp_lib_table_lexer.h>
#endif
#include <pcbplot.h> #include <pcbplot.h>
#include <pcbnew.h> #include <pcbnew.h>
...@@ -92,7 +90,6 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -92,7 +90,6 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
FP_LIB_TABLE gbl; FP_LIB_TABLE gbl;
FP_LIB_TABLE prj; FP_LIB_TABLE prj;
#if defined(DEBUG)
FP_LIB_TABLE_LEXER glex( FP_LIB_TABLE_LEXER glex(
"(fp_lib_table\n" "(fp_lib_table\n"
" (lib (name passives)(descr \"R/C Lib\")(type KiCad)(uri ${KISYSMODS}/passives.pretty))\n" " (lib (name passives)(descr \"R/C Lib\")(type KiCad)(uri ${KISYSMODS}/passives.pretty))\n"
...@@ -124,29 +121,35 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -124,29 +121,35 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
break; break;
} }
#else
gbl.InsertRow( FP_LIB_TABLE::ROW(
wxT( "passives" ), wxT( "%G/passives" ), wxT( "KiCad" ), wxT( "speed=fast,purpose=testing" ) ) );
gbl.InsertRow( FP_LIB_TABLE::ROW(
wxT( "micros" ), wxT( "%P/micros" ), wxT( "Legacy" ), wxT( "speed=fast,purpose=testing" ) ) );
prj.InsertRow( FP_LIB_TABLE::ROW(
wxT( "micros" ), wxT( "%P/potato_chips" ), wxT( "Eagle" ), wxT( "speed=fast,purpose=testing" ) ) );
#endif
int r = InvokePcbLibTableEditor( this, &gbl, &prj ); int r = InvokePcbLibTableEditor( this, &gbl, &prj );
if( r & 1 ) if( r & 1 )
{ {
#if defined(DEBUG)
printf( "changed global:\n" );)
STRING_FORMATTER sf;
gbl.Format( &sf, 0 );
printf( "%s\n", sf.GetString().c_str() );
#endif
// save global table to disk and apply it // save global table to disk and apply it
D( printf( "global has changed\n" );)
} }
if( r & 2 ) if( r & 2 )
{ {
#if defined(DEBUG)
D( printf( "changed project:n" );)
STRING_FORMATTER sf;
prj.Format( &sf, 0 );
printf( "%s\n", sf.GetString().c_str() );
#endif
// save project table to disk and apply it // save project table to disk and apply it
D( printf( "project has changed\n" );)
} }
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment