From dc138512b99511c59251d07992a178a3a887b121 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 11 Nov 2013 19:14:17 -0600 Subject: [PATCH] wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser() now returns empty string on abort. GITHUB_PLUGIN uses redirected URL to remove one HTTP hit time. --- include/wxBasePcbFrame.h | 9 +++++---- pcbnew/github/github_plugin.cpp | 29 ++++++++++++++++++++++------- pcbnew/loadcmp.cpp | 24 ++++++++++++++---------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 9f4cc53893..f28fe191a2 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -503,11 +503,12 @@ public: wxDC* aDC = NULL ); /** - * SelectFootprintFromLibBrowser - * Launch the footprint viewer to select the name of a footprint to load. - * @return the selected footprint name + * Function SelectFootprintFromLibBrowser + * launches the footprint viewer to select the name of a footprint to load. + * + * @return the selected footprint name or an empty string if no selection was made. */ - wxString SelectFootprintFromLibBrowser( void ); + wxString SelectFootprintFromLibBrowser(); /** * Function GetFootprintLibraryTable diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp index 0eb0f62c29..353d6ff6d9 100644 --- a/pcbnew/github/github_plugin.cpp +++ b/pcbnew/github/github_plugin.cpp @@ -36,15 +36,17 @@ remote pretty libraries. If you want to support writing to the repo, then you could use the above API. -@todo: Derive this PLUGIN from KICAD_PLUGIN so we can use its FootprintSave(). - +@todo: + Derive this PLUGIN from KICAD_PLUGIN so we can use its FootprintSave(). + Support local footprints if they are present in an optional directory. + Possibly cache the zip file locally. Use HTTP's "have changed" or whatever it is called. */ #ifdef WIN32 - // defines needed by avhttp - // Minimal Windows version is XP: Google for _WIN32_WINNT - #define _WIN32_WINNT 0x0501 - #define WINVER 0x0501 + // defines needed by avhttp + // Minimal Windows version is XP: Google for _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #define WINVER 0x0501 #endif #include @@ -53,7 +55,6 @@ #include #include #include -//#include #include // Under Windows Mingw/msys, avhttp.hpp should be included after fctsys.h @@ -247,10 +248,24 @@ bool GITHUB_PLUGIN::repoURL_zipURL( const wxString& aRepoURL, string* aZipURL ) // goal: "https://github.com/liftoff-sr/pretty_footprints/archive/master.zip" wxString zip_url( wxT( "https://" ) ); +#if 0 // Github issues a redirect for this "master.zip". i.e. + // "https://github.com/liftoff-sr/pretty_footprints/archive/master.zip" + // would be redirected to: + // "https://codeload.github.com/liftoff-sr/pretty_footprints/zip/master" + + // The alternate code path below uses the redirected URL on first attempt + // to save one HTTP GET hit. avhttp does the redirect behind the scenes normally. + zip_url += repo.GetServer(); zip_url += repo.GetPath(); zip_url += wxT( '/' ); zip_url += wxT( "archive/master.zip" ); +#else + zip_url += wxT( "codeload.github.com" ); + zip_url += repo.GetPath(); + zip_url += wxT( '/' ); + zip_url += wxT( "zip/master" ); +#endif *aZipURL = zip_url.utf8_str(); return true; diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 9a25c6bad2..cd5a1982b8 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -110,13 +110,12 @@ bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) return true; } -/* - * Launch the footprint viewer to select the name of a footprint to load. - * return the selected footprint name - */ -wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void ) + +wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser() { wxString fpname; + wxString fpid; + wxSemaphore semaphore( 0, 1 ); // Close the current Lib browser, if opened, and open a new one, in "modal" mode: @@ -135,17 +134,22 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void ) wxMilliSleep( 50 ); } + fpname = viewer->GetSelectedFootprint(); + + if( !!fpname ) + { #if !defined( USE_FP_LIB_TABLE ) - // Returns the full fp name, i.e. the lib name and th fp name, - // separated by a '/' (/ is now an illegal char in fp names) - fpname = viewer->GetSelectedLibraryFullName() + wxT( "/" ) + viewer->GetSelectedFootprint(); + // Returns the full fp name, i.e. the lib name and the fp name, + // separated by a '/' (/ is now an illegal char in fp names) + fpid = viewer->GetSelectedLibraryFullName() + wxT( "/" ) + fpname; #else - fpname = viewer->GetSelectedLibrary() + wxT( ":" ) + viewer->GetSelectedFootprint(); + fpid = viewer->GetSelectedLibrary() + wxT( ":" ) + fpname; #endif + } viewer->Destroy(); - return fpname; + return fpid; }