diff --git a/include/base_struct.h b/include/base_struct.h index 368da50827..c4cb4b1f8f 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -173,7 +173,7 @@ public: * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to * stop the scan, else #SEARCH_CONTINUE; */ - SEARCH_RESULT virtual Inspect( EDA_ITEM* aItem, const void* aTestData ) = 0; + virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData ) = 0; }; diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 92140becdc..1d7404752e 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -1,5 +1,12 @@ add_definitions(-DPCBNEW) +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) + +FIND_PACKAGE(PythonLibs) +INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) + + ### # Includes ### @@ -209,6 +216,31 @@ set(PCBNEW_COMMON_SRCS ../common/dialogs/dialog_page_settings.cpp ) +## +# Scripting sources +## +set(PCBNEW_SCRIPTING_SRCS + kicad_wrap.cxx + pcbnew_wrap.cxx + ) + +## +# Scripting build +## + +SET(SWIG_OPTS -python -c++ -outdir ${CMAKE_CURRENT_BINARY_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../.. -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../include -DKICAD_TESTING_VERSION -D_FILE_OFFSET_BITS=64 -DPCBNEW -D_LARGE_FILES -D__WXGTK__ -DHAVE_SVN_VERSION -DDEBUG) + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/kicad_wrap.cxx + COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/kicad_wrap.cxx scripting/kicad.i + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx + COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + ### # Windows resource file @@ -269,6 +301,7 @@ make_lexer( add_executable(pcbnew WIN32 MACOSX_BUNDLE ${PCBNEW_SRCS} ${PCBNEW_COMMON_SRCS} + ${PCBNEW_SCRIPTING_SRCS} ${PCBNEW_RESOURCES} ) @@ -292,6 +325,7 @@ target_link_libraries(pcbnew ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${GDI_PLUS_LIBRARIES} + ${PYTHON_LIBRARIES} ) ### diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 84a18f2d03..be4b4871c5 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -45,6 +45,7 @@ #include #include #include +#include // Colors for layers and items @@ -104,11 +105,59 @@ void EDA_APP::MacOpenFile( const wxString& fileName ) } +struct _inittab SWIG_Import_Inittab[1000]; +static int swig_num_modules = 0; + +static void swig_add_module(char *name, void (*initfunc)()) { + SWIG_Import_Inittab[swig_num_modules].name = name; + SWIG_Import_Inittab[swig_num_modules].initfunc = initfunc; + swig_num_modules++; + SWIG_Import_Inittab[swig_num_modules].name = (char *) 0; + SWIG_Import_Inittab[swig_num_modules].initfunc = 0; +} + +extern "C" void init_kicad(void); +extern "C" void init_pcbnew(void); + +static void swig_add_builtin() { + int i = 0; + while (PyImport_Inittab[i].name) { + swig_add_module(PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc); + i++; + } + swig_add_module("_kicad",init_kicad); + swig_add_module("_pcbnew",init_pcbnew); + PyImport_Inittab = SWIG_Import_Inittab; + +} + + bool EDA_APP::OnInit() { wxFileName fn; PCB_EDIT_FRAME* frame = NULL; + int i=0; + + swig_add_builtin(); + + +#if 0 + while(PyImport_Inittab[i].name) + { + printf("name[%d]=>%s\n",i,PyImport_Inittab[i].name); + i++; + } +#endif + Py_Initialize(); + + PyRun_SimpleString("import sys\n" + "sys.path.append(\".\")\n" + "import kicad,pcbnew\n" + "from time import time,ctime\n" + "print 'Today is',ctime(time())\n"); + + InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T ); if( m_Checker && m_Checker->IsAnotherRunning() ) diff --git a/pcbnew/scripting/kicad.i b/pcbnew/scripting/kicad.i new file mode 100644 index 0000000000..38b8f0fc34 --- /dev/null +++ b/pcbnew/scripting/kicad.i @@ -0,0 +1,19 @@ +%module kicad + +%nodefaultctor EDA_ITEM; +%ignore InitKiCadAbout; +%ignore GetCommandOptions; + +%{ + #include + #include + #include + +%} + +%include +%include +%include + + + diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i new file mode 100644 index 0000000000..5754c54be3 --- /dev/null +++ b/pcbnew/scripting/pcbnew.i @@ -0,0 +1,25 @@ +%module pcbnew +%import "kicad.i" + + +%{ + #include + #include + #include + #include + #include +%} + +%include +%include +%include +%include + + + + +/*%template(BOARD_ITEM_List) DLIST; +%template(MODULE_List) DLIST; +%template(TRACK_List) DLIST; +%template(PAD_List) DLIST; +*/