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:
parent
7c8bfab5ca
commit
be15057977
|
@ -1,7 +1,9 @@
|
|||
add_definitions(-DPCBNEW)
|
||||
|
||||
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)
|
||||
|
||||
FIND_PACKAGE(SWIG REQUIRED)
|
||||
|
@ -275,8 +277,10 @@ if (KICAD_SCRIPTING)
|
|||
add_custom_command(
|
||||
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 ${CMAKE_CURRENT_SOURCE_DIR}/../scripting/fixswigimports.py ${CMAKE_CURRENT_BINARY_DIR}/pcbnew.py
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
|
||||
endif(KICAD_SCRIPTING)
|
||||
|
||||
|
@ -397,12 +401,31 @@ install(TARGETS pcbnew
|
|||
DESTINATION ${KICAD_BIN}
|
||||
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
|
||||
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
|
||||
DESTINATION share/python)
|
||||
DESTINATION ${PYTHON_DEST})
|
||||
endif(KICAD_SCRIPTING_MODULES)
|
||||
|
||||
|
||||
|
@ -418,3 +441,4 @@ add_executable(layer_widget_test WIN32 EXCLUDE_FROM_ALL
|
|||
layer_widget.cpp
|
||||
)
|
||||
target_link_libraries(layer_widget_test common ${wxWidgets_LIBRARIES})
|
||||
|
||||
|
|
|
@ -1,17 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
#!/usr/bin/env python2.7
|
||||
from pcbnew import *
|
||||
|
||||
size_0_6mm = wxSize(FromMM(0.6),FromMM(0.6))
|
||||
|
||||
|
||||
# create a blank board
|
||||
pcb = BOARD()
|
||||
|
||||
# create a new module, it's parent is our previously created 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)
|
||||
module.Add(pad)
|
||||
# create a pad 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)
|
||||
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 = 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 "Saved?"
|
||||
for m in pcb.GetModules():
|
||||
for p in m.GetPads():
|
||||
print p.GetPadName(),p.GetPosition(), p.GetOffset()
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
|
||||
|
||||
%module pcbnew
|
||||
|
||||
%feature("autodoc", "1");
|
||||
|
||||
%include "kicad.i"
|
||||
|
||||
// ignore a couple of items that generate warnings from swig built code
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#ifndef SWIG
|
||||
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame);
|
||||
BOARD *GetBoard();
|
||||
#endif
|
||||
|
||||
BOARD *GetBoard();
|
||||
BOARD* LoadBoard(wxString aFileName);
|
||||
bool SaveBoard(wxString aFileName, BOARD* aBoard);
|
||||
|
||||
|
|
|
@ -33,26 +33,26 @@
|
|||
%pythoncode
|
||||
{
|
||||
def ToMM(iu):
|
||||
if type(iu) is int:
|
||||
if type(iu) in [int,float]:
|
||||
return iu * 0.00254
|
||||
elif type(iu) is wxPoint:
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
return tuple(map(ToMM,iu))
|
||||
|
||||
def FromMM(mm):
|
||||
if type(iu) is int:
|
||||
def FromMM(iu):
|
||||
if type(iu) in [int,float]:
|
||||
return iu / 0.00254
|
||||
elif type(iu) is wxPoint:
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
return tuple(map(FromMM,iu))
|
||||
|
||||
def ToMils(iu):
|
||||
if type(iu) is int:
|
||||
if type(iu) in [int,float]:
|
||||
return iu / 10.0
|
||||
elif type(iu) is wxPoint:
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
return tuple(map(ToMils,iu))
|
||||
|
||||
def FromMils(mils):
|
||||
if type(iu) is int:
|
||||
if type(iu) in [int,float]:
|
||||
return mils*10.0
|
||||
elif type(iu) is wxPoint:
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
return tuple(map(FromMils,iu))
|
||||
}
|
|
@ -108,7 +108,7 @@ class wxSize
|
|||
public:
|
||||
int x,y;
|
||||
wxSize(int xx, int yy) : x(xx), y(yy) { }
|
||||
|
||||
wxSize(double xx, double yy) : x(xx), y(yy) {}
|
||||
%extend
|
||||
{
|
||||
PyObject* Get()
|
||||
|
@ -130,20 +130,20 @@ public:
|
|||
|
||||
%pythoncode
|
||||
{
|
||||
def Scale(self,xscale,yscale):
|
||||
return wxSize(self.x*xscale,self.y*yscale)
|
||||
def __eq__(self,other):
|
||||
return self.GetWidth()==other.GetWidth() and self.GetHeight()==other.GetHeight()
|
||||
def __str__(self): return str(self.Get())
|
||||
def __repr__(self): return 'wxSize'+str(self.Get())
|
||||
def __len__(self): return len(self.Get())
|
||||
def __getitem__(self, index): return self.Get()[index]
|
||||
def __setitem__(self, index, val):
|
||||
if index == 0: self.SetWidth(val)
|
||||
elif index == 1: self.SetHeight(val)
|
||||
else: raise IndexError
|
||||
def __nonzero__(self): return self.Get() != (0,0)
|
||||
__safe_for_unpickling__ = True
|
||||
def Scale(self,xscale,yscale):
|
||||
return wxSize(self.x*xscale,self.y*yscale)
|
||||
def __eq__(self,other):
|
||||
return self.GetWidth()==other.GetWidth() and self.GetHeight()==other.GetHeight()
|
||||
def __str__(self): return str(self.Get())
|
||||
def __repr__(self): return 'wxSize'+str(self.Get())
|
||||
def __len__(self): return len(self.Get())
|
||||
def __getitem__(self, index): return self.Get()[index]
|
||||
def __setitem__(self, index, val):
|
||||
if index == 0: self.SetWidth(val)
|
||||
elif index == 1: self.SetHeight(val)
|
||||
else: raise IndexError
|
||||
def __nonzero__(self): return self.Get() != (0,0)
|
||||
__safe_for_unpickling__ = True
|
||||
|
||||
}
|
||||
};
|
||||
|
@ -155,6 +155,7 @@ class wxPoint
|
|||
public:
|
||||
int x, y;
|
||||
wxPoint(int xx, int yy);
|
||||
wxPoint(double xx, double yy) : x(xx), y(yy) {}
|
||||
~wxPoint();
|
||||
%extend {
|
||||
wxPoint __add__(const wxPoint& pt) { return *self + pt; }
|
||||
|
|
Loading…
Reference in New Issue