Commit 829e952e authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

Python scripting and fixes for non-scripting compilation

parents 5a6c088b 863c1b48
......@@ -48,6 +48,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)"
)
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)
if (KICAD_STABLE_VERSION )
......@@ -82,13 +92,13 @@ endif(KICAD_STABLE_VERSION )
if(CMAKE_COMPILER_IS_GNUCXX)
# Set default flags for Release build.
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2 -DNDEBUG ")
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2 -DNDEBUG -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -O2 -DNDEBUG -fPIC")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s")
# Set default flags for Debug build.
set(CMAKE_C_FLAGS_DEBUG "-Wall -g3 -ggdb3 -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -ggdb3 -DDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-Wall -g3 -ggdb3 -DDEBUG -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -ggdb3 -DDEBUG -fPIC")
endif(CMAKE_COMPILER_IS_GNUCXX)
......
......@@ -330,6 +330,7 @@ set( BMAPS_MID
modratsnest
module_check
module_edit
module_wizard
module_filtered_list
module_full_list
module_options
......
/* Do not modify this file, it was automatically generated by the
* PNG2cpp CMake script, using a *.png file as input.
*/
#include <bitmaps.h>
static const unsigned char png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 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, 0x51, 0x58, 0x58, 0x88, 0xbd,
0x5b, 0x37, 0xe3, 0xb8, 0x7a, 0x35, 0xba, 0x3c, 0x66, 0xde, 0xfd, 0x07, 0x3e, 0x0a, 0x38, 0xab,
0xbb, 0xc7, 0x1e, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
const BITMAP_OPAQUE module_wizard_xpm[1] = {{ png, sizeof( png ), "module_wizard_xpm" }};
//EOF
This diff is collapsed.
......@@ -163,6 +163,6 @@ if(NOT MSVC)
# This one gets made only when testing.
# to build it, first enable #define STAND_ALONE at top of dsnlexer.cpp
add_executable( dsntest EXCLUDE_FROM_ALL dsnlexer.cpp )
target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} )
target_link_libraries( dsntest common ${wxWidgets_LIBRARIES} rt )
endif( NOT MSVC )
......@@ -189,7 +189,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;
};
......
......@@ -275,6 +275,7 @@ EXTERN_BITMAP( mode_track_xpm )
EXTERN_BITMAP( modratsnest_xpm )
EXTERN_BITMAP( module_check_xpm )
EXTERN_BITMAP( module_edit_xpm )
EXTERN_BITMAP( module_wizard_xpm )
EXTERN_BITMAP( module_filtered_list_xpm )
EXTERN_BITMAP( module_pin_filtered_list_xpm )
EXTERN_BITMAP( module_full_list_xpm )
......
......@@ -41,12 +41,12 @@
#include <richio.h>
#include <convert_to_biu.h>
#if !wxUSE_PRINTING_ARCHITECTURE
#if !wxUSE_PRINTING_ARCHITECTURE && !SWIG
# error "You must use '--enable-printarch' in your wx library configuration."
#endif
#if defined( __WXGTK__ )
# if !wxUSE_LIBGNOMEPRINT && !wxUSE_GTKPRINT
# if !wxUSE_LIBGNOMEPRINT && !wxUSE_GTKPRINT && !SWIG
# error "You must use '--with-gnomeprint' or '--with-gtkprint' in your wx library configuration."
# endif
#endif
......
add_definitions(-DPCBNEW)
if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES)
EXECUTE_PROCESS(COMMAND python2 -c "import sys;print\"%s.%s\"%sys.version_info[0:2]" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(PYTHON_DEST "lib/python${PYTHON_VERSION}/dist-packages" )
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripting)
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
add_definitions(-DPCBNEW -DKICAD_SCRIPTING)
endif()
###
# Includes
###
......@@ -12,6 +23,8 @@ include_directories(
${Boost_INCLUDE_DIR}
../polygon
../common/dialogs
./scripting
../scripting
${INC_AFTER}
)
......@@ -86,9 +99,12 @@ set(PCBNEW_DIALOGS
dialogs/dialog_SVG_print.cpp
dialogs/dialog_SVG_print_base.cpp
dialogs/dialog_set_grid_base.cpp
footprint_wizard.cpp
footprint_wizard_frame.cpp
dialogs/dialog_footprint_wizard_list_base.cpp
dialogs/dialog_footprint_wizard_list.cpp
)
set(PCBNEW_AUTOROUTER_SRCS
autorouter/automove.cpp
autorouter/autoplac.cpp
......@@ -101,8 +117,7 @@ set(PCBNEW_AUTOROUTER_SRCS
autorouter/work.cpp
)
set(PCBNEW_SRCS
${PCBNEW_AUTOROUTER_SRCS}
set(PCBNEW_CLASS_SRCS
tool_modview.cpp
modview.cpp
modview_frame.cpp
......@@ -113,8 +128,8 @@ set(PCBNEW_SRCS
block.cpp
block_module_editor.cpp
build_BOM_from_board.cpp
class_pcb_layer_box_selector.cpp
class_pcb_layer_widget.cpp
class_pcb_layer_box_selector.cpp
clean.cpp
connect.cpp
controle.cpp
......@@ -209,8 +224,11 @@ set(PCBNEW_SRCS
zones_polygons_insulated_copper_islands.cpp
zones_polygons_test_connections.cpp
zones_test_and_combine_areas.cpp
class_footprint_wizard.cpp
)
set(PCBNEW_SRCS ${PCBNEW_AUTOROUTER_SRCS} ${PCBNEW_CLASS_SRCS} ${PCBNEW_DIALOGS})
###
# We need some extra sources from common
###
......@@ -219,6 +237,105 @@ set(PCBNEW_COMMON_SRCS
../common/base_units.cpp
)
##
# Scripting sources
##
set(PCBNEW_SCRIPTING_DIALOGS
dialogs/dialog_scripting_base.cpp
dialogs/dialog_scripting.cpp
)
set(PCBNEW_SCRIPTING_PYTHON_HELPERS
../scripting/wx_python_helpers.cpp
../scripting/python_scripting.cpp
scripting/pcbnew_scripting_helpers.cpp
scripting/pcbnew_footprint_wizards.cpp
)
if (KICAD_SCRIPTING)
set(PCBNEW_SCRIPTING_SRCS
${PCBNEW_SCRIPTING_DIALOGS}
pcbnew_wrap.cxx
${PCBNEW_SCRIPTING_PYTHON_HELPERS}
)
endif()
##
# 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 -I${CMAKE_CURRENT_SOURCE_DIR}/../scripting )
if (DEBUG)
set(SWIG_FLAGS ${SWIG_FLAGS} -DDEBUG)
endif()
# collect CFLAGS , and pass them to swig later
get_directory_property( DirDefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} )
SET(SWIG_FLAGS ${SWIG_FLAGS} -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_FLAGS ${SWIG_FLAGS} -DBUILD_WITH_PLUGIN)
endif()
if ( USE_PCBNEW_NANOMETRES )
SET(SWIG_FLAGS ${SWIG_FLAGS} -DUSE_PCBNEW_NANOMETRES)
endif()
endif()
if (KICAD_SCRIPTING)
SET(SWIG_OPTS -python -c++ -outdir ${CMAKE_CURRENT_BINARY_DIR} ${SWIG_FLAGS} )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx
DEPENDS scripting/pcbnew.i
DEPENDS scripting/board.i
DEPENDS scripting/board_item.i
DEPENDS scripting/module.i
DEPENDS scripting/plugins.i
DEPENDS scripting/units.i
DEPENDS ../scripting/dlist.i
DEPENDS ../scripting/kicad.i
DEPENDS ../scripting/wx.i
DEPENDS ../scripting/kicadplugins.i
COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../scripting/fixswigimports.py ${CMAKE_CURRENT_BINARY_DIR}/pcbnew.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif(KICAD_SCRIPTING)
###
# _pcbnew DLL/DSO file creation
###
if (KICAD_SCRIPTING_MODULES)
SET(CMAKE_SWIG_FLAGS ${SWIG_FLAGS})
SET_SOURCE_FILES_PROPERTIES(scripting/pcbnew.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(pcbnew python scripting/pcbnew.i ${PCBNEW_SCRIPTING_PYTHON_HELPERS} ${PCBNEW_SRCS} ${PCBNEW_COMMON_SRCS})
SWIG_LINK_LIBRARIES(pcbnew
3d-viewer
pcbcommon
common
bitmaps
polygon
kbool
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES})
endif (KICAD_SCRIPTING_MODULES)
###
# Windows resource file
......@@ -279,6 +396,7 @@ make_lexer(
add_executable(pcbnew WIN32 MACOSX_BUNDLE
${PCBNEW_SRCS}
${PCBNEW_COMMON_SRCS}
${PCBNEW_SCRIPTING_SRCS}
${PCBNEW_RESOURCES}
)
......@@ -302,6 +420,8 @@ target_link_libraries(pcbnew
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES}
rt
)
###
......@@ -311,16 +431,44 @@ install(TARGETS pcbnew
DESTINATION ${KICAD_BIN}
COMPONENT binary)
if(KICAD_SCRIPTING)
add_custom_target(FixSwigImportsScripting ALL
${CMAKE_CURRENT_SOURCE_DIR}/../scripting/fixswigimports.py ${CMAKE_CURRENT_BINARY_DIR}/pcbnew.py
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pcbnew
COMMENT "Fixing swig_import_helper"
)
install(FILES ${CMAKE_BINARY_DIR}/pcbnew/pcbnew.py
DESTINATION ${PYTHON_DEST})
endif(KICAD_SCRIPTING)
if (KICAD_SCRIPTING_MODULES)
add_custom_target(FixSwigImportsModuleScripting ALL
${CMAKE_CURRENT_SOURCE_DIR}/../scripting/fixswigimports.py ${CMAKE_CURRENT_BINARY_DIR}/pcbnew.py
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew
COMMENT "Fixing swig_import_helper"
)
install(FILES ${CMAKE_BINARY_DIR}/pcbnew/pcbnew.py
DESTINATION ${PYTHON_DEST})
install(FILES ${CMAKE_BINARY_DIR}/pcbnew/_pcbnew.so
DESTINATION ${PYTHON_DEST})
endif(KICAD_SCRIPTING_MODULES)
# The specctra test fails to build properly using MS Visual Studio.
if(NOT MSVC)
# This one gets made only when testing.
add_executable(specctra_test EXCLUDE_FROM_ALL specctra_test.cpp specctra.cpp)
target_link_libraries(specctra_test common ${wxWidgets_LIBRARIES})
target_link_libraries(specctra_test common ${wxWidgets_LIBRARIES} rt)
endif(NOT MSVC)
# This one gets made only when testing.
add_executable(layer_widget_test WIN32 EXCLUDE_FROM_ALL
layer_widget.cpp
)
target_link_libraries(layer_widget_test common ${wxWidgets_LIBRARIES})
target_link_libraries(layer_widget_test common ${wxWidgets_LIBRARIES} rt)
/**
* @file class_footprint_wizard.cpp
* @brief Class FOOTPRINT_WIZARD and FOOTPRINT_WIZARDS
*/
#include "class_footprint_wizard.h"
#include <stdio.h>
void FOOTPRINT_WIZARD::register_wizard()
{
FOOTPRINT_WIZARDS::register_wizard( this );
}
/**
* FOOTPRINT_WIZARD system wide static list
*/
std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards;
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex )
{
return m_FootprintWizards[aIndex];
}
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( wxString aName )
{
int max = GetSize();
for( int i=0; i<max;i++ )
{
FOOTPRINT_WIZARD *wizard = GetWizard( i );
wxString name = wizard->GetName();
if ( name.Cmp(aName) )
return wizard;
}
return NULL;
}
int FOOTPRINT_WIZARDS::GetSize()
{
return m_FootprintWizards.size();
}
void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard)
{
wxString name = aWizard->GetName();
m_FootprintWizards.push_back(aWizard);
//printf("Registered footprint wizard '%s'\n",(const char*)name.mb_str() );
}
/**
* @file pcbnew_footprint_wizards.h
* @brief Class PCBNEW_FOOTPRINT_WIZARDS
*/
#ifndef CLASS_FOOTPRINT_WIZARD_H
#define CLASS_FOOTPRINT_WIZARD_H
#include <vector>
#include <wxPcbStruct.h>
/**
* Class FOOTPRINT_WIZARD
* This is the parent class from where any footprint wizard class must
* derive */
class FOOTPRINT_WIZARD
{
public:
FOOTPRINT_WIZARD() {}
~FOOTPRINT_WIZARD() {}
/**
* Function GetName
* @return the name of the wizard
*/
virtual wxString GetName()=0;
/**
* Function GetImage
* @return an svg image of the wizard to be rendered
*/
virtual wxString GetImage()=0;
/**
* Function GetDescription
* @return a description of the footprint wizard
*/
virtual wxString GetDescription()=0;
/**
* Function GetNumParameterPages
* @return the number of parameter pages that this wizard will show to the user
*/
virtual int GetNumParameterPages()=0;
/**
* Function GetParameterPageName
* @param aPage is the page we want the name of
* @return a string with the page name
*/
virtual wxString GetParameterPageName(int aPage)=0;
/**
* Function GetParameterNames
* @param aPage is the page we want the parameter names of
* @return an array string with the parameter names on a certain page
*/
virtual wxArrayString GetParameterNames(int aPage)=0;
/**
* Function GetParameterValues
* @param aPage is the page we want the parameter values of
* @return an array of parameter values
*/
virtual wxArrayString GetParameterValues(int aPage)=0;
/**
* Function GetParameterErrors
* @param aPAge is the page we want to know the errors of
* @return an array of errors (if any) for the parameters, empty strings for OK parameters
*/
virtual wxArrayString GetParameterErrors(int aPage)=0;
/**
* Function SetParameterValues
* @param aPage is the page we want to set the parameters in
* @param aValues are the values we want to set into the parameters
* @return an array of parameter values
*/
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
/**
* Function GetModule
* This method builds the module itself and returns it to the caller function
* @return PCB module built from the parameters given to the class
*/
virtual MODULE *GetModule()=0;
/**
* Function register_wizard
* It's the standard method of a "FOOTPRINT_WIZARD" to register itself into
* the FOOTPRINT_WIZARDS singleton manager
*
*/
void register_wizard();
};
class FOOTPRINT_WIZARDS
{
private:
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
public:
/**
* Function register_wizard
* A footprint wizard calls this static method when it wants to register itself
* into the system wizards
*
* @param aWizard is the footprint wizard to be registered
*
*/
static void register_wizard(FOOTPRINT_WIZARD *wizard);
/**
* Function GetWizard
* @return a wizard object by it's name or NULL if it isn't available.
*
*/
static FOOTPRINT_WIZARD* GetWizard(wxString aName);
/**
* Function GetWizard
* @return a wizard object by it's number or NULL if it isn't available.
*
*/
static FOOTPRINT_WIZARD* GetWizard(int aIndex);
/**
* Function GetSize
* @return the number of wizards available into the system
*/
static int GetSize();
};
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
......@@ -235,8 +235,6 @@ public:
*/
bool Read_GPCB_Descr( const wxString& CmpFullFileName );
int Read_3D_Descr( LINE_READER* aReader );
/* drawing functions */
void Draw( EDA_DRAW_PANEL* aPanel,
......
......@@ -294,13 +294,6 @@ public:
*/
NETCLASS* Find( const wxString& aName ) const;
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
};
#endif // CLASS_NETCLASS_H
/**
* @file dialog_scripting.cpp
*/
#include <wx-2.8/wx/generic/grid.h>
#include <fctsys.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <pcbcommon.h>
#include <dialog_footprint_wizard_list.h>
#include <class_footprint_wizard.h>
DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
: DIALOG_FOOTPRINT_WIZARD_LIST_BASE( aParent )
{
SetFocus();
int n_wizards = FOOTPRINT_WIZARDS::GetSize();
// Current wizard selection, empty or first
m_FootprintWizard = NULL;
if (n_wizards)
m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(0);
// Choose selection mode and insert the needed rows
m_footprintWizardsGrid->SetColSize( 0, 0 ); // hide the preview for now
m_footprintWizardsGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
m_footprintWizardsGrid->InsertRows(0,n_wizards,true);
// Put all wizards in the list
for (int i=0;i<n_wizards;i++)
{
FOOTPRINT_WIZARD *wizard = FOOTPRINT_WIZARDS::GetWizard(i);
wxString name = wizard->GetName();
wxString description = wizard->GetDescription();
wxString image = wizard->GetImage();
m_footprintWizardsGrid->SetCellValue(i,1,name);
m_footprintWizardsGrid->SetCellValue(i,2,description);
}
// Select the first row
m_footprintWizardsGrid->ClearSelection();
m_footprintWizardsGrid->SelectRow(0,false);
}
void DIALOG_FOOTPRINT_WIZARD_LIST::OnCellWizardClick( wxGridEvent& event )
{
int click_row = event.GetRow();
m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(click_row);
m_footprintWizardsGrid->SelectRow(event.GetRow(),false);
}
FOOTPRINT_WIZARD* DIALOG_FOOTPRINT_WIZARD_LIST::GetWizard()
{
return m_FootprintWizard;
}
void DIALOG_FOOTPRINT_WIZARD_LIST::OnOpenButtonClick( wxCommandEvent& event )
{
this->MakeModal(false);
this->Close(true);
}
This diff is collapsed.
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_footprint_wizard_list.h
/////////////////////////////////////////////////////////////////////////////
#ifndef _DIALOG_FOOTPRINT_WIZARD_LIST_H_
#define _DIALOG_FOOTPRINT_WIZARD_LIST_H_
#include <dialog_footprint_wizard_list_base.h>
#include <class_footprint_wizard.h>
class DIALOG_FOOTPRINT_WIZARD_LIST: public DIALOG_FOOTPRINT_WIZARD_LIST_BASE
{
private:
wxDialog * m_Parent;
FOOTPRINT_WIZARD *m_FootprintWizard;
public:
DIALOG_FOOTPRINT_WIZARD_LIST(wxWindow * parent );
FOOTPRINT_WIZARD* GetWizard();
private:
void OnCellWizardClick( wxGridEvent& event );
void OnOpenButtonClick( wxCommandEvent& event );
};
#endif // _DIALOG_FOOTPRINT_WIZARD_LIST_H_
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_footprint_wizard_list_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_FOOTPRINT_WIZARD_LIST_BASE::DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_footprintWizardsGrid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_footprintWizardsGrid->CreateGrid( 0, 3 );
m_footprintWizardsGrid->EnableEditing( false );
m_footprintWizardsGrid->EnableGridLines( true );
m_footprintWizardsGrid->EnableDragGridSize( false );
m_footprintWizardsGrid->SetMargins( 0, 0 );
// Columns
m_footprintWizardsGrid->SetColSize( 0, 80 );
m_footprintWizardsGrid->SetColSize( 1, 80 );
m_footprintWizardsGrid->SetColSize( 2, 325 );
m_footprintWizardsGrid->EnableDragColMove( false );
m_footprintWizardsGrid->EnableDragColSize( true );
m_footprintWizardsGrid->SetColLabelSize( 20 );
m_footprintWizardsGrid->SetColLabelValue( 0, _("Preview") );
m_footprintWizardsGrid->SetColLabelValue( 1, _("Name") );
m_footprintWizardsGrid->SetColLabelValue( 2, _("Description") );
m_footprintWizardsGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
// Rows
m_footprintWizardsGrid->AutoSizeRows();
m_footprintWizardsGrid->EnableDragRowSize( true );
m_footprintWizardsGrid->SetRowLabelSize( 1 );
m_footprintWizardsGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Label Appearance
// Cell Defaults
m_footprintWizardsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
m_footprintWizardsGrid->SetMinSize( wxSize( -1,120 ) );
bSizer4->Add( m_footprintWizardsGrid, 1, wxALL, 5 );
m_btOpen = new wxButton( this, wxID_ANY, _("Open"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_btOpen, 0, wxALIGN_CENTER|wxALL, 5 );
this->SetSizer( bSizer4 );
this->Layout();
bSizer4->Fit( this );
this->Centre( wxBOTH );
// Connect Events
m_footprintWizardsGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellWizardClick ), NULL, this );
m_btOpen->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnOpenButtonClick ), NULL, this );
}
DIALOG_FOOTPRINT_WIZARD_LIST_BASE::~DIALOG_FOOTPRINT_WIZARD_LIST_BASE()
{
// Disconnect Events
m_footprintWizardsGrid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnCellWizardClick ), NULL, this );
m_btOpen->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_WIZARD_LIST_BASE::OnOpenButtonClick ), NULL, this );
}
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_footprint_wizard_list_base__
#define __dialog_footprint_wizard_list_base__
#include <wx/intl.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/font.h>
#include <wx/grid.h>
#include <wx/gdicmn.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_FOOTPRINT_WIZARD_LIST_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_FOOTPRINT_WIZARD_LIST_BASE : public wxDialog
{
private:
protected:
wxGrid* m_footprintWizardsGrid;
wxButton* m_btOpen;
// Virtual event handlers, overide them in your derived class
virtual void OnCellWizardClick( wxGridEvent& event ) { event.Skip(); }
virtual void OnOpenButtonClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_FOOTPRINT_WIZARD_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Wizards"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE );
~DIALOG_FOOTPRINT_WIZARD_LIST_BASE();
};
#endif //__dialog_footprint_wizard_list_base__
/**
* @file dialog_scripting.cpp
*/
#include <Python.h>
#include <fctsys.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <pcbcommon.h>
#include <dialog_scripting.h>
DIALOG_SCRIPTING::DIALOG_SCRIPTING( wxWindow* parent )
: DIALOG_SCRIPTING_BASE( parent )
{
SetFocus();
}
void DIALOG_SCRIPTING::OnRunButtonClick( wxCommandEvent& event )
{
wxCharBuffer buffer = m_txScript->GetValue().ToUTF8();
PyRun_SimpleString(buffer.data());
}
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_scripting.h
/////////////////////////////////////////////////////////////////////////////
#ifndef _DIALOG_SCRIPTING_H_
#define _DIALOG_SCRIPTING_H_
#include <dialog_scripting_base.h>
class DIALOG_SCRIPTING: public DIALOG_SCRIPTING_BASE
{
private:
wxDialog * m_Parent;
public:
DIALOG_SCRIPTING(wxWindow * parent );
private:
void OnRunButtonClick( wxCommandEvent& event );
};
#endif // _DIALOG_SCRIPTING_H_
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_scripting_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_SCRIPTING_BASE::DIALOG_SCRIPTING_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_txScript = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxTE_MULTILINE );
m_txScript->SetMinSize( wxSize( 480,500 ) );
bSizer4->Add( m_txScript, 0, wxALL, 5 );
m_btRun = new wxButton( this, wxID_ANY, wxT("&Run"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_btRun, 0, wxALL, 5 );
this->SetSizer( bSizer4 );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
m_btRun->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCRIPTING_BASE::OnRunButtonClick ), NULL, this );
}
DIALOG_SCRIPTING_BASE::~DIALOG_SCRIPTING_BASE()
{
// Disconnect Events
m_btRun->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCRIPTING_BASE::OnRunButtonClick ), NULL, this );
}
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_scripting_base__
#define __dialog_scripting_base__
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_SCRIPTING_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_SCRIPTING_BASE : public wxFrame
{
private:
protected:
wxTextCtrl* m_txScript;
wxButton* m_btRun;
// Virtual event handlers, overide them in your derived class
virtual void OnRunButtonClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_SCRIPTING_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Scripting Test Window"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,600 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~DIALOG_SCRIPTING_BASE();
};
#endif //__dialog_scripting_base__
/**
* @file footprint_wizard.cpp
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <dialog_helpers.h>
#include <3d_viewer.h>
#include <pcbcommon.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include "footprint_wizard_frame.h"
#include <wildcards_and_files_ext.h>
#include <dialogs/dialog_footprint_wizard_list.h>
#define NEXT_PART 1
#define NEW_PART 0
#define PREVIOUS_PART -1
void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
{
wxString msg;
int page;
switch( event.GetId() )
{
case ID_FOOTPRINT_WIZARD_NEXT:
m_PageList->SetSelection(m_PageList->GetSelection()+1,true);
break;
case ID_FOOTPRINT_WIZARD_PREVIOUS:
page = m_PageList->GetSelection()-1;
if (page<0) page=0;
m_PageList->SetSelection(page,true);
break;
default:
msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
<< event.GetId();
wxMessageBox( msg );
break;
}
}
/* Function OnLeftClick
* Captures a left click event in the dialog
*
*/
void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{
}
/* Function OnRightClick
* Captures a right click event in the dialog
*
*/
bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
return true;
}
/* Displays the name of the current opened library in the caption */
void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
{
wxString msg;
msg = _( "Footprint Wizard" );
msg << wxT( " [" );
if( ! m_wizardName.IsEmpty() )
msg << m_wizardName;
else
msg += _( "no wizard selected" );
msg << wxT( "]" );
SetTitle( msg );
}
void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
{
SetCurItem( NULL );
// Delete the current footprint
GetBoard()->m_Modules.DeleteAll();
MODULE *m = m_FootprintWizard->GetModule();
if (m)
{
/* Here we should make a copy of the object before adding to board*/
m->SetParent((EDA_ITEM*)GetBoard());
GetBoard()->m_Modules.Append(m);
wxPoint p(0,0);
m->SetPosition(p);
}
else
{
printf ("m_FootprintWizard->GetModule() returns NULL\n");
}
m_canvas->Refresh();
}
void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
{
DIALOG_FOOTPRINT_WIZARD_LIST *selectWizard =
new DIALOG_FOOTPRINT_WIZARD_LIST(this);
selectWizard->ShowModal();
m_FootprintWizard = selectWizard->GetWizard();
if (m_FootprintWizard)
{
m_wizardName = m_FootprintWizard->GetName();
m_wizardDescription = m_FootprintWizard->GetDescription();
}
ReloadFootprint();
Zoom_Automatique(false);
DisplayWizardInfos();
ReCreatePageList();
ReCreateParameterList();
}
void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
{
SelectFootprintWizard();
}
/**
* Function SelectCurrentFootprint
* Selects the current footprint name and display it
*/
void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
{
int page = m_PageList->GetSelection();
if (page<0)
return;
int n=m_ParameterGrid->GetNumberRows();
wxArrayString arr;
for (int i=0;i<n;i++)
{
wxString val = m_ParameterGrid->GetCellValue(i,1);
arr.Add(val);
}
wxString res = m_FootprintWizard->SetParameterValues(page,arr);
ReloadFootprint();
DisplayWizardInfos();
}
/**
* Function RedrawActiveWindow
* Display the current selected component.
* If the component is an alias, the ROOT component is displayed
*
*/
void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
if( !GetBoard() )
return;
m_canvas->DrawBackGround( DC );
GetBoard()->Draw( m_canvas, DC, GR_COPY );
MODULE* module = GetBoard()->m_Modules;
if ( module )
module->DisplayInfo( this );
m_canvas->DrawCrossHair( DC );
ClearMsgPanel();
if( module )
module->DisplayInfo( this );
}
This diff is collapsed.
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es
* Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2012 KiCad Developers, see change_log.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
*/
/**
* @file footprint_wizard_frame.h
*/
#ifndef FOOTPRINT_WIZARD_FRAME_H_
#define FOOTPRINT_WIZARD_FRAME_H_
#include <wx/gdicmn.h>
#include <class_footprint_wizard.h>
class wxSashLayoutWindow;
class wxListBox;
class wxSemaphore;
class wxGrid;
class wxGridEvent;
/**
* Component library viewer main window.
*/
class FOOTPRINT_WIZARD_FRAME : public PCB_BASE_FRAME
{
private:
wxSashLayoutWindow* m_PageListWindow; //< List of libraries (for selection )
wxListBox* m_PageList; //< The list of pages
wxSize m_PageListSize; //< size of the window
wxSashLayoutWindow* m_ParameterGridWindow; //< List of components in the selected library
wxGrid* m_ParameterGrid; //< The list of parameters
wxSize m_ParameterGridSize; //< size of the window
// Flags
wxSemaphore* m_Semaphore; //< != NULL if the frame must emulate a modal dialog
wxString m_configPath; //< subpath for configuration
FOOTPRINT_WIZARD* m_FootprintWizard;
protected:
wxString m_wizardName; //< name of the current wizard
wxString m_wizardDescription; //< description of the wizard
wxString m_wizardStatus; //< current wizard status
public:
FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* semaphore = NULL );
~FOOTPRINT_WIZARD_FRAME();
MODULE* GetBuiltFootrint( void );
private:
void OnSize( wxSizeEvent& event );
/**
* Function OnSashDrag
* resizes the child windows when dragging a sash window border.
*/
void OnSashDrag( wxSashEvent& event );
/**
* Function ReCreatePageList
* Creates or recreates the list of parameter pages for the current wizard.
* This list is sorted
*/
void ReCreatePageList();
/**
* Function ReCreateParameterList
* Creates the list of parameters for the current page
*/
void ReCreateParameterList();
/**
* Function SelectFootprintWizard
* Shows the list of footprint wizards available into the system
*/
void SelectFootprintWizard();
/**
* Function ReloadFootprint
* Reloads the current footprint
*/
void ReloadFootprint();
void Process_Special_Functions( wxCommandEvent& event );
/**
* Function DisplayWizardInfos
* Shows all the details about the current wizard
*/
void DisplayWizardInfos();
void RedrawActiveWindow( wxDC* DC, bool EraseBg );
void OnCloseWindow( wxCloseEvent& Event );
void ReCreateHToolbar();
void ReCreateVToolbar();
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
void ClickOnPageList( wxCommandEvent& event );
void OnSetRelativeOffset( wxCommandEvent& event );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/**
* Function LoadSettings
* loads the library viewer frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void LoadSettings();
/**
* Function SaveSettings
* save library viewer frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void SaveSettings();
/**
* Function OnActivate
* is called when the frame frame is activate to reload the libraries and component lists
* that can be changed by the schematic editor or the library editor.
*/
virtual void OnActivate( wxActivateEvent& event );
void SelectCurrentWizard( wxCommandEvent& event );
void ParametersUpdated( wxGridEvent& event );
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
/**
* Function Show3D_Frame (virtual)
* displays 3D view of the footprint (module) being edited.
*/
void Show3D_Frame( wxCommandEvent& event );
/**
* Function Update3D_Frame
* must be called after a footprint selection
* Updates the 3D view and 3D frame title.
* @param aForceReloadFootprint = true to reload data (default)
* = false to update title only -(aftre creating the 3D viewer)
*/
void Update3D_Frame( bool aForceReloadFootprint = true );
/*
* Virtual functions, not used here, but needed by PCB_BASE_FRAME
* (virtual pure functions )
*/
void OnLeftDClick(wxDC*, const wxPoint&) {}
void SaveCopyInUndoList(BOARD_ITEM*, UNDO_REDO_T, const wxPoint&) {}
void SaveCopyInUndoList(PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint&) {}
DECLARE_EVENT_TABLE()
};
#endif // FOOTPRINT_WIZARD_FRM_H_
......@@ -29,6 +29,8 @@
#include <dialog_edit_module_for_Modedit.h>
#include <wildcards_and_files_ext.h>
#include <menus_helpers.h>
#include <footprint_wizard_frame.h>
// Functions defined in block_module_editor, but used here
// These 2 functions are used in modedit to rotate or mirror the whole footprint
......@@ -283,6 +285,36 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
}
break;
}
case ID_MODEDIT_NEW_MODULE_FROM_WIZARD:
{
Clear_Pcb( true );
GetScreen()->ClearUndoRedoList();
SetCurItem( NULL );
GetScreen()->SetCrossHairPosition( wxPoint( 0, 0 ) );
MODULE* module = NULL;
FOOTPRINT_WIZARD_FRAME *wizard = new FOOTPRINT_WIZARD_FRAME(this,NULL);
wizard->Show( true );
wizard->Zoom_Automatique( false );
if( module ) // i.e. if create module command not aborted
{
// Initialize data relative to nets and netclasses (for a new
// module the defaults are used)
// This is mandatory to handle and draw pads
GetBoard()->BuildListOfNets();
redraw = true;
module->SetPosition( wxPoint( 0, 0 ) );
if( GetBoard()->m_Modules )
GetBoard()->m_Modules->ClearFlags();
Zoom_Automatique( false );
}
break;
}
case ID_MODEDIT_SAVE_LIBMODULE:
if( GetBoard()->m_Modules == NULL )
......
......@@ -72,6 +72,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
EVT_TOOL( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_NEW_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_NEW_MODULE_FROM_WIZARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_LOAD_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_IMPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
......
......@@ -28,6 +28,9 @@
* @brief Pcbnew main program.
*/
#ifdef KICAD_SCRIPTING
#include <pcbnew_scripting_helpers.h>
#endif
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <confirm.h>
......@@ -46,7 +49,13 @@
#include <protos.h>
#include <hotkeys.h>
#include <wildcards_and_files_ext.h>
#include <class_board.h>
#include <dialogs/dialog_scripting.h>
#ifdef KICAD_SCRIPTING
#include <python_scripting.h>
#endif
// Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings;
......@@ -102,6 +111,11 @@ bool EDA_APP::OnInit()
wxFileName fn;
PCB_EDIT_FRAME* frame = NULL;
#ifdef KICAD_SCRIPTING
pcbnewInitPythonScripting();
#endif
InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T );
if( m_Checker && m_Checker->IsAnotherRunning() )
......@@ -136,6 +150,11 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) );
ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr );
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();
SetTopWindow( frame );
......
......@@ -302,6 +302,7 @@ enum pcbnew_ids
ID_MODEDIT_SAVE_LIBMODULE,
ID_MODEDIT_DELETE_PART,
ID_MODEDIT_NEW_MODULE,
ID_MODEDIT_NEW_MODULE_FROM_WIZARD,
ID_MODEDIT_SHEET_SET,
ID_MODEDIT_LOAD_MODULE,
ID_MODEDIT_PAD_SETTINGS,
......@@ -326,8 +327,21 @@ enum pcbnew_ids
ID_MODVIEW_PREVIOUS,
ID_MODVIEW_NEXT,
ID_MODVIEW_SHOW_3D_VIEW,
ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD
ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD,
ID_FOOTPRINT_WIZARD_WINDOW,
ID_FOOTPRINT_WIZARD_PAGES,
ID_FOOTPRINT_WIZARD_PARAMETERS,
ID_FOOTPRINT_WIZARD_NEXT,
ID_FOOTPRINT_WIZARD_PREVIOUS,
ID_FOOTPRINT_WIZARD_DONE,
ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW,
ID_FOOTPRINT_WIZARD_PAGE_LIST,
ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
ID_FOOTPRINT_WIZARD_PAGES_WINDOW,
ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW,
ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
ID_FOOTPRINT_WIZARD_EXPORT_TO_BOARD,
};
#endif /* __PCBNEW_IDS_H__ */
* finish wizard implementation
* cleanup
* better build script helpers
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file board.i
* @brief Specific BOARD extensions and templates
*/
%extend BOARD
{
%pythoncode
{
def GetModules(self): return self.m_Modules
def GetDrawings(self): return self.m_Drawings
def GetTracks(self): return self.m_Track
def GetSegZones(self): return self.m_Zone
def GetFullRatsnest(self): return self.m_FullRatsnest
def GetLocalRatsnest(self): return self.m_LocalRatsnest
def GetNetClasses(self): return self.m_NetClasses
def GetCurrentNetClassName(self): return self.m_CurrentNetClassName
def GetViasDimensionsList(self): return self.m_ViasDimensionsList
def GetTrackWidthList(self): return self.m_TrackWidthList
def Save(self,filename,format = None):
if format is None:
str_filename = str(filename)
if str_filename.endswith(".brd"):
format = IO_MGR.LEGACY
if str_filename.endswith(".kicad_brd"):
format = IO_MGR.KICAD
return SaveBoard(filename,self,format)
#
# add function, clears the thisown to avoid python from deleting
# the object in the garbage collector
#
def Add(self,item):
item.thisown=0
self.AddNative(item)
}
}
// this is to help python with the * accessor of DLIST templates
%rename(Get) operator BOARD_ITEM*;
%rename(Get) operator TRACK*;
%rename(Get) operator D_PAD*;
%rename(Get) operator MODULE*;
%rename(Get) operator SEGZONE*;
// we must translate C++ templates to scripting languages
%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(MODULE_List) DLIST<MODULE>;
%template(SEGZONE_List) DLIST<SEGZONE>;
%template(TRACK_List) DLIST<TRACK>;
%template(PAD_List) DLIST<D_PAD>;
// std::vector templates
%template(VIA_DIMENSION_Vector) std::vector<VIA_DIMENSION>;
%template (RASTNET_Vector) std::vector<RATSNEST_ITEM>;
%extend DRAWSEGMENT
{
%pythoncode
{
def GetShapeStr(self):
return self.ShowShape(self.GetShape())
}
}
%extend BOARD_ITEM
{
%pythoncode
{
def SetPos(self,p):
self.SetPosition(p)
self.SetPos0(p)
def SetStartEnd(self,start,end):
self.SetStart(start)
self.SetStart0(start)
self.SetEnd(end)
self.SetEnd0(end)
}
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file board_item.i
* @brief board_item helpers, mainly for casting down to all child classes
*/
/* Cast downs from EDA_ITEM/BOARD_ITEM to childs */
%inline
{
BOARD_ITEM* Cast_to_BOARD_ITEM(EDA_ITEM* base) { return dynamic_cast<BOARD_ITEM*>(base); }
}
%extend BOARD_ITEM
{
TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast<TEXTE_PCB*>(self); }
DIMENSION* Cast_to_DIMENSION() { return dynamic_cast<DIMENSION*>(self); }
MODULE* Cast_to_MODULE() { return dynamic_cast<MODULE*>(self); }
TEXTE_MODULE* Cast_to_TEXTE_MODULE(){ return dynamic_cast<TEXTE_MODULE*>(self); }
DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast<DRAWSEGMENT*>(self); }
MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast<MARKER_PCB*>(self); }
BOARD* Cast_to_BOARD() { return dynamic_cast<BOARD*>(self); }
EDGE_MODULE* Cast_to_EDGE_MODULE() { return dynamic_cast<EDGE_MODULE*>(self); }
D_PAD* Cast_to_D_PAD() { return dynamic_cast<D_PAD*>(self); }
TRACK* Cast_to_TRACK() { return dynamic_cast<TRACK*>(self); }
SEGZONE* Cast_to_SEGZONE() { return dynamic_cast<SEGZONE*>(self); }
SEGVIA* Cast_to_SEGVIA() { return dynamic_cast<SEGVIA*>(self); }
%pythoncode
{
def Cast(self):
ct = self.GetClass()
if ct=="PTEXT":
return self.Cast_to_TEXTE_PCB()
elif ct=="BOARD":
return self.Cast_to_BOARD()
elif ct=="DIMENSION":
return self.Cast_to_DIMENSION()
elif ct=="DRAWSEGMENT":
return self.Cast_to_DRAWSEGMENT()
elif ct=="MGRAPHIC":
return self.Cast_to_EDGE_MODULE()
elif ct=="MODULE":
return self.Cast_to_MODULE()
elif ct=="PAD":
return self.Cast_to_D_PAD()
elif ct=="MTEXT":
return self.Cast_to_TEXTE_MODULE()
elif ct=="ZONE":
return self.Cast_to_SEGZONE()
elif ct=="VIA":
return self.Cast_to_SEGVIA()
elif ct=="TRACK":
return self.Cast_to_TRACK()
else:
return None
}
}
#!/usr/bin/env python2.7
from pcbnew import *
size_025_160mm = wxSizeMM(0.25,1.6)
size_150_200mm = wxSizeMM(1.50,2.0)
pads = 40
# create a blank board
pcb = BOARD()
pcb.m_NetClasses.GetDefault().SetClearance(FromMM(0.1))
# create a new module, it's parent is our previously created pcb
module = MODULE(pcb)
module.SetReference("FPC"+str(pads)) # give it a reference name
module.m_Reference.SetPos0(wxPointMM(-1,-1))
pcb.Add(module) # add it to our pcb
m_pos = wxPointMM(50,50)
module.SetPosition(m_pos)
# create a pad array and add it to the module
def smdRectPad(module,size,pos,name):
pad = D_PAD(module)
pad.SetSize(size)
pad.SetShape(PAD_RECT)
pad.SetAttribute(PAD_SMD)
pad.SetLayerMask(PAD_SMD_DEFAULT_LAYERS)
pad.SetPos0(pos)
pad.SetPadName(name)
return pad
for n in range (0,pads):
pad = smdRectPad(module,size_025_160mm,wxPointMM(0.5*n,0),str(n+1))
module.Add(pad)
pad_s0 = smdRectPad(module,size_150_200mm,wxPointMM(-1.6,1.3),"0")
pad_s1 = smdRectPad(module,size_150_200mm,wxPointMM((pads-1)*0.5+1.6,1.3),"0")
module.Add(pad_s0)
module.Add(pad_s1)
e = EDGE_MODULE(module)
e.SetStart0(wxPointMM(-1,0))
e.SetEnd0(wxPointMM(0,0))
e.SetWidth(FromMM(0.2))
e.SetLayer(EDGE_LAYER)
e.SetShape(S_SEGMENT)
module.Add(e)
# save the PCB to disk
module.SetLibRef("FPC"+str(pads))
try:
FootprintLibCreate("fpc.mod")
except:
pass # we try to create, but may be it exists already
FootprintSave("fpc40.mod",module)
#!/usr/bin/env python2.7
from pcbnew import *
size_0_6mm = wxSizeMM(0.6,0.6)
size_1_0mm = wxSizeMM(1.0,1.0)
# create a blank board
pcb = BOARD()
pcb.m_NetClasses.GetDefault().SetClearance(FromMM(0.1))
# create a new module, it's parent is our previously created pcb
module = MODULE(pcb)
module.SetReference("M1") # give it a reference name
module.m_Reference.SetPos0(wxPointMM(-10,-10))
pcb.Add(module) # add it to our pcb
m_pos = wxPointMM(50,50)
module.SetPosition(m_pos)
# create a pad array and add it to the module
n = 1
for y in range (0,10):
for x in range (0,10):
pad = D_PAD(module)
pad.SetDrillSize(size_0_6mm)
pad.SetSize(size_1_0mm)
pt = wxPointMM(1.27*x,1.27*y)
pad.SetPos0(pt);
#pad.SetPosition(pt)
pad.SetPadName(str(n))
module.Add(pad)
n+=1
# save the PCB to disk
pcb.Save("/tmp/my2.kicad_brd")
pcb.Save("/tmp/my2.brd")
pcb = LoadBoard("/tmp/my2.brd")
print map( lambda x: x.GetReference() , list(pcb.GetModules()))
for m in pcb.GetModules():
for p in m.GetPads():
print p.GetPadName(),p.GetPosition(), p.GetOffset()
# pcb.GetDesignSettings()
#!/usr/bin/env python
import sys
from pcbnew import *
filename=sys.argv[1]
pcb = LoadBoard(filename)
for module in pcb.GetModules():
print "* Module: %s"%module.GetReference()
module.GetValueObj().SetVisible(False) # set Value as Hidden
module.GetReferenceObj().SetVisible(True) # set Reference as Visible
pcb.Save("mod_"+filename)
\ No newline at end of file
#!/usr/bin/env python
import sys
from pcbnew import *
filename=sys.argv[1]
pcb = LoadBoard(filename)
#ToUnits = ToMM
#FromUnits = FromMM
ToUnits=ToMils
FromUnits=FromMils
print "LISTING VIAS:"
for item in pcb.GetTracks():
if type(item) is SEGVIA:
pos = item.GetPosition()
drill = item.GetDrillValue()
width = item.GetWidth()
print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width))
elif type(item) is TRACK:
start = item.GetStart()
end = item.GetEnd()
width = item.GetWidth()
print " * Track: %s to %s, width %f" % (ToUnits(start),ToUnits(end),ToUnits(width))
else:
print "Unknown type %s" % type(item)
print ""
print "LISTING DRAWINGS:"
for item in pcb.GetDrawings():
if type(item) is TEXTE_PCB:
print "* Text: '%s' at %s"%(item.GetText(),item.GetPosition())
elif type(item) is DRAWSEGMENT:
print "* Drawing: %s"%item.GetShapeStr() # dir(item)
else:
print type(item)
print ""
print "LIST MODULES:"
for module in pcb.GetModules():
print "* Module: %s at %s"%(module.GetReference(),ToUnits(module.GetPosition()))
print ""
print "LIST ZONES:"
for zone in pcb.GetSegZones():
print zone
print ""
print "RATSNEST:",len(pcb.GetFullRatsnest())
print dir(pcb.GetNetClasses())
\ No newline at end of file
#!/usr/bin/env python
from pcbnew import *
lst = FootprintEnumerate("/usr/share/kicad/modules/sockets.mod")
for name in lst:
m = FootprintLoad("/usr/share/kicad/modules/sockets.mod",name)
print name,"->",m.GetLibRef(), m.GetReference()
for p in m.GetPads():
print "\t",p.GetPadName(),p.GetPosition(),p.GetPos0(), p.GetOffset()
\ No newline at end of file
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file module.i
* @brief Specific BOARD extensions and templates
*/
%extend MODULE
{
%pythoncode
{
def GetPads(self): return self.m_Pads
def GetDrawings(self): return self.m_Drawings
def GetReferenceObj(self): return self.m_Reference
def GetValueObj(self): return self.m_Value
#def SaveToLibrary(self,filename):
# return SaveModuleToLibrary(filename,self)
#
# add function, clears the thisown to avoid python from deleting
# the object in the garbage collector
#
def Add(self,item):
itemC = item.Cast()
if type(itemC) is D_PAD:
item.thisown=0
self.m_Pads.PushBack(itemC)
elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT,EDGE_MODULE]:
item.thisown = 0
self.m_Drawings.PushBack(item)
}
}
%pythoncode
{
def GetPluginForPath(lpath):
return IO_MGR.PluginFind(IO_MGR.LEGACY)
def FootprintEnumerate(lpath):
plug = GetPluginForPath(lpath)
return plug.FootprintEnumerate(lpath)
def FootprintLoad(lpath,name):
plug = GetPluginForPath(lpath)
return plug.FootprintLoad(lpath,name)
def FootprintSave(lpath,module):
plug = GetPluginForPath(lpath)
return plug.FootprintSave(lpath,module)
def FootprintDelete(lpath,name):
plug = GetPluginForPath(lpath)
plug.FootprintDelete(lpath,name)
def FootprintLibCreate(lpath):
plug = GetPluginForPath(lpath)
plug.FootprintLibCreate(lpath)
def FootprintLibDelete(lpath):
plug = GetPluginForPath(lpath)
plug.FootprintLibDelete(lpath)
def FootprintIsWritable(lpath):
plug = GetPluginForPath(lpath)
plug.FootprintLibIsWritable(lpath)
}
%{
MODULE *PyModule_to_MODULE(PyObject *obj0)
{
void *argp;
int res1 = SWIG_ConvertPtr(obj0, &argp,SWIGTYPE_p_MODULE, 0 | 0 );
if (!SWIG_IsOK(res1))
{
SWIG_exception_fail(SWIG_ArgError(res1), "Converting object to MODULE*");
}
return (MODULE*)argp;
fail:
return NULL;
}
%}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file pcbnew.i
* @brief Specific pcbnew wrappers
*/
%module pcbnew
%feature("autodoc", "1");
%include "kicad.i"
// ignore a couple of items that generate warnings from swig built code
%ignore BOARD_ITEM::ZeroOffset;
%ignore D_PAD::m_PadSketchModePenSize;
// rename the Add method of classes to Add native, so we will handle
// the Add method in python
%rename(AddNative) *::Add;
%exception {
try{
$action
}
catch( IO_ERROR e )
{
char ExceptionError[256];
sprintf(ExceptionError, "%s\n", TO_UTF8(e.errorText) );
PyErr_SetString(PyExc_IOError,ExceptionError);
return NULL;
}
catch( ... )
{
SWIG_fail;
}
}
%include exception.i
// this is what it must be included in the wrapper .cxx code to compile
%{
#include <wx_python_helpers.h>
#include <class_board_item.h>
#include <class_board_connected_item.h>
#include <class_board_design_settings.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <layers_id_colors_and_visibility.h>
#include <class_pad.h>
#include <pad_shapes.h>
#include <class_netinfo.h>
#include <class_pcb_text.h>
#include <class_dimension.h>
#include <class_drawsegment.h>
#include <class_marker_pcb.h>
#include <class_text_mod.h>
#include <class_edge_mod.h>
#include <dlist.h>
#include <class_zone_settings.h>
#include <class_netclass.h>
#include <class_netinfo.h>
#include <pcbnew_scripting_helpers.h>
BOARD *GetBoard(); /* get current editor board */
%}
%{
#include <io_mgr.h>
#include <kicad_plugin.h>
%}
%include <class_board_item.h>
%include <class_board_connected_item.h>
%include <class_board_design_settings.h>
%include <class_board.h>
%include <class_module.h>
%include <class_track.h>
%include <layers_id_colors_and_visibility.h>
%include <class_pad.h>
%include <pad_shapes.h>
%include <class_netinfo.h>
%include <class_pcb_text.h>
%include <class_dimension.h>
%include <class_drawsegment.h>
%include <class_marker_pcb.h>
%include <class_text_mod.h>
%include <class_edge_mod.h>
%include <dlist.h>
%include <class_zone_settings.h>
%include <class_netclass.h>
%include <class_netinfo.h>
%include "board_item.i"
%include <pcbnew_scripting_helpers.h>
// ignore RELEASER as nested classes are still unsupported by swig
%ignore IO_MGR::RELEASER;
%include <io_mgr.h>
%include <kicad_plugin.h>
%include "board.i"
%include "module.i"
%include "plugins.i"
%include "units.i"
\ No newline at end of file
/**
* @file pcbnew_footprint_wizards.cpp
* @brief Class PCBNEW_PYTHON_FOOTPRINT_WIZARDS
*/
#include "pcbnew_footprint_wizards.h"
#include <stdio.h>
PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD(PyObject *aWizard)
{
this->m_PyWizard= aWizard;
Py_XINCREF(aWizard);
}
PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD()
{
Py_XDECREF(this->m_PyWizard);
}
PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod(const char* aMethod, PyObject *aArglist)
{
PyObject *pFunc;
/* pFunc is a new reference to the desired method */
pFunc = PyObject_GetAttrString(this->m_PyWizard, aMethod);
if (pFunc && PyCallable_Check(pFunc))
{
PyObject *result;
result = PyObject_CallObject(pFunc, aArglist);
if (PyErr_Occurred())
{
PyObject *t, *v, *b;
PyErr_Fetch(&t, &v, &b);
printf ("calling %s()\n",aMethod);
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v)));
printf (" : %s\n",PyString_AsString(PyObject_Str(b)));
}
if (result)
{
Py_XDECREF(pFunc);
return result;
}
}
else
{
printf("method not found, or not callable: %s\n",aMethod);
}
if (pFunc) Py_XDECREF(pFunc);
return NULL;
}
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod(const char* aMethod, PyObject *aArglist)
{
wxString ret;
ret.Clear();
PyObject *result = CallMethod(aMethod,aArglist);
if (result)
{
const char *str_res = PyString_AsString(result);
ret = wxString::FromUTF8(str_res);
Py_DECREF(result);
}
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod
(const char *aMethod, PyObject *aArglist)
{
PyObject *result, *element;
wxArrayString ret;
wxString str_item;
result = CallMethod(aMethod,aArglist);
if (result)
{
if (!PyList_Check(result))
{
Py_DECREF(result);
ret.Add(wxT("PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, "
"result is not a list"),1);
return ret;
}
int list_size = PyList_Size(result);
for (int n=0;n<list_size;n++)
{
element = PyList_GetItem(result,n);
const char *str_res = PyString_AsString(element);
str_item = wxString::FromUTF8(str_res);
ret.Add(str_item,1);
}
Py_DECREF(result);
}
return ret;
}
wxString PYTHON_FOOTPRINT_WIZARD::GetName()
{
return CallRetStrMethod("GetName");
}
wxString PYTHON_FOOTPRINT_WIZARD::GetImage()
{
return CallRetStrMethod("GetImage");
}
wxString PYTHON_FOOTPRINT_WIZARD::GetDescription()
{
return CallRetStrMethod("GetDescription");
}
int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages()
{
int ret;
PyObject *result;
/* Time to call the callback */
result = CallMethod("GetNumParameterPages",NULL);
if (result)
{
if (!PyInt_Check(result)) return -1;
ret = PyInt_AsLong(result);
Py_DECREF(result);
}
return ret;
}
wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName(int aPage)
{
wxString ret;
PyObject *arglist;
PyObject *result;
/* Time to call the callback */
arglist = Py_BuildValue("(i)", aPage);
result = CallMethod("GetParameterPageName",arglist);
Py_DECREF(arglist);
if (result)
{
const char *str_res = PyString_AsString(result);
ret = wxString::FromUTF8(str_res);
Py_DECREF(result);
}
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage)
{
PyObject *arglist;
wxArrayString ret;
arglist = Py_BuildValue("(i)", aPage);
ret = CallRetArrayStrMethod("GetParameterNames",arglist);
Py_DECREF(arglist);
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)
{
PyObject *arglist;
wxArrayString ret;
arglist = Py_BuildValue("(i)", aPage);
ret = CallRetArrayStrMethod("GetParameterValues",arglist);
Py_DECREF(arglist);
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors(int aPage)
{
PyObject *arglist;
wxArrayString ret;
arglist = Py_BuildValue("(i)", aPage);
ret = CallRetArrayStrMethod("GetParameterErrors",arglist);
Py_DECREF(arglist);
return ret;
}
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues(int aPage,wxArrayString& aValues)
{
int len = aValues.size();
PyObject *py_list;
py_list = PyList_New(len);
for (int i=0;i<len;i++)
{
wxString str = aValues[i];
PyObject *py_str = PyString_FromString((const char*)str.mb_str());
PyList_SetItem(py_list, i, py_str);
}
PyObject *arglist;
arglist = Py_BuildValue("(i,O)", aPage,py_list);
wxString res = CallRetStrMethod("SetParameterValues",arglist);
Py_DECREF(arglist);
return res;
}
/* this is a SWIG function declaration -from module.i*/
MODULE *PyModule_to_MODULE(PyObject *obj0);
MODULE *PYTHON_FOOTPRINT_WIZARD::GetModule()
{
PyObject *result, *obj;
result = CallMethod("GetModule",NULL);
if (!result) return NULL;
obj = PyObject_GetAttrString(result, "this");
if (PyErr_Occurred())
{
/*
PyObject *t, *v, *b;
PyErr_Fetch(&t, &v, &b);
printf ("calling GetModule()\n");
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v)));
printf (" : %s\n",PyString_AsString(PyObject_Str(b)));
*/
PyErr_Print();
}
return PyModule_to_MODULE(obj);
}
void PYTHON_FOOTPRINT_WIZARDS::register_wizard(PyObject* aPyWizard)
{
PYTHON_FOOTPRINT_WIZARD *fw;
fw = new PYTHON_FOOTPRINT_WIZARD(aPyWizard);
printf("Registered python footprint wizard '%s'\n",
(const char*)fw->GetName().mb_str()
);
// this get the wizard registered in the common
// FOOTPRINT_WIZARDS class
fw->register_wizard();
#if 0
/* just to test if it works correctly */
int pages = fw->GetNumParameterPages();
printf(" %d pages\n",pages);
for (int n=0; n<pages; n++)
{
printf(" page %d->'%s'\n",n,
(const char*)fw->GetParameterPageName(n).mb_str());
}
#endif
}
/**
* @file pcbnew_footprint_wizards.h
* @brief Class PCBNEW_FOOTPRINT_WIZARDS
*/
#ifndef PCBNEW_FOOTPRINT_WIZARDS_H
#define PCBNEW_FOOTPRINT_WIZARDS_H
#include <Python.h>
#include <vector>
#include <class_footprint_wizard.h>
class PYTHON_FOOTPRINT_WIZARD: public FOOTPRINT_WIZARD
{
PyObject *m_PyWizard;
PyObject *CallMethod(const char *aMethod, PyObject *aArglist=NULL);
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL);
wxArrayString CallRetArrayStrMethod(const char *aMethod,
PyObject *aArglist=NULL);
public:
PYTHON_FOOTPRINT_WIZARD(PyObject *wizard);
~PYTHON_FOOTPRINT_WIZARD();
wxString GetName();
wxString GetImage();
wxString GetDescription();
int GetNumParameterPages();
wxString GetParameterPageName(int aPage);
wxArrayString GetParameterNames(int aPage);
wxArrayString GetParameterValues(int aPage);
wxArrayString GetParameterErrors(int aPage);
wxString SetParameterValues(int aPage,wxArrayString& aValues); //< must return "OK" or error description
MODULE *GetModule();
};
class PYTHON_FOOTPRINT_WIZARDS
{
public:
static void register_wizard(PyObject *aPyWizard);
};
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file pcbnew_scripting_helpers.cpp
* @brief Scripting helper functions for pcbnew functionality
*/
#include <Python.h>
#include <pcbnew_scripting_helpers.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <build_version.h>
#include <class_board.h>
#include <kicad_string.h>
#include <io_mgr.h>
#include <macros.h>
#include <stdlib.h>
static PCB_EDIT_FRAME *PcbEditFrame=NULL;
BOARD *GetBoard()
{
if (PcbEditFrame) return PcbEditFrame->GetBoard();
else return NULL;
}
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame)
{
PcbEditFrame = aPCBEdaFrame;
}
BOARD* LoadBoard(wxString& aFileName)
{
if (aFileName.EndsWith(wxT(".kicad_brd")))
return LoadBoard(aFileName,IO_MGR::KICAD);
else if (aFileName.EndsWith(wxT(".brd")))
return LoadBoard(aFileName,IO_MGR::LEGACY);
// as fall back for any other kind use the legacy format
return LoadBoard(aFileName,IO_MGR::LEGACY);
}
BOARD* LoadBoard(wxString& aFileName,IO_MGR::PCB_FILE_T aFormat)
{
return IO_MGR::Load(aFormat,aFileName);
}
bool SaveBoard(wxString& aFilename, BOARD* aBoard)
{
return SaveBoard(aFilename,aBoard,IO_MGR::KICAD);
}
bool SaveBoard(wxString& aFileName, BOARD* aBoard,
IO_MGR::PCB_FILE_T aFormat)
{
aBoard->m_Status_Pcb &= ~CONNEXION_OK;
aBoard->SynchronizeNetsAndNetClasses();
aBoard->SetCurrentNetClass( aBoard->m_NetClasses.GetDefault()->GetName() );
wxString header;
PROPERTIES props;
if (aFormat==IO_MGR::LEGACY)
{
header = wxString::Format(
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s scripting\n\n" ),
LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
GetBuildVersion().GetData() );
props["header"] = header;
}
IO_MGR::Save( aFormat, aFileName, aBoard, &props );
return true;
}
#ifndef __PCBNEW_SCRIPTING_HELPERS_H
#define __PCBNEW_SCRIPTING_HELPERS_H
#include <wxPcbStruct.h>
#include <io_mgr.h>
/* we could be including all these methods as static in a class, but
* we want plain pcbnew.<method_name> access from python */
#ifndef SWIG
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame);
#endif
BOARD *GetBoard();
BOARD* LoadBoard(wxString& aFileName, IO_MGR::PCB_FILE_T aFormat);
BOARD* LoadBoard(wxString& aFileName);
bool SaveBoard(wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat);
bool SaveBoard(wxString& aFileName, BOARD* aBoard);
#endif
\ No newline at end of file
%{
#include <scripting/pcbnew_footprint_wizards.h>
%}
class PYTHON_FOOTPRINT_WIZARDS
{
public:
static void register_wizard(PyObject *wizard);
};
#!/usr/bin/python
from pcbnew import *
class FPCFootprintWizard(FootprintWizardPlugin):
def __init__(self):
FootprintWizardPlugin.__init__(self)
self.name = "FPC"
self.description = "FPC Footprint Wizard"
self.parameters = {
"Pads":
{"n":40,"pitch":FromMM(0.5),
"width":FromMM(0.25),"height":FromMM(1.6)},
"Shield":
{"shield_to_pad":FromMM(1.6),"from_top":FromMM(1.3),
"width":FromMM(1.5),"height":FromMM(2)},
}
self.ClearErrors()
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
values = self.parameters[name].values()
str_values = map( lambda x: str(x) , values)
print values,str_values
return str_values
def smdRectPad(self,module,size,pos,name):
pad = D_PAD(module)
# print "smdRectPad( size=",size,"pos=",pos,"name=",name,")"
pad.SetSize(size)
pad.SetShape(PAD_RECT)
pad.SetAttribute(PAD_SMD)
pad.SetLayerMask(PAD_SMD_DEFAULT_LAYERS)
pad.SetPos0(pos)
pad.SetPosition(pos)
pad.SetPadName(name)
return pad
def CheckParameters(self):
p = self.parameters
pads = p["Pads"]["n"]
errors = ""
if (pads<1):
self.parameter_errors["Pads"]["n"]="Must be positive"
errors +="Pads/n has wrong value, "
p["Pads"]["n"] = int(pads) # make sure it stays as int (default is float)
pad_width = p["Pads"]["width"]
pad_height = p["Pads"]["height"]
pad_pitch = p["Pads"]["pitch"]
shl_width = p["Shield"]["width"]
shl_height = p["Shield"]["height"]
shl_to_pad = p["Shield"]["shield_to_pad"]
shl_from_top = p["Shield"]["from_top"]
return errors
def SetParameterValues(self,page,values):
print "SetParameterValues("+str(page)+","+str(values)+")"
FootprintWizardPlugin.SetParameterValues(self,page,values)
def BuildFootprint(self):
print "parameters:",self.parameters
#self.ClearErrors()
#print "errors:",self.parameter_errors
module = MODULE(None) # create a new module
self.module = module
p = self.parameters
pads = int(p["Pads"]["n"])
pad_width = p["Pads"]["width"]
pad_height = p["Pads"]["height"]
pad_pitch = p["Pads"]["pitch"]
shl_width = p["Shield"]["width"]
shl_height = p["Shield"]["height"]
shl_to_pad = p["Shield"]["shield_to_pad"]
shl_from_top = p["Shield"]["from_top"]
size_pad = wxSize(pad_width,pad_height)
size_shld = wxSize(shl_width,shl_height)
module.SetReference("FPC"+str(pads)) # give it a reference name
module.m_Reference.SetPos0(wxPointMM(-1,-2))
module.m_Reference.SetPosition(wxPointMM(-1,-2))
# create a pad array and add it to the module
for n in range (0,pads):
pad = self.smdRectPad(module,size_pad,wxPoint(pad_pitch*n,0),str(n+1))
module.Add(pad)
pad_s0 = self.smdRectPad(module,
size_shld,
wxPoint(-shl_to_pad,shl_from_top),
"0")
pad_s1 = self.smdRectPad(module,
size_shld,
wxPoint((pads-1)*pad_pitch+shl_to_pad,shl_from_top),
"0")
module.Add(pad_s0)
module.Add(pad_s1)
e = EDGE_MODULE(module)
e.SetStartEnd(wxPointMM(-1,0),wxPointMM(0,0))
e.SetWidth(FromMM(0.2))
e.SetLayer(EDGE_LAYER)
e.SetShape(S_SEGMENT)
module.Add(e)
module.SetLibRef("FPC"+str(pads))
# create our footprint wizard
fpc_wizard = FPCFootprintWizard()
# register it into pcbnew
fpc_wizard.register()
pcb = pcbnew.GetBoard()
m = pcb.m_Modules
while m:
print m.GetPosition()
p = m.m_Pads
while p:
print "p=>",p.GetPosition(),p.GetPadName()
print p.GetPosition()
p = p.Next()
m = m.Next()
pcb = pcbnew.GetBoard()
m = pcb.m_Modules.item()
while m:
print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition()
m.SetValue("pepe")
p = m.m_Pads.item()
while p:
print " pad",p.GetPadName(), "at",p.GetPosition()
p = p.Next()
m = m.Next()
from pcbnew import *
import unittest
class TestLoadSave(unittest.TestCase):
def setUp(self):
self.TITLE="Test Board"
self.COMMENT1="For load/save test"
self.FILENAME="/tmp/test.brd"
def test_00_save(self):
pcb = BOARD()
pcb.GetTitleBlock().SetTitle(self.TITLE)
pcb.GetTitleBlock().SetComment1(self.COMMENT1)
result = SaveBoard(self.FILENAME,pcb)
self.assertTrue(result)
def test_01_load(self):
pcb2 = LoadBoard(self.FILENAME)
self.assertIsNotNone(pcb2)
def test_02_titleblock_ok(self):
pcb2 = LoadBoard(self.FILENAME)
tb = pcb2.GetTitleBlock()
self.assertEqual(tb.GetTitle(),self.TITLE)
self.assertEqual(tb.GetComment1(),self.COMMENT1)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file units.i
* @brief unit conversion code
*/
// Unit conversion, must be conditionally adapter to the new
// nanometer mode that will be soon included in pcbnew
%pythoncode
{
def ToMM(iu):
if type(iu) in [int,float]:
return float(iu) / float(IU_PER_MM)
elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMM,iu))
def FromMM(mm):
if type(mm) in [int,float]:
return int(float(mm) * float(IU_PER_MM))
elif type(mm) in [wxPoint,wxSize]:
return tuple(map(FromMM,mm))
def ToMils(iu):
if type(iu) in [int,float]:
return float(iu) / float(IU_PER_MILS)
elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMils,iu))
def FromMils(mils):
if type(mils) in [int,float]:
return int(float(mils)*float(IU_PER_MILS))
elif type(mils) in [wxPoint,wxSize]:
return tuple(map(FromMils,mils))
def wxSizeMM(mmx,mmy): return wxSize(FromMM(mmx),FromMM(mmy))
def wxSizeMils(mmx,mmy): return wxSize(FromMils(mmx),FromMils(mmy))
def wxPointMM(mmx,mmy): return wxPoint(FromMM(mmx),FromMM(mmy))
def wxPointMils(mmx,mmy): return wxPoint(FromMils(mmx),FromMils(mmy))
def wxRectMM(x,y,wx,wy):
x = int(FromMM(x))
y = int(FromMM(y))
wx = int(FromMM(wx))
wy = int (FromMM(wy))
return wxRect(x,y,wx,wy)
def wxRectMils(x,y,wx,wy):
x = int(FromMils(x))
y = int(FromMils(y))
wx = int(FromMils(wx))
wy = int (FromMils(wy))
return wxRect(x,y,wx,wy)
}
......@@ -77,6 +77,12 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_MODEDIT_NEW_MODULE, wxEmptyString, KiBitmap( new_footprint_xpm ),
_( "New module" ) );
m_mainToolBar->AddTool( ID_MODEDIT_NEW_MODULE_FROM_WIZARD, wxEmptyString,
KiBitmap( module_wizard_xpm ),
_( "New module from footprint wizard" ) );
m_mainToolBar->AddTool( ID_MODEDIT_LOAD_MODULE, wxEmptyString,
KiBitmap( load_module_lib_xpm ),
......
/* DLIST python iteration code, to allow standard iteration over DLIST */
%extend DLIST
{
%pythoncode
{
class DLISTIter:
def __init__(self,aList):
self.last = aList # last item is the start of list
def next(self): # get the next item
item = self.last
try:
item = item.Get()
except:
pass
if item is None: # if the item is None, then finish the iteration
raise StopIteration
else:
ret = None
# first item in list has "Get" as a DLIST
try:
ret = self.last.Get()
except:
ret = self.last # next items do not..
self.last = self.last.Next()
# when the iterated object can be casted down in inheritance, just do it..
if 'Cast' in dir(ret):
ret = ret.Cast()
return ret
def __iter__(self):
return self.DLISTIter(self)
}
}
#!/usr/bin/env python2
# the purpose of this script is rewriting the swig_import_helper
# call so it will not load _xxxxx.so/dso from inside a kicad executable
# because the kicad executable itself sill provide an _xxxxx module
# that's linked inside itself.
#
# for the normal module import it should work the same way with this
# fix in the swig_import_helper
#
from sys import argv,exit
if len(argv)<2:
print "usage:"
print " fixswigimports.py file.py"
print ""
print " will fix the swig import code for working inside KiCad"
print " where it happended that the external _pcbnew.so/dll was"
print " loaded too -and the internal _pcbnew module was to be used"
exit(1)
filename = argv[1]
f = open(filename,"rb")
lines = f.readlines()
f.close()
doneOk = False
if (len(lines)<4000):
print "still building"
exit(0)
txt = ""
for l in lines:
if l.startswith("if version_info >= (2,6,0):"):
l = l.replace("version_info >= (2,6,0)","False")
doneOk = True
elif l.startswith("if False:"): # it was already patched?
doneOk = True
txt = txt + l
f = open(filename,"wb")
f.write(txt)
f.close()
if doneOk:
print "swig_import_helper fixed for",filename
else:
print "Error: the swig import helper was not fixed, check",filename
print " and fix this script: fixswigimports.py"
exit(2)
exit(0)
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* @file kicad.i
* @brief General wrappers for kicad / wx structures and classes
*/
%include <std_vector.i>
%include <std_string.i>
/* ignore some constructors of EDA_ITEM that will make the build fail */
%nodefaultctor EDA_ITEM;
%ignore EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
%ignore EDA_ITEM::EDA_ITEM( KICAD_T idType );
%ignore EDA_ITEM::EDA_ITEM( const EDA_ITEM& base );
/* swig tries to wrap SetBack/SetNext on derived classes, but this method is
private for most childs, so if we don't ignore it won't compile */
%ignore EDA_ITEM::SetBack;
%ignore EDA_ITEM::SetNext;
/* ignore other functions that cause trouble */
%ignore InitKiCadAbout;
%ignore GetCommandOptions;
%rename(getWxRect) operator wxRect;
%ignore operator <<;
%ignore operator=;
/* headers/imports that must be included in the _wrapper.cpp at top */
%{
#include <cstddef>
#include <dlist.h>
#include <base_struct.h>
#include <common.h>
#include <wx_python_helpers.h>
#include <cstddef>
#include <vector>
using namespace std;
#include <class_title_block.h>
#include <class_colors_design_settings.h>
#include <class_marker_base.h>
#include <eda_text.h>
#include <convert_from_iu.h>
#include <convert_to_biu.h>
%}
/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */
%include <wx.i>
/* exception handling */
/* the IO_ERROR exception handler, not working yet... */
/*
%exception
{
try {
$function
}
catch (IO_ERROR e) {
PyErr_SetString(PyExc_IOError,"IO error");
return NULL;
}
}
*/
/* header files that must be wrapped */
%include <dlist.h>
%include <base_struct.h>
%include <common.h>
%include <class_title_block.h>
%include <class_colors_design_settings.h>
%include <class_marker_base.h>
%include <eda_text.h>
%include <convert_from_iu.h>
%include <convert_to_biu.h>
/* special iteration wrapper for DLIST objects */
%include "dlist.i"
/* std template mappings */
%template(intVector) std::vector<int>;
/* KiCad plugin handling */
%include "kicadplugins.i"
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
* Copyright (C) 1992-2012 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
*/
/**
* This file builds the base classes for all kind of python plugins that
* can be included into kicad.
* they provide generic code to all the classes:
*
* KiCadPlugin
* /|\
* |
* |\-FilePlugin
* |\-FootprintWizardPlugin
* |\-ActionPlugin
*
* It defines the LoadPlugins() function that loads all the plugins
* available in the system
*
*/
%pythoncode
{
def LoadPlugins():
import os
import sys
plugins_dir = os.environ['HOME']+'/.kicad_plugins/'
sys.path.append(plugins_dir)
for module in os.listdir(plugins_dir):
if os.path.isdir(plugins_dir+module):
__import__(module, locals(), globals())
if module == '__init__.py' or module[-3:] != '.py':
continue
__import__(module[:-3], locals(), globals())
# KiCadPlugin base class will register any plugin into the right place
class KiCadPlugin:
def __init__(self):
pass
def register(self):
if isinstance(self,FilePlugin):
pass # register to file plugins in C++
if isinstance(self,FootprintWizardPlugin):
PYTHON_FOOTPRINT_WIZARDS.register_wizard(self)
return
if isinstance(self,ActionPlugin):
pass # register to action plugins in C++
return
# This will be the file io scripting based plugins class
class FilePlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
# Scriping footprint wizards
class FootprintWizardPlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
self.defaults()
def defaults(self):
self.module = None
self.parameters = {}
self.parameter_errors={}
self.name = "Undefined Footprint Wizard plugin"
self.description = ""
self.image = ""
def GetName(self):
return self.name
def GetImage(self):
return self.image
def GetDescription(self):
return self.description
def GetNumParameterPages(self):
return len(self.parameters)
def GetParameterPageName(self,page_n):
return self.parameters.keys()[page_n]
def GetParameterNames(self,page_n):
name = self.GetParameterPageName(page_n)
return self.parameters[name].keys()
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
values = self.parameters[name].values()
return map( lambda x: str(x) , values) # list elements as strings
def GetParameterErrors(self,page_n):
self.CheckParameters()
name = self.GetParameterPageName(page_n)
values = self.parameter_errors[name].values()
return map( lambda x: str(x) , values) # list elements as strings
def CheckParameters(self):
return ""
def TryConvertToFloat(self,value):
v = value
try:
v = float(value)
except:
pass
return v
def SetParameterValues(self,page_n,values):
name = self.GetParameterPageName(page_n)
keys = self.parameters[name].keys()
n=0
for key in keys:
val = self.TryConvertToFloat(values[n])
self.parameters[name][key] = val
print "[%s][%s]<="%(name,key),val
n+=1
# copies the parameter list on parameter_errors but empty
def ClearErrors(self):
errs={}
for page in self.parameters.keys():
page_dict = self.parameters[page]
page_params = {}
for param in page_dict.keys():
page_params[param]=""
errs[page]=page_params
self.parameter_errors = errs
def GetModule(self):
self.BuildFootprint()
return self.module
def BuildFootprint(self):
return
def Show(self):
print "Footprint Wizard Name: ",self.GetName()
print "Footprint Wizard Description: ",self.GetDescription()
n_pages = self.GetNumParameterPages()
print " setup pages: ",n_pages
for page in range(0,n_pages):
name = self.GetParameterPageName(page)
values = self.GetParameterValues(page)
names = self.GetParameterNames(page)
print "page %d) %s"%(page,name)
for n in range (0,len(values)):
print "\t%s\t:\t%s"%(names[n],values[n])
class ActionPlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
}
This diff is collapsed.
#ifndef __PYTHON_SCRIPTING_H
#define __PYTHON_SCRIPTING_H
#include <Python.h>
/* Function pcbnewInitPythonScripting
* Initializes the Python engine inside pcbnew
*/
void pcbnewInitPythonScripting( void );
#endif
This diff is collapsed.
This diff is collapsed.
#ifndef __wx_helpers_h
#define __wx_helpers_h
#include <Python.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/arrstr.h>
PyObject* wxArrayString2PyList( const wxArrayString& lst );
wxString* newWxStringFromPy( PyObject* source );
wxString Py2wxString( PyObject* source );
PyObject* wx2PyString( const wxString& src );
void wxSetDefaultPyEncoding( const char* encoding );
const char* wxGetDefaultPyEncoding();
#endif
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