From 3dacab9691a381e138fcbf6c907b969cd689776d Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Mon, 5 Mar 2012 23:49:49 +0100 Subject: [PATCH] wxPoint + more lists --- pcbnew/scripting/kicad.i | 12 +++++++ pcbnew/scripting/pcbnew.i | 17 ++++++++-- pcbnew/scripting/tests/test1.py | 14 ++++++++ pcbnew/scripting/wx.i | 58 +++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 pcbnew/scripting/tests/test1.py create mode 100644 pcbnew/scripting/wx.i diff --git a/pcbnew/scripting/kicad.i b/pcbnew/scripting/kicad.i index 38b8f0fc34..d5140d0177 100644 --- a/pcbnew/scripting/kicad.i +++ b/pcbnew/scripting/kicad.i @@ -1,6 +1,15 @@ %module kicad %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 GetCommandOptions; @@ -16,4 +25,7 @@ %include +%include + + diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i index 8301253399..342ee37eb4 100644 --- a/pcbnew/scripting/pcbnew.i +++ b/pcbnew/scripting/pcbnew.i @@ -1,13 +1,13 @@ %module pcbnew %import "kicad.i" - %{ #include #include #include #include #include + #include BOARD *GetBoard(); @@ -17,12 +17,23 @@ %include %include %include +%include +%include + +%rename(item) operator BOARD_ITEM*; +%rename(item) operator TRACK*; +%rename(item) operator D_PAD*; +%rename(item) operator MODULE*; BOARD *GetBoard(); -/*%template(BOARD_ITEM_List) DLIST; + + +%template(BOARD_ITEM_List) DLIST; %template(MODULE_List) DLIST; %template(TRACK_List) DLIST; %template(PAD_List) DLIST; -*/ + + + diff --git a/pcbnew/scripting/tests/test1.py b/pcbnew/scripting/tests/test1.py new file mode 100644 index 0000000000..6b50b24914 --- /dev/null +++ b/pcbnew/scripting/tests/test1.py @@ -0,0 +1,14 @@ +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() + + diff --git a/pcbnew/scripting/wx.i b/pcbnew/scripting/wx.i new file mode 100644 index 0000000000..227859e02b --- /dev/null +++ b/pcbnew/scripting/wx.i @@ -0,0 +1,58 @@ + + +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 + } +}; +