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

code cleanup, io_mgr and kicad_plugin included when enabled in cmake...

parent 562d2461
...@@ -223,22 +223,49 @@ set(PCBNEW_COMMON_SRCS ...@@ -223,22 +223,49 @@ set(PCBNEW_COMMON_SRCS
# Scripting sources # Scripting sources
## ##
set(PCBNEW_SCRIPTING_SRCS set(PCBNEW_SCRIPTING_SRCS
kicad_wrap.cxx # kicad_wrap.cxx
pcbnew_wrap.cxx pcbnew_wrap.cxx
scripting/helpers.cpp scripting/wx_python_helpers.cpp
scripting/python_scripting.cpp
) )
## ##
# Scripting build # 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 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 -DDEBUG )
COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/kicad_wrap.cxx scripting/kicad.i
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} # collect CFLAGS , and pass them to swig later
)
get_directory_property( DirDefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} )
SET(SWIG_OPTS ${SWIG_OPTS} -D${d} )
endforeach()
# check if we have IO_MGR and KICAD_PLUGIN available
if ( USE_NEW_PCBNEW_LOAD OR USE_NEW_PCBNEW_SAVE )
SET(SWIG_OPTS ${SWIG_OPTS} -DBUILD_WITH_PLUGIN)
endif()
foreach( d ${SWIG_OPTS} )
message(STATUS "Swig options:" ${d})
endforeach()
if ( USE_NEW_PCBNEW_LOAD OR USE_NEW_PCBNEW_SAVE )
endif()
#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( add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx
COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i
......
...@@ -45,11 +45,10 @@ ...@@ -45,11 +45,10 @@
#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>
#include <class_board.h> #include <class_board.h>
#include <dialogs/dialog_scripting.h> #include <dialogs/dialog_scripting.h>
#include <scripting/python_scripting.h>
// Colors for layers and items // Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings; COLORS_DESIGN_SETTINGS g_ColorsSettings;
...@@ -108,64 +107,14 @@ void EDA_APP::MacOpenFile( const wxString& fileName ) ...@@ -108,64 +107,14 @@ 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;
}
static BOARD *st_board;
BOARD *GetBoard()
{
return st_board;
}
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; int i=0;
swig_add_builtin();
pcbnewInitPythonScripting();
#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 );
...@@ -253,7 +202,7 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); ...@@ -253,7 +202,7 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
*/ */
frame->SetFocus(); frame->SetFocus();
frame->GetCanvas()->SetFocus(); frame->GetCanvas()->SetFocus();
st_board = frame->GetBoard(); pythonSetPcbEditFrame(frame);
DIALOG_SCRIPTING* sw = new DIALOG_SCRIPTING(frame); DIALOG_SCRIPTING* sw = new DIALOG_SCRIPTING(frame);
sw->Show(true); sw->Show(true);
return true; return true;
......
%module kicad //%module kicad
/* OFF NOW, it triggers an error with GCC 4.6 and swig-2.0.4 or trunk..
http://sourceforge.net/tracker/index.php?func=detail&aid=3391906&group_id=1645&atid=101645
%include <std_vector.i>
%include <std_string.i>
*/
%nodefaultctor EDA_ITEM; %nodefaultctor EDA_ITEM;
...@@ -17,7 +23,10 @@ ...@@ -17,7 +23,10 @@
#include <dlist.h> #include <dlist.h>
#include <base_struct.h> #include <base_struct.h>
#include <common.h> #include <common.h>
#include <wx_helpers.h> #include <wx_python_helpers.h>
#include <cstddef>
#include <vector>
using namespace std;
%} %}
...@@ -25,8 +34,12 @@ ...@@ -25,8 +34,12 @@
%include <base_struct.h> %include <base_struct.h>
%include <common.h> %include <common.h>
/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */
%include <wx.i> %include <wx.i>
/*
namespace std
{
%template(intVector) vector<int>;
}
*/
%module pcbnew %module pcbnew
%import "kicad.i"
%include "kicad.i"
%{ %{
#include <wx_python_helpers.h>
#include <class_board_item.h> #include <class_board_item.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_track.h> #include <class_track.h>
#include <class_pad.h> #include <class_pad.h>
#include <class_netinfo.h>
#include <class_pcb_text.h>
#include <class_dimension.h>
#include <dlist.h> #include <dlist.h>
#include <wx_helpers.h>
BOARD *GetBoard(); BOARD *GetBoard();
%} %}
#ifdef BUILD_WITH_PLUGIN
%{
#include <io_mgr.h>
#include <kicad_plugin.h>
%}
#endif
%include <class_board_item.h> %include <class_board_item.h>
%include <class_board.h> %include <class_board.h>
%include <class_module.h> %include <class_module.h>
%include <class_track.h> %include <class_track.h>
%include <class_pad.h> %include <class_pad.h>
%include <class_netinfo.h>
%include <class_pcb_text.h>
%include <class_dimension.h>
%include <dlist.h> %include <dlist.h>
%rename(item) operator BOARD_ITEM*; #ifdef BUILD_WITH_PLUGIN
%rename(item) operator TRACK*; %include <io_mgr.h>
%rename(item) operator D_PAD*; %include <kicad_plugin.h>
%rename(item) operator MODULE*; #endif
%rename(Get) operator BOARD_ITEM*;
%rename(Get) operator TRACK*;
%rename(Get) operator D_PAD*;
%rename(Get) operator MODULE*;
BOARD *GetBoard();
BOARD *GetBoard();
// se must translate C++ templates to scripting languages
%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>; %template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(MODULE_List) DLIST<MODULE>; %template(MODULE_List) DLIST<MODULE>;
...@@ -37,4 +59,3 @@ BOARD *GetBoard(); ...@@ -37,4 +59,3 @@ BOARD *GetBoard();
%template(PAD_List) DLIST<D_PAD>; %template(PAD_List) DLIST<D_PAD>;
#include <python_scripting.h>
/* init functions defined by swig */
extern "C" void init_kicad(void);
extern "C" void init_pcbnew(void);
/* python inittab that links module names to module init functions
* we will rebuild it to include the original python modules plus
* our own ones
*/
struct _inittab SwigImportInittab[1000];
static int SwigNumModules = 0;
/* Add a name + initfuction to our SwigImportInittab */
static void swigAddModule(const char *name, void (*initfunc)()) {
SwigImportInittab[SwigNumModules].name = (char *)name;
SwigImportInittab[SwigNumModules].initfunc = initfunc;
SwigNumModules++;
SwigImportInittab[SwigNumModules].name = (char *) 0;
SwigImportInittab[SwigNumModules].initfunc = 0;
}
/* Add the builting python modules */
static void swigAddBuiltin() {
int i = 0;
while (PyImport_Inittab[i].name) {
swigAddModule(PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc);
i++;
}
}
static void swigAddModules()
{
//swigAddModule("_kicad",init_kicad);
swigAddModule("_pcbnew",init_pcbnew);
}
static void swigSwitchPythonBuiltin()
{
PyImport_Inittab = SwigImportInittab;
}
static PCB_EDIT_FRAME *PcbEditFrame=NULL;
BOARD *GetBoard()
{
if (PcbEditFrame) return PcbEditFrame->GetBoard();
else return NULL;
}
void pythonSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame)
{
PcbEditFrame = aPCBEdaFrame;
}
void pcbnewInitPythonScripting()
{
swigAddBuiltin();
swigAddModules();
swigSwitchPythonBuiltin();
#if 0
/* print the list of modules available from python */
while(PyImport_Inittab[i].name)
{
printf("name[%d]=>%s\n",i,PyImport_Inittab[i].name);
i++;
}
#endif
Py_Initialize();
/* setup the scripting path, we may need to add the installation path
of kicad here */
PyRun_SimpleString("import sys\n"
"sys.path.append(\".\")\n"
"import pcbnew\n");
}
#ifndef __PYTHON_SCRIPTING_H
#define __PYTHON_SCRIPTING_H
#include <wxPcbStruct.h>
#include <Python.h>
void pythonSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame);
void pcbnewInitPythonScripting(void);
#endif
%{ %{
#include <wx_helpers.h> #include <wx_python_helpers.h>
%} %}
// encoding setup, ascii by default /////////////////////////////////////////// // encoding setup, ascii by default ///////////////////////////////////////////
......
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