Commit d7692cd1 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

SWIG+Python initial scripting support added.

It does nothing but loading and initializing right now.
parent 07e5eee1
...@@ -173,7 +173,7 @@ public: ...@@ -173,7 +173,7 @@ public:
* @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
* stop the scan, else #SEARCH_CONTINUE; * 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;
}; };
......
add_definitions(-DPCBNEW) add_definitions(-DPCBNEW)
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
### ###
# Includes # Includes
### ###
...@@ -209,6 +216,31 @@ set(PCBNEW_COMMON_SRCS ...@@ -209,6 +216,31 @@ set(PCBNEW_COMMON_SRCS
../common/dialogs/dialog_page_settings.cpp ../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 # Windows resource file
...@@ -269,6 +301,7 @@ make_lexer( ...@@ -269,6 +301,7 @@ make_lexer(
add_executable(pcbnew WIN32 MACOSX_BUNDLE add_executable(pcbnew WIN32 MACOSX_BUNDLE
${PCBNEW_SRCS} ${PCBNEW_SRCS}
${PCBNEW_COMMON_SRCS} ${PCBNEW_COMMON_SRCS}
${PCBNEW_SCRIPTING_SRCS}
${PCBNEW_RESOURCES} ${PCBNEW_RESOURCES}
) )
...@@ -292,6 +325,7 @@ target_link_libraries(pcbnew ...@@ -292,6 +325,7 @@ target_link_libraries(pcbnew
${wxWidgets_LIBRARIES} ${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES} ${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES}
) )
### ###
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <protos.h> #include <protos.h>
#include <hotkeys.h> #include <hotkeys.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <Python.h>
// Colors for layers and items // Colors for layers and items
...@@ -104,11 +105,59 @@ void EDA_APP::MacOpenFile( const wxString& fileName ) ...@@ -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() bool EDA_APP::OnInit()
{ {
wxFileName fn; wxFileName fn;
PCB_EDIT_FRAME* frame = NULL; 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 ); InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T );
if( m_Checker && m_Checker->IsAnotherRunning() ) if( m_Checker && m_Checker->IsAnotherRunning() )
......
%module kicad
%nodefaultctor EDA_ITEM;
%ignore InitKiCadAbout;
%ignore GetCommandOptions;
%{
#include <dlist.h>
#include <base_struct.h>
#include <common.h>
%}
%include <dlist.h>
%include <base_struct.h>
%include <common.h>
%module pcbnew
%import "kicad.i"
%{
#include <class_board_item.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_pad.h>
%}
%include <class_board_item.h>
%include <class_board.h>
%include <class_module.h>
%include <class_track.h>
/*%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(MODULE_List) DLIST<MODULE>;
%template(TRACK_List) DLIST<TRACK>;
%template(PAD_List) DLIST<D_PAD>;
*/
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