diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b446d867..72269494cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ option( KICAD_SCRIPTING_WXPYTHON option( USE_FP_LIB_TABLE "Use the new footprint library table implementation. ( default OFF)" ) -#option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." OFF ) +option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." OFF ) #Set version option (stable or testing) @@ -110,18 +110,18 @@ if( CMAKE_COMPILER_IS_GNUCXX ) "Setting GCC version ${GCC_VERSION} build flags \"${KICAD_GCC_RELEASE_BUILD_FLAGS}\"" ) endif() - if( MINGW ) - # According to some sources, under Windows -fPIC option is not needed: - # http://mingw.5.n7.nabble.com/Option-fPIC-not-supported-td18480.html + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) + if( MINGW ) # Set default flags for Release build. - set( CMAKE_C_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) - set( CMAKE_CXX_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) + set( CMAKE_C_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) + set( CMAKE_CXX_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s -static-libgcc -static-libstdc++" ) # Set default flags for Debug build. - set( CMAKE_C_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) - set( CMAKE_CXX_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) + set( CMAKE_C_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) + set( CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) set( CMAKE_MODULE_LINKER_FLAGS "-static-libgcc -static-libstdc++") # SWIG macros on Windows else() @@ -136,13 +136,13 @@ if( CMAKE_COMPILER_IS_GNUCXX ) set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" ) # needed by SWIG macros on linux # Set default flags for Release build. - set( CMAKE_C_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -Wall -DNDEBUG" ) - set( CMAKE_CXX_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -Wall -DNDEBUG" ) + set( CMAKE_C_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) + set( CMAKE_CXX_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) # Set default flags for Debug build. - set( CMAKE_C_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall -g3 -ggdb3 -DDEBUG" ) - set( CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall -g3 -ggdb3 -DDEBUG" ) + set( CMAKE_C_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) + set( CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" ) endif() # quiet GCC 4.8.1 while in boost diff --git a/CMakeModules/PerformFeatureChecks.cmake b/CMakeModules/PerformFeatureChecks.cmake index e1cc304ab6..2749d23ec9 100644 --- a/CMakeModules/PerformFeatureChecks.cmake +++ b/CMakeModules/PerformFeatureChecks.cmake @@ -63,11 +63,11 @@ macro(perform_feature_checks) # included in pyport.h which is where the problem ocurrs without this # fix. check_include_file("stdint.h" HAVE_STDINT_H) - + if( HAVE_STDINT_H ) add_definitions( -DHAVE_STDINT_H ) endif() - + # no place is this used, and "HAVE_STRINGS_H", if present in config.h then # conflicts with /usr/include/python2.6/Python.h. Please rename the macro if # re-introduce this. diff --git a/CMakeModules/download_avhttp.cmake b/CMakeModules/download_avhttp.cmake new file mode 100644 index 0000000000..35c6195c65 --- /dev/null +++ b/CMakeModules/download_avhttp.cmake @@ -0,0 +1,59 @@ +# This program source code file is part of KICAD, a free EDA CAD application. +# +# Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck +# Copyright (C) 2013 Kicad Developers, see AUTHORS.txt for contributors. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you may find one here: +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# or you may search the http://www.gnu.org website for the version 2 license, +# or you may write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + +# Download av_http and install into ${PREFIX}, typically in our KiCad source tree. +# Assumes include( ExternalProject ) was done inline previous to this file +# and that set( DOWNLOAD_DIR ... ) was set in a higher context. + +#------------------------------------------------------------------------------------------ + +# soon cmake will have https support, switch to a true download then: +#set( AVHTTP_RELEASE ??? ) +#set( AVHTTP_MD5 ???? ) # re-calc this on every RELEASE change + +#---------------------------------------------------------------------------------------- + + +# Where the library is to be installed. +set( PREFIX ${DOWNLOAD_DIR}/avhttp ) + + +# Install the AVHTTP header only library ${PREFIX} +ExternalProject_Add( avhttp + PREFIX ${PREFIX} + DOWNLOAD_DIR ${DOWNLOAD_DIR} # no true download yet + + # grab it from a local zip file for now, cmake caller's source dir + URL ${CMAKE_CURRENT_SOURCE_DIR}/avhttp-master.zip + DEPENDS boost + + CONFIGURE_COMMAND "" + + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory + ) + + +set( AVHTTP_INCLUDE_DIR "${PREFIX}/include" CACHE FILEPATH "AVHTTP include directory" ) + diff --git a/CMakeModules/download_boost.cmake b/CMakeModules/download_boost.cmake index 02d2add3e3..68c9cb7cfc 100644 --- a/CMakeModules/download_boost.cmake +++ b/CMakeModules/download_boost.cmake @@ -29,13 +29,8 @@ #--------------------------------------------------------------------- -if( false ) - set( BOOST_RELEASE 1.53.0 ) - set( BOOST_MD5 a00d22605d5dbcfb4c9936a9b35bc4c2 ) # re-calc this on every RELEASE change -else() - set( BOOST_RELEASE 1.54.0 ) - set( BOOST_MD5 15cb8c0803064faef0c4ddf5bc5ca279 ) # re-calc this on every RELEASE change -endif() +set( BOOST_RELEASE 1.54.0 ) +set( BOOST_MD5 15cb8c0803064faef0c4ddf5bc5ca279 ) # re-calc this on every RELEASE change # The boost headers [and static libs if built] go here, at the top of KiCad # source tree in boost_root. @@ -44,14 +39,19 @@ set( BOOST_ROOT "${PROJECT_SOURCE_DIR}/boost_root" ) if( BUILD_GITHUB_PLUGIN ) # Space separated list which indicates the subset of boost libraries to compile. + # Chosen libraries are based on pion-net _client_ (not server) requirements. Client + # requirements are less demanding. set( BOOST_LIBS_BUILT - #filesystem - system - #regex - #program_options - #date_time - #thread + date_time #exception + filesystem + iostreams + locale + program_options + regex + #signals + #system + thread unit_test_framework ) endif() @@ -73,7 +73,7 @@ set( PREFIX ${DOWNLOAD_DIR}/boost_${BOOST_VERS} ) set( headers_src "${PREFIX}/src/boost/boost" ) -# don't look at this: +# don't look at this, not used, not working, not needed at this time. function( set_boost_lib_names libs output ) foreach( lib ${libs} ) set( fullpath_lib, "${BOOST_ROOT}/lib/libboost_${lib}.a" ) @@ -85,13 +85,15 @@ endfunction() if( BUILD_GITHUB_PLUGIN ) + # It will probably be simpler to make this the only path in the future. + # (BTW "test" yields "unit_test_framework" when passed to bootstrap.{sh,bat} ). - message( STATUS "BOOST_LIBS_BUILT:${BOOST_LIBS_BUILT}" ) + #message( STATUS "BOOST_LIBS_BUILT:${BOOST_LIBS_BUILT}" ) string( REPLACE "unit_test_framework" "test" libs_csv "${BOOST_LIBS_BUILT}" ) - message( STATUS "REPLACE libs_csv:${libs_csv}" ) + #message( STATUS "REPLACE libs_csv:${libs_csv}" ) string( REGEX REPLACE "\\;" "," libs_csv "${libs_csv}" ) - message( STATUS "libs_csv:${libs_csv}" ) + #message( STATUS "libs_csv:${libs_csv}" ) if( MINGW ) set( bootstrap "bootstart.bat mingw" ) @@ -120,14 +122,14 @@ if( BUILD_GITHUB_PLUGIN ) variant=release threading=multi toolset=gcc - link=static + #link=static --prefix=${BOOST_ROOT} install INSTALL_COMMAND "" ) - file( GLOB boost_libs "${BOOST_ROOT}/lib/*" ) + file( GLOB boost_libs "${BOOST_ROOT}/lib/*${CMAKE_STATIC_LIBRARY_SUFFIX}" ) #message( STATUS BOOST_ROOT:${BOOST_ROOT} boost_libs:${boost_libs} ) set( Boost_LIBRARIES ${boost_libs} CACHE FILEPATH "Boost libraries directory" ) set( Boost_INCLUDE_DIR "${BOOST_ROOT}/include" CACHE FILEPATH "Boost include directory" ) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 9909a8d54c..bb7d281901 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -172,7 +172,7 @@ make_lexer( ${CMAKE_CURRENT_SOURCE_DIR}/pcb_plot_params_keywords.cpp PCBPLOTPARAMS_T - # Pass header file with dependency on *_lexer.h as extra_arg + # Pass header file with dependencies on *_lexer.h as extra_arg ${PROJECT_SOURCE_DIR}/pcbnew/pcb_plot_params.h ) @@ -204,11 +204,7 @@ make_lexer( TB_READER_T ) -# The dsntest may not build properly using MS Visual Studio. -if(NOT MSVC) - # This one gets made only when testing. - # to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp - add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp ) - target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt ) - -endif( NOT MSVC ) +# This one gets made only when testing. +# to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp +add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp ) +target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt ) diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 3e4d8e3f47..f3f0bf7822 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -104,6 +104,11 @@ target_link_libraries( cvpcb ${GDI_PLUS_LIBRARIES} ) +if( BUILD_GITHUB_PLUGIN ) + target_link_libraries( cvpcb github_plugin ) +endif() + + ### # Add cvpcb as install target ### diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 740b962b9a..2d757b7fec 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -465,7 +465,6 @@ if( BUILD_GITHUB_PLUGIN ) endif() - ### # Create the pcbnew executable ### @@ -501,6 +500,11 @@ target_link_libraries( pcbnew ${PCBNEW_EXTRA_LIBS} ) +if( BUILD_GITHUB_PLUGIN ) + target_link_libraries( pcbnew github_plugin ) +endif() + + ### # Add pcbnew as install target ### @@ -536,12 +540,10 @@ if( KICAD_SCRIPTING_MODULES ) endif() -# The specctra test fails to build properly using MS Visual Studio. -if( NOT MSVC ) - # This one gets made only when testing. - add_executable( specctra_test EXCLUDE_FROM_ALL specctra_test.cpp specctra.cpp ) - target_link_libraries( specctra_test common ${wxWidgets_LIBRARIES} ) -endif() +# This one gets made only when testing. +add_executable( specctra_test EXCLUDE_FROM_ALL specctra_test.cpp specctra.cpp ) +target_link_libraries( specctra_test common ${wxWidgets_LIBRARIES} ) + # This one gets made only when testing. add_executable( layer_widget_test WIN32 EXCLUDE_FROM_ALL diff --git a/pcbnew/github/CMakeLists.txt b/pcbnew/github/CMakeLists.txt index 5407515c91..191c27ca2e 100644 --- a/pcbnew/github/CMakeLists.txt +++ b/pcbnew/github/CMakeLists.txt @@ -22,12 +22,51 @@ +# Download avhttp and install the headers, not actually compiled +################################################# +include( download_avhttp ) -include_directories( . ) +if( MINGW ) + # @todo: take this from python-a-mingw-us' PythonExternalPackages.cmake which does + # openssl compilation on MINGW. About 20 minutes work. + include( download_openssl ) +else() + find_package( OpenSSL REQUIRED ) + #message( STATUS "OPENSSL_FOUND:${OPENSSL_FOUND} OPENSSL_LIBRARIES:${OPENSSL_LIBRARIES}" ) + + # FindOpenSSL.cmake does not set this var into cache, so is not globally visible, + # do it here incase some other link image needs these libraries + set( OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES}" CACHE FILEPATH "OpenSSL link libraries" ) +endif() + + +# These are additions to any inherited from pcbnew dir: +include_directories( . ${OPENSSL_INCLUDE_DIR} ${AVHTTP_INCLUDE_DIR} ) + +# Tell AVHTTP we have SSL. +add_definitions( -DAVHTTP_ENABLE_OPENSSL ) + +# tone down the compiler warnings for avhttp header library: +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare -Wno-reorder -Wno-unused-variable -Wno-unused-function" ) set( GITHUB_PLUGIN_SRCS github_plugin.cpp - PARENT_SCOPE # tell links based in 'directory pcbnew' about it, i.e. "../" ) +add_library( github_plugin + github_plugin.cpp + ) + +# No, you don't get github without boost and openssl +target_link_libraries( github_plugin + ${Boost_LIBRARIES} + ${OPENSSL_LIBRARIES} + ) + +add_dependencies( github_plugin boost ) +add_dependencies( github_plugin avhttp ) + + +#target_link_libraries( github_plugin ${wxWidgets_LIBRARIES} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES}) + diff --git a/pcbnew/github/avhttp-master.zip b/pcbnew/github/avhttp-master.zip new file mode 100644 index 0000000000..4e68fee6a7 Binary files /dev/null and b/pcbnew/github/avhttp-master.zip differ diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp new file mode 100644 index 0000000000..665948d37d --- /dev/null +++ b/pcbnew/github/github_plugin.cpp @@ -0,0 +1,293 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2013 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +/* + This is a pcbnew PLUGIN which supports some of the PLUGIN::Footprint*() functions + in the PLUGIN interface, and could do so by utilizing the version 3 github.com + API documented here: + + http://developer.github.com + https://help.github.com/articles/creating-an-access-token-for-command-line-use + + but it does not. Rather it simply reads in a zip file of the repo and unzips it + from RAM as needed. Therefore the PLUGIN is read only for accessing + remote pretty libraries. If you want to support writing to the repo, then you + could use the above API. +*/ + + +#include +#include +#include +#include + +//#include +//#include +//#include +//#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +using namespace std; + + +typedef boost::ptr_map MODULE_MAP; +typedef MODULE_MAP::iterator MODULE_ITER; +typedef MODULE_MAP::const_iterator MODULE_CITER; + + +/** + * Class FPL_CACHE + * assists only within GITHUB_PLUGIN and hold a map of footprint name to wxZipEntry + */ +struct FPL_CACHE : public MODULE_MAP +{ + // MODULE_MAP is a boost::ptr_map template, made into a class hereby. +}; + + +GITHUB_PLUGIN::GITHUB_PLUGIN() : + m_cache( 0 ) +{ +} + + +GITHUB_PLUGIN::~GITHUB_PLUGIN() +{ + delete m_cache; +} + + +const wxString& GITHUB_PLUGIN::PluginName() const +{ + static wxString name( wxT( "Github" ) ); + return name; +} + + +const wxString& GITHUB_PLUGIN::GetFileExtension() const +{ + static wxString empty_ext; + return empty_ext; +} + + +wxArrayString GITHUB_PLUGIN::FootprintEnumerate( + const wxString& aLibraryPath, PROPERTIES* aProperties ) +{ + cacheLib( aLibraryPath ); + + wxArrayString ret; + + for( MODULE_ITER it = m_cache->begin(); it!=m_cache->end(); ++it ) + { + ret.Add( FROM_UTF8( it->first.c_str() ) ); + } + + return ret; +} + + +MODULE* GITHUB_PLUGIN::FootprintLoad( const wxString& aLibraryPath, + const wxString& aFootprintName, PROPERTIES* aProperties ) +{ + cacheLib( aLibraryPath ); + + string fp_name = TO_UTF8( aFootprintName ); + + MODULE_CITER it = m_cache->find( fp_name ); + + if( it != m_cache->end() ) // fp_name is present + { + wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() ); + + // This decoder should always be UTF8, since it was saved that way by git. + // That is, since pretty footprints are UTF8, and they were pushed to the + // github repo, they are still UTF8. + wxZipInputStream zis( mis, wxConvUTF8 ); + wxZipEntry* entry = (wxZipEntry*) it->second; // remove "const"-ness + + if( zis.OpenEntry( *entry ) ) + { + INPUTSTREAM_LINE_READER reader( &zis ); + PCB_PARSER parser( &reader ); + + MODULE* ret = (MODULE*) parser.Parse(); + + return ret; + } + } + + return NULL; // this API function returns NULL for "not found", per spec. +} + + +bool GITHUB_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath ) +{ + return false; +} + + +void GITHUB_PLUGIN::cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR ) +{ + if( !m_cache || m_lib_path != aLibraryPath ) + { + delete m_cache; + m_cache = new FPL_CACHE(); + remote_get_zip( aLibraryPath ); + m_lib_path = aLibraryPath; + + wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() ); + + // @todo: generalize this name encoding from a PROPERTY (option) later + wxZipInputStream zis( mis, wxConvUTF8 ); + + wxZipEntry* entry; + + while( (entry = zis.GetNextEntry()) != NULL ) + { + wxFileName fn( entry->GetName() ); + + if( fn.GetExt() == wxT( "kicad_mod" ) ) + { + string fp_name = TO_UTF8( fn.GetName() ); + + m_cache->insert( fp_name, entry ); + } + else + delete entry; + } + } +} + + +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 ) );) + + wxURI repo( aRepoURL ); + + if( repo.HasServer() && repo.HasPath() ) + { + // goal: "https://github.com/liftoff-sr/pretty_footprints/archive/master.zip" + wxString zip_url( wxT("https://") ); + + zip_url += repo.GetServer(); + zip_url += repo.GetPath(); + zip_url += wxT('/'); + zip_url += wxT( "archive/master.zip" ); + + *aZipURL = zip_url.utf8_str(); + return true; + } + return false; +} + + +void GITHUB_PLUGIN::remote_get_zip( const wxString& aRepoURL ) throw( IO_ERROR ) +{ + string zip_url; + + if( !repoURL_zipURL( aRepoURL, &zip_url ) ) + { + wxString msg = wxString::Format( _("Unable to parse URL: %s"), GetChars( m_lib_path ) ); + THROW_IO_ERROR( msg ); + } + + boost::asio::io_service io; + avhttp::http_stream h( io ); + avhttp::request_opts options; + + options.insert( "Accept", "application/zip" ); + options.insert( "User-Agent", "http://kicad-pcb.org" ); // THAT WOULD BE ME. + h.request_options( options ); + + try + { + h.open( zip_url ); // only one file, therefore do it synchronously. + ostringstream os; + os << &h; + + // Keep zip file byte image in RAM. That plus the MODULE_MAP will constitute + // the cache. We don't cache the MODULEs per se, we parse those as needed from + // this zip file image. + m_zip_image = os.str(); + + // 4 lines, using SSL, top that. + } + catch( std::exception& e ) + { + THROW_IO_ERROR( e.what() ); + } +} + + +#if 0 && defined(STANDALONE) + +int main( int argc, char** argv ) +{ + INIT_LOGGER( ".", "test.log" ); + + GITHUB_PLUGIN gh; + + try + { + wxArrayString fps = gh.FootprintEnumerate( + wxT( "https://github.com/liftoff-sr/pretty_footprints" ), + NULL + ); + + for( int i=0; i<(int)fps.Count(); ++i ) + { + printf("[%d]:%s\n", i, TO_UTF8( fps[i] ) ); + } + } + catch( IO_ERROR ioe ) + { + printf( "%s\n", TO_UTF8(ioe.errorText) ); + } + + UNINIT_LOGGER(); + + return 0; +} + +#endif + diff --git a/pcbnew/github/github_plugin.h b/pcbnew/github/github_plugin.h new file mode 100644 index 0000000000..7812baced6 --- /dev/null +++ b/pcbnew/github/github_plugin.h @@ -0,0 +1,88 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2013 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef GITHUB_PLUGIN_H_ +#define GITHUB_PLUGIN_H_ + + +struct FPL_CACHE; + + +/** + * Class GITHUB_PLUGIN + * implements a portion of pcbnew PLUGIN to provide read only access to a github + * repo consisting of pretty footprints + * + * @author Dick Hollenbeck + * @date Original date: 10-Sep-2013 + */ +class GITHUB_PLUGIN : public PLUGIN +{ +public: + //--------------------------------------------------------------- + // ("read-only" subset) + + const wxString& PluginName() const; + + const wxString& GetFileExtension() const; + + wxArrayString FootprintEnumerate( const wxString& aLibraryPath, PROPERTIES* aProperties ); + + MODULE* FootprintLoad( const wxString& aLibraryPath, + const wxString& aFootprintName, PROPERTIES* aProperties ); + + bool IsFootprintLibWritable( const wxString& aLibraryPath ); + + //-------------------------------------------------------------- + + GITHUB_PLUGIN(); // constructor, if any, must be zero arg + ~GITHUB_PLUGIN(); + +private: + + void cacheLib( const wxString& aLibraryPath ) throw( IO_ERROR ); + + /** + * Function repoURL_zipURL + * translates a repo URL to a zipfile URL name as commonly seen on github.com + * + * @param aRepoURL points to the base of the repo. + * @param aZipURL is where to put the zip file URL. + * @return bool - true if @a aRepoULR was parseable, else false + */ + static bool repoURL_zipURL( const wxString& aRepoURL, std::string* aZipURL ); + + /** + * Function remote_get_zip + * fetches a zip file image from a github repo synchronously. The byte image + * is received into the m_input_stream. + */ + void remote_get_zip( const wxString& aRepoURL ) throw( IO_ERROR ); + + 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. + FPL_CACHE* m_cache; +}; + +#endif // GITHUB_PLUGIN_H_ diff --git a/pcbnew/io_mgr.cpp b/pcbnew/io_mgr.cpp index 6872640622..2877a8d899 100644 --- a/pcbnew/io_mgr.cpp +++ b/pcbnew/io_mgr.cpp @@ -30,6 +30,11 @@ #include #include #include + +#if defined(BUILD_GITHUB_PLUGIN) + #include +#endif + #include #define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." ) @@ -72,6 +77,12 @@ PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType ) case GEDA_PCB: return new GPCB_PLUGIN(); + + case GITHUB: +#if defined(BUILD_GITHUB_PLUGIN) + return new GITHUB_PLUGIN(); +#endif + ; // GITHUB fall thru to NULL below } return NULL; @@ -113,6 +124,12 @@ const wxString IO_MGR::ShowType( PCB_FILE_T aType ) case GEDA_PCB: return wxString( wxT( "Geda-PCB" ) ); + +#if defined(BUILD_GITHUB_PLUGIN) + case GITHUB: + return wxString( wxT( "Github" ) ); +#endif + } } @@ -138,6 +155,11 @@ IO_MGR::PCB_FILE_T IO_MGR::EnumFromStr( const wxString& aType ) if( aType == wxT( "Geda-PCB" ) ) return GEDA_PCB; +#if defined(BUILD_GITHUB_PLUGIN) + if( aType == wxT( "Github" ) ) + return GITHUB; +#endif + // wxASSERT( blow up here ) return PCB_FILE_T( -1 ); @@ -176,6 +198,11 @@ IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath { ret = EAGLE; } + +#if defined(BUILD_GITHUB_PLUGIN) + // There is no extension for a remote repo. We're thinking about this. +#endif + else { // Although KICAD PLUGIN uses libpaths with fixed extension of diff --git a/pcbnew/io_mgr.h b/pcbnew/io_mgr.h index 1a5bd082c2..a83f7e8914 100644 --- a/pcbnew/io_mgr.h +++ b/pcbnew/io_mgr.h @@ -48,11 +48,12 @@ public: */ enum PCB_FILE_T { - LEGACY, //< Legacy Pcbnew file formats prior to s-expression. - KICAD, //< S-expression Pcbnew file format. + LEGACY, ///< Legacy Pcbnew file formats prior to s-expression. + KICAD, ///< S-expression Pcbnew file format. EAGLE, PCAD, - GEDA_PCB, //< Geda PCB file formats. + GEDA_PCB, ///< Geda PCB file formats. + GITHUB, ///< Read only http://github.com repo holding pretty footprints // add your type here. @@ -397,7 +398,7 @@ public: API functions which take one. */ - virtual ~PLUGIN() {} + virtual ~PLUGIN() {}; /** * Class RELEASER diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index 3e4fbae982..8de731b4e8 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -55,6 +55,19 @@ class PCB_PARSER; /// a BOARD file underneath IO_MGR. #define CTL_FOR_BOARD (CTL_OMIT_INITIAL_COMMENTS) + +class DIMENSION; +class EDGE_MODULE; +class DRAWSEGMENT; +class PCB_TARGET; +class D_PAD; +class TEXTE_MODULE; +class TRACK; +class ZONE_CONTAINER; +class TEXTE_PCB; + + + /** * Class PCB_IO * is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files. diff --git a/pcbnew/pcb_parser.h b/pcbnew/pcb_parser.h index e679a356f3..233acb1291 100644 --- a/pcbnew/pcb_parser.h +++ b/pcbnew/pcb_parser.h @@ -31,6 +31,8 @@ #include #include +#include // LAYER_NUM +#include // KiROUND using namespace PCB_KEYS_T; @@ -40,15 +42,16 @@ class BOARD_ITEM; class D_PAD; class DIMENSION; class DRAWSEGMENT; +class EDA_TEXT; class EDGE_MODULE; class TEXTE_MODULE; class TEXTE_PCB; +class TRACK; class MODULE; class PCB_TARGET; +class SEGVIA; class S3D_MASTER; class ZONE_CONTAINER; -class FPL_CACHE; - /** diff --git a/pcbnew/plugin.cpp b/pcbnew/plugin.cpp new file mode 100644 index 0000000000..7153247b39 --- /dev/null +++ b/pcbnew/plugin.cpp @@ -0,0 +1,72 @@ + +#include +//#include + + +#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." ) +#define FMT_NOTFOUND _( "Plugin type '%s' is not found." ) + + +BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, 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__ ) ); +} + + +void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, 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__ ) ); +} + + +wxArrayString PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, 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__ ) ); +} + + +MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, + 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__ ) ); +} + + +void PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, 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__ ) ); +} + + +void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName ) +{ + // 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__ ) ); +} + + +void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, 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__ ) ); +} + + +bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, 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__ ) ); +} + + +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__ ) ); +} +