Commit fb43f4ad authored by Dick Hollenbeck's avatar Dick Hollenbeck

fp_lib_table dialog work

parent 80693fa7
......@@ -178,6 +178,52 @@ std::vector<wxString> FP_LIB_TABLE::GetLogicalLibs()
}
FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aNickName ) const
{
// this function must be *super* fast, so therefore should not instantiate
// anything which would require using the heap.
const FP_LIB_TABLE* cur = this;
do
{
INDEX_CITER it = cur->nickIndex.find( aNickName );
if( it != cur->nickIndex.end() )
{
return (FP_LIB_TABLE::ROW*) &cur->rows[it->second]; // found
}
// not found, search fall back table(s), if any
} while( ( cur = cur->fallBack ) != 0 );
return 0; // not found
}
bool FP_LIB_TABLE::InsertRow( const ROW& aRow, bool doReplace )
{
// this does not need to be super fast.
INDEX_CITER it = nickIndex.find( aRow.nickName );
if( it == nickIndex.end() )
{
rows.push_back( aRow );
nickIndex.insert( INDEX_VALUE( aRow.nickName, rows.size() - 1 ) );
return true;
}
if( doReplace )
{
rows[it->second] = aRow;
return true;
}
return false;
}
#if 0 // will need PLUGIN_RELEASER.
MODULE* FP_LIB_TABLE::LookupFootprint( const FP_LIB_ID& aFootprintId )
throw( IO_ERROR )
......@@ -256,47 +302,3 @@ void FP_LIB_TABLE::loadLib( ROW* aRow ) throw( IO_ERROR )
}
#endif
FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aNickName ) const
{
// this function must be *super* fast, so therefore should not instantiate
// anything which would require using the heap.
const FP_LIB_TABLE* cur = this;
do
{
INDEX_CITER it = cur->nickIndex.find( aNickName );
if( it != cur->nickIndex.end() )
{
return (FP_LIB_TABLE::ROW*) &cur->rows[it->second]; // found
}
// not found, search fall back table(s), if any
} while( ( cur = cur->fallBack ) != 0 );
return 0; // not found
}
bool FP_LIB_TABLE::InsertRow( const ROW& aRow, bool doReplace )
{
// this does not need to be super fast.
INDEX_CITER it = nickIndex.find( aRow.nickName );
if( it == nickIndex.end() )
{
rows.push_back( aRow );
nickIndex.insert( INDEX_VALUE( aRow.nickName, rows.size() - 1 ) );
return true;
}
if( doReplace )
{
rows[it->second] = aRow;
return true;
}
return false;
}
......@@ -82,6 +82,8 @@ class FP_LIB_TABLE_LEXER;
*/
class FP_LIB_TABLE : public wxGridTableBase
{
friend class DIALOG_FP_LIB_TABLE;
public:
/**
......@@ -92,6 +94,7 @@ public:
class ROW
{
friend class FP_LIB_TABLE;
friend class DIALOG_FP_LIB_TABLE;
public:
......@@ -148,8 +151,6 @@ public:
void Format( OUTPUTFORMATTER* out, int nestLevel ) const
throw( IO_ERROR );
protected:
ROW( FP_LIB_TABLE* aOwner ) :
owner( aOwner )
// lib( 0 )
......@@ -316,9 +317,9 @@ public:
switch( aCol )
{
case 1: r.SetType( aValue );
case 2: r.SetFullURI( aValue );
case 3: r.SetOptions( aValue );
case 1: r.SetType( aValue ); break;
case 2: r.SetFullURI( aValue ); break;
case 3: r.SetOptions( aValue ); break;
}
}
}
......@@ -330,6 +331,51 @@ public:
return true;
}
bool InsertRows( size_t aPos = 0, size_t aNumRows = 1 )
{
if( aPos < rows.size() )
{
rows.insert( rows.begin() + aPos, aNumRows, ROW( this ) );
return true;
}
return false;
}
bool AppendRows( size_t aNumRows = 1 )
{
while( aNumRows-- )
rows.push_back( ROW( this ) );
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 );
return true;
}
return false;
}
void Clear()
{
rows.clear();
}
wxString GetColLabelValue( int aCol )
{
switch( aCol )
{
case 0: return _( "Nickname" );
case 1: return _( "Plugin" );
case 2: return _( "Library Path" );
case 3: return _( "Options" );
default: return wxEmptyString;
}
}
//-----</wxGridTableBase overloads>------------------------------------------
......
......@@ -24,7 +24,7 @@
*/
#include <fctsys.h>
#include <dialog_fp_lib_table_base.h>
#include <fp_lib_table.h>
......@@ -35,11 +35,113 @@
*/
class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
{
//-----<event handlers>----------------------------------
void pageChangedHandler( wxAuiNotebookEvent& event )
{
int pageNdx = m_auinotebook->GetSelection();
m_cur_grid = pageNdx ? m_global_grid : m_project_grid;
}
void appendRowHandler( wxMouseEvent& event )
{
D(printf("%s\n", __func__);)
}
void deleteRowHandler( wxMouseEvent& event )
{
D(printf("%s\n", __func__);)
}
void moveUpHandler( wxMouseEvent& event )
{
D(printf("%s\n", __func__);)
}
void moveDownHandler( wxMouseEvent& event )
{
D(printf("%s\n", __func__);)
}
void onCancelButtonClick( wxCommandEvent& event )
{
m_global->rows = m_orig_global;
m_project->rows = m_orig_project;
// @todo reindex, or add member function for wholesale row replacement
EndModal( wxID_CANCEL );
}
void onOKButtonClick( wxCommandEvent& event )
{
EndModal( wxID_OK );
}
//-----</event handlers>---------------------------------
// caller's tables are modified only on OK button.
FP_LIB_TABLE* m_global;
FP_LIB_TABLE* m_project;
// local copies are saved and restored if Cancel button.
FP_LIB_TABLE::ROWS m_orig_global;
FP_LIB_TABLE::ROWS m_orig_project;
wxGrid* m_cur_grid; ///< changed based on tab choice
public:
DIALOG_FP_LIB_TABLE( wxFrame* aParent ) :
DIALOG_FP_LIB_TABLE_BASE( aParent )
DIALOG_FP_LIB_TABLE( wxFrame* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ) :
DIALOG_FP_LIB_TABLE_BASE( aParent ),
m_global( aGlobal ),
m_project( aProject ),
m_orig_global( aGlobal->rows ),
m_orig_project( aProject->rows )
{
/*
GetSizer()->SetSizeHints( this );
Centre();
SetAutoLayout( true );
Layout();
*/
#if 1 && defined(DEBUG)
// put some dummy data into table(s)
FP_LIB_TABLE::ROW row( m_global );
row.SetNickName( wxT( "passives" ) );
row.SetType( wxT( "kicad" ) );
row.SetFullURI( wxT( "%G/passives" ) );
row.SetOptions( wxT( "speed=fast,purpose=testing" ) );
m_global->InsertRow( row );
row.SetNickName( wxT( "micros" ) );
row.SetType( wxT( "legacy" ) );
row.SetFullURI( wxT( "%P/micros" ) );
row.SetOptions( wxT( "speed=fast,purpose=testing" ) );
m_global->InsertRow( row );
row.owner = m_project;
row.SetFullURI( wxT( "%P/chips" ) );
m_project->InsertRow( row );
#endif
m_global_grid->SetTable( m_global );
m_project_grid->SetTable( m_project );
//m_global_grid->AutoSize();
m_global_grid->AutoSizeColumns( false );
//m_project_grid->AutoSize();
m_project_grid->AutoSizeColumns( false );
//m_path_subs_grid->AutoSize();
m_path_subs_grid->AutoSizeColumns( false );
}
};
......@@ -47,9 +149,17 @@ public:
int InvokePcbLibTableEditor( wxFrame* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject )
{
DIALOG_FP_LIB_TABLE dlg( aParent );
DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject );
dlg.Show( true );
int ret = dlg.ShowModal();
switch( ret )
{
case wxID_OK:
break;
case wxID_CANCEL:
break;
}
return 0;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -42,32 +42,42 @@ class DIALOG_FP_LIB_TABLE_BASE : public DIALOG_SHIM
private:
protected:
wxSplitterWindow* m_splitter1;
wxSplitterWindow* m_splitter;
wxPanel* m_top;
wxAuiNotebook* m_auinotebook2;
wxPanel* m_panel4;
wxGrid* m_grid1;
wxPanel* m_panel5;
wxGrid* m_grid11;
wxButton* m_button1;
wxButton* m_button2;
wxButton* m_button3;
wxButton* m_button4;
wxAuiNotebook* m_auinotebook;
wxPanel* m_global_panel;
wxGrid* m_global_grid;
wxPanel* m_project_panel;
wxGrid* m_project_grid;
wxButton* m_append_button;
wxButton* m_delete_button;
wxButton* m_move_up_button;
wxButton* m_move_down_button;
wxPanel* m_bottom;
wxGrid* m_grid2;
wxGrid* m_path_subs_grid;
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void pageChangedHandler( wxAuiNotebookEvent& event ) { event.Skip(); }
virtual void appendRowHandler( wxMouseEvent& event ) { event.Skip(); }
virtual void deleteRowHandler( wxMouseEvent& event ) { event.Skip(); }
virtual void moveUpHandler( wxMouseEvent& event ) { event.Skip(); }
virtual void moveDownHandler( wxMouseEvent& event ) { event.Skip(); }
virtual void onCancelButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onOKButtonClick( wxCommandEvent& event ) { event.Skip(); }
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( -1,-1 ), 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( 864,652 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_FP_LIB_TABLE_BASE();
void m_splitter1OnIdle( wxIdleEvent& )
void m_splitterOnIdle( wxIdleEvent& )
{
m_splitter1->SetSashPosition( 254 );
m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitter1OnIdle ), NULL, this );
m_splitter->SetSashPosition( 343 );
m_splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitterOnIdle ), NULL, this );
}
};
......
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