Commit 3dacab96 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

wxPoint + more lists

parent b21dbd95
%module kicad %module kicad
%nodefaultctor EDA_ITEM; %nodefaultctor EDA_ITEM;
/* swig tries to wrap SetBack/SetNext on derived classes, but this method is
private for most childs, so if we don't ignore it it won't compile */
%ignore EDA_ITEM::SetBack;
%ignore EDA_ITEM::SetNext;
%ignore InitKiCadAbout; %ignore InitKiCadAbout;
%ignore GetCommandOptions; %ignore GetCommandOptions;
...@@ -16,4 +25,7 @@ ...@@ -16,4 +25,7 @@
%include <common.h> %include <common.h>
%include <wx.i>
%module pcbnew %module pcbnew
%import "kicad.i" %import "kicad.i"
%{ %{
#include <class_board_item.h> #include <class_board_item.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_track.h> #include <class_track.h>
#include <class_pad.h> #include <class_pad.h>
#include <dlist.h>
BOARD *GetBoard(); BOARD *GetBoard();
...@@ -17,12 +17,23 @@ ...@@ -17,12 +17,23 @@
%include <class_board.h> %include <class_board.h>
%include <class_module.h> %include <class_module.h>
%include <class_track.h> %include <class_track.h>
%include <class_pad.h>
%include <dlist.h>
%rename(item) operator BOARD_ITEM*;
%rename(item) operator TRACK*;
%rename(item) operator D_PAD*;
%rename(item) operator MODULE*;
BOARD *GetBoard(); BOARD *GetBoard();
/*%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(MODULE_List) DLIST<MODULE>; %template(MODULE_List) DLIST<MODULE>;
%template(TRACK_List) DLIST<TRACK>; %template(TRACK_List) DLIST<TRACK>;
%template(PAD_List) DLIST<D_PAD>; %template(PAD_List) DLIST<D_PAD>;
*/
pcb = pcbnew.GetBoard()
m = pcb.m_Modules.item()
while m:
print m.GetPosition()
p = m.m_Pads.item()
while p:
print "p=>",p.GetPosition(),p.GetPadName()
print p.GetPosition()
p = p.Next()
m = m.Next()
class wxPoint
{
public:
int x, y;
wxPoint(int xx, int yy);
~wxPoint();
%extend {
wxPoint __add__(const wxPoint& pt) {
return *self + pt;
}
wxPoint __sub__(const wxPoint& pt) {
return *self - pt;
}
void Set(long x, long y) {
self->x = x;
self->y = y;
}
PyObject* Get() {
//wxPyBlock_t blocked = wxPyBeginBlockThreads();
PyObject* tup = PyTuple_New(2);
PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
//wxPyEndBlockThreads(blocked);
return tup;
}
}
%pythoncode {
def __eq__(self,other): return (self.x==other.x and self.y==other.y)
def __ne__(self,other): return not (self==other)
def __str__(self): return str(self.Get())
def __repr__(self): return 'wx.Point'+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.x = val
elif index == 1: self.y = val
else: raise IndexError
def __nonzero__(self): return self.Get() != (0,0)
__safe_for_unpickling__ = True
}
};
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