Commit f4223506 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo
Browse files

pcbnew_scripting_helpers.cpp/h to handle generic scripting tools

CMakeLists.txt options to build scripting or scripting modules
parent 970e0333
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,16 @@ option(KICAD_TESTING_VERSION
       "set this option to ON to build the stable version of KICAD. mainly used to set version ID (default OFF)"
       "set this option to ON to build the stable version of KICAD. mainly used to set version ID (default OFF)"
       )
       )


option(KICAD_SCRIPTING
       "set this option ON to build the scripting support inside kicad binaries"
       )

option(KICAD_SCRIPTING_MODULES
       "set this option ON to build kicad modules that can be used from scripting languages"
       )
       
       

#Set version option (stable or testing)
#Set version option (stable or testing)


if (KICAD_STABLE_VERSION )
if (KICAD_STABLE_VERSION )
+75 −65
Original line number Original line Diff line number Diff line
add_definitions(-DPCBNEW)
add_definitions(-DPCBNEW)


if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES)

	FIND_PACKAGE(SWIG REQUIRED)
	FIND_PACKAGE(SWIG REQUIRED)
	INCLUDE(${SWIG_USE_FILE})
	INCLUDE(${SWIG_USE_FILE})
	
	
	FIND_PACKAGE(PythonLibs)
	FIND_PACKAGE(PythonLibs)
	INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
	INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

  add_definitions(-DPCBNEW -DKICAD_SCRIPTING)	
endif()


###
###
# Includes
# Includes
@@ -223,21 +226,26 @@ set(PCBNEW_COMMON_SRCS
##
##
# Scripting sources
# Scripting sources
##
##

if (KICAD_SCRIPTING)

	set(PCBNEW_SCRIPTING_PYTHON_HELPERS    
	set(PCBNEW_SCRIPTING_PYTHON_HELPERS    
	   scripting/wx_python_helpers.cpp
	   scripting/wx_python_helpers.cpp
	   scripting/pcbnew_scripting_helpers.cpp
	   scripting/python_scripting.cpp
	   scripting/python_scripting.cpp
	   )
	   )


	set(PCBNEW_SCRIPTING_SRCS
	set(PCBNEW_SCRIPTING_SRCS
#   kicad_wrap.cxx
    	pcbnew_wrap.cxx
    	pcbnew_wrap.cxx
    	${PCBNEW_SCRIPTING_PYTHON_HELPERS}
    	${PCBNEW_SCRIPTING_PYTHON_HELPERS}
   	)
   	)
endif()


##
##
# Scripting build
# Scripting build
##
##


if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES)


	set(SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/../.. -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../include -DDEBUG)
	set(SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/../.. -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../include -DDEBUG)
	
	
@@ -253,34 +261,27 @@ if ( USE_NEW_PCBNEW_LOAD OR USE_NEW_PCBNEW_SAVE )
	    SET(SWIG_FLAGS ${SWIG_FLAGS} -DBUILD_WITH_PLUGIN)
	    SET(SWIG_FLAGS ${SWIG_FLAGS} -DBUILD_WITH_PLUGIN)
	endif()
	endif()


endif()
       
       
foreach( d ${SWIG_FLAGS} )
if (KICAD_SCRIPTING)
    message(STATUS "Swig options:" ${d})
endforeach()
      
      
	SET(SWIG_OPTS -python -c++ -outdir ${CMAKE_CURRENT_BINARY_DIR} ${SWIG_FLAGS} )
	SET(SWIG_OPTS -python -c++ -outdir ${CMAKE_CURRENT_BINARY_DIR} ${SWIG_FLAGS} )
		
		

# we checked the posibility to build kicad thinks in a separate module, but it 
# will be easier in just one "pcbnew" for now
#
#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
	               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	)
	)
	
	
endif(KICAD_SCRIPTING)



###
###
# _pcbnew DLL/DSO file creation
# _pcbnew DLL/DSO file creation
###
###


if (KICAD_SCRIPTING_MODULES)

  SET(CMAKE_SWIG_FLAGS ${SWIG_FLAGS})
  SET(CMAKE_SWIG_FLAGS ${SWIG_FLAGS})
  SET_SOURCE_FILES_PROPERTIES(scripting/pcbnew.i PROPERTIES CPLUSPLUS ON)
  SET_SOURCE_FILES_PROPERTIES(scripting/pcbnew.i PROPERTIES CPLUSPLUS ON)
  SWIG_ADD_MODULE(pcbnew python scripting/pcbnew.i ${PCBNEW_SCRIPTING_PYTHON_HELPERS} ${PCBNEW_SRCS})
  SWIG_ADD_MODULE(pcbnew python scripting/pcbnew.i ${PCBNEW_SCRIPTING_PYTHON_HELPERS} ${PCBNEW_SRCS})
@@ -296,6 +297,7 @@ SWIG_LINK_LIBRARIES(pcbnew
      ${GDI_PLUS_LIBRARIES}
      ${GDI_PLUS_LIBRARIES}
      ${PYTHON_LIBRARIES})
      ${PYTHON_LIBRARIES})
      
      
endif (KICAD_SCRIPTING_MODULES)


###
###
# Windows resource file
# Windows resource file
@@ -390,6 +392,14 @@ install(TARGETS pcbnew
    DESTINATION ${KICAD_BIN}
    DESTINATION ${KICAD_BIN}
    COMPONENT binary)
    COMPONENT binary)


