From e61505149ae495b0bdd0b56b92f4d915082beb70 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Thu, 24 Oct 2013 08:58:05 -0500 Subject: [PATCH] more DIALOG_FP_PLUGIN_OPTIONS work, make PROPERTIES a map instead of a hashtable for alphabetical iteration. --- include/hashtables.h | 13 ---- pcbnew/dialogs/dialog_fp_lib_table.cpp | 3 + pcbnew/dialogs/dialog_fp_plugin_options.cpp | 83 ++++++++++++++++++--- pcbnew/io_mgr.h | 13 +++- 4 files changed, 87 insertions(+), 25 deletions(-) diff --git a/include/hashtables.h b/include/hashtables.h index 04c842808a..edb3f798e0 100644 --- a/include/hashtables.h +++ b/include/hashtables.h @@ -36,12 +36,6 @@ #include -/// Map a C string to a wxString, used in PLUGINs. -/// was typedef std::unordered_map< std::string, std::string > PROPERTIES; -class PROPERTIES : public std::unordered_map< std::string, std::string > -{ -}; - /// Map a C string to an integer. Used in DSNLEXER. typedef std::unordered_map< std::string, int > KEYWORD_MAP; @@ -60,13 +54,6 @@ typedef std::unordered_map< std::string, EDA_RECT > RECT_MAP; // see http://www.boost.org/doc/libs/1_49_0/doc/html/boost/unordered_map.html -/// Map a std::string to a wxString, used in PLUGINs. -/// was typedef boost::unordered_map< std::string, std::string > PROPERTIES; -class PROPERTIES : public boost::unordered_map< std::string, std::string > -{ -}; - - /// Equality test for "const char*" type used in very specialized KEYWORD_MAP below struct iequal_to : std::binary_function< const char*, const char*, bool > { diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index 33797c7334..3b614b18da 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -512,7 +512,10 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE InvokePluginOptionsEditor( this, row.GetNickName(), options, &result ); if( options != result ) + { row.SetOptions( result ); + m_cur_grid->AutoSizeColumn( COL_OPTIONS, false ); + } } void onCancelButtonClick( wxCommandEvent& event ) diff --git a/pcbnew/dialogs/dialog_fp_plugin_options.cpp b/pcbnew/dialogs/dialog_fp_plugin_options.cpp index 583985ead7..523eccbb31 100644 --- a/pcbnew/dialogs/dialog_fp_plugin_options.cpp +++ b/pcbnew/dialogs/dialog_fp_plugin_options.cpp @@ -29,6 +29,12 @@ #include #include +using std::string; + +// re-enter the dialog with the column sizes preserved from last time. +static int col_width_option; +static int col_width_value; + class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE { @@ -38,7 +44,6 @@ public: const wxString& aNickname, const wxString& aOptions, wxString* aResult ) : DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ), m_callers_options( aOptions ), - m_options( aOptions ), m_result( aResult ) { wxString title = wxString::Format( @@ -46,26 +51,85 @@ public: SetTitle( title ); - m_grid->AutoSizeColumns( false ); - // add Cut, Copy, and Paste to wxGrids m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); + string options = TO_UTF8( aOptions ); + + PROPERTIES* props = FP_LIB_TABLE::ParseOptions( options ); + + if( props ) + { + m_grid->AppendRows( props->size() ); + + int row = 0; + for( PROPERTIES::const_iterator it = props->begin(); it != props->end(); ++it, ++row ) + { + m_grid->SetCellValue( row, 0, FROM_UTF8( it->first.c_str() ) ); + m_grid->SetCellValue( row, 1, FROM_UTF8( it->second.c_str() ) ); + } + } + + if( !col_width_option ) + { + m_grid->AutoSizeColumns( false ); + } + else + { + m_grid->SetColSize( 0, col_width_option ); + m_grid->SetColSize( 1, col_width_value ); + } + // initial focus on the grid please. m_grid->SetFocus(); } ~DIALOG_FP_PLUGIN_OPTIONS() { + // destroy GRID_TRICKS before m_grid. m_grid->PopEventHandler( true ); } private: const wxString& m_callers_options; - wxString m_options; wxString* m_result; + wxString makeResult() + { + PROPERTIES props; + const int rowCount = m_grid->GetNumberRows(); + + for( int row = 0; rowGetCellValue( row, 0 ).Trim( false ).Trim() ); + string value = TO_UTF8( m_grid->GetCellValue( row, 1 ).Trim( false ).Trim() ); + + if( name.size() ) + { + props[name] = value; + } + } + + string options = FP_LIB_TABLE::FormatOptions( &props ); + + return FROM_UTF8( options.c_str() ); + } + + void saveColSizes() + { + col_width_option = m_grid->GetColSize( 0 ); + col_width_value = m_grid->GetColSize( 1 ); + } + + void abort() + { + saveColSizes(); + + *m_result = m_callers_options; // tell caller "no change" + EndModal( 0 ); + } + //----------------------------------------------------------- void onAddRow( wxCommandEvent& event ) { @@ -85,25 +149,22 @@ private: void onCancelButtonClick( wxCommandEvent& event ) { - *m_result = m_callers_options; // no change - EndModal( 0 ); + abort(); } void onCancelButtonClick( wxCloseEvent& event ) { - *m_result = m_callers_options; // no change - EndModal( 0 ); + abort(); } void onOKButtonClick( wxCommandEvent& event ) { - *m_result = m_options; // change from edits + saveColSizes(); + *m_result = makeResult(); // change from edits EndModal( 1 ); } - //---------------------------------------------------------- - }; diff --git a/pcbnew/io_mgr.h b/pcbnew/io_mgr.h index bbfe216f30..aeba281533 100644 --- a/pcbnew/io_mgr.h +++ b/pcbnew/io_mgr.h @@ -26,12 +26,23 @@ */ #include -#include +#include + class BOARD; class PLUGIN; class MODULE; +/** + * Class PROPERTIES + * is a name/value tuple with unique names and optional values. The names + * may be iterated alphabetically. + */ +class PROPERTIES : public std::map< std::string, std::string > +{ + // alphabetical tuple of name and value hereby defined. +}; + /** * Class IO_MGR