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

wxPoint + more lists

parent b21dbd95
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
%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 <common.h>


%include <wx.i>


+14 −3
Original line number Diff line number Diff line
%module pcbnew
%import "kicad.i"


%{
	#include <class_board_item.h>
	#include <class_board.h>
	#include <class_module.h>
	#include <class_track.h>	
	#include <class_pad.h>
	#include <dlist.h>


	BOARD *GetBoard();
@@ -17,12 +17,23 @@
%include <class_board.h>
%include <class_module.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();

/*%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;


%template(BOARD_ITEM_List) DLIST<BOARD_ITEM>;
%template(MODULE_List) DLIST<MODULE>;
%template(TRACK_List) DLIST<TRACK>;
%template(PAD_List) DLIST<D_PAD>;
*/


+14 −0
Original line number Diff line number Diff line
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()		

pcbnew/scripting/wx.i

0 → 100644
+58 −0
Original line number Diff line number Diff line


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
    }
};