if (KICAD_SCRIPTING_MODULES)
  install(FILES ${CMAKE_BINARY_DIR}/pcbnew/pcbnew.py
          DESTINATION share/python)
        
  install(FILES ${CMAKE_BINARY_DIR}/pcbnew/_pcbnew.so
          DESTINATION share/python)
endif(KICAD_SCRIPTING_MODULES)



# The specctra test fails to build properly using MS Visual Studio.
# The specctra test fails to build properly using MS Visual Studio.
if(NOT MSVC)
if(NOT MSVC)
+11 −2
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@


#include <dialogs/dialog_scripting.h>
#include <dialogs/dialog_scripting.h>
#include <scripting/python_scripting.h>
#include <scripting/python_scripting.h>
#include <scripting/pcbnew_scripting_helpers.h>


// Colors for layers and items
// Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings;
COLORS_DESIGN_SETTINGS g_ColorsSettings;
@@ -114,7 +115,10 @@ bool EDA_APP::OnInit()


    int i=0;
    int i=0;


#ifdef KICAD_SCRIPTING    
    pcbnewInitPythonScripting();
    pcbnewInitPythonScripting();
#endif    
    


    InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T );
    InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T );


@@ -150,6 +154,11 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
    ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr );
    ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr );


    frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
    frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );

    #ifdef KICAD_SCRIPTING    
        ScriptingSetPcbEditFrame(frame); /* give the scripting helpers access to our frame */
    #endif    
    
    frame->UpdateTitle();
    frame->UpdateTitle();


    SetTopWindow( frame );
    SetTopWindow( frame );
@@ -202,7 +211,7 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
     */
     */
    frame->SetFocus();
    frame->SetFocus();
    frame->GetCanvas()->SetFocus();
    frame->GetCanvas()->SetFocus();
    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;
+9 −3
Original line number Original line Diff line number Diff line
@@ -27,15 +27,21 @@
	#include <cstddef>
	#include <cstddef>
  #include <vector>
  #include <vector>
	using namespace std;
	using namespace std;
	#include <class_title_block.h>
	#include <class_colors_design_settings.h>


%}
%}


/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */
%include <wx.i>


%include <dlist.h>
%include <dlist.h>
%include <base_struct.h>
%include <base_struct.h>
%include <common.h>
%include <common.h>
%include <class_title_block.h>
%include <class_colors_design_settings.h>


/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */
%include <wx.i>


/*
/*
namespace std 
namespace std 
+43 −16
Original line number Original line Diff line number Diff line
%module pcbnew
%module pcbnew

%include "kicad.i"
%include "kicad.i"


// this is what it must be included in the wrapper .cxx code to compile

%{ 
%{ 
  #include <wx_python_helpers.h>
  #include <wx_python_helpers.h>
	#include <class_board_item.h>
	#include <class_board_item.h>
@@ -13,11 +14,13 @@
  #include <class_pcb_text.h>
  #include <class_pcb_text.h>
	#include <class_dimension.h>
	#include <class_dimension.h>
	#include <dlist.h>
	#include <dlist.h>
	#include <class_zone_settings.h>
	#include <class_netclass.h>
	#include <class_netinfo.h>
	#include <layers_id_colors_and_visibility.h>
	#include <pcbnew_scripting_helpers.h>
      
      

	BOARD *GetBoard(); /* get current editor board */


	BOARD *GetBoard();
%}
%}


#ifdef BUILD_WITH_PLUGIN
#ifdef BUILD_WITH_PLUGIN
@@ -27,7 +30,6 @@
%}
%}
#endif
#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>
@@ -37,12 +39,32 @@
%include <class_pcb_text.h>
%include <class_pcb_text.h>
%include <class_dimension.h>
%include <class_dimension.h>
%include <dlist.h>
%include <dlist.h>
%include <class_zone_settings.h>
%include <class_netclass.h>
%include <class_netinfo.h>
%include <layers_id_colors_and_visibility.h>

/* the IO_ERROR exception handler, not working yet... */
%exception
{
	try {
	$function
	}
	catch (IO_ERROR e) {
	 	PyErr_SetString(PyExc_IOError,"IO error");
		return NULL;
	}
}

%include <pcbnew_scripting_helpers.h>


#ifdef BUILD_WITH_PLUGIN
#ifdef BUILD_WITH_PLUGIN
  %include <io_mgr.h>
  %include <io_mgr.h>
  %include <kicad_plugin.h>
  %include <kicad_plugin.h>
#endif
#endif


/* this is to help python with the * accessor of DLIST templates */

%rename(Get) operator BOARD_ITEM*; 
%rename(Get) operator BOARD_ITEM*; 
%rename(Get) operator TRACK*; 
%rename(Get) operator TRACK*; 
%rename(Get) operator D_PAD*; 
%rename(Get) operator D_PAD*; 
@@ -51,11 +73,16 @@


BOARD *GetBoard();
BOARD *GetBoard();


// se must translate C++ templates to scripting languages
// we 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>;
%template(TRACK_List)      DLIST<TRACK>;
%template(TRACK_List)      DLIST<TRACK>;
%template(PAD_List)        DLIST<D_PAD>;
%template(PAD_List)        DLIST<D_PAD>;


/* TODO: -the std::* compilatio is broken with some swig + gcc combinations 
 *        see kicad.i for more information.
 * %template(MARKER_Vector) std::vector<MARKER_PCB*>;
 * %template(ZONE_CONTAINER_Vector) std::vector<ZONE_CONTAINER*>;
 */
Loading