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

Fixed wxSize bug, wxPoint(double,double) support, units. Fixed GetBoard wasn't...

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)
parent 7c8bfab5
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,9 +277,11 @@ if (KICAD_SCRIPTING) ...@@ -275,9 +277,11 @@ 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 ...@@ -397,12 +401,31 @@ install(TARGETS pcbnew
DESTINATION ${KICAD_BIN} DESTINATION ${KICAD_BIN}
COMPONENT binary) 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) 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 install(FILES ${CMAKE_BINARY_DIR}/pcbnew/pcbnew.py
DESTINATION share/python) 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 ...@@ -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})
#!/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()
...@@ -29,6 +29,9 @@ ...@@ -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
......
...@@ -8,9 +8,9 @@ ...@@ -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);
......
...@@ -33,26 +33,26 @@ ...@@ -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))
} }
\ No newline at end of file
...@@ -108,7 +108,7 @@ class wxSize ...@@ -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()
...@@ -155,6 +155,7 @@ class wxPoint ...@@ -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; }
......
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