Commit 4a2f8693 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Early GITHUB_PLUGIN hopefull-ness

parent a602c1b2
...@@ -53,7 +53,7 @@ option( KICAD_SCRIPTING_WXPYTHON ...@@ -53,7 +53,7 @@ option( KICAD_SCRIPTING_WXPYTHON
option( USE_FP_LIB_TABLE "Use the new footprint library table implementation. ( default OFF)" ) 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) #Set version option (stable or testing)
...@@ -110,18 +110,18 @@ if( CMAKE_COMPILER_IS_GNUCXX ) ...@@ -110,18 +110,18 @@ if( CMAKE_COMPILER_IS_GNUCXX )
"Setting GCC version ${GCC_VERSION} build flags \"${KICAD_GCC_RELEASE_BUILD_FLAGS}\"" ) "Setting GCC version ${GCC_VERSION} build flags \"${KICAD_GCC_RELEASE_BUILD_FLAGS}\"" )
endif() endif()
if( MINGW ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
# According to some sources, under Windows -fPIC option is not needed: set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
# http://mingw.5.n7.nabble.com/Option-fPIC-not-supported-td18480.html
if( MINGW )
# Set default flags for Release build. # Set default flags for Release build.
set( CMAKE_C_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 "-Wall ${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( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s -static-libgcc -static-libstdc++" )
# Set default flags for Debug build. # Set default flags for Debug build.
set( CMAKE_C_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 "-Wall ${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 set( CMAKE_MODULE_LINKER_FLAGS "-static-libgcc -static-libstdc++") # SWIG macros on Windows
else() else()
...@@ -136,13 +136,13 @@ if( CMAKE_COMPILER_IS_GNUCXX ) ...@@ -136,13 +136,13 @@ if( CMAKE_COMPILER_IS_GNUCXX )
set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" ) # needed by SWIG macros on linux set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" ) # needed by SWIG macros on linux
# Set default flags for Release build. # Set default flags for Release build.
set( CMAKE_C_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} -Wall -DNDEBUG" ) set( CMAKE_CXX_FLAGS_RELEASE "${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG" )
set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" )
# Set default flags for Debug build. # Set default flags for Debug build.
set( CMAKE_C_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} -Wall -g3 -ggdb3 -DDEBUG" ) set( CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG" )
endif() endif()
# quiet GCC 4.8.1 while in boost # quiet GCC 4.8.1 while in boost
......
...@@ -63,11 +63,11 @@ macro(perform_feature_checks) ...@@ -63,11 +63,11 @@ macro(perform_feature_checks)
# included in pyport.h which is where the problem ocurrs without this # included in pyport.h which is where the problem ocurrs without this
# fix. # fix.
check_include_file("stdint.h" HAVE_STDINT_H) check_include_file("stdint.h" HAVE_STDINT_H)
if( HAVE_STDINT_H ) if( HAVE_STDINT_H )
add_definitions( -DHAVE_STDINT_H ) add_definitions( -DHAVE_STDINT_H )
endif() endif()
# no place is this used, and "HAVE_STRINGS_H", if present in config.h then # 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 # conflicts with /usr/include/python2.6/Python.h. Please rename the macro if
# re-introduce this. # re-introduce this.
......
# This program source code file is part of KICAD, a free EDA CAD application.
#
# Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
# 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.
#-----<configure>-------------------------------------------------------------------------------------
# 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
#-----</configure>-----------------------------------------------------------------------------------
# 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 <SOURCE_DIR> <INSTALL_DIR>
)
set( AVHTTP_INCLUDE_DIR "${PREFIX}/include" CACHE FILEPATH "AVHTTP include directory" )
...@@ -29,13 +29,8 @@ ...@@ -29,13 +29,8 @@
#-----<configure>---------------------------------------------------------------- #-----<configure>----------------------------------------------------------------
if( false ) set( BOOST_RELEASE 1.54.0 )
set( BOOST_RELEASE 1.53.0 ) set( BOOST_MD5 15cb8c0803064faef0c4ddf5bc5ca279 ) # re-calc this on every RELEASE change
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()
# The boost headers [and static libs if built] go here, at the top of KiCad # The boost headers [and static libs if built] go here, at the top of KiCad
# source tree in boost_root. # source tree in boost_root.
...@@ -44,14 +39,19 @@ set( BOOST_ROOT "${PROJECT_SOURCE_DIR}/boost_root" ) ...@@ -44,14 +39,19 @@ set( BOOST_ROOT "${PROJECT_SOURCE_DIR}/boost_root" )
if( BUILD_GITHUB_PLUGIN ) if( BUILD_GITHUB_PLUGIN )
# Space separated list which indicates the subset of boost libraries to compile. # 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 set( BOOST_LIBS_BUILT
#filesystem date_time
system
#regex
#program_options
#date_time
#thread
#exception #exception
filesystem
iostreams
locale
program_options
regex
#signals
#system
thread
unit_test_framework unit_test_framework
) )
endif() endif()
...@@ -73,7 +73,7 @@ set( PREFIX ${DOWNLOAD_DIR}/boost_${BOOST_VERS} ) ...@@ -73,7 +73,7 @@ set( PREFIX ${DOWNLOAD_DIR}/boost_${BOOST_VERS} )
set( headers_src "${PREFIX}/src/boost/boost" ) 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 ) function( set_boost_lib_names libs output )
foreach( lib ${libs} ) foreach( lib ${libs} )
set( fullpath_lib, "${BOOST_ROOT}/lib/libboost_${lib}.a" ) set( fullpath_lib, "${BOOST_ROOT}/lib/libboost_${lib}.a" )
...@@ -85,13 +85,15 @@ endfunction() ...@@ -85,13 +85,15 @@ endfunction()
if( BUILD_GITHUB_PLUGIN ) 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} ). # (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}" ) 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}" ) string( REGEX REPLACE "\\;" "," libs_csv "${libs_csv}" )
message( STATUS "libs_csv:${libs_csv}" ) #message( STATUS "libs_csv:${libs_csv}" )
if( MINGW ) if( MINGW )
set( bootstrap "bootstart.bat mingw" ) set( bootstrap "bootstart.bat mingw" )
...@@ -120,14 +122,14 @@ if( BUILD_GITHUB_PLUGIN ) ...@@ -120,14 +122,14 @@ if( BUILD_GITHUB_PLUGIN )
variant=release variant=release
threading=multi threading=multi
toolset=gcc toolset=gcc
link=static #link=static
--prefix=${BOOST_ROOT} --prefix=${BOOST_ROOT}
install install
INSTALL_COMMAND "" 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} ) #message( STATUS BOOST_ROOT:${BOOST_ROOT} boost_libs:${boost_libs} )
set( Boost_LIBRARIES ${boost_libs} CACHE FILEPATH "Boost libraries directory" ) set( Boost_LIBRARIES ${boost_libs} CACHE FILEPATH "Boost libraries directory" )
set( Boost_INCLUDE_DIR "${BOOST_ROOT}/include" CACHE FILEPATH "Boost include directory" ) set( Boost_INCLUDE_DIR "${BOOST_ROOT}/include" CACHE FILEPATH "Boost include directory" )
......
...@@ -172,7 +172,7 @@ make_lexer( ...@@ -172,7 +172,7 @@ make_lexer(
${CMAKE_CURRENT_SOURCE_DIR}/pcb_plot_params_keywords.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pcb_plot_params_keywords.cpp
PCBPLOTPARAMS_T 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 ${PROJECT_SOURCE_DIR}/pcbnew/pcb_plot_params.h
) )
...@@ -204,11 +204,7 @@ make_lexer( ...@@ -204,11 +204,7 @@ make_lexer(
TB_READER_T TB_READER_T
) )
# The dsntest may not build properly using MS Visual Studio. # This one gets made only when testing.
if(NOT MSVC) # to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp
# This one gets made only when testing. add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp )
# to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt )
add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp )
target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt )
endif( NOT MSVC )
...@@ -104,6 +104,11 @@ target_link_libraries( cvpcb ...@@ -104,6 +104,11 @@ target_link_libraries( cvpcb
${GDI_PLUS_LIBRARIES} ${GDI_PLUS_LIBRARIES}
) )
if( BUILD_GITHUB_PLUGIN )
target_link_libraries( cvpcb github_plugin )
endif()
### ###
# Add cvpcb as install target # Add cvpcb as install target
### ###
......
...@@ -465,7 +465,6 @@ if( BUILD_GITHUB_PLUGIN ) ...@@ -465,7 +465,6 @@ if( BUILD_GITHUB_PLUGIN )
endif() endif()
### ###
# Create the pcbnew executable # Create the pcbnew executable
### ###
...@@ -501,6 +500,11 @@ target_link_libraries( pcbnew ...@@ -501,6 +500,11 @@ target_link_libraries( pcbnew
${PCBNEW_EXTRA_LIBS} ${PCBNEW_EXTRA_LIBS}
) )
if( BUILD_GITHUB_PLUGIN )
target_link_libraries( pcbnew github_plugin )
endif()
### ###
# Add pcbnew as install target # Add pcbnew as install target
### ###
...@@ -536,12 +540,10 @@ if( KICAD_SCRIPTING_MODULES ) ...@@ -536,12 +540,10 @@ if( KICAD_SCRIPTING_MODULES )
endif() endif()
# The specctra test fails to build properly using MS Visual Studio. # This one gets made only when testing.
if( NOT MSVC ) add_executable( specctra_test EXCLUDE_FROM_ALL specctra_test.cpp specctra.cpp )
# This one gets made only when testing. target_link_libraries( specctra_test common ${wxWidgets_LIBRARIES} )
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. # This one gets made only when testing.
add_executable( layer_widget_test WIN32 EXCLUDE_FROM_ALL add_executable( layer_widget_test WIN32 EXCLUDE_FROM_ALL
......
...@@ -22,12 +22,51 @@ ...@@ -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 set( GITHUB_PLUGIN_SRCS
github_plugin.cpp 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})
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 <string>
#include <vector>
#include <iostream>
#include <sstream>
//#include <boost/filesystem.hpp>
//#include <boost/array.hpp>
//#include <boost/shared_ptr.hpp>
//#include <boost/enable_shared_from_this.hpp>
#include <boost/ptr_container/ptr_map.hpp>
#include <avhttp.hpp>
#include <wx/zipstrm.h>
#include <wx/mstream.h>
#include <wx/uri.h>
#include <macros.h>
#include <fctsys.h>
#include <io_mgr.h>
#include <richio.h>
#include <pcb_parser.h>
#include <class_board.h>
#include <github_plugin.h>
using namespace std;
typedef boost::ptr_map<std::string, wxZipEntry> 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
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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:
//-----<PLUGIN API>----------------------------------------------------------
// ("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 );
//-----</PLUGIN API>---------------------------------------------------------
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_
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
#include <eagle_plugin.h> #include <eagle_plugin.h>
#include <pcad2kicadpcb_plugin/pcad_plugin.h> #include <pcad2kicadpcb_plugin/pcad_plugin.h>
#include <gpcb_plugin.h> #include <gpcb_plugin.h>
#if defined(BUILD_GITHUB_PLUGIN)
#include <github/github_plugin.h>
#endif
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." ) #define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )
...@@ -72,6 +77,12 @@ PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType ) ...@@ -72,6 +77,12 @@ PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType )
case GEDA_PCB: case GEDA_PCB:
return new GPCB_PLUGIN(); return new GPCB_PLUGIN();
case GITHUB:
#if defined(BUILD_GITHUB_PLUGIN)
return new GITHUB_PLUGIN();
#endif
; // GITHUB fall thru to NULL below
} }
return NULL; return NULL;
...@@ -113,6 +124,12 @@ const wxString IO_MGR::ShowType( PCB_FILE_T aType ) ...@@ -113,6 +124,12 @@ const wxString IO_MGR::ShowType( PCB_FILE_T aType )
case GEDA_PCB: case GEDA_PCB:
return wxString( wxT( "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 ) ...@@ -138,6 +155,11 @@ IO_MGR::PCB_FILE_T IO_MGR::EnumFromStr( const wxString& aType )
if( aType == wxT( "Geda-PCB" ) ) if( aType == wxT( "Geda-PCB" ) )
return GEDA_PCB; return GEDA_PCB;
#if defined(BUILD_GITHUB_PLUGIN)
if( aType == wxT( "Github" ) )
return GITHUB;
#endif
// wxASSERT( blow up here ) // wxASSERT( blow up here )
return PCB_FILE_T( -1 ); return PCB_FILE_T( -1 );
...@@ -176,6 +198,11 @@ IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath ...@@ -176,6 +198,11 @@ IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath
{ {
ret = EAGLE; ret = EAGLE;
} }
#if defined(BUILD_GITHUB_PLUGIN)
// There is no extension for a remote repo. We're thinking about this.
#endif
else else
{ {
// Although KICAD PLUGIN uses libpaths with fixed extension of // Although KICAD PLUGIN uses libpaths with fixed extension of
......
...@@ -48,11 +48,12 @@ public: ...@@ -48,11 +48,12 @@ public:
*/ */
enum PCB_FILE_T enum PCB_FILE_T
{ {
LEGACY, //< Legacy Pcbnew file formats prior to s-expression. LEGACY, ///< Legacy Pcbnew file formats prior to s-expression.
KICAD, //< S-expression Pcbnew file format. KICAD, ///< S-expression Pcbnew file format.
EAGLE, EAGLE,
PCAD, 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. // add your type here.
...@@ -397,7 +398,7 @@ public: ...@@ -397,7 +398,7 @@ public:
API functions which take one. API functions which take one.
*/ */
virtual ~PLUGIN() {} virtual ~PLUGIN() {};
/** /**
* Class RELEASER * Class RELEASER
......
...@@ -55,6 +55,19 @@ class PCB_PARSER; ...@@ -55,6 +55,19 @@ class PCB_PARSER;
/// a BOARD file underneath IO_MGR. /// a BOARD file underneath IO_MGR.
#define CTL_FOR_BOARD (CTL_OMIT_INITIAL_COMMENTS) #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 * Class PCB_IO
* is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files. * is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include <pcb_lexer.h> #include <pcb_lexer.h>
#include <hashtables.h> #include <hashtables.h>
#include <layers_id_colors_and_visibility.h> // LAYER_NUM
#include <common.h> // KiROUND
using namespace PCB_KEYS_T; using namespace PCB_KEYS_T;
...@@ -40,15 +42,16 @@ class BOARD_ITEM; ...@@ -40,15 +42,16 @@ class BOARD_ITEM;
class D_PAD; class D_PAD;
class DIMENSION; class DIMENSION;
class DRAWSEGMENT; class DRAWSEGMENT;
class EDA_TEXT;
class EDGE_MODULE; class EDGE_MODULE;
class TEXTE_MODULE; class TEXTE_MODULE;
class TEXTE_PCB; class TEXTE_PCB;
class TRACK;
class MODULE; class MODULE;
class PCB_TARGET; class PCB_TARGET;
class SEGVIA;
class S3D_MASTER; class S3D_MASTER;
class ZONE_CONTAINER; class ZONE_CONTAINER;
class FPL_CACHE;
/** /**
......
#include <io_mgr.h>
//#include <string>
#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__ ) );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment