Fixed wxSize bug, wxPoint(double,double) support, units. Fixed GetBoard wasn't accessible at every build. Extended example for board creation (now adds pads). Also fixed the _pcbnew loading from pcbnew which should only go to the internal _pcbnew and not the _pcbnew.so/dso. Right installation path for _pcbnew.so (in linux only)

This commit is contained in:
Miguel Angel Ajo 2012-04-08 16:25:49 +02:00
parent 7c8bfab5ca
commit be15057977
6 changed files with 91 additions and 36 deletions

View File

@ -1,7 +1,9 @@
add_definitions(-DPCBNEW) add_definitions(-DPCBNEW)
if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES) if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES)
EXECUTE_PROCESS(COMMAND python -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) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripting)
FIND_PACKAGE(SWIG REQUIRED) FIND_PACKAGE(SWIG REQUIRED)
@ -275,8 +277,10 @@ if (KICAD_SCRIPTING)
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
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../scripting/fixswigimports.py ${CMAKE_CURRENT_BINARY_DIR}/pcbnew.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
endif(KICAD_SCRIPTING) endif(KICAD_SCRIPTING)
@ -397,12 +401,31 @@ install(TARGETS pcbnew
DESTINATION ${KICAD_BIN} DESTINATION ${KICAD_BIN}
COMPONENT binary) COMPONENT binary)
if (KICAD_SCRIPTING_MODULES) 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 install(FILES ${CMAKE_BINARY_DIR}/pcbnew/pcbnew.py
DESTINATION share/python) 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 install(FILES ${CMAKE_BINARY_DIR}/pcbnew/_pcbnew.so
DESTINATION share/python) DESTINATION ${PYTHON_DEST})
endif(KICAD_SCRIPTING_MODULES) endif(KICAD_SCRIPTING_MODULES)
@ -418,3 +441,4 @@ add_executable(layer_widget_test WIN32 EXCLUDE_FROM_ALL
layer_widget.cpp layer_widget.cpp
) )
target_link_libraries(layer_widget_test common ${wxWidgets_LIBRARIES}) target_link_libraries(layer_widget_test common ${wxWidgets_LIBRARIES})

View File

@ -1,17 +1,44 @@
#!/usr/bin/env python #!/usr/bin/env python2.7
from pcbnew import * from pcbnew import *
size_0_6mm = wxSize(FromMM(0.6),FromMM(0.6))
# create a blank board
pcb = BOARD() pcb = BOARD()
# create a new module, it's parent is our previously created pcb
module = MODULE(pcb) module = MODULE(pcb)
module.SetReference("M1") module.SetReference("M1") # give it a reference name
pcb.Add(module) # add it to our pcb
m_pos = wxPoint(FromMM(50),FromMM(50))
module.SetPosition(m_pos)
print "module position:",m_pos
pad = D_PAD(module) # create a pad and add it to the module
module.Add(pad) n = 1
for y in range (0,10):
for x in range (0,10):
pad = D_PAD(module)
pad.SetDrillSize(size_0_6mm)
pt = wxPoint(FromMM(x*2),FromMM(y*2))
pad.SetPos0(pt);
pad.SetPosition(pt)
pad.SetPadName(str(n))
module.Add(pad)
n+=1
pcb.Add(module) # save the PCB to disk
pcb.Save("/tmp/my2.brd") pcb.Save("/tmp/my2.brd")
pcb = LoadBoard("/tmp/my2.brd")
#pcb = LoadBoard("/home/ajo/work/xpress-hardware/boards/hexa-xpress/esp.brd");
print map( lambda x: x.GetReference() , list(pcb.GetModules())) print map( lambda x: x.GetReference() , list(pcb.GetModules()))
print "Saved?" for m in pcb.GetModules():
for p in m.GetPads():
print p.GetPadName(),p.GetPosition(), p.GetOffset()

View File

