From be4d7a624984180dd6fe8378987b5f1174d729b5 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 30 Sep 2013 16:26:49 -0500 Subject: [PATCH] Make environment variable wxGrid/table read-only in the fp lib table dialog. Fix throwing of IO_ERROR in plugin.cpp by converting function name to wxString.GetData(). Switch to const PROPERTIES* in GITHUB PLUGIN functions. --- pcbnew/dialogs/dialog_fp_lib_table_base.cpp | 2 +- pcbnew/dialogs/dialog_fp_lib_table_base.fbp | 2 +- pcbnew/github/github_plugin.cpp | 17 +++++++-- pcbnew/github/github_plugin.h | 6 +-- pcbnew/plugin.cpp | 41 +++++++++++++++------ 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/pcbnew/dialogs/dialog_fp_lib_table_base.cpp b/pcbnew/dialogs/dialog_fp_lib_table_base.cpp index 01bc85152f..bb78ba1333 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table_base.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table_base.cpp @@ -150,7 +150,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID // Grid m_path_subs_grid->CreateGrid( 1, 2 ); - m_path_subs_grid->EnableEditing( true ); + m_path_subs_grid->EnableEditing( false ); m_path_subs_grid->EnableGridLines( true ); m_path_subs_grid->EnableDragGridSize( false ); m_path_subs_grid->SetMargins( 0, 0 ); diff --git a/pcbnew/dialogs/dialog_fp_lib_table_base.fbp b/pcbnew/dialogs/dialog_fp_lib_table_base.fbp index aea158009e..1885fe1772 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table_base.fbp +++ b/pcbnew/dialogs/dialog_fp_lib_table_base.fbp @@ -1399,7 +1399,7 @@ 1 0 1 - 1 + 0 1 1 diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp index 8da1683d15..66fc3acdd7 100644 --- a/pcbnew/github/github_plugin.cpp +++ b/pcbnew/github/github_plugin.cpp @@ -98,8 +98,10 @@ const wxString& GITHUB_PLUGIN::GetFileExtension() const wxArrayString GITHUB_PLUGIN::FootprintEnumerate( - const wxString& aLibraryPath, PROPERTIES* aProperties ) + const wxString& aLibraryPath, const PROPERTIES* aProperties ) { + D(printf("%s: this:%p aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );) + cacheLib( aLibraryPath ); wxArrayString ret; @@ -114,8 +116,10 @@ wxArrayString GITHUB_PLUGIN::FootprintEnumerate( MODULE* GITHUB_PLUGIN::FootprintLoad( const wxString& aLibraryPath, - const wxString& aFootprintName, PROPERTIES* aProperties ) + const wxString& aFootprintName, const PROPERTIES* aProperties ) { + D(printf("%s: this:%p aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );) + cacheLib( aLibraryPath ); string fp_name = TO_UTF8( aFootprintName ); @@ -162,11 +166,18 @@ void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR ) { if( !m_cache || m_lib_path != aLibraryPath ) { + D(printf("%s: this:%p m_lib_path:'%s' aLibraryPath:'%s'\n", + __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );) + delete m_cache; m_cache = new GH_CACHE(); remote_get_zip( aLibraryPath ); + m_lib_path = aLibraryPath; + D(printf("%s2: this:%p m_lib_path:'%s' aLibraryPath:'%s'\n", + __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );) + wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() ); // @todo: generalize this name encoding from a PROPERTY (option) later @@ -194,7 +205,7 @@ void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR ) bool GITHUB_PLUGIN::repoURL_zipURL( const wxString& aRepoURL, string* aZipURL ) { // e.g. "https://github.com/liftoff-sr/pretty_footprints" - D(printf("aRepoURL:%s\n", TO_UTF8( aRepoURL ) );) + //D(printf("aRepoURL:%s\n", TO_UTF8( aRepoURL ) );) wxURI repo( aRepoURL ); diff --git a/pcbnew/github/github_plugin.h b/pcbnew/github/github_plugin.h index c5955ecfac..8e0a01e122 100644 --- a/pcbnew/github/github_plugin.h +++ b/pcbnew/github/github_plugin.h @@ -47,10 +47,10 @@ public: const wxString& GetFileExtension() const; - wxArrayString FootprintEnumerate( const wxString& aLibraryPath, PROPERTIES* aProperties ); + wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties ); MODULE* FootprintLoad( const wxString& aLibraryPath, - const wxString& aFootprintName, PROPERTIES* aProperties ); + const wxString& aFootprintName, const PROPERTIES* aProperties ); bool IsFootprintLibWritable( const wxString& aLibraryPath ); @@ -82,7 +82,7 @@ private: wxString m_lib_path; ///< from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints std::string m_zip_image; ///< byte image of the zip file in its entirety. - GH_CACHE* m_cache; + GH_CACHE* m_cache; }; #endif // GITHUB_PLUGIN_H_ diff --git a/pcbnew/plugin.cpp b/pcbnew/plugin.cpp index 77d6e7f3ec..9fbce0e98b 100644 --- a/pcbnew/plugin.cpp +++ b/pcbnew/plugin.cpp @@ -25,27 +25,42 @@ #include #define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." ) -#define FMT_NOTFOUND _( "Plugin type '%s' is not found." ) + +/** + * Function not_implemented + * throws an IO_ERROR and complains of an API function not being implemented. + * + * @param aPlugin is a PLUGIN instance + * @param aCaller is the name of the unimplemented API function. + */ +static void not_implemented( PLUGIN* aPlugin, const char* aCaller ) +{ + THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, + aPlugin->PluginName().GetData(), + wxString::FromUTF8( aCaller ).GetData() ) + ); +} BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties ) { - // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData(), __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); + return NULL; } void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData(), __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); } wxArrayString PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); + return wxArrayString(); } @@ -53,41 +68,43 @@ MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFo const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); + return NULL; } void PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); } void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); } void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); } bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); + return false; } bool PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. - THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, PluginName().GetData() , __FUNCTION__ ) ); + not_implemented( this, __FUNCTION__ ); + return false; } -