From 9e41a8127dc65ef66d0702f70f54969b94d9691b Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Thu, 18 Oct 2012 10:28:50 -0500 Subject: [PATCH] more fp_lib_table work --- include/fp_lib_table.h | 21 +++- pcbnew/dialogs/dialog_fp_lib_table.cpp | 163 +++++++++++++++++++------ pcbnew/pcbnew_config.cpp | 4 +- 3 files changed, 152 insertions(+), 36 deletions(-) diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index ba5d6482e5..2d23bee00e 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -100,7 +100,9 @@ public: typedef IO_MGR::PCB_FILE_T LIB_T; - ROW(){} + ROW() : type( IO_MGR::KICAD ) + { + } ROW( const wxString& aNick, const wxString& aURI, const wxString& aType, const wxString& aOptions ) : nickName( aNick ), @@ -222,6 +224,23 @@ public: */ FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL ); + bool operator==( const FP_LIB_TABLE& r ) const + { + if( rows.size() == r.rows.size() ) + { + unsigned i; + for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i ) + ; + + if( i == rows.size() ) + return true; + } + + return false; + } + + bool operator!=( const FP_LIB_TABLE& r ) const { return !( *this == r ); } + /** * Function Parse * fills this table fragment from information in the input stream \a aParser, which diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index f02f0f9c1b..b78e9ff883 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -28,13 +28,12 @@ #include #include #include -#include /** * Class FP_TBL_MODEL * mixes in wxGridTableBase into FP_LIB_TABLE so that the latter can be used - * as table within wxGrid. + * as a table within wxGrid. */ class FP_TBL_MODEL : public wxGridTableBase, public FP_LIB_TABLE { @@ -42,23 +41,14 @@ public: /** * Constructor FP_TBL_MODEL - * builds a wxGridTableBase (table model) by wrapping an FP_LIB_TABLE. - * @a aFallBackTable. Loading of this table fragment is done by using Parse(). - * - * @param aFallBackTable is another FP_LIB_TABLE which is searched only when - * a record is not found in this table. No ownership is - * taken of aFallBackTable. + * is a copy constructor that builds a wxGridTableBase (table model) by wrapping + * an FP_LIB_TABLE. */ FP_TBL_MODEL( const FP_LIB_TABLE& aTableToEdit ) : FP_LIB_TABLE( aTableToEdit ) // copy constructor { } - ~FP_TBL_MODEL() - { - D(printf("%s\n", __func__ );) - } - //------------------------------------------------ int GetNumberRows () { return rows.size(); } @@ -93,8 +83,8 @@ public: switch( aCol ) { case 0: r.SetNickName( aValue ); break; - case 1: r.SetType( aValue ); break; - case 2: r.SetFullURI( aValue ); break; + case 1: r.SetFullURI( aValue ); break; + case 2: r.SetType( aValue ); break; case 3: r.SetOptions( aValue ); break; } } @@ -112,6 +102,18 @@ public: if( aPos < rows.size() ) { rows.insert( rows.begin() + aPos, aNumRows, ROW() ); + + // use the (wxGridStringTable) source Luke. + if( GetView() ) + { + wxGridTableMessage msg( this, + wxGRIDTABLE_NOTIFY_ROWS_INSERTED, + aPos, + aNumRows ); + + GetView()->ProcessTableMessage( msg ); + } + return true; } return false; @@ -119,8 +121,19 @@ public: bool AppendRows( size_t aNumRows = 1 ) { - while( aNumRows-- ) + // do not modify aNumRows, original value needed for wxGridTableMessage below + for( int i = aNumRows; i; --i ) rows.push_back( ROW() ); + + if( GetView() ) + { + wxGridTableMessage msg( this, + wxGRIDTABLE_NOTIFY_ROWS_APPENDED, + aNumRows ); + + GetView()->ProcessTableMessage( msg ); + } + return true; } @@ -130,6 +143,17 @@ public: { ROWS_ITER start = rows.begin() + aPos; rows.erase( start, start + aNumRows ); + + if( GetView() ) + { + wxGridTableMessage msg( this, + wxGRIDTABLE_NOTIFY_ROWS_DELETED, + aPos, + aNumRows ); + + GetView()->ProcessTableMessage( msg ); + } + return true; } return false; @@ -168,6 +192,39 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE { typedef FP_LIB_TABLE::ROW ROW; + /* row & col "selection" acquisition, not currently used but works. + // selected area by cell coordinate and count + int selRowStart; + int selColStart; + int selRowCount; + int selColCount; + + /// Gets the selected area into a sensible rectable of sel{Row,Col}{Start,Count} above. + void getSelectedArea() + { + wxGridCellCoordsArray topLeft = m_cur_grid->GetSelectionBlockTopLeft(); + wxGridCellCoordsArray botRight = m_cur_grid->GetSelectionBlockBottomRight(); + + if( topLeft.Count() && botRight.Count() ) + { + selRowStart = topLeft[0].GetRow(); + selColStart = topLeft[0].GetCol(); + + selRowCount = botRight[0].GetRow() - selRowStart + 1; + selColCount = botRight[0].GetCol() - selColStart + 1; + } + else + { + selRowStart = -1; + selColStart = -1; + selRowCount = 0; + selColCount = 0; + } + + D(printf("selRowStart:%d selColStart:%d selRowCount:%d selColCount:%d\n", + selRowStart, selColStart, selRowCount, selColCount );) + } + */ //--------------------------------------- @@ -175,22 +232,52 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE { int pageNdx = m_auinotebook->GetSelection(); - m_cur_grid = pageNdx ? m_global_grid : m_project_grid; + m_cur_grid = pageNdx==0 ? m_global_grid : m_project_grid; + + D(printf("%s cur_grid is %s\n", __func__, pageNdx==0 ? "global" : "project" );) } void appendRowHandler( wxMouseEvent& event ) { D(printf("%s\n", __func__);) + m_cur_grid->AppendRows( 1 ); } void deleteRowHandler( wxMouseEvent& event ) { D(printf("%s\n", __func__);) + + int curRow = m_cur_grid->GetGridCursorRow(); + + m_cur_grid->DeleteRows( curRow ); } void moveUpHandler( wxMouseEvent& event ) { D(printf("%s\n", __func__);) + + int curRow = m_cur_grid->GetGridCursorRow(); + if( curRow >= 1 ) + { + FP_TBL_MODEL* tbl = (FP_TBL_MODEL*) m_cur_grid->GetTable(); + + ROW save = tbl->rows[curRow]; + + tbl->DeleteRows( curRow, 1 ); + tbl->InsertRows( --curRow, 1 ); + + tbl->rows[curRow] = save; + + if( tbl->GetView() ) + { + wxGridTableMessage msg( tbl, + wxGRIDTABLE_NOTIFY_ROWS_INSERTED, + curRow, + 0 ); + + tbl->GetView()->ProcessTableMessage( msg ); + } + } } void moveDownHandler( wxMouseEvent& event ) @@ -200,20 +287,32 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE void onCancelButtonClick( wxCommandEvent& event ) { - EndModal( wxID_CANCEL ); + EndModal( 0 ); } void onOKButtonClick( wxCommandEvent& event ) { - *m_global = m_global_model; - *m_project = m_project_model; + int dialogRet = 0; - // @todo reindex, or add member function for wholesale row replacement + if( m_global_model != *m_global ) + { + dialogRet |= 1; - EndModal( wxID_OK ); + *m_global = m_global_model; + m_global->reindex(); + } + + if( m_project_model != *m_project ) + { + dialogRet |= 2; + + *m_project = m_project_model; + m_project->reindex(); + } + + EndModal( dialogRet ); } - //-------------------------------------- @@ -244,6 +343,10 @@ public: m_project_grid->AutoSizeColumns( false ); m_path_subs_grid->AutoSizeColumns( false ); + + // fire pageChangedHandler() so m_cur_grid gets set + wxAuiNotebookEvent uneventful; + pageChangedHandler( uneventful ); } ~DIALOG_FP_LIB_TABLE() @@ -262,18 +365,10 @@ public: 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 ); - int ret = dlg.ShowModal(); - switch( ret ) - { - case wxID_OK: - break; + int dialogRet = dlg.ShowModal(); // returns value passed to EndModal() above - case wxID_CANCEL: - break; - } - - return 0; + return dialogRet; } diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index ce528a3df1..8930e593dc 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -102,11 +102,13 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) if( r & 1 ) { // save global table to disk and apply it + D( printf( "global has changed\n" );) } if( r & 2 ) { - // save project table to disk and apply it + // save project table to disk and apply it + D( printf( "project has changed\n" );) } } break;