@ -29,6 +29,9 @@
%module pcbnew %module pcbnew
%feature("autodoc", "1");
%include "kicad.i" %include "kicad.i"
// ignore a couple of items that generate warnings from swig built code // ignore a couple of items that generate warnings from swig built code

View File

@ -8,9 +8,9 @@
#ifndef SWIG #ifndef SWIG
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame); void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame);
BOARD *GetBoard();
#endif #endif
BOARD *GetBoard();
BOARD* LoadBoard(wxString aFileName); BOARD* LoadBoard(wxString aFileName);
bool SaveBoard(wxString aFileName, BOARD* aBoard); bool SaveBoard(wxString aFileName, BOARD* aBoard);

View File

@ -33,26 +33,26 @@
%pythoncode %pythoncode
{ {
def ToMM(iu): def ToMM(iu):
if type(iu) is int: if type(iu) in [int,float]:
return iu * 0.00254 return iu * 0.00254
elif type(iu) is wxPoint: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMM,iu)) return tuple(map(ToMM,iu))
def FromMM(mm): def FromMM(iu):
if type(iu) is int: if type(iu) in [int,float]:
return iu / 0.00254 return iu / 0.00254
elif type(iu) is wxPoint: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(FromMM,iu)) return tuple(map(FromMM,iu))
def ToMils(iu): def ToMils(iu):
if type(iu) is int: if type(iu) in [int,float]:
return iu / 10.0 return iu / 10.0
elif type(iu) is wxPoint: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMils,iu)) return tuple(map(ToMils,iu))
def FromMils(mils): def FromMils(mils):
if type(iu) is int: if type(iu) in [int,float]:
return mils*10.0 return mils*10.0
elif type(iu) is wxPoint: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(FromMils,iu)) return tuple(map(FromMils,iu))
} }

View File

@ -108,7 +108,7 @@ class wxSize
public: public:
int x,y; int x,y;
wxSize(int xx, int yy) : x(xx), y(yy) { } wxSize(int xx, int yy) : x(xx), y(yy) { }
wxSize(double xx, double yy) : x(xx), y(yy) {}
%extend %extend
{ {
PyObject* Get() PyObject* Get()
@ -130,20 +130,20 @@ public:
%pythoncode %pythoncode
{ {
def Scale(self,xscale,yscale): def Scale(self,xscale,yscale):
return wxSize(self.x*xscale,self.y*yscale) return wxSize(self.x*xscale,self.y*yscale)
def __eq__(self,other): def __eq__(self,other):
return self.GetWidth()==other.GetWidth() and self.GetHeight()==other.GetHeight() return self.GetWidth()==other.GetWidth() and self.GetHeight()==other.GetHeight()
def __str__(self): return str(self.Get()) def __str__(self): return str(self.Get())
def __repr__(self): return 'wxSize'+str(self.Get()) def __repr__(self): return 'wxSize'+str(self.Get())
def __len__(self): return len(self.Get()) def __len__(self): return len(self.Get())
def __getitem__(self, index): return self.Get()[index] def __getitem__(self, index): return self.Get()[index]
def __setitem__(self, index, val): def __setitem__(self, index, val):
if index == 0: self.SetWidth(val) if index == 0: self.SetWidth(val)
elif index == 1: self.SetHeight(val) elif index == 1: self.SetHeight(val)
else: raise IndexError else: raise IndexError
def __nonzero__(self): return self.Get() != (0,0) def __nonzero__(self): return self.Get() != (0,0)
__safe_for_unpickling__ = True __safe_for_unpickling__ = True
} }
}; };
@ -155,6 +155,7 @@ class wxPoint
public: public:
int x, y; int x, y;
wxPoint(int xx, int yy); wxPoint(int xx, int yy);
wxPoint(double xx, double yy) : x(xx), y(yy) {}
~wxPoint(); ~wxPoint();
%extend { %extend {
wxPoint __add__(const wxPoint& pt) { return *self + pt; } wxPoint __add__(const wxPoint& pt) { return *self + pt